teodor-new-chat-ui 4.3.150 → 4.3.152

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(_e,b){typeof exports=="object"&&typeof module<"u"?b(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"],b):(_e=typeof globalThis<"u"?globalThis:_e||self,b(_e.NewChatUI={},_e.React,_e.LucideReact,_e.reactSlot,_e.classVarianceAuthority,_e.clsx,_e.tailwindMerge,_e.ReactDOM))})(this,function(_e,b,he,wr,Yo,Zm,Qm,Ri){"use strict";var xT=Object.defineProperty;var vT=(_e,b,he)=>b in _e?xT(_e,b,{enumerable:!0,configurable:!0,writable:!0,value:he}):_e[b]=he;var Xm=(_e,b,he)=>vT(_e,typeof b!="symbol"?b+"":b,he);function Kl(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=Kl(b),Xo=Kl(Ri);var Oi={exports:{}},co={};/**
1
+ (function(Ae,b){typeof exports=="object"&&typeof module<"u"?b(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"],b):(Ae=typeof globalThis<"u"?globalThis:Ae||self,b(Ae.NewChatUI={},Ae.React,Ae.LucideReact,Ae.reactSlot,Ae.classVarianceAuthority,Ae.clsx,Ae.tailwindMerge,Ae.ReactDOM))})(this,function(Ae,b,he,vr,Go,Zm,Qm,Ri){"use strict";var wT=Object.defineProperty;var bT=(Ae,b,he)=>b in Ae?wT(Ae,b,{enumerable:!0,configurable:!0,writable:!0,value:he}):Ae[b]=he;var Xm=(Ae,b,he)=>bT(Ae,typeof b!="symbol"?b+"":b,he);function Kl(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=Kl(b),Yo=Kl(Ri);var Oi={exports:{}},co={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -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 Gl;function tg(){return Gl||(Gl=1,process.env.NODE_ENV!=="production"&&function(){var e=b,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"),m=Symbol.iterator,g="@@iterator";function y(N){if(N===null||typeof N!="object")return null;var q=m&&N[m]||N[g];return typeof q=="function"?q:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(N){{for(var q=arguments.length,de=new Array(q>1?q-1:0),Ce=1;Ce<q;Ce++)de[Ce-1]=arguments[Ce];C("error",N,de)}}function C(N,q,de){{var Ce=x.ReactDebugCurrentFrame,He=Ce.getStackAddendum();He!==""&&(q+="%s",de=de.concat([He]));var lt=de.map(function(Oe){return String(Oe)});lt.unshift("Warning: "+q),Function.prototype.apply.call(console[N],console,lt)}}var T=!1,k=!1,S=!1,E=!1,j=!1,_;_=Symbol.for("react.module.reference");function P(N){return!!(typeof N=="string"||typeof N=="function"||N===r||N===s||j||N===o||N===c||N===d||E||N===p||T||k||S||typeof N=="object"&&N!==null&&(N.$$typeof===h||N.$$typeof===f||N.$$typeof===i||N.$$typeof===a||N.$$typeof===l||N.$$typeof===_||N.getModuleId!==void 0))}function D(N,q,de){var Ce=N.displayName;if(Ce)return Ce;var He=q.displayName||q.name||"";return He!==""?de+"("+He+")":de}function z(N){return N.displayName||"Context"}function B(N){if(N==null)return null;if(typeof N.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof N=="function")return N.displayName||N.name||null;if(typeof N=="string")return N;switch(N){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof N=="object")switch(N.$$typeof){case a:var q=N;return z(q)+".Consumer";case i:var de=N;return z(de._context)+".Provider";case l:return D(N,N.render,"ForwardRef");case f:var Ce=N.displayName||null;return Ce!==null?Ce:B(N.type)||"Memo";case h:{var He=N,lt=He._payload,Oe=He._init;try{return B(Oe(lt))}catch{return null}}}return null}var O=Object.assign,H=0,R,V,$,F,ne,Q,ye;function Pe(){}Pe.__reactDisabledLog=!0;function Z(){{if(H===0){R=console.log,V=console.info,$=console.warn,F=console.error,ne=console.group,Q=console.groupCollapsed,ye=console.groupEnd;var N={configurable:!0,enumerable:!0,value:Pe,writable:!0};Object.defineProperties(console,{info:N,log:N,warn:N,error:N,group:N,groupCollapsed:N,groupEnd:N})}H++}}function ue(){{if(H--,H===0){var N={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},N,{value:R}),info:O({},N,{value:V}),warn:O({},N,{value:$}),error:O({},N,{value:F}),group:O({},N,{value:ne}),groupCollapsed:O({},N,{value:Q}),groupEnd:O({},N,{value:ye})})}H<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ke=x.ReactCurrentDispatcher,te;function L(N,q,de){{if(te===void 0)try{throw Error()}catch(He){var Ce=He.stack.trim().match(/\n( *(at )?)/);te=Ce&&Ce[1]||""}return`
18
- `+te+N}}var G=!1,se;{var le=typeof WeakMap=="function"?WeakMap:Map;se=new le}function U(N,q){if(!N||G)return"";{var de=se.get(N);if(de!==void 0)return de}var Ce;G=!0;var He=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var lt;lt=ke.current,ke.current=null,Z();try{if(q){var Oe=function(){throw Error()};if(Object.defineProperty(Oe.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Oe,[])}catch(Lt){Ce=Lt}Reflect.construct(N,[],Oe)}else{try{Oe.call()}catch(Lt){Ce=Lt}N.call(Oe.prototype)}}else{try{throw Error()}catch(Lt){Ce=Lt}N()}}catch(Lt){if(Lt&&Ce&&typeof Lt.stack=="string"){for(var $e=Lt.stack.split(`
17
+ */var Gl;function tg(){return Gl||(Gl=1,process.env.NODE_ENV!=="production"&&function(){var e=b,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"),m=Symbol.iterator,g="@@iterator";function y(N){if(N===null||typeof N!="object")return null;var Y=m&&N[m]||N[g];return typeof Y=="function"?Y:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(N){{for(var Y=arguments.length,ae=new Array(Y>1?Y-1:0),Ce=1;Ce<Y;Ce++)ae[Ce-1]=arguments[Ce];C("error",N,ae)}}function C(N,Y,ae){{var Ce=x.ReactDebugCurrentFrame,Ge=Ce.getStackAddendum();Ge!==""&&(Y+="%s",ae=ae.concat([Ge]));var qe=ae.map(function(He){return String(He)});qe.unshift("Warning: "+Y),Function.prototype.apply.call(console[N],console,qe)}}var T=!1,k=!1,S=!1,E=!1,j=!1,_;_=Symbol.for("react.module.reference");function P(N){return!!(typeof N=="string"||typeof N=="function"||N===r||N===s||j||N===o||N===c||N===d||E||N===p||T||k||S||typeof N=="object"&&N!==null&&(N.$$typeof===h||N.$$typeof===f||N.$$typeof===i||N.$$typeof===a||N.$$typeof===l||N.$$typeof===_||N.getModuleId!==void 0))}function D(N,Y,ae){var Ce=N.displayName;if(Ce)return Ce;var Ge=Y.displayName||Y.name||"";return Ge!==""?ae+"("+Ge+")":ae}function z(N){return N.displayName||"Context"}function B(N){if(N==null)return null;if(typeof N.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof N=="function")return N.displayName||N.name||null;if(typeof N=="string")return N;switch(N){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof N=="object")switch(N.$$typeof){case a:var Y=N;return z(Y)+".Consumer";case i:var ae=N;return z(ae._context)+".Provider";case l:return D(N,N.render,"ForwardRef");case f:var Ce=N.displayName||null;return Ce!==null?Ce:B(N.type)||"Memo";case h:{var Ge=N,qe=Ge._payload,He=Ge._init;try{return B(He(qe))}catch{return null}}}return null}var O=Object.assign,H=0,R,V,$,F,ne,Q,ye;function je(){}je.__reactDisabledLog=!0;function J(){{if(H===0){R=console.log,V=console.info,$=console.warn,F=console.error,ne=console.group,Q=console.groupCollapsed,ye=console.groupEnd;var N={configurable:!0,enumerable:!0,value:je,writable:!0};Object.defineProperties(console,{info:N,log:N,warn:N,error:N,group:N,groupCollapsed:N,groupEnd:N})}H++}}function ue(){{if(H--,H===0){var N={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},N,{value:R}),info:O({},N,{value:V}),warn:O({},N,{value:$}),error:O({},N,{value:F}),group:O({},N,{value:ne}),groupCollapsed:O({},N,{value:Q}),groupEnd:O({},N,{value:ye})})}H<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ke=x.ReactCurrentDispatcher,te;function L(N,Y,ae){{if(te===void 0)try{throw Error()}catch(Ge){var Ce=Ge.stack.trim().match(/\n( *(at )?)/);te=Ce&&Ce[1]||""}return`
18
+ `+te+N}}var q=!1,ie;{var ce=typeof WeakMap=="function"?WeakMap:Map;ie=new ce}function U(N,Y){if(!N||q)return"";{var ae=ie.get(N);if(ae!==void 0)return ae}var Ce;q=!0;var Ge=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var qe;qe=ke.current,ke.current=null,J();try{if(Y){var He=function(){throw Error()};if(Object.defineProperty(He.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(He,[])}catch(zt){Ce=zt}Reflect.construct(N,[],He)}else{try{He.call()}catch(zt){Ce=zt}N.call(He.prototype)}}else{try{throw Error()}catch(zt){Ce=zt}N()}}catch(zt){if(zt&&Ce&&typeof zt.stack=="string"){for(var Re=zt.stack.split(`
19
19
  `),At=Ce.stack.split(`
20
- `),pt=$e.length-1,mt=At.length-1;pt>=1&&mt>=0&&$e[pt]!==At[mt];)mt--;for(;pt>=1&&mt>=0;pt--,mt--)if($e[pt]!==At[mt]){if(pt!==1||mt!==1)do if(pt--,mt--,mt<0||$e[pt]!==At[mt]){var en=`
21
- `+$e[pt].replace(" at new "," at ");return N.displayName&&en.includes("<anonymous>")&&(en=en.replace("<anonymous>",N.displayName)),typeof N=="function"&&se.set(N,en),en}while(pt>=1&&mt>=0);break}}}finally{G=!1,ke.current=lt,ue(),Error.prepareStackTrace=He}var Dn=N?N.displayName||N.name:"",In=Dn?L(Dn):"";return typeof N=="function"&&se.set(N,In),In}function We(N,q,de){return U(N,!1)}function re(N){var q=N.prototype;return!!(q&&q.isReactComponent)}function xe(N,q,de){if(N==null)return"";if(typeof N=="function")return U(N,re(N));if(typeof N=="string")return L(N);switch(N){case c:return L("Suspense");case d:return L("SuspenseList")}if(typeof N=="object")switch(N.$$typeof){case l:return We(N.render);case f:return xe(N.type,q,de);case h:{var Ce=N,He=Ce._payload,lt=Ce._init;try{return xe(lt(He),q,de)}catch{}}}return""}var Re=Object.prototype.hasOwnProperty,Fe={},tt=x.ReactDebugCurrentFrame;function Se(N){if(N){var q=N._owner,de=xe(N.type,N._source,q?q.type:null);tt.setExtraStackFrame(de)}else tt.setExtraStackFrame(null)}function Ge(N,q,de,Ce,He){{var lt=Function.call.bind(Re);for(var Oe in N)if(lt(N,Oe)){var $e=void 0;try{if(typeof N[Oe]!="function"){var At=Error((Ce||"React class")+": "+de+" type `"+Oe+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof N[Oe]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw At.name="Invariant Violation",At}$e=N[Oe](q,Oe,Ce,de,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(pt){$e=pt}$e&&!($e instanceof Error)&&(Se(He),w("%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",de,Oe,typeof $e),Se(null)),$e instanceof Error&&!($e.message in Fe)&&(Fe[$e.message]=!0,Se(He),w("Failed %s type: %s",de,$e.message),Se(null))}}}var nt=Array.isArray;function Qe(N){return nt(N)}function Ye(N){{var q=typeof Symbol=="function"&&Symbol.toStringTag,de=q&&N[Symbol.toStringTag]||N.constructor.name||"Object";return de}}function qe(N){try{return et(N),!1}catch{return!0}}function et(N){return""+N}function Mt(N){if(qe(N))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ye(N)),et(N)}var Ct=x.ReactCurrentOwner,dt={key:!0,ref:!0,__self:!0,__source:!0},xt,ft;function rt(N){if(Re.call(N,"ref")){var q=Object.getOwnPropertyDescriptor(N,"ref").get;if(q&&q.isReactWarning)return!1}return N.ref!==void 0}function rn(N){if(Re.call(N,"key")){var q=Object.getOwnPropertyDescriptor(N,"key").get;if(q&&q.isReactWarning)return!1}return N.key!==void 0}function on(N,q){typeof N.ref=="string"&&Ct.current}function Wt(N,q){{var de=function(){xt||(xt=!0,w("%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))};de.isReactWarning=!0,Object.defineProperty(N,"key",{get:de,configurable:!0})}}function zt(N,q){{var de=function(){ft||(ft=!0,w("%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))};de.isReactWarning=!0,Object.defineProperty(N,"ref",{get:de,configurable:!0})}}var ht=function(N,q,de,Ce,He,lt,Oe){var $e={$$typeof:t,type:N,key:q,ref:de,props:Oe,_owner:lt};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:Ce}),Object.defineProperty($e,"_source",{configurable:!1,enumerable:!1,writable:!1,value:He}),Object.freeze&&(Object.freeze($e.props),Object.freeze($e)),$e};function Ve(N,q,de,Ce,He){{var lt,Oe={},$e=null,At=null;de!==void 0&&(Mt(de),$e=""+de),rn(q)&&(Mt(q.key),$e=""+q.key),rt(q)&&(At=q.ref,on(q,He));for(lt in q)Re.call(q,lt)&&!dt.hasOwnProperty(lt)&&(Oe[lt]=q[lt]);if(N&&N.defaultProps){var pt=N.defaultProps;for(lt in pt)Oe[lt]===void 0&&(Oe[lt]=pt[lt])}if($e||At){var mt=typeof N=="function"?N.displayName||N.name||"Unknown":N;$e&&Wt(Oe,mt),At&&zt(Oe,mt)}return ht(N,$e,At,He,Ce,Ct.current,Oe)}}var Dt=x.ReactCurrentOwner,_t=x.ReactDebugCurrentFrame;function Y(N){if(N){var q=N._owner,de=xe(N.type,N._source,q?q.type:null);_t.setExtraStackFrame(de)}else _t.setExtraStackFrame(null)}var Ie;Ie=!1;function ve(N){return typeof N=="object"&&N!==null&&N.$$typeof===t}function ot(){{if(Dt.current){var N=B(Dt.current.type);if(N)return`
20
+ `),gt=Re.length-1,Ct=At.length-1;gt>=1&&Ct>=0&&Re[gt]!==At[Ct];)Ct--;for(;gt>=1&&Ct>=0;gt--,Ct--)if(Re[gt]!==At[Ct]){if(gt!==1||Ct!==1)do if(gt--,Ct--,Ct<0||Re[gt]!==At[Ct]){var Zt=`
21
+ `+Re[gt].replace(" at new "," at ");return N.displayName&&Zt.includes("<anonymous>")&&(Zt=Zt.replace("<anonymous>",N.displayName)),typeof N=="function"&&ie.set(N,Zt),Zt}while(gt>=1&&Ct>=0);break}}}finally{q=!1,ke.current=qe,ue(),Error.prepareStackTrace=Ge}var Fn=N?N.displayName||N.name:"",hn=Fn?L(Fn):"";return typeof N=="function"&&ie.set(N,hn),hn}function We(N,Y,ae){return U(N,!1)}function re(N){var Y=N.prototype;return!!(Y&&Y.isReactComponent)}function xe(N,Y,ae){if(N==null)return"";if(typeof N=="function")return U(N,re(N));if(typeof N=="string")return L(N);switch(N){case c:return L("Suspense");case d:return L("SuspenseList")}if(typeof N=="object")switch(N.$$typeof){case l:return We(N.render);case f:return xe(N.type,Y,ae);case h:{var Ce=N,Ge=Ce._payload,qe=Ce._init;try{return xe(qe(Ge),Y,ae)}catch{}}}return""}var Pe=Object.prototype.hasOwnProperty,$e={},rt=x.ReactDebugCurrentFrame;function Se(N){if(N){var Y=N._owner,ae=xe(N.type,N._source,Y?Y.type:null);rt.setExtraStackFrame(ae)}else rt.setExtraStackFrame(null)}function Ye(N,Y,ae,Ce,Ge){{var qe=Function.call.bind(Pe);for(var He in N)if(qe(N,He)){var Re=void 0;try{if(typeof N[He]!="function"){var At=Error((Ce||"React class")+": "+ae+" type `"+He+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof N[He]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw At.name="Invariant Violation",At}Re=N[He](Y,He,Ce,ae,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(gt){Re=gt}Re&&!(Re instanceof Error)&&(Se(Ge),w("%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",ae,He,typeof Re),Se(null)),Re instanceof Error&&!(Re.message in $e)&&($e[Re.message]=!0,Se(Ge),w("Failed %s type: %s",ae,Re.message),Se(null))}}}var ot=Array.isArray;function et(N){return ot(N)}function Xe(N){{var Y=typeof Symbol=="function"&&Symbol.toStringTag,ae=Y&&N[Symbol.toStringTag]||N.constructor.name||"Object";return ae}}function Ke(N){try{return tt(N),!1}catch{return!0}}function tt(N){return""+N}function Ot(N){if(Ke(N))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Xe(N)),tt(N)}var St=x.ReactCurrentOwner,nt={key:!0,ref:!0,__self:!0,__source:!0},yt,Nt;function st(N){if(Pe.call(N,"ref")){var Y=Object.getOwnPropertyDescriptor(N,"ref").get;if(Y&&Y.isReactWarning)return!1}return N.ref!==void 0}function Gt(N){if(Pe.call(N,"key")){var Y=Object.getOwnPropertyDescriptor(N,"key").get;if(Y&&Y.isReactWarning)return!1}return N.key!==void 0}function Yt(N,Y){typeof N.ref=="string"&&St.current}function Xt(N,Y){{var ae=function(){yt||(yt=!0,w("%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)",Y))};ae.isReactWarning=!0,Object.defineProperty(N,"key",{get:ae,configurable:!0})}}function Jt(N,Y){{var ae=function(){Nt||(Nt=!0,w("%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)",Y))};ae.isReactWarning=!0,Object.defineProperty(N,"ref",{get:ae,configurable:!0})}}var ft=function(N,Y,ae,Ce,Ge,qe,He){var Re={$$typeof:t,type:N,key:Y,ref:ae,props:He,_owner:qe};return Re._store={},Object.defineProperty(Re._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Re,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Ce}),Object.defineProperty(Re,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ge}),Object.freeze&&(Object.freeze(Re.props),Object.freeze(Re)),Re};function Ve(N,Y,ae,Ce,Ge){{var qe,He={},Re=null,At=null;ae!==void 0&&(Ot(ae),Re=""+ae),Gt(Y)&&(Ot(Y.key),Re=""+Y.key),st(Y)&&(At=Y.ref,Yt(Y,Ge));for(qe in Y)Pe.call(Y,qe)&&!nt.hasOwnProperty(qe)&&(He[qe]=Y[qe]);if(N&&N.defaultProps){var gt=N.defaultProps;for(qe in gt)He[qe]===void 0&&(He[qe]=gt[qe])}if(Re||At){var Ct=typeof N=="function"?N.displayName||N.name||"Unknown":N;Re&&Xt(He,Ct),At&&Jt(He,Ct)}return ft(N,Re,At,Ge,Ce,St.current,He)}}var Mt=x.ReactCurrentOwner,_t=x.ReactDebugCurrentFrame;function G(N){if(N){var Y=N._owner,ae=xe(N.type,N._source,Y?Y.type:null);_t.setExtraStackFrame(ae)}else _t.setExtraStackFrame(null)}var Te;Te=!1;function ve(N){return typeof N=="object"&&N!==null&&N.$$typeof===t}function pt(){{if(Mt.current){var N=B(Mt.current.type);if(N)return`
22
22
 
23
- Check the render method of \``+N+"`."}return""}}function vt(N){return""}var It={};function Ne(N){{var q=ot();if(!q){var de=typeof N=="string"?N:N.displayName||N.name;de&&(q=`
23
+ Check the render method of \``+N+"`."}return""}}function mt(N){return""}var ct={};function Me(N){{var Y=pt();if(!Y){var ae=typeof N=="string"?N:N.displayName||N.name;ae&&(Y=`
24
24
 
25
- Check the top-level render call using <`+de+">.")}return q}}function Qt(N,q){{if(!N._store||N._store.validated||N.key!=null)return;N._store.validated=!0;var de=Ne(q);if(It[de])return;It[de]=!0;var Ce="";N&&N._owner&&N._owner!==Dt.current&&(Ce=" It was passed a child from "+B(N._owner.type)+"."),Y(N),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',de,Ce),Y(null)}}function at(N,q){{if(typeof N!="object")return;if(Qe(N))for(var de=0;de<N.length;de++){var Ce=N[de];ve(Ce)&&Qt(Ce,q)}else if(ve(N))N._store&&(N._store.validated=!0);else if(N){var He=y(N);if(typeof He=="function"&&He!==N.entries)for(var lt=He.call(N),Oe;!(Oe=lt.next()).done;)ve(Oe.value)&&Qt(Oe.value,q)}}}function Xe(N){{var q=N.type;if(q==null||typeof q=="string")return;var de;if(typeof q=="function")de=q.propTypes;else if(typeof q=="object"&&(q.$$typeof===l||q.$$typeof===f))de=q.propTypes;else return;if(de){var Ce=B(q);Ge(de,N.props,"prop",Ce,N)}else if(q.PropTypes!==void 0&&!Ie){Ie=!0;var He=B(q);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",He||"Unknown")}typeof q.getDefaultProps=="function"&&!q.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function sn(N){{for(var q=Object.keys(N.props),de=0;de<q.length;de++){var Ce=q[de];if(Ce!=="children"&&Ce!=="key"){Y(N),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ce),Y(null);break}}N.ref!==null&&(Y(N),w("Invalid attribute `ref` supplied to `React.Fragment`."),Y(null))}}var qn={};function jt(N,q,de,Ce,He,lt){{var Oe=P(N);if(!Oe){var $e="";(N===void 0||typeof N=="object"&&N!==null&&Object.keys(N).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 At=vt();At?$e+=At:$e+=ot();var pt;N===null?pt="null":Qe(N)?pt="array":N!==void 0&&N.$$typeof===t?(pt="<"+(B(N.type)||"Unknown")+" />",$e=" Did you accidentally export a JSX literal instead of a component?"):pt=typeof N,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",pt,$e)}var mt=Ve(N,q,de,He,lt);if(mt==null)return mt;if(Oe){var en=q.children;if(en!==void 0)if(Ce)if(Qe(en)){for(var Dn=0;Dn<en.length;Dn++)at(en[Dn],N);Object.freeze&&Object.freeze(en)}else w("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 at(en,N)}if(Re.call(q,"key")){var In=B(N),Lt=Object.keys(q).filter(function(ce){return ce!=="key"}),xr=Lt.length>0?"{key: someKey, "+Lt.join(": ..., ")+": ...}":"{key: someKey}";if(!qn[In+xr]){var J=Lt.length>0?"{"+Lt.join(": ..., ")+": ...}":"{}";w(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+ae+">.")}return Y}}function Ut(N,Y){{if(!N._store||N._store.validated||N.key!=null)return;N._store.validated=!0;var ae=Me(Y);if(ct[ae])return;ct[ae]=!0;var Ce="";N&&N._owner&&N._owner!==Mt.current&&(Ce=" It was passed a child from "+B(N._owner.type)+"."),G(N),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ae,Ce),G(null)}}function Le(N,Y){{if(typeof N!="object")return;if(et(N))for(var ae=0;ae<N.length;ae++){var Ce=N[ae];ve(Ce)&&Ut(Ce,Y)}else if(ve(N))N._store&&(N._store.validated=!0);else if(N){var Ge=y(N);if(typeof Ge=="function"&&Ge!==N.entries)for(var qe=Ge.call(N),He;!(He=qe.next()).done;)ve(He.value)&&Ut(He.value,Y)}}}function xt(N){{var Y=N.type;if(Y==null||typeof Y=="string")return;var ae;if(typeof Y=="function")ae=Y.propTypes;else if(typeof Y=="object"&&(Y.$$typeof===l||Y.$$typeof===f))ae=Y.propTypes;else return;if(ae){var Ce=B(Y);Ye(ae,N.props,"prop",Ce,N)}else if(Y.PropTypes!==void 0&&!Te){Te=!0;var Ge=B(Y);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ge||"Unknown")}typeof Y.getDefaultProps=="function"&&!Y.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ln(N){{for(var Y=Object.keys(N.props),ae=0;ae<Y.length;ae++){var Ce=Y[ae];if(Ce!=="children"&&Ce!=="key"){G(N),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ce),G(null);break}}N.ref!==null&&(G(N),w("Invalid attribute `ref` supplied to `React.Fragment`."),G(null))}}var Dt={};function fn(N,Y,ae,Ce,Ge,qe){{var He=P(N);if(!He){var Re="";(N===void 0||typeof N=="object"&&N!==null&&Object.keys(N).length===0)&&(Re+=" 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 At=mt();At?Re+=At:Re+=pt();var gt;N===null?gt="null":et(N)?gt="array":N!==void 0&&N.$$typeof===t?(gt="<"+(B(N.type)||"Unknown")+" />",Re=" Did you accidentally export a JSX literal instead of a component?"):gt=typeof N,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",gt,Re)}var Ct=Ve(N,Y,ae,Ge,qe);if(Ct==null)return Ct;if(He){var Zt=Y.children;if(Zt!==void 0)if(Ce)if(et(Zt)){for(var Fn=0;Fn<Zt.length;Fn++)Le(Zt[Fn],N);Object.freeze&&Object.freeze(Zt)}else w("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 Le(Zt,N)}if(Pe.call(Y,"key")){var hn=B(N),zt=Object.keys(Y).filter(function(se){return se!=="key"}),$n=zt.length>0?"{key: someKey, "+zt.join(": ..., ")+": ...}":"{key: someKey}";if(!Dt[hn+$n]){var Z=zt.length>0?"{"+zt.join(": ..., ")+": ...}":"{}";w(`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} />`,xr,In,J,In),qn[In+xr]=!0}}return N===r?sn(mt):Xe(mt),mt}}function rr(N,q,de){return jt(N,q,de,!0)}function Fr(N,q,de){return jt(N,q,de,!1)}var Ko=Fr,$r=rr;uo.Fragment=r,uo.jsx=Ko,uo.jsxs=$r}()),uo}process.env.NODE_ENV==="production"?Oi.exports=eg():Oi.exports=tg();var u=Oi.exports;function Yl(e,t){return function(){return e.apply(t,arguments)}}const{toString:ng}=Object.prototype,{getPrototypeOf:Mi}=Object,{iterator:Jo,toStringTag:Xl}=Symbol,Zo=(e=>t=>{const n=ng.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),An=e=>(e=e.toLowerCase(),t=>Zo(t)===e),Qo=e=>t=>typeof t===e,{isArray:Hr}=Array,Ur=Qo("undefined");function fo(e){return e!==null&&!Ur(e)&&e.constructor!==null&&!Ur(e.constructor)&&an(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Jl=An("ArrayBuffer");function rg(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Jl(e.buffer),t}const og=Qo("string"),an=Qo("function"),Zl=Qo("number"),ho=e=>e!==null&&typeof e=="object",sg=e=>e===!0||e===!1,es=e=>{if(Zo(e)!=="object")return!1;const t=Mi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xl in e)&&!(Jo in e)},ig=e=>{if(!ho(e)||fo(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},ag=An("Date"),lg=An("File"),cg=An("Blob"),ug=An("FileList"),dg=e=>ho(e)&&an(e.pipe),fg=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||an(e.append)&&((t=Zo(e))==="formdata"||t==="object"&&an(e.toString)&&e.toString()==="[object FormData]"))},hg=An("URLSearchParams"),[pg,mg,gg,yg]=["ReadableStream","Request","Response","Headers"].map(An),xg=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function po(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Hr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(fo(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 Ql(e,t){if(fo(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 br=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,ec=e=>!Ur(e)&&e!==br;function Di(){const{caseless:e,skipUndefined:t}=ec(this)&&this||{},n={},r=(o,s)=>{const i=e&&Ql(n,s)||s;es(n[i])&&es(o)?n[i]=Di(n[i],o):es(o)?n[i]=Di({},o):Hr(o)?n[i]=o.slice():(!t||!Ur(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&po(arguments[o],r);return n}const vg=(e,t,n,{allOwnKeys:r}={})=>(po(t,(o,s)=>{n&&an(o)?e[s]=Yl(o,n):e[s]=o},{allOwnKeys:r}),e),wg=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),bg=(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)},Sg=(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&&Mi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Cg=(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},kg=e=>{if(!e)return null;if(Hr(e))return e;let t=e.length;if(!Zl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Tg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Mi(Uint8Array)),Eg=(e,t)=>{const r=(e&&e[Jo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Ig=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Ng=An("HTMLFormElement"),Ag=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tc=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),_g=An("RegExp"),nc=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};po(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},jg=e=>{nc(e,(t,n)=>{if(an(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(an(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+"'")})}})},Pg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Hr(e)?r(e):r(String(e).split(t)),n},Rg=()=>{},Og=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Mg(e){return!!(e&&an(e.append)&&e[Xl]==="FormData"&&e[Jo])}const Dg=e=>{const t=new Array(10),n=(r,o)=>{if(ho(r)){if(t.indexOf(r)>=0)return;if(fo(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Hr(r)?[]:{};return po(r,(i,a)=>{const l=n(i,o+1);!Ur(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Lg=An("AsyncFunction"),Fg=e=>e&&(ho(e)||an(e))&&an(e.then)&&an(e.catch),rc=((e,t)=>e?setImmediate:t?((n,r)=>(br.addEventListener("message",({source:o,data:s})=>{o===br&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),br.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",an(br.postMessage)),$g=typeof queueMicrotask<"u"?queueMicrotask.bind(br):typeof process<"u"&&process.nextTick||rc,M={isArray:Hr,isArrayBuffer:Jl,isBuffer:fo,isFormData:fg,isArrayBufferView:rg,isString:og,isNumber:Zl,isBoolean:sg,isObject:ho,isPlainObject:es,isEmptyObject:ig,isReadableStream:pg,isRequest:mg,isResponse:gg,isHeaders:yg,isUndefined:Ur,isDate:ag,isFile:lg,isBlob:cg,isRegExp:_g,isFunction:an,isStream:dg,isURLSearchParams:hg,isTypedArray:Tg,isFileList:ug,forEach:po,merge:Di,extend:vg,trim:xg,stripBOM:wg,inherits:bg,toFlatObject:Sg,kindOf:Zo,kindOfTest:An,endsWith:Cg,toArray:kg,forEachEntry:Eg,matchAll:Ig,isHTMLForm:Ng,hasOwnProperty:tc,hasOwnProp:tc,reduceDescriptors:nc,freezeMethods:jg,toObjectSet:Pg,toCamelCase:Ag,noop:Rg,toFiniteNumber:Og,findKey:Ql,global:br,isContextDefined:ec,isSpecCompliantForm:Mg,toJSONObject:Dg,isAsyncFn:Lg,isThenable:Fg,setImmediate:rc,asap:$g,isIterable:e=>e!=null&&an(e[Jo])};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 oc=Le.prototype,sc={};["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=>{sc[e]={value:e}}),Object.defineProperties(Le,sc),Object.defineProperty(oc,"isAxiosError",{value:!0}),Le.from=(e,t,n,r,o,s)=>{const i=Object.create(oc);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 zg=null;function Li(e){return M.isPlainObject(e)||M.isArray(e)}function ic(e){return M.endsWith(e,"[]")?e.slice(0,-2):e}function ac(e,t,n){return e?e.concat(t).map(function(o,s){return o=ic(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Bg(e){return M.isArray(e)&&!e.some(Li)}const Hg=M.toFlatObject(M,{},null,function(t){return/^is[A-Z]/.test(t)});function ts(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(g,y){return!M.isUndefined(y[g])});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(m){if(m===null)return"";if(M.isDate(m))return m.toISOString();if(M.isBoolean(m))return m.toString();if(!l&&M.isBlob(m))throw new Le("Blob is not supported. Use a Buffer instead.");return M.isArrayBuffer(m)||M.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function d(m,g,y){let x=m;if(m&&!y&&typeof m=="object"){if(M.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(M.isArray(m)&&Bg(m)||(M.isFileList(m)||M.endsWith(g,"[]"))&&(x=M.toArray(m)))return g=ic(g),x.forEach(function(C,T){!(M.isUndefined(C)||C===null)&&t.append(i===!0?ac([g],T,s):i===null?g:g+"[]",c(C))}),!1}return Li(m)?!0:(t.append(ac(y,g,s),c(m)),!1)}const f=[],h=Object.assign(Hg,{defaultVisitor:d,convertValue:c,isVisitable:Li});function p(m,g){if(!M.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),M.forEach(m,function(x,w){(!(M.isUndefined(x)||x===null)&&o.call(t,x,M.isString(w)?w.trim():w,g,h))===!0&&p(x,g?g.concat(w):[w])}),f.pop()}}if(!M.isObject(e))throw new TypeError("data must be an object");return p(e),t}function lc(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Fi(e,t){this._pairs=[],e&&ts(e,this,t)}const cc=Fi.prototype;cc.append=function(t,n){this._pairs.push([t,n])},cc.toString=function(t){const n=t?function(r){return t.call(this,r,lc)}:lc;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Ug(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function uc(e,t,n){if(!t)return e;const r=n&&n.encode||Ug;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 Fi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dc{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 fc={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Wg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Fi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},$i=typeof window<"u"&&typeof document<"u",zi=typeof navigator=="object"&&navigator||void 0,Vg=$i&&(!zi||["ReactNative","NativeScript","NS"].indexOf(zi.product)<0),Kg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",qg=$i&&window.location.href||"http://localhost",Yt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:$i,hasStandardBrowserEnv:Vg,hasStandardBrowserWebWorkerEnv:Kg,navigator:zi,origin:qg},Symbol.toStringTag,{value:"Module"})),...Wg};function Gg(e,t){return ts(e,new Yt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Yt.isNode&&M.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Yg(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Xg(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 hc(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]=Xg(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t(Yg(r),o,n,0)}),n}return null}function Jg(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 mo={transitional:fc,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(hc(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 Gg(t,this.formSerializer).toString();if((a=M.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return ts(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Jg(t)):t}],transformResponse:[function(t){const n=this.transitional||mo.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:Yt.classes.FormData,Blob:Yt.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=>{mo.headers[e]={}});const Zg=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"]),Qg=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]&&Zg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},pc=Symbol("internals");function go(e){return e&&String(e).trim().toLowerCase()}function ns(e){return e===!1||e==null?e:M.isArray(e)?e.map(ns):String(e)}function ey(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 ty=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Bi(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 ny(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function ry(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 ln=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=go(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]=ns(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())&&!ty(t))i(Qg(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=go(t),t){const r=M.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return ey(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=go(t),t){const r=M.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Bi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=go(i),i){const a=M.findKey(r,i);a&&(!n||Bi(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||Bi(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]=ns(o),delete n[s];return}const a=t?ny(s):String(s).trim();a!==s&&delete n[s],n[a]=ns(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[pc]=this[pc]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=go(i);r[a]||(ry(o,i),r[a]=!0)}return M.isArray(t)?t.forEach(s):s(t),this}};ln.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),M.reduceDescriptors(ln.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),M.freezeMethods(ln);function Hi(e,t){const n=this||mo,r=t||n,o=ln.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 mc(e){return!!(e&&e.__CANCEL__)}function Wr(e,t,n){Le.call(this,e??"canceled",Le.ERR_CANCELED,t,n),this.name="CanceledError"}M.inherits(Wr,Le,{__CANCEL__:!0});function gc(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 oy(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function sy(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 iy(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 rs=(e,t,n=3)=>{let r=0;const o=sy(50,250);return iy(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)},yc=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},xc=e=>(...t)=>M.asap(()=>e(...t)),ay=Yt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Yt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Yt.origin),Yt.navigator&&/(msie|trident)/i.test(Yt.navigator.userAgent)):()=>!0,ly=Yt.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 cy(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function uy(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function vc(e,t,n){let r=!cy(t);return e&&(r||n==!1)?uy(e,t):t}const wc=e=>e instanceof ln?{...e}:e;function Sr(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(wc(c),wc(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 bc=e=>{const t=Sr({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=ln.from(i),t.url=uc(vc(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(Yt.hasStandardBrowserEnv||Yt.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(Yt.hasStandardBrowserEnv&&(r&&M.isFunction(r)&&(r=r(t)),r||r!==!1&&ay(t.url))){const l=o&&s&&ly.read(s);l&&i.set(o,l)}return t},dy=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=bc(e);let s=o.data;const i=ln.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,m;function g(){p&&p(),m&&m(),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 x(){if(!y)return;const C=ln.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:C,config:e,request:y};gc(function(E){n(E),g()},function(E){r(E),g()},k),y=null}"onloadend"in y?y.onloadend=x:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(x)},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",S=new Le(k,Le.ERR_NETWORK,e,y);S.event=T||null,r(S),y=null},y.ontimeout=function(){let T=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||fc;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,m]=rs(c,!0),y.addEventListener("progress",h)),l&&y.upload&&([f,p]=rs(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=C=>{y&&(r(!C||C.type?new Wr(null,e,y):C),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const w=oy(o.url);if(w&&Yt.protocols.indexOf(w)===-1){r(new Le("Unsupported protocol "+w+":",Le.ERR_BAD_REQUEST,e));return}y.send(s||null)})},fy=(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 Wr(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}},hy=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},py=async function*(e,t){for await(const n of my(e))yield*hy(n,t)},my=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()}},Sc=(e,t,n,r)=>{const o=py(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})},Cc=64*1024,{isFunction:os}=M,gy=(({Request:e,Response:t})=>({Request:e,Response:t}))(M.global),{ReadableStream:kc,TextEncoder:Tc}=M.global,Ec=(e,...t)=>{try{return!!e(...t)}catch{return!1}},yy=e=>{e=M.merge.call({skipUndefined:!0},gy,e);const{fetch:t,Request:n,Response:r}=e,o=t?os(t):typeof fetch=="function",s=os(n),i=os(r);if(!o)return!1;const a=o&&os(kc),l=o&&(typeof Tc=="function"?(m=>g=>m.encode(g))(new Tc):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Ec(()=>{let m=!1;const g=new n(Yt.origin,{body:new kc,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),d=i&&a&&Ec(()=>M.isReadableStream(new r("").body)),f={stream:d&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,y)=>{let x=g&&g[m];if(x)return x.call(g);throw new Le(`Response type '${m}' is not supported`,Le.ERR_NOT_SUPPORT,y)})});const h=async m=>{if(m==null)return 0;if(M.isBlob(m))return m.size;if(M.isSpecCompliantForm(m))return(await new n(Yt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(M.isArrayBufferView(m)||M.isArrayBuffer(m))return m.byteLength;if(M.isURLSearchParams(m)&&(m=m+""),M.isString(m))return(await l(m)).byteLength},p=async(m,g)=>{const y=M.toFiniteNumber(m.getContentLength());return y??h(g)};return async m=>{let{url:g,method:y,data:x,signal:w,cancelToken:C,timeout:T,onDownloadProgress:k,onUploadProgress:S,responseType:E,headers:j,withCredentials:_="same-origin",fetchOptions:P}=bc(m),D=t||fetch;E=E?(E+"").toLowerCase():"text";let z=fy([w,C&&C.toAbortSignal()],T),B=null;const O=z&&z.unsubscribe&&(()=>{z.unsubscribe()});let H;try{if(S&&c&&y!=="get"&&y!=="head"&&(H=await p(j,x))!==0){let Q=new n(g,{method:"POST",body:x,duplex:"half"}),ye;if(M.isFormData(x)&&(ye=Q.headers.get("content-type"))&&j.setContentType(ye),Q.body){const[Pe,Z]=yc(H,rs(xc(S)));x=Sc(Q.body,Cc,Pe,Z)}}M.isString(_)||(_=_?"include":"omit");const R=s&&"credentials"in n.prototype,V={...P,signal:z,method:y.toUpperCase(),headers:j.normalize().toJSON(),body:x,duplex:"half",credentials:R?_:void 0};B=s&&new n(g,V);let $=await(s?D(B,P):D(g,V));const F=d&&(E==="stream"||E==="response");if(d&&(k||F&&O)){const Q={};["status","statusText","headers"].forEach(ue=>{Q[ue]=$[ue]});const ye=M.toFiniteNumber($.headers.get("content-length")),[Pe,Z]=k&&yc(ye,rs(xc(k),!0))||[];$=new r(Sc($.body,Cc,Pe,()=>{Z&&Z(),O&&O()}),Q)}E=E||"text";let ne=await f[M.findKey(f,E)||"text"]($,m);return!F&&O&&O(),await new Promise((Q,ye)=>{gc(Q,ye,{data:ne,headers:ln.from($.headers),status:$.status,statusText:$.statusText,config:m,request:B})})}catch(R){throw O&&O(),R&&R.name==="TypeError"&&/Load failed|fetch/i.test(R.message)?Object.assign(new Le("Network Error",Le.ERR_NETWORK,m,B),{cause:R.cause||R}):Le.from(R,R&&R.code,m,B)}}},xy=new Map,Ic=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=xy;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:yy(t)),d=c;return c};Ic();const Ui={http:zg,xhr:dy,fetch:{get:Ic}};M.forEach(Ui,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Nc=e=>`- ${e}`,vy=e=>M.isFunction(e)||e===null||e===!1,Ac={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,!vy(r)&&(o=Ui[(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 :
30
+ <%s key={someKey} {...props} />`,$n,hn,Z,hn),Dt[hn+$n]=!0}}return N===r?Ln(Ct):xt(Ct),Ct}}function io(N,Y,ae){return fn(N,Y,ae,!0)}function ao(N,Y,ae){return fn(N,Y,ae,!1)}var Lr=ao,Fr=io;uo.Fragment=r,uo.jsx=Lr,uo.jsxs=Fr}()),uo}process.env.NODE_ENV==="production"?Oi.exports=eg():Oi.exports=tg();var u=Oi.exports;function Yl(e,t){return function(){return e.apply(t,arguments)}}const{toString:ng}=Object.prototype,{getPrototypeOf:Mi}=Object,{iterator:Xo,toStringTag:Xl}=Symbol,Jo=(e=>t=>{const n=ng.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),_n=e=>(e=e.toLowerCase(),t=>Jo(t)===e),Zo=e=>t=>typeof t===e,{isArray:Br}=Array,Hr=Zo("undefined");function fo(e){return e!==null&&!Hr(e)&&e.constructor!==null&&!Hr(e.constructor)&&an(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Jl=_n("ArrayBuffer");function rg(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Jl(e.buffer),t}const og=Zo("string"),an=Zo("function"),Zl=Zo("number"),ho=e=>e!==null&&typeof e=="object",sg=e=>e===!0||e===!1,Qo=e=>{if(Jo(e)!=="object")return!1;const t=Mi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xl in e)&&!(Xo in e)},ig=e=>{if(!ho(e)||fo(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},ag=_n("Date"),lg=_n("File"),cg=_n("Blob"),ug=_n("FileList"),dg=e=>ho(e)&&an(e.pipe),fg=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||an(e.append)&&((t=Jo(e))==="formdata"||t==="object"&&an(e.toString)&&e.toString()==="[object FormData]"))},hg=_n("URLSearchParams"),[pg,mg,gg,yg]=["ReadableStream","Request","Response","Headers"].map(_n),xg=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function po(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Br(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(fo(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 Ql(e,t){if(fo(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 wr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,ec=e=>!Hr(e)&&e!==wr;function Di(){const{caseless:e,skipUndefined:t}=ec(this)&&this||{},n={},r=(o,s)=>{const i=e&&Ql(n,s)||s;Qo(n[i])&&Qo(o)?n[i]=Di(n[i],o):Qo(o)?n[i]=Di({},o):Br(o)?n[i]=o.slice():(!t||!Hr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&po(arguments[o],r);return n}const vg=(e,t,n,{allOwnKeys:r}={})=>(po(t,(o,s)=>{n&&an(o)?e[s]=Yl(o,n):e[s]=o},{allOwnKeys:r}),e),wg=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),bg=(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)},Sg=(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&&Mi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Cg=(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},kg=e=>{if(!e)return null;if(Br(e))return e;let t=e.length;if(!Zl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Tg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Mi(Uint8Array)),Eg=(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])}},Ig=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Ng=_n("HTMLFormElement"),Ag=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tc=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),_g=_n("RegExp"),nc=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};po(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},jg=e=>{nc(e,(t,n)=>{if(an(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(an(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+"'")})}})},Pg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Br(e)?r(e):r(String(e).split(t)),n},Rg=()=>{},Og=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Mg(e){return!!(e&&an(e.append)&&e[Xl]==="FormData"&&e[Xo])}const Dg=e=>{const t=new Array(10),n=(r,o)=>{if(ho(r)){if(t.indexOf(r)>=0)return;if(fo(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Br(r)?[]:{};return po(r,(i,a)=>{const l=n(i,o+1);!Hr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Lg=_n("AsyncFunction"),Fg=e=>e&&(ho(e)||an(e))&&an(e.then)&&an(e.catch),rc=((e,t)=>e?setImmediate:t?((n,r)=>(wr.addEventListener("message",({source:o,data:s})=>{o===wr&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),wr.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",an(wr.postMessage)),$g=typeof queueMicrotask<"u"?queueMicrotask.bind(wr):typeof process<"u"&&process.nextTick||rc,M={isArray:Br,isArrayBuffer:Jl,isBuffer:fo,isFormData:fg,isArrayBufferView:rg,isString:og,isNumber:Zl,isBoolean:sg,isObject:ho,isPlainObject:Qo,isEmptyObject:ig,isReadableStream:pg,isRequest:mg,isResponse:gg,isHeaders:yg,isUndefined:Hr,isDate:ag,isFile:lg,isBlob:cg,isRegExp:_g,isFunction:an,isStream:dg,isURLSearchParams:hg,isTypedArray:Tg,isFileList:ug,forEach:po,merge:Di,extend:vg,trim:xg,stripBOM:wg,inherits:bg,toFlatObject:Sg,kindOf:Jo,kindOfTest:_n,endsWith:Cg,toArray:kg,forEachEntry:Eg,matchAll:Ig,isHTMLForm:Ng,hasOwnProperty:tc,hasOwnProp:tc,reduceDescriptors:nc,freezeMethods:jg,toObjectSet:Pg,toCamelCase:Ag,noop:Rg,toFiniteNumber:Og,findKey:Ql,global:wr,isContextDefined:ec,isSpecCompliantForm:Mg,toJSONObject:Dg,isAsyncFn:Lg,isThenable:Fg,setImmediate:rc,asap:$g,isIterable:e=>e!=null&&an(e[Xo])};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 oc=Fe.prototype,sc={};["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=>{sc[e]={value:e}}),Object.defineProperties(Fe,sc),Object.defineProperty(oc,"isAxiosError",{value:!0}),Fe.from=(e,t,n,r,o,s)=>{const i=Object.create(oc);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 zg=null;function Li(e){return M.isPlainObject(e)||M.isArray(e)}function ic(e){return M.endsWith(e,"[]")?e.slice(0,-2):e}function ac(e,t,n){return e?e.concat(t).map(function(o,s){return o=ic(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Bg(e){return M.isArray(e)&&!e.some(Li)}const Hg=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(g,y){return!M.isUndefined(y[g])});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(m){if(m===null)return"";if(M.isDate(m))return m.toISOString();if(M.isBoolean(m))return m.toString();if(!l&&M.isBlob(m))throw new Fe("Blob is not supported. Use a Buffer instead.");return M.isArrayBuffer(m)||M.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function d(m,g,y){let x=m;if(m&&!y&&typeof m=="object"){if(M.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(M.isArray(m)&&Bg(m)||(M.isFileList(m)||M.endsWith(g,"[]"))&&(x=M.toArray(m)))return g=ic(g),x.forEach(function(C,T){!(M.isUndefined(C)||C===null)&&t.append(i===!0?ac([g],T,s):i===null?g:g+"[]",c(C))}),!1}return Li(m)?!0:(t.append(ac(y,g,s),c(m)),!1)}const f=[],h=Object.assign(Hg,{defaultVisitor:d,convertValue:c,isVisitable:Li});function p(m,g){if(!M.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),M.forEach(m,function(x,w){(!(M.isUndefined(x)||x===null)&&o.call(t,x,M.isString(w)?w.trim():w,g,h))===!0&&p(x,g?g.concat(w):[w])}),f.pop()}}if(!M.isObject(e))throw new TypeError("data must be an object");return p(e),t}function lc(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Fi(e,t){this._pairs=[],e&&es(e,this,t)}const cc=Fi.prototype;cc.append=function(t,n){this._pairs.push([t,n])},cc.toString=function(t){const n=t?function(r){return t.call(this,r,lc)}:lc;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Ug(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function uc(e,t,n){if(!t)return e;const r=n&&n.encode||Ug;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 Fi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dc{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 fc={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Wg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Fi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},$i=typeof window<"u"&&typeof document<"u",zi=typeof navigator=="object"&&navigator||void 0,Vg=$i&&(!zi||["ReactNative","NativeScript","NS"].indexOf(zi.product)<0),Kg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",qg=$i&&window.location.href||"http://localhost",Qt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:$i,hasStandardBrowserEnv:Vg,hasStandardBrowserWebWorkerEnv:Kg,navigator:zi,origin:qg},Symbol.toStringTag,{value:"Module"})),...Wg};function Gg(e,t){return es(e,new Qt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Qt.isNode&&M.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Yg(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Xg(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 hc(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]=Xg(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t(Yg(r),o,n,0)}),n}return null}function Jg(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 mo={transitional:fc,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(hc(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 Gg(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),Jg(t)):t}],transformResponse:[function(t){const n=this.transitional||mo.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:Qt.classes.FormData,Blob:Qt.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=>{mo.headers[e]={}});const Zg=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"]),Qg=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]&&Zg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},pc=Symbol("internals");function go(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 ey(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 ty=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Bi(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 ny(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function ry(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 ln=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=go(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())&&!ty(t))i(Qg(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=go(t),t){const r=M.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return ey(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=go(t),t){const r=M.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Bi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=go(i),i){const a=M.findKey(r,i);a&&(!n||Bi(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||Bi(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?ny(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[pc]=this[pc]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=go(i);r[a]||(ry(o,i),r[a]=!0)}return M.isArray(t)?t.forEach(s):s(t),this}};ln.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),M.reduceDescriptors(ln.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),M.freezeMethods(ln);function Hi(e,t){const n=this||mo,r=t||n,o=ln.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 mc(e){return!!(e&&e.__CANCEL__)}function Ur(e,t,n){Fe.call(this,e??"canceled",Fe.ERR_CANCELED,t,n),this.name="CanceledError"}M.inherits(Ur,Fe,{__CANCEL__:!0});function gc(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 oy(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function sy(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 iy(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=sy(50,250);return iy(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)},yc=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},xc=e=>(...t)=>M.asap(()=>e(...t)),ay=Qt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Qt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Qt.origin),Qt.navigator&&/(msie|trident)/i.test(Qt.navigator.userAgent)):()=>!0,ly=Qt.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 cy(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function uy(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function vc(e,t,n){let r=!cy(t);return e&&(r||n==!1)?uy(e,t):t}const wc=e=>e instanceof ln?{...e}:e;function br(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(wc(c),wc(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 bc=e=>{const t=br({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=ln.from(i),t.url=uc(vc(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(Qt.hasStandardBrowserEnv||Qt.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(Qt.hasStandardBrowserEnv&&(r&&M.isFunction(r)&&(r=r(t)),r||r!==!1&&ay(t.url))){const l=o&&s&&ly.read(s);l&&i.set(o,l)}return t},dy=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=bc(e);let s=o.data;const i=ln.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,m;function g(){p&&p(),m&&m(),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 x(){if(!y)return;const C=ln.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:C,config:e,request:y};gc(function(E){n(E),g()},function(E){r(E),g()},k),y=null}"onloadend"in y?y.onloadend=x:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(x)},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",S=new Fe(k,Fe.ERR_NETWORK,e,y);S.event=T||null,r(S),y=null},y.ontimeout=function(){let T=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||fc;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,m]=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=C=>{y&&(r(!C||C.type?new Ur(null,e,y):C),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const w=oy(o.url);if(w&&Qt.protocols.indexOf(w)===-1){r(new Fe("Unsupported protocol "+w+":",Fe.ERR_BAD_REQUEST,e));return}y.send(s||null)})},fy=(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 Ur(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}},hy=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},py=async function*(e,t){for await(const n of my(e))yield*hy(n,t)},my=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()}},Sc=(e,t,n,r)=>{const o=py(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})},Cc=64*1024,{isFunction:rs}=M,gy=(({Request:e,Response:t})=>({Request:e,Response:t}))(M.global),{ReadableStream:kc,TextEncoder:Tc}=M.global,Ec=(e,...t)=>{try{return!!e(...t)}catch{return!1}},yy=e=>{e=M.merge.call({skipUndefined:!0},gy,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(kc),l=o&&(typeof Tc=="function"?(m=>g=>m.encode(g))(new Tc):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Ec(()=>{let m=!1;const g=new n(Qt.origin,{body:new kc,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),d=i&&a&&Ec(()=>M.isReadableStream(new r("").body)),f={stream:d&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,y)=>{let x=g&&g[m];if(x)return x.call(g);throw new Fe(`Response type '${m}' is not supported`,Fe.ERR_NOT_SUPPORT,y)})});const h=async m=>{if(m==null)return 0;if(M.isBlob(m))return m.size;if(M.isSpecCompliantForm(m))return(await new n(Qt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(M.isArrayBufferView(m)||M.isArrayBuffer(m))return m.byteLength;if(M.isURLSearchParams(m)&&(m=m+""),M.isString(m))return(await l(m)).byteLength},p=async(m,g)=>{const y=M.toFiniteNumber(m.getContentLength());return y??h(g)};return async m=>{let{url:g,method:y,data:x,signal:w,cancelToken:C,timeout:T,onDownloadProgress:k,onUploadProgress:S,responseType:E,headers:j,withCredentials:_="same-origin",fetchOptions:P}=bc(m),D=t||fetch;E=E?(E+"").toLowerCase():"text";let z=fy([w,C&&C.toAbortSignal()],T),B=null;const O=z&&z.unsubscribe&&(()=>{z.unsubscribe()});let H;try{if(S&&c&&y!=="get"&&y!=="head"&&(H=await p(j,x))!==0){let Q=new n(g,{method:"POST",body:x,duplex:"half"}),ye;if(M.isFormData(x)&&(ye=Q.headers.get("content-type"))&&j.setContentType(ye),Q.body){const[je,J]=yc(H,ns(xc(S)));x=Sc(Q.body,Cc,je,J)}}M.isString(_)||(_=_?"include":"omit");const R=s&&"credentials"in n.prototype,V={...P,signal:z,method:y.toUpperCase(),headers:j.normalize().toJSON(),body:x,duplex:"half",credentials:R?_:void 0};B=s&&new n(g,V);let $=await(s?D(B,P):D(g,V));const F=d&&(E==="stream"||E==="response");if(d&&(k||F&&O)){const Q={};["status","statusText","headers"].forEach(ue=>{Q[ue]=$[ue]});const ye=M.toFiniteNumber($.headers.get("content-length")),[je,J]=k&&yc(ye,ns(xc(k),!0))||[];$=new r(Sc($.body,Cc,je,()=>{J&&J(),O&&O()}),Q)}E=E||"text";let ne=await f[M.findKey(f,E)||"text"]($,m);return!F&&O&&O(),await new Promise((Q,ye)=>{gc(Q,ye,{data:ne,headers:ln.from($.headers),status:$.status,statusText:$.statusText,config:m,request:B})})}catch(R){throw O&&O(),R&&R.name==="TypeError"&&/Load failed|fetch/i.test(R.message)?Object.assign(new Fe("Network Error",Fe.ERR_NETWORK,m,B),{cause:R.cause||R}):Fe.from(R,R&&R.code,m,B)}}},xy=new Map,Ic=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=xy;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:yy(t)),d=c;return c};Ic();const Ui={http:zg,xhr:dy,fetch:{get:Ic}};M.forEach(Ui,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Nc=e=>`- ${e}`,vy=e=>M.isFunction(e)||e===null||e===!1,Ac={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,!vy(r)&&(o=Ui[(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
33
  `+i.map(Nc).join(`
34
- `):" "+Nc(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:Ui};function Wi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Wr(null,e)}function _c(e){return Wi(e),e.headers=ln.from(e.headers),e.data=Hi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ac.getAdapter(e.adapter||mo.adapter,e)(e).then(function(r){return Wi(e),r.data=Hi.call(e,e.transformResponse,r),r.headers=ln.from(r.headers),r},function(r){return mc(r)||(Wi(e),r&&r.response&&(r.response.data=Hi.call(e,e.transformResponse,r.response),r.response.headers=ln.from(r.response.headers))),Promise.reject(r)})}const jc="1.12.2",ss={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ss[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Pc={};ss.transitional=function(t,n,r){function o(s,i){return"[Axios v"+jc+"] 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&&!Pc[i]&&(Pc[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}},ss.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function wy(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 is={assertOptions:wy,validators:ss},Ln=is.validators;let Cr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new dc,response:new dc}}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=Sr(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&is.assertOptions(r,{silentJSONParsing:Ln.transitional(Ln.boolean),forcedJSONParsing:Ln.transitional(Ln.boolean),clarifyTimeoutError:Ln.transitional(Ln.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:is.assertOptions(o,{encode:Ln.function,serialize:Ln.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),is.assertOptions(n,{baseUrl:Ln.spelling("baseURL"),withXsrfToken:Ln.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"],m=>{delete s[m]}),n.headers=ln.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,h;if(!l){const m=[_c.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,d=Promise.resolve(n);f<h;)d=d.then(m[f++],m[f++]);return d}h=a.length;let p=n;for(;f<h;){const m=a[f++],g=a[f++];try{p=m(p)}catch(y){g.call(this,y);break}}try{d=_c.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Sr(this.defaults,t);const n=vc(t.baseURL,t.url,t.allowAbsoluteUrls);return uc(n,t.params,t.paramsSerializer)}};M.forEach(["delete","get","head","options"],function(t){Cr.prototype[t]=function(n,r){return this.request(Sr(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(Sr(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Cr.prototype[t]=n(),Cr.prototype[t+"Form"]=n(!0)});let by=class Jm{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new Wr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Jm(function(o){t=o}),cancel:t}}};function Sy(e){return function(n){return e.apply(null,n)}}function Cy(e){return M.isObject(e)&&e.isAxiosError===!0}const Vi={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(Vi).forEach(([e,t])=>{Vi[t]=e});function Rc(e){const t=new Cr(e),n=Yl(Cr.prototype.request,t);return M.extend(n,Cr.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Rc(Sr(e,o))},n}const Rt=Rc(mo);Rt.Axios=Cr,Rt.CanceledError=Wr,Rt.CancelToken=by,Rt.isCancel=mc,Rt.VERSION=jc,Rt.toFormData=ts,Rt.AxiosError=Le,Rt.Cancel=Rt.CanceledError,Rt.all=function(t){return Promise.all(t)},Rt.spread=Sy,Rt.isAxiosError=Cy,Rt.mergeConfig=Sr,Rt.AxiosHeaders=ln,Rt.formToJSON=e=>hc(M.isHTMLForm(e)?new FormData(e):e),Rt.getAdapter=Ac.getAdapter,Rt.HttpStatusCode=Vi,Rt.default=Rt;const{Axios:ET,AxiosError:IT,CanceledError:NT,isCancel:AT,CancelToken:_T,VERSION:jT,all:PT,Cancel:RT,isAxiosError:OT,spread:MT,toFormData:DT,AxiosHeaders:LT,HttpStatusCode:FT,formToJSON:$T,getAdapter:zT,mergeConfig:BT}=Rt,Oc=typeof window<"u"?window.__API_BASE_URL__:void 0,Mc=Oc?Jn(Oc):void 0;function Jn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let as=null;const Ki=new Set;let qi=null;function Dc(){return as}function Gi(e){as=e,Ki.forEach(t=>t(e))}function Lc(e){return Ki.add(e),()=>Ki.delete(e)}function ky(e){qi=e}const Ty=3e4,Ey=9e4,xn=Rt.create({...Mc?{baseURL:Mc}:{},timeout:Ty,withCredentials:!0});xn.interceptors.request.use(e=>(as&&(e.headers.Authorization=`Bearer ${as}`),e)),xn.interceptors.response.use(e=>{if(qi&&(e!=null&&e.data))try{qi(e.data)}catch(t){console.warn("[chat-api] Error in token sync handler:",t)}return e},e=>Promise.reject(e));const ls=new Map;async function vn(e,t){if(!xn.defaults.baseURL)return Promise.reject(new Error("API base URL is not configured"));const n=`GET:${e}`,r=ls.get(n);if(r)return r;const o=xn.get(e,t).then(s=>(ls.delete(n),s.data)).catch(s=>{throw ls.delete(n),s});return ls.set(n,o),o}async function Yi(e,t,n){return xn.defaults.baseURL?(await xn.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fc(e,t,n){return xn.defaults.baseURL?(await xn.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $c(e,t){return xn.defaults.baseURL?(await xn.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function wn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class zc{get baseUrl(){const t=xn.defaults.baseURL;return t?Jn(String(t)):""}updateConfig(t){t.baseUrl&&(xn.defaults.baseURL=Jn(String(t.baseUrl))),t.authToken!==void 0&&Gi(t.authToken)}getAuthToken(){return Dc()}setAuthToken(t){Gi(t)}onTokenChange(t){return Lc(t)}async listThreads(){const t=await vn("/threads"),n=wn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Yi("/threads",t?{title:t}:void 0);return wn(r)}async updateThread(t,n){const r=await Fc(`/threads/${t}`,{title:n});return wn(r)}async deleteThread(t){const n=await $c(`/threads/${t}`);return wn(n)}async threadInfo(t){const n=await vn(`/threads/${t}/info`);return wn(n)}async listAgents(){const t=await vn("/agents"),n=wn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await vn(`/agents/${t}`);return wn(n)}async getAgentSchema(t){const n=await vn(`/agents/${t}/schema`);return wn(n)}async getState(t){const n=await vn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return wn(n)}async getStateHistory(t){const n=await vn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Ey});return wn(n)}async cancelRun(t){const n=await Yi("/runs/cancel",{threadId:t});return wn(n)}async listCheckpointSummaries(t){const n=await vn(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=wn(n);return(r==null?void 0:r.items)??[]}}const sr=new zc,Bc=b.createContext(null);function Iy({children:e,apiConfig:t}){const n=sr;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(Bc.Provider,{value:r,children:e})}function Xi(){const e=b.useContext(Bc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Ny(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 Ay(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Ny(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const _y={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Ji(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 Vr(e,t){return`${e??""}::${t??""}`}function cs(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(!Ji(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Py(t),i=Hc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Hc(e,t){if(!Ji(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((_,P)=>$y(_,P)).filter(_=>!!_),d=cn(e.config),f=cn(d==null?void 0:d.configurable),h=Ft(f,["checkpoint_id","checkpointId"]),p=Ft(f,["checkpoint_ns","checkpointNs"]),m=cn(e==null?void 0:e.parentConfig),g=cn(m==null?void 0:m.configurable),y=Ft(g,["checkpoint_id","checkpointId"])??null,x=Ft(g,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,C=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),T=c[c.length-1]??null,k=cn(e==null?void 0:e.metadata),S=Ft(k,["branch_label","branchLabel"]),E=Ft(g,["checkpoint_id","checkpointId"]),j=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:x,interrupt:jy(a,c,t),createdAt:C,parentId:E??null,branchLabel:S??null,lastMessageId:(T==null?void 0:T.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:k??null,config:d??null,parentConfig:m??null,next:j??null,tasks:l??null,values:i??null}}function jy(e,t,n){const r=Ly(e,n);return r||Dy(t,n)}function Py(e){const t=new Map;e.forEach((o,s)=>{if(!Ji(o))return;const i=Hc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Vr(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ry(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Wc(s.createdAt??"")-Wc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Ry(e,t){return{...e,metadata:us(e.metadata,t.metadata)??null,config:us(e.config,t.config)??null,parentConfig:us(e.parentConfig,t.parentConfig)??null,next:Oy(e.next,t.next)??null,tasks:My(e.tasks,t.tasks)??null,values:us(e.values,t.values)??null}}function us(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 Oy(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 My(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 Dy(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 Ly(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Fy(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=yo(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=yo(r.state,`${o}-state`);if(s)return s}}return null}function Fy(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,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=h.length?h[h.length-1]:void 0;return{id:p,name:m,interrupts:g,state:y!==void 0?y:f}}const n=cn(e);if(!n)return null;const r=Ft(n,["id","task_id","taskId"])??t,o=Ft(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function yo(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=Uc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=yo(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=yo(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=yo(l,t,n+1,r);if(c)return c}}return null}function Uc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=Ft(n,["type","event","kind"]),o=Ft(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Uc(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 Wc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function $y(e,t){if(!e||typeof e!="object")return null;const n=e,r=cn(e)??{},o=cn(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=_y[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=cn(o.additional_kwargs)??cn(o.additionalKwargs),d=cn(o.response_metadata)??cn(o.responseMetadata),f=Ft(c,["createdAt","created_at"])??Ft(o,["created_at","createdAt"]),h=Ft(c,["checkpointId","checkpoint_id"]),p=Ft(c,["checkpointNs","checkpoint_ns"]),m=zy(o.content),g={id:l,role:i,content:m};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),h&&(g.checkpointId=h),p&&(g.checkpointNs=p);const y=Wy(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),x=d?{...d}:void 0;y&&Object.keys(y).length&&(g.additionalKwargs=y),x&&Object.keys(x).length&&(g.responseMetadata=x);const w=By((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(g.content=[...g.content,...w]),i==="tool"){const C=Hy(o,g.content);C&&(g.content=C)}return g}function zy(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Vc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Vc(e);return t?[t]:[]}return[]}function Vc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=Ft(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=Ft(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Kc(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=Ft(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Kc(e,t){var s;const n=Ft(e,["id","call_id"])??t,r=Ft(e,["name"])??Ft(cn(e.function),["name"]);if(!n||!r)return null;const o=Uy(e.args??e.arguments??((s=cn(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function By(e){return Array.isArray(e)?e.map((t,n)=>Kc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Hy(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 Uy(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 cn(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Ft(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Wy(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 Vy(e){return e.type!=="thread_info"&&e.type!=="token"}const Ky={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function qy(e,t){var n;switch(t.type){case"reset":return{messages:Zi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=Zi(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=Zi(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 Gc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Gc(o,s),e):e}case"interrupt_response":return{...e,messages:Yc(e.messages),pendingInterrupt:null};default:return e}}function qc(e=[]){const[t,n]=b.useReducer(qy,{...Ky,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.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=b.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=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.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 Gc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Jy(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??Xc(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:Qc(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:m,newMeta:g,changed:y}=Gy(d.content,t.delta,h,p);if(!y)return e;const x={...d,content:m},w=ds(l,c,x),C={...f,[a]:g};return{...e,messages:w,messagesStreamMeta:C}}if(t.type==="message_end"){const a=e.assemblingId??Xc(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=Jc(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=Zc(e,d,c),h=f>=0?e.messages[f]:null,p=l??d[0]??`${c}-${Date.now()}`,m=(h==null?void 0:h.id)??`tool-${p}`,g=d[0]??p,y={type:"tool_call",id:g,name:c,args:t.args};if(h){const C=ea(h,d,c,t.args),T={...h,name:h.name??c,additionalKwargs:C},k=f,S=k>=0?ds(e.messages,k,T):e.messages,E=fs(T,d),j=ta(e.toolIndex,m,E);return{...e,messages:S,toolIndex:j}}const x={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:ea(void 0,d.length?d:[g],c,t.args)},w=fs(x,d.length?d:[g]);return{...e,messages:[...e.messages,x],toolIndex:ta(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=Jc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=Zc(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}`,m=fs(d,a);let g=t.output;if(typeof t.output=="string")try{const S=t.output.trim();(S.startsWith("{")||S.startsWith("["))&&(g=JSON.parse(S))}catch{g=t.output}const y={type:"text",text:typeof g=="string"?g:JSON.stringify(g)},x=(d==null?void 0:d.createdAt)??new Date().toISOString(),w=ea(d??void 0,m.length?m:a,f),C={id:p,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[y],createdAt:x,additionalKwargs:w},T=c>=0?ds(e.messages,c,C):[...e.messages,C],k=fs(C,a.length?a:m);return{...e,messages:T,toolIndex:ta(e.toolIndex,p,k)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Xy(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=cs(t),l=a.interrupt,c=a.latest,d=l===null?Yc(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 Zi(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 ds(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Yc(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 Xc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Jc(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 Qi(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 ea(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=Qi(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 fs(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Qi(e);for(const o of r)n.add(o);return Array.from(n)}function ta(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 Zc(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(Qi(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 Qc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Gy(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??Qc(e);let l="",c=e.slice();if(s){const f=Yy(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??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}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 eu(e){return e.replace(/\s+/g," ").trim()}function Yy(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=eu(e),o=eu(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 Xy(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 ds(e,r,s)}return e}function Jy(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function tu(e={}){const t=b.useMemo(()=>Jn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[f,h]=b.useState(""),[p,m]=b.useState(null),[g,y]=b.useState(0),[x,w]=b.useState(!1),C=b.useRef(null),T=b.useRef(!0),k=b.useRef(0),S=b.useRef(null),E=b.useRef(null),j=b.useRef(null),_=b.useRef(null),P=b.useCallback(O=>{o(O)},[]),D=b.useCallback(()=>{h(""),m(null),d(null),E.current=null,j.current=null,_.current=null},[]),z=b.useCallback(()=>{var O;console.debug("[use-chat] stop() invoked - aborting stream"),(O=C.current)==null||O.abort(),C.current=null,S.current=null,l(!1),w(!1),k.current=0,y(0)},[]),B=b.useCallback((O,H,R)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),m(null),E.current=null,j.current=null,_.current=null;const V=new AbortController;C.current=V;let $=null,F=null,ne=!1;return S.current={threadId:O.threadId??null,headers:{}},(async()=>{var ye,Pe,Z,ue,ke,te,L,G,se,le,U,We,re,xe,Re,Fe,tt,Se;const Q=Ge=>{var nt;try{const Qe=JSON.parse(JSON.stringify(Ge));return(nt=Qe==null?void 0:Qe.payload)!=null&&nt.files_info&&Array.isArray(Qe.payload.files_info)&&(Qe.payload.files_info=Qe.payload.files_info.map(Ye=>({...Ye,data:Ye!=null&&Ye.data?`<base64 ${String(Ye.data).length} chars>`:Ye==null?void 0:Ye.data}))),Qe}catch{return Ge}};try{let Ge={};try{if(r)Ge={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ve=window.__AUTH_TOKEN__,Dt=((ye=window.localStorage)==null?void 0:ye.getItem("authToken"))||null;let _t=null;try{const Ie=(Pe=window.localStorage)==null?void 0:Pe.getItem("chat-settings");Ie&&(_t=((Z=JSON.parse(Ie))==null?void 0:Z.apiKey)||null)}catch{}const Y=Ve||Dt||_t||null;Y&&(Ge={Authorization:`Bearer ${Y}`})}}catch{}console.debug("[use-chat] POST",t+n,Q(O));let nt={};if(typeof window<"u")try{const ht=(ue=window.localStorage)==null?void 0:ue.getItem("authSessionId");ht&&(nt={"X-Session-Id":ht})}catch{}const Qe={...Ge,...nt,...s.current},Ye={"Content-Type":"application/json",Accept:"text/event-stream",...Qe},qe=await fetch(t+n,{method:"POST",headers:Ye,body:JSON.stringify(O),signal:V.signal,credentials:i});if(S.current&&(S.current.headers=Qe),!qe.ok||!qe.body){const ht=await qe.text().catch(()=>"");console.debug("[use-chat] non-OK response",qe.status,ht==null?void 0:ht.slice(0,500));const Ve=`stream ${qe.status}${ht?": "+ht:""}`;throw(ke=R==null?void 0:R.onConnectionError)==null||ke.call(R,Ve),ne=!0,$="error",F=Ve,new Error(Ve)}w(!0);const et=qe.body.getReader(),Mt=new TextDecoder;let Ct="",dt=[];k.current=0,y(0);let xt=0,ft=null;const rt=()=>{if(dt.length){const ht=dt.join("");dt=[],T.current&&h(Ve=>Ve+ht)}ft=null},rn=()=>{typeof window<"u"&&ft==null&&(ft=requestAnimationFrame(rt))};let on=Date.now();const Wt=setInterval(()=>{var ht;if(Date.now()-on>18e5){const Ve="Stream idle timeout";d(Ve),$="error",F=Ve,V.abort(),(ht=R==null?void 0:R.onError)==null||ht.call(R,Ve)}},5e3),zt=1024*1024;try{const ht=qe.headers.get("X-Thread-Id")||qe.headers.get("x-thread-id"),Ve=qe.headers.get("X-Thread-Created")||qe.headers.get("x-thread-created"),Dt=ht??null,_t=String(Ve??"").toLowerCase()==="true";for(S.current&&!S.current.threadId&&(S.current={...S.current,threadId:Dt}),(te=R==null?void 0:R.onOpen)==null||te.call(R,{threadId:Dt,created:_t});;){const{value:Y,done:Ie}=await et.read();if(Ie)break;Ct+=Mt.decode(Y,{stream:!0}),Ct.length>zt&&(Ct="",console.warn("Stream buffer reset: exceeded 1MB"));let ve;for(;(ve=Ct.indexOf(`
34
+ `):" "+Nc(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:Ui};function Wi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Ur(null,e)}function _c(e){return Wi(e),e.headers=ln.from(e.headers),e.data=Hi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ac.getAdapter(e.adapter||mo.adapter,e)(e).then(function(r){return Wi(e),r.data=Hi.call(e,e.transformResponse,r),r.headers=ln.from(r.headers),r},function(r){return mc(r)||(Wi(e),r&&r.response&&(r.response.data=Hi.call(e,e.transformResponse,r.response),r.response.headers=ln.from(r.response.headers))),Promise.reject(r)})}const jc="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 Pc={};os.transitional=function(t,n,r){function o(s,i){return"[Axios v"+jc+"] 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&&!Pc[i]&&(Pc[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 wy(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 ss={assertOptions:wy,validators:os},zn=ss.validators;let Sr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new dc,response:new dc}}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=br(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ss.assertOptions(r,{silentJSONParsing:zn.transitional(zn.boolean),forcedJSONParsing:zn.transitional(zn.boolean),clarifyTimeoutError:zn.transitional(zn.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:ss.assertOptions(o,{encode:zn.function,serialize:zn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ss.assertOptions(n,{baseUrl:zn.spelling("baseURL"),withXsrfToken:zn.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"],m=>{delete s[m]}),n.headers=ln.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,h;if(!l){const m=[_c.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,d=Promise.resolve(n);f<h;)d=d.then(m[f++],m[f++]);return d}h=a.length;let p=n;for(;f<h;){const m=a[f++],g=a[f++];try{p=m(p)}catch(y){g.call(this,y);break}}try{d=_c.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=br(this.defaults,t);const n=vc(t.baseURL,t.url,t.allowAbsoluteUrls);return uc(n,t.params,t.paramsSerializer)}};M.forEach(["delete","get","head","options"],function(t){Sr.prototype[t]=function(n,r){return this.request(br(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(br(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Sr.prototype[t]=n(),Sr.prototype[t+"Form"]=n(!0)});let by=class Jm{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new Ur(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Jm(function(o){t=o}),cancel:t}}};function Sy(e){return function(n){return e.apply(null,n)}}function Cy(e){return M.isObject(e)&&e.isAxiosError===!0}const Vi={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(Vi).forEach(([e,t])=>{Vi[t]=e});function Rc(e){const t=new Sr(e),n=Yl(Sr.prototype.request,t);return M.extend(n,Sr.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Rc(br(e,o))},n}const Pt=Rc(mo);Pt.Axios=Sr,Pt.CanceledError=Ur,Pt.CancelToken=by,Pt.isCancel=mc,Pt.VERSION=jc,Pt.toFormData=es,Pt.AxiosError=Fe,Pt.Cancel=Pt.CanceledError,Pt.all=function(t){return Promise.all(t)},Pt.spread=Sy,Pt.isAxiosError=Cy,Pt.mergeConfig=br,Pt.AxiosHeaders=ln,Pt.formToJSON=e=>hc(M.isHTMLForm(e)?new FormData(e):e),Pt.getAdapter=Ac.getAdapter,Pt.HttpStatusCode=Vi,Pt.default=Pt;const{Axios:NT,AxiosError:AT,CanceledError:_T,isCancel:jT,CancelToken:PT,VERSION:RT,all:OT,Cancel:MT,isAxiosError:DT,spread:LT,toFormData:FT,AxiosHeaders:$T,HttpStatusCode:zT,formToJSON:BT,getAdapter:HT,mergeConfig:UT}=Pt,Oc=typeof window<"u"?window.__API_BASE_URL__:void 0,Mc=Oc?Zn(Oc):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 is=null;const Ki=new Set;let qi=null;function Dc(){return is}function Gi(e){is=e,Ki.forEach(t=>t(e))}function Lc(e){return Ki.add(e),()=>Ki.delete(e)}function ky(e){qi=e}const Ty=3e4,Ey=9e4,vn=Pt.create({...Mc?{baseURL:Mc}:{},timeout:Ty,withCredentials:!0});vn.interceptors.request.use(e=>(is&&(e.headers.Authorization=`Bearer ${is}`),e)),vn.interceptors.response.use(e=>{if(qi&&(e!=null&&e.data))try{qi(e.data)}catch(t){console.warn("[chat-api] Error in token sync handler:",t)}return e},e=>Promise.reject(e));const as=new Map,Fc=new Map,Iy=5e3;function Ny(e,t){const n=t==null?void 0:t.params,r=n?JSON.stringify(n):"";return`GET:${e}:${r}`}async function wn(e,t){if(!vn.defaults.baseURL)return Promise.reject(new Error("API base URL is not configured"));const n=Ny(e,t),r=Fc.get(n);if(r&&Date.now()-r.timestamp<Iy)return r.data;const o=as.get(n);if(o)return o;const s=vn.get(e,t).then(i=>(as.delete(n),Fc.set(n,{data:i.data,timestamp:Date.now()}),i.data)).catch(i=>{throw as.delete(n),i});return as.set(n,s),s}async function Yi(e,t,n){return vn.defaults.baseURL?(await vn.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $c(e,t,n){return vn.defaults.baseURL?(await vn.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function zc(e,t){return vn.defaults.baseURL?(await vn.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function bn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Bc{get baseUrl(){const t=vn.defaults.baseURL;return t?Zn(String(t)):""}updateConfig(t){t.baseUrl&&(vn.defaults.baseURL=Zn(String(t.baseUrl))),t.authToken!==void 0&&Gi(t.authToken)}getAuthToken(){return Dc()}setAuthToken(t){Gi(t)}onTokenChange(t){return Lc(t)}async listThreads(){const t=await wn("/threads"),n=bn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Yi("/threads",t?{title:t}:void 0);return bn(r)}async updateThread(t,n){const r=await $c(`/threads/${t}`,{title:n});return bn(r)}async deleteThread(t){const n=await zc(`/threads/${t}`);return bn(n)}async threadInfo(t){const n=await wn(`/threads/${t}/info`);return bn(n)}async listAgents(){const t=await wn("/agents"),n=bn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await wn(`/agents/${t}`);return bn(n)}async getAgentSchema(t){const n=await wn(`/agents/${t}/schema`);return bn(n)}async getState(t){const n=await wn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return bn(n)}async getStateHistory(t){const n=await wn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Ey});return bn(n)}async cancelRun(t){const n=await Yi("/runs/cancel",{threadId:t});return bn(n)}async listCheckpointSummaries(t){const n=await wn(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=bn(n);return(r==null?void 0:r.items)??[]}}const sr=new Bc,Hc=b.createContext(null);function Ay({children:e,apiConfig:t}){const n=sr;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(Hc.Provider,{value:r,children:e})}function Xi(){const e=b.useContext(Hc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function _y(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 jy(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await _y(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Py={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Ji(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 Wr(e,t){return`${e??""}::${t??""}`}function ls(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(!Ji(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Oy(t),i=Uc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Uc(e,t){if(!Ji(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((_,P)=>By(_,P)).filter(_=>!!_),d=cn(e.config),f=cn(d==null?void 0:d.configurable),h=Lt(f,["checkpoint_id","checkpointId"]),p=Lt(f,["checkpoint_ns","checkpointNs"]),m=cn(e==null?void 0:e.parentConfig),g=cn(m==null?void 0:m.configurable),y=Lt(g,["checkpoint_id","checkpointId"])??null,x=Lt(g,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,C=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),T=c[c.length-1]??null,k=cn(e==null?void 0:e.metadata),S=Lt(k,["branch_label","branchLabel"]),E=Lt(g,["checkpoint_id","checkpointId"]),j=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:x,interrupt:Ry(a,c,t),createdAt:C,parentId:E??null,branchLabel:S??null,lastMessageId:(T==null?void 0:T.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:k??null,config:d??null,parentConfig:m??null,next:j??null,tasks:l??null,values:i??null}}function Ry(e,t,n){const r=$y(e,n);return r||Fy(t,n)}function Oy(e){const t=new Map;e.forEach((o,s)=>{if(!Ji(o))return;const i=Uc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Wr(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,My(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Vc(s.createdAt??"")-Vc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function My(e,t){return{...e,metadata:cs(e.metadata,t.metadata)??null,config:cs(e.config,t.config)??null,parentConfig:cs(e.parentConfig,t.parentConfig)??null,next:Dy(e.next,t.next)??null,tasks:Ly(e.tasks,t.tasks)??null,values:cs(e.values,t.values)??null}}function cs(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 Dy(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 Ly(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 Fy(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 $y(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=zy(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=yo(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=yo(r.state,`${o}-state`);if(s)return s}}return null}function zy(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,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=h.length?h[h.length-1]:void 0;return{id:p,name:m,interrupts:g,state:y!==void 0?y:f}}const n=cn(e);if(!n)return null;const r=Lt(n,["id","task_id","taskId"])??t,o=Lt(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 yo(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=Wc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=yo(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=yo(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=yo(l,t,n+1,r);if(c)return c}}return null}function Wc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=Lt(n,["type","event","kind"]),o=Lt(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=Wc(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 Vc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function By(e,t){if(!e||typeof e!="object")return null;const n=e,r=cn(e)??{},o=cn(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Py[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=cn(o.additional_kwargs)??cn(o.additionalKwargs),d=cn(o.response_metadata)??cn(o.responseMetadata),f=Lt(c,["createdAt","created_at"])??Lt(o,["created_at","createdAt"]),h=Lt(c,["checkpointId","checkpoint_id"]),p=Lt(c,["checkpointNs","checkpoint_ns"]),m=Hy(o.content),g={id:l,role:i,content:m};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),h&&(g.checkpointId=h),p&&(g.checkpointNs=p);const y=Ky(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),x=d?{...d}:void 0;y&&Object.keys(y).length&&(g.additionalKwargs=y),x&&Object.keys(x).length&&(g.responseMetadata=x);const w=Uy((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(g.content=[...g.content,...w]),i==="tool"){const C=Wy(o,g.content);C&&(g.content=C)}return g}function Hy(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Kc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Kc(e);return t?[t]:[]}return[]}function Kc(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=Lt(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=Lt(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 qc(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=Lt(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 qc(e,t){var s;const n=Lt(e,["id","call_id"])??t,r=Lt(e,["name"])??Lt(cn(e.function),["name"]);if(!n||!r)return null;const o=Vy(e.args??e.arguments??((s=cn(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Uy(e){return Array.isArray(e)?e.map((t,n)=>qc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Wy(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 Vy(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 cn(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Lt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Ky(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 qy(e){return e.type!=="thread_info"&&e.type!=="token"}const Gy={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Yy(e,t){var n;switch(t.type){case"reset":return{messages:Zi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=Zi(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=Zi(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 Yc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Yc(o,s),e):e}case"interrupt_response":return{...e,messages:Xc(e.messages),pendingInterrupt:null};default:return e}}function Gc(e=[]){const[t,n]=b.useReducer(Yy,{...Gy,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.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=b.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=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.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 Yc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Qy(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??Jc(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:eu(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:m,newMeta:g,changed:y}=Xy(d.content,t.delta,h,p);if(!y)return e;const x={...d,content:m},w=us(l,c,x),C={...f,[a]:g};return{...e,messages:w,messagesStreamMeta:C}}if(t.type==="message_end"){const a=e.assemblingId??Jc(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=Zc(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=Qc(e,d,c),h=f>=0?e.messages[f]:null,p=l??d[0]??`${c}-${Date.now()}`,m=(h==null?void 0:h.id)??`tool-${p}`,g=d[0]??p,y={type:"tool_call",id:g,name:c,args:t.args};if(h){const C=ea(h,d,c,t.args),T={...h,name:h.name??c,additionalKwargs:C},k=f,S=k>=0?us(e.messages,k,T):e.messages,E=ds(T,d),j=ta(e.toolIndex,m,E);return{...e,messages:S,toolIndex:j}}const x={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:ea(void 0,d.length?d:[g],c,t.args)},w=ds(x,d.length?d:[g]);return{...e,messages:[...e.messages,x],toolIndex:ta(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=Zc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=Qc(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}`,m=ds(d,a);let g=t.output;if(typeof t.output=="string")try{const S=t.output.trim();(S.startsWith("{")||S.startsWith("["))&&(g=JSON.parse(S))}catch{g=t.output}const y={type:"text",text:typeof g=="string"?g:JSON.stringify(g)},x=(d==null?void 0:d.createdAt)??new Date().toISOString(),w=ea(d??void 0,m.length?m:a,f),C={id:p,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[y],createdAt:x,additionalKwargs:w},T=c>=0?us(e.messages,c,C):[...e.messages,C],k=ds(C,a.length?a:m);return{...e,messages:T,toolIndex:ta(e.toolIndex,p,k)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Zy(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=ls(t),l=a.interrupt,c=a.latest,d=l===null?Xc(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 Zi(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 us(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Xc(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 Jc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Zc(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 Qi(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 ea(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=Qi(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 ds(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Qi(e);for(const o of r)n.add(o);return Array.from(n)}function ta(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 Qc(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(Qi(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 eu(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Xy(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??eu(e);let l="",c=e.slice();if(s){const f=Jy(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??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}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 tu(e){return e.replace(/\s+/g," ").trim()}function Jy(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=tu(e),o=tu(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 Zy(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 us(e,r,s)}return e}function Qy(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function nu(e={}){const t=b.useMemo(()=>Zn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[f,h]=b.useState(""),[p,m]=b.useState(null),[g,y]=b.useState(0),[x,w]=b.useState(!1),C=b.useRef(null),T=b.useRef(!0),k=b.useRef(0),S=b.useRef(null),E=b.useRef(null),j=b.useRef(null),_=b.useRef(null),P=b.useCallback(O=>{o(O)},[]),D=b.useCallback(()=>{h(""),m(null),d(null),E.current=null,j.current=null,_.current=null},[]),z=b.useCallback(()=>{var O;console.debug("[use-chat] stop() invoked - aborting stream"),(O=C.current)==null||O.abort(),C.current=null,S.current=null,l(!1),w(!1),k.current=0,y(0)},[]),B=b.useCallback((O,H,R)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),m(null),E.current=null,j.current=null,_.current=null;const V=new AbortController;C.current=V;let $=null,F=null,ne=!1;return S.current={threadId:O.threadId??null,headers:{}},(async()=>{var ye,je,J,ue,ke,te,L,q,ie,ce,U,We,re,xe,Pe,$e,rt,Se;const Q=Ye=>{var ot;try{const et=JSON.parse(JSON.stringify(Ye));return(ot=et==null?void 0:et.payload)!=null&&ot.files_info&&Array.isArray(et.payload.files_info)&&(et.payload.files_info=et.payload.files_info.map(Xe=>({...Xe,data:Xe!=null&&Xe.data?`<base64 ${String(Xe.data).length} chars>`:Xe==null?void 0:Xe.data}))),et}catch{return Ye}};try{let Ye={};try{if(r)Ye={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ve=window.__AUTH_TOKEN__,Mt=((ye=window.localStorage)==null?void 0:ye.getItem("authToken"))||null;let _t=null;try{const Te=(je=window.localStorage)==null?void 0:je.getItem("chat-settings");Te&&(_t=((J=JSON.parse(Te))==null?void 0:J.apiKey)||null)}catch{}const G=Ve||Mt||_t||null;G&&(Ye={Authorization:`Bearer ${G}`})}}catch{}console.debug("[use-chat] POST",t+n,Q(O));let ot={};if(typeof window<"u")try{const ft=(ue=window.localStorage)==null?void 0:ue.getItem("authSessionId");ft&&(ot={"X-Session-Id":ft})}catch{}const et={...Ye,...ot,...s.current},Xe={"Content-Type":"application/json",Accept:"text/event-stream",...et},Ke=await fetch(t+n,{method:"POST",headers:Xe,body:JSON.stringify(O),signal:V.signal,credentials:i});if(S.current&&(S.current.headers=et),!Ke.ok||!Ke.body){const ft=await Ke.text().catch(()=>"");console.debug("[use-chat] non-OK response",Ke.status,ft==null?void 0:ft.slice(0,500));const Ve=`stream ${Ke.status}${ft?": "+ft:""}`;throw(ke=R==null?void 0:R.onConnectionError)==null||ke.call(R,Ve),ne=!0,$="error",F=Ve,new Error(Ve)}w(!0);const tt=Ke.body.getReader(),Ot=new TextDecoder;let St="",nt=[];k.current=0,y(0);let yt=0,Nt=null;const st=()=>{if(nt.length){const ft=nt.join("");nt=[],T.current&&h(Ve=>Ve+ft)}Nt=null},Gt=()=>{typeof window<"u"&&Nt==null&&(Nt=requestAnimationFrame(st))};let Yt=Date.now();const Xt=setInterval(()=>{var ft;if(Date.now()-Yt>18e5){const Ve="Stream idle timeout";d(Ve),$="error",F=Ve,V.abort(),(ft=R==null?void 0:R.onError)==null||ft.call(R,Ve)}},5e3),Jt=1024*1024;try{const ft=Ke.headers.get("X-Thread-Id")||Ke.headers.get("x-thread-id"),Ve=Ke.headers.get("X-Thread-Created")||Ke.headers.get("x-thread-created"),Mt=ft??null,_t=String(Ve??"").toLowerCase()==="true";for(S.current&&!S.current.threadId&&(S.current={...S.current,threadId:Mt}),(te=R==null?void 0:R.onOpen)==null||te.call(R,{threadId:Mt,created:_t});;){const{value:G,done:Te}=await tt.read();if(Te)break;St+=Ot.decode(G,{stream:!0}),St.length>Jt&&(St="",console.warn("Stream buffer reset: exceeded 1MB"));let ve;for(;(ve=St.indexOf(`
36
36
 
37
- `))>=0;){const ot=Ct.slice(0,ve);Ct=Ct.slice(ve+2);const vt=Qy(ot);if(!vt)continue;let It;try{It=JSON.parse(vt)}catch{console.debug("[use-chat] malformed SSE:",vt.slice(0,200));continue}const Ne=Zy(It)?It.data:It;on=Date.now();const Qt=Ne.seq;if(Qt!==void 0){if(Qt<=xt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Qt,lastProcessedSeq:xt,type:Ne.type});continue}xt>0&&Qt>xt+1&&((L=R==null?void 0:R.onGap)==null||L.call(R,{from:xt,to:Qt})),xt=Qt,k.current=Qt,y(Qt)}if(console.debug("[use-chat] received event",{seq:Ne.seq,type:Ne.type,preview:(()=>{var at;try{return Ne.type==="message_delta"?{deltaTypes:(at=Ne.delta)==null?void 0:at.map(Xe=>Xe.type),textLen:(Ne.delta||[]).filter(Xe=>Xe.type==="text").map(Xe=>String(Xe.text||"").length)}:Ne.content||Ne.delta?{hasContent:!0}:{}}catch(Xe){return{err:String(Xe)}}})()}),Ne.type==="checkpoint")E.current=Ne.checkpointId??null,j.current=Ne.checkpointNs??null,m(Ne.checkpointId??null);else if(Ne.type==="state_history"){_.current=Ne;try{const Xe=cs(Ne).latest;Xe&&(E.current=Xe.checkpointId??null,j.current=Xe.checkpointNs??null,m(Xe.checkpointId??null))}catch(at){console.warn("[use-chat] Failed to hydrate state_history payload",at)}}try{H==null||H(Ne)}catch(at){console.error("[use-chat] Error in onEvent callback:",at,"for event:",Ne.type)}if(Ne.type==="token"&&e.autoAppendAssistant!==!1)dt.push(Ne.content),rn();else if(Ne.type==="message_delta"){const at=Ne.delta.filter(Xe=>Xe.type==="text").map(Xe=>Xe.text).join("");at&&e.autoAppendAssistant!==!1&&(dt.push(at),rn())}else if(Ne.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(G=R==null?void 0:R.onHeartbeat)==null||G.call(R,Ne)}catch(at){console.warn("[use-chat] heartbeat callback failed",at)}}else if(ft!==null&&cancelAnimationFrame(ft),rt(),Ne.type==="checkpoint")m(Ne.checkpointId);else if(Ne.type==="error"){const at=Ne;if(d(at.message),$="error",F=at.message,at.error_type==="auth_error"||at.code==="TOKEN_EXPIRED"||((se=at.message)==null?void 0:se.includes("token"))||((le=at.message)==null?void 0:le.includes("401"))||((U=at.message)==null?void 0:U.includes("unauthorized"))||((We=at.message)==null?void 0:We.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",at.message);try{(re=R==null?void 0:R.onAuthError)==null||re.call(R,at.message)}catch(sn){console.warn("[use-chat] onAuthError handler failed",sn)}V.abort()}}}}rt(),$===null&&!V.signal.aborted&&($="complete")}catch(ht){if(ht.name==="AbortError")$=$??"aborted";else{const Ve=ht.message||String(ht);$="error",F=Ve,d(Ve),(xe=R==null?void 0:R.onError)==null||xe.call(R,Ve)}}finally{try{await et.cancel()}catch{}finally{(Re=et.releaseLock)==null||Re.call(et)}ft!==null&&typeof window<"u"&&window.cancelAnimationFrame(ft),clearInterval(Wt)}}catch(Ge){if(Ge.name==="AbortError")$=$??"aborted";else{const nt=Ge.message||String(Ge);$="error",F=nt,d(nt),(Fe=R==null?void 0:R.onError)==null||Fe.call(R,nt),ne||((tt=R==null?void 0:R.onConnectionError)==null||tt.call(R,nt),ne=!0)}}finally{const Ge=k.current,nt=E.current,Qe=j.current,Ye=_.current,qe=$??(V.signal.aborted?"aborted":F?"error":"complete");try{(Se=R==null?void 0:R.onClosed)==null||Se.call(R,{reason:qe,lastSeq:Ge,lastCheckpointId:nt,lastCheckpointNs:Qe,lastStateHistory:Ye,error:F})}catch(et){console.warn("[use-chat] onClosed callback failed",et)}l(!1),w(!1),C.current=null,k.current=0,y(0),S.current=null}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var O;T.current=!1,(O=C.current)==null||O.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:g,connected:x,stream:B,stop:z,clear:D,setToken:P}}function Zy(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Qy(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 nu=200;function ex({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),h=b.useRef(null),p=b.useCallback(_=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(_)}catch{}try{return JSON.parse(JSON.stringify(_))}catch{return _}},[]),m=b.useCallback((_,P)=>{if(!_)return;const D=f.current.get(_)??[],z=p(P),B=D.length>=nu?[...D.slice(D.length-nu+1),z]:[...D,z];f.current.set(_,B)},[p]),g=b.useCallback(_=>{_&&f.current.set(_,[])},[]),y=b.useCallback(_=>{const P=_??d.current;if(!P)return;const D=f.current.get(P);D!=null&&D.length&&D.forEach(z=>{try{n(z)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),x=b.useCallback(_=>{var z,B,O,H,R;const P=_.seq??null;if(P!==null){const V=c.current;if(V!==null){if(P<=V)return;P>V+1&&(o==null||o({from:V,to:P}))}c.current=P}if(_.type==="thread_info"){d.current=_.threadId,h.current&&(h.current.threadIdGuess=_.threadId),g(_.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{l==null||l(_)}catch(V){console.error("[useChatStreamingService] Error in onHeartbeat 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"))||((B=V.message)==null?void 0:B.includes("401"))||((O=V.message)==null?void 0:O.includes("unauthorized"))||((H=V.message)==null?void 0:H.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??((R=h.current)==null?void 0:R.threadIdGuess)??null;if(_.type==="state_history"&&(d.current=D??d.current),Vy(_)){_.type==="checkpoint"||_.type==="state_history"?g(D??null):m(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)}},[m,g,n,o,t,r]),{stream:w,stop:C,isStreaming:T,error:k,setToken:S}=tu({baseUrl:e,token:void 0}),E=b.useCallback((_,P)=>{c.current=null,d.current=_.threadId??null,h.current={request:_,callbacks:P,manualStop:!1,threadIdGuess:_.threadId??null},w(_,x,{onOpen:P==null?void 0:P.onOpen,onError:D=>{var z;(z=P==null?void 0:P.onError)==null||z.call(P,D)},onGap:(P==null?void 0:P.onGap)??o,onConnectionError:D=>{var z;i==null||i(D),(z=P==null?void 0:P.onConnectionError)==null||z.call(P,D)},onAuthError:D=>{var z;a==null||a(D),(z=P==null?void 0:P.onAuthError)==null||z.call(P,D)},onHeartbeat:D=>{var z;try{l==null||l(D)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(z=P==null?void 0:P.onHeartbeat)==null||z.call(P,D)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:D=>{var H,R,V,$;const z=((H=h.current)==null?void 0:H.manualStop)??!1,B=d.current??((R=h.current)==null?void 0:R.threadIdGuess)??((V=D.lastStateHistory)==null?void 0:V.threadId)??null;(D.reason==="complete"||D.reason==="aborted"&&z)&&g(B);const O={...D,threadId:B,manualStop:z};try{s==null||s(O)}catch(F){console.warn("[useChatStreamingService] onStreamClosed handler failed",F)}try{($=P==null?void 0:P.onClosed)==null||$.call(P,O)}catch(F){console.warn("[useChatStreamingService] downstream onClosed handler failed",F)}h.current&&(h.current=null)}})},[g,x,a,i,l,o,s,w]),j=b.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return b.useMemo(()=>({startStream:E,stop:j,isStreaming:T,error:k,setAuthToken:S,replayBufferedEvents:y}),[E,j,T,k,S,y])}const ru=50,tx=750,na="chat-history@1",nx=5,rx=1e3,ox=15e3,hs=300;function ou(e,t=hs){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function kr(){return typeof window<"u"&&typeof window.localStorage<"u"}function ra(e){if(!kr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function oa(e,t){if(!kr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function sa(e){if(kr())try{window.localStorage.removeItem(e)}catch{}}function ia(e){return e==null?e:{...e}}function sx(e){return e==null?e:{...e}}function ix(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function ax(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function un(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=ia(e==null?void 0:e.metadata),s=ia(e==null?void 0:e.config),i=ia(e==null?void 0:e.parentConfig),a=ix(e==null?void 0:e.next),l=ax(e==null?void 0:e.tasks),c=sx(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 lx(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 su(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}}function aa(e,t){return`${e}${t}`}function cx(e,t){const n=ra(aa(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:un(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function ux(e,t,n=100){if(!kr())return;const r=un(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=aa(e,t.threadId),i=JSON.stringify(o);if(!oa(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),oa(s,i))break}catch{}}function dx(e,t){sa(aa(e,t))}function fx(e){if(kr())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{}}function iu(e,t,n){return`${e}__${t??""}__${n??""}`}function ps(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 hx(e,t){return ps(e,t)}function px(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 mx(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 au(e,t){const n=ps(e.metadata,t.metadata),r=ps(e.config,t.config),o=ps(e.parentConfig,t.parentConfig),s=px(e.next,t.next),i=mx(e.tasks,t.tasks),a=hx(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 lu(e){return Array.isArray(e)?e.filter(t=>!!(t&&(t.checkpointId||t.checkpointNs))).map(t=>{const n=un(t,{cloneMessages:!0});return{...n,messages:Array.isArray(n.messages)?n.messages:[],values:n.values??null}}):[]}const gx="cachedThreads",yx="v1",la=200;function xx(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 ca(e,t){return`cachedThreads:v1:${e}:${xx(t||"anon")}`}function vx(){const e=ra(gx);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 wx(e){const t=ra(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 ua(e,t){oa(e,JSON.stringify(t))}function da(e){const t=wx(e);if(t.length>0)return t;const n=vx();if(n.length>0)try{ua(e,n.slice(0,la))}catch{}return n}function ms(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 fa(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function bx({currentThreadId:e,currentThreadIdRef:t}){const[n,r]=b.useState([]),o=b.useRef(new Map),s=b.useRef(new Map),i=b.useCallback(m=>{if(!m){r([]);return}const g=o.current.get(m);if(!g||!g.length){r([]);return}r(g.map(y=>un(y,{cloneMessages:!0})))},[]);b.useEffect(()=>{i(e)},[e,i]);const a=b.useCallback((m,g,y)=>{if(!m)return;const x=y==="replace"?[]:o.current.get(m)??[],w=y==="replace"?g:[...g,...x];if(!w.length){y==="replace"&&o.current.set(m,[]),m===t.current&&r([]);return}const C=new Map;for(const k of w){if(!(k!=null&&k.checkpointId))continue;const S=`${k.checkpointId}::${k.checkpointNs??""}`,E=un(k,{cloneMessages:!0}),j=C.get(S);if(!j){C.set(S,E);continue}const _=au(j,E);C.set(S,{...j,..._})}const T=Array.from(C.values()).sort((k,S)=>{const E=Number.isFinite(Date.parse(k.createdAt??""))?Date.parse(k.createdAt??""):0;return(Number.isFinite(Date.parse(S.createdAt??""))?Date.parse(S.createdAt??""):0)-E});o.current.set(m,T),m===t.current&&i(m)},[t,i]),l=b.useCallback((m,g,y)=>{if(!m)return;const x=s.current.get(m),w=y==="replace"||!x?new Map:new Map(x);if(g&&typeof g=="object")for(const[C,T]of Object.entries(g)){if(!(T!=null&&T.checkpointId))continue;const k=C||Vr(T.checkpointId,T.checkpointNs??null);w.set(k,un(T,{cloneMessages:!0}))}s.current.set(m,w)},[]),c=b.useCallback((m,g)=>{if(!m)return!1;const y=lu(g);if(!y.length)return!1;const x=o.current.get(m)??[],w=new Map,C=(k,{preferExisting:S})=>{for(const E of k){if(!(E!=null&&E.checkpointId)&&!(E!=null&&E.checkpointNs))continue;const j=Vr(E.checkpointId??null,E.checkpointNs??null);j&&(S&&w.has(j)?w.set(j,E):w.has(j)&&S||w.set(j,E))}};C(y,{preferExisting:!1}),C(x,{preferExisting:!0});const T=Array.from(w.values()).sort((k,S)=>{const E=Number.isFinite(Date.parse(k.createdAt??""))?Date.parse(k.createdAt??""):0;return(Number.isFinite(Date.parse(S.createdAt??""))?Date.parse(S.createdAt??""):0)-E});return o.current.set(m,T),m===t.current&&r(T.map(k=>un(k,{cloneMessages:!0}))),!0},[t]),d=b.useCallback(m=>{m&&(o.current.delete(m),s.current.delete(m),m===t.current&&r([]))},[t]),f=b.useCallback(()=>{r([])},[]),h=b.useCallback(m=>m?s.current.get(m)??null:null,[]),p=b.useCallback((m,g)=>{var y;if(m)return(y=s.current.get(m))==null?void 0:y.get(g)},[]);return{threadCheckpoints:n,syncActiveThreadCheckpoints:i,updateCheckpointCache:a,updateCheckpointSnapshots:l,applyCheckpointSummaries:c,clearThreadCaches:d,resetThreadCheckpoints:f,getSnapshotCache:h,getSnapshotFromCache:p}}const cu=b.createContext(null),uu=b.createContext(null),du=b.createContext(null),Sx=b.createContext(!1);function Cx({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}=Xi(),f=b.useMemo(()=>Jn(d),[d]),h=b.useMemo(()=>{try{return new URL(d).host}catch{return"unknown"}},[d]),p=b.useMemo(()=>`threadPayload:${yx}:${h}:`,[h]),m=b.useCallback(I=>cx(p,I),[p]),g=b.useCallback((I,A=100)=>{ux(p,I,A)},[p]),y=b.useCallback(I=>{dx(p,I)},[p]),x=b.useCallback(()=>{fx(p)},[p]),[w,C]=b.useState(()=>{var I;return ca(h,(I=c.getAuthToken)==null?void 0:I.call(c))}),[T,k]=b.useState(()=>{var A;const I=da(ca(h,(A=c.getAuthToken)==null?void 0:A.call(c)));return ms(I)}),S=b.useMemo(()=>fa(T),[T]),[E,j]=b.useState(t),[_,P]=b.useState(!1),[D,z]=b.useState(!1),[B,O]=b.useState(null),[H,R]=b.useState(null),[V,$]=b.useState(null),F=b.useCallback(()=>{const I=da(w);b.startTransition(()=>{k(ms(I))})},[w]),[ne,Q]=b.useState(!1),[ye,Pe]=b.useState(!1),[Z,ue]=b.useState(null),[ke,te]=b.useState(void 0),[L,G]=b.useState(void 0),[se,le]=b.useState(void 0),{state:U,dispatch:We,seed:re,prepend:xe,pushUser:Re,onEvent:Fe,reset:tt}=qc(),Se=b.useRef(E);b.useEffect(()=>{Se.current=E},[E]);const Ge=b.useRef(!1),nt=b.useRef([]),Qe=b.useRef(null),Ye=b.useRef(null),qe=b.useRef(new Map),et=b.useRef(E),Mt=b.useRef(!1),Ct=b.useRef(null),dt=b.useRef(null),xt=b.useRef(new Map),ft=b.useRef(new Map),{threadCheckpoints:rt,syncActiveThreadCheckpoints:rn,updateCheckpointCache:on,updateCheckpointSnapshots:Wt,applyCheckpointSummaries:zt,clearThreadCaches:ht,resetThreadCheckpoints:Ve,getSnapshotCache:Dt,getSnapshotFromCache:_t}=bx({currentThreadId:E,currentThreadIdRef:Se}),Y=b.useCallback(()=>{var K;const I=ft.current;if(I.size<=ru)return;const A=Array.from(I.entries()).sort((fe,ae)=>fe[1].timestamp-ae[1].timestamp),W=I.size-ru;for(let fe=0;fe<W;fe++){const ae=(K=A[fe])==null?void 0:K[0];ae&&I.delete(ae)}},[]),Ie=b.useCallback((I,A)=>{if(!I)return null;const W=Array.isArray(I.checkpoints)?I.checkpoints:[];return W.length===0?null:{version:I.version===na?I.version:na,threadId:I.threadId??A,checkpoints:W}},[]),ve=b.useCallback((I,A)=>{const{threadId:W,checkpointId:K=null,checkpointNs:fe=null}=I,ae=iu(W,K,fe);if(A!=null&&A.force)xt.current.delete(ae),ft.current.delete(ae);else{if(A!=null&&A.preferCache){const kt=ft.current.get(ae);if(kt)return Promise.resolve(kt.result)}const Be=xt.current.get(ae);if(Be)return Be}const St=(async()=>{try{const Be=await c.getStateHistory({threadId:W,checkpointId:K??void 0,checkpointNs:fe??void 0}),kt=Ie(Be,W);if(kt)return{payload:kt,usedHistoryApi:!0};throw new Error("History response missing checkpoints")}catch(Be){console.warn("[ChatSessionProvider] getStateHistory failed, falling back to getState:",Be);const kt=await c.getState({threadId:W,checkpointId:K??void 0,checkpointNs:fe??void 0});return{payload:{version:na,threadId:W,checkpoints:[kt]},usedHistoryApi:!1}}})().then(Be=>(ft.current.set(ae,{result:Be,timestamp:Date.now()}),Y(),Be)).finally(()=>{xt.current.get(ae)===St&&xt.current.delete(ae)});return xt.current.set(ae,St),St},[c,Ie,Y]),ot=b.useCallback((I,A)=>new Promise((W,K)=>{const fe=async()=>{Ge.current=!0;try{await I(),W()}catch(ae){K(ae)}finally{Ge.current=!1;const ae=nt.current.shift();ae&&ae().catch(()=>{})}};Ge.current?nt.current.push(fe):fe().catch(ae=>{K(ae)})}),[]),vt=b.useRef(S.length),It=b.useRef(!1);b.useEffect(()=>{vt.current=S.length},[S.length]),b.useEffect(()=>{const I=U.pendingInterrupt??lx(U.messages);su(V,I)||$(I??null)},[V,U.messages,U.pendingInterrupt]);const Ne=b.useCallback(async()=>{const I=vt.current>0;I||P(!0);try{const A=await c.listThreads();b.startTransition(()=>{k(W=>{const K=yt=>yt.map(St=>`${St.threadId}:${St.updatedAt??""}:${St.messageCount??""}`).join("|"),fe=fa(W);return K(fe)===K(A)||A.length===0&&fe.length>0&&!It.current?W:ms(A)}),I||P(!1)}),O(null),It.current||(It.current=!0)}catch(A){i==null||i(String(A)),console.error("[ChatSessionProvider] Failed to refresh threads:",A),O(String(A)),I||P(!1)}},[c,i]),Qt=b.useRef(!1),at=b.useRef(null),Xe=b.useRef(null),sn=b.useRef(""),[qn,jt]=b.useState("idle"),rr=b.useRef({attempts:0,timer:null,reason:null}),Fr=b.useRef(null),Ko=b.useRef(0),$r=b.useRef(()=>{}),N=b.useRef(()=>{}),q=b.useRef(()=>{}),de=I=>{if(!I||typeof I!="object")return!1;const A=I;return A.code==="ECONNABORTED"?!0:(typeof A.message=="string"?A.message.toLowerCase():"").includes("timeout")},Ce=b.useCallback(async I=>{const A=await c.listCheckpointSummaries(I);return lu(A??[])},[c]),He=b.useCallback((I,A)=>{if(!kr())return;Xe.current!==null&&(window.clearTimeout(Xe.current),Xe.current=null);const W=I.map(fe=>`${fe.threadId}:${fe.updatedAt??""}:${fe.messageCount??""}`).join("|");if(I.length===0){try{sa(w)}catch{}sn.current="";return}if(W===sn.current)return;const K=()=>{try{const fe=I.slice(0,la);ua(w,fe),sn.current=W}catch{}finally{Xe.current=null}};if(A!=null&&A.immediate){K();return}Xe.current=window.setTimeout(()=>{ou(K)},hs)},[w]),lt=b.useCallback(()=>{He(S,{immediate:!0})},[He,S]),Oe=b.useCallback((I,A,W,K)=>{var Wl;const fe=W??Se.current;if(!fe)return;const ae=un(I),yt=fe===Se.current,St=(K==null?void 0:K.persist)!==!1;if(A==="replace"){if(St){const Kt={threadId:fe,snapshot:un(I,{cloneMessages:!0})};qe.current.set(fe,Kt),et.current=fe}if(!yt)return;re(ae.messages,{checkpointId:ae.checkpointId??null,checkpointNs:ae.checkpointNs??null,pendingInterrupt:ae.interrupt??null}),$(ae.interrupt??null),ue(ae.nextCursor??null),Q(!!ae.nextCursor),te(ae.checkpointId??void 0),G(ae.checkpointNs??void 0),le(ae.nextCursorNs??void 0);return}const Be=qe.current.get(fe),kt=(Be==null?void 0:Be.snapshot)??null,Ut=Array.isArray(kt==null?void 0:kt.messages)?kt.messages:[],hn=un(kt),Xn=Array.isArray(I==null?void 0:I.messages)?I.messages:[],Vt=new Set,Pt=[...Xn,...Ut].filter(Kt=>{const Vl=Kt==null?void 0:Kt.id;return Vl?Vt.has(Vl)?!1:(Vt.add(Vl),!0):!0}),or=au(hn,ae),zr={checkpointId:hn.checkpointId??ae.checkpointId??null,checkpointNs:hn.checkpointNs??ae.checkpointNs??null,createdAt:ae.createdAt??hn.createdAt??null,parentId:ae.parentId??hn.parentId??null,branchLabel:ae.branchLabel??hn.branchLabel??null,lastMessageId:((Wl=Pt[Pt.length-1])==null?void 0:Wl.id)??null,messagesLen:Pt.length,hasMessages:Pt.length>0,messages:Pt,nextCursor:ae.nextCursor??hn.nextCursor??null,nextCursorNs:ae.nextCursorNs??hn.nextCursorNs??null,interrupt:hn.interrupt??ae.interrupt??null,...or};if(qe.current.set(fe,{threadId:fe,snapshot:un(zr,{cloneMessages:!0})}),!yt)return;Xn.length&&xe(Xn);const lo=I&&Object.prototype.hasOwnProperty.call(I,"checkpointId")?I.checkpointId:void 0,Nn=I&&Object.prototype.hasOwnProperty.call(I,"checkpointNs")?I.checkpointNs:void 0,Br=I&&Object.prototype.hasOwnProperty.call(I,"nextCursor")?I.nextCursor:void 0,vr=I&&Object.prototype.hasOwnProperty.call(I,"nextCursorNs")?I.nextCursorNs:void 0;ue(Kt=>Br!==void 0?Br??Kt??null:Kt??null),Q(Kt=>Br!==void 0?!!Br:Kt),te(Kt=>lo!==void 0?lo??Kt??void 0:Kt??void 0),G(Kt=>Nn!==void 0?Nn??Kt??void 0:Kt??void 0),le(Kt=>vr!==void 0?vr??void 0:Kt)},[xe,re,$]),$e=b.useCallback(I=>{if(I.threadId!=null&&I.threadId!==Se.current)return;const A=un(I.snapshot,{cloneMessages:!0});re(A.messages,{checkpointId:A.checkpointId??null,checkpointNs:A.checkpointNs??null,pendingInterrupt:A.interrupt??null}),$(A.interrupt??null),ue(A.nextCursor??null),Q(!!A.nextCursor),te(A.checkpointId??void 0),G(A.checkpointNs??void 0),le(A.nextCursorNs??void 0),et.current=I.threadId,rn(I.threadId??Se.current??null)},[re,$,rn]),At=b.useCallback(I=>{if(!I)return;qe.current.delete(I),y(I),ht(I);const A=`${I}__`;for(const W of xt.current.keys())W.startsWith(A)&&xt.current.delete(W);for(const W of ft.current.keys())W.startsWith(A)&&ft.current.delete(W);et.current===I&&(et.current=null)},[ht,y]),pt=b.useCallback(()=>{const I=Se.current;I&&At(I),tt([]),Q(!1),Pe(!1),ue(null),te(void 0),G(void 0),le(void 0)},[At,tt]),mt=b.useCallback(({from:I,to:A})=>{const W=Se.current;W&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${I} -> ${A}) for thread ${W}`)},[]),en=b.useCallback(I=>{const A=I.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:A,title:I.title,created:I.created,currentThreads:S.length});const W={threadId:A,title:I.title||`Thread ${A.slice(0,8)}`,createdAt:I.createdAt||new Date().toISOString(),updatedAt:I.updatedAt||new Date().toISOString(),messageCount:I.messageCount||0};Se.current!==A&&(!Se.current&&U.messages.length<=1&&(Ye.current=A),j(A)),b.startTransition(()=>{k(K=>{const fe=K.byId[A];return fe?fe.title===W.title&&fe.updatedAt===W.updatedAt&&fe.messageCount===W.messageCount?K:{byId:{...K.byId,[A]:W},order:K.order}:{byId:{...K.byId,[A]:W},order:[A,...K.order]}})})},[U.messages.length]),{startStream:Dn,stop:In,isStreaming:Lt,error:xr,setAuthToken:J,replayBufferedEvents:ce}=ex({baseUrl:f,onThreadInfo:en,onMessageEvent:Fe,onUnhandledEvent:I=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${I.type}`,I)},onSequenceGap:mt,onStreamClosed:I=>{$r.current(I)},onConnectionError:I=>{N.current(I)},onAuthError:a,onHeartbeat:I=>{q.current(I)}}),ie=b.useCallback(()=>{const I=rr.current;I.timer!==null&&(window.clearTimeout(I.timer),I.timer=null),I.reason=null},[]),Te=b.useCallback((I,A)=>{jt("connecting"),Dn(I,{onOpen:W=>{var K;ie(),rr.current.attempts=0,jt("connected"),(K=A==null?void 0:A.onOpen)==null||K.call(A,W)},onError:W=>{var K;(K=A==null?void 0:A.onError)==null||K.call(A,W)},onGap:(A==null?void 0:A.onGap)??mt,onConnectionError:W=>{var K;N.current(W),(K=A==null?void 0:A.onConnectionError)==null||K.call(A,W)},onHeartbeat:W=>{var K;q.current(W),(K=A==null?void 0:A.onHeartbeat)==null||K.call(A,W)},onClosed:W=>{var K;$r.current(W),(K=A==null?void 0:A.onClosed)==null||K.call(A,W)}})},[ie,mt,jt,Dn]),gt=b.useCallback(()=>{const I=Se.current;if(!I)return null;const A=Fr.current,W=U.lastCheckpointId??(A==null?void 0:A.lastCheckpointId)??null,K=U.lastCheckpointNs??(A==null?void 0:A.lastCheckpointNs)??null,fe={};return W&&(fe.checkpointId=W),K&&(fe.checkpointNs=K),{threadId:I,checkpointId:W,checkpointNs:K,command:{kind:"resume",value:fe}}},[U.lastCheckpointId,U.lastCheckpointNs]),Ke=b.useCallback(I=>{const A=rr.current;if(A.timer!==null)return;if(A.attempts>=nx){jt("error");return}A.attempts+=1,A.reason=I;const W=Math.min(rx*Math.pow(2,A.attempts-1),ox);jt("reconnecting"),A.timer=window.setTimeout(()=>{A.timer=null,A.reason=null;const K=gt();if(!K){jt("error");return}ce(K.threadId??void 0),Te(K)},W)},[gt,ce,jt,Te]),st=b.useCallback(I=>{var A;if(Fr.current=I,I.manualStop||I.reason==="complete"){ie(),rr.current.attempts=0,jt("idle");return}if(I.error&&(I.error.includes("token")||I.error.includes("401")||I.error.includes("unauthorized")||I.error.includes("Unauthorized")||I.error.includes("TOKEN_EXPIRED")||I.error.includes("auth_error"))){console.error("[ChatSessionProvider] Auth error detected:",I.error);try{a==null||a(I.error)}catch(K){console.error("[ChatSessionProvider] Error in onAuthError handler:",K)}return}if(I.reason==="error"||I.reason==="aborted"){if((A=I.error)!=null&&A.includes("Stream idle timeout")){console.warn("[ChatSessionProvider] Idle timeout - not scheduling resume (watchdog is generous)");return}Ke(`closed:${I.reason}`)}},[ie,Ke,jt,a]),Ht=b.useCallback(I=>{console.warn("[ChatSessionProvider] Stream connection error:",I),Ke("connection-error")},[Ke]),fn=b.useCallback(I=>{Ko.current=Date.now(),jt(A=>A==="reconnecting"?"connected":A)},[jt]);$r.current=st,N.current=Ht,q.current=fn,b.useEffect(()=>()=>{ie()},[ie]);const Gn=b.useCallback(()=>{ie(),rr.current.attempts=0,jt("idle"),In()},[ie,jt,In]);b.useEffect(()=>{Qt.current=Lt},[Lt]),b.useEffect(()=>{if(!kr())return;Xe.current!==null&&(window.clearTimeout(Xe.current),Xe.current=null);const I=S.map(W=>`${W.threadId}:${W.updatedAt??""}:${W.messageCount??""}`).join("|");if(S.length===0){try{sa(w)}catch{}sn.current="";return}if(I===sn.current)return;const A=()=>{try{const W=S.slice(0,la);ua(w,W),sn.current=I}catch{}finally{Xe.current=null}};return Xe.current=window.setTimeout(()=>{ou(A),Xe.current=null},hs),()=>{Xe.current!==null&&(window.clearTimeout(Xe.current),Xe.current=null)}},[S,He]),b.useEffect(()=>{var K;const I=c.getAuthToken();J(I);const A=fe=>{const ae=ca(h,fe);Ct.current!==ae&&(Ct.current=ae,Mt.current=!1),C(ae);const yt=da(ae);b.startTransition(()=>{k(ms(yt))}),fe&&!Mt.current&&(Mt.current=!0)};A(I);const W=(K=c.onTokenChange)==null?void 0:K.call(c,fe=>{fe!==I&&(J(fe),x(),xt.current.clear(),ft.current.clear(),A(fe))});return()=>{W==null||W()}},[c,h,J,x]);const qo=b.useCallback(async I=>{var K;const A=`Thread ${(K=crypto.randomUUID)==null?void 0:K.call(crypto)}`,W={threadId:A,title:I||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(fe=>({byId:{...fe.byId,[A]:W},order:[A,...fe.order]})),j(A);try{const fe=await c.createThread(I),ae=typeof fe=="string"?fe:fe.threadId;return k(yt=>{const St=yt.byId[A];if(!St)return yt;const Be={...yt.byId};delete Be[A],Be[ae]={...St,threadId:ae};const kt=yt.order.map(Ut=>Ut===A?ae:Ut);return{byId:Be,order:kt}}),j(ae),dt.current&&clearTimeout(dt.current),dt.current=setTimeout(()=>Ne(),300),O(null),ae}catch(fe){throw k(ae=>{if(!ae.byId[A])return ae;const yt={...ae.byId};delete yt[A];const St=ae.order.filter(Be=>Be!==A);return{byId:yt,order:St}}),j(null),O(String(fe)),fe}},[c,Ne]),Pi=b.useCallback(async I=>{try{await c.deleteThread(I);let A=null;k(W=>{if(!W.byId[I])return W;const K={...W.byId};delete K[I];const fe=W.order.filter(yt=>yt!==I),ae={byId:K,order:fe};return A=fa(ae),ae}),A&&He(A,{immediate:!0}),At(I),Se.current===I&&(Ye.current=I,j(null),Se.current=null,et.current=null,pt()),await Ne(),O(null)}catch(A){throw O(String(A)),A}},[c,pt,At,Ne,He]),ao=b.useCallback(async(I,A)=>{try{await c.updateThread(I,A),k(W=>{const K=W.byId[I];return K?{byId:{...W.byId,[I]:{...K,title:A}},order:W.order}:W}),O(null)}catch(W){throw await Ne(),O(String(W)),W}},[c,Ne]),Yn=b.useCallback(async(I,A,W,K=!1)=>{await ot(async()=>{if(Ye.current===I&&!K){Ye.current=null;return}if(Qe.current===I&&!K)return;j(Vt=>Vt===I?Vt:I),Se.current=I;const yt=iu(I,A??null,W??null),St=ft.current.get(yt),Be=!K&&!A&&!W&&St&&Date.now()-St.timestamp<tx,kt=!K&&!A&&!W;let Ut=!1;if(kt){const Vt=qe.current.get(I);if(Vt)$e(Vt),Ut=!0;else{const Pt=m(I);Pt&&(qe.current.set(I,Pt),$e(Pt),Ut=!0)}}const hn=K||!Ut||!!A||!!W,Xn=async Vt=>{Vt&&z(!0),Qe.current=I;try{const Pt=await ve({threadId:I,checkpointId:A,checkpointNs:W},{force:K}),{latest:or,checkpoints:zr,snapshots:lo}=cs(Pt.payload);b.startTransition(()=>{Oe(or,"replace",I),on(I,zr,"replace"),Wt(I,lo,"replace"),R(null),Vt&&z(!1)}),Pt.usedHistoryApi||Ce(I).then(Nn=>{zt(I,Nn)}).catch(Nn=>{console.warn("[ChatSessionProvider] Failed to refresh checkpoint summaries:",Nn)})}catch(Pt){if(de(Pt))try{const or=await Ce(I),zr=zt(I,or);if(Q(!1),ue(null),le(void 0),te(void 0),G(void 0),zr){R("History request timed out. Select a checkpoint to load manually.");return}}catch(or){console.warn("[ChatSessionProvider] Failed to fetch checkpoint summaries after timeout:",or)}throw(!Ut||K||Vt)&&(i==null||i(String(Pt))),R(String(Pt)),Pt}finally{Qe.current=null}};hn?await Xn(!0):kt&&Ut&&!Be&&Xn(!1).catch(Vt=>{console.warn("[ChatSessionProvider] Background refresh failed:",Vt)})},`loadThread-${I}`)},[$e,zt,Oe,ot,Ce,ve,de,i,on,Wt]),Wm=b.useCallback(async()=>{await ot(async()=>{const I=Se.current;I&&At(I),Ye.current=null,j(null),Se.current=null,et.current=null,pt(),te(void 0),G(void 0),le(void 0),Ve();try{localStorage.removeItem("lastThreadId")}catch(A){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",A)}},"clearCurrentThread")},[pt,At,ot,Ve]),Vm=b.useCallback(async(I,A)=>{const W=Se.current;if(!W)throw new Error("No active thread");const K=Vr(I,A??null),fe=_t(W,K);if(fe){await ot(async()=>{Oe(fe,"replace",W,{persist:!1})},`navigateToCheckpoint-${W}-${K}`);return}await Yn(W,I,A??void 0,!0)},[Oe,ot,_t,Yn]),Km=b.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");await Yn(Se.current,void 0,void 0,!0)},[Yn]),qm=b.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");if(ye||!ne)return;const I=Z;if(I){Pe(!0);try{const A=Se.current,W=await ve({threadId:A,checkpointId:I??ke??null,checkpointNs:se??L??null}),{latest:K,checkpoints:fe,snapshots:ae}=cs(W.payload),yt=Dt(A);let St=fe.length>0;if(St&&yt&&yt.size>0&&(St=fe.some(Be=>{if(!(Be!=null&&Be.checkpointId))return!1;const kt=Vr(Be.checkpointId,Be.checkpointNs??null);return!yt.has(kt)})),!St){ue(null),le(void 0),Q(!1),R(null);return}if(Oe(K,"prepend",A??void 0),A&&(on(A,fe,"prepend"),Wt(A,ae,"prepend"),!W.usedHistoryApi))try{const Be=await Ce(A);zt(A,Be)}catch(Be){console.warn("[ChatSessionProvider] Failed to refresh checkpoint summaries during prepend:",Be)}R(null)}catch(A){throw R(String(A)),A}finally{Pe(!1)}}},[Oe,ve,Dt,ne,ke,L,se,Z,Ce,zt,ye,on,Wt]),Gm=b.useCallback(I=>{if(I!=null&&I.threadId){if(I.checkpointId){const A=Vr(I.checkpointId,I.checkpointNs??null),W=un({...I,interrupt:I.interrupt??null},{cloneMessages:!0});Wt(I.threadId,{[A]:W},"prepend")}Oe(I,"replace",I.threadId)}},[Oe,Wt]),Go=b.useCallback(async(I,A)=>{var Br;const W=Se.current,K=(I==null?void 0:I.text)??"",fe=(I==null?void 0:I.attachments)??[],ae=fe.length?fe:(A==null?void 0:A.attachments)??[],yt=I==null?void 0:I.messageAdditionalKwargs,St={...(A==null?void 0:A.payloadExtras)??{},...(I==null?void 0:I.payload)??{}};if(!W&&!Object.keys(St).length&&ae.length===0&&!K.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!W&&!St.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Be,filesInfo:kt}=await Ay(c,ae),Ut=[...Be];K&&K.trim()&&Ut.push({type:"text",text:K.trim()});const hn=!!W,Xn=hn?(A==null?void 0:A.checkpointId)??U.lastCheckpointId??void 0:void 0,Vt=hn?(A==null?void 0:A.checkpointNs)??U.lastCheckpointNs??void 0:void 0,Pt={id:((Br=crypto.randomUUID)==null?void 0:Br.call(crypto))||`user-${Date.now()}`,role:"user",content:Ut,createdAt:new Date().toISOString(),...Xn!=null?{checkpointId:Xn}:{},...Vt!=null?{checkpointNs:Vt}:{}};yt&&Object.keys(yt).length&&(Pt.additionalKwargs={...Pt.additionalKwargs??{},...yt}),Ut.length>0&&Re(Pt);const or={...Pt,content:Ut},zr=ae.length>0,lo={messages:Ut.length>0?[or]:[],files_info:kt,...o&&zr&&s?{active_agent:s}:{},...St},Nn={threadId:W??null,payload:lo,checkpointId:Xn??null,checkpointNs:Vt??null,nodeFilter:(A==null?void 0:A.nodeFilter)??null,config:A==null?void 0:A.config,command:(A==null?void 0:A.command)??null};Nn.threadId||delete Nn.threadId,Nn.command||delete Nn.command,Te(Nn,{onError:vr=>{console.warn("[ChatSessionProvider] Stream error:",vr)},onOpen:({threadId:vr})=>{!Se.current&&vr&&(U.messages.length<=1&&(Ye.current=vr),j(vr))},onGap:mt})},[c,o,s,mt,U.lastCheckpointId,U.lastCheckpointNs,U.messages.length,Re,Te]),Ym=b.useCallback(async(I,A,W)=>{if(!Se.current)throw new Error("No active thread to handle interrupt");const fe=A?W??!0:!1;try{try{We({type:"interrupt_response",payload:{interruptId:I}})}catch(ae){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",ae)}await Go({payload:{}},{checkpointId:U.lastCheckpointId??void 0,checkpointNs:U.lastCheckpointNs??void 0,command:{kind:"resume",value:fe}}),$(null)}catch(ae){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${I}:`,ae),ae}},[We,U.lastCheckpointId,U.lastCheckpointNs,Go]);b.useEffect(()=>{if(l==null||l(E),E)try{localStorage.setItem("lastThreadId",E)}catch(I){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",I)}},[E,l]),b.useEffect(()=>((async()=>{try{if(Ne().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&&(j(A),n&&await Yn(A))}catch(A){console.warn("[ChatSessionProvider] Failed to restore last thread:",A)}else t&&n&&await Yn(t)}catch(A){console.error("[ChatSessionProvider] Initialization failed:",A),i==null||i(String(A))}})(),()=>{}),[]),b.useEffect(()=>{const I=Se.current;if(!I||et.current!==I)return;U.messages.length&&U.messages[U.messages.length-1];const A=un({checkpointId:U.lastCheckpointId??null,checkpointNs:U.lastCheckpointNs??null,messages:U.messages.slice(),nextCursor:Z??null,nextCursorNs:se??null,interrupt:U.pendingInterrupt??V??null}),W=qe.current.get(I),K=W==null?void 0:W.snapshot,fe=!K||K.messages.length!==A.messages.length||K.messages.some((Be,kt)=>{var Ut;return(Be==null?void 0:Be.id)!==((Ut=A.messages[kt])==null?void 0:Ut.id)}),ae=((K==null?void 0:K.checkpointId)??null)!==A.checkpointId||((K==null?void 0:K.checkpointNs)??null)!==A.checkpointNs,yt=((K==null?void 0:K.nextCursor)??null)!==A.nextCursor||((K==null?void 0:K.nextCursorNs)??null)!==A.nextCursorNs,St=!su((K==null?void 0:K.interrupt)??null,A.interrupt??null);if(fe||ae||yt||St){const Be={threadId:I,snapshot:A};qe.current.set(I,Be),at.current&&window.clearTimeout(at.current),at.current=window.setTimeout(()=>{try{g(Be,100)}catch(kt){console.warn("[ChatSessionProvider] Failed to persist thread payload:",kt)}},hs)}},[Z,se,U.lastCheckpointId,U.lastCheckpointNs,U.messages,U.pendingInterrupt,V,g]);const mT=b.useMemo(()=>({threads:S,currentThreadId:E,setCurrentThreadId:j,isLoading:_,error:B,actions:{createThread:qo,deleteThread:Pi,renameThread:ao,refreshThreads:()=>Ne()},persistThreadsCache:lt,hydrateFromCache:F}),[S,E,_,B,qo,Pi,ao,Ne,lt,F,j]),gT=b.useMemo(()=>{const I=U.lastBranch??null,A=U.assemblingId??null,W=I||A?{branchLabel:(I==null?void 0:I.branchLabel)??null,lastBranch:I,assemblingMessageId:A}:null;return{threadId:E,messages:U.messages,interrupt:V,checkpoint:{id:U.lastCheckpointId??null,namespace:U.lastCheckpointNs??null},checkpoints:rt,metadata:W,isLoading:D,isHistoryLoading:ye,error:H,hasMore:ne,loadOlder:qm,seedFromSnapshot:Gm,clearState:pt,navigateToCheckpoint:Vm,returnToLatest:Km,loadThread:Yn,clearThread:Wm,respondToInterrupt:Ym}},[Wm,pt,E,V,ne,ye,D,qm,Yn,U.assemblingId,U.lastBranch,U.lastCheckpointId,U.lastCheckpointNs,U.messages,Vm,Ym,Km,Gm,H,rt]),yT=b.useMemo(()=>({isStreaming:Lt,error:xr,connectionState:qn,submit:Go,send:Go,stop:Gn,setAuthToken:J}),[qn,Lt,xr,Gn,Go,J]);return u.jsx(Sx.Provider,{value:!0,children:u.jsx(du.Provider,{value:yT,children:u.jsx(cu.Provider,{value:mT,children:u.jsx(uu.Provider,{value:gT,children:e})})})})}function gs(){const e=b.useContext(cu);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function ys(){const e=b.useContext(uu);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function fu(){const e=b.useContext(du);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function xs({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(Iy,{apiConfig:t,children:u.jsx(Cx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onAuthError:l,onThreadChange:c,children:e})})}function oe(...e){return Qm.twMerge(Zm.clsx(e))}const kx=Yo.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"}}),ct=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?wr.Slot:"button";return u.jsx(i,{className:oe(kx({variant:t,size:n,className:e})),ref:s,...o})});ct.displayName="Button";const hu=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}));hu.displayName="Textarea";function pu({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 m=i!==void 0,[g,y]=b.useState(e),x=(m?i:g)??"",[w,C]=b.useTransition(),T=b.useRef(null),k=b.useRef(0),S=b.useRef(null);b.useEffect(()=>{m||(y(e??""),S.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const H=T.current;H&&(H.style.height="auto",H.style.height=`${H.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,x]);const j=b.useCallback((H,{fromUser:R})=>{m||y(H),R&&(a==null||a(H))},[m,a]),_=b.useCallback(async H=>{H&&H.preventDefault();const R=(x??"").trim();if(!R&&!p)return;const V=++k.current;S.current={id:V,shouldClear:!0},C(()=>{var $,F,ne;try{const Q=l(R);Q&&typeof Q.then=="function"?Q.then(()=>{var ye,Pe;((ye=S.current)==null?void 0:ye.id)===V&&S.current.shouldClear&&(m||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((Pe=S.current)==null?void 0:Pe.id)===V&&(S.current=null)}).catch(()=>{var ye;((ye=S.current)==null?void 0:ye.id)===V&&(S.current=null)}):((($=S.current)==null?void 0:$.id)===V&&S.current.shouldClear&&(m||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((F=S.current)==null?void 0:F.id)===V&&(S.current=null))}catch{((ne=S.current)==null?void 0:ne.id)===V&&(S.current=null)}})},[x,l,p,m,a]),P=b.useCallback(H=>{const R=H.target.value;j(R,{fromUser:!0}),S.current&&(S.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[j]),D=b.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(hu,{ref:T,value:x,onChange:P,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(ct,{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(ct,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!p||w,children:u.jsx(he.Send,{size:16})})})]})})}const Tx=b.memo(pu);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 mu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ha(...e){return t=>{let n=!1;const r=e.map(o=>{const s=mu(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():mu(e[o],null)}}}}function Je(...e){return v.useCallback(ha(...e),e)}function Ex(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 Zn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:h,children:p,...m}=f,g=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(g.Provider,{value:y,children:p})};c.displayName=s+"Provider";function d(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,m=v.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Ix(o,...t)]}function Ix(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var qt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},Nx=v[" useInsertionEffect ".trim().toString()]||qt;function Kr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Ax({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=_x(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 Ax({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Nx(()=>{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 _x(e){return typeof e=="function"}var jx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],De=jx.reduce((e,t)=>{const n=wr.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 gu(e,t){e&&Xo.flushSync(()=>e.dispatchEvent(t))}function pa(e){const t=e+"CollectionProvider",[n,r]=Zn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,w=b.useRef(null),C=b.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:C,collectionRef:w,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=wr.createSlot(a),c=b.forwardRef((g,y)=>{const{scope:x,children:w}=g,C=s(a,x),T=Je(y,C.collectionRef);return u.jsx(l,{ref:T,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=wr.createSlot(d),p=b.forwardRef((g,y)=>{const{scope:x,children:w,...C}=g,T=b.useRef(null),k=Je(y,T),S=s(d,x);return b.useEffect(()=>(S.itemMap.set(T,{ref:T,...C}),()=>void S.itemMap.delete(T))),u.jsx(h,{[f]:"",ref:k,children:w})});p.displayName=d;function m(g){const y=s(e+"CollectionConsumer",g);return b.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const C=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((S,E)=>C.indexOf(S.ref.current)-C.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},m,r]}var Px=v.createContext(void 0);function vs(e){const t=v.useContext(Px);return e||t||"ltr"}function Gt(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 Rx(e,t=globalThis==null?void 0:globalThis.document){const n=Gt(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 Ox="DismissableLayer",ma="dismissableLayer.update",Mx="dismissableLayer.pointerDownOutside",Dx="dismissableLayer.focusOutside",yu,xu=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),ws=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(xu),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),m=Je(t,E=>f(E)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),w=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,T=w>=x,k=$x(E=>{const j=E.target,_=[...c.branches].some(P=>P.contains(j));!T||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),S=zx(E=>{const j=E.target;[...c.branches].some(P=>P.contains(j))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return Rx(E=>{w===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&&(yu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),vu(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=yu)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),vu())},[d,c]),v.useEffect(()=>{const E=()=>p({});return document.addEventListener(ma,E),()=>document.removeEventListener(ma,E)},[]),u.jsx(De.div,{...l,ref:m,style:{pointerEvents:C?T?"auto":"none":void 0,...e.style},onFocusCapture:ge(e.onFocusCapture,S.onFocusCapture),onBlurCapture:ge(e.onBlurCapture,S.onBlurCapture),onPointerDownCapture:ge(e.onPointerDownCapture,k.onPointerDownCapture)})});ws.displayName=Ox;var Lx="DismissableLayerBranch",Fx=v.forwardRef((e,t)=>{const n=v.useContext(xu),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(De.div,{...e,ref:o})});Fx.displayName=Lx;function $x(e,t=globalThis==null?void 0:globalThis.document){const n=Gt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){wu(Mx,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 zx(e,t=globalThis==null?void 0:globalThis.document){const n=Gt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&wu(Dx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function vu(){const e=new CustomEvent(ma);document.dispatchEvent(e)}function wu(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?gu(o,s):o.dispatchEvent(s)}var ga=0;function ya(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??bu()),document.body.insertAdjacentElement("beforeend",e[1]??bu()),ga++,()=>{ga===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ga--}},[])}function bu(){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 xa="focusScope.autoFocusOnMount",va="focusScope.autoFocusOnUnmount",Su={bubbles:!1,cancelable:!0},Bx="FocusScope",bs=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Gt(o),d=Gt(s),f=v.useRef(null),h=Je(t,g=>l(g)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let g=function(C){if(p.paused||!a)return;const T=C.target;a.contains(T)?f.current=T:ir(f.current,{select:!0})},y=function(C){if(p.paused||!a)return;const T=C.relatedTarget;T!==null&&(a.contains(T)||ir(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const k of C)k.removedNodes.length>0&&ir(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const w=new MutationObserver(x);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),w.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){Tu.add(p);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(xa,Su);a.addEventListener(xa,c),a.dispatchEvent(x),x.defaultPrevented||(Hx(qx(Cu(a)),{select:!0}),document.activeElement===g&&ir(a))}return()=>{a.removeEventListener(xa,c),setTimeout(()=>{const x=new CustomEvent(va,Su);a.addEventListener(va,d),a.dispatchEvent(x),x.defaultPrevented||ir(g??document.body,{select:!0}),a.removeEventListener(va,d),Tu.remove(p)},0)}}},[a,c,d,p]);const m=v.useCallback(g=>{if(!n&&!r||p.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const w=g.currentTarget,[C,T]=Ux(w);C&&T?!g.shiftKey&&x===T?(g.preventDefault(),n&&ir(C,{select:!0})):g.shiftKey&&x===C&&(g.preventDefault(),n&&ir(T,{select:!0})):x===w&&g.preventDefault()}},[n,r,p.paused]);return u.jsx(De.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});bs.displayName=Bx;function Hx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(ir(r,{select:t}),document.activeElement!==n)return}function Ux(e){const t=Cu(e),n=ku(t,e),r=ku(t.reverse(),e);return[n,r]}function Cu(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 ku(e,t){for(const n of e)if(!Wx(n,{upTo:t}))return n}function Wx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Vx(e){return e instanceof HTMLInputElement&&"select"in e}function ir(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Vx(e)&&t&&e.select()}}var Tu=Kx();function Kx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Eu(e,t),e.unshift(t)},remove(t){var n;e=Eu(e,t),(n=e[0])==null||n.resume()}}}function Eu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function qx(e){return e.filter(t=>t.tagName!=="A")}var Gx=v[" useId ".trim().toString()]||(()=>{}),Yx=0;function Qn(e){const[t,n]=v.useState(Gx());return qt(()=>{n(r=>r??String(Yx++))},[e]),t?`radix-${t}`:""}const Xx=["top","right","bottom","left"],ar=Math.min,pn=Math.max,Ss=Math.round,Cs=Math.floor,Fn=e=>({x:e,y:e}),Jx={left:"right",right:"left",bottom:"top",top:"bottom"},Zx={start:"end",end:"start"};function wa(e,t,n){return pn(e,ar(t,n))}function er(e,t){return typeof e=="function"?e(t):e}function tr(e){return e.split("-")[0]}function qr(e){return e.split("-")[1]}function ba(e){return e==="x"?"y":"x"}function Sa(e){return e==="y"?"height":"width"}const Qx=new Set(["top","bottom"]);function $n(e){return Qx.has(tr(e))?"y":"x"}function Ca(e){return ba($n(e))}function ev(e,t,n){n===void 0&&(n=!1);const r=qr(e),o=Ca(e),s=Sa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=ks(i)),[i,ks(i)]}function tv(e){const t=ks(e);return[ka(e),t,ka(t)]}function ka(e){return e.replace(/start|end/g,t=>Zx[t])}const Iu=["left","right"],Nu=["right","left"],nv=["top","bottom"],rv=["bottom","top"];function ov(e,t,n){switch(e){case"top":case"bottom":return n?t?Nu:Iu:t?Iu:Nu;case"left":case"right":return t?nv:rv;default:return[]}}function sv(e,t,n,r){const o=qr(e);let s=ov(tr(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ka)))),s}function ks(e){return e.replace(/left|right|bottom|top/g,t=>Jx[t])}function iv(e){return{top:0,right:0,bottom:0,left:0,...e}}function Au(e){return typeof e!="number"?iv(e):{top:e,right:e,bottom:e,left:e}}function Ts(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 _u(e,t,n){let{reference:r,floating:o}=e;const s=$n(t),i=Ca(t),a=Sa(i),l=tr(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(qr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const av=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}=_u(c,r,l),h=r,p={},m=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:w,y:C,data:T,reset:k}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=C??f,p={...p,[y]:{...p[y],...T}},k&&m<=50&&(m++,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}=_u(c,h,l)),g=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function xo(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}=er(t,e),m=Au(p),y=a[h?f==="floating"?"reference":"floating":f],x=Ts(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})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),T=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},k=Ts(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:C,strategy:l}):w);return{top:(x.top-k.top+m.top)/T.y,bottom:(k.bottom-x.bottom+m.bottom)/T.y,left:(x.left-k.left+m.left)/T.x,right:(k.right-x.right+m.right)/T.x}}const lv=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}=er(e,t)||{};if(c==null)return{};const f=Au(d),h={x:n,y:r},p=Ca(o),m=Sa(p),g=await i.getDimensions(c),y=p==="y",x=y?"top":"left",w=y?"bottom":"right",C=y?"clientHeight":"clientWidth",T=s.reference[m]+s.reference[p]-h[p]-s.floating[m],k=h[p]-s.reference[p],S=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=S?S[C]:0;(!E||!await(i.isElement==null?void 0:i.isElement(S)))&&(E=a.floating[C]||s.floating[m]);const j=T/2-k/2,_=E/2-g[m]/2-1,P=ar(f[x],_),D=ar(f[w],_),z=P,B=E-g[m]-D,O=E/2-g[m]/2+j,H=wa(z,O,B),R=!l.arrow&&qr(o)!=null&&O!==H&&s.reference[m]/2-(O<z?P:D)-g[m]/2<0,V=R?O<z?O-z:O-B:0;return{[p]:h[p]+V,data:{[p]:H,centerOffset:O-H-V,...R&&{alignmentOffset:V}},reset:R}}}),cv=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:m="none",flipAlignment:g=!0,...y}=er(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=tr(o),w=$n(a),C=tr(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(C||!g?[ks(a)]:tv(a)),S=m!=="none";!h&&S&&k.push(...sv(a,g,m,T));const E=[a,...k],j=await xo(t,y),_=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(j[x]),f){const O=ev(o,i,T);_.push(j[O[0]],j[O[1]])}if(P=[...P,{placement:o,overflows:_}],!_.every(O=>O<=0)){var D,z;const O=(((D=s.flip)==null?void 0:D.index)||0)+1,H=E[O];if(H&&(!(f==="alignment"?w!==$n(H):!1)||P.every($=>$n($.placement)===w?$.overflows[0]>0:!0)))return{data:{index:O,overflows:P},reset:{placement:H}};let R=(z=P.filter(V=>V.overflows[0]<=0).sort((V,$)=>V.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!R)switch(p){case"bestFit":{var B;const V=(B=P.filter($=>{if(S){const F=$n($.placement);return F===w||F==="y"}return!0}).map($=>[$.placement,$.overflows.filter(F=>F>0).reduce((F,ne)=>F+ne,0)]).sort(($,F)=>$[1]-F[1])[0])==null?void 0:B[0];V&&(R=V);break}case"initialPlacement":R=a;break}if(o!==R)return{reset:{placement:R}}}return{}}}};function ju(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pu(e){return Xx.some(t=>e[t]>=0)}const uv=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=er(e,t);switch(r){case"referenceHidden":{const s=await xo(t,{...o,elementContext:"reference"}),i=ju(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pu(i)}}}case"escaped":{const s=await xo(t,{...o,altBoundary:!0}),i=ju(s,n.floating);return{data:{escapedOffsets:i,escaped:Pu(i)}}}default:return{}}}}},Ru=new Set(["left","top"]);async function dv(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=tr(n),a=qr(n),l=$n(n)==="y",c=Ru.has(i)?-1:1,d=s&&l?-1:1,f=er(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const fv=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 dv(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}}}}},hv=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,y:w}=y;return{x,y:w}}},...l}=er(e,t),c={x:n,y:r},d=await xo(t,l),f=$n(tr(o)),h=ba(f);let p=c[h],m=c[f];if(s){const y=h==="y"?"top":"left",x=h==="y"?"bottom":"right",w=p+d[y],C=p-d[x];p=wa(w,p,C)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",w=m+d[y],C=m-d[x];m=wa(w,m,C)}const g=a.fn({...t,[h]:p,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},pv=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}=er(e,t),d={x:n,y:r},f=$n(o),h=ba(f);let p=d[h],m=d[f];const g=er(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=h==="y"?"height":"width",T=s.reference[h]-s.floating[C]+y.mainAxis,k=s.reference[h]+s.reference[C]-y.mainAxis;p<T?p=T:p>k&&(p=k)}if(c){var x,w;const C=h==="y"?"width":"height",T=Ru.has(tr(o)),k=s.reference[f]-s.floating[C]+(T&&((x=i.offset)==null?void 0:x[f])||0)+(T?0:y.crossAxis),S=s.reference[f]+s.reference[C]+(T?0:((w=i.offset)==null?void 0:w[f])||0)-(T?y.crossAxis:0);m<k?m=k:m>S&&(m=S)}return{[h]:p,[f]:m}}}},mv=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}=er(e,t),d=await xo(t,c),f=tr(o),h=qr(o),p=$n(o)==="y",{width:m,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=h==="end"?"top":"bottom");const w=g-d.top-d.bottom,C=m-d.left-d.right,T=ar(g-d[y],w),k=ar(m-d[x],C),S=!t.middlewareData.shift;let E=T,j=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),S&&!h){const P=pn(d.left,0),D=pn(d.right,0),z=pn(d.top,0),B=pn(d.bottom,0);p?j=m-2*(P!==0||D!==0?P+D:pn(d.left,d.right)):E=g-2*(z!==0||B!==0?z+B:pn(d.top,d.bottom))}await l({...t,availableWidth:j,availableHeight:E});const _=await i.getDimensions(a.floating);return m!==_.width||g!==_.height?{reset:{rects:!0}}:{}}}};function Es(){return typeof window<"u"}function Gr(e){return Ou(e)?(e.nodeName||"").toLowerCase():"#document"}function mn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function zn(e){var t;return(t=(Ou(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Ou(e){return Es()?e instanceof Node||e instanceof mn(e).Node:!1}function _n(e){return Es()?e instanceof Element||e instanceof mn(e).Element:!1}function Bn(e){return Es()?e instanceof HTMLElement||e instanceof mn(e).HTMLElement:!1}function Mu(e){return!Es()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof mn(e).ShadowRoot}const gv=new Set(["inline","contents"]);function vo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=jn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!gv.has(o)}const yv=new Set(["table","td","th"]);function xv(e){return yv.has(Gr(e))}const vv=[":popover-open",":modal"];function Is(e){return vv.some(t=>{try{return e.matches(t)}catch{return!1}})}const wv=["transform","translate","scale","rotate","perspective"],bv=["transform","translate","scale","rotate","perspective","filter"],Sv=["paint","layout","strict","content"];function Ta(e){const t=Ea(),n=_n(e)?jn(e):e;return wv.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)||bv.some(r=>(n.willChange||"").includes(r))||Sv.some(r=>(n.contain||"").includes(r))}function Cv(e){let t=lr(e);for(;Bn(t)&&!Yr(t);){if(Ta(t))return t;if(Is(t))return null;t=lr(t)}return null}function Ea(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const kv=new Set(["html","body","#document"]);function Yr(e){return kv.has(Gr(e))}function jn(e){return mn(e).getComputedStyle(e)}function Ns(e){return _n(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function lr(e){if(Gr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Mu(e)&&e.host||zn(e);return Mu(t)?t.host:t}function Du(e){const t=lr(e);return Yr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Bn(t)&&vo(t)?t:Du(t)}function wo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Du(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=mn(o);if(s){const a=Ia(i);return t.concat(i,i.visualViewport||[],vo(o)?o:[],a&&n?wo(a):[])}return t.concat(o,wo(o,[],n))}function Ia(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Lu(e){const t=jn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Bn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Ss(n)!==s||Ss(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Na(e){return _n(e)?e:e.contextElement}function Xr(e){const t=Na(e);if(!Bn(t))return Fn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Lu(t);let i=(s?Ss(n.width):n.width)/r,a=(s?Ss(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Tv=Fn(0);function Fu(e){const t=mn(e);return!Ea()||!t.visualViewport?Tv:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ev(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==mn(e)?!1:t}function Tr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Na(e);let i=Fn(1);t&&(r?_n(r)&&(i=Xr(r)):i=Xr(e));const a=Ev(s,n,r)?Fu(s):Fn(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&&_n(r)?mn(r):r;let m=h,g=Ia(m);for(;g&&r&&p!==m;){const y=Xr(g),x=g.getBoundingClientRect(),w=jn(g),C=x.left+(g.clientLeft+parseFloat(w.paddingLeft))*y.x,T=x.top+(g.clientTop+parseFloat(w.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=C,c+=T,m=mn(g),g=Ia(m)}}return Ts({width:d,height:f,x:l,y:c})}function As(e,t){const n=Ns(e).scrollLeft;return t?t.left+n:Tr(zn(e)).left+n}function $u(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-As(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Iv(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=zn(r),a=t?Is(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=Fn(1);const d=Fn(0),f=Bn(r);if((f||!f&&!s)&&((Gr(r)!=="body"||vo(i))&&(l=Ns(r)),Bn(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?$u(i,l):Fn(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 Nv(e){return Array.from(e.getClientRects())}function Av(e){const t=zn(e),n=Ns(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+As(e);const a=-n.scrollTop;return jn(r).direction==="rtl"&&(i+=pn(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const zu=25;function _v(e,t){const n=mn(e),r=zn(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=Ea();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=As(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,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=zu&&(s-=m)}else c<=zu&&(s+=c);return{width:s,height:i,x:a,y:l}}const jv=new Set(["absolute","fixed"]);function Pv(e,t){const n=Tr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Bn(e)?Xr(e):Fn(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 Bu(e,t,n){let r;if(t==="viewport")r=_v(e,n);else if(t==="document")r=Av(zn(e));else if(_n(t))r=Pv(t,n);else{const o=Fu(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ts(r)}function Hu(e,t){const n=lr(e);return n===t||!_n(n)||Yr(n)?!1:jn(n).position==="fixed"||Hu(n,t)}function Rv(e,t){const n=t.get(e);if(n)return n;let r=wo(e,[],!1).filter(a=>_n(a)&&Gr(a)!=="body"),o=null;const s=jn(e).position==="fixed";let i=s?lr(e):e;for(;_n(i)&&!Yr(i);){const a=jn(i),l=Ta(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&jv.has(o.position)||vo(i)&&!l&&Hu(e,i))?r=r.filter(d=>d!==i):o=a,i=lr(i)}return t.set(e,r),r}function Ov(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Is(t)?[]:Rv(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Bu(t,d,o);return c.top=pn(f.top,c.top),c.right=ar(f.right,c.right),c.bottom=ar(f.bottom,c.bottom),c.left=pn(f.left,c.left),c},Bu(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Mv(e){const{width:t,height:n}=Lu(e);return{width:t,height:n}}function Dv(e,t,n){const r=Bn(t),o=zn(t),s=n==="fixed",i=Tr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=Fn(0);function c(){l.x=As(o)}if(r||!r&&!s)if((Gr(t)!=="body"||vo(o))&&(a=Ns(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?$u(o,a):Fn(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 Aa(e){return jn(e).position==="static"}function Uu(e,t){if(!Bn(e)||jn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return zn(e)===n&&(n=n.ownerDocument.body),n}function Wu(e,t){const n=mn(e);if(Is(e))return n;if(!Bn(e)){let o=lr(e);for(;o&&!Yr(o);){if(_n(o)&&!Aa(o))return o;o=lr(o)}return n}let r=Uu(e,t);for(;r&&xv(r)&&Aa(r);)r=Uu(r,t);return r&&Yr(r)&&Aa(r)&&!Ta(r)?n:r||Cv(e)||n}const Lv=async function(e){const t=this.getOffsetParent||Wu,n=this.getDimensions,r=await n(e.floating);return{reference:Dv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Fv(e){return jn(e).direction==="rtl"}const $v={convertOffsetParentRelativeRectToViewportRelativeRect:Iv,getDocumentElement:zn,getClippingRect:Ov,getOffsetParent:Wu,getElementRects:Lv,getClientRects:Nv,getDimensions:Mv,getScale:Xr,isElement:_n,isRTL:Fv};function Vu(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function zv(e,t){let n=null,r;const o=zn(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 m=Cs(f),g=Cs(o.clientWidth-(d+h)),y=Cs(o.clientHeight-(f+p)),x=Cs(d),C={rootMargin:-m+"px "+-g+"px "+-y+"px "+-x+"px",threshold:pn(0,ar(1,l))||1};let T=!0;function k(S){const E=S[0].intersectionRatio;if(E!==l){if(!T)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Vu(c,e.getBoundingClientRect())&&i(),T=!1}try{n=new IntersectionObserver(k,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,C)}n.observe(e)}return i(!0),s}function Bv(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=Na(e),d=o||s?[...c?wo(c):[],...wo(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?zv(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[w]=x;w&&w.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var C;(C=p)==null||C.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let m,g=l?Tr(e):null;l&&y();function y(){const x=Tr(e);g&&!Vu(g,x)&&n(),g=x,m=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const Hv=fv,Uv=hv,Wv=cv,Vv=mv,Kv=uv,Ku=lv,qv=pv,Gv=(e,t,n)=>{const r=new Map,o={platform:$v,...n},s={...o.platform,_c:r};return av(e,t,{...o,platform:s})};var Yv=typeof document<"u",Xv=function(){},_s=Yv?b.useLayoutEffect:Xv;function js(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(!js(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)&&!js(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function qu(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Gu(e,t){const n=qu(e);return Math.round(t*n)/n}function _a(e){const t=v.useRef(e);return _s(()=>{t.current=e}),t}function Jv(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);js(h,r)||p(r);const[m,g]=v.useState(null),[y,x]=v.useState(null),w=v.useCallback($=>{$!==S.current&&(S.current=$,g($))},[]),C=v.useCallback($=>{$!==E.current&&(E.current=$,x($))},[]),T=s||m,k=i||y,S=v.useRef(null),E=v.useRef(null),j=v.useRef(d),_=l!=null,P=_a(l),D=_a(o),z=_a(c),B=v.useCallback(()=>{if(!S.current||!E.current)return;const $={placement:t,strategy:n,middleware:h};D.current&&($.platform=D.current),Gv(S.current,E.current,$).then(F=>{const ne={...F,isPositioned:z.current!==!1};O.current&&!js(j.current,ne)&&(j.current=ne,Xo.flushSync(()=>{f(ne)}))})},[h,t,n,D,z]);_s(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[c]);const O=v.useRef(!1);_s(()=>(O.current=!0,()=>{O.current=!1}),[]),_s(()=>{if(T&&(S.current=T),k&&(E.current=k),T&&k){if(P.current)return P.current(T,k,B);B()}},[T,k,B,P,_]);const H=v.useMemo(()=>({reference:S,floating:E,setReference:w,setFloating:C}),[w,C]),R=v.useMemo(()=>({reference:T,floating:k}),[T,k]),V=v.useMemo(()=>{const $={position:n,left:0,top:0};if(!R.floating)return $;const F=Gu(R.floating,d.x),ne=Gu(R.floating,d.y);return a?{...$,transform:"translate("+F+"px, "+ne+"px)",...qu(R.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:ne}},[n,a,R.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:B,refs:H,elements:R,floatingStyles:V}),[d,B,H,R,V])}const Zv=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?Ku({element:r.current,padding:o}).fn(n):{}:r?Ku({element:r,padding:o}).fn(n):{}}}},Qv=(e,t)=>({...Hv(e),options:[e,t]}),ew=(e,t)=>({...Uv(e),options:[e,t]}),tw=(e,t)=>({...qv(e),options:[e,t]}),nw=(e,t)=>({...Wv(e),options:[e,t]}),rw=(e,t)=>({...Vv(e),options:[e,t]}),ow=(e,t)=>({...Kv(e),options:[e,t]}),sw=(e,t)=>({...Zv(e),options:[e,t]});var iw="Arrow",Yu=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"})})});Yu.displayName=iw;var aw=Yu;function Xu(e){const[t,n]=v.useState(void 0);return qt(()=>{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 ja="Popper",[Ju,Ps]=Zn(ja),[lw,Zu]=Ju(ja),Qu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(lw,{scope:t,anchor:r,onAnchorChange:o,children:n})};Qu.displayName=ja;var ed="PopperAnchor",td=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Zu(ed,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(De.div,{...o,ref:a})});td.displayName=ed;var Pa="PopperContent",[cw,uw]=Ju(Pa),nd=v.forwardRef((e,t)=>{var te,L,G,se,le,U;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:m,...g}=e,y=Zu(Pa,n),[x,w]=v.useState(null),C=Je(t,We=>w(We)),[T,k]=v.useState(null),S=Xu(T),E=(S==null?void 0:S.width)??0,j=(S==null?void 0:S.height)??0,_=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},D=Array.isArray(c)?c:[c],z=D.length>0,B={padding:P,boundary:D.filter(fw),altBoundary:z},{refs:O,floatingStyles:H,placement:R,isPositioned:V,middlewareData:$}=Jv({strategy:"fixed",placement:_,whileElementsMounted:(...We)=>Bv(...We,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[Qv({mainAxis:o+j,alignmentAxis:i}),l&&ew({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?tw():void 0,...B}),l&&nw({...B}),rw({...B,apply:({elements:We,rects:re,availableWidth:xe,availableHeight:Re})=>{const{width:Fe,height:tt}=re.reference,Se=We.floating.style;Se.setProperty("--radix-popper-available-width",`${xe}px`),Se.setProperty("--radix-popper-available-height",`${Re}px`),Se.setProperty("--radix-popper-anchor-width",`${Fe}px`),Se.setProperty("--radix-popper-anchor-height",`${tt}px`)}}),T&&sw({element:T,padding:a}),hw({arrowWidth:E,arrowHeight:j}),h&&ow({strategy:"referenceHidden",...B})]}),[F,ne]=sd(R),Q=Gt(m);qt(()=>{V&&(Q==null||Q())},[V,Q]);const ye=(te=$.arrow)==null?void 0:te.x,Pe=(L=$.arrow)==null?void 0:L.y,Z=((G=$.arrow)==null?void 0:G.centerOffset)!==0,[ue,ke]=v.useState();return qt(()=>{x&&ke(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...H,transform:V?H.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ue,"--radix-popper-transform-origin":[(se=$.transformOrigin)==null?void 0:se.x,(le=$.transformOrigin)==null?void 0:le.y].join(" "),...((U=$.hide)==null?void 0:U.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(cw,{scope:n,placedSide:F,onArrowChange:k,arrowX:ye,arrowY:Pe,shouldHideArrow:Z,children:u.jsx(De.div,{"data-side":F,"data-align":ne,...g,ref:C,style:{...g.style,animation:V?void 0:"none"}})})})});nd.displayName=Pa;var rd="PopperArrow",dw={top:"bottom",right:"left",bottom:"top",left:"right"},od=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=uw(rd,r),i=dw[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(aw,{...o,ref:n,style:{...o.style,display:"block"}})})});od.displayName=rd;function fw(e){return e!==null}var hw=e=>({name:"transformOrigin",options:e,fn(t){var y,x,w;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]=sd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",g="";return c==="bottom"?(m=i?f:`${h}px`,g=`${-l}px`):c==="top"?(m=i?f:`${h}px`,g=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,g=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,g=i?f:`${p}px`),{data:{x:m,y:g}}}});function sd(e){const[t,n="center"]=e.split("-");return[t,n]}var id=Qu,ad=td,ld=nd,cd=od,pw="Portal",Rs=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);qt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ri.createPortal(u.jsx(De.div,{...r,ref:t}),i):null});Rs.displayName=pw;function mw(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var bn=e=>{const{present:t,children:n}=e,r=gw(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};bn.displayName="Presence";function gw(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=mw(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Os(r.current);s.current=a==="mounted"?c:"none"},[a]),qt(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=Os(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]),qt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const g=Os(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(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=Os(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 Os(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 Ra="rovingFocusGroup.onEntryFocus",xw={bubbles:!1,cancelable:!0},bo="RovingFocusGroup",[Oa,ud,vw]=pa(bo),[ww,dd]=Zn(bo,[vw]),[bw,Sw]=ww(bo),fd=v.forwardRef((e,t)=>u.jsx(Oa.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Oa.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Cw,{...e,ref:t})})}));fd.displayName=bo;var Cw=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),m=vs(s),[g,y]=Kr({prop:i,defaultProp:a??null,onChange:l,caller:bo}),[x,w]=v.useState(!1),C=Gt(c),T=ud(n),k=v.useRef(!1),[S,E]=v.useState(0);return v.useEffect(()=>{const j=h.current;if(j)return j.addEventListener(Ra,C),()=>j.removeEventListener(Ra,C)},[C]),u.jsx(bw,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:v.useCallback(j=>y(j),[y]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>E(j=>j-1),[]),children:u.jsx(De.div,{tabIndex:x||S===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,j=>{const _=!k.current;if(j.target===j.currentTarget&&_&&!x){const P=new CustomEvent(Ra,xw);if(j.currentTarget.dispatchEvent(P),!P.defaultPrevented){const D=T().filter(R=>R.focusable),z=D.find(R=>R.active),B=D.find(R=>R.id===g),H=[z,B,...D].filter(Boolean).map(R=>R.ref.current);md(H,d)}}k.current=!1}),onBlur:ge(e.onBlur,()=>w(!1))})})}),hd="RovingFocusGroupItem",pd=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Qn(),c=s||l,d=Sw(hd,n),f=d.currentTabStopId===c,h=ud(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:g}=d;return v.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),u.jsx(Oa.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: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 x=Ew(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let C=h().filter(T=>T.focusable).map(T=>T.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const T=C.indexOf(y.currentTarget);C=d.loop?Iw(C,T+1):C.slice(T+1)}setTimeout(()=>md(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});pd.displayName=hd;var kw={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Tw(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Ew(e,t,n){const r=Tw(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return kw[r]}function md(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Iw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Nw=fd,Aw=pd,_w=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Jr=new WeakMap,Ms=new WeakMap,Ds={},Ma=0,gd=function(e){return e&&(e.host||gd(e.parentNode))},jw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=gd(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})},Pw=function(e,t,n,r){var o=jw(t,Array.isArray(e)?e:[e]);Ds[n]||(Ds[n]=new WeakMap);var s=Ds[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),m=p!==null&&p!=="false",g=(Jr.get(h)||0)+1,y=(s.get(h)||0)+1;Jr.set(h,g),s.set(h,y),i.push(h),g===1&&m&&Ms.set(h,!0),y===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),Ma++,function(){i.forEach(function(f){var h=Jr.get(f)-1,p=s.get(f)-1;Jr.set(f,h),s.set(f,p),h||(Ms.has(f)||f.removeAttribute(r),Ms.delete(f)),p||f.removeAttribute(n)}),Ma--,Ma||(Jr=new WeakMap,Jr=new WeakMap,Ms=new WeakMap,Ds={})}},Da=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=_w(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Pw(r,o,n,"aria-hidden")):function(){return null}},Hn=function(){return Hn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Hn.apply(this,arguments)};function yd(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 Rw(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",Ow="with-scroll-bars-hidden",Mw="--removed-body-scroll-bar-size";function La(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Dw(e,t){var n=b.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 Lw=typeof window<"u"?v.useLayoutEffect:v.useEffect,xd=new WeakMap;function Fw(e,t){var n=Dw(null,function(r){return e.forEach(function(o){return La(o,r)})});return Lw(function(){var r=xd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||La(a,null)}),s.forEach(function(a){o.has(a)||La(a,i)})}xd.set(n,e)},[e]),n}function $w(e){return e}function zw(e,t){t===void 0&&(t=$w);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 Bw(e){e===void 0&&(e={});var t=zw(null);return t.options=Hn({async:!0,ssr:!1},e),t}var vd=function(e){var t=e.sideCar,n=yd(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,Hn({},n))};vd.isSideCarExport=!0;function Hw(e,t){return e.useMedium(t),vd}var wd=Bw(),Fa=function(){},$s=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Fa,onWheelCapture:Fa,onTouchMoveCapture:Fa}),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,m=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,w=x===void 0?"div":x,C=e.gapMode,T=yd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,S=Fw([n,t]),E=Hn(Hn({},T),o);return v.createElement(v.Fragment,null,d&&v.createElement(k,{sideCar:wd,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:C}),i?v.cloneElement(v.Children.only(a),Hn(Hn({},E),{ref:S})):v.createElement(w,Hn({},E,{className:l,ref:S}),a))});$s.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},$s.classNames={fullWidth:Fs,zeroRight:Ls};var Uw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ww(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Uw();return t&&e.setAttribute("nonce",t),e}function Vw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Kw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var qw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Ww())&&(Vw(t,n),Kw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Gw=function(){var e=qw();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},bd=function(){var e=Gw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Yw={left:0,top:0,right:0,gap:0},$a=function(e){return parseInt(e||"",10)||0},Xw=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)]},Jw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Yw;var t=Xw(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])}},Zw=bd(),Zr="data-scroll-locked",Qw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
39
- .`.concat(Ow,` {
37
+ `))>=0;){const pt=St.slice(0,ve);St=St.slice(ve+2);const mt=tx(pt);if(!mt)continue;let ct;try{ct=JSON.parse(mt)}catch{console.debug("[use-chat] malformed SSE:",mt.slice(0,200));continue}const Me=ex(ct)?ct.data:ct;Yt=Date.now();const Ut=Me.seq;if(Ut!==void 0){if(Ut<=yt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Ut,lastProcessedSeq:yt,type:Me.type});continue}yt>0&&Ut>yt+1&&((L=R==null?void 0:R.onGap)==null||L.call(R,{from:yt,to:Ut})),yt=Ut,k.current=Ut,y(Ut)}if(console.debug("[use-chat] received event",{seq:Me.seq,type:Me.type,preview:(()=>{var Le;try{return Me.type==="message_delta"?{deltaTypes:(Le=Me.delta)==null?void 0:Le.map(xt=>xt.type),textLen:(Me.delta||[]).filter(xt=>xt.type==="text").map(xt=>String(xt.text||"").length)}:Me.content||Me.delta?{hasContent:!0}:{}}catch(xt){return{err:String(xt)}}})()}),Me.type==="checkpoint")E.current=Me.checkpointId??null,j.current=Me.checkpointNs??null,m(Me.checkpointId??null);else if(Me.type==="state_history"){_.current=Me;try{const xt=ls(Me).latest;xt&&(E.current=xt.checkpointId??null,j.current=xt.checkpointNs??null,m(xt.checkpointId??null))}catch(Le){console.warn("[use-chat] Failed to hydrate state_history payload",Le)}}try{H==null||H(Me)}catch(Le){console.error("[use-chat] Error in onEvent callback:",Le,"for event:",Me.type)}if(Me.type==="token"&&e.autoAppendAssistant!==!1)nt.push(Me.content),Gt();else if(Me.type==="message_delta"){const Le=Me.delta.filter(xt=>xt.type==="text").map(xt=>xt.text).join("");Le&&e.autoAppendAssistant!==!1&&(nt.push(Le),Gt())}else if(Me.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(q=R==null?void 0:R.onHeartbeat)==null||q.call(R,Me)}catch(Le){console.warn("[use-chat] heartbeat callback failed",Le)}}else if(Nt!==null&&cancelAnimationFrame(Nt),st(),Me.type==="checkpoint")m(Me.checkpointId);else if(Me.type==="error"){const Le=Me;if(d(Le.message),$="error",F=Le.message,Le.error_type==="auth_error"||Le.code==="TOKEN_EXPIRED"||((ie=Le.message)==null?void 0:ie.includes("token"))||((ce=Le.message)==null?void 0:ce.includes("401"))||((U=Le.message)==null?void 0:U.includes("unauthorized"))||((We=Le.message)==null?void 0:We.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Le.message);try{(re=R==null?void 0:R.onAuthError)==null||re.call(R,Le.message)}catch(Ln){console.warn("[use-chat] onAuthError handler failed",Ln)}V.abort()}}}}st(),$===null&&!V.signal.aborted&&($="complete")}catch(ft){if(ft.name==="AbortError")$=$??"aborted";else{const Ve=ft.message||String(ft);$="error",F=Ve,d(Ve),(xe=R==null?void 0:R.onError)==null||xe.call(R,Ve)}}finally{try{await tt.cancel()}catch{}finally{(Pe=tt.releaseLock)==null||Pe.call(tt)}Nt!==null&&typeof window<"u"&&window.cancelAnimationFrame(Nt),clearInterval(Xt)}}catch(Ye){if(Ye.name==="AbortError")$=$??"aborted";else{const ot=Ye.message||String(Ye);$="error",F=ot,d(ot),($e=R==null?void 0:R.onError)==null||$e.call(R,ot),ne||((rt=R==null?void 0:R.onConnectionError)==null||rt.call(R,ot),ne=!0)}}finally{const Ye=k.current,ot=E.current,et=j.current,Xe=_.current,Ke=$??(V.signal.aborted?"aborted":F?"error":"complete");try{(Se=R==null?void 0:R.onClosed)==null||Se.call(R,{reason:Ke,lastSeq:Ye,lastCheckpointId:ot,lastCheckpointNs:et,lastStateHistory:Xe,error:F})}catch(tt){console.warn("[use-chat] onClosed callback failed",tt)}l(!1),w(!1),C.current=null,k.current=0,y(0),S.current=null}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var O;T.current=!1,(O=C.current)==null||O.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:g,connected:x,stream:B,stop:z,clear:D,setToken:P}}function ex(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function tx(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 ru=200;function nx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),h=b.useRef(null),p=b.useCallback(_=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(_)}catch{}try{return JSON.parse(JSON.stringify(_))}catch{return _}},[]),m=b.useCallback((_,P)=>{if(!_)return;const D=f.current.get(_)??[],z=p(P),B=D.length>=ru?[...D.slice(D.length-ru+1),z]:[...D,z];f.current.set(_,B)},[p]),g=b.useCallback(_=>{_&&f.current.set(_,[])},[]),y=b.useCallback(_=>{const P=_??d.current;if(!P)return;const D=f.current.get(P);D!=null&&D.length&&D.forEach(z=>{try{n(z)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),x=b.useCallback(_=>{var z,B,O,H,R;const P=_.seq??null;if(P!==null){const V=c.current;if(V!==null){if(P<=V)return;P>V+1&&(o==null||o({from:V,to:P}))}c.current=P}if(_.type==="thread_info"){d.current=_.threadId,h.current&&(h.current.threadIdGuess=_.threadId),g(_.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{l==null||l(_)}catch(V){console.error("[useChatStreamingService] Error in onHeartbeat 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"))||((B=V.message)==null?void 0:B.includes("401"))||((O=V.message)==null?void 0:O.includes("unauthorized"))||((H=V.message)==null?void 0:H.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??((R=h.current)==null?void 0:R.threadIdGuess)??null;if(_.type==="state_history"&&(d.current=D??d.current),qy(_)){_.type==="checkpoint"||_.type==="state_history"?g(D??null):m(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)}},[m,g,n,o,t,r]),{stream:w,stop:C,isStreaming:T,error:k,setToken:S}=nu({baseUrl:e,token:void 0}),E=b.useCallback((_,P)=>{c.current=null,d.current=_.threadId??null,h.current={request:_,callbacks:P,manualStop:!1,threadIdGuess:_.threadId??null},w(_,x,{onOpen:P==null?void 0:P.onOpen,onError:D=>{var z;(z=P==null?void 0:P.onError)==null||z.call(P,D)},onGap:(P==null?void 0:P.onGap)??o,onConnectionError:D=>{var z;i==null||i(D),(z=P==null?void 0:P.onConnectionError)==null||z.call(P,D)},onAuthError:D=>{var z;a==null||a(D),(z=P==null?void 0:P.onAuthError)==null||z.call(P,D)},onHeartbeat:D=>{var z;try{l==null||l(D)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(z=P==null?void 0:P.onHeartbeat)==null||z.call(P,D)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:D=>{var H,R,V,$;const z=((H=h.current)==null?void 0:H.manualStop)??!1,B=d.current??((R=h.current)==null?void 0:R.threadIdGuess)??((V=D.lastStateHistory)==null?void 0:V.threadId)??null;(D.reason==="complete"||D.reason==="aborted"&&z)&&g(B);const O={...D,threadId:B,manualStop:z};try{s==null||s(O)}catch(F){console.warn("[useChatStreamingService] onStreamClosed handler failed",F)}try{($=P==null?void 0:P.onClosed)==null||$.call(P,O)}catch(F){console.warn("[useChatStreamingService] downstream onClosed handler failed",F)}h.current&&(h.current=null)}})},[g,x,a,i,l,o,s,w]),j=b.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return b.useMemo(()=>({startStream:E,stop:j,isStreaming:T,error:k,setAuthToken:S,replayBufferedEvents:y}),[E,j,T,k,S,y])}const ou=50,rx=750,na="chat-history@1",ox=5,sx=1e3,ix=15e3,fs=300;function su(e,t=fs){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function Cr(){return typeof window<"u"&&typeof window.localStorage<"u"}function ra(e){if(!Cr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function oa(e,t){if(!Cr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function sa(e){if(Cr())try{window.localStorage.removeItem(e)}catch{}}function ia(e){return e==null?e:{...e}}function ax(e){return e==null?e:{...e}}function lx(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function cx(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function un(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=ia(e==null?void 0:e.metadata),s=ia(e==null?void 0:e.config),i=ia(e==null?void 0:e.parentConfig),a=lx(e==null?void 0:e.next),l=cx(e==null?void 0:e.tasks),c=ax(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 ux(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 iu(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}}function aa(e,t){return`${e}${t}`}function dx(e,t){const n=ra(aa(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:un(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function fx(e,t,n=100){if(!Cr())return;const r=un(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=aa(e,t.threadId),i=JSON.stringify(o);if(!oa(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),oa(s,i))break}catch{}}function hx(e,t){sa(aa(e,t))}function px(e){if(Cr())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{}}function au(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 mx(e,t){return hs(e,t)}function gx(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 yx(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 lu(e,t){const n=hs(e.metadata,t.metadata),r=hs(e.config,t.config),o=hs(e.parentConfig,t.parentConfig),s=gx(e.next,t.next),i=yx(e.tasks,t.tasks),a=mx(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 cu(e){return Array.isArray(e)?e.filter(t=>!!(t&&(t.checkpointId||t.checkpointNs))).map(t=>{const n=un(t,{cloneMessages:!0});return{...n,messages:Array.isArray(n.messages)?n.messages:[],values:n.values??null}}):[]}const xx="cachedThreads",vx="v1",la=200;function wx(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 ca(e,t){return`cachedThreads:v1:${e}:${wx(t||"anon")}`}function bx(){const e=ra(xx);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 Sx(e){const t=ra(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 ua(e,t){oa(e,JSON.stringify(t))}function da(e){const t=Sx(e);if(t.length>0)return t;const n=bx();if(n.length>0)try{ua(e,n.slice(0,la))}catch{}return n}function ps(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 fa(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Cx({currentThreadId:e,currentThreadIdRef:t}){const[n,r]=b.useState([]),o=b.useRef(new Map),s=b.useRef(new Map),i=b.useCallback(m=>{if(!m){r([]);return}const g=o.current.get(m);if(!g||!g.length){r([]);return}r(g.map(y=>un(y,{cloneMessages:!0})))},[]);b.useEffect(()=>{i(e)},[e,i]);const a=b.useCallback((m,g,y)=>{if(!m)return;const x=y==="replace"?[]:o.current.get(m)??[],w=y==="replace"?g:[...g,...x];if(!w.length){y==="replace"&&o.current.set(m,[]),m===t.current&&r([]);return}const C=new Map;for(const k of w){if(!(k!=null&&k.checkpointId))continue;const S=`${k.checkpointId}::${k.checkpointNs??""}`,E=un(k,{cloneMessages:!0}),j=C.get(S);if(!j){C.set(S,E);continue}const _=lu(j,E);C.set(S,{...j,..._})}const T=Array.from(C.values()).sort((k,S)=>{const E=Number.isFinite(Date.parse(k.createdAt??""))?Date.parse(k.createdAt??""):0;return(Number.isFinite(Date.parse(S.createdAt??""))?Date.parse(S.createdAt??""):0)-E});o.current.set(m,T),m===t.current&&i(m)},[t,i]),l=b.useCallback((m,g,y)=>{if(!m)return;const x=s.current.get(m),w=y==="replace"||!x?new Map:new Map(x);if(g&&typeof g=="object")for(const[C,T]of Object.entries(g)){if(!(T!=null&&T.checkpointId))continue;const k=C||Wr(T.checkpointId,T.checkpointNs??null);w.set(k,un(T,{cloneMessages:!0}))}s.current.set(m,w)},[]),c=b.useCallback((m,g)=>{if(!m)return!1;const y=cu(g);if(!y.length)return!1;const x=o.current.get(m)??[],w=new Map,C=(k,{preferExisting:S})=>{for(const E of k){if(!(E!=null&&E.checkpointId)&&!(E!=null&&E.checkpointNs))continue;const j=Wr(E.checkpointId??null,E.checkpointNs??null);j&&(S&&w.has(j)?w.set(j,E):w.has(j)&&S||w.set(j,E))}};C(y,{preferExisting:!1}),C(x,{preferExisting:!0});const T=Array.from(w.values()).sort((k,S)=>{const E=Number.isFinite(Date.parse(k.createdAt??""))?Date.parse(k.createdAt??""):0;return(Number.isFinite(Date.parse(S.createdAt??""))?Date.parse(S.createdAt??""):0)-E});return o.current.set(m,T),m===t.current&&r(T.map(k=>un(k,{cloneMessages:!0}))),!0},[t]),d=b.useCallback(m=>{m&&(o.current.delete(m),s.current.delete(m),m===t.current&&r([]))},[t]),f=b.useCallback(()=>{r([])},[]),h=b.useCallback(m=>m?s.current.get(m)??null:null,[]),p=b.useCallback((m,g)=>{var y;if(m)return(y=s.current.get(m))==null?void 0:y.get(g)},[]);return{threadCheckpoints:n,syncActiveThreadCheckpoints:i,updateCheckpointCache:a,updateCheckpointSnapshots:l,applyCheckpointSummaries:c,clearThreadCaches:d,resetThreadCheckpoints:f,getSnapshotCache:h,getSnapshotFromCache:p}}const uu=b.createContext(null),du=b.createContext(null),fu=b.createContext(null),kx=b.createContext(!1);function Tx({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}=Xi(),f=b.useMemo(()=>Zn(d),[d]),h=b.useMemo(()=>{try{return new URL(d).host}catch{return"unknown"}},[d]),p=b.useMemo(()=>`threadPayload:${vx}:${h}:`,[h]),m=b.useCallback(I=>dx(p,I),[p]),g=b.useCallback((I,A=100)=>{fx(p,I,A)},[p]),y=b.useCallback(I=>{hx(p,I)},[p]),x=b.useCallback(()=>{px(p)},[p]),[w,C]=b.useState(()=>{var I;return ca(h,(I=c.getAuthToken)==null?void 0:I.call(c))}),[T,k]=b.useState(()=>{var A;const I=da(ca(h,(A=c.getAuthToken)==null?void 0:A.call(c)));return ps(I)}),S=b.useMemo(()=>fa(T),[T]),[E,j]=b.useState(t),[_,P]=b.useState(!1),[D,z]=b.useState(!1),[B,O]=b.useState(null),[H,R]=b.useState(null),[V,$]=b.useState(null),F=b.useCallback(()=>{const I=da(w);b.startTransition(()=>{k(ps(I))})},[w]),[ne,Q]=b.useState(!1),[ye,je]=b.useState(!1),[J,ue]=b.useState(null),[ke,te]=b.useState(void 0),[L,q]=b.useState(void 0),[ie,ce]=b.useState(void 0),{state:U,dispatch:We,seed:re,prepend:xe,pushUser:Pe,onEvent:$e,reset:rt}=Gc(),Se=b.useRef(E);b.useEffect(()=>{Se.current=E},[E]);const Ye=b.useRef(!1),ot=b.useRef([]),et=b.useRef(null),Xe=b.useRef(null),Ke=b.useRef(new Map),tt=b.useRef(E),Ot=b.useRef(!1),St=b.useRef(null),nt=b.useRef(new Map),yt=b.useRef(new Map),{threadCheckpoints:Nt,syncActiveThreadCheckpoints:st,updateCheckpointCache:Gt,updateCheckpointSnapshots:Yt,applyCheckpointSummaries:Xt,clearThreadCaches:Jt,resetThreadCheckpoints:ft,getSnapshotCache:Ve,getSnapshotFromCache:Mt}=Cx({currentThreadId:E,currentThreadIdRef:Se}),_t=b.useCallback(()=>{var K;const I=yt.current;if(I.size<=ou)return;const A=Array.from(I.entries()).sort((fe,le)=>fe[1].timestamp-le[1].timestamp),W=I.size-ou;for(let fe=0;fe<W;fe++){const le=(K=A[fe])==null?void 0:K[0];le&&I.delete(le)}},[]),G=b.useCallback((I,A)=>{if(!I)return null;const W=Array.isArray(I.checkpoints)?I.checkpoints:[];return W.length===0?null:{version:I.version===na?I.version:na,threadId:I.threadId??A,checkpoints:W}},[]),Te=b.useCallback((I,A)=>{const{threadId:W,checkpointId:K=null,checkpointNs:fe=null}=I,le=au(W,K,fe);if(A!=null&&A.force)nt.current.delete(le),yt.current.delete(le);else{if(A!=null&&A.preferCache){const kt=yt.current.get(le);if(kt)return Promise.resolve(kt.result)}const Be=nt.current.get(le);if(Be)return Be}const bt=(async()=>{try{const Be=await c.getStateHistory({threadId:W,checkpointId:K??void 0,checkpointNs:fe??void 0}),kt=G(Be,W);if(kt)return{payload:kt,usedHistoryApi:!0};throw new Error("History response missing checkpoints")}catch(Be){console.warn("[ChatSessionProvider] getStateHistory failed, falling back to getState:",Be);const kt=await c.getState({threadId:W,checkpointId:K??void 0,checkpointNs:fe??void 0});return{payload:{version:na,threadId:W,checkpoints:[kt]},usedHistoryApi:!1}}})().then(Be=>(yt.current.set(le,{result:Be,timestamp:Date.now()}),_t(),Be)).finally(()=>{nt.current.get(le)===bt&&nt.current.delete(le)});return nt.current.set(le,bt),bt},[c,G,_t]),ve=b.useCallback((I,A)=>new Promise((W,K)=>{const fe=async()=>{Ye.current=!0;try{await I(),W()}catch(le){K(le)}finally{Ye.current=!1;const le=ot.current.shift();le&&le().catch(()=>{})}};Ye.current?ot.current.push(fe):fe().catch(le=>{K(le)})}),[]),pt=b.useRef(S.length),mt=b.useRef(!1);b.useEffect(()=>{pt.current=S.length},[S.length]),b.useEffect(()=>{const I=U.pendingInterrupt??ux(U.messages);iu(V,I)||$(I??null)},[V,U.messages,U.pendingInterrupt]);const ct=b.useCallback(async()=>{const I=pt.current>0;I||P(!0);try{const A=await c.listThreads();b.startTransition(()=>{k(W=>{const K=ht=>ht.map(bt=>`${bt.threadId}:${bt.updatedAt??""}:${bt.messageCount??""}`).join("|"),fe=fa(W);return K(fe)===K(A)||A.length===0&&fe.length>0&&!mt.current?W:ps(A)})}),O(null),mt.current||(mt.current=!0)}catch(A){i==null||i(String(A)),console.error("[ChatSessionProvider] Failed to refresh threads:",A),O(String(A))}finally{I||P(!1)}},[c,i]),Me=b.useRef(!1),Ut=b.useRef(null),Le=b.useRef(null),xt=b.useRef(""),[Ln,Dt]=b.useState("idle"),fn=b.useRef({attempts:0,timer:null,reason:null}),io=b.useRef(null),ao=b.useRef(0),Lr=b.useRef(()=>{}),Fr=b.useRef(()=>{}),N=b.useRef(()=>{}),Y=I=>{if(!I||typeof I!="object")return!1;const A=I;return A.code==="ECONNABORTED"?!0:(typeof A.message=="string"?A.message.toLowerCase():"").includes("timeout")},ae=b.useCallback(async I=>{const A=await c.listCheckpointSummaries(I);return cu(A??[])},[c]),Ce=b.useCallback((I,A)=>{if(!Cr())return;Le.current!==null&&(window.clearTimeout(Le.current),Le.current=null);const W=I.map(fe=>`${fe.threadId}:${fe.updatedAt??""}:${fe.messageCount??""}`).join("|");if(I.length===0){try{sa(w)}catch{}xt.current="";return}if(W===xt.current)return;const K=()=>{try{const fe=I.slice(0,la);ua(w,fe),xt.current=W}catch{}finally{Le.current=null}};if(A!=null&&A.immediate){K();return}Le.current=window.setTimeout(()=>{su(K)},fs)},[w]),Ge=b.useCallback(()=>{Ce(S,{immediate:!0})},[Ce,S]),qe=b.useCallback((I,A,W,K)=>{var Wl;const fe=W??Se.current;if(!fe)return;const le=un(I),ht=fe===Se.current,bt=(K==null?void 0:K.persist)!==!1;if(A==="replace"){if(bt){const Vt={threadId:fe,snapshot:un(I,{cloneMessages:!0})};Ke.current.set(fe,Vt),tt.current=fe}if(!ht)return;re(le.messages,{checkpointId:le.checkpointId??null,checkpointNs:le.checkpointNs??null,pendingInterrupt:le.interrupt??null}),$(le.interrupt??null),ue(le.nextCursor??null),Q(!!le.nextCursor),te(le.checkpointId??void 0),q(le.checkpointNs??void 0),ce(le.nextCursorNs??void 0);return}const Be=Ke.current.get(fe),kt=(Be==null?void 0:Be.snapshot)??null,Ht=Array.isArray(kt==null?void 0:kt.messages)?kt.messages:[],pn=un(kt),Jn=Array.isArray(I==null?void 0:I.messages)?I.messages:[],Wt=new Set,jt=[...Jn,...Ht].filter(Vt=>{const Vl=Vt==null?void 0:Vt.id;return Vl?Wt.has(Vl)?!1:(Wt.add(Vl),!0):!0}),or=lu(pn,le),$r={checkpointId:pn.checkpointId??le.checkpointId??null,checkpointNs:pn.checkpointNs??le.checkpointNs??null,createdAt:le.createdAt??pn.createdAt??null,parentId:le.parentId??pn.parentId??null,branchLabel:le.branchLabel??pn.branchLabel??null,lastMessageId:((Wl=jt[jt.length-1])==null?void 0:Wl.id)??null,messagesLen:jt.length,hasMessages:jt.length>0,messages:jt,nextCursor:le.nextCursor??pn.nextCursor??null,nextCursorNs:le.nextCursorNs??pn.nextCursorNs??null,interrupt:pn.interrupt??le.interrupt??null,...or};if(Ke.current.set(fe,{threadId:fe,snapshot:un($r,{cloneMessages:!0})}),!ht)return;Jn.length&&xe(Jn);const lo=I&&Object.prototype.hasOwnProperty.call(I,"checkpointId")?I.checkpointId:void 0,An=I&&Object.prototype.hasOwnProperty.call(I,"checkpointNs")?I.checkpointNs:void 0,zr=I&&Object.prototype.hasOwnProperty.call(I,"nextCursor")?I.nextCursor:void 0,xr=I&&Object.prototype.hasOwnProperty.call(I,"nextCursorNs")?I.nextCursorNs:void 0;ue(Vt=>zr!==void 0?zr??Vt??null:Vt??null),Q(Vt=>zr!==void 0?!!zr:Vt),te(Vt=>lo!==void 0?lo??Vt??void 0:Vt??void 0),q(Vt=>An!==void 0?An??Vt??void 0:Vt??void 0),ce(Vt=>xr!==void 0?xr??void 0:Vt)},[xe,re,$]),He=b.useCallback(I=>{if(I.threadId!=null&&I.threadId!==Se.current)return;const A=un(I.snapshot,{cloneMessages:!0});re(A.messages,{checkpointId:A.checkpointId??null,checkpointNs:A.checkpointNs??null,pendingInterrupt:A.interrupt??null}),$(A.interrupt??null),ue(A.nextCursor??null),Q(!!A.nextCursor),te(A.checkpointId??void 0),q(A.checkpointNs??void 0),ce(A.nextCursorNs??void 0),tt.current=I.threadId,st(I.threadId??Se.current??null)},[re,$,st]),Re=b.useCallback(I=>{if(!I)return;Ke.current.delete(I),y(I),Jt(I);const A=`${I}__`;for(const W of nt.current.keys())W.startsWith(A)&&nt.current.delete(W);for(const W of yt.current.keys())W.startsWith(A)&&yt.current.delete(W);tt.current===I&&(tt.current=null)},[Jt,y]),At=b.useCallback(()=>{const I=Se.current;I&&Re(I),rt([]),Q(!1),je(!1),ue(null),te(void 0),q(void 0),ce(void 0)},[Re,rt]),gt=b.useCallback(({from:I,to:A})=>{const W=Se.current;W&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${I} -> ${A}) for thread ${W}`)},[]),Ct=b.useCallback(I=>{const A=I.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:A,title:I.title,created:I.created,currentThreads:S.length});const W={threadId:A,title:I.title||`Thread ${A.slice(0,8)}`,createdAt:I.createdAt||new Date().toISOString(),updatedAt:I.updatedAt||new Date().toISOString(),messageCount:I.messageCount||0};Se.current!==A&&(!Se.current&&U.messages.length<=1&&(Xe.current=A),j(A)),b.startTransition(()=>{k(K=>{const fe=K.byId[A];return fe?fe.title===W.title&&fe.updatedAt===W.updatedAt&&fe.messageCount===W.messageCount?K:{byId:{...K.byId,[A]:W},order:K.order}:{byId:{...K.byId,[A]:W},order:[A,...K.order]}})})},[U.messages.length]),{startStream:Zt,stop:Fn,isStreaming:hn,error:zt,setAuthToken:$n,replayBufferedEvents:Z}=nx({baseUrl:f,onThreadInfo:Ct,onMessageEvent:$e,onUnhandledEvent:I=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${I.type}`,I)},onSequenceGap:gt,onStreamClosed:I=>{Lr.current(I)},onConnectionError:I=>{Fr.current(I)},onAuthError:a,onHeartbeat:I=>{N.current(I)}}),se=b.useCallback(()=>{const I=fn.current;I.timer!==null&&(window.clearTimeout(I.timer),I.timer=null),I.reason=null},[]),de=b.useCallback((I,A)=>{Dt("connecting"),Zt(I,{onOpen:W=>{var K;se(),fn.current.attempts=0,Dt("connected"),(K=A==null?void 0:A.onOpen)==null||K.call(A,W)},onError:W=>{var K;(K=A==null?void 0:A.onError)==null||K.call(A,W)},onGap:(A==null?void 0:A.onGap)??gt,onConnectionError:W=>{var K;Fr.current(W),(K=A==null?void 0:A.onConnectionError)==null||K.call(A,W)},onHeartbeat:W=>{var K;N.current(W),(K=A==null?void 0:A.onHeartbeat)==null||K.call(A,W)},onClosed:W=>{var K;Lr.current(W),(K=A==null?void 0:A.onClosed)==null||K.call(A,W)}})},[se,gt,Dt,Zt]),Ie=b.useCallback(()=>{const I=Se.current;if(!I)return null;const A=io.current,W=U.lastCheckpointId??(A==null?void 0:A.lastCheckpointId)??null,K=U.lastCheckpointNs??(A==null?void 0:A.lastCheckpointNs)??null,fe={};return W&&(fe.checkpointId=W),K&&(fe.checkpointNs=K),{threadId:I,checkpointId:W,checkpointNs:K,command:{kind:"resume",value:fe}}},[U.lastCheckpointId,U.lastCheckpointNs]),lt=b.useCallback(I=>{const A=fn.current;if(A.timer!==null)return;if(A.attempts>=ox){Dt("error");return}A.attempts+=1,A.reason=I;const W=Math.min(sx*Math.pow(2,A.attempts-1),ix);Dt("reconnecting"),A.timer=window.setTimeout(()=>{A.timer=null,A.reason=null;const K=Ie();if(!K){Dt("error");return}Z(K.threadId??void 0),de(K)},W)},[Ie,Z,Dt,de]),Je=b.useCallback(I=>{var A;if(io.current=I,I.manualStop||I.reason==="complete"){se(),fn.current.attempts=0,Dt("idle");return}if(I.error&&(I.error.includes("token")||I.error.includes("401")||I.error.includes("unauthorized")||I.error.includes("Unauthorized")||I.error.includes("TOKEN_EXPIRED")||I.error.includes("auth_error"))){console.error("[ChatSessionProvider] Auth error detected:",I.error);try{a==null||a(I.error)}catch(K){console.error("[ChatSessionProvider] Error in onAuthError handler:",K)}return}if(I.reason==="error"||I.reason==="aborted"){if((A=I.error)!=null&&A.includes("Stream idle timeout")){console.warn("[ChatSessionProvider] Idle timeout - not scheduling resume (watchdog is generous)");return}lt(`closed:${I.reason}`)}},[se,lt,Dt,a]),it=b.useCallback(I=>{console.warn("[ChatSessionProvider] Stream connection error:",I),lt("connection-error")},[lt]),Bt=b.useCallback(I=>{ao.current=Date.now(),Dt(A=>A==="reconnecting"?"connected":A)},[Dt]);Lr.current=Je,Fr.current=it,N.current=Bt,b.useEffect(()=>()=>{se()},[se]);const sn=b.useCallback(()=>{se(),fn.current.attempts=0,Dt("idle"),Fn()},[se,Dt,Fn]);b.useEffect(()=>{Me.current=hn},[hn]),b.useEffect(()=>{if(!Cr())return;Le.current!==null&&(window.clearTimeout(Le.current),Le.current=null);const I=S.map(W=>`${W.threadId}:${W.updatedAt??""}:${W.messageCount??""}`).join("|");if(S.length===0){try{sa(w)}catch{}xt.current="";return}if(I===xt.current)return;const A=()=>{try{const W=S.slice(0,la);ua(w,W),xt.current=I}catch{}finally{Le.current=null}};return Le.current=window.setTimeout(()=>{su(A),Le.current=null},fs),()=>{Le.current!==null&&(window.clearTimeout(Le.current),Le.current=null)}},[S,Ce]),b.useEffect(()=>{var K;const I=c.getAuthToken();$n(I);const A=fe=>{const le=ca(h,fe);St.current!==le&&(St.current=le,Ot.current=!1),C(le);const ht=da(le);b.startTransition(()=>{k(ps(ht))}),fe&&!Ot.current&&(Ot.current=!0)};A(I);const W=(K=c.onTokenChange)==null?void 0:K.call(c,fe=>{fe!==I&&($n(fe),x(),nt.current.clear(),yt.current.clear(),A(fe))});return()=>{W==null||W()}},[c,h,$n,x]);const Xn=b.useCallback(async I=>{var K;const A=`Thread ${(K=crypto.randomUUID)==null?void 0:K.call(crypto)}`,W={threadId:A,title:I||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(fe=>({byId:{...fe.byId,[A]:W},order:[A,...fe.order]})),j(A);try{const fe=await c.createThread(I),le=typeof fe=="string"?fe:fe.threadId;return k(ht=>{const bt=ht.byId[A];if(!bt)return ht;const Be={...ht.byId};delete Be[A],Be[le]={...bt,threadId:le};const kt=ht.order.map(Ht=>Ht===A?le:Ht);return{byId:Be,order:kt}}),j(le),setTimeout(()=>ct(),10),O(null),le}catch(fe){throw k(le=>{if(!le.byId[A])return le;const ht={...le.byId};delete ht[A];const bt=le.order.filter(Be=>Be!==A);return{byId:ht,order:bt}}),j(null),O(String(fe)),fe}},[c,ct]),Ko=b.useCallback(async I=>{try{await c.deleteThread(I);let A=null;k(W=>{if(!W.byId[I])return W;const K={...W.byId};delete K[I];const fe=W.order.filter(ht=>ht!==I),le={byId:K,order:fe};return A=fa(le),le}),A&&Ce(A,{immediate:!0}),Re(I),Se.current===I&&(Xe.current=I,j(null),Se.current=null,tt.current=null,At()),await ct(),O(null)}catch(A){throw O(String(A)),A}},[c,At,Re,ct,Ce]),ji=b.useCallback(async(I,A)=>{try{await c.updateThread(I,A),k(W=>{const K=W.byId[I];return K?{byId:{...W.byId,[I]:{...K,title:A}},order:W.order}:W}),O(null)}catch(W){throw await ct(),O(String(W)),W}},[c,ct]),Nn=b.useCallback(async(I,A,W,K=!1)=>{await ve(async()=>{if(Xe.current===I&&!K){Xe.current=null;return}if(et.current===I&&!K)return;j(Wt=>Wt===I?Wt:I),Se.current=I;const ht=au(I,A??null,W??null),bt=yt.current.get(ht),Be=!K&&!A&&!W&&bt&&Date.now()-bt.timestamp<rx,kt=!K&&!A&&!W;let Ht=!1;if(kt){const Wt=Ke.current.get(I);if(Wt)He(Wt),Ht=!0;else{const jt=m(I);jt&&(Ke.current.set(I,jt),He(jt),Ht=!0)}}const pn=K||!Ht||!!A||!!W,Jn=async Wt=>{Wt&&z(!0),et.current=I;try{const jt=await Te({threadId:I,checkpointId:A,checkpointNs:W},{force:K}),{latest:or,checkpoints:$r,snapshots:lo}=ls(jt.payload);qe(or,"replace",I),Gt(I,$r,"replace"),Yt(I,lo,"replace"),R(null),jt.usedHistoryApi||ae(I).then(An=>{Xt(I,An)}).catch(An=>{console.warn("[ChatSessionProvider] Failed to refresh checkpoint summaries:",An)})}catch(jt){if(Y(jt))try{const or=await ae(I),$r=Xt(I,or);if(Q(!1),ue(null),ce(void 0),te(void 0),q(void 0),$r){R("History request timed out. Select a checkpoint to load manually.");return}}catch(or){console.warn("[ChatSessionProvider] Failed to fetch checkpoint summaries after timeout:",or)}throw(!Ht||K||Wt)&&(i==null||i(String(jt))),R(String(jt)),jt}finally{et.current=null,Wt&&z(!1)}};pn?await Jn(!0):kt&&Ht&&!Be&&Jn(!1).catch(Wt=>{console.warn("[ChatSessionProvider] Background refresh failed:",Wt)})},`loadThread-${I}`)},[He,Xt,qe,ve,ae,Te,Y,i,Gt,Yt]),Pi=b.useCallback(async()=>{await ve(async()=>{const I=Se.current;I&&Re(I),Xe.current=null,j(null),Se.current=null,tt.current=null,At(),te(void 0),q(void 0),ce(void 0),ft();try{localStorage.removeItem("lastThreadId")}catch(A){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",A)}},"clearCurrentThread")},[At,Re,ve,ft]),Vm=b.useCallback(async(I,A)=>{const W=Se.current;if(!W)throw new Error("No active thread");const K=Wr(I,A??null),fe=Mt(W,K);if(fe){await ve(async()=>{qe(fe,"replace",W,{persist:!1})},`navigateToCheckpoint-${W}-${K}`);return}await Nn(W,I,A??void 0,!0)},[qe,ve,Mt,Nn]),Km=b.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");await Nn(Se.current,void 0,void 0,!0)},[Nn]),qm=b.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");if(ye||!ne)return;const I=J;if(I){je(!0);try{const A=Se.current,W=await Te({threadId:A,checkpointId:I??ke??null,checkpointNs:ie??L??null}),{latest:K,checkpoints:fe,snapshots:le}=ls(W.payload),ht=Ve(A);let bt=fe.length>0;if(bt&&ht&&ht.size>0&&(bt=fe.some(Be=>{if(!(Be!=null&&Be.checkpointId))return!1;const kt=Wr(Be.checkpointId,Be.checkpointNs??null);return!ht.has(kt)})),!bt){ue(null),ce(void 0),Q(!1),R(null);return}if(qe(K,"prepend",A??void 0),A&&(Gt(A,fe,"prepend"),Yt(A,le,"prepend"),!W.usedHistoryApi))try{const Be=await ae(A);Xt(A,Be)}catch(Be){console.warn("[ChatSessionProvider] Failed to refresh checkpoint summaries during prepend:",Be)}R(null)}catch(A){throw R(String(A)),A}finally{je(!1)}}},[qe,Te,Ve,ne,ke,L,ie,J,ae,Xt,ye,Gt,Yt]),Gm=b.useCallback(I=>{if(I!=null&&I.threadId){if(I.checkpointId){const A=Wr(I.checkpointId,I.checkpointNs??null),W=un({...I,interrupt:I.interrupt??null},{cloneMessages:!0});Yt(I.threadId,{[A]:W},"prepend")}qe(I,"replace",I.threadId)}},[qe,Yt]),qo=b.useCallback(async(I,A)=>{var zr;const W=Se.current,K=(I==null?void 0:I.text)??"",fe=(I==null?void 0:I.attachments)??[],le=fe.length?fe:(A==null?void 0:A.attachments)??[],ht=I==null?void 0:I.messageAdditionalKwargs,bt={...(A==null?void 0:A.payloadExtras)??{},...(I==null?void 0:I.payload)??{}};if(!W&&!Object.keys(bt).length&&le.length===0&&!K.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!W&&!bt.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Be,filesInfo:kt}=await jy(c,le),Ht=[...Be];K&&K.trim()&&Ht.push({type:"text",text:K.trim()});const pn=!!W,Jn=pn?(A==null?void 0:A.checkpointId)??U.lastCheckpointId??void 0:void 0,Wt=pn?(A==null?void 0:A.checkpointNs)??U.lastCheckpointNs??void 0:void 0,jt={id:((zr=crypto.randomUUID)==null?void 0:zr.call(crypto))||`user-${Date.now()}`,role:"user",content:Ht,createdAt:new Date().toISOString(),...Jn!=null?{checkpointId:Jn}:{},...Wt!=null?{checkpointNs:Wt}:{}};ht&&Object.keys(ht).length&&(jt.additionalKwargs={...jt.additionalKwargs??{},...ht}),Ht.length>0&&Pe(jt);const or={...jt,content:Ht},$r=le.length>0,lo={messages:Ht.length>0?[or]:[],files_info:kt,...o&&$r&&s?{active_agent:s}:{},...bt},An={threadId:W??null,payload:lo,checkpointId:Jn??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};An.threadId||delete An.threadId,An.command||delete An.command,de(An,{onError:xr=>{console.warn("[ChatSessionProvider] Stream error:",xr)},onOpen:({threadId:xr})=>{!Se.current&&xr&&(U.messages.length<=1&&(Xe.current=xr),j(xr))},onGap:gt})},[c,o,s,gt,U.lastCheckpointId,U.lastCheckpointNs,U.messages.length,Pe,de]),Ym=b.useCallback(async(I,A,W)=>{if(!Se.current)throw new Error("No active thread to handle interrupt");const fe=A?W??!0:!1;try{try{We({type:"interrupt_response",payload:{interruptId:I}})}catch(le){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",le)}await qo({payload:{}},{checkpointId:U.lastCheckpointId??void 0,checkpointNs:U.lastCheckpointNs??void 0,command:{kind:"resume",value:fe}}),$(null)}catch(le){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${I}:`,le),le}},[We,U.lastCheckpointId,U.lastCheckpointNs,qo]);b.useEffect(()=>{if(l==null||l(E),E)try{localStorage.setItem("lastThreadId",E)}catch(I){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",I)}},[E,l]),b.useEffect(()=>((async()=>{try{if(ct().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&&(j(A),n&&await Nn(A))}catch(A){console.warn("[ChatSessionProvider] Failed to restore last thread:",A)}else t&&n&&await Nn(t)}catch(A){console.error("[ChatSessionProvider] Initialization failed:",A),i==null||i(String(A))}})(),()=>{}),[]),b.useEffect(()=>{const I=Se.current;if(!I||tt.current!==I)return;U.messages.length&&U.messages[U.messages.length-1];const A=un({checkpointId:U.lastCheckpointId??null,checkpointNs:U.lastCheckpointNs??null,messages:U.messages.slice(),nextCursor:J??null,nextCursorNs:ie??null,interrupt:U.pendingInterrupt??V??null}),W=Ke.current.get(I),K=W==null?void 0:W.snapshot,fe=!K||K.messages.length!==A.messages.length||K.messages.some((Be,kt)=>{var Ht;return(Be==null?void 0:Be.id)!==((Ht=A.messages[kt])==null?void 0:Ht.id)}),le=((K==null?void 0:K.checkpointId)??null)!==A.checkpointId||((K==null?void 0:K.checkpointNs)??null)!==A.checkpointNs,ht=((K==null?void 0:K.nextCursor)??null)!==A.nextCursor||((K==null?void 0:K.nextCursorNs)??null)!==A.nextCursorNs,bt=!iu((K==null?void 0:K.interrupt)??null,A.interrupt??null);if(fe||le||ht||bt){const Be={threadId:I,snapshot:A};Ke.current.set(I,Be),Ut.current&&window.clearTimeout(Ut.current),Ut.current=window.setTimeout(()=>{try{g(Be,100)}catch(kt){console.warn("[ChatSessionProvider] Failed to persist thread payload:",kt)}},fs)}},[J,ie,U.lastCheckpointId,U.lastCheckpointNs,U.messages,U.pendingInterrupt,V,g]);const yT=b.useMemo(()=>({threads:S,currentThreadId:E,setCurrentThreadId:j,isLoading:_,error:B,actions:{createThread:Xn,deleteThread:Ko,renameThread:ji,refreshThreads:()=>ct()},persistThreadsCache:Ge,hydrateFromCache:F}),[S,E,_,B,Xn,Ko,ji,ct,Ge,F,j]),xT=b.useMemo(()=>{const I=U.lastBranch??null,A=U.assemblingId??null,W=I||A?{branchLabel:(I==null?void 0:I.branchLabel)??null,lastBranch:I,assemblingMessageId:A}:null;return{threadId:E,messages:U.messages,interrupt:V,checkpoint:{id:U.lastCheckpointId??null,namespace:U.lastCheckpointNs??null},checkpoints:Nt,metadata:W,isLoading:D,isHistoryLoading:ye,error:H,hasMore:ne,loadOlder:qm,seedFromSnapshot:Gm,clearState:At,navigateToCheckpoint:Vm,returnToLatest:Km,loadThread:Nn,clearThread:Pi,respondToInterrupt:Ym}},[Pi,At,E,V,ne,ye,D,qm,Nn,U.assemblingId,U.lastBranch,U.lastCheckpointId,U.lastCheckpointNs,U.messages,Vm,Ym,Km,Gm,H,Nt]),vT=b.useMemo(()=>({isStreaming:hn,error:zt,connectionState:Ln,submit:qo,send:qo,stop:sn,setAuthToken:$n}),[Ln,hn,zt,sn,qo,$n]);return u.jsx(kx.Provider,{value:!0,children:u.jsx(fu.Provider,{value:vT,children:u.jsx(uu.Provider,{value:yT,children:u.jsx(du.Provider,{value:xT,children:e})})})})}function ms(){const e=b.useContext(uu);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function gs(){const e=b.useContext(du);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function hu(){const e=b.useContext(fu);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function ys({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(Ay,{apiConfig:t,children:u.jsx(Tx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onAuthError:l,onThreadChange:c,children:e})})}function oe(...e){return Qm.twMerge(Zm.clsx(e))}const Ex=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?vr.Slot:"button";return u.jsx(i,{className:oe(Ex({variant:t,size:n,className:e})),ref:s,...o})});ut.displayName="Button";const pu=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}));pu.displayName="Textarea";function mu({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 m=i!==void 0,[g,y]=b.useState(e),x=(m?i:g)??"",[w,C]=b.useTransition(),T=b.useRef(null),k=b.useRef(0),S=b.useRef(null);b.useEffect(()=>{m||(y(e??""),S.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const H=T.current;H&&(H.style.height="auto",H.style.height=`${H.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,x]);const j=b.useCallback((H,{fromUser:R})=>{m||y(H),R&&(a==null||a(H))},[m,a]),_=b.useCallback(async H=>{H&&H.preventDefault();const R=(x??"").trim();if(!R&&!p)return;const V=++k.current;S.current={id:V,shouldClear:!0},C(()=>{var $,F,ne;try{const Q=l(R);Q&&typeof Q.then=="function"?Q.then(()=>{var ye,je;((ye=S.current)==null?void 0:ye.id)===V&&S.current.shouldClear&&(m||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((je=S.current)==null?void 0:je.id)===V&&(S.current=null)}).catch(()=>{var ye;((ye=S.current)==null?void 0:ye.id)===V&&(S.current=null)}):((($=S.current)==null?void 0:$.id)===V&&S.current.shouldClear&&(m||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((F=S.current)==null?void 0:F.id)===V&&(S.current=null))}catch{((ne=S.current)==null?void 0:ne.id)===V&&(S.current=null)}})},[x,l,p,m,a]),P=b.useCallback(H=>{const R=H.target.value;j(R,{fromUser:!0}),S.current&&(S.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[j]),D=b.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(pu,{ref:T,value:x,onChange:P,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||!x.trim()&&!p||w,children:u.jsx(he.Send,{size:16})})})]})})}const Ix=b.memo(mu);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 gu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ha(...e){return t=>{let n=!1;const r=e.map(o=>{const s=gu(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():gu(e[o],null)}}}}function Ze(...e){return v.useCallback(ha(...e),e)}function Nx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Qn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:h,children:p,...m}=f,g=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(g.Provider,{value:y,children:p})};c.displayName=s+"Provider";function d(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,m=v.useContext(p);if(m)return m;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,Ax(o,...t)]}function Ax(...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:()=>{},_x=v[" useInsertionEffect ".trim().toString()]||Kt;function Vr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=jx({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=Px(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 jx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return _x(()=>{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 Px(e){return typeof e=="function"}var Rx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],De=Rx.reduce((e,t)=>{const n=vr.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 yu(e,t){e&&Yo.flushSync(()=>e.dispatchEvent(t))}function pa(e){const t=e+"CollectionProvider",[n,r]=Qn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,w=b.useRef(null),C=b.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:C,collectionRef:w,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=vr.createSlot(a),c=b.forwardRef((g,y)=>{const{scope:x,children:w}=g,C=s(a,x),T=Ze(y,C.collectionRef);return u.jsx(l,{ref:T,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=vr.createSlot(d),p=b.forwardRef((g,y)=>{const{scope:x,children:w,...C}=g,T=b.useRef(null),k=Ze(y,T),S=s(d,x);return b.useEffect(()=>(S.itemMap.set(T,{ref:T,...C}),()=>void S.itemMap.delete(T))),u.jsx(h,{[f]:"",ref:k,children:w})});p.displayName=d;function m(g){const y=s(e+"CollectionConsumer",g);return b.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const C=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((S,E)=>C.indexOf(S.ref.current)-C.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},m,r]}var Ox=v.createContext(void 0);function xs(e){const t=v.useContext(Ox);return e||t||"ltr"}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 Mx(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 Dx="DismissableLayer",ma="dismissableLayer.update",Lx="dismissableLayer.pointerDownOutside",Fx="dismissableLayer.focusOutside",xu,vu=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),vs=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(vu),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),m=Ze(t,E=>f(E)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),w=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,T=w>=x,k=Bx(E=>{const j=E.target,_=[...c.branches].some(P=>P.contains(j));!T||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),S=Hx(E=>{const j=E.target;[...c.branches].some(P=>P.contains(j))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return Mx(E=>{w===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&&(xu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wu(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=xu)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wu())},[d,c]),v.useEffect(()=>{const E=()=>p({});return document.addEventListener(ma,E),()=>document.removeEventListener(ma,E)},[]),u.jsx(De.div,{...l,ref:m,style:{pointerEvents:C?T?"auto":"none":void 0,...e.style},onFocusCapture:ge(e.onFocusCapture,S.onFocusCapture),onBlurCapture:ge(e.onBlurCapture,S.onBlurCapture),onPointerDownCapture:ge(e.onPointerDownCapture,k.onPointerDownCapture)})});vs.displayName=Dx;var $x="DismissableLayerBranch",zx=v.forwardRef((e,t)=>{const n=v.useContext(vu),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})});zx.displayName=$x;function Bx(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(){bu(Lx,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 Hx(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&&bu(Fx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function wu(){const e=new CustomEvent(ma);document.dispatchEvent(e)}function bu(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?yu(o,s):o.dispatchEvent(s)}var ga=0;function ya(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Su()),document.body.insertAdjacentElement("beforeend",e[1]??Su()),ga++,()=>{ga===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ga--}},[])}function Su(){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 xa="focusScope.autoFocusOnMount",va="focusScope.autoFocusOnUnmount",Cu={bubbles:!1,cancelable:!0},Ux="FocusScope",ws=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=Ze(t,g=>l(g)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let g=function(C){if(p.paused||!a)return;const T=C.target;a.contains(T)?f.current=T:ir(f.current,{select:!0})},y=function(C){if(p.paused||!a)return;const T=C.relatedTarget;T!==null&&(a.contains(T)||ir(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const k of C)k.removedNodes.length>0&&ir(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const w=new MutationObserver(x);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),w.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){Eu.add(p);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(xa,Cu);a.addEventListener(xa,c),a.dispatchEvent(x),x.defaultPrevented||(Wx(Yx(ku(a)),{select:!0}),document.activeElement===g&&ir(a))}return()=>{a.removeEventListener(xa,c),setTimeout(()=>{const x=new CustomEvent(va,Cu);a.addEventListener(va,d),a.dispatchEvent(x),x.defaultPrevented||ir(g??document.body,{select:!0}),a.removeEventListener(va,d),Eu.remove(p)},0)}}},[a,c,d,p]);const m=v.useCallback(g=>{if(!n&&!r||p.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const w=g.currentTarget,[C,T]=Vx(w);C&&T?!g.shiftKey&&x===T?(g.preventDefault(),n&&ir(C,{select:!0})):g.shiftKey&&x===C&&(g.preventDefault(),n&&ir(T,{select:!0})):x===w&&g.preventDefault()}},[n,r,p.paused]);return u.jsx(De.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});ws.displayName=Ux;function Wx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(ir(r,{select:t}),document.activeElement!==n)return}function Vx(e){const t=ku(e),n=Tu(t,e),r=Tu(t.reverse(),e);return[n,r]}function ku(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 Tu(e,t){for(const n of e)if(!Kx(n,{upTo:t}))return n}function Kx(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 qx(e){return e instanceof HTMLInputElement&&"select"in e}function ir(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&qx(e)&&t&&e.select()}}var Eu=Gx();function Gx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Iu(e,t),e.unshift(t)},remove(t){var n;e=Iu(e,t),(n=e[0])==null||n.resume()}}}function Iu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Yx(e){return e.filter(t=>t.tagName!=="A")}var Xx=v[" useId ".trim().toString()]||(()=>{}),Jx=0;function er(e){const[t,n]=v.useState(Xx());return Kt(()=>{n(r=>r??String(Jx++))},[e]),t?`radix-${t}`:""}const Zx=["top","right","bottom","left"],ar=Math.min,mn=Math.max,bs=Math.round,Ss=Math.floor,Bn=e=>({x:e,y:e}),Qx={left:"right",right:"left",bottom:"top",top:"bottom"},ev={start:"end",end:"start"};function wa(e,t,n){return mn(e,ar(t,n))}function tr(e,t){return typeof e=="function"?e(t):e}function nr(e){return e.split("-")[0]}function Kr(e){return e.split("-")[1]}function ba(e){return e==="x"?"y":"x"}function Sa(e){return e==="y"?"height":"width"}const tv=new Set(["top","bottom"]);function Hn(e){return tv.has(nr(e))?"y":"x"}function Ca(e){return ba(Hn(e))}function nv(e,t,n){n===void 0&&(n=!1);const r=Kr(e),o=Ca(e),s=Sa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Cs(i)),[i,Cs(i)]}function rv(e){const t=Cs(e);return[ka(e),t,ka(t)]}function ka(e){return e.replace(/start|end/g,t=>ev[t])}const Nu=["left","right"],Au=["right","left"],ov=["top","bottom"],sv=["bottom","top"];function iv(e,t,n){switch(e){case"top":case"bottom":return n?t?Au:Nu:t?Nu:Au;case"left":case"right":return t?ov:sv;default:return[]}}function av(e,t,n,r){const o=Kr(e);let s=iv(nr(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ka)))),s}function Cs(e){return e.replace(/left|right|bottom|top/g,t=>Qx[t])}function lv(e){return{top:0,right:0,bottom:0,left:0,...e}}function _u(e){return typeof e!="number"?lv(e):{top:e,right:e,bottom:e,left:e}}function ks(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 ju(e,t,n){let{reference:r,floating:o}=e;const s=Hn(t),i=Ca(t),a=Sa(i),l=nr(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 cv=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}=ju(c,r,l),h=r,p={},m=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:w,y:C,data:T,reset:k}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=C??f,p={...p,[y]:{...p[y],...T}},k&&m<=50&&(m++,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}=ju(c,h,l)),g=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function xo(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}=tr(t,e),m=_u(p),y=a[h?f==="floating"?"reference":"floating":f],x=ks(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})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),T=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},k=ks(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:C,strategy:l}):w);return{top:(x.top-k.top+m.top)/T.y,bottom:(k.bottom-x.bottom+m.bottom)/T.y,left:(x.left-k.left+m.left)/T.x,right:(k.right-x.right+m.right)/T.x}}const uv=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}=tr(e,t)||{};if(c==null)return{};const f=_u(d),h={x:n,y:r},p=Ca(o),m=Sa(p),g=await i.getDimensions(c),y=p==="y",x=y?"top":"left",w=y?"bottom":"right",C=y?"clientHeight":"clientWidth",T=s.reference[m]+s.reference[p]-h[p]-s.floating[m],k=h[p]-s.reference[p],S=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=S?S[C]:0;(!E||!await(i.isElement==null?void 0:i.isElement(S)))&&(E=a.floating[C]||s.floating[m]);const j=T/2-k/2,_=E/2-g[m]/2-1,P=ar(f[x],_),D=ar(f[w],_),z=P,B=E-g[m]-D,O=E/2-g[m]/2+j,H=wa(z,O,B),R=!l.arrow&&Kr(o)!=null&&O!==H&&s.reference[m]/2-(O<z?P:D)-g[m]/2<0,V=R?O<z?O-z:O-B:0;return{[p]:h[p]+V,data:{[p]:H,centerOffset:O-H-V,...R&&{alignmentOffset:V}},reset:R}}}),dv=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:m="none",flipAlignment:g=!0,...y}=tr(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=nr(o),w=Hn(a),C=nr(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(C||!g?[Cs(a)]:rv(a)),S=m!=="none";!h&&S&&k.push(...av(a,g,m,T));const E=[a,...k],j=await xo(t,y),_=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(j[x]),f){const O=nv(o,i,T);_.push(j[O[0]],j[O[1]])}if(P=[...P,{placement:o,overflows:_}],!_.every(O=>O<=0)){var D,z;const O=(((D=s.flip)==null?void 0:D.index)||0)+1,H=E[O];if(H&&(!(f==="alignment"?w!==Hn(H):!1)||P.every($=>Hn($.placement)===w?$.overflows[0]>0:!0)))return{data:{index:O,overflows:P},reset:{placement:H}};let R=(z=P.filter(V=>V.overflows[0]<=0).sort((V,$)=>V.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!R)switch(p){case"bestFit":{var B;const V=(B=P.filter($=>{if(S){const F=Hn($.placement);return F===w||F==="y"}return!0}).map($=>[$.placement,$.overflows.filter(F=>F>0).reduce((F,ne)=>F+ne,0)]).sort(($,F)=>$[1]-F[1])[0])==null?void 0:B[0];V&&(R=V);break}case"initialPlacement":R=a;break}if(o!==R)return{reset:{placement:R}}}return{}}}};function Pu(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ru(e){return Zx.some(t=>e[t]>=0)}const fv=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=tr(e,t);switch(r){case"referenceHidden":{const s=await xo(t,{...o,elementContext:"reference"}),i=Pu(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ru(i)}}}case"escaped":{const s=await xo(t,{...o,altBoundary:!0}),i=Pu(s,n.floating);return{data:{escapedOffsets:i,escaped:Ru(i)}}}default:return{}}}}},Ou=new Set(["left","top"]);async function hv(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=nr(n),a=Kr(n),l=Hn(n)==="y",c=Ou.has(i)?-1:1,d=s&&l?-1:1,f=tr(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const pv=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 hv(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}}}}},mv=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,y:w}=y;return{x,y:w}}},...l}=tr(e,t),c={x:n,y:r},d=await xo(t,l),f=Hn(nr(o)),h=ba(f);let p=c[h],m=c[f];if(s){const y=h==="y"?"top":"left",x=h==="y"?"bottom":"right",w=p+d[y],C=p-d[x];p=wa(w,p,C)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",w=m+d[y],C=m-d[x];m=wa(w,m,C)}const g=a.fn({...t,[h]:p,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},gv=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}=tr(e,t),d={x:n,y:r},f=Hn(o),h=ba(f);let p=d[h],m=d[f];const g=tr(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=h==="y"?"height":"width",T=s.reference[h]-s.floating[C]+y.mainAxis,k=s.reference[h]+s.reference[C]-y.mainAxis;p<T?p=T:p>k&&(p=k)}if(c){var x,w;const C=h==="y"?"width":"height",T=Ou.has(nr(o)),k=s.reference[f]-s.floating[C]+(T&&((x=i.offset)==null?void 0:x[f])||0)+(T?0:y.crossAxis),S=s.reference[f]+s.reference[C]+(T?0:((w=i.offset)==null?void 0:w[f])||0)-(T?y.crossAxis:0);m<k?m=k:m>S&&(m=S)}return{[h]:p,[f]:m}}}},yv=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}=tr(e,t),d=await xo(t,c),f=nr(o),h=Kr(o),p=Hn(o)==="y",{width:m,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=h==="end"?"top":"bottom");const w=g-d.top-d.bottom,C=m-d.left-d.right,T=ar(g-d[y],w),k=ar(m-d[x],C),S=!t.middlewareData.shift;let E=T,j=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),S&&!h){const P=mn(d.left,0),D=mn(d.right,0),z=mn(d.top,0),B=mn(d.bottom,0);p?j=m-2*(P!==0||D!==0?P+D:mn(d.left,d.right)):E=g-2*(z!==0||B!==0?z+B:mn(d.top,d.bottom))}await l({...t,availableWidth:j,availableHeight:E});const _=await i.getDimensions(a.floating);return m!==_.width||g!==_.height?{reset:{rects:!0}}:{}}}};function Ts(){return typeof window<"u"}function qr(e){return Mu(e)?(e.nodeName||"").toLowerCase():"#document"}function gn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Un(e){var t;return(t=(Mu(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Mu(e){return Ts()?e instanceof Node||e instanceof gn(e).Node:!1}function jn(e){return Ts()?e instanceof Element||e instanceof gn(e).Element:!1}function Wn(e){return Ts()?e instanceof HTMLElement||e instanceof gn(e).HTMLElement:!1}function Du(e){return!Ts()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof gn(e).ShadowRoot}const xv=new Set(["inline","contents"]);function vo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Pn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!xv.has(o)}const vv=new Set(["table","td","th"]);function wv(e){return vv.has(qr(e))}const bv=[":popover-open",":modal"];function Es(e){return bv.some(t=>{try{return e.matches(t)}catch{return!1}})}const Sv=["transform","translate","scale","rotate","perspective"],Cv=["transform","translate","scale","rotate","perspective","filter"],kv=["paint","layout","strict","content"];function Ta(e){const t=Ea(),n=jn(e)?Pn(e):e;return Sv.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||Cv.some(r=>(n.willChange||"").includes(r))||kv.some(r=>(n.contain||"").includes(r))}function Tv(e){let t=lr(e);for(;Wn(t)&&!Gr(t);){if(Ta(t))return t;if(Es(t))return null;t=lr(t)}return null}function Ea(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Ev=new Set(["html","body","#document"]);function Gr(e){return Ev.has(qr(e))}function Pn(e){return gn(e).getComputedStyle(e)}function Is(e){return jn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function lr(e){if(qr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Du(e)&&e.host||Un(e);return Du(t)?t.host:t}function Lu(e){const t=lr(e);return Gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Wn(t)&&vo(t)?t:Lu(t)}function wo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Lu(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=gn(o);if(s){const a=Ia(i);return t.concat(i,i.visualViewport||[],vo(o)?o:[],a&&n?wo(a):[])}return t.concat(o,wo(o,[],n))}function Ia(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Fu(e){const t=Pn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Wn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=bs(n)!==s||bs(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Na(e){return jn(e)?e:e.contextElement}function Yr(e){const t=Na(e);if(!Wn(t))return Bn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Fu(t);let i=(s?bs(n.width):n.width)/r,a=(s?bs(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Iv=Bn(0);function $u(e){const t=gn(e);return!Ea()||!t.visualViewport?Iv:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Nv(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==gn(e)?!1:t}function kr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Na(e);let i=Bn(1);t&&(r?jn(r)&&(i=Yr(r)):i=Yr(e));const a=Nv(s,n,r)?$u(s):Bn(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=gn(s),p=r&&jn(r)?gn(r):r;let m=h,g=Ia(m);for(;g&&r&&p!==m;){const y=Yr(g),x=g.getBoundingClientRect(),w=Pn(g),C=x.left+(g.clientLeft+parseFloat(w.paddingLeft))*y.x,T=x.top+(g.clientTop+parseFloat(w.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=C,c+=T,m=gn(g),g=Ia(m)}}return ks({width:d,height:f,x:l,y:c})}function Ns(e,t){const n=Is(e).scrollLeft;return t?t.left+n:kr(Un(e)).left+n}function zu(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ns(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Av(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=Un(r),a=t?Es(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=Bn(1);const d=Bn(0),f=Wn(r);if((f||!f&&!s)&&((qr(r)!=="body"||vo(i))&&(l=Is(r)),Wn(r))){const p=kr(r);c=Yr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?zu(i,l):Bn(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 _v(e){return Array.from(e.getClientRects())}function jv(e){const t=Un(e),n=Is(e),r=e.ownerDocument.body,o=mn(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=mn(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ns(e);const a=-n.scrollTop;return Pn(r).direction==="rtl"&&(i+=mn(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Bu=25;function Pv(e,t){const n=gn(e),r=Un(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=Ea();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Ns(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,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=Bu&&(s-=m)}else c<=Bu&&(s+=c);return{width:s,height:i,x:a,y:l}}const Rv=new Set(["absolute","fixed"]);function Ov(e,t){const n=kr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Wn(e)?Yr(e):Bn(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 Hu(e,t,n){let r;if(t==="viewport")r=Pv(e,n);else if(t==="document")r=jv(Un(e));else if(jn(t))r=Ov(t,n);else{const o=$u(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ks(r)}function Uu(e,t){const n=lr(e);return n===t||!jn(n)||Gr(n)?!1:Pn(n).position==="fixed"||Uu(n,t)}function Mv(e,t){const n=t.get(e);if(n)return n;let r=wo(e,[],!1).filter(a=>jn(a)&&qr(a)!=="body"),o=null;const s=Pn(e).position==="fixed";let i=s?lr(e):e;for(;jn(i)&&!Gr(i);){const a=Pn(i),l=Ta(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Rv.has(o.position)||vo(i)&&!l&&Uu(e,i))?r=r.filter(d=>d!==i):o=a,i=lr(i)}return t.set(e,r),r}function Dv(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Es(t)?[]:Mv(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Hu(t,d,o);return c.top=mn(f.top,c.top),c.right=ar(f.right,c.right),c.bottom=ar(f.bottom,c.bottom),c.left=mn(f.left,c.left),c},Hu(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Lv(e){const{width:t,height:n}=Fu(e);return{width:t,height:n}}function Fv(e,t,n){const r=Wn(t),o=Un(t),s=n==="fixed",i=kr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=Bn(0);function c(){l.x=Ns(o)}if(r||!r&&!s)if((qr(t)!=="body"||vo(o))&&(a=Is(t)),r){const p=kr(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?zu(o,a):Bn(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 Aa(e){return Pn(e).position==="static"}function Wu(e,t){if(!Wn(e)||Pn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Un(e)===n&&(n=n.ownerDocument.body),n}function Vu(e,t){const n=gn(e);if(Es(e))return n;if(!Wn(e)){let o=lr(e);for(;o&&!Gr(o);){if(jn(o)&&!Aa(o))return o;o=lr(o)}return n}let r=Wu(e,t);for(;r&&wv(r)&&Aa(r);)r=Wu(r,t);return r&&Gr(r)&&Aa(r)&&!Ta(r)?n:r||Tv(e)||n}const $v=async function(e){const t=this.getOffsetParent||Vu,n=this.getDimensions,r=await n(e.floating);return{reference:Fv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function zv(e){return Pn(e).direction==="rtl"}const Bv={convertOffsetParentRelativeRectToViewportRelativeRect:Av,getDocumentElement:Un,getClippingRect:Dv,getOffsetParent:Vu,getElementRects:$v,getClientRects:_v,getDimensions:Lv,getScale:Yr,isElement:jn,isRTL:zv};function Ku(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Hv(e,t){let n=null,r;const o=Un(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 m=Ss(f),g=Ss(o.clientWidth-(d+h)),y=Ss(o.clientHeight-(f+p)),x=Ss(d),C={rootMargin:-m+"px "+-g+"px "+-y+"px "+-x+"px",threshold:mn(0,ar(1,l))||1};let T=!0;function k(S){const E=S[0].intersectionRatio;if(E!==l){if(!T)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Ku(c,e.getBoundingClientRect())&&i(),T=!1}try{n=new IntersectionObserver(k,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,C)}n.observe(e)}return i(!0),s}function Uv(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=Na(e),d=o||s?[...c?wo(c):[],...wo(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Hv(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[w]=x;w&&w.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var C;(C=p)==null||C.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let m,g=l?kr(e):null;l&&y();function y(){const x=kr(e);g&&!Ku(g,x)&&n(),g=x,m=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const Wv=pv,Vv=mv,Kv=dv,qv=yv,Gv=fv,qu=uv,Yv=gv,Xv=(e,t,n)=>{const r=new Map,o={platform:Bv,...n},s={...o.platform,_c:r};return cv(e,t,{...o,platform:s})};var Jv=typeof document<"u",Zv=function(){},As=Jv?b.useLayoutEffect:Zv;function _s(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(!_s(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)&&!_s(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Gu(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yu(e,t){const n=Gu(e);return Math.round(t*n)/n}function _a(e){const t=v.useRef(e);return As(()=>{t.current=e}),t}function Qv(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);_s(h,r)||p(r);const[m,g]=v.useState(null),[y,x]=v.useState(null),w=v.useCallback($=>{$!==S.current&&(S.current=$,g($))},[]),C=v.useCallback($=>{$!==E.current&&(E.current=$,x($))},[]),T=s||m,k=i||y,S=v.useRef(null),E=v.useRef(null),j=v.useRef(d),_=l!=null,P=_a(l),D=_a(o),z=_a(c),B=v.useCallback(()=>{if(!S.current||!E.current)return;const $={placement:t,strategy:n,middleware:h};D.current&&($.platform=D.current),Xv(S.current,E.current,$).then(F=>{const ne={...F,isPositioned:z.current!==!1};O.current&&!_s(j.current,ne)&&(j.current=ne,Yo.flushSync(()=>{f(ne)}))})},[h,t,n,D,z]);As(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[c]);const O=v.useRef(!1);As(()=>(O.current=!0,()=>{O.current=!1}),[]),As(()=>{if(T&&(S.current=T),k&&(E.current=k),T&&k){if(P.current)return P.current(T,k,B);B()}},[T,k,B,P,_]);const H=v.useMemo(()=>({reference:S,floating:E,setReference:w,setFloating:C}),[w,C]),R=v.useMemo(()=>({reference:T,floating:k}),[T,k]),V=v.useMemo(()=>{const $={position:n,left:0,top:0};if(!R.floating)return $;const F=Yu(R.floating,d.x),ne=Yu(R.floating,d.y);return a?{...$,transform:"translate("+F+"px, "+ne+"px)",...Gu(R.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:ne}},[n,a,R.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:B,refs:H,elements:R,floatingStyles:V}),[d,B,H,R,V])}const ew=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?qu({element:r.current,padding:o}).fn(n):{}:r?qu({element:r,padding:o}).fn(n):{}}}},tw=(e,t)=>({...Wv(e),options:[e,t]}),nw=(e,t)=>({...Vv(e),options:[e,t]}),rw=(e,t)=>({...Yv(e),options:[e,t]}),ow=(e,t)=>({...Kv(e),options:[e,t]}),sw=(e,t)=>({...qv(e),options:[e,t]}),iw=(e,t)=>({...Gv(e),options:[e,t]}),aw=(e,t)=>({...ew(e),options:[e,t]});var lw="Arrow",Xu=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"})})});Xu.displayName=lw;var cw=Xu;function Ju(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 ja="Popper",[Zu,js]=Qn(ja),[uw,Qu]=Zu(ja),ed=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(uw,{scope:t,anchor:r,onAnchorChange:o,children:n})};ed.displayName=ja;var td="PopperAnchor",nd=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Qu(td,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})});nd.displayName=td;var Pa="PopperContent",[dw,fw]=Zu(Pa),rd=v.forwardRef((e,t)=>{var te,L,q,ie,ce,U;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:m,...g}=e,y=Qu(Pa,n),[x,w]=v.useState(null),C=Ze(t,We=>w(We)),[T,k]=v.useState(null),S=Ju(T),E=(S==null?void 0:S.width)??0,j=(S==null?void 0:S.height)??0,_=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},D=Array.isArray(c)?c:[c],z=D.length>0,B={padding:P,boundary:D.filter(pw),altBoundary:z},{refs:O,floatingStyles:H,placement:R,isPositioned:V,middlewareData:$}=Qv({strategy:"fixed",placement:_,whileElementsMounted:(...We)=>Uv(...We,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[tw({mainAxis:o+j,alignmentAxis:i}),l&&nw({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?rw():void 0,...B}),l&&ow({...B}),sw({...B,apply:({elements:We,rects:re,availableWidth:xe,availableHeight:Pe})=>{const{width:$e,height:rt}=re.reference,Se=We.floating.style;Se.setProperty("--radix-popper-available-width",`${xe}px`),Se.setProperty("--radix-popper-available-height",`${Pe}px`),Se.setProperty("--radix-popper-anchor-width",`${$e}px`),Se.setProperty("--radix-popper-anchor-height",`${rt}px`)}}),T&&aw({element:T,padding:a}),mw({arrowWidth:E,arrowHeight:j}),h&&iw({strategy:"referenceHidden",...B})]}),[F,ne]=id(R),Q=qt(m);Kt(()=>{V&&(Q==null||Q())},[V,Q]);const ye=(te=$.arrow)==null?void 0:te.x,je=(L=$.arrow)==null?void 0:L.y,J=((q=$.arrow)==null?void 0:q.centerOffset)!==0,[ue,ke]=v.useState();return Kt(()=>{x&&ke(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...H,transform:V?H.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ue,"--radix-popper-transform-origin":[(ie=$.transformOrigin)==null?void 0:ie.x,(ce=$.transformOrigin)==null?void 0:ce.y].join(" "),...((U=$.hide)==null?void 0:U.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(dw,{scope:n,placedSide:F,onArrowChange:k,arrowX:ye,arrowY:je,shouldHideArrow:J,children:u.jsx(De.div,{"data-side":F,"data-align":ne,...g,ref:C,style:{...g.style,animation:V?void 0:"none"}})})})});rd.displayName=Pa;var od="PopperArrow",hw={top:"bottom",right:"left",bottom:"top",left:"right"},sd=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=fw(od,r),i=hw[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(cw,{...o,ref:n,style:{...o.style,display:"block"}})})});sd.displayName=od;function pw(e){return e!==null}var mw=e=>({name:"transformOrigin",options:e,fn(t){var y,x,w;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]=id(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",g="";return c==="bottom"?(m=i?f:`${h}px`,g=`${-l}px`):c==="top"?(m=i?f:`${h}px`,g=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,g=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,g=i?f:`${p}px`),{data:{x:m,y:g}}}});function id(e){const[t,n="center"]=e.split("-");return[t,n]}var ad=ed,ld=nd,cd=rd,ud=sd,gw="Portal",Ps=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?Ri.createPortal(u.jsx(De.div,{...r,ref:t}),i):null});Ps.displayName=gw;function yw(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Sn=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,vw(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Sn.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]=yw(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Rs(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=Rs(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 g=Rs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(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=Rs(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 Rs(e){return(e==null?void 0:e.animationName)||"none"}function vw(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 Ra="rovingFocusGroup.onEntryFocus",ww={bubbles:!1,cancelable:!0},bo="RovingFocusGroup",[Oa,dd,bw]=pa(bo),[Sw,fd]=Qn(bo,[bw]),[Cw,kw]=Sw(bo),hd=v.forwardRef((e,t)=>u.jsx(Oa.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Oa.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Tw,{...e,ref:t})})}));hd.displayName=bo;var Tw=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),m=xs(s),[g,y]=Vr({prop:i,defaultProp:a??null,onChange:l,caller:bo}),[x,w]=v.useState(!1),C=qt(c),T=dd(n),k=v.useRef(!1),[S,E]=v.useState(0);return v.useEffect(()=>{const j=h.current;if(j)return j.addEventListener(Ra,C),()=>j.removeEventListener(Ra,C)},[C]),u.jsx(Cw,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:v.useCallback(j=>y(j),[y]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>E(j=>j-1),[]),children:u.jsx(De.div,{tabIndex:x||S===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,j=>{const _=!k.current;if(j.target===j.currentTarget&&_&&!x){const P=new CustomEvent(Ra,ww);if(j.currentTarget.dispatchEvent(P),!P.defaultPrevented){const D=T().filter(R=>R.focusable),z=D.find(R=>R.active),B=D.find(R=>R.id===g),H=[z,B,...D].filter(Boolean).map(R=>R.ref.current);gd(H,d)}}k.current=!1}),onBlur:ge(e.onBlur,()=>w(!1))})})}),pd="RovingFocusGroupItem",md=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=er(),c=s||l,d=kw(pd,n),f=d.currentTabStopId===c,h=dd(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:g}=d;return v.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),u.jsx(Oa.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: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 x=Nw(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let C=h().filter(T=>T.focusable).map(T=>T.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const T=C.indexOf(y.currentTarget);C=d.loop?Aw(C,T+1):C.slice(T+1)}setTimeout(()=>gd(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});md.displayName=pd;var Ew={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Iw(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Nw(e,t,n){const r=Iw(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Ew[r]}function gd(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Aw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var _w=hd,jw=md,Pw=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Xr=new WeakMap,Os=new WeakMap,Ms={},Ma=0,yd=function(e){return e&&(e.host||yd(e.parentNode))},Rw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=yd(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})},Ow=function(e,t,n,r){var o=Rw(t,Array.isArray(e)?e:[e]);Ms[n]||(Ms[n]=new WeakMap);var s=Ms[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),m=p!==null&&p!=="false",g=(Xr.get(h)||0)+1,y=(s.get(h)||0)+1;Xr.set(h,g),s.set(h,y),i.push(h),g===1&&m&&Os.set(h,!0),y===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),Ma++,function(){i.forEach(function(f){var h=Xr.get(f)-1,p=s.get(f)-1;Xr.set(f,h),s.set(f,p),h||(Os.has(f)||f.removeAttribute(r),Os.delete(f)),p||f.removeAttribute(n)}),Ma--,Ma||(Xr=new WeakMap,Xr=new WeakMap,Os=new WeakMap,Ms={})}},Da=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Pw(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Ow(r,o,n,"aria-hidden")):function(){return null}},Vn=function(){return Vn=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},Vn.apply(this,arguments)};function xd(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 Mw(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 Ds="right-scroll-bar-position",Ls="width-before-scroll-bar",Dw="with-scroll-bars-hidden",Lw="--removed-body-scroll-bar-size";function La(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Fw(e,t){var n=b.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 $w=typeof window<"u"?v.useLayoutEffect:v.useEffect,vd=new WeakMap;function zw(e,t){var n=Fw(null,function(r){return e.forEach(function(o){return La(o,r)})});return $w(function(){var r=vd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||La(a,null)}),s.forEach(function(a){o.has(a)||La(a,i)})}vd.set(n,e)},[e]),n}function Bw(e){return e}function Hw(e,t){t===void 0&&(t=Bw);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 Uw(e){e===void 0&&(e={});var t=Hw(null);return t.options=Vn({async:!0,ssr:!1},e),t}var wd=function(e){var t=e.sideCar,n=xd(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,Vn({},n))};wd.isSideCarExport=!0;function Ww(e,t){return e.useMedium(t),wd}var bd=Uw(),Fa=function(){},Fs=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Fa,onWheelCapture:Fa,onTouchMoveCapture:Fa}),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,m=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,w=x===void 0?"div":x,C=e.gapMode,T=xd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,S=zw([n,t]),E=Vn(Vn({},T),o);return v.createElement(v.Fragment,null,d&&v.createElement(k,{sideCar:bd,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:C}),i?v.cloneElement(v.Children.only(a),Vn(Vn({},E),{ref:S})):v.createElement(w,Vn({},E,{className:l,ref:S}),a))});Fs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Fs.classNames={fullWidth:Ls,zeroRight:Ds};var Vw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Kw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Vw();return t&&e.setAttribute("nonce",t),e}function qw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Gw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Yw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Kw())&&(qw(t,n),Gw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Xw=function(){var e=Yw();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Sd=function(){var e=Xw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Jw={left:0,top:0,right:0,gap:0},$a=function(e){return parseInt(e||"",10)||0},Zw=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)]},Qw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Jw;var t=Zw(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])}},eb=Sd(),Jr="data-scroll-locked",tb=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
39
+ .`.concat(Dw,` {
40
40
  overflow: hidden `).concat(r,`;
41
41
  padding-right: `).concat(a,"px ").concat(r,`;
42
42
  }
43
- body[`).concat(Zr,`] {
43
+ body[`).concat(Jr,`] {
44
44
  overflow: hidden `).concat(r,`;
45
45
  overscroll-behavior: contain;
46
46
  `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
@@ -53,29 +53,29 @@ React keys must be passed directly to JSX without using spread:
53
53
  `),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
54
54
  }
55
55
 
56
- .`).concat(Ls,` {
56
+ .`).concat(Ds,` {
57
57
  right: `).concat(a,"px ").concat(r,`;
58
58
  }
59
59
 
60
- .`).concat(Fs,` {
60
+ .`).concat(Ls,` {
61
61
  margin-right: `).concat(a,"px ").concat(r,`;
62
62
  }
63
63
 
64
- .`).concat(Ls," .").concat(Ls,` {
64
+ .`).concat(Ds," .").concat(Ds,` {
65
65
  right: 0 `).concat(r,`;
66
66
  }
67
67
 
68
- .`).concat(Fs," .").concat(Fs,` {
68
+ .`).concat(Ls," .").concat(Ls,` {
69
69
  margin-right: 0 `).concat(r,`;
70
70
  }
71
71
 
72
- body[`).concat(Zr,`] {
73
- `).concat(Mw,": ").concat(a,`px;
72
+ body[`).concat(Jr,`] {
73
+ `).concat(Lw,": ").concat(a,`px;
74
74
  }
75
- `)},Sd=function(){var e=parseInt(document.body.getAttribute(Zr)||"0",10);return isFinite(e)?e:0},eb=function(){v.useEffect(function(){return document.body.setAttribute(Zr,(Sd()+1).toString()),function(){var e=Sd()-1;e<=0?document.body.removeAttribute(Zr):document.body.setAttribute(Zr,e.toString())}},[])},tb=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;eb();var s=v.useMemo(function(){return Jw(o)},[o]);return v.createElement(Zw,{styles:Qw(s,!t,o,n?"":"!important")})},za=!1;if(typeof window<"u")try{var zs=Object.defineProperty({},"passive",{get:function(){return za=!0,!0}});window.addEventListener("test",zs,zs),window.removeEventListener("test",zs,zs)}catch{za=!1}var Qr=za?{passive:!1}:!1,nb=function(e){return e.tagName==="TEXTAREA"},Cd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!nb(e)&&n[t]==="visible")},rb=function(e){return Cd(e,"overflowY")},ob=function(e){return Cd(e,"overflowX")},kd=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Td(e,r);if(o){var s=Ed(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},sb=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},ib=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Td=function(e,t){return e==="v"?rb(t):ob(t)},Ed=function(e,t){return e==="v"?sb(t):ib(t)},ab=function(e,t){return e==="h"&&t==="rtl"?-1:1},lb=function(e,t,n,r,o){var s=ab(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=Ed(e,a),m=p[0],g=p[1],y=p[2],x=g-y-s*m;(m||x)&&Td(e,a)&&(f+=x,h+=m);var w=a.parentNode;a=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}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]},Id=function(e){return[e.deltaX,e.deltaY]},Nd=function(e){return e&&"current"in e?e.current:e},cb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},ub=function(e){return`
75
+ `)},Cd=function(){var e=parseInt(document.body.getAttribute(Jr)||"0",10);return isFinite(e)?e:0},nb=function(){v.useEffect(function(){return document.body.setAttribute(Jr,(Cd()+1).toString()),function(){var e=Cd()-1;e<=0?document.body.removeAttribute(Jr):document.body.setAttribute(Jr,e.toString())}},[])},rb=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;nb();var s=v.useMemo(function(){return Qw(o)},[o]);return v.createElement(eb,{styles:tb(s,!t,o,n?"":"!important")})},za=!1;if(typeof window<"u")try{var $s=Object.defineProperty({},"passive",{get:function(){return za=!0,!0}});window.addEventListener("test",$s,$s),window.removeEventListener("test",$s,$s)}catch{za=!1}var Zr=za?{passive:!1}:!1,ob=function(e){return e.tagName==="TEXTAREA"},kd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!ob(e)&&n[t]==="visible")},sb=function(e){return kd(e,"overflowY")},ib=function(e){return kd(e,"overflowX")},Td=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Ed(e,r);if(o){var s=Id(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},ab=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},lb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Ed=function(e,t){return e==="v"?sb(t):ib(t)},Id=function(e,t){return e==="v"?ab(t):lb(t)},cb=function(e,t){return e==="h"&&t==="rtl"?-1:1},ub=function(e,t,n,r,o){var s=cb(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=Id(e,a),m=p[0],g=p[1],y=p[2],x=g-y-s*m;(m||x)&&Ed(e,a)&&(f+=x,h+=m);var w=a.parentNode;a=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}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},zs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Nd=function(e){return[e.deltaX,e.deltaY]},Ad=function(e){return e&&"current"in e?e.current:e},db=function(e,t){return e[0]===t[0]&&e[1]===t[1]},fb=function(e){return`
76
76
  .block-interactivity-`.concat(e,` {pointer-events: none;}
77
77
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
78
- `)},db=0,eo=[];function fb(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(db++)[0],s=v.useState(bd)[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 g=Rw([e.lockRef.current],(e.shards||[]).map(Nd),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=Bs(g),w=n.current,C="deltaX"in g?g.deltaX:w[0]-x[0],T="deltaY"in g?g.deltaY:w[1]-x[1],k,S=g.target,E=Math.abs(C)>Math.abs(T)?"h":"v";if("touches"in g&&E==="h"&&S.type==="range")return!1;var j=kd(E,S);if(!j)return!0;if(j?k=E:(k=E==="v"?"h":"v",j=kd(E,S)),!j)return!1;if(!r.current&&"changedTouches"in g&&(C||T)&&(r.current=k),!k)return!0;var _=r.current||k;return lb(_,y,g,_==="h"?C:T)},[]),l=v.useCallback(function(g){var y=g;if(!(!eo.length||eo[eo.length-1]!==s)){var x="deltaY"in y?Id(y):Bs(y),w=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&cb(k.delta,x)})[0];if(w&&w.should){y.cancelable&&y.preventDefault();return}if(!w){var C=(i.current.shards||[]).map(Nd).filter(Boolean).filter(function(k){return k.contains(y.target)}),T=C.length>0?a(y,C[0]):!i.current.noIsolation;T&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(g,y,x,w){var C={name:g,delta:y,target:x,should:w,shadowParent:hb(x)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(T){return T!==C})},1)},[]),d=v.useCallback(function(g){n.current=Bs(g),r.current=void 0},[]),f=v.useCallback(function(g){c(g.type,Id(g),g.target,a(g,e.lockRef.current))},[]),h=v.useCallback(function(g){c(g.type,Bs(g),g.target,a(g,e.lockRef.current))},[]);v.useEffect(function(){return eo.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Qr),document.addEventListener("touchmove",l,Qr),document.addEventListener("touchstart",d,Qr),function(){eo=eo.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,Qr),document.removeEventListener("touchmove",l,Qr),document.removeEventListener("touchstart",d,Qr)}},[]);var p=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:ub(o)}):null,p?v.createElement(tb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function hb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const pb=Hw(wd,fb);var Hs=v.forwardRef(function(e,t){return v.createElement($s,Hn({},e,{ref:t,sideCar:pb}))});Hs.classNames=$s.classNames;var Ba=["Enter"," "],mb=["ArrowDown","PageUp","Home"],Ad=["ArrowUp","PageDown","End"],gb=[...mb,...Ad],yb={ltr:[...Ba,"ArrowRight"],rtl:[...Ba,"ArrowLeft"]},xb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},So="Menu",[Co,vb,wb]=pa(So),[Er,_d]=Zn(So,[wb,Ps,dd]),Us=Ps(),jd=dd(),[bb,Ir]=Er(So),[Sb,ko]=Er(So),Pd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Us(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Gt(s),h=vs(o);return v.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(id,{...a,children:u.jsx(bb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Sb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Pd.displayName=So;var Cb="MenuAnchor",Ha=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Us(n);return u.jsx(ad,{...o,...r,ref:t})});Ha.displayName=Cb;var Ua="MenuPortal",[kb,Rd]=Er(Ua,{forceMount:void 0}),Od=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Ir(Ua,t);return u.jsx(kb,{scope:t,forceMount:n,children:u.jsx(bn,{present:n||s.open,children:u.jsx(Rs,{asChild:!0,container:o,children:r})})})};Od.displayName=Ua;var Sn="MenuContent",[Tb,Wa]=Er(Sn),Md=v.forwardRef((e,t)=>{const n=Rd(Sn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Ir(Sn,e.__scopeMenu),i=ko(Sn,e.__scopeMenu);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(bn,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(Eb,{...o,ref:t}):u.jsx(Ib,{...o,ref:t})})})})}),Eb=v.forwardRef((e,t)=>{const n=Ir(Sn,e.__scopeMenu),r=v.useRef(null),o=Je(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),u.jsx(Va,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Ib=v.forwardRef((e,t)=>{const n=Ir(Sn,e.__scopeMenu);return u.jsx(Va,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Nb=wr.createSlot("MenuContent.ScrollLock"),Va=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:m,...g}=e,y=Ir(Sn,n),x=ko(Sn,n),w=Us(n),C=jd(n),T=vb(n),[k,S]=v.useState(null),E=v.useRef(null),j=Je(t,E,y.onContentChange),_=v.useRef(0),P=v.useRef(""),D=v.useRef(0),z=v.useRef(null),B=v.useRef("right"),O=v.useRef(0),H=m?Hs:v.Fragment,R=m?{as:Nb,allowPinchZoom:!0}:void 0,V=F=>{var te,L;const ne=P.current+F,Q=T().filter(G=>!G.disabled),ye=document.activeElement,Pe=(te=Q.find(G=>G.ref.current===ye))==null?void 0:te.textValue,Z=Q.map(G=>G.textValue),ue=zb(Z,ne,Pe),ke=(L=Q.find(G=>G.textValue===ue))==null?void 0:L.ref.current;(function G(se){P.current=se,window.clearTimeout(_.current),se!==""&&(_.current=window.setTimeout(()=>G(""),1e3))})(ne),ke&&setTimeout(()=>ke.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),ya();const $=v.useCallback(F=>{var Q,ye;return B.current===((Q=z.current)==null?void 0:Q.side)&&Hb(F,(ye=z.current)==null?void 0:ye.area)},[]);return u.jsx(Tb,{scope:n,searchRef:P,onItemEnter:v.useCallback(F=>{$(F)&&F.preventDefault()},[$]),onItemLeave:v.useCallback(F=>{var ne;$(F)||((ne=E.current)==null||ne.focus(),S(null))},[$]),onTriggerLeave:v.useCallback(F=>{$(F)&&F.preventDefault()},[$]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(F=>{z.current=F},[]),children:u.jsx(H,{...R,children:u.jsx(bs,{asChild:!0,trapped:o,onMountAutoFocus:ge(s,F=>{var ne;F.preventDefault(),(ne=E.current)==null||ne.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(ws,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(Nw,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:S,onEntryFocus:ge(l,F=>{x.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ld,{role:"menu","aria-orientation":"vertical","data-state":Zd(y.open),"data-radix-menu-content":"",dir:x.dir,...w,...g,ref:j,style:{outline:"none",...g.style},onKeyDown:ge(g.onKeyDown,F=>{const Q=F.target.closest("[data-radix-menu-content]")===F.currentTarget,ye=F.ctrlKey||F.altKey||F.metaKey,Pe=F.key.length===1;Q&&(F.key==="Tab"&&F.preventDefault(),!ye&&Pe&&V(F.key));const Z=E.current;if(F.target!==Z||!gb.includes(F.key))return;F.preventDefault();const ke=T().filter(te=>!te.disabled).map(te=>te.ref.current);Ad.includes(F.key)&&ke.reverse(),Fb(ke)}),onBlur:ge(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(_.current),P.current="")}),onPointerMove:ge(e.onPointerMove,Eo(F=>{const ne=F.target,Q=O.current!==F.clientX;if(F.currentTarget.contains(ne)&&Q){const ye=F.clientX>O.current?"right":"left";B.current=ye,O.current=F.clientX}}))})})})})})})});Md.displayName=Sn;var Ab="MenuGroup",Ka=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{role:"group",...r,ref:t})});Ka.displayName=Ab;var _b="MenuLabel",Dd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{...r,ref:t})});Dd.displayName=_b;var Ws="MenuItem",Ld="menu.itemSelect",Vs=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=ko(Ws,e.__scopeMenu),a=Wa(Ws,e.__scopeMenu),l=Je(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Ld,{bubbles:!0,cancelable:!0});f.addEventListener(Ld,p=>r==null?void 0:r(p),{once:!0}),gu(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Fd,{...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===" "||Ba.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Vs.displayName=Ws;var Fd=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Wa(Ws,n),a=jd(n),l=v.useRef(null),c=Je(t,l),[d,f]=v.useState(!1),[h,p]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),u.jsx(Co.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(Aw,{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:ge(e.onPointerMove,Eo(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,Eo(m=>i.onItemLeave(m))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),jb="MenuCheckboxItem",$d=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Wd,{scope:e.__scopeMenu,checked:n,children:u.jsx(Vs,{role:"menuitemcheckbox","aria-checked":Ks(n)?"mixed":n,...o,ref:t,"data-state":Ga(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(Ks(n)?!0:!n),{checkForDefaultPrevented:!1})})})});$d.displayName=jb;var zd="MenuRadioGroup",[Pb,Rb]=Er(zd,{value:void 0,onValueChange:()=>{}}),Bd=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Gt(r);return u.jsx(Pb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Ka,{...o,ref:t})})});Bd.displayName=zd;var Hd="MenuRadioItem",Ud=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=Rb(Hd,e.__scopeMenu),s=n===o.value;return u.jsx(Wd,{scope:e.__scopeMenu,checked:s,children:u.jsx(Vs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ga(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Ud.displayName=Hd;var qa="MenuItemIndicator",[Wd,Ob]=Er(qa,{checked:!1}),Vd=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Ob(qa,n);return u.jsx(bn,{present:r||Ks(s.checked)||s.checked===!0,children:u.jsx(De.span,{...o,ref:t,"data-state":Ga(s.checked)})})});Vd.displayName=qa;var Mb="MenuSeparator",Kd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Kd.displayName=Mb;var Db="MenuArrow",qd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Us(n);return u.jsx(cd,{...o,...r,ref:t})});qd.displayName=Db;var Lb="MenuSub",[HT,Gd]=Er(Lb),To="MenuSubTrigger",Yd=v.forwardRef((e,t)=>{const n=Ir(To,e.__scopeMenu),r=ko(To,e.__scopeMenu),o=Gd(To,e.__scopeMenu),s=Wa(To,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(Ha,{asChild:!0,...c,children:u.jsx(Fd,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Zd(n.open),...e,ref:ha(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,Eo(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,Eo(f=>{var p,m;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(m=n.content)==null?void 0:m.dataset.side,y=g==="right",x=y?-5:5,w=h[y?"left":"right"],C=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:w,y:h.top},{x:C,y:h.top},{x:C,y:h.bottom},{x:w,y:h.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ge(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||yb[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Yd.displayName=To;var Xd="MenuSubContent",Jd=v.forwardRef((e,t)=>{const n=Rd(Sn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Ir(Sn,e.__scopeMenu),i=ko(Sn,e.__scopeMenu),a=Gd(Xd,e.__scopeMenu),l=v.useRef(null),c=Je(t,l);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(bn,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:u.jsx(Va,{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=xb[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Jd.displayName=Xd;function Zd(e){return e?"open":"closed"}function Ks(e){return e==="indeterminate"}function Ga(e){return Ks(e)?"indeterminate":e?"checked":"unchecked"}function Fb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function $b(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function zb(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=$b(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Bb(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function Hb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Bb(n,t)}function Eo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Ub=Pd,Wb=Ha,Vb=Od,Kb=Md,qb=Ka,Gb=Dd,Yb=Vs,Xb=$d,Jb=Bd,Zb=Ud,Qb=Vd,e0=Kd,t0=qd,n0=Yd,r0=Jd,qs="DropdownMenu",[o0,UT]=Zn(qs,[_d]),tn=_d(),[s0,Qd]=o0(qs),ef=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]=Kr({prop:o,defaultProp:s??!1,onChange:i,caller:qs});return u.jsx(s0,{scope:t,triggerId:Qn(),triggerRef:c,contentId:Qn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(Ub,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};ef.displayName=qs;var tf="DropdownMenuTrigger",nf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Qd(tf,n),i=tn(n);return u.jsx(Wb,{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:ha(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())})})})});nf.displayName=tf;var i0="DropdownMenuPortal",rf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=tn(t);return u.jsx(Vb,{...r,...n})};rf.displayName=i0;var of="DropdownMenuContent",sf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Qd(of,n),s=tn(n),i=v.useRef(!1);return u.jsx(Kb,{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)"}})});sf.displayName=of;var a0="DropdownMenuGroup",l0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(qb,{...o,...r,ref:t})});l0.displayName=a0;var c0="DropdownMenuLabel",af=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Gb,{...o,...r,ref:t})});af.displayName=c0;var u0="DropdownMenuItem",lf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Yb,{...o,...r,ref:t})});lf.displayName=u0;var d0="DropdownMenuCheckboxItem",cf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Xb,{...o,...r,ref:t})});cf.displayName=d0;var f0="DropdownMenuRadioGroup",h0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Jb,{...o,...r,ref:t})});h0.displayName=f0;var p0="DropdownMenuRadioItem",uf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Zb,{...o,...r,ref:t})});uf.displayName=p0;var m0="DropdownMenuItemIndicator",df=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Qb,{...o,...r,ref:t})});df.displayName=m0;var g0="DropdownMenuSeparator",ff=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(e0,{...o,...r,ref:t})});ff.displayName=g0;var y0="DropdownMenuArrow",x0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(t0,{...o,...r,ref:t})});x0.displayName=y0;var v0="DropdownMenuSubTrigger",hf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(n0,{...o,...r,ref:t})});hf.displayName=v0;var w0="DropdownMenuSubContent",pf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(r0,{...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)"}})});pf.displayName=w0;var b0=ef,S0=nf,C0=rf,mf=sf,gf=af,yf=lf,xf=cf,vf=uf,wf=df,bf=ff,Sf=hf,Cf=pf;const k0=b0,T0=S0,E0=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(Sf,{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"})]}));E0.displayName=Sf.displayName;const I0=v.forwardRef(({className:e,...t},n)=>u.jsx(Cf,{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}));I0.displayName=Cf.displayName;const kf=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(C0,{children:u.jsx(mf,{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})}));kf.displayName=mf.displayName;const Ya=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(yf,{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}));Ya.displayName=yf.displayName;const N0=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(xf,{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(wf,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),t]}));N0.displayName=xf.displayName;const A0=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vf,{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(wf,{children:u.jsx(he.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));A0.displayName=vf.displayName;const _0=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(gf,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));_0.displayName=gf.displayName;const j0=v.forwardRef(({className:e,...t},n)=>u.jsx(bf,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));j0.displayName=bf.displayName;const Gs=1e4;function P0(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
78
+ `)},hb=0,Qr=[];function pb(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(hb++)[0],s=v.useState(Sd)[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 g=Mw([e.lockRef.current],(e.shards||[]).map(Ad),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=zs(g),w=n.current,C="deltaX"in g?g.deltaX:w[0]-x[0],T="deltaY"in g?g.deltaY:w[1]-x[1],k,S=g.target,E=Math.abs(C)>Math.abs(T)?"h":"v";if("touches"in g&&E==="h"&&S.type==="range")return!1;var j=Td(E,S);if(!j)return!0;if(j?k=E:(k=E==="v"?"h":"v",j=Td(E,S)),!j)return!1;if(!r.current&&"changedTouches"in g&&(C||T)&&(r.current=k),!k)return!0;var _=r.current||k;return ub(_,y,g,_==="h"?C:T)},[]),l=v.useCallback(function(g){var y=g;if(!(!Qr.length||Qr[Qr.length-1]!==s)){var x="deltaY"in y?Nd(y):zs(y),w=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&db(k.delta,x)})[0];if(w&&w.should){y.cancelable&&y.preventDefault();return}if(!w){var C=(i.current.shards||[]).map(Ad).filter(Boolean).filter(function(k){return k.contains(y.target)}),T=C.length>0?a(y,C[0]):!i.current.noIsolation;T&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(g,y,x,w){var C={name:g,delta:y,target:x,should:w,shadowParent:mb(x)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(T){return T!==C})},1)},[]),d=v.useCallback(function(g){n.current=zs(g),r.current=void 0},[]),f=v.useCallback(function(g){c(g.type,Nd(g),g.target,a(g,e.lockRef.current))},[]),h=v.useCallback(function(g){c(g.type,zs(g),g.target,a(g,e.lockRef.current))},[]);v.useEffect(function(){return Qr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Zr),document.addEventListener("touchmove",l,Zr),document.addEventListener("touchstart",d,Zr),function(){Qr=Qr.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,Zr),document.removeEventListener("touchmove",l,Zr),document.removeEventListener("touchstart",d,Zr)}},[]);var p=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:fb(o)}):null,p?v.createElement(rb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function mb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const gb=Ww(bd,pb);var Bs=v.forwardRef(function(e,t){return v.createElement(Fs,Vn({},e,{ref:t,sideCar:gb}))});Bs.classNames=Fs.classNames;var Ba=["Enter"," "],yb=["ArrowDown","PageUp","Home"],_d=["ArrowUp","PageDown","End"],xb=[...yb,..._d],vb={ltr:[...Ba,"ArrowRight"],rtl:[...Ba,"ArrowLeft"]},wb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},So="Menu",[Co,bb,Sb]=pa(So),[Tr,jd]=Qn(So,[Sb,js,fd]),Hs=js(),Pd=fd(),[Cb,Er]=Tr(So),[kb,ko]=Tr(So),Rd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Hs(t),[l,c]=v.useState(null),d=v.useRef(!1),f=qt(s),h=xs(o);return v.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(ad,{...a,children:u.jsx(Cb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(kb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Rd.displayName=So;var Tb="MenuAnchor",Ha=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Hs(n);return u.jsx(ld,{...o,...r,ref:t})});Ha.displayName=Tb;var Ua="MenuPortal",[Eb,Od]=Tr(Ua,{forceMount:void 0}),Md=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Er(Ua,t);return u.jsx(Eb,{scope:t,forceMount:n,children:u.jsx(Sn,{present:n||s.open,children:u.jsx(Ps,{asChild:!0,container:o,children:r})})})};Md.displayName=Ua;var Cn="MenuContent",[Ib,Wa]=Tr(Cn),Dd=v.forwardRef((e,t)=>{const n=Od(Cn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Er(Cn,e.__scopeMenu),i=ko(Cn,e.__scopeMenu);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(Sn,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(Nb,{...o,ref:t}):u.jsx(Ab,{...o,ref:t})})})})}),Nb=v.forwardRef((e,t)=>{const n=Er(Cn,e.__scopeMenu),r=v.useRef(null),o=Ze(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),u.jsx(Va,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Ab=v.forwardRef((e,t)=>{const n=Er(Cn,e.__scopeMenu);return u.jsx(Va,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),_b=vr.createSlot("MenuContent.ScrollLock"),Va=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:m,...g}=e,y=Er(Cn,n),x=ko(Cn,n),w=Hs(n),C=Pd(n),T=bb(n),[k,S]=v.useState(null),E=v.useRef(null),j=Ze(t,E,y.onContentChange),_=v.useRef(0),P=v.useRef(""),D=v.useRef(0),z=v.useRef(null),B=v.useRef("right"),O=v.useRef(0),H=m?Bs:v.Fragment,R=m?{as:_b,allowPinchZoom:!0}:void 0,V=F=>{var te,L;const ne=P.current+F,Q=T().filter(q=>!q.disabled),ye=document.activeElement,je=(te=Q.find(q=>q.ref.current===ye))==null?void 0:te.textValue,J=Q.map(q=>q.textValue),ue=Hb(J,ne,je),ke=(L=Q.find(q=>q.textValue===ue))==null?void 0:L.ref.current;(function q(ie){P.current=ie,window.clearTimeout(_.current),ie!==""&&(_.current=window.setTimeout(()=>q(""),1e3))})(ne),ke&&setTimeout(()=>ke.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),ya();const $=v.useCallback(F=>{var Q,ye;return B.current===((Q=z.current)==null?void 0:Q.side)&&Wb(F,(ye=z.current)==null?void 0:ye.area)},[]);return u.jsx(Ib,{scope:n,searchRef:P,onItemEnter:v.useCallback(F=>{$(F)&&F.preventDefault()},[$]),onItemLeave:v.useCallback(F=>{var ne;$(F)||((ne=E.current)==null||ne.focus(),S(null))},[$]),onTriggerLeave:v.useCallback(F=>{$(F)&&F.preventDefault()},[$]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(F=>{z.current=F},[]),children:u.jsx(H,{...R,children:u.jsx(ws,{asChild:!0,trapped:o,onMountAutoFocus:ge(s,F=>{var ne;F.preventDefault(),(ne=E.current)==null||ne.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(vs,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(_w,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:S,onEntryFocus:ge(l,F=>{x.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(cd,{role:"menu","aria-orientation":"vertical","data-state":Qd(y.open),"data-radix-menu-content":"",dir:x.dir,...w,...g,ref:j,style:{outline:"none",...g.style},onKeyDown:ge(g.onKeyDown,F=>{const Q=F.target.closest("[data-radix-menu-content]")===F.currentTarget,ye=F.ctrlKey||F.altKey||F.metaKey,je=F.key.length===1;Q&&(F.key==="Tab"&&F.preventDefault(),!ye&&je&&V(F.key));const J=E.current;if(F.target!==J||!xb.includes(F.key))return;F.preventDefault();const ke=T().filter(te=>!te.disabled).map(te=>te.ref.current);_d.includes(F.key)&&ke.reverse(),zb(ke)}),onBlur:ge(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(_.current),P.current="")}),onPointerMove:ge(e.onPointerMove,Eo(F=>{const ne=F.target,Q=O.current!==F.clientX;if(F.currentTarget.contains(ne)&&Q){const ye=F.clientX>O.current?"right":"left";B.current=ye,O.current=F.clientX}}))})})})})})})});Dd.displayName=Cn;var jb="MenuGroup",Ka=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{role:"group",...r,ref:t})});Ka.displayName=jb;var Pb="MenuLabel",Ld=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{...r,ref:t})});Ld.displayName=Pb;var Us="MenuItem",Fd="menu.itemSelect",Ws=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=ko(Us,e.__scopeMenu),a=Wa(Us,e.__scopeMenu),l=Ze(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Fd,{bubbles:!0,cancelable:!0});f.addEventListener(Fd,p=>r==null?void 0:r(p),{once:!0}),yu(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx($d,{...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===" "||Ba.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Ws.displayName=Us;var $d=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Wa(Us,n),a=Pd(n),l=v.useRef(null),c=Ze(t,l),[d,f]=v.useState(!1),[h,p]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),u.jsx(Co.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(jw,{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:ge(e.onPointerMove,Eo(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,Eo(m=>i.onItemLeave(m))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),Rb="MenuCheckboxItem",zd=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Vd,{scope:e.__scopeMenu,checked:n,children:u.jsx(Ws,{role:"menuitemcheckbox","aria-checked":Vs(n)?"mixed":n,...o,ref:t,"data-state":Ga(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(Vs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});zd.displayName=Rb;var Bd="MenuRadioGroup",[Ob,Mb]=Tr(Bd,{value:void 0,onValueChange:()=>{}}),Hd=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=qt(r);return u.jsx(Ob,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Ka,{...o,ref:t})})});Hd.displayName=Bd;var Ud="MenuRadioItem",Wd=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=Mb(Ud,e.__scopeMenu),s=n===o.value;return u.jsx(Vd,{scope:e.__scopeMenu,checked:s,children:u.jsx(Ws,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ga(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Wd.displayName=Ud;var qa="MenuItemIndicator",[Vd,Db]=Tr(qa,{checked:!1}),Kd=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Db(qa,n);return u.jsx(Sn,{present:r||Vs(s.checked)||s.checked===!0,children:u.jsx(De.span,{...o,ref:t,"data-state":Ga(s.checked)})})});Kd.displayName=qa;var Lb="MenuSeparator",qd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});qd.displayName=Lb;var Fb="MenuArrow",Gd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Hs(n);return u.jsx(ud,{...o,...r,ref:t})});Gd.displayName=Fb;var $b="MenuSub",[WT,Yd]=Tr($b),To="MenuSubTrigger",Xd=v.forwardRef((e,t)=>{const n=Er(To,e.__scopeMenu),r=ko(To,e.__scopeMenu),o=Yd(To,e.__scopeMenu),s=Wa(To,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(Ha,{asChild:!0,...c,children:u.jsx($d,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Qd(n.open),...e,ref:ha(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,Eo(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,Eo(f=>{var p,m;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(m=n.content)==null?void 0:m.dataset.side,y=g==="right",x=y?-5:5,w=h[y?"left":"right"],C=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:w,y:h.top},{x:C,y:h.top},{x:C,y:h.bottom},{x:w,y:h.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ge(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||vb[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Xd.displayName=To;var Jd="MenuSubContent",Zd=v.forwardRef((e,t)=>{const n=Od(Cn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Er(Cn,e.__scopeMenu),i=ko(Cn,e.__scopeMenu),a=Yd(Jd,e.__scopeMenu),l=v.useRef(null),c=Ze(t,l);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(Sn,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:u.jsx(Va,{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=wb[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Zd.displayName=Jd;function Qd(e){return e?"open":"closed"}function Vs(e){return e==="indeterminate"}function Ga(e){return Vs(e)?"indeterminate":e?"checked":"unchecked"}function zb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Bb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Hb(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=Bb(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 Ub(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 Wb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Ub(n,t)}function Eo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Vb=Rd,Kb=Ha,qb=Md,Gb=Dd,Yb=Ka,Xb=Ld,Jb=Ws,Zb=zd,Qb=Hd,e0=Wd,t0=Kd,n0=qd,r0=Gd,o0=Xd,s0=Zd,Ks="DropdownMenu",[i0,VT]=Qn(Ks,[jd]),rn=jd(),[a0,ef]=i0(Ks),tf=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]=Vr({prop:o,defaultProp:s??!1,onChange:i,caller:Ks});return u.jsx(a0,{scope:t,triggerId:er(),triggerRef:c,contentId:er(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(Vb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};tf.displayName=Ks;var nf="DropdownMenuTrigger",rf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=ef(nf,n),i=rn(n);return u.jsx(Kb,{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:ha(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())})})})});rf.displayName=nf;var l0="DropdownMenuPortal",of=e=>{const{__scopeDropdownMenu:t,...n}=e,r=rn(t);return u.jsx(qb,{...r,...n})};of.displayName=l0;var sf="DropdownMenuContent",af=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=ef(sf,n),s=rn(n),i=v.useRef(!1);return u.jsx(Gb,{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)"}})});af.displayName=sf;var c0="DropdownMenuGroup",u0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(Yb,{...o,...r,ref:t})});u0.displayName=c0;var d0="DropdownMenuLabel",lf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(Xb,{...o,...r,ref:t})});lf.displayName=d0;var f0="DropdownMenuItem",cf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(Jb,{...o,...r,ref:t})});cf.displayName=f0;var h0="DropdownMenuCheckboxItem",uf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(Zb,{...o,...r,ref:t})});uf.displayName=h0;var p0="DropdownMenuRadioGroup",m0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(Qb,{...o,...r,ref:t})});m0.displayName=p0;var g0="DropdownMenuRadioItem",df=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(e0,{...o,...r,ref:t})});df.displayName=g0;var y0="DropdownMenuItemIndicator",ff=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(t0,{...o,...r,ref:t})});ff.displayName=y0;var x0="DropdownMenuSeparator",hf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(n0,{...o,...r,ref:t})});hf.displayName=x0;var v0="DropdownMenuArrow",w0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(r0,{...o,...r,ref:t})});w0.displayName=v0;var b0="DropdownMenuSubTrigger",pf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(o0,{...o,...r,ref:t})});pf.displayName=b0;var S0="DropdownMenuSubContent",mf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(s0,{...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)"}})});mf.displayName=S0;var C0=tf,k0=rf,T0=of,gf=af,yf=lf,xf=cf,vf=uf,wf=df,bf=ff,Sf=hf,Cf=pf,kf=mf;const E0=C0,I0=k0,N0=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(Cf,{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"})]}));N0.displayName=Cf.displayName;const A0=v.forwardRef(({className:e,...t},n)=>u.jsx(kf,{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}));A0.displayName=kf.displayName;const Tf=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(T0,{children:u.jsx(gf,{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})}));Tf.displayName=gf.displayName;const Ya=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(xf,{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}));Ya.displayName=xf.displayName;const _0=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(vf,{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(bf,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),t]}));_0.displayName=vf.displayName;const j0=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(wf,{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(bf,{children:u.jsx(he.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));j0.displayName=wf.displayName;const P0=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(yf,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));P0.displayName=yf.displayName;const R0=v.forwardRef(({className:e,...t},n)=>u.jsx(Sf,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));R0.displayName=Sf.displayName;const qs=1e4;function O0(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
79
79
  `).replace(/<p>(.*?)<\/p>/gi,`$1
80
80
 
81
81
  `).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
@@ -83,24 +83,24 @@ React keys must be passed directly to JSX without using spread:
83
83
  `).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
84
84
  `).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
85
85
  `).replace(/<li>(.*?)<\/li>/gi,`- $1
86
- `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function R0(e,t=Gs){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 O0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),R0(t),P0(t)}const Ys=0,cr=1,to=2,Tf=4;function Ef(e){return()=>e}function M0(e){e()}function If(e,t){return n=>e(t(n))}function Nf(e,t){return()=>e(t)}function D0(e,t){return n=>e(t,n)}function Xa(e){return e!==void 0}function L0(...e){return()=>{e.map(M0)}}function no(){}function Xs(e,t){return t(e),e}function F0(e,t){return t(e)}function Tt(...e){return e}function ut(e,t){return e(cr,t)}function ze(e,t){e(Ys,t)}function Ja(e){e(to)}function Ot(e){return e(Tf)}function we(e,t){return ut(e,D0(t,Ys))}function Pn(e,t){const n=e(cr,r=>{n(),t(r)});return n}function Af(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function _f(e,t){return e===t}function Et(e=_f){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function je(e){return t=>n=>{e(n)&&t(n)}}function pe(e){return t=>If(t,e)}function Un(e){return t=>()=>{t(e)}}function X(e,...t){const n=$0(...t);return(r,o)=>{switch(r){case to:Ja(e);return;case cr:return ut(e,n(o))}}}function Wn(e,t){return n=>r=>{n(t=e(t,r))}}function Nr(e){return t=>n=>{e>0?e--:t(n)}}function nr(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ue(...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);ut(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 $0(...e){return t=>e.reduceRight(F0,t)}function z0(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case cr:return s?n===s?void 0:(r(),n=s,t=ut(e,s),t):(r(),no);case to:r(),n=null;return}}}function ee(e){let t=e;const n=Ze();return(r,o)=>{switch(r){case Ys:t=o;break;case cr:{o(t);break}case Tf:return t}return n(r,o)}}function Xt(e,t){return Xs(ee(t),n=>we(e,n))}function Ze(){const e=[];return(t,n)=>{switch(t){case Ys:e.slice().forEach(r=>{r(n)});return;case to:e.splice(0,e.length);return;case cr:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function gn(e){return Xs(Ze(),t=>we(e,t))}function it(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:B0(),singleton:n}}const B0=()=>Symbol();function H0(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 $t(...e){const t=Ze(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);ut(s,l=>{n[i]=l,r=r|a,r===o&&ze(t,n)})}),function(s,i){switch(s){case to:{Ja(t);return}case cr:return r===o&&i(n),ut(t,i)}}}function Ae(e,t=_f){return X(e,Et(t))}function Za(...e){return function(t,n){switch(t){case to:return;case cr:return L0(...e.map(r=>ut(r,n)))}}}var dn=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(dn||{});const U0={0:"debug",3:"error",1:"log",2:"warn"},W0=()=>typeof globalThis>"u"?window:globalThis,ur=it(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=W0().VIRTUOSO_LOG_LEVEL)!=null?o:Ot(e);r>=s&&console[U0[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Ar(e,t,n){return Qa(e,t,n).callbackRef}function Qa(e,t,n){const r=b.useRef(null);let o=i=>{};const s=b.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 V0(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const f=K0(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 m;p&&(m=h.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:p?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?jf("column-gap",getComputedStyle(d).columnGap,o):jf("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Qa(c,n,l)}function K0(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},dn.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 jf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,dn.WARN),t==="normal"?0:parseInt(t??"0",10)}function Pf(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=c.top-p.top;h=p.height-Math.max(0,m),f=m+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}=Qa(o,!0,n),a=b.useCallback(()=>{o(i.current)},[o,i]);return b.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=it(()=>{const e=Ze(),t=Ze(),n=ee(0),r=Ze(),o=ee(0),s=Ze(),i=Ze(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Ze(),h=Ze(),p=ee(!1),m=ee(!1),g=ee(!1);return we(X(e,pe(({scrollTop:y})=>y)),t),we(X(e,pe(({scrollHeight:y})=>y)),i),we(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Io={lvl:0};function Rf(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 wt(e){return e===Io}function No(e,t){if(!wt(e))return t===e.k?e.v:t<e.k?No(e.l,t):No(e.r,t)}function Rn(e,t,n="k"){if(wt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Rn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Rn(e.l,t,n)}function yn(e,t,n){return wt(e)?Df(t,n,1):t===e.k?Bt(e,{k:t,v:n}):t<e.k?Lf(Bt(e,{l:yn(e.l,t,n)})):Lf(Bt(e,{r:yn(e.r,t,n)}))}function ro(){return Io}function Js(e,t,n){if(wt(e))return[];const r=Rn(e,t)[0];return q0(tl(e,r,n))}function el(e,t){if(wt(e))return Io;const{k:n,l:r,r:o}=e;if(t===n){if(wt(r))return o;if(wt(o))return r;{const[s,i]=Mf(r);return Zs(Bt(e,{k:s,l:Of(r),v:i}))}}else return t<n?Zs(Bt(e,{l:el(r,t)})):Zs(Bt(e,{r:el(o,t)}))}function _r(e){return wt(e)?[]:[..._r(e.l),{k:e.k,v:e.v},..._r(e.r)]}function tl(e,t,n){if(wt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(tl(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(tl(s,t,n))),a}function Zs(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(nl(t))return Ff(Bt(e,{lvl:n-1}));if(!wt(t)&&!wt(t.r))return Bt(t.r,{l:Bt(t,{r:t.r.l}),lvl:n,r:Bt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(nl(e))return rl(Bt(e,{lvl:n-1}));if(!wt(r)&&!wt(r.l)){const o=r.l,s=nl(o)?r.lvl-1:r.lvl;return Bt(o,{l:Bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:rl(Bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Bt(e,t){return Df(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 Of(e){return wt(e.r)?e.l:Zs(Bt(e,{r:Of(e.r)}))}function nl(e){return wt(e)||e.lvl>e.r.lvl}function Mf(e){return wt(e.r)?[e.k,e.v]:Mf(e.r)}function Df(e,t,n,r=Io,o=Io){return{k:e,l:r,lvl:n,r:o,v:t}}function Lf(e){return rl(Ff(e))}function Ff(e){const{l:t}=e;return!wt(t)&&t.lvl===e.lvl?Bt(t,{r:Bt(e,{l:t.r})}):e}function rl(e){const{lvl:t,r:n}=e;return!wt(n)&&!wt(n.r)&&n.lvl===t&&n.r.lvl===t?Bt(n,{l:Bt(e,{r:n.l}),lvl:t+1}):e}function q0(e){return Rf(e,({k:t,v:n})=>({index:t,value:n}))}function $f(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Ao(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ol=it(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function zf(e,t,n){return e[Qs(e,t,n)]}function Qs(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 G0(e,t,n,r){const o=Qs(e,t,r),s=Qs(e,n,r,o);return e.slice(o,s+1)}function dr(e,t){return Math.round(e.getBoundingClientRect()[t])}function ei(e){return!wt(e.groupOffsetTree)}function sl({index:e},t){return t===e?0:t<e?-1:1}function Y0(){return{groupIndices:[],groupOffsetTree:ro(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ro()}}function X0(e,t){let n=wt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),wt(e)){e=yn(e,0,s);continue}const a=Js(e,i-1,o+1);if(a.some(rS(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=el(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=yn(e,o+1,h));c&&(e=yn(e,i,s))}return[e,n]}function J0(e){return typeof e.groupIndex<"u"}function Z0({offset:e},t){return t===e?0:t<e?-1:1}function _o(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=zf(t,e,sl),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Bf(e,t){if(!ei(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Hf(e,t,n){if(J0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Bf(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Q0(e,t,n,r=0){return r>0&&(t=Math.max(t,zf(e,r,sl).offset)),Rf(G0(e,t,n,Z0),nS)}function eS(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,dn.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&wt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,g)=>yn(yn(m,g,h),g+1,p),i)}else[i,a]=X0(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=il(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>yn(h,p,_o(p,f,o)),ro()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function tS(e){return _r(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 Uf(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 il(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Qs(o,t-1,sl),a=o[l].offset;const c=Rn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===Rn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of Js(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 nS(e){return{index:e.index,value:e}}function rS(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 oS={offsetHeight:"height",offsetWidth:"width"},Vn=it(([{log:e},{recalcInProgress:t}])=>{const n=Ze(),r=Ze(),o=Xt(r,0),s=Ze(),i=Ze(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((k,S)=>dr(k,oS[S])),h=ee(void 0),p=ee(0),m=Y0(),g=Xt(X(n,Ue(l,e,p),Wn(eS,m),Et()),m),y=Xt(X(l,Et(),Wn((k,S)=>({current:S,prev:k.current}),{current:[],prev:[]}),pe(({prev:k})=>k)),[]);we(X(l,je(k=>k.length>0),Ue(g,p),pe(([k,S,E])=>{const j=k.reduce((_,P,D)=>yn(_,P,_o(P,S.offsetTree,E)||D),ro());return{...S,groupIndices:k,groupOffsetTree:j}})),g),we(X(r,Ue(g),je(([k,{lastIndex:S}])=>k<S),pe(([k,{lastIndex:S,lastSize:E}])=>[{endIndex:S,size:E,startIndex:k}])),n),we(c,d);const x=Xt(X(c,pe(k=>k===void 0)),!0);we(X(d,je(k=>k!==void 0&&wt(Ot(g).sizeTree)),pe(k=>[{endIndex:0,size:k,startIndex:0}])),n);const w=gn(X(n,Ue(g),Wn(({sizes:k},[S,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:m}),pe(k=>k.changed)));ut(X(a,Wn((k,S)=>({diff:k.prev-S,prev:S}),{diff:0,prev:0}),pe(k=>k.diff)),k=>{const{groupIndices:S}=Ot(g);if(k>0)ze(t,!0),ze(s,k+Uf(k,S));else if(k<0){const E=Ot(y);E.length>0&&(k-=Uf(-k,E)),ze(i,k)}}),ut(X(a,Ue(e)),([k,S])=>{k<0&&S("`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},dn.ERROR)});const C=gn(s);we(X(s,Ue(g),pe(([k,S])=>{const E=S.groupIndices.length>0,j=[],_=S.lastSize;if(E){const P=No(S.sizeTree,0);let D=0,z=0;for(;D<k;){const O=S.groupIndices[z],H=S.groupIndices.length===z+1?1/0:S.groupIndices[z+1]-O-1;j.push({endIndex:O,size:P,startIndex:O}),j.push({endIndex:O+1+H-1,size:_,startIndex:O+1}),z++,D+=H+1}const B=_r(S.sizeTree);return D!==k&&B.shift(),B.reduce((O,{k:H,v:R})=>{let V=O.ranges;return O.prevSize!==0&&(V=[...O.ranges,{endIndex:H+k-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:H+k,prevSize:R,ranges:V}},{prevIndex:k,prevSize:0,ranges:j}).ranges}return _r(S.sizeTree).reduce((P,{k:D,v:z})=>({prevIndex:D+k,prevSize:z,ranges:[...P.ranges,{endIndex:D+k-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const T=gn(X(i,Ue(g,p),pe(([k,{offsetTree:S},E])=>{const j=-k;return _o(j,S,E)})));return we(X(i,Ue(g,p),pe(([k,S,E])=>{if(S.groupIndices.length>0){if(wt(S.sizeTree))return S;let j=ro();const _=Ot(y);let P=0,D=0,z=0;for(;P<-k;){z=_[D];const B=_[D+1]-z-1;D++,P+=B+1}if(j=_r(S.sizeTree).reduce((B,{k:O,v:H})=>yn(B,Math.max(0,O+k),H),j),P!==-k){const B=No(S.sizeTree,z);j=yn(j,0,B);const O=Rn(S.sizeTree,-k+1)[1];j=yn(j,1,O)}return{...S,sizeTree:j,...il(S.offsetTree,0,j,E)}}else{const j=_r(S.sizeTree).reduce((_,{k:P,v:D})=>yn(_,Math.max(0,P+k),D),ro());return{...S,sizeTree:j,...il(S.offsetTree,0,j,E)}}})),g),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Tt(ur,ol),{singleton:!0});function sS(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Wf=it(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ze(),i=Ze(),a=gn(X(s,pe(sS)));return we(X(a,pe(l=>l.totalCount)),n),we(X(a,pe(l=>l.groupIndices)),e),we(X($t(o,t,r),je(([l,c])=>ei(c)),pe(([l,c,d])=>Rn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),Et(),pe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},Tt(Vn,nn)),fr=it(([{log:e}])=>{const t=ee(!1),n=gn(X(t,je(r=>r),Et()));return ut(t,r=>{r&&Ot(e)("props updated",{},dn.DEBUG)}),{didMount:n,propsReady:t}},Tt(ur),{singleton:!0}),iS=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Vf(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!iS)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const jo=it(([{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=Ze(),m=Ze(),g=ee(0);let y=null,x=null,w=null;function C(){y&&(y(),y=null),w&&(w(),w=null),x&&(clearTimeout(x),x=null),ze(l,!1)}return we(X(p,Ue(n,f,r,g,a,i,h),Ue(e,s,o),pe(([[T,k,S,E,j,_,P,D],z,B,O])=>{const H=Vf(T),{align:R,behavior:V,offset:$}=H,F=E-1,ne=Hf(H,k,F);let Q=_o(ne,k.offsetTree,z)+_;R==="end"?(Q+=B+Rn(k.sizeTree,ne)[1]-S+O,ne===F&&(Q+=P)):R==="center"?Q+=(B+Rn(k.sizeTree,ne)[1]-S+O)/2:Q-=j,$&&(Q+=$);const ye=Pe=>{C(),Pe?(D("retrying to scroll to",{location:T},dn.DEBUG),ze(p,T)):(ze(m,!0),D("list did not change, scroll successful",{},dn.DEBUG))};if(C(),V==="smooth"){let Pe=!1;w=ut(t,Z=>{Pe=Pe||Z}),y=Pn(d,()=>{ye(Pe)})}else y=Pn(X(t,aS(150)),ye);return x=setTimeout(()=>{C()},1200),ze(l,!0),D("scrolling from index to",{behavior:V,index:ne,top:Q},dn.DEBUG),{behavior:V,top:Q}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:g}},Tt(Vn,nn,ur),{singleton:!0});function aS(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function al(e,t){e==0?t():requestAnimationFrame(()=>{al(e-1,t)})}function ll(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Po=it(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return we(X(i,Ue(l),je(([d,f])=>!!f),Un(!1)),a),we(X(i,Ue(l),je(([d,f])=>!!f),Un(!1)),c),ut(X($t(t,i),Ue(a,n,e,c),je(([[,d],f,{sizeTree:h},p,m])=>d&&(!wt(h)||Xa(p))&&!f&&!m),Ue(l)),([,d])=>{Pn(o,()=>{ze(c,!0)}),al(4,()=>{Pn(r,()=>{ze(a,!0)}),ze(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},Tt(Vn,nn,jo,fr),{singleton:!0});function Kf(e,t){return Math.abs(e-t)<1.01}const Ro="up",Oo="down",lS="none",cS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},uS=0,Mo=it(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Ze(),c=Ze(),d=ee(4),f=ee(uS),h=Xt(X(Za(X(Ae(o),Nr(1),Un(!0)),X(Ae(o),Nr(1),Un(!1),Af(100))),Et()),!1),p=Xt(X(Za(X(n,Un(!0)),X(n,Un(!1),Af(200))),Et()),!1);we(X($t(Ae(o),Ae(f)),pe(([w,C])=>w<=C),Et()),a),we(X(a,nr(50)),c);const m=gn(X($t(r,Ae(s),Ae(t),Ae(e),Ae(d)),Wn((w,[{scrollHeight:C,scrollTop:T},k,S,E,j])=>{const _=T+k-C>-j,P={scrollHeight:C,scrollTop:T,viewportHeight:k};if(_){let z,B;return T>w.state.scrollTop?(z="SCROLLED_DOWN",B=w.state.scrollTop-T):(z="SIZE_DECREASED",B=w.state.scrollTop-T||w.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:B,state:P}}let D;return P.scrollHeight>w.state.scrollHeight?D="SIZE_INCREASED":k<w.state.viewportHeight?D="VIEWPORT_HEIGHT_DECREASING":T<w.state.scrollTop?D="SCROLLING_UPWARDS":D="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:D,state:P}},cS),Et((w,C)=>w&&w.atBottom===C.atBottom))),g=Xt(X(r,Wn((w,{scrollHeight:C,scrollTop:T,viewportHeight:k})=>{if(Kf(w.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:T};{const S=C-(T+k)<1;return w.scrollTop!==T&&S?{changed:!0,jump:w.scrollTop-T,scrollHeight:C,scrollTop:T}:{changed:!0,jump:0,scrollHeight:C,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),je(w=>w.changed),pe(w=>w.jump)),0);we(X(m,pe(w=>w.atBottom)),i),we(X(i,nr(50)),l);const y=ee(Oo);we(X(r,pe(({scrollTop:w})=>w),Et(),Wn((w,C)=>Ot(p)?{direction:w.direction,prevScrollTop:C}:{direction:C<w.prevScrollTop?Ro:Oo,prevScrollTop:C},{direction:Oo,prevScrollTop:0}),pe(w=>w.direction)),y),we(X(r,nr(50),Un(lS)),y);const x=ee(0);return we(X(h,je(w=>!w),Un(0)),x),we(X(o,nr(100),Ue(h),je(([w,C])=>!!C),Wn(([w,C],[T])=>[C,T],[0,0]),pe(([w,C])=>C-w)),x),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},Tt(nn)),ti="top",ni="bottom",qf="none";function Gf(e,t,n){return typeof e=="number"?n===Ro&&t===ti||n===Oo&&t===ni?e:0:n===Ro?t===ti?e.main:e.reverse:t===ni?e.main:e.reverse}function Yf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const cl=it(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ze(),i=ee(0),a=ee(0),l=ee(0),c=Xt(X($t(Ae(r),Ae(o),Ae(n),Ae(s,Ao),Ae(l),Ae(i),Ae(t),Ae(e),Ae(a)),pe(([d,f,h,[p,m],g,y,x,w,C])=>{const T=d-w,k=y+x,S=Math.max(h-T,0);let E=qf;const j=Yf(C,ti),_=Yf(C,ni);return p-=w,p+=h+x,m+=h+x,m-=w,p>d+k-j&&(E=Ro),m<d-S+f+_&&(E=Oo),E!==qf?[Math.max(T-h-Gf(g,ti,E)-j,0),T-S-x+f+Gf(g,ni,E)+_]:null}),je(d=>d!=null),Et(Ao)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},Tt(nn),{singleton:!0});function dS(e,t,n){if(ei(t)){const r=Bf(e,t);return[{index:Rn(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 ul={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ri(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 g=e[e.length-1];d=g.offset+g.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,m=h-d;return{bottom:d,firstItemIndex:s,items:Jf(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:Jf(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function Xf(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=ll(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ri(c,[],a,o,n,r)}function Jf(e,t,n){if(e.length===0)return[];if(!ei(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=Js(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 jr=it(([{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:m}])=>{const g=ee([]),y=ee(0),x=Ze();we(s.topItemsIndexes,g);const w=Xt(X($t(p,m,Ae(l,Ao),Ae(o),Ae(r),Ae(c),d,Ae(g),Ae(t),Ae(n),e),je(([S,E,,j,,,,,,,_])=>{const P=_&&_.length!==j;return S&&!E&&!P}),pe(([,,[S,E],j,_,P,D,z,B,O,H])=>{const R=_,{offsetTree:V,sizeTree:$}=R,F=Ot(y);if(j===0)return{...ul,totalCount:j};if(S===0&&E===0)return F===0?{...ul,totalCount:j}:Xf(F,P,_,B,O,H||[]);if(wt($))return F>0?null:ri(dS(ll(P,j),R,H),[],j,O,R,B);const ne=[];if(z.length>0){const ue=z[0],ke=z[z.length-1];let te=0;for(const L of Js($,ue,ke)){const G=L.value,se=Math.max(L.start,ue),le=Math.min(L.end,ke);for(let U=se;U<=le;U++)ne.push({data:H==null?void 0:H[U],index:U,offset:te,size:G}),te+=G}}if(!D)return ri([],ne,j,O,R,B);const Q=z.length>0?z[z.length-1]+1:0,ye=Q0(V,S,E,Q);if(ye.length===0)return null;const Pe=j-1,Z=Xs([],ue=>{for(const ke of ye){const te=ke.value;let L=te.offset,G=ke.start;const se=te.size;if(te.offset<S){G+=Math.floor((S-te.offset+O)/(se+O));const U=G-ke.start;L+=U*se+U*O}G<Q&&(L+=(Q-G)*se,G=Q);const le=Math.min(ke.end,Pe);for(let U=G;U<=le&&!(L>=E);U++)ue.push({data:H==null?void 0:H[U],index:U,offset:L,size:se}),L+=se+O}});return ri(Z,ne,j,O,R,B)}),je(S=>S!==null),Et()),ul);we(X(e,je(Xa),pe(S=>S==null?void 0:S.length)),o),we(X(w,pe(S=>S.topListHeight)),f),we(f,a),we(X(w,pe(S=>[S.top,S.bottom])),i),we(X(w,pe(S=>S.items)),x);const C=gn(X(w,je(({items:S})=>S.length>0),Ue(o,e),je(([{items:S},E])=>S[S.length-1].originalIndex===E-1),pe(([,S,E])=>[S-1,E]),Et(Ao),pe(([S])=>S))),T=gn(X(w,nr(200),je(({items:S,topItems:E})=>S.length>0&&S[0].originalIndex===E.length),pe(({items:S})=>S[0].index),Et())),k=gn(X(w,je(({items:S})=>S.length>0),pe(({items:S})=>{let E=0,j=S.length-1;for(;S[E].type==="group"&&E<j;)E++;for(;S[j].type==="group"&&j>E;)j--;return{endIndex:S[j].index,startIndex:S[E].index}}),Et($f)));return{endReached:C,initialItemCount:y,itemsRendered:x,listState:w,rangeChanged:k,startReached:T,topItemsIndexes:g,...h}},Tt(Vn,Wf,cl,Po,jo,Mo,fr,ol),{singleton:!0}),Zf=it(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ze(),i=Xt(X($t(n,e,r,t,o),pe(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return we(Ae(i),s),{totalListHeight:i,totalListHeightChanged:s}},Tt(nn,jr),{singleton:!0}),fS=it(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Xt(X($t(n,e,t),je(([o])=>o),pe(([,o,s])=>Math.max(0,o-s)),nr(0),Et()),0);return{alignToBottom:n,paddingTopAddition:r}},Tt(nn,Zf),{singleton:!0}),Qf=it(()=>({context:ee(null)})),hS=({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,eh=it(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ze();return we(X(d,Ue(t,l,n,s,o,r,a),Ue(e),pe(([[f,h,p,m,g,y,x,w],C])=>{const{align:T,behavior:k,calculateViewLocation:S=hS,done:E,...j}=f,_=Hf(f,h,m-1),P=_o(_,h.offsetTree,C)+g+y,D=P+Rn(h.sizeTree,_)[1],z=w+y,B=w+p-x,O=S({itemBottom:D,itemTop:P,locationParams:{align:T,behavior:k,...j},viewportBottom:B,viewportTop:z});return O?E&&Pn(X(i,je(H=>!H),Nr(Ot(i)?1:2)),E):E&&E(),O}),je(f=>f!==null)),c),{scrollIntoView:d}},Tt(Vn,nn,jo,jr,ur),{singleton:!0});function th(e){return e?e==="smooth"?"smooth":"auto":!1}const pS=(e,t)=>typeof e=="function"?th(e(t)):t&&th(e),mS=it(([{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 m=ee(!1),g=Ze();let y=null;function x(k){ze(i,{align:"end",behavior:k,index:"LAST"})}ut(X($t(X(Ae(t),Nr(1)),l),Ue(Ae(m),s,a,f),pe(([[k,S],E,j,_,P])=>{let D=S&&_,z="auto";return D&&(z=pS(E,j||P),D=D&&!!z),{followOutputBehavior:z,shouldFollow:D,totalCount:k}}),je(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:S})=>{y&&(y(),y=null),Ot(n)?requestAnimationFrame(()=>{Ot(d)("following output to ",{totalCount:S},dn.DEBUG),x(k)}):y=Pn(e,()=>{Ot(d)("following output to ",{totalCount:S},dn.DEBUG),x(k),y=null})});function w(k){const S=Pn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(Ot(d)("scrolling to bottom due to increased size",{},dn.DEBUG),x("auto"))});setTimeout(S,100)}ut(X($t(Ae(m),t,c),je(([k,,S])=>k&&S),Wn(({value:k},[,S])=>({refreshed:k===S,value:S}),{refreshed:!1,value:0}),je(({refreshed:k})=>k),Ue(m,t)),([,k])=>{Ot(a)&&w(k!==!1)}),ut(g,()=>{w(Ot(m)!==!1)}),ut($t(Ae(m),o),([k,S])=>{k&&!S.atBottom&&S.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=ee(null),T=Ze();return we(Za(X(Ae(r),pe(k=>{var S;return(S=k==null?void 0:k.length)!=null?S:0})),X(Ae(t))),T),ut(X($t(X(T,Nr(1)),l),Ue(Ae(C),a,f,h),pe(([[k,S],E,j,_,P])=>S&&j&&(E==null?void 0:E({context:P,totalCount:k,scrollingInProgress:_}))),je(k=>!!k),nr(0)),k=>{y&&(y(),y=null),Ot(n)?requestAnimationFrame(()=>{Ot(d)("scrolling into view",{}),ze(p,k)}):y=Pn(e,()=>{Ot(d)("scrolling into view",{}),ze(p,k),y=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:C}},Tt(Vn,Mo,jo,Po,fr,ur,nn,Qf,eh)),gS=it(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(we(X(a,Ue(s),je(([,l])=>l!==0),Ue(o,r,t,n,e),pe(([[,l],c,d,f,h,p=[]])=>Xf(l,c,d,f,h,p))),i),{}),Tt(Vn,Po,jr,fr),{singleton:!0}),yS=it(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return ut(X(e,Ue(r),je(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{Pn(X(n,Nr(1),je(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ze(t,o)})})}),{initialScrollTop:r}},Tt(fr,nn,jr),{singleton:!0}),nh=it(([{scrollVelocity:e}])=>{const t=ee(!1),n=Ze(),r=ee(!1);return we(X(e,Ue(r,t,n),je(([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}),Et()),t),ut(X($t(t,e,n),Ue(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Tt(Mo),{singleton:!0}),dl=it(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ze(),r=Ze(),o=Ze(),s=ee(!1),i=ee(void 0);return we(X($t(n,r),pe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),we(X(t,Ue(r),pe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Tt(nn)),xS=it(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ze(),d=ee(void 0),f=ee(null),h=ee(null);return we(a,f),we(l,h),ut(X(c,Ue(t,r,i,f,h,n)),([p,m,g,y,x,w,C])=>{const T=tS(m.sizeTree);y&&x!==null&&w!==null&&(g=x.scrollTop-w.offsetTop),g-=C,p({ranges:T,scrollTop:g})}),we(X(d,je(Xa),pe(vS)),o),we(X(s,Ue(d),je(([,p])=>p!==void 0),Et(),pe(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},Tt(Vn,nn,Po,fr,dl));function vS(e){return{align:"start",index:0,offset:e.scrollTop}}const wS=it(([{topItemsIndexes:e}])=>{const t=ee(0);return we(X(t,je(n=>n>=0),pe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Tt(jr));function rh(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const bS=rh(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),SS=it(([{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:m}])=>{const g=gn(X(l,Ue(i),Wn(([,x,w,C],[{bottom:T,items:k,offsetBottom:S,totalCount:E},j])=>{const _=T+S;let P=0;return w===E&&x.length>0&&k.length>0&&(k[0].originalIndex===0&&x[0].originalIndex===0||(P=_-C,P!==0&&(P+=j))),[P,k,E,_]},[0,[],0,0]),je(([x])=>x!==0),Ue(r,a,n,o,p,m),je(([,x,w,C,,,T])=>!T&&!C&&x!==0&&w===Ro),pe(([[x],,,,,w])=>(w("Upward scrolling compensation",{amount:x},dn.DEBUG),x))));function y(x){x>0?(ze(t,{behavior:"auto",top:-x}),ze(e,0)):(ze(e,0),ze(t,{behavior:"auto",top:-x}))}return ut(X(g,Ue(e,s)),([x,w,C])=>{C&&bS()?ze(e,w-x):y(-x)}),ut(X($t(Xt(s,!1),e,m),je(([x,w,C])=>!x&&!C&&w!==0),pe(([x,w])=>w),nr(1)),y),we(X(f,pe(x=>({top:-x}))),t),ut(X(c,Ue(h,d),pe(([x,{groupIndices:w,lastSize:C,sizeTree:T},k])=>{function S(E){return E*(C+k)}if(w.length===0)return S(x);{let E=0;const j=No(T,0);let _=0,P=0;for(;_<x;){_++,E+=j;let D=w.length===P+1?1/0:w[P+1]-w[P]-1;_+D>x&&(E-=j,D=x-_+1),_+=D,E+=S(D),P++}return E}})),x=>{ze(e,x),requestAnimationFrame(()=>{ze(t,{top:x}),requestAnimationFrame(()=>{ze(e,0),ze(m,!1)})})}),{deviation:e}},Tt(nn,Mo,jr,Vn,ur,ol)),CS=it(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),Tt(cl,gS,fr,nh,Zf,yS,fS,dl,eh,ur,Qf)),oh=it(([{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:m},g,y,x,{listState:w,topItemsIndexes:C,...T},{scrollToIndex:k},S,{topItemCount:E},{groupCounts:j},_])=>(we(T.rangeChanged,_.scrollSeekRangeChanged),we(X(_.windowViewportRect,pe(P=>P.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:j,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m,sizeRanges:a,topItemCount:E,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:w,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,..._,...g,sizes:l,...y}),Tt(Vn,Po,nn,xS,mS,jr,jo,SS,wS,Wf,CS));function kS(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 oi=typeof document<"u"?b.useLayoutEffect:b.useEffect;function sh(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=b.createContext({});function l(y,x){y.propsReady&&ze(y.propsReady,!1);for(const w of r){const C=y[t.required[w]];ze(C,x[w])}for(const w of o)if(w in x){const C=y[t.optional[w]];ze(C,x[w])}y.propsReady&&ze(y.propsReady,!0)}function c(y){return s.reduce((x,w)=>(x[w]=C=>{const T=y[t.methods[w]];ze(T,C)},x),{})}function d(y){return i.reduce((x,w)=>(x[w]=z0(y[t.events[w]]),x),{})}const f=b.forwardRef((y,x)=>{const{children:w,...C}=y,[T]=b.useState(()=>Xs(H0(e),E=>{l(E,C)})),[k]=b.useState(Nf(d,T));oi(()=>{for(const E of i)E in C&&ut(k[E],C[E]);return()=>{Object.values(k).map(Ja)}},[C,k,T]),oi(()=>{l(T,C)}),b.useImperativeHandle(x,Ef(c(T)));const S=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(S,{...kS([...r,...o,...i],C),children:w}):w})}),h=y=>{const x=b.useContext(a);return b.useCallback(w=>{ze(x[y],w)},[x,y])},p=y=>{const x=b.useContext(a)[y],w=b.useCallback(C=>ut(x,C),[x]);return b.useSyncExternalStore(w,()=>Ot(x),()=>Ot(x))},m=y=>{const x=b.useContext(a)[y],[w,C]=b.useState(Nf(Ot,x));return oi(()=>ut(x,T=>{T!==w&&C(Ef(T))}),[x,w]),w},g=b.version.startsWith("18")?p:m;return{Component:f,useEmitter:(y,x)=>{const w=b.useContext(a)[y];oi(()=>ut(w,x),[x,w])},useEmitterValue:g,usePublisher:h}}const ih=b.createContext(void 0),ah=b.createContext(void 0),lh=typeof document<"u"?b.useLayoutEffect:b.useEffect;function fl(e){return"self"in e}function TS(e){return"body"in e}function ch(e,t,n,r=no,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(h=>{let p,m,g;const y=h.target;if(TS(y)||fl(y)){const w=fl(y)?y:y.defaultView;g=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else g=s?y.scrollLeft:y.scrollTop,p=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:m})};h.suppressFlushSync?x():Ri.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===p-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.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 m=h.behavior==="smooth";let g,y,x;fl(p)?(y=Math.max(dr(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(y=p[s?"scrollWidth":"scrollHeight"],g=dr(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const w=y-g;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),Kf(g,y)||h.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),m&&t(!0);return}m?(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 hl="-webkit-sticky",uh="sticky",pl=rh(()=>{if(typeof document>"u")return uh;const e=document.createElement("div");return e.style.position=hl,e.style.position===hl?hl:uh});function ml(e){return e}const ES=it(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ml),o=ee("div"),s=ee(no),i=(a,l=null)=>Xt(X(n,pe(c=>c[a]),Et()),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")}}),IS=it(([e,t])=>({...e,...t}),Tt(oh,ES)),NS=({height:e})=>u.jsx("div",{style:{height:e}}),AS={overflowAnchor:"none",position:pl(),zIndex:1},dh={overflowAnchor:"none"},_S={...dh,display:"inline-block",height:"100%"},fh=b.memo(function({showTopList:e=!1}){const t=Me("listState"),n=Cn("sizeRanges"),r=Me("useWindowScroll"),o=Me("customScrollParent"),s=Cn("windowScrollContainerState"),i=Cn("scrollContainerState"),a=o||r?s:i,l=Me("itemContent"),c=Me("context"),d=Me("groupContent"),f=Me("trackItemSizes"),h=Me("itemSize"),p=Me("log"),m=Cn("gap"),g=Me("horizontalDirection"),{callbackRef:y}=V0(n,h,f,e?no:a,p,m,o,g,Me("skipAnimationFrameInResizeObserver")),[x,w]=b.useState(0);gl("deviation",O=>{x!==O&&w(O)});const C=Me("EmptyPlaceholder"),T=Me("ScrollSeekPlaceholder")||NS,k=Me("ListComponent"),S=Me("ItemComponent"),E=Me("GroupComponent"),j=Me("computeItemKey"),_=Me("isSeeking"),P=Me("groupIndices").length>0,D=Me("alignToBottom"),z=Me("initialItemFinalLocationReached"),B=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:x!==0?x:D?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:D?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...z?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?u.jsx(C,{...Jt(C,c)}):u.jsx(k,{...Jt(k,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:B,children:(e?t.topItems:t.items).map(O=>{const H=O.originalIndex,R=j(H+t.firstItemIndex,O.data,c);return _?b.createElement(T,{...Jt(T,c),height:O.size,index:O.index,key:R,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?b.createElement(E,{...Jt(E,c),"data-index":H,"data-item-index":O.index,"data-known-size":O.size,key:R,style:AS},d(O.index,c)):b.createElement(S,{...Jt(S,c),...OS(S,O.data),"data-index":H,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:R,style:g?_S:dh},P?l(O.index,O.groupIndex,O.data,c):l(O.index,O.data,c))})})}),jS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},PS={outline:"none",overflowX:"auto",position:"relative"},si=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),RS={position:pl(),top:0,width:"100%",zIndex:1};function Jt(e,t){if(typeof e!="string")return{context:t}}function OS(e,t){return{item:typeof e=="string"?void 0:t}}const MS=b.memo(function(){const e=Me("HeaderComponent"),t=Cn("headerHeight"),n=Me("HeaderFooterTag"),r=Ar(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,Me("skipAnimationFrameInResizeObserver")),o=Me("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),DS=b.memo(function(){const e=Me("FooterComponent"),t=Cn("footerHeight"),n=Me("HeaderFooterTag"),r=Ar(b.useMemo(()=>s=>{t(dr(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 hh({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.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:m}=ch(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?PS:jS,...o},tabIndex:0,...i,...Jt(l,s),children:r})})}function ph({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.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=b.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=ch(a,c,l,m,h);return lh(()=>{var w;return y.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{y.current=null}},[y,h]),e("windowScrollTo",x),e("scrollBy",g),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 LS=({children:e})=>{const t=b.useContext(ih),n=Cn("viewportHeight"),r=Cn("fixedItemHeight"),o=Me("alignToBottom"),s=Me("horizontalDirection"),i=b.useMemo(()=>If(n,l=>dr(l,s?"width":"height")),[n,s]),a=Ar(i,!0,Me("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:si(o),children:e})},FS=({children:e})=>{const t=b.useContext(ih),n=Cn("windowViewportRect"),r=Cn("fixedItemHeight"),o=Me("customScrollParent"),s=Pf(n,o,Me("skipAnimationFrameInResizeObserver")),i=Me("alignToBottom");return b.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:si(i),children:e})},$S=({children:e})=>{const t=Me("TopItemListComponent")||"div",n=Me("headerHeight"),r={...RS,marginTop:`${n}px`},o=Me("context");return u.jsx(t,{style:r,...Jt(t,o),children:e})},zS=b.memo(function(e){const t=Me("useWindowScroll"),n=Me("topItemsIndexes").length>0,r=Me("customScrollParent"),o=Me("context");return u.jsxs(r||t?US:HS,{...e,context:o,children:[n&&u.jsx($S,{children:u.jsx(fh,{showTopList:!0})}),u.jsxs(r||t?FS:LS,{children:[u.jsx(MS,{}),u.jsx(fh,{}),u.jsx(DS,{})]})]})}),{Component:BS,useEmitter:gl,useEmitterValue:Me,usePublisher:Cn}=sh(IS,{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"}},zS),HS=hh({useEmitter:gl,useEmitterValue:Me,usePublisher:Cn}),US=ph({useEmitter:gl,useEmitterValue:Me,usePublisher:Cn}),WS=BS;Tt(oh,it(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ml),a=ee(no),l=(c,d=null)=>Xt(X(s,pe(f=>f[c]),Et()),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")}})),pl();const mh={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},VS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:gh,floor:ii,max:Do,min:yl,round:yh}=Math;function xh(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function KS(e){return{...VS,items:e}}function ai(e,t){return e&&e.width===t.width&&e.height===t.height}function qS(e,t){return e&&e.column===t.column&&e.row===t.row}const GS=it(([{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:m,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:w,windowScrollTo:C,windowViewportRect:T},k])=>{const S=ee(0),E=ee(0),j=ee(mh),_=ee({height:0,width:0}),P=ee({height:0,width:0}),D=Ze(),z=Ze(),B=ee(0),O=ee(null),H=ee({column:0,row:0}),R=Ze(),V=Ze(),$=ee(!1),F=ee(0),ne=ee(!0),Q=ee(!1),ye=ee(!1);ut(X(m,Ue(F),je(([L,G])=>!!G)),()=>{ze(ne,!1)}),ut(X($t(m,ne,P,_,F,Q),je(([L,G,se,le,,U])=>L&&!G&&se.height!==0&&le.height!==0&&!U)),([,,,,L])=>{ze(Q,!0),al(1,()=>{ze(D,L)}),Pn(X(c),()=>{ze(t,[0,0]),ze(ne,!0)})}),we(X(V,je(L=>L!=null&&L.scrollTop>0),Un(0)),E),ut(X(m,Ue(V),je(([,L])=>L!=null)),([,L])=>{L&&(ze(_,L.viewport),ze(P,L.item),ze(H,L.gap),L.scrollTop>0&&(ze($,!0),Pn(X(c,Nr(1)),G=>{ze($,!1)}),ze(l,{top:L.scrollTop})))}),we(X(_,pe(({height:L})=>L)),f),we(X($t(Ae(_,ai),Ae(P,ai),Ae(H,(L,G)=>L&&L.column===G.column&&L.row===G.row),Ae(c)),pe(([L,G,se,le])=>({gap:se,item:G,scrollTop:le,viewport:L}))),R),we(X($t(Ae(S),r,Ae(H,qS),Ae(P,ai),Ae(_,ai),Ae(O),Ae(E),Ae($),Ae(ne),Ae(F)),je(([,,,,,,,L])=>!L),pe(([L,[G,se],le,U,We,re,xe,,Re,Fe])=>{const{column:tt,row:Se}=le,{height:Ge,width:nt}=U,{width:Qe}=We;if(xe===0&&(L===0||Qe===0))return mh;if(nt===0){const rt=ll(Fe,L),rn=rt+Math.max(xe-1,0);return KS(xh(rt,rn,re))}const Ye=vh(Qe,nt,tt);let qe,et;Re?G===0&&se===0&&xe>0?(qe=0,et=xe-1):(qe=Ye*ii((G+Se)/(Ge+Se)),et=Ye*gh((se+Se)/(Ge+Se))-1,et=yl(L-1,Do(et,Ye-1)),qe=yl(et,Do(0,qe))):(qe=0,et=-1);const Mt=xh(qe,et,re),{bottom:Ct,top:dt}=wh(We,le,U,Mt),xt=gh(L/Ye),ft=xt*Ge+(xt-1)*Se-Ct;return{bottom:Ct,itemHeight:Ge,items:Mt,itemWidth:nt,offsetBottom:ft,offsetTop:dt,top:dt}})),j),we(X(O,je(L=>L!==null),pe(L=>L.length)),S),we(X($t(_,P,j,H),je(([L,G,{items:se}])=>se.length>0&&G.height!==0&&L.height!==0),pe(([L,G,{items:se},le])=>{const{bottom:U,top:We}=wh(L,le,G,se);return[We,U]}),Et(Ao)),t);const Pe=ee(!1);we(X(c,Ue(Pe),pe(([L,G])=>G||L!==0)),Pe);const Z=gn(X($t(j,S),je(([{items:L}])=>L.length>0),Ue(Pe),je(([[L,G],se])=>{const le=L.items[L.items.length-1].index===G-1;return(se||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===G)&&le}),pe(([[,L]])=>L-1),Et())),ue=gn(X(Ae(j),je(({items:L})=>L.length>0&&L[0].index===0),Un(0),Et())),ke=gn(X(Ae(j),Ue($),je(([{items:L},G])=>L.length>0&&!G),pe(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),Et($f),nr(0)));we(ke,p.scrollSeekRangeChanged),we(X(D,Ue(_,P,S,H),pe(([L,G,se,le,U])=>{const We=Vf(L),{align:re,behavior:xe,offset:Re}=We;let Fe=We.index;Fe==="LAST"&&(Fe=le-1),Fe=Do(0,Fe,yl(le-1,Fe));let tt=xl(G,U,se,Fe);return re==="end"?tt=yh(tt-G.height+se.height):re==="center"&&(tt=yh(tt-G.height/2+se.height/2)),Re&&(tt+=Re),{behavior:xe,top:tt}})),l);const te=Xt(X(j,pe(L=>L.offsetBottom+L.bottom)),0);return we(X(T,pe(L=>({height:L.visibleHeight,width:L.visibleWidth}))),_),{customScrollParent:y,data:O,deviation:B,footerHeight:o,gap:H,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:z,scrollTo:l,scrollToIndex:D,scrollTop:c,smoothScrollTargetReached:d,totalCount:S,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:w,windowScrollTo:C,windowViewportRect:T,...p,gridState:j,horizontalDirection:ye,initialTopMostItemIndex:F,totalListHeight:te,...h,endReached:Z,propsReady:g,rangeChanged:ke,startReached:ue,stateChanged:R,stateRestoreInProgress:$,...k}},Tt(cl,nn,Mo,nh,fr,dl,ur));function vh(e,t,n){return Do(1,ii((e+n)/(ii(t)+n)))}function wh(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=xl(e,t,n,r[0].index);return{bottom:xl(e,t,n,r[r.length-1].index)+o,top:s}}function xl(e,t,n,r){const o=vh(e.width,n.width,t.column),s=ii(r/o),i=s*n.height+Do(0,s-1)*t.row;return i>0?i+t.row:i}const YS=it(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ml),i=ee("div"),a=ee(no),l=(f,h=null)=>Xt(X(t,pe(p=>p[f]),Et()),h),c=ee(!1),d=ee(!1);return we(Ae(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")}}),XS=it(([e,t])=>({...e,...t}),Tt(GS,YS)),JS=b.memo(function(){const e=Nt("gridState"),t=Nt("listClassName"),n=Nt("itemClassName"),r=Nt("itemContent"),o=Nt("computeItemKey"),s=Nt("isSeeking"),i=kn("scrollHeight"),a=Nt("ItemComponent"),l=Nt("ListComponent"),c=Nt("ScrollSeekPlaceholder"),d=Nt("context"),f=kn("itemDimensions"),h=kn("gap"),p=Nt("log"),m=Nt("stateRestoreInProgress"),g=kn("reportReadyState"),y=Ar(b.useMemo(()=>x=>{const w=x.parentElement.parentElement.scrollHeight;i(w);const C=x.firstChild;if(C){const{height:T,width:k}=C.getBoundingClientRect();f({height:T,width:k})}h({column:Sh("column-gap",getComputedStyle(x).columnGap,p),row:Sh("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return lh(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?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(x=>{const w=o(x.index,x.data,d);return s?u.jsx(c,{...Jt(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},w):b.createElement(a,{...Jt(a,d),className:n,"data-index":x.index,key:w},r(x.index,x.data,d))})})}),ZS=b.memo(function(){const e=Nt("HeaderComponent"),t=kn("headerHeight"),n=Nt("headerFooterTag"),r=Ar(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,!1),o=Nt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),QS=b.memo(function(){const e=Nt("FooterComponent"),t=kn("footerHeight"),n=Nt("headerFooterTag"),r=Ar(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,!1),o=Nt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),eC=({children:e})=>{const t=b.useContext(ah),n=kn("itemDimensions"),r=kn("viewportDimensions"),o=Ar(b.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return b.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:si(!1),children:e})},tC=({children:e})=>{const t=b.useContext(ah),n=kn("windowViewportRect"),r=kn("itemDimensions"),o=Nt("customScrollParent"),s=Pf(n,o,!1);return b.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:si(!1),children:e})},nC=b.memo(function({...e}){const t=Nt("useWindowScroll"),n=Nt("customScrollParent"),r=n||t?oC:rC,o=n||t?tC:eC,s=Nt("context");return u.jsx(r,{...e,...Jt(r,s),children:u.jsxs(o,{children:[u.jsx(ZS,{}),u.jsx(JS,{}),u.jsx(QS,{})]})})}),{useEmitter:bh,useEmitterValue:Nt,usePublisher:kn}=sh(XS,{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"}},nC),rC=hh({useEmitter:bh,useEmitterValue:Nt,usePublisher:kn}),oC=ph({useEmitter:bh,useEmitterValue:Nt,usePublisher:kn});function Sh(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,dn.WARN),t==="normal"?0:parseInt(t??"0",10)}const sC=Yo.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 Ch({className:e,variant:t,...n}){return u.jsx("div",{className:oe(sC({variant:t}),e),...n})}const Lo=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}));Lo.displayName="Card";const Fo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));Fo.displayName="CardHeader";const $o=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));$o.displayName="CardTitle";const kh=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));kh.displayName="CardDescription";const zo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));zo.displayName="CardContent";const Th=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));Th.displayName="CardFooter";const iC=1,aC=1e6;let vl=0;function lC(){return vl=(vl+1)%Number.MAX_SAFE_INTEGER,vl.toString()}const wl=new Map,Eh=e=>{if(wl.has(e))return;const t=setTimeout(()=>{wl.delete(e),Bo({type:"REMOVE_TOAST",toastId:e})},aC);wl.set(e,t)},cC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,iC)};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?Eh(n):e.toasts.forEach(r=>{Eh(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)}}},li=[];let ci={toasts:[]};function Bo(e){ci=cC(ci,e),li.forEach(t=>{t(ci)})}function uC({...e}){const t=lC(),n=o=>Bo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Bo({type:"DISMISS_TOAST",toastId:t});return Bo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function bl(){const[e,t]=v.useState(ci);return v.useEffect(()=>(li.push(t),()=>{const n=li.indexOf(t);n>-1&&li.splice(n,1)}),[e]),{...e,toast:uC,dismiss:n=>Bo({type:"DISMISS_TOAST",toastId:n})}}async function Ih(e,t){return await vn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Nh(e,t){return await(await Ih(`/files/${e}/view`,t)).text()}async function dC(e,t){const n=await Ih(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await vn(`/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 fC(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await vn("/files",{params:r})}function Sl(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 Ah(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Ho(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Ho).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(Ah(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=Ho(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 Uo(e){if(typeof e=="string")return e;if(Ah(e))return"";try{const t=Ho(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function hC(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function pC(e){const t=Uo(e);return typeof e=="string"&&hC(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function ui(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Sl(t);if(n!==null)return ui(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?ui(e.content):e}var di="Dialog",[_h,VT]=Zn(di),[mC,On]=_h(di),jh=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]=Kr({prop:r,defaultProp:o??!1,onChange:s,caller:di});return u.jsx(mC,{scope:t,triggerRef:a,contentRef:l,contentId:Qn(),titleId:Qn(),descriptionId:Qn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};jh.displayName=di;var Ph="DialogTrigger",Rh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(Ph,n),s=Je(t,o.triggerRef);return u.jsx(De.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Tl(o.open),...r,ref:s,onClick:ge(e.onClick,o.onOpenToggle)})});Rh.displayName=Ph;var Cl="DialogPortal",[gC,Oh]=_h(Cl,{forceMount:void 0}),Mh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=On(Cl,t);return u.jsx(gC,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(bn,{present:n||s.open,children:u.jsx(Rs,{asChild:!0,container:o,children:i})}))})};Mh.displayName=Cl;var fi="DialogOverlay",Dh=v.forwardRef((e,t)=>{const n=Oh(fi,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=On(fi,e.__scopeDialog);return s.modal?u.jsx(bn,{present:r||s.open,children:u.jsx(xC,{...o,ref:t})}):null});Dh.displayName=fi;var yC=wr.createSlot("DialogOverlay.RemoveScroll"),xC=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(fi,n);return u.jsx(Hs,{as:yC,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(De.div,{"data-state":Tl(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Pr="DialogContent",Lh=v.forwardRef((e,t)=>{const n=Oh(Pr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=On(Pr,e.__scopeDialog);return u.jsx(bn,{present:r||s.open,children:s.modal?u.jsx(vC,{...o,ref:t}):u.jsx(wC,{...o,ref:t})})});Lh.displayName=Pr;var vC=v.forwardRef((e,t)=>{const n=On(Pr,e.__scopeDialog),r=v.useRef(null),o=Je(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),u.jsx(Fh,{...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())})}),wC=v.forwardRef((e,t)=>{const n=On(Pr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Fh,{...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()}})}),Fh=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=On(Pr,n),l=v.useRef(null),c=Je(t,l);return ya(),u.jsxs(u.Fragment,{children:[u.jsx(bs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(ws,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Tl(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(bC,{titleId:a.titleId}),u.jsx(CC,{contentRef:l,descriptionId:a.descriptionId})]})]})}),kl="DialogTitle",$h=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(kl,n);return u.jsx(De.h2,{id:o.titleId,...r,ref:t})});$h.displayName=kl;var zh="DialogDescription",Bh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(zh,n);return u.jsx(De.p,{id:o.descriptionId,...r,ref:t})});Bh.displayName=zh;var Hh="DialogClose",Uh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(Hh,n);return u.jsx(De.button,{type:"button",...r,ref:t,onClick:ge(e.onClick,()=>o.onOpenChange(!1))})});Uh.displayName=Hh;function Tl(e){return e?"open":"closed"}var Wh="DialogTitleWarning",[KT,Vh]=Ex(Wh,{contentName:Pr,titleName:kl,docsSlug:"dialog"}),bC=({titleId:e})=>{const t=Vh(Wh),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
86
+ `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function M0(e,t=qs){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 D0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),M0(t),O0(t)}const Gs=0,cr=1,eo=2,Ef=4;function If(e){return()=>e}function L0(e){e()}function Nf(e,t){return n=>e(t(n))}function Af(e,t){return()=>e(t)}function F0(e,t){return n=>e(t,n)}function Xa(e){return e!==void 0}function $0(...e){return()=>{e.map(L0)}}function to(){}function Ys(e,t){return t(e),e}function z0(e,t){return t(e)}function Tt(...e){return e}function dt(e,t){return e(cr,t)}function ze(e,t){e(Gs,t)}function Ja(e){e(eo)}function Rt(e){return e(Ef)}function we(e,t){return dt(e,F0(t,Gs))}function Rn(e,t){const n=e(cr,r=>{n(),t(r)});return n}function _f(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function jf(e,t){return e===t}function Et(e=jf){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function _e(e){return t=>n=>{e(n)&&t(n)}}function pe(e){return t=>Nf(t,e)}function Kn(e){return t=>()=>{t(e)}}function X(e,...t){const n=B0(...t);return(r,o)=>{switch(r){case eo:Ja(e);return;case cr:return dt(e,n(o))}}}function qn(e,t){return n=>r=>{n(t=e(t,r))}}function Ir(e){return t=>n=>{e>0?e--:t(n)}}function rr(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ue(...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 B0(...e){return t=>e.reduceRight(z0,t)}function H0(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case cr:return s?n===s?void 0:(r(),n=s,t=dt(e,s),t):(r(),to);case eo:r(),n=null;return}}}function ee(e){let t=e;const n=Qe();return(r,o)=>{switch(r){case Gs:t=o;break;case cr:{o(t);break}case Ef:return t}return n(r,o)}}function en(e,t){return Ys(ee(t),n=>we(e,n))}function Qe(){const e=[];return(t,n)=>{switch(t){case Gs:e.slice().forEach(r=>{r(n)});return;case eo:e.splice(0,e.length);return;case cr:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function yn(e){return Ys(Qe(),t=>we(e,t))}function at(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:U0(),singleton:n}}const U0=()=>Symbol();function W0(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 Ft(...e){const t=Qe(),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 eo:{Ja(t);return}case cr:return r===o&&i(n),dt(t,i)}}}function Ne(e,t=jf){return X(e,Et(t))}function Za(...e){return function(t,n){switch(t){case eo:return;case cr:return $0(...e.map(r=>dt(r,n)))}}}var dn=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(dn||{});const V0={0:"debug",3:"error",1:"log",2:"warn"},K0=()=>typeof globalThis>"u"?window:globalThis,ur=at(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=K0().VIRTUOSO_LOG_LEVEL)!=null?o:Rt(e);r>=s&&console[V0[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Nr(e,t,n){return Qa(e,t,n).callbackRef}function Qa(e,t,n){const r=b.useRef(null);let o=i=>{};const s=b.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 q0(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const f=G0(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 m;p&&(m=h.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:p?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?Pf("column-gap",getComputedStyle(d).columnGap,o):Pf("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Qa(c,n,l)}function G0(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},dn.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 Pf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,dn.WARN),t==="normal"?0:parseInt(t??"0",10)}function Rf(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=c.top-p.top;h=p.height-Math.max(0,m),f=m+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}=Qa(o,!0,n),a=b.useCallback(()=>{o(i.current)},[o,i]);return b.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 on=at(()=>{const e=Qe(),t=Qe(),n=ee(0),r=Qe(),o=ee(0),s=Qe(),i=Qe(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Qe(),h=Qe(),p=ee(!1),m=ee(!1),g=ee(!1);return we(X(e,pe(({scrollTop:y})=>y)),t),we(X(e,pe(({scrollHeight:y})=>y)),i),we(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Io={lvl:0};function Of(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 vt(e){return e===Io}function No(e,t){if(!vt(e))return t===e.k?e.v:t<e.k?No(e.l,t):No(e.r,t)}function On(e,t,n="k"){if(vt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=On(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return On(e.l,t,n)}function xn(e,t,n){return vt(e)?Lf(t,n,1):t===e.k?$t(e,{k:t,v:n}):t<e.k?Ff($t(e,{l:xn(e.l,t,n)})):Ff($t(e,{r:xn(e.r,t,n)}))}function no(){return Io}function Xs(e,t,n){if(vt(e))return[];const r=On(e,t)[0];return Y0(tl(e,r,n))}function el(e,t){if(vt(e))return Io;const{k:n,l:r,r:o}=e;if(t===n){if(vt(r))return o;if(vt(o))return r;{const[s,i]=Df(r);return Js($t(e,{k:s,l:Mf(r),v:i}))}}else return t<n?Js($t(e,{l:el(r,t)})):Js($t(e,{r:el(o,t)}))}function Ar(e){return vt(e)?[]:[...Ar(e.l),{k:e.k,v:e.v},...Ar(e.r)]}function tl(e,t,n){if(vt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(tl(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(tl(s,t,n))),a}function Js(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(nl(t))return $f($t(e,{lvl:n-1}));if(!vt(t)&&!vt(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(nl(e))return rl($t(e,{lvl:n-1}));if(!vt(r)&&!vt(r.l)){const o=r.l,s=nl(o)?r.lvl-1:r.lvl;return $t(o,{l:$t(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:rl($t(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function $t(e,t){return Lf(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 Mf(e){return vt(e.r)?e.l:Js($t(e,{r:Mf(e.r)}))}function nl(e){return vt(e)||e.lvl>e.r.lvl}function Df(e){return vt(e.r)?[e.k,e.v]:Df(e.r)}function Lf(e,t,n,r=Io,o=Io){return{k:e,l:r,lvl:n,r:o,v:t}}function Ff(e){return rl($f(e))}function $f(e){const{l:t}=e;return!vt(t)&&t.lvl===e.lvl?$t(t,{r:$t(e,{l:t.r})}):e}function rl(e){const{lvl:t,r:n}=e;return!vt(n)&&!vt(n.r)&&n.lvl===t&&n.r.lvl===t?$t(n,{l:$t(e,{r:n.l}),lvl:t+1}):e}function Y0(e){return Of(e,({k:t,v:n})=>({index:t,value:n}))}function zf(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Ao(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ol=at(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Bf(e,t,n){return e[Zs(e,t,n)]}function Zs(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 X0(e,t,n,r){const o=Zs(e,t,r),s=Zs(e,n,r,o);return e.slice(o,s+1)}function dr(e,t){return Math.round(e.getBoundingClientRect()[t])}function Qs(e){return!vt(e.groupOffsetTree)}function sl({index:e},t){return t===e?0:t<e?-1:1}function J0(){return{groupIndices:[],groupOffsetTree:no(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:no()}}function Z0(e,t){let n=vt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),vt(e)){e=xn(e,0,s);continue}const a=Xs(e,i-1,o+1);if(a.some(sS(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=el(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=xn(e,o+1,h));c&&(e=xn(e,i,s))}return[e,n]}function Q0(e){return typeof e.groupIndex<"u"}function eS({offset:e},t){return t===e?0:t<e?-1:1}function _o(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Bf(t,e,sl),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Hf(e,t){if(!Qs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Uf(e,t,n){if(Q0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Hf(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function tS(e,t,n,r=0){return r>0&&(t=Math.max(t,Bf(e,r,sl).offset)),Of(X0(e,t,n,eS),oS)}function nS(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,dn.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&vt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,g)=>xn(xn(m,g,h),g+1,p),i)}else[i,a]=Z0(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=il(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>xn(h,p,_o(p,f,o)),no()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function rS(e){return Ar(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 Wf(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 il(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Zs(o,t-1,sl),a=o[l].offset;const c=On(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===On(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of Xs(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 oS(e){return{index:e.index,value:e}}function sS(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 iS={offsetHeight:"height",offsetWidth:"width"},Gn=at(([{log:e},{recalcInProgress:t}])=>{const n=Qe(),r=Qe(),o=en(r,0),s=Qe(),i=Qe(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((k,S)=>dr(k,iS[S])),h=ee(void 0),p=ee(0),m=J0(),g=en(X(n,Ue(l,e,p),qn(nS,m),Et()),m),y=en(X(l,Et(),qn((k,S)=>({current:S,prev:k.current}),{current:[],prev:[]}),pe(({prev:k})=>k)),[]);we(X(l,_e(k=>k.length>0),Ue(g,p),pe(([k,S,E])=>{const j=k.reduce((_,P,D)=>xn(_,P,_o(P,S.offsetTree,E)||D),no());return{...S,groupIndices:k,groupOffsetTree:j}})),g),we(X(r,Ue(g),_e(([k,{lastIndex:S}])=>k<S),pe(([k,{lastIndex:S,lastSize:E}])=>[{endIndex:S,size:E,startIndex:k}])),n),we(c,d);const x=en(X(c,pe(k=>k===void 0)),!0);we(X(d,_e(k=>k!==void 0&&vt(Rt(g).sizeTree)),pe(k=>[{endIndex:0,size:k,startIndex:0}])),n);const w=yn(X(n,Ue(g),qn(({sizes:k},[S,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:m}),pe(k=>k.changed)));dt(X(a,qn((k,S)=>({diff:k.prev-S,prev:S}),{diff:0,prev:0}),pe(k=>k.diff)),k=>{const{groupIndices:S}=Rt(g);if(k>0)ze(t,!0),ze(s,k+Wf(k,S));else if(k<0){const E=Rt(y);E.length>0&&(k-=Wf(-k,E)),ze(i,k)}}),dt(X(a,Ue(e)),([k,S])=>{k<0&&S("`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},dn.ERROR)});const C=yn(s);we(X(s,Ue(g),pe(([k,S])=>{const E=S.groupIndices.length>0,j=[],_=S.lastSize;if(E){const P=No(S.sizeTree,0);let D=0,z=0;for(;D<k;){const O=S.groupIndices[z],H=S.groupIndices.length===z+1?1/0:S.groupIndices[z+1]-O-1;j.push({endIndex:O,size:P,startIndex:O}),j.push({endIndex:O+1+H-1,size:_,startIndex:O+1}),z++,D+=H+1}const B=Ar(S.sizeTree);return D!==k&&B.shift(),B.reduce((O,{k:H,v:R})=>{let V=O.ranges;return O.prevSize!==0&&(V=[...O.ranges,{endIndex:H+k-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:H+k,prevSize:R,ranges:V}},{prevIndex:k,prevSize:0,ranges:j}).ranges}return Ar(S.sizeTree).reduce((P,{k:D,v:z})=>({prevIndex:D+k,prevSize:z,ranges:[...P.ranges,{endIndex:D+k-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const T=yn(X(i,Ue(g,p),pe(([k,{offsetTree:S},E])=>{const j=-k;return _o(j,S,E)})));return we(X(i,Ue(g,p),pe(([k,S,E])=>{if(S.groupIndices.length>0){if(vt(S.sizeTree))return S;let j=no();const _=Rt(y);let P=0,D=0,z=0;for(;P<-k;){z=_[D];const B=_[D+1]-z-1;D++,P+=B+1}if(j=Ar(S.sizeTree).reduce((B,{k:O,v:H})=>xn(B,Math.max(0,O+k),H),j),P!==-k){const B=No(S.sizeTree,z);j=xn(j,0,B);const O=On(S.sizeTree,-k+1)[1];j=xn(j,1,O)}return{...S,sizeTree:j,...il(S.offsetTree,0,j,E)}}else{const j=Ar(S.sizeTree).reduce((_,{k:P,v:D})=>xn(_,Math.max(0,P+k),D),no());return{...S,sizeTree:j,...il(S.offsetTree,0,j,E)}}})),g),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Tt(ur,ol),{singleton:!0});function aS(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Vf=at(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Qe(),i=Qe(),a=yn(X(s,pe(aS)));return we(X(a,pe(l=>l.totalCount)),n),we(X(a,pe(l=>l.groupIndices)),e),we(X(Ft(o,t,r),_e(([l,c])=>Qs(c)),pe(([l,c,d])=>On(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),Et(),pe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},Tt(Gn,on)),fr=at(([{log:e}])=>{const t=ee(!1),n=yn(X(t,_e(r=>r),Et()));return dt(t,r=>{r&&Rt(e)("props updated",{},dn.DEBUG)}),{didMount:n,propsReady:t}},Tt(ur),{singleton:!0}),lS=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Kf(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!lS)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const jo=at(([{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=Qe(),m=Qe(),g=ee(0);let y=null,x=null,w=null;function C(){y&&(y(),y=null),w&&(w(),w=null),x&&(clearTimeout(x),x=null),ze(l,!1)}return we(X(p,Ue(n,f,r,g,a,i,h),Ue(e,s,o),pe(([[T,k,S,E,j,_,P,D],z,B,O])=>{const H=Kf(T),{align:R,behavior:V,offset:$}=H,F=E-1,ne=Uf(H,k,F);let Q=_o(ne,k.offsetTree,z)+_;R==="end"?(Q+=B+On(k.sizeTree,ne)[1]-S+O,ne===F&&(Q+=P)):R==="center"?Q+=(B+On(k.sizeTree,ne)[1]-S+O)/2:Q-=j,$&&(Q+=$);const ye=je=>{C(),je?(D("retrying to scroll to",{location:T},dn.DEBUG),ze(p,T)):(ze(m,!0),D("list did not change, scroll successful",{},dn.DEBUG))};if(C(),V==="smooth"){let je=!1;w=dt(t,J=>{je=je||J}),y=Rn(d,()=>{ye(je)})}else y=Rn(X(t,cS(150)),ye);return x=setTimeout(()=>{C()},1200),ze(l,!0),D("scrolling from index to",{behavior:V,index:ne,top:Q},dn.DEBUG),{behavior:V,top:Q}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:g}},Tt(Gn,on,ur),{singleton:!0});function cS(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function al(e,t){e==0?t():requestAnimationFrame(()=>{al(e-1,t)})}function ll(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Po=at(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return we(X(i,Ue(l),_e(([d,f])=>!!f),Kn(!1)),a),we(X(i,Ue(l),_e(([d,f])=>!!f),Kn(!1)),c),dt(X(Ft(t,i),Ue(a,n,e,c),_e(([[,d],f,{sizeTree:h},p,m])=>d&&(!vt(h)||Xa(p))&&!f&&!m),Ue(l)),([,d])=>{Rn(o,()=>{ze(c,!0)}),al(4,()=>{Rn(r,()=>{ze(a,!0)}),ze(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},Tt(Gn,on,jo,fr),{singleton:!0});function qf(e,t){return Math.abs(e-t)<1.01}const Ro="up",Oo="down",uS="none",dS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},fS=0,Mo=at(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Qe(),c=Qe(),d=ee(4),f=ee(fS),h=en(X(Za(X(Ne(o),Ir(1),Kn(!0)),X(Ne(o),Ir(1),Kn(!1),_f(100))),Et()),!1),p=en(X(Za(X(n,Kn(!0)),X(n,Kn(!1),_f(200))),Et()),!1);we(X(Ft(Ne(o),Ne(f)),pe(([w,C])=>w<=C),Et()),a),we(X(a,rr(50)),c);const m=yn(X(Ft(r,Ne(s),Ne(t),Ne(e),Ne(d)),qn((w,[{scrollHeight:C,scrollTop:T},k,S,E,j])=>{const _=T+k-C>-j,P={scrollHeight:C,scrollTop:T,viewportHeight:k};if(_){let z,B;return T>w.state.scrollTop?(z="SCROLLED_DOWN",B=w.state.scrollTop-T):(z="SIZE_DECREASED",B=w.state.scrollTop-T||w.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:B,state:P}}let D;return P.scrollHeight>w.state.scrollHeight?D="SIZE_INCREASED":k<w.state.viewportHeight?D="VIEWPORT_HEIGHT_DECREASING":T<w.state.scrollTop?D="SCROLLING_UPWARDS":D="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:D,state:P}},dS),Et((w,C)=>w&&w.atBottom===C.atBottom))),g=en(X(r,qn((w,{scrollHeight:C,scrollTop:T,viewportHeight:k})=>{if(qf(w.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:T};{const S=C-(T+k)<1;return w.scrollTop!==T&&S?{changed:!0,jump:w.scrollTop-T,scrollHeight:C,scrollTop:T}:{changed:!0,jump:0,scrollHeight:C,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),_e(w=>w.changed),pe(w=>w.jump)),0);we(X(m,pe(w=>w.atBottom)),i),we(X(i,rr(50)),l);const y=ee(Oo);we(X(r,pe(({scrollTop:w})=>w),Et(),qn((w,C)=>Rt(p)?{direction:w.direction,prevScrollTop:C}:{direction:C<w.prevScrollTop?Ro:Oo,prevScrollTop:C},{direction:Oo,prevScrollTop:0}),pe(w=>w.direction)),y),we(X(r,rr(50),Kn(uS)),y);const x=ee(0);return we(X(h,_e(w=>!w),Kn(0)),x),we(X(o,rr(100),Ue(h),_e(([w,C])=>!!C),qn(([w,C],[T])=>[C,T],[0,0]),pe(([w,C])=>C-w)),x),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},Tt(on)),ei="top",ti="bottom",Gf="none";function Yf(e,t,n){return typeof e=="number"?n===Ro&&t===ei||n===Oo&&t===ti?e:0:n===Ro?t===ei?e.main:e.reverse:t===ti?e.main:e.reverse}function Xf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const cl=at(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Qe(),i=ee(0),a=ee(0),l=ee(0),c=en(X(Ft(Ne(r),Ne(o),Ne(n),Ne(s,Ao),Ne(l),Ne(i),Ne(t),Ne(e),Ne(a)),pe(([d,f,h,[p,m],g,y,x,w,C])=>{const T=d-w,k=y+x,S=Math.max(h-T,0);let E=Gf;const j=Xf(C,ei),_=Xf(C,ti);return p-=w,p+=h+x,m+=h+x,m-=w,p>d+k-j&&(E=Ro),m<d-S+f+_&&(E=Oo),E!==Gf?[Math.max(T-h-Yf(g,ei,E)-j,0),T-S-x+f+Yf(g,ti,E)+_]:null}),_e(d=>d!=null),Et(Ao)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},Tt(on),{singleton:!0});function hS(e,t,n){if(Qs(t)){const r=Hf(e,t);return[{index:On(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const ul={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ni(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 g=e[e.length-1];d=g.offset+g.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,m=h-d;return{bottom:d,firstItemIndex:s,items:Zf(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:Zf(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function Jf(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=ll(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ni(c,[],a,o,n,r)}function Zf(e,t,n){if(e.length===0)return[];if(!Qs(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=Xs(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 _r=at(([{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:m}])=>{const g=ee([]),y=ee(0),x=Qe();we(s.topItemsIndexes,g);const w=en(X(Ft(p,m,Ne(l,Ao),Ne(o),Ne(r),Ne(c),d,Ne(g),Ne(t),Ne(n),e),_e(([S,E,,j,,,,,,,_])=>{const P=_&&_.length!==j;return S&&!E&&!P}),pe(([,,[S,E],j,_,P,D,z,B,O,H])=>{const R=_,{offsetTree:V,sizeTree:$}=R,F=Rt(y);if(j===0)return{...ul,totalCount:j};if(S===0&&E===0)return F===0?{...ul,totalCount:j}:Jf(F,P,_,B,O,H||[]);if(vt($))return F>0?null:ni(hS(ll(P,j),R,H),[],j,O,R,B);const ne=[];if(z.length>0){const ue=z[0],ke=z[z.length-1];let te=0;for(const L of Xs($,ue,ke)){const q=L.value,ie=Math.max(L.start,ue),ce=Math.min(L.end,ke);for(let U=ie;U<=ce;U++)ne.push({data:H==null?void 0:H[U],index:U,offset:te,size:q}),te+=q}}if(!D)return ni([],ne,j,O,R,B);const Q=z.length>0?z[z.length-1]+1:0,ye=tS(V,S,E,Q);if(ye.length===0)return null;const je=j-1,J=Ys([],ue=>{for(const ke of ye){const te=ke.value;let L=te.offset,q=ke.start;const ie=te.size;if(te.offset<S){q+=Math.floor((S-te.offset+O)/(ie+O));const U=q-ke.start;L+=U*ie+U*O}q<Q&&(L+=(Q-q)*ie,q=Q);const ce=Math.min(ke.end,je);for(let U=q;U<=ce&&!(L>=E);U++)ue.push({data:H==null?void 0:H[U],index:U,offset:L,size:ie}),L+=ie+O}});return ni(J,ne,j,O,R,B)}),_e(S=>S!==null),Et()),ul);we(X(e,_e(Xa),pe(S=>S==null?void 0:S.length)),o),we(X(w,pe(S=>S.topListHeight)),f),we(f,a),we(X(w,pe(S=>[S.top,S.bottom])),i),we(X(w,pe(S=>S.items)),x);const C=yn(X(w,_e(({items:S})=>S.length>0),Ue(o,e),_e(([{items:S},E])=>S[S.length-1].originalIndex===E-1),pe(([,S,E])=>[S-1,E]),Et(Ao),pe(([S])=>S))),T=yn(X(w,rr(200),_e(({items:S,topItems:E})=>S.length>0&&S[0].originalIndex===E.length),pe(({items:S})=>S[0].index),Et())),k=yn(X(w,_e(({items:S})=>S.length>0),pe(({items:S})=>{let E=0,j=S.length-1;for(;S[E].type==="group"&&E<j;)E++;for(;S[j].type==="group"&&j>E;)j--;return{endIndex:S[j].index,startIndex:S[E].index}}),Et(zf)));return{endReached:C,initialItemCount:y,itemsRendered:x,listState:w,rangeChanged:k,startReached:T,topItemsIndexes:g,...h}},Tt(Gn,Vf,cl,Po,jo,Mo,fr,ol),{singleton:!0}),Qf=at(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Qe(),i=en(X(Ft(n,e,r,t,o),pe(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return we(Ne(i),s),{totalListHeight:i,totalListHeightChanged:s}},Tt(on,_r),{singleton:!0}),pS=at(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=en(X(Ft(n,e,t),_e(([o])=>o),pe(([,o,s])=>Math.max(0,o-s)),rr(0),Et()),0);return{alignToBottom:n,paddingTopAddition:r}},Tt(on,Qf),{singleton:!0}),eh=at(()=>({context:ee(null)})),mS=({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,th=at(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Qe();return we(X(d,Ue(t,l,n,s,o,r,a),Ue(e),pe(([[f,h,p,m,g,y,x,w],C])=>{const{align:T,behavior:k,calculateViewLocation:S=mS,done:E,...j}=f,_=Uf(f,h,m-1),P=_o(_,h.offsetTree,C)+g+y,D=P+On(h.sizeTree,_)[1],z=w+y,B=w+p-x,O=S({itemBottom:D,itemTop:P,locationParams:{align:T,behavior:k,...j},viewportBottom:B,viewportTop:z});return O?E&&Rn(X(i,_e(H=>!H),Ir(Rt(i)?1:2)),E):E&&E(),O}),_e(f=>f!==null)),c),{scrollIntoView:d}},Tt(Gn,on,jo,_r,ur),{singleton:!0});function nh(e){return e?e==="smooth"?"smooth":"auto":!1}const gS=(e,t)=>typeof e=="function"?nh(e(t)):t&&nh(e),yS=at(([{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 m=ee(!1),g=Qe();let y=null;function x(k){ze(i,{align:"end",behavior:k,index:"LAST"})}dt(X(Ft(X(Ne(t),Ir(1)),l),Ue(Ne(m),s,a,f),pe(([[k,S],E,j,_,P])=>{let D=S&&_,z="auto";return D&&(z=gS(E,j||P),D=D&&!!z),{followOutputBehavior:z,shouldFollow:D,totalCount:k}}),_e(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:S})=>{y&&(y(),y=null),Rt(n)?requestAnimationFrame(()=>{Rt(d)("following output to ",{totalCount:S},dn.DEBUG),x(k)}):y=Rn(e,()=>{Rt(d)("following output to ",{totalCount:S},dn.DEBUG),x(k),y=null})});function w(k){const S=Rn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(Rt(d)("scrolling to bottom due to increased size",{},dn.DEBUG),x("auto"))});setTimeout(S,100)}dt(X(Ft(Ne(m),t,c),_e(([k,,S])=>k&&S),qn(({value:k},[,S])=>({refreshed:k===S,value:S}),{refreshed:!1,value:0}),_e(({refreshed:k})=>k),Ue(m,t)),([,k])=>{Rt(a)&&w(k!==!1)}),dt(g,()=>{w(Rt(m)!==!1)}),dt(Ft(Ne(m),o),([k,S])=>{k&&!S.atBottom&&S.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=ee(null),T=Qe();return we(Za(X(Ne(r),pe(k=>{var S;return(S=k==null?void 0:k.length)!=null?S:0})),X(Ne(t))),T),dt(X(Ft(X(T,Ir(1)),l),Ue(Ne(C),a,f,h),pe(([[k,S],E,j,_,P])=>S&&j&&(E==null?void 0:E({context:P,totalCount:k,scrollingInProgress:_}))),_e(k=>!!k),rr(0)),k=>{y&&(y(),y=null),Rt(n)?requestAnimationFrame(()=>{Rt(d)("scrolling into view",{}),ze(p,k)}):y=Rn(e,()=>{Rt(d)("scrolling into view",{}),ze(p,k),y=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:C}},Tt(Gn,Mo,jo,Po,fr,ur,on,eh,th)),xS=at(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(we(X(a,Ue(s),_e(([,l])=>l!==0),Ue(o,r,t,n,e),pe(([[,l],c,d,f,h,p=[]])=>Jf(l,c,d,f,h,p))),i),{}),Tt(Gn,Po,_r,fr),{singleton:!0}),vS=at(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return dt(X(e,Ue(r),_e(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{Rn(X(n,Ir(1),_e(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ze(t,o)})})}),{initialScrollTop:r}},Tt(fr,on,_r),{singleton:!0}),rh=at(([{scrollVelocity:e}])=>{const t=ee(!1),n=Qe(),r=ee(!1);return we(X(e,Ue(r,t,n),_e(([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}),Et()),t),dt(X(Ft(t,e,n),Ue(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Tt(Mo),{singleton:!0}),dl=at(([{scrollContainerState:e,scrollTo:t}])=>{const n=Qe(),r=Qe(),o=Qe(),s=ee(!1),i=ee(void 0);return we(X(Ft(n,r),pe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),we(X(t,Ue(r),pe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Tt(on)),wS=at(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Qe(),d=ee(void 0),f=ee(null),h=ee(null);return we(a,f),we(l,h),dt(X(c,Ue(t,r,i,f,h,n)),([p,m,g,y,x,w,C])=>{const T=rS(m.sizeTree);y&&x!==null&&w!==null&&(g=x.scrollTop-w.offsetTop),g-=C,p({ranges:T,scrollTop:g})}),we(X(d,_e(Xa),pe(bS)),o),we(X(s,Ue(d),_e(([,p])=>p!==void 0),Et(),pe(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},Tt(Gn,on,Po,fr,dl));function bS(e){return{align:"start",index:0,offset:e.scrollTop}}const SS=at(([{topItemsIndexes:e}])=>{const t=ee(0);return we(X(t,_e(n=>n>=0),pe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Tt(_r));function oh(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const CS=oh(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),kS=at(([{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:m}])=>{const g=yn(X(l,Ue(i),qn(([,x,w,C],[{bottom:T,items:k,offsetBottom:S,totalCount:E},j])=>{const _=T+S;let P=0;return w===E&&x.length>0&&k.length>0&&(k[0].originalIndex===0&&x[0].originalIndex===0||(P=_-C,P!==0&&(P+=j))),[P,k,E,_]},[0,[],0,0]),_e(([x])=>x!==0),Ue(r,a,n,o,p,m),_e(([,x,w,C,,,T])=>!T&&!C&&x!==0&&w===Ro),pe(([[x],,,,,w])=>(w("Upward scrolling compensation",{amount:x},dn.DEBUG),x))));function y(x){x>0?(ze(t,{behavior:"auto",top:-x}),ze(e,0)):(ze(e,0),ze(t,{behavior:"auto",top:-x}))}return dt(X(g,Ue(e,s)),([x,w,C])=>{C&&CS()?ze(e,w-x):y(-x)}),dt(X(Ft(en(s,!1),e,m),_e(([x,w,C])=>!x&&!C&&w!==0),pe(([x,w])=>w),rr(1)),y),we(X(f,pe(x=>({top:-x}))),t),dt(X(c,Ue(h,d),pe(([x,{groupIndices:w,lastSize:C,sizeTree:T},k])=>{function S(E){return E*(C+k)}if(w.length===0)return S(x);{let E=0;const j=No(T,0);let _=0,P=0;for(;_<x;){_++,E+=j;let D=w.length===P+1?1/0:w[P+1]-w[P]-1;_+D>x&&(E-=j,D=x-_+1),_+=D,E+=S(D),P++}return E}})),x=>{ze(e,x),requestAnimationFrame(()=>{ze(t,{top:x}),requestAnimationFrame(()=>{ze(e,0),ze(m,!1)})})}),{deviation:e}},Tt(on,Mo,_r,Gn,ur,ol)),TS=at(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),Tt(cl,xS,fr,rh,Qf,vS,pS,dl,th,ur,eh)),sh=at(([{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:m},g,y,x,{listState:w,topItemsIndexes:C,...T},{scrollToIndex:k},S,{topItemCount:E},{groupCounts:j},_])=>(we(T.rangeChanged,_.scrollSeekRangeChanged),we(X(_.windowViewportRect,pe(P=>P.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:j,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m,sizeRanges:a,topItemCount:E,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:w,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,..._,...g,sizes:l,...y}),Tt(Gn,Po,on,wS,yS,_r,jo,kS,SS,Vf,TS));function ES(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 ri=typeof document<"u"?b.useLayoutEffect:b.useEffect;function ih(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=b.createContext({});function l(y,x){y.propsReady&&ze(y.propsReady,!1);for(const w of r){const C=y[t.required[w]];ze(C,x[w])}for(const w of o)if(w in x){const C=y[t.optional[w]];ze(C,x[w])}y.propsReady&&ze(y.propsReady,!0)}function c(y){return s.reduce((x,w)=>(x[w]=C=>{const T=y[t.methods[w]];ze(T,C)},x),{})}function d(y){return i.reduce((x,w)=>(x[w]=H0(y[t.events[w]]),x),{})}const f=b.forwardRef((y,x)=>{const{children:w,...C}=y,[T]=b.useState(()=>Ys(W0(e),E=>{l(E,C)})),[k]=b.useState(Af(d,T));ri(()=>{for(const E of i)E in C&&dt(k[E],C[E]);return()=>{Object.values(k).map(Ja)}},[C,k,T]),ri(()=>{l(T,C)}),b.useImperativeHandle(x,If(c(T)));const S=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(S,{...ES([...r,...o,...i],C),children:w}):w})}),h=y=>{const x=b.useContext(a);return b.useCallback(w=>{ze(x[y],w)},[x,y])},p=y=>{const x=b.useContext(a)[y],w=b.useCallback(C=>dt(x,C),[x]);return b.useSyncExternalStore(w,()=>Rt(x),()=>Rt(x))},m=y=>{const x=b.useContext(a)[y],[w,C]=b.useState(Af(Rt,x));return ri(()=>dt(x,T=>{T!==w&&C(If(T))}),[x,w]),w},g=b.version.startsWith("18")?p:m;return{Component:f,useEmitter:(y,x)=>{const w=b.useContext(a)[y];ri(()=>dt(w,x),[x,w])},useEmitterValue:g,usePublisher:h}}const ah=b.createContext(void 0),lh=b.createContext(void 0),ch=typeof document<"u"?b.useLayoutEffect:b.useEffect;function fl(e){return"self"in e}function IS(e){return"body"in e}function uh(e,t,n,r=to,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(h=>{let p,m,g;const y=h.target;if(IS(y)||fl(y)){const w=fl(y)?y:y.defaultView;g=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else g=s?y.scrollLeft:y.scrollTop,p=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:m})};h.suppressFlushSync?x():Ri.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===p-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.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 m=h.behavior==="smooth";let g,y,x;fl(p)?(y=Math.max(dr(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(y=p[s?"scrollWidth":"scrollHeight"],g=dr(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const w=y-g;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),qf(g,y)||h.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),m&&t(!0);return}m?(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 hl="-webkit-sticky",dh="sticky",pl=oh(()=>{if(typeof document>"u")return dh;const e=document.createElement("div");return e.style.position=hl,e.style.position===hl?hl:dh});function ml(e){return e}const NS=at(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ml),o=ee("div"),s=ee(to),i=(a,l=null)=>en(X(n,pe(c=>c[a]),Et()),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")}}),AS=at(([e,t])=>({...e,...t}),Tt(sh,NS)),_S=({height:e})=>u.jsx("div",{style:{height:e}}),jS={overflowAnchor:"none",position:pl(),zIndex:1},fh={overflowAnchor:"none"},PS={...fh,display:"inline-block",height:"100%"},hh=b.memo(function({showTopList:e=!1}){const t=Oe("listState"),n=kn("sizeRanges"),r=Oe("useWindowScroll"),o=Oe("customScrollParent"),s=kn("windowScrollContainerState"),i=kn("scrollContainerState"),a=o||r?s:i,l=Oe("itemContent"),c=Oe("context"),d=Oe("groupContent"),f=Oe("trackItemSizes"),h=Oe("itemSize"),p=Oe("log"),m=kn("gap"),g=Oe("horizontalDirection"),{callbackRef:y}=q0(n,h,f,e?to:a,p,m,o,g,Oe("skipAnimationFrameInResizeObserver")),[x,w]=b.useState(0);gl("deviation",O=>{x!==O&&w(O)});const C=Oe("EmptyPlaceholder"),T=Oe("ScrollSeekPlaceholder")||_S,k=Oe("ListComponent"),S=Oe("ItemComponent"),E=Oe("GroupComponent"),j=Oe("computeItemKey"),_=Oe("isSeeking"),P=Oe("groupIndices").length>0,D=Oe("alignToBottom"),z=Oe("initialItemFinalLocationReached"),B=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:x!==0?x:D?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:D?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...z?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?u.jsx(C,{...tn(C,c)}):u.jsx(k,{...tn(k,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:B,children:(e?t.topItems:t.items).map(O=>{const H=O.originalIndex,R=j(H+t.firstItemIndex,O.data,c);return _?b.createElement(T,{...tn(T,c),height:O.size,index:O.index,key:R,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?b.createElement(E,{...tn(E,c),"data-index":H,"data-item-index":O.index,"data-known-size":O.size,key:R,style:jS},d(O.index,c)):b.createElement(S,{...tn(S,c),...DS(S,O.data),"data-index":H,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:R,style:g?PS:fh},P?l(O.index,O.groupIndex,O.data,c):l(O.index,O.data,c))})})}),RS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},OS={outline:"none",overflowX:"auto",position:"relative"},oi=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),MS={position:pl(),top:0,width:"100%",zIndex:1};function tn(e,t){if(typeof e!="string")return{context:t}}function DS(e,t){return{item:typeof e=="string"?void 0:t}}const LS=b.memo(function(){const e=Oe("HeaderComponent"),t=kn("headerHeight"),n=Oe("HeaderFooterTag"),r=Nr(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,Oe("skipAnimationFrameInResizeObserver")),o=Oe("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...tn(e,o)})}):null}),FS=b.memo(function(){const e=Oe("FooterComponent"),t=kn("footerHeight"),n=Oe("HeaderFooterTag"),r=Nr(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,Oe("skipAnimationFrameInResizeObserver")),o=Oe("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...tn(e,o)})}):null});function ph({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.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:m}=uh(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?OS:RS,...o},tabIndex:0,...i,...tn(l,s),children:r})})}function mh({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.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=b.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=uh(a,c,l,m,h);return ch(()=>{var w;return y.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{y.current=null}},[y,h]),e("windowScrollTo",x),e("scrollBy",g),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...tn(l,s),children:r})})}const $S=({children:e})=>{const t=b.useContext(ah),n=kn("viewportHeight"),r=kn("fixedItemHeight"),o=Oe("alignToBottom"),s=Oe("horizontalDirection"),i=b.useMemo(()=>Nf(n,l=>dr(l,s?"width":"height")),[n,s]),a=Nr(i,!0,Oe("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:oi(o),children:e})},zS=({children:e})=>{const t=b.useContext(ah),n=kn("windowViewportRect"),r=kn("fixedItemHeight"),o=Oe("customScrollParent"),s=Rf(n,o,Oe("skipAnimationFrameInResizeObserver")),i=Oe("alignToBottom");return b.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:oi(i),children:e})},BS=({children:e})=>{const t=Oe("TopItemListComponent")||"div",n=Oe("headerHeight"),r={...MS,marginTop:`${n}px`},o=Oe("context");return u.jsx(t,{style:r,...tn(t,o),children:e})},HS=b.memo(function(e){const t=Oe("useWindowScroll"),n=Oe("topItemsIndexes").length>0,r=Oe("customScrollParent"),o=Oe("context");return u.jsxs(r||t?VS:WS,{...e,context:o,children:[n&&u.jsx(BS,{children:u.jsx(hh,{showTopList:!0})}),u.jsxs(r||t?zS:$S,{children:[u.jsx(LS,{}),u.jsx(hh,{}),u.jsx(FS,{})]})]})}),{Component:US,useEmitter:gl,useEmitterValue:Oe,usePublisher:kn}=ih(AS,{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"}},HS),WS=ph({useEmitter:gl,useEmitterValue:Oe,usePublisher:kn}),VS=mh({useEmitter:gl,useEmitterValue:Oe,usePublisher:kn}),KS=US;Tt(sh,at(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ml),a=ee(to),l=(c,d=null)=>en(X(s,pe(f=>f[c]),Et()),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")}})),pl();const gh={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},qS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:yh,floor:si,max:Do,min:yl,round:xh}=Math;function vh(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function GS(e){return{...qS,items:e}}function ii(e,t){return e&&e.width===t.width&&e.height===t.height}function YS(e,t){return e&&e.column===t.column&&e.row===t.row}const XS=at(([{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:m,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:w,windowScrollTo:C,windowViewportRect:T},k])=>{const S=ee(0),E=ee(0),j=ee(gh),_=ee({height:0,width:0}),P=ee({height:0,width:0}),D=Qe(),z=Qe(),B=ee(0),O=ee(null),H=ee({column:0,row:0}),R=Qe(),V=Qe(),$=ee(!1),F=ee(0),ne=ee(!0),Q=ee(!1),ye=ee(!1);dt(X(m,Ue(F),_e(([L,q])=>!!q)),()=>{ze(ne,!1)}),dt(X(Ft(m,ne,P,_,F,Q),_e(([L,q,ie,ce,,U])=>L&&!q&&ie.height!==0&&ce.height!==0&&!U)),([,,,,L])=>{ze(Q,!0),al(1,()=>{ze(D,L)}),Rn(X(c),()=>{ze(t,[0,0]),ze(ne,!0)})}),we(X(V,_e(L=>L!=null&&L.scrollTop>0),Kn(0)),E),dt(X(m,Ue(V),_e(([,L])=>L!=null)),([,L])=>{L&&(ze(_,L.viewport),ze(P,L.item),ze(H,L.gap),L.scrollTop>0&&(ze($,!0),Rn(X(c,Ir(1)),q=>{ze($,!1)}),ze(l,{top:L.scrollTop})))}),we(X(_,pe(({height:L})=>L)),f),we(X(Ft(Ne(_,ii),Ne(P,ii),Ne(H,(L,q)=>L&&L.column===q.column&&L.row===q.row),Ne(c)),pe(([L,q,ie,ce])=>({gap:ie,item:q,scrollTop:ce,viewport:L}))),R),we(X(Ft(Ne(S),r,Ne(H,YS),Ne(P,ii),Ne(_,ii),Ne(O),Ne(E),Ne($),Ne(ne),Ne(F)),_e(([,,,,,,,L])=>!L),pe(([L,[q,ie],ce,U,We,re,xe,,Pe,$e])=>{const{column:rt,row:Se}=ce,{height:Ye,width:ot}=U,{width:et}=We;if(xe===0&&(L===0||et===0))return gh;if(ot===0){const st=ll($e,L),Gt=st+Math.max(xe-1,0);return GS(vh(st,Gt,re))}const Xe=wh(et,ot,rt);let Ke,tt;Pe?q===0&&ie===0&&xe>0?(Ke=0,tt=xe-1):(Ke=Xe*si((q+Se)/(Ye+Se)),tt=Xe*yh((ie+Se)/(Ye+Se))-1,tt=yl(L-1,Do(tt,Xe-1)),Ke=yl(tt,Do(0,Ke))):(Ke=0,tt=-1);const Ot=vh(Ke,tt,re),{bottom:St,top:nt}=bh(We,ce,U,Ot),yt=yh(L/Xe),Nt=yt*Ye+(yt-1)*Se-St;return{bottom:St,itemHeight:Ye,items:Ot,itemWidth:ot,offsetBottom:Nt,offsetTop:nt,top:nt}})),j),we(X(O,_e(L=>L!==null),pe(L=>L.length)),S),we(X(Ft(_,P,j,H),_e(([L,q,{items:ie}])=>ie.length>0&&q.height!==0&&L.height!==0),pe(([L,q,{items:ie},ce])=>{const{bottom:U,top:We}=bh(L,ce,q,ie);return[We,U]}),Et(Ao)),t);const je=ee(!1);we(X(c,Ue(je),pe(([L,q])=>q||L!==0)),je);const J=yn(X(Ft(j,S),_e(([{items:L}])=>L.length>0),Ue(je),_e(([[L,q],ie])=>{const ce=L.items[L.items.length-1].index===q-1;return(ie||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===q)&&ce}),pe(([[,L]])=>L-1),Et())),ue=yn(X(Ne(j),_e(({items:L})=>L.length>0&&L[0].index===0),Kn(0),Et())),ke=yn(X(Ne(j),Ue($),_e(([{items:L},q])=>L.length>0&&!q),pe(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),Et(zf),rr(0)));we(ke,p.scrollSeekRangeChanged),we(X(D,Ue(_,P,S,H),pe(([L,q,ie,ce,U])=>{const We=Kf(L),{align:re,behavior:xe,offset:Pe}=We;let $e=We.index;$e==="LAST"&&($e=ce-1),$e=Do(0,$e,yl(ce-1,$e));let rt=xl(q,U,ie,$e);return re==="end"?rt=xh(rt-q.height+ie.height):re==="center"&&(rt=xh(rt-q.height/2+ie.height/2)),Pe&&(rt+=Pe),{behavior:xe,top:rt}})),l);const te=en(X(j,pe(L=>L.offsetBottom+L.bottom)),0);return we(X(T,pe(L=>({height:L.visibleHeight,width:L.visibleWidth}))),_),{customScrollParent:y,data:O,deviation:B,footerHeight:o,gap:H,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:z,scrollTo:l,scrollToIndex:D,scrollTop:c,smoothScrollTargetReached:d,totalCount:S,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:w,windowScrollTo:C,windowViewportRect:T,...p,gridState:j,horizontalDirection:ye,initialTopMostItemIndex:F,totalListHeight:te,...h,endReached:J,propsReady:g,rangeChanged:ke,startReached:ue,stateChanged:R,stateRestoreInProgress:$,...k}},Tt(cl,on,Mo,rh,fr,dl,ur));function wh(e,t,n){return Do(1,si((e+n)/(si(t)+n)))}function bh(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=xl(e,t,n,r[0].index);return{bottom:xl(e,t,n,r[r.length-1].index)+o,top:s}}function xl(e,t,n,r){const o=wh(e.width,n.width,t.column),s=si(r/o),i=s*n.height+Do(0,s-1)*t.row;return i>0?i+t.row:i}const JS=at(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ml),i=ee("div"),a=ee(to),l=(f,h=null)=>en(X(t,pe(p=>p[f]),Et()),h),c=ee(!1),d=ee(!1);return we(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")}}),ZS=at(([e,t])=>({...e,...t}),Tt(XS,JS)),QS=b.memo(function(){const e=It("gridState"),t=It("listClassName"),n=It("itemClassName"),r=It("itemContent"),o=It("computeItemKey"),s=It("isSeeking"),i=Tn("scrollHeight"),a=It("ItemComponent"),l=It("ListComponent"),c=It("ScrollSeekPlaceholder"),d=It("context"),f=Tn("itemDimensions"),h=Tn("gap"),p=It("log"),m=It("stateRestoreInProgress"),g=Tn("reportReadyState"),y=Nr(b.useMemo(()=>x=>{const w=x.parentElement.parentElement.scrollHeight;i(w);const C=x.firstChild;if(C){const{height:T,width:k}=C.getBoundingClientRect();f({height:T,width:k})}h({column:Ch("column-gap",getComputedStyle(x).columnGap,p),row:Ch("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return ch(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?null:u.jsx(l,{className:t,ref:y,...tn(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const w=o(x.index,x.data,d);return s?u.jsx(c,{...tn(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},w):b.createElement(a,{...tn(a,d),className:n,"data-index":x.index,key:w},r(x.index,x.data,d))})})}),eC=b.memo(function(){const e=It("HeaderComponent"),t=Tn("headerHeight"),n=It("headerFooterTag"),r=Nr(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,!1),o=It("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...tn(e,o)})}):null}),tC=b.memo(function(){const e=It("FooterComponent"),t=Tn("footerHeight"),n=It("headerFooterTag"),r=Nr(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,!1),o=It("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...tn(e,o)})}):null}),nC=({children:e})=>{const t=b.useContext(lh),n=Tn("itemDimensions"),r=Tn("viewportDimensions"),o=Nr(b.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return b.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:oi(!1),children:e})},rC=({children:e})=>{const t=b.useContext(lh),n=Tn("windowViewportRect"),r=Tn("itemDimensions"),o=It("customScrollParent"),s=Rf(n,o,!1);return b.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:oi(!1),children:e})},oC=b.memo(function({...e}){const t=It("useWindowScroll"),n=It("customScrollParent"),r=n||t?iC:sC,o=n||t?rC:nC,s=It("context");return u.jsx(r,{...e,...tn(r,s),children:u.jsxs(o,{children:[u.jsx(eC,{}),u.jsx(QS,{}),u.jsx(tC,{})]})})}),{useEmitter:Sh,useEmitterValue:It,usePublisher:Tn}=ih(ZS,{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"}},oC),sC=ph({useEmitter:Sh,useEmitterValue:It,usePublisher:Tn}),iC=mh({useEmitter:Sh,useEmitterValue:It,usePublisher:Tn});function Ch(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,dn.WARN),t==="normal"?0:parseInt(t??"0",10)}const aC=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 kh({className:e,variant:t,...n}){return u.jsx("div",{className:oe(aC({variant:t}),e),...n})}const Lo=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}));Lo.displayName="Card";const Fo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));Fo.displayName="CardHeader";const $o=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));$o.displayName="CardTitle";const Th=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Th.displayName="CardDescription";const zo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));zo.displayName="CardContent";const Eh=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));Eh.displayName="CardFooter";const lC=1,cC=1e6;let vl=0;function uC(){return vl=(vl+1)%Number.MAX_SAFE_INTEGER,vl.toString()}const wl=new Map,Ih=e=>{if(wl.has(e))return;const t=setTimeout(()=>{wl.delete(e),Bo({type:"REMOVE_TOAST",toastId:e})},cC);wl.set(e,t)},dC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,lC)};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?Ih(n):e.toasts.forEach(r=>{Ih(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)}}},ai=[];let li={toasts:[]};function Bo(e){li=dC(li,e),ai.forEach(t=>{t(li)})}function fC({...e}){const t=uC(),n=o=>Bo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Bo({type:"DISMISS_TOAST",toastId:t});return Bo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function bl(){const[e,t]=v.useState(li);return v.useEffect(()=>(ai.push(t),()=>{const n=ai.indexOf(t);n>-1&&ai.splice(n,1)}),[e]),{...e,toast:fC,dismiss:n=>Bo({type:"DISMISS_TOAST",toastId:n})}}async function Nh(e,t){return await wn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Ah(e,t){return await(await Nh(`/files/${e}/view`,t)).text()}async function hC(e,t){const n=await Nh(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await wn(`/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 pC(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await wn("/files",{params:r})}function Sl(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 _h(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Ho(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Ho).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(_h(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=Ho(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 Uo(e){if(typeof e=="string")return e;if(_h(e))return"";try{const t=Ho(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function mC(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function gC(e){const t=Uo(e);return typeof e=="string"&&mC(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function ci(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Sl(t);if(n!==null)return ci(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?ci(e.content):e}var ui="Dialog",[jh,qT]=Qn(ui),[yC,Mn]=jh(ui),Ph=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]=Vr({prop:r,defaultProp:o??!1,onChange:s,caller:ui});return u.jsx(yC,{scope:t,triggerRef:a,contentRef:l,contentId:er(),titleId:er(),descriptionId:er(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Ph.displayName=ui;var Rh="DialogTrigger",Oh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Mn(Rh,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":Tl(o.open),...r,ref:s,onClick:ge(e.onClick,o.onOpenToggle)})});Oh.displayName=Rh;var Cl="DialogPortal",[xC,Mh]=jh(Cl,{forceMount:void 0}),Dh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Mn(Cl,t);return u.jsx(xC,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Sn,{present:n||s.open,children:u.jsx(Ps,{asChild:!0,container:o,children:i})}))})};Dh.displayName=Cl;var di="DialogOverlay",Lh=v.forwardRef((e,t)=>{const n=Mh(di,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Mn(di,e.__scopeDialog);return s.modal?u.jsx(Sn,{present:r||s.open,children:u.jsx(wC,{...o,ref:t})}):null});Lh.displayName=di;var vC=vr.createSlot("DialogOverlay.RemoveScroll"),wC=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Mn(di,n);return u.jsx(Bs,{as:vC,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(De.div,{"data-state":Tl(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),jr="DialogContent",Fh=v.forwardRef((e,t)=>{const n=Mh(jr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Mn(jr,e.__scopeDialog);return u.jsx(Sn,{present:r||s.open,children:s.modal?u.jsx(bC,{...o,ref:t}):u.jsx(SC,{...o,ref:t})})});Fh.displayName=jr;var bC=v.forwardRef((e,t)=>{const n=Mn(jr,e.__scopeDialog),r=v.useRef(null),o=Ze(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),u.jsx($h,{...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())})}),SC=v.forwardRef((e,t)=>{const n=Mn(jr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx($h,{...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()}})}),$h=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Mn(jr,n),l=v.useRef(null),c=Ze(t,l);return ya(),u.jsxs(u.Fragment,{children:[u.jsx(ws,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(vs,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Tl(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(CC,{titleId:a.titleId}),u.jsx(TC,{contentRef:l,descriptionId:a.descriptionId})]})]})}),kl="DialogTitle",zh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Mn(kl,n);return u.jsx(De.h2,{id:o.titleId,...r,ref:t})});zh.displayName=kl;var Bh="DialogDescription",Hh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Mn(Bh,n);return u.jsx(De.p,{id:o.descriptionId,...r,ref:t})});Hh.displayName=Bh;var Uh="DialogClose",Wh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Mn(Uh,n);return u.jsx(De.button,{type:"button",...r,ref:t,onClick:ge(e.onClick,()=>o.onOpenChange(!1))})});Wh.displayName=Uh;function Tl(e){return e?"open":"closed"}var Vh="DialogTitleWarning",[GT,Kh]=Nx(Vh,{contentName:jr,titleName:kl,docsSlug:"dialog"}),CC=({titleId:e})=>{const t=Kh(Vh),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
87
87
 
88
88
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
89
89
 
90
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},SC="DialogDescriptionWarning",CC=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Vh(SC).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},Kh=jh,kC=Rh,qh=Mh,hi=Dh,pi=Lh,Rr=$h,mi=Bh,Gh=Uh;const TC=Kh,EC=qh,Yh=v.forwardRef(({className:e,...t},n)=>u.jsx(hi,{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}));Yh.displayName=hi.displayName;const Xh=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===Rr||(c==null?void 0:c.displayName)===Rr.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(EC,{children:[u.jsx(Yh,{}),u.jsxs(pi,{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(Rr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Gh,{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"})]})]})]})});Xh.displayName=pi.displayName;const Jh=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Jh.displayName="DialogHeader";const Zh=v.forwardRef(({className:e,...t},n)=>u.jsx(Rr,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",e),...t}));Zh.displayName=Rr.displayName;const IC=v.forwardRef(({className:e,...t},n)=>u.jsx(mi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));IC.displayName=mi.displayName;function NC({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=b.useState(!1),[a,l]=b.useState(null),[c,d]=b.useState(null),{toast:f}=bl(),h=b.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Nh(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);b.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await dC(n),f({title:"Download started",description:`Downloading ${r}`})}catch(x){console.error("Failed to download file:",x),f({title:"Download failed",description:String(x),variant:"destructive"})}},m=async()=>{if(n)try{const x=await Nh(n),w=new Blob([x],{type:o}),C=URL.createObjectURL(w);window.open(C,"_blank"),URL.revokeObjectURL(C)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?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(ct,{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(TC,{open:e,onOpenChange:t,children:u.jsxs(Xh,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Jh,{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(Zh,{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(ct,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(he.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(ct,{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:g()})]})})}function Qh(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Or=Qh();function AC(e){Or=e}const ep=/[&<>"']/,_C=new RegExp(ep.source,"g"),tp=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,jC=new RegExp(tp.source,"g"),PC={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},np=e=>PC[e];function Zt(e,t){if(t){if(ep.test(e))return e.replace(_C,np)}else if(tp.test(e))return e.replace(jC,np);return e}const RC=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function rp(e){return e.replace(RC,(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 OC=/(^|[^\[])\^/g;function bt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(OC,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const MC=/[^\w:]/g,DC=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function op(e,t,n){if(e){let r;try{r=decodeURIComponent(rp(n)).replace(MC,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!DC.test(n)&&(n=zC(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const gi={},LC=/^[^:]+:\/*[^/]*$/,FC=/^([^:]+:)[\s\S]*$/,$C=/^([^:]+:\/*[^/]*)[\s\S]*$/;function zC(e,t){gi[" "+e]||(LC.test(e)?gi[" "+e]=e+"/":gi[" "+e]=xi(e,"/",!0)),e=gi[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(FC,"$1")+t:t.charAt(0)==="/"?n?t:e.replace($C,"$1")+t:e+t}const yi={exec:function(){}};function sp(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 xi(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function BC(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function HC(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 ip(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function ap(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 UC(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
90
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},kC="DialogDescriptionWarning",TC=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Kh(kC).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},qh=Ph,EC=Oh,Gh=Dh,fi=Lh,hi=Fh,Pr=zh,pi=Hh,Yh=Wh;const IC=qh,NC=Gh,Xh=v.forwardRef(({className:e,...t},n)=>u.jsx(fi,{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}));Xh.displayName=fi.displayName;const Jh=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===Pr||(c==null?void 0:c.displayName)===Pr.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(NC,{children:[u.jsx(Xh,{}),u.jsxs(hi,{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(Pr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Yh,{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"})]})]})]})});Jh.displayName=hi.displayName;const Zh=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Zh.displayName="DialogHeader";const Qh=v.forwardRef(({className:e,...t},n)=>u.jsx(Pr,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",e),...t}));Qh.displayName=Pr.displayName;const AC=v.forwardRef(({className:e,...t},n)=>u.jsx(pi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));AC.displayName=pi.displayName;function _C({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=b.useState(!1),[a,l]=b.useState(null),[c,d]=b.useState(null),{toast:f}=bl(),h=b.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Ah(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);b.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await hC(n),f({title:"Download started",description:`Downloading ${r}`})}catch(x){console.error("Failed to download file:",x),f({title:"Download failed",description:String(x),variant:"destructive"})}},m=async()=>{if(n)try{const x=await Ah(n),w=new Blob([x],{type:o}),C=URL.createObjectURL(w);window.open(C,"_blank"),URL.revokeObjectURL(C)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?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(IC,{open:e,onOpenChange:t,children:u.jsxs(Jh,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Zh,{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(Qh,{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:m,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:g()})]})})}function ep(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Rr=ep();function jC(e){Rr=e}const tp=/[&<>"']/,PC=new RegExp(tp.source,"g"),np=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,RC=new RegExp(np.source,"g"),OC={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},rp=e=>OC[e];function nn(e,t){if(t){if(tp.test(e))return e.replace(PC,rp)}else if(np.test(e))return e.replace(RC,rp);return e}const MC=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function op(e){return e.replace(MC,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const DC=/(^|[^\[])\^/g;function wt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(DC,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const LC=/[^\w:]/g,FC=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function sp(e,t,n){if(e){let r;try{r=decodeURIComponent(op(n)).replace(LC,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!FC.test(n)&&(n=HC(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const mi={},$C=/^[^:]+:\/*[^/]*$/,zC=/^([^:]+:)[\s\S]*$/,BC=/^([^:]+:\/*[^/]*)[\s\S]*$/;function HC(e,t){mi[" "+e]||($C.test(e)?mi[" "+e]=e+"/":mi[" "+e]=yi(e,"/",!0)),e=mi[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(zC,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(BC,"$1")+t:e+t}const gi={exec:function(){}};function ip(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 yi(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 UC(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 WC(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 ap(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function lp(e,t,n,r){const o=t.href,s=t.title?nn(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:nn(i)}}function VC(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
91
91
  `).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
92
- `)}class El{constructor(t){this.options=t||Or}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:xi(r,`
93
- `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=UC(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:o}}}heading(t){const n=this.rules.block.heading.exec(t);if(n){let r=n[2].trim();if(/#$/.test(r)){const o=xi(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,m,g=n[1].trim();const y=g.length>1,x={type:"list",raw:"",ordered:y,start:y?+g.slice(0,-1):"",loose:!1,items:[]};g=y?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=y?g:"[*+-]");const w=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(m=!1,!(!(n=w.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
92
+ `)}class El{constructor(t){this.options=t||Rr}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:yi(r,`
93
+ `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=VC(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=yi(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,m,g=n[1].trim();const y=g.length>1,x={type:"list",raw:"",ordered:y,start:y?+g.slice(0,-1):"",loose:!1,items:[]};g=y?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=y?g:"[*+-]");const w=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(m=!1,!(!(n=w.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
94
94
  `,1)[0].replace(/^\t+/,T=>" ".repeat(3*T.length)),f=t.split(`
95
95
  `,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+`
96
96
  `,t=t.substring(f.length+1),m=!0),!m){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+|$)`),S=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),E=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
97
97
  `,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(S.test(f)||E.test(f)||T.test(f)||k.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
98
98
  `+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||S.test(d)||E.test(d)||k.test(d))break;p+=`
99
99
  `+f}!l&&!f.trim()&&(l=!0),r+=h+`
100
- `,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const C=x.items.length;for(a=0;a<C;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const T=x.items[a].tokens.filter(S=>S.type==="space"),k=T.length>0&&T.some(S=>/\n.*\n/.test(S.raw));x.loose=k}if(x.loose)for(a=0;a<C;a++)x.items[a].loose=!0;return x}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):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:sp(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
101
- `):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=sp(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
102
- `?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text: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=xi(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=BC(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),ap(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 ap(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 m=h.slice(1,-1);return{type:"em",raw:h,text:m,tokens:this.lexer.inlineTokens(m)}}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:yi,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=bt(Ee.def).replace("label",Ee._label).replace("title",Ee._title).getRegex(),Ee.bullet=/(?:[*+-]|\d{1,9}[.)])/,Ee.listItemStart=bt(/^( *)(bull) */).replace("bull",Ee.bullet).getRegex(),Ee.list=bt(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=bt(Ee.html,"i").replace("comment",Ee._comment).replace("tag",Ee._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ee.paragraph=bt(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=bt(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=bt(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=bt(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:bt(`^ *(?: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:yi,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:bt(Ee.normal._paragraph).replace("hr",Ee.hr).replace("heading",` *#{1,6} *[^
103
- ]`).replace("lheading",Ee.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const me={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:yi,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:yi,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};me._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",me.punctuation=bt(me.punctuation).replace(/punctuation/g,me._punctuation).getRegex(),me.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,me.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,me._comment=bt(Ee._comment).replace("(?:-->|$)","-->").getRegex(),me.emStrong.lDelim=bt(me.emStrong.lDelim).replace(/punct/g,me._punctuation).getRegex(),me.emStrong.rDelimAst=bt(me.emStrong.rDelimAst,"g").replace(/punct/g,me._punctuation).getRegex(),me.emStrong.rDelimUnd=bt(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=bt(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=bt(me.tag).replace("comment",me._comment).replace("attribute",me._attribute).getRegex(),me._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,me._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,me._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,me.link=bt(me.link).replace("label",me._label).replace("href",me._href).replace("title",me._title).getRegex(),me.reflink=bt(me.reflink).replace("label",me._label).replace("ref",Ee._label).getRegex(),me.nolink=bt(me.nolink).replace("ref",Ee._label).getRegex(),me.reflinkSearch=bt(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:bt(/^!?\[(label)\]\((.*?)\)/).replace("label",me._label).getRegex(),reflink:bt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",me._label).getRegex()},me.gfm={...me.normal,escape:bt(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=bt(me.gfm.url,"i").replace("email",me.gfm._extended_email).getRegex(),me.breaks={...me.gfm,br:bt(me.br).replace("{2,}","*").getRegex(),text:bt(me.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function WC(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 lp(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 hr{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Or,this.options.tokenizer=this.options.tokenizer||new El,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:me.normal};this.options.pedantic?(n.block=Ee.pedantic,n.inline=me.pedantic):this.options.gfm&&(n.block=Ee.gfm,this.options.breaks?n.inline=me.breaks:n.inline=me.gfm),this.tokenizer.rules=n}static get rules(){return{block:Ee,inline:me}}static lex(t,n){return new hr(n).lex(t)}static lexInline(t,n){return new hr(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
100
+ `,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const C=x.items.length;for(a=0;a<C;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const T=x.items[a].tokens.filter(S=>S.type==="space"),k=T.length>0&&T.some(S=>/\n.*\n/.test(S.raw));x.loose=k}if(x.loose)for(a=0;a<C;a++)x.items[a].loose=!0;return x}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):nn(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:ip(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
101
+ `):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=ip(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
102
+ `?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:nn(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]):nn(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=yi(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=UC(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)),lp(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 lp(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 m=h.slice(1,-1);return{type:"em",raw:h,text:m,tokens:this.lexer.inlineTokens(m)}}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=nn(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=nn(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=nn(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=nn(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=nn(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]):nn(r[0]):r[0]:o=nn(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:gi,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=wt(Ee.def).replace("label",Ee._label).replace("title",Ee._title).getRegex(),Ee.bullet=/(?:[*+-]|\d{1,9}[.)])/,Ee.listItemStart=wt(/^( *)(bull) */).replace("bull",Ee.bullet).getRegex(),Ee.list=wt(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=wt(Ee.html,"i").replace("comment",Ee._comment).replace("tag",Ee._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ee.paragraph=wt(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=wt(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=wt(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=wt(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:wt(`^ *(?: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:gi,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:wt(Ee.normal._paragraph).replace("hr",Ee.hr).replace("heading",` *#{1,6} *[^
103
+ ]`).replace("lheading",Ee.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const me={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:gi,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:gi,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};me._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",me.punctuation=wt(me.punctuation).replace(/punctuation/g,me._punctuation).getRegex(),me.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,me.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,me._comment=wt(Ee._comment).replace("(?:-->|$)","-->").getRegex(),me.emStrong.lDelim=wt(me.emStrong.lDelim).replace(/punct/g,me._punctuation).getRegex(),me.emStrong.rDelimAst=wt(me.emStrong.rDelimAst,"g").replace(/punct/g,me._punctuation).getRegex(),me.emStrong.rDelimUnd=wt(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=wt(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=wt(me.tag).replace("comment",me._comment).replace("attribute",me._attribute).getRegex(),me._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,me._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,me._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,me.link=wt(me.link).replace("label",me._label).replace("href",me._href).replace("title",me._title).getRegex(),me.reflink=wt(me.reflink).replace("label",me._label).replace("ref",Ee._label).getRegex(),me.nolink=wt(me.nolink).replace("ref",Ee._label).getRegex(),me.reflinkSearch=wt(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:wt(/^!?\[(label)\]\((.*?)\)/).replace("label",me._label).getRegex(),reflink:wt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",me._label).getRegex()},me.gfm={...me.normal,escape:wt(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=wt(me.gfm.url,"i").replace("email",me.gfm._extended_email).getRegex(),me.breaks={...me.gfm,br:wt(me.br).replace("{2,}","*").getRegex(),text:wt(me.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function KC(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 cp(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 hr{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Rr,this.options.tokenizer=this.options.tokenizer||new El,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:me.normal};this.options.pedantic?(n.block=Ee.pedantic,n.inline=me.pedantic):this.options.gfm&&(n.block=Ee.gfm,this.options.breaks?n.inline=me.breaks:n.inline=me.gfm),this.tokenizer.rules=n}static get rules(){return{block:Ee,inline:me}}static lex(t,n){return new hr(n).lex(t)}static lexInline(t,n){return new hr(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
104
104
  `),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
105
105
  `:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
106
106
  `+r.raw,o.text+=`
@@ -110,9 +110,9 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
110
110
  `+r.raw,o.text+=`
111
111
  `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r),i=s.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&o.type==="text"?(o.raw+=`
112
112
  `+r.raw,o.text+=`
113
- `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+ip("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)+"["+ip("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,lp)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,lp))){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,WC)){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 Il{constructor(t){this.options=t||Or}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
114
- `,o?'<pre><code class="'+this.options.langPrefix+Zt(o)+'">'+(r?t:Zt(t,!0))+`</code></pre>
115
- `:"<pre><code>"+(r?t:Zt(t,!0))+`</code></pre>
113
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+ap("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)+"["+ap("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,cp)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,cp))){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,KC)){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 Il{constructor(t){this.options=t||Rr}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
114
+ `,o?'<pre><code class="'+this.options.langPrefix+nn(o)+'">'+(r?t:nn(t,!0))+`</code></pre>
115
+ `:"<pre><code>"+(r?t:nn(t,!0))+`</code></pre>
116
116
  `}blockquote(t){return`<blockquote>
117
117
  ${t}</blockquote>
118
118
  `}html(t){return t}heading(t,n,r,o){if(this.options.headerIds){const s=this.options.headerPrefix+o.slug(r);return`<h${n} id="${s}">${t}</h${n}>
@@ -130,8 +130,8 @@ ${t}</blockquote>
130
130
  `}tablerow(t){return`<tr>
131
131
  ${t}</tr>
132
132
  `}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
133
- `}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=op(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=op(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 cp{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 up{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 pr{constructor(t){this.options=t||Or,this.options.renderer=this.options.renderer||new Il,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new cp,this.slugger=new up}static parse(t,n){return new pr(n).parse(t)}static parseInline(t,n){return new pr(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,m,g,y,x,w,C,T,k,S;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]&&(S=this.options.extensions.renderers[p.type].call({parser:this},p),S!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=S||"";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,rp(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(m=p.ordered,g=p.start,y=p.loose,a=p.items.length,h="",s=0;s<a;s++)w=p.items[s],C=w.checked,T=w.task,x="",w.task&&(k=this.renderer.checkbox(C),y?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=k+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=k+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:k}):x+=k),x+=this.parse(w.tokens,y),h+=this.renderer.listitem(x,T,C);r+=this.renderer.list(h,m,g);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
134
- `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const j='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(j);return}else throw new Error(j)}}}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 vi{constructor(t){this.options=t||Or}preprocess(t){return t}postprocess(t){return t}}Xm(vi,"passThroughHooks",new Set(["preprocess","postprocess"]));function VC(e,t,n){return r=>{if(r.message+=`
135
- Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+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 dp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...be.defaults,...s};const i=VC(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(HC(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&&be.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;be.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(be.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&&be.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function be(e,t,n){return dp(hr.lex,pr.parse)(e,t,n)}be.options=be.setOptions=function(e){return be.defaults={...be.defaults,...e},AC(be.defaults),be},be.getDefaults=Qh,be.defaults=Or,be.use=function(...e){const t=be.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=be.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=be.defaults.renderer||new Il;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=be.defaults.tokenizer||new El;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=be.defaults.hooks||new vi;for(const s in n.hooks){const i=o[s];vi.passThroughHooks.has(s)?o[s]=a=>{if(be.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=be.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}}be.setOptions(r)})},be.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(be,r)),r.type){case"table":{for(const o of r.header)n=n.concat(be.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(be.walkTokens(s.tokens,t));break}case"list":{n=n.concat(be.walkTokens(r.items,t));break}default:be.defaults.extensions&&be.defaults.extensions.childTokens&&be.defaults.extensions.childTokens[r.type]?be.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(be.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(be.walkTokens(r.tokens,t)))}return n},be.parseInline=dp(hr.lexInline,pr.parseInline),be.Parser=pr,be.parser=pr.parse,be.Renderer=Il,be.TextRenderer=cp,be.Lexer=hr,be.lexer=hr.lex,be.Tokenizer=El,be.Slugger=up,be.Hooks=vi,be.parse=be,be.options,be.setOptions,be.use,be.walkTokens,be.parseInline,pr.parse,hr.lex;function Wo({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof be.parse=="function"?be.parse(i):be(i)}return typeof be.parse=="function"?be.parse(e):be(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=b.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 KC="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 qC(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function fp(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 wi(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function GC(e){const t=o=>{try{const s=Ho(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
136
- `)):r=t(e),r||""}function YC(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function hp(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 XC({className:e}){const[t,n]=b.useState(0);return b.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 Nl=b.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:m,onCancelEdit:g,onCopy:y,activeInterrupt:x,disableInterruptActions:w=!1,onInterruptActionStart:C,onInterruptActionEnd:T,checkpointCandidates:k=[],activeCheckpointId:S=null,onSelectCheckpoint:E,defaultCheckpointId:j=null,messageParentCheckpointId:_=null}){const[P,D]=b.useState(!1),[z,B]=b.useState("preview"),[O,H]=b.useState(!1),{currentThreadId:R}=gs(),{respondToInterrupt:V}=ys(),$=l==="phone"||l==="half-screen",F=t.role,ne=F==="tool",Q=b.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!Q,Pe=!(r&&F!=="user"),{uploadingFiles:Z,handleFileClick:ue,fileViewerOpen:ke,currentFileInfo:te,closeFileViewer:L}=ZC({allowFileOpen:Pe,currentThreadId:R}),G=b.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=b.useMemo(()=>Q?"":qC(t.content),[Q,t]),le=b.useMemo(()=>Q?{}:fp(t),[Q,t]),U=b.useMemo(()=>Q?[]:t.content.filter(Y=>Y.type==="image_url"),[Q,t]),We=b.useMemo(()=>Q?[]:t.content.filter(Y=>Y.type==="file"),[Q,t]),re=b.useMemo(()=>Q?[]:t.content.filter(Y=>Y.type==="interrupt"),[Q,t]),xe=(x==null?void 0:x.id)??(x==null?void 0:x.interrupt_id),Re=wi(xe),Fe=x==null?void 0:x.value,tt=b.useMemo(()=>Q?"":GC(t.content),[Q,t]),Se=b.useCallback(async()=>{const Y=ne?tt:se;async function Ie(ve){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ve);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ot=new Blob([ve],{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 Ie(Y),D(!0),setTimeout(()=>D(!1),2e3),y==null||y(Y)}catch(ve){console.error("Failed to copy:",ve)}},[ne,tt,se,y]),Ge=b.useCallback(()=>{if(!p)return;const Y=ne?tt:se,Ie="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};p(t.id,Y,Ie)},[p,t.id,ne,tt,se,t]),nt=b.useCallback(()=>{m==null||m(n)},[m,n]),Qe=b.useCallback(()=>{const Ie=oe($?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",G);switch(F){case"user":return u.jsx(he.User,{className:Ie});case"assistant":return u.jsx(he.Bot,{className:Ie});case"tool":return u.jsx(he.Wrench,{className:Ie});default:return u.jsx(he.Bot,{className:Ie})}},[$,G,F]),Ye=b.useCallback(()=>{const Y="group relative mb-4 flex w-full";switch(F){case"user":return oe(Y,"justify-end");case"assistant":case"tool":case"system":return oe(Y,"justify-start");default:return Y}},[F]),qe=b.useCallback(()=>{const Y=oe("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",$&&"px-3 py-2 text-sm");if(ye)return oe(Y,"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(Y,"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(Y,"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(Y,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return oe(Y,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return oe(Y,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[$,ye,F]);if(ye&&Q)return u.jsx("div",{className:oe(Ye(),h.container),children:u.jsxs("div",{className:oe(qe(),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",G)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(Wo,{content:Q.content,className:"text-current"})]})});const et=b.useCallback(async Y=>{if(w)return;const Ie=wi((Y==null?void 0:Y.id)??(Y==null?void 0:Y.interrupt_id));if(!Ie){console.warn("Interrupt part missing id",Y);return}try{C==null||C(),await V(Ie,!0)}catch(ve){console.error("Failed to approve interrupt:",ve)}finally{T==null||T()}},[w,T,C,V]),Mt=b.useCallback(async Y=>{if(w)return;const Ie=wi((Y==null?void 0:Y.id)??(Y==null?void 0:Y.interrupt_id));if(!Ie){console.warn("Interrupt part missing id",Y);return}try{C==null||C(),await V(Ie,!1)}catch(ve){console.error("Failed to reject interrupt:",ve)}finally{T==null||T()}},[w,T,C,V]),Ct=b.useCallback(({part:Y,i:Ie})=>{if(Y.type==="text"){const ve=Y.text??"",ot=ve.trim(),vt=Sl(ot);return vt&&F!=="tool"?u.jsx(pp,{data:vt},Ie):F==="user"&&c&&ot.length>d?u.jsx(QC,{text:ot,expanded:O,onExpandedChange:H,previewLength:d,isCompact:$},Ie):u.jsx(Wo,{content:ve,allowHtml:!1},Ie)}if(Y.type==="image_url"){const ve=Y;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ve.url,alt:ve.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Ie)}if(Y.type==="file"){const ve=Y,ot=ve.name||"file";return u.jsxs("a",{href:ve.url,onClick:vt=>ue(vt,ve,Ie),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
- dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Z[Ie]?u.jsx(he.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ot,Z[Ie]?" (processing)":""]})]},Ie)}if(Y.type==="interrupt"){const ve=Y,ot=wi((ve==null?void 0:ve.id)??(ve==null?void 0:ve.interrupt_id)),vt=!!(Re&&ot&&ot===Re),It=vt?Fe??(ve==null?void 0:ve.value):ve==null?void 0:ve.value,Ne=ot?{...ve,id:ot,interrupt_id:ot}:ve;return u.jsx(JC,{interruptPart:Ne,onApprove:et,onReject:Mt,disabled:w,isActive:vt,payload:It},Ie)}return null},[ue,Z,et,Mt,F,c,d,O,$,Re,Fe,x,w,re]),dt=b.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"})]}),[]),xt=b.useCallback(()=>{const Y=se.trim().length>0||U.length>0||We.length>0||re.length>0;if(!ne&&We.length>0&&!r)return dt();if(!ne&&!Y&&!r)return null;if(ne)return u.jsx(ek,{message:t,viewMode:z},t.id);if(!ne&&!Q){const Ie=t,ve=u.jsx("div",{className:"space-y-2",children:Ie.content.map((ot,vt)=>u.jsx(Ct,{part:ot,i:vt},vt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ve,u.jsx(XC,{className:G})]}):ve}},[se,U.length,We.length,re.length,r,ne,z,dt,G]),ft=b.useMemo(()=>Q?"Assistant":YC(t),[Q,t]),rt=b.useMemo(()=>Q?[]:Array.isArray(k)?k:[],[k,Q]),rn=b.useMemo(()=>{var Y;return rt.length?j&&rt.some(Ie=>Ie.id===j)?j:((Y=rt[0])==null?void 0:Y.id)??null:null},[j,rt]),Wt=b.useMemo(()=>!rt.length||!S?null:rt.some(Y=>Y.id===S)?S:null,[S,rt])??rn,zt=F==="user"&&rt.length>0&&typeof E=="function",ht=b.useCallback(Y=>{if(!E)return;const Ie=(Y==null?void 0:Y.id)??null,ve=(Y==null?void 0:Y.parentId)??_??null;E(Ie,ve)},[_,E]),Ve=b.useMemo(()=>Wt?rt.findIndex(Y=>Y.id===Wt):-1,[Wt,rt]),Dt=b.useMemo(()=>Ve<0?null:rt[Ve]??null,[Ve,rt]),_t=b.useCallback(Y=>{const Ie=[];if(Y.step!==null&&Ie.push(`Step ${Y.step}`),Y.source&&Ie.push(Y.source),!Y.createdAt)return Ie.length?Ie.join(" • "):Y.id.slice(0,8);let ve="";try{const ot=new Date(Y.createdAt);Number.isNaN(ot.getTime())||(ve=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(ot))}catch{ve=""}return`${ve}`},[]);return ne&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:oe(Ye(),h.container),children:u.jsxs("div",{className:oe(qe(),h.content),children:[(i||a||ne)&&u.jsxs("div",{className:oe("flex items-center justify-between mb-2 pb-2 border-b border-current/10",$&&"mb-1 pb-1",G,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Qe(),a&&ft&&u.jsx("span",{className:oe("font-medium",$?"text-xs":"text-sm"),children:ft}),ne&&u.jsxs(Ch,{variant:"outline",className:oe("text-xs flex items-center gap-1 cursor-pointer select-none",G,"border border-current/40",$&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":z==="expanded",onClick:()=>B(Y=>Y==="expanded"?"preview":"expanded"),onKeyDown:Y=>{(Y.key==="Enter"||Y.key===" ")&&(Y.preventDefault(),B(Ie=>Ie==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:le.name??"Tool Output"}),le.toolCallId&&u.jsx("span",{className:"opacity-70",children:le.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:[zt&&Dt&&Ve>=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",Ve>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ve<=0)return;const Y=rt[Ve-1];Y&&ht(Y)},"aria-label":"Previous checkpoint",disabled:Ve<=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:[Ve+1," / ",rt.length]}),u.jsx("span",{className:"text-muted-foreground",children:_t(Dt)})]}),u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ve<rt.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ve>=rt.length-1)return;const Y=rt[Ve+1];Y&&ht(Y)},"aria-label":"Next checkpoint",disabled:Ve>=rt.length-1,children:u.jsx(he.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:oe("text-xs opacity-60",G,$&&"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(ct,{variant:"ghost",size:"sm",onClick:()=>Se(),className:oe("h-6 w-6 p-0 hover:bg-foreground/10",G,$&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(he.Copy,{className:oe(P?"text-success":G,$?"h-3 w-3":"h-4 w-4")})})}),F==="user"&&p&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:Ge,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",G,$&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(he.Edit,{className:oe(G,$?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&m&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:nt,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",G,$&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(he.RotateCcw,{className:oe(G,$?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:xt()}),ne&&z==="expanded"&&(le.toolCallId||le.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",$&&"text-xs"),children:[le.name&&u.jsxs("div",{children:["Function: ",le.name]}),le.toolCallId&&u.jsxs("div",{children:["Call ID: ",le.toolCallId]})]}),!(i||a||ne)&&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(ct,{variant:"ghost",size:"sm",onClick:()=>Se(),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(P?"text-success":"text-current",$?"h-3 w-3":"h-4 w-4")})}),F==="user"&&p&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:Ge,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"&&m&&u.jsx(ct,{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.RotateCcw,{className:oe("text-current",$?"h-3 w-3":"h-4 w-4")})})]})]})}),te&&u.jsx(NC,{isOpen:ke,onClose:L,fileId:te.id,fileName:te.name,mimeType:te.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&hp(e.message)===hp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),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 pp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:KC,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:Uo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Uo(e)})}function JC({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=Uo(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(Lo,{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(Fo,{className:"pb-3",children:[u.jsx($o,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(kh,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(zo,{className:"pt-0 pb-3",children:a}),u.jsx(Th,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(ct,{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(ct,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function ZC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=bl(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(p=>{a(p),c(!0)},[]),h=b.useCallback(async(p,m,g)=>{var y,x;if(!t){p.preventDefault();return}if(o[g]){p.preventDefault();return}try{const w=String(m.url??""),C=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(C){p.preventDefault();const T=C[1],k=m.name||`file_${T}`,S=m.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:S});return}if(w.startsWith("data:")){p.preventDefault(),s(k=>({...k,[g]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await fC(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const S=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(S!=null&&S.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!S.id||!S.filename)throw new Error("Invalid file data received from server");f({id:S.id,name:m.name||S.filename||`file_${S.id}`,mimeType:m.mimeType||S.mime_type||"application/octet-stream"}),(y=T.update)==null||y.call(T,{id:T.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const S=k instanceof Error?k.message:"Unknown error occurred";(x=T.update)==null||x.call(T,{id:T.id,title:"Failed",description:S}),r({title:"Failed to fetch file",description:S,open:!0})}finally{s(k=>({...k,[g]:!1}))}}}catch(w){console.error("File click error:",w),s(C=>({...C,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function QC({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(Wo,{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(ct,{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 ek({message:e,viewMode:t}){const r=fp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Sl(c)??c:c;if(d&&typeof d=="object")return u.jsx(pp,{data:d});const f=typeof d=="string"?d:(()=>{try{return Uo(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}=pC(c);return f?u.jsx(Wo,{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=ui(d);return s(f)}const a=Ho(i),l=ui(a);return s(l)}const mp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,tk=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},Al=b.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:m=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:w,disableInterruptActions:C=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:S=!0,checkpointMetaById:E,checkpointIndexByKey:j,activeCheckpointId:_,onSelectCheckpoint:P,timelineCheckpoints:D},z)=>{const B=b.useRef(null),O=b.useRef(null),H=b.useRef(!1),[R,V]=b.useState(!0),$=b.useMemo(()=>w?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===w.id)):!1,[w,e]),F=b.useMemo(()=>{if(!w||$)return null;const re=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let xe;const Re=w.value;if(Re&&typeof Re=="object"&&!Array.isArray(Re)){const Fe=Re.title;typeof Fe=="string"&&Fe.trim()&&(xe=Fe.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Re,title:xe}]}},[w,$]),ne=b.useMemo(()=>F?[...e,F]:e,[e,F]),Q=b.useMemo(()=>S?ne:ne.filter(re=>(re==null?void 0:re.role)!=="tool"),[ne,S]),ye=b.useMemo(()=>{const re=new Set,xe=[];for(let Re=Q.length-1;Re>=0;Re--){const Fe=Q[Re];if(!Fe)continue;if("type"in Fe&&Fe.type==="default_message"){xe.push(Fe);continue}const tt=Fe,Se=tk(tt);re.has(Se)||(re.add(Se),xe.push(tt))}return xe.reverse()},[Q]),Pe=b.useCallback(re=>{V(re),y&&y(!re),x&&x(re)},[y,x]),Z=b.useMemo(()=>{if(a)return async()=>{if(!H.current){H.current=!0;try{await a()}finally{H.current=!1}}}},[a]),ue=b.useMemo(()=>!m||g?!1:R?"auto":!1,[R,m,g]),ke=b.useMemo(()=>D??[],[D]),te=_??(ke.length?ke[ke.length-1].id:null),L=ke.length>0,G=b.useMemo(()=>{if(typeof p!="string")return null;const re=p.trim();return re?{id:"default-message",role:"assistant",type:"default_message",content:re,createdAt:new Date().toISOString()}:null},[p]),se=L?u.jsxs("div",{className:"hidden w-48 flex-shrink-0 flex-col border-r border-border/40 pr-4 md:flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-5 pb-5 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative z-50",children:[u.jsx(he.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-56 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.'})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-5 top-0 bottom-0 w-px bg-border/50"}),u.jsx("div",{className:"flex flex-col gap-4",children:ke.map(re=>{const xe=te===re.id;return u.jsxs("button",{type:"button",disabled:!P,onClick:()=>P==null?void 0:P(re.id),className:`relative flex items-start gap-3 text-left text-xs transition ${xe?"text-primary":"text-muted-foreground"} ${P?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-4 w-4 items-center justify-center rounded-full border ${xe?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${xe?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:re.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[re.step!==null?`STEP ${re.step}`:"STEP —",re.next?` - ${re.next}`:""]})]})]},re.id)})})]}),P&&u.jsx("button",{type:"button",onClick:()=>P==null?void 0:P(null),className:"mt-auto rounded-md border border-border/70 px-3 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null,le=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),U=()=>G?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Nl,{message:G,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:p??"No messages yet. Start a conversation!"}),We=ye.length>0;return b.useImperativeHandle(z,()=>({scrollToLatest:()=>{var re,xe;if(B.current&&ye.length>0){const Re=ye.length-1;(xe=(re=B.current).scrollToIndex)==null||xe.call(re,{index:Re,align:"end",behavior:"auto"})}else O.current&&(O.current.scrollTop=O.current.scrollHeight)},scrollToTop:()=>{var re,xe;B.current&&ye.length>0?(xe=(re=B.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):O.current&&(O.current.scrollTop=0)}}),[ye]),u.jsxs("div",{className:le,style:h,children:[se,u.jsx("div",{className:"relative flex-1 min-h-0",children:We?u.jsx(WS,{ref:re=>{B.current=re},scrollerRef:re=>{O.current=re instanceof HTMLDivElement?re:null},data:ye,followOutput:ue,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{Z&&Z()},atBottomStateChange:Pe,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>mp(xe,re),itemContent:(re,xe)=>{var et;const Re=mp(xe,re),Fe="type"in xe&&xe.type==="default_message";let tt=[],Se=null,Ge={},nt={},Qe=null,Ye=null;if(!Fe){const Mt=xe,Ct=Mt.checkpointId??null;Ge=Mt.additionalKwargs??{},nt=Mt.responseMetadata??{};const dt=Ct&&E?E.get(Ct)??null:null;Qe=typeof Ge.step=="number"?Ge.step:typeof nt.step=="number"?nt.step:(dt==null?void 0:dt.step)??null;const xt=typeof Ge.source=="string"?Ge.source:typeof nt.source=="string"?nt.source:(dt==null?void 0:dt.source)??null;Ye=xt?String(xt):null;const ft=Qe!==null&&Ye?`${Qe}:${Ye}`:null;ft&&(j!=null&&j.has(ft))?tt=j.get(ft)??[]:Ct&&dt&&(tt=[dt]),Se=Ct??((et=tt[0])==null?void 0:et.id)??null}const qe=(()=>{if(typeof Ge.parentCheckpointId=="string")return Ge.parentCheckpointId;if(typeof nt.parentCheckpointId=="string")return nt.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":Re,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Nl,{message:xe,messageIndex:re,isStreamingMessage:t&&n===xe.id,streamingDebounceMs:r,isEditing:i===xe.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(re),onCancelEdit:d,activeInterrupt:w,disableInterruptActions:C,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:S,checkpointCandidates:tt,activeCheckpointId:_??null,onSelectCheckpoint:P,defaultCheckpointId:Se,messageParentCheckpointId:qe})})}}):U()})]})});Al.displayName="MessageList";const gp={value:""};function bi({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:m}){const{api:g}=Xi(),{currentThreadId:y}=gs(),{threadId:x,messages:w,hasMore:C,isHistoryLoading:T,isLoading:k,loadOlder:S,navigateToCheckpoint:E,returnToLatest:j,checkpoint:_,checkpoints:P,interrupt:D,metadata:z}=ys(),{isStreaming:B,error:O,connectionState:H,submit:R,stop:V}=fu(),$=x??y??null,F=(_==null?void 0:_.id)??null,ne=(_==null?void 0:_.namespace)??null,Q=(z==null?void 0:z.assemblingMessageId)??null,ye=D,[Pe,Z]=b.useState(!1);b.useEffect(()=>{ye||Z(!1)},[ye]);const ue=b.useCallback(()=>{Z(!0)},[]),ke=b.useCallback(()=>{Z(!1)},[]),te=!!ye||Pe,[L,G]=b.useState(null),[se,le]=b.useState(""),[U,We]=b.useState(null),[re,xe]=b.useState(null),[Re,Fe]=b.useState([]),[tt,Se]=b.useState(0),[Ge,nt]=b.useState(0),[Qe,Ye]=b.useState(!1),[qe,et]=b.useState(null),[Mt,Ct]=b.useState(null),[dt,xt]=b.useState(!1),[ft,rt]=b.useState(null),[rn,on]=b.useState(!1),Wt=b.useRef(!1),[zt,ht]=b.useState(()=>gp.value),Ve=b.useRef(zt),Dt=b.useRef(null),_t=b.useCallback(J=>{gp.value=J,ht(J)},[]),[Y,Ie]=b.useState(!1),ve=b.useRef(null),ot=b.useCallback(J=>{if(!Array.isArray(J))return{text:null,messageId:null};for(let ce=J.length-1;ce>=0;ce--){const ie=J[ce];if(!ie||ie.role!=="user")continue;const Te=(ie.content??[]).filter(Ke=>(Ke==null?void 0:Ke.type)==="text").map(Ke=>Ke.text).filter(Ke=>typeof Ke=="string"&&Ke.trim().length>0);return{text:Te.length?Te.join(" ").trim():null,messageId:ie.id??null}}return{text:null,messageId:null}},[]),vt=b.useCallback((J,ce)=>{if(!J||typeof J!="object")return null;const ie=J[ce];return typeof ie=="number"?ie:null},[]),It=b.useCallback((J,ce)=>{if(!J||typeof J!="object")return null;const ie=J[ce];return typeof ie=="string"&&ie.trim()?ie:null},[]),Ne=b.useMemo(()=>{const J=Te=>{if(!Array.isArray(Te)||Te.length===0)return null;const gt=Te.map(Ke=>{if(typeof Ke=="string")return Ke.trim();if(Ke&&typeof Ke=="object"&&"type"in Ke){const st=Ke;if(typeof st.type=="string")return st.type}return null}).filter(Ke=>!!(Ke&&Ke.length));return gt.length?gt.join(", "):null},ce=Array.isArray(P)?P.map(Te=>{const gt=J(Te.next);return gt?{...Te,metadata:{...Te.metadata??{},next:gt}}:Te}):[];return ce.some(Te=>vt(Te.metadata,"step")!==null)&&ce.sort((Te,gt)=>{const Ke=vt(Te.metadata,"step"),st=vt(gt.metadata,"step");if(Ke!==null||st!==null)return(st??Number.NEGATIVE_INFINITY)-(Ke??Number.NEGATIVE_INFINITY);const Ht=Date.parse(Te.createdAt??""),fn=Date.parse(gt.createdAt??"");return Number.isNaN(Ht)||Number.isNaN(fn)?0:fn-Ht}),ce},[P,vt]),{checkpointMetaById:Qt,checkpointIndexByKey:at}=b.useMemo(()=>{const J=new Map,ce=new Map;for(const ie of Ne){const Te=ie.checkpointId??null;if(!Te)continue;const gt=vt(ie.metadata,"step"),Ke=It(ie.metadata,"source"),st={id:Te,step:gt,source:Ke,createdAt:ie.createdAt??null,namespace:ie.checkpointNs??null,parentId:ie.parentId??null};if(J.set(Te,st),gt!==null&&Ke){const Ht=`${gt}:${Ke}`,fn=ce.get(Ht)??[];fn.push(st),ce.set(Ht,fn)}}for(const ie of ce.values())ie.sort((Te,gt)=>{const Ke=Te.createdAt??"";return(gt.createdAt??"").localeCompare(Ke)});return{checkpointMetaById:J,checkpointIndexByKey:ce}},[Ne,vt,It]),Xe=b.useMemo(()=>{var Ke;if(!Ne.length)return[];const J=[...Ne].reverse(),ce=(st,Ht)=>{const fn=st.checkpointId??null;if(!fn)return null;const Gn=It(st.metadata,"source");It(st.metadata,"next");const{text:qo,messageId:Pi}=ot(st.messages),ao=qo&&qo.replace(/\s+/g," ").trim()||It(st.metadata,"title")||It(st.metadata,"label")||Ht||Gn||"Checkpoint",Yn=ao.length>60?`${ao.slice(0,57)}…`:ao;return{id:fn,label:Yn,messageId:Pi??null,createdAt:st.createdAt??null,step:vt(st.metadata,"step"),source:Gn??null,next:It(st.metadata,"next")}},ie=[],Te=new Set;for(const st of J){const Ht=((Ke=It(st.metadata,"source"))==null?void 0:Ke.toLowerCase())??null;if(!(Ht==="input"||Ht==="user_input"||Ht==="user"))continue;const Gn=ce(st,"User input");Gn&&!Te.has(Gn.id)&&(ie.push(Gn),Te.add(Gn.id))}if(!ie.length)for(const st of J){const Ht=ce(st);Ht&&!Te.has(Ht.id)&&(ie.push(Ht),Te.add(Ht.id))}const gt=Ne.find(st=>{var fn;return(((fn=It(st.metadata,"source"))==null?void 0:fn.toLowerCase())??null)==="loop"});if(gt){const st=ce(gt,"Latest loop");st&&!Te.has(st.id)&&(ie.push(st),Te.add(st.id))}return ie},[Ne,ot,vt,It]),sn=b.useRef(null),qn=b.useRef(null),jt=b.useCallback(()=>{sn.current&&(sn.current.value=""),qn.current&&(qn.current.value=""),Se(J=>J+1),nt(J=>J+1)},[]),rr=b.useCallback(J=>{_t(J)},[_t]),Fr=b.useRef(!1);b.useEffect(()=>{Fr.current&&!B&&(Fe([]),jt()),Fr.current=B},[B,jt]);const[Ko,$r]=b.useState("desktop");b.useEffect(()=>{const J=()=>{const ce=window.innerWidth;$r(ce<640?"phone":ce<1024?"tablet":"desktop")};return J(),window.addEventListener("resize",J),()=>window.removeEventListener("resize",J)},[]),b.useEffect(()=>{on(!1),Wt.current=!1},[$]),b.useEffect(()=>{Ve.current=zt},[zt]),b.useEffect(()=>{if(!L){Dt.current=null;return}Dt.current===null&&(Dt.current=Ve.current),_t(se??"")},[se,L,_t]);const N=b.useCallback(async()=>{if(!(!C||T||!rn))try{await S()}catch(J){console.warn("loadOlder failed",J)}},[C,rn,T,S]);b.useEffect(()=>{(async()=>{if(!g.baseUrl){rt(null);return}try{const ie=(await g.getAgent("default")).uiDefaultMessage||"";rt(ie||null)}catch(ce){console.warn("Failed to fetch default message:",ce),rt(null)}})()},[g.baseUrl]),b.useEffect(()=>{O&&!dt&&(m==null||m(O))},[O,dt,m]);const q=J=>{if(J.length>Gs)return`Message too long (${J.length}/${Gs} characters)`;try{return O0(J),null}catch(ce){return(ce==null?void 0:ce.message)||"Invalid message"}},de=async J=>{const ce=J.trim();if(!(!ce&&Re.length===0)){if(ce){const ie=q(ce);if(ie){xe(ie);return}}try{const ie=F??void 0,Te=ne??void 0,gt=L?{edit:!0,originalMessageId:L,...U!=null&&U.checkpointId?{originalCheckpointId:U.checkpointId}:{},...U!=null&&U.checkpointNs?{originalCheckpointNs:U.checkpointNs}:{}}:void 0;await R({text:ce||"",attachments:Re,messageAdditionalKwargs:gt},{checkpointId:ie,checkpointNs:Te}),h==null||h(ce),_t(""),xe(null),Fe([]),jt(),G(null),le(""),We(null)}catch(ie){const Te=(ie==null?void 0:ie.message)||"Failed to send message";xe(Te),m==null||m(Te)}}},Ce=b.useCallback((J,ce,ie)=>{c&&(Dt.current=zt,G(J),le(ce),_t(ce),xe(null),We({checkpointId:(ie==null?void 0:ie.checkpointId)??null,checkpointNs:(ie==null?void 0:ie.checkpointNs)??null}))},[zt,c,_t]),He=b.useCallback(()=>{G(null),le(""),We(null),xe(null),_t(Dt.current??zt),Dt.current=null},[zt,_t]),lt=b.useCallback((J,ce,ie)=>{Ce(J,ce,ie)},[Ce]),Oe=b.useCallback(J=>{for(let ce=J-1;ce>=0;ce--)if(w[ce].role==="user"){const ie=w[ce].content||[],gt=ie.filter(Ke=>Ke.type==="text").map(Ke=>Ke.text).join("")||(()=>{try{return JSON.stringify(ie,null,2)}catch{return String(ie)}})();gt&&R({text:gt},{checkpointId:F??void 0,checkpointNs:ne??void 0});break}},[w,R,F,ne]),$e=J=>{const ce=Array.from(J.target.files||[]);Fe(ie=>[...ie,...ce]),J.target.value=""},At=J=>{Fe(ce=>{const ie=ce.filter((Te,gt)=>J!==gt);return ie.length===0&&jt(),ie})},pt=async J=>{const ce=(J.target.files||[])[0];if(ce){et(null),Ct(null),Ye(!0);try{await R({attachments:[ce]},{checkpointId:F??void 0,checkpointNs:ne??void 0});const ie=`Uploaded ${ce.name} - processing through chat stream`;Ct(ie)}catch(ie){const Te=ie instanceof Error?ie.message:"Failed to upload Excel file";console.error("Excel upload failed",ie),et(Te),m==null||m(Te)}finally{Ye(!1),J.target.value="",jt()}}},mt=async J=>{if(y){Ie(!0);try{if(!J){await j(),on(!1),requestAnimationFrame(()=>{var Te;(Te=ve.current)==null||Te.scrollToLatest()});return}const ce=Ne.find(Te=>Te.checkpointId===J),ie=(ce==null?void 0:ce.checkpointNs)??null;await E(J,ie),on(!0),requestAnimationFrame(()=>{var Te;(Te=ve.current)==null||Te.scrollToTop()})}finally{Ie(!1)}}},en=b.useCallback(async J=>{await mt(J)},[mt]),Dn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,In=`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||""}`,Lt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,xr=b.useCallback(J=>{if(!J)return"Latest";const ce=[];J.step!==null&&ce.push(`Step ${J.step}`),J.source&&ce.push(J.source);const ie=J.createdAt?new Date(J.createdAt):null,Te=ie&&!Number.isNaN(ie.getTime())?ie.toLocaleString():J.createdAt??J.id,gt=ce.length?` — ${ce.join(" • ")}`:"";return`${Te}${gt}`},[]);return u.jsxs("div",{className:Dn,children:[!!O&&!dt&&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(ct,{variant:"ghost",size:"sm",onClick:()=>xt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(he.X,{size:16})})]}),y&&Ne.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:J=>{const ce=J.target.value||null;mt(ce)},children:[u.jsx("option",{value:"",children:"Latest"}),Ne.map(J=>{const ce=Qt.get(J.checkpointId??"")??null;return u.jsx("option",{value:J.checkpointId??void 0,children:xr(ce)},J.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${In}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Al,{ref:ve,className:"h-full",style:{height:"100%"},messages:w,isStreaming:B,streamingAssistantId:Q,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Ko,enableMessageEditing:c,editingMessageId:L,onStartReached:()=>{rn&&N()},onScrollAway:J=>{if(!Wt.current){Wt.current=!0;return}J&&on(!0)},onEdit:lt,onRegenerate:Oe,onCancelEdit:He,emptyMessage:ft??void 0,isNavigatingCheckpoint:Y,activeInterrupt:ye,disableInterruptActions:Pe,onInterruptActionStart:ue,onInterruptActionEnd:ke,showToolMessages:d,checkpointMetaById:Qt,checkpointIndexByKey:at,activeCheckpointId:F,onSelectCheckpoint:en,timelineCheckpoints:Xe}),(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(he.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(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:Lt,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(ct,{variant:"ghost",size:"sm",onClick:He,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:sn,type:"file",multiple:!0,onChange:J=>$e(J),className:"hidden"},tt),Re.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Re.map((J,ce)=>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:J.name}),u.jsx(ct,{variant:"ghost",size:"sm",onClick:()=>At(ce),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${J.name}`,children:u.jsx(he.X,{size:12})})]},ce))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:qn,type:"file",accept:".xls,.xlsx,.xlsm",onChange:pt,className:"hidden"},Ge),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..."]}),Mt&&!Qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Mt}),qe&&!Qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:qe})]})]}),re&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:re}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(k0,{children:[u.jsx(T0,{asChild:!0,children:u.jsx(ct,{type:"button",size:"icon",variant:"outline",disabled:B||te,title:"More input actions",className:f.moreButton||"",children:u.jsx(he.Plus,{size:16})})}),u.jsxs(kf,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ya,{onClick:()=>{var J;return(J=sn.current)==null?void 0:J.click()},className:"cursor-pointer",children:[u.jsx(he.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Ya,{onClick:()=>{var J;Qe||(J=qn.current)==null||J.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(Tx,{initialValue:se,editingMessageId:L,value:zt,onValueChange:rr,placeholder:L?"Edit your message...":t,isStreaming:B,disabled:te,maxLength:Gs,onSend:de,onCancelEdit:He,onStop:V,allowEmptySend:Re.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":""} ${re?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const Si=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}));Si.displayName="Input";function _l(e,[t,n]){return Math.min(n,Math.max(t,e))}function nk(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var jl="ScrollArea",[yp,qT]=Zn(jl),[rk,Tn]=yp(jl),xp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,h]=v.useState(null),[p,m]=v.useState(null),[g,y]=v.useState(null),[x,w]=v.useState(0),[C,T]=v.useState(0),[k,S]=v.useState(!1),[E,j]=v.useState(!1),_=Je(t,D=>l(D)),P=vs(o);return u.jsx(rk,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:k,onScrollbarXEnabledChange:S,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:w,onCornerHeightChange:T,children:u.jsx(De.div,{dir:P,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});xp.displayName=jl;var vp="ScrollAreaViewport",wp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Tn(vp,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(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})})]})});wp.displayName=vp;var Kn="ScrollAreaScrollbar",Pl=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Tn(Kn,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(ok,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(sk,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(bp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Rl,{...r,ref:t}):null});Pl.displayName=Kn;var ok=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Tn(Kn,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(bn,{present:n||s,children:u.jsx(bp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),sk=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Tn(Kn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ei(()=>l("SCROLL_END"),100),[a,l]=nk("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(bn,{present:n||a!=="hidden",children:u.jsx(Rl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),bp=v.forwardRef((e,t)=>{const n=Tn(Kn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ei(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return oo(n.viewport,l),oo(n.content,l),u.jsx(bn,{present:r||s,children:u.jsx(Rl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Rl=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Tn(Kn,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=Ep(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 dk(h,i.current,a,p)}return n==="horizontal"?u.jsx(ik,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Ip(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(ak,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Ip(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}),ik=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Tn(Kn,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(Cp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ti(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),Ap(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:ki(i.paddingLeft),paddingEnd:ki(i.paddingRight)}})}})}),ak=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Tn(Kn,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(Cp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ti(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),Ap(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:ki(i.paddingTop),paddingEnd:ki(i.paddingBottom)}})}})}),[lk,Sp]=yp(Kn),Cp=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=Tn(Kn,n),[m,g]=v.useState(null),y=Je(t,_=>g(_)),x=v.useRef(null),w=v.useRef(""),C=p.viewport,T=r.content-r.viewport,k=Gt(d),S=Gt(l),E=Ei(f,10);function j(_){if(x.current){const P=_.clientX-x.current.left,D=_.clientY-x.current.top;c({x:P,y:D})}}return v.useEffect(()=>{const _=P=>{const D=P.target;(m==null?void 0:m.contains(D))&&k(P,T)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[C,m,T,k]),v.useEffect(S,[r,S]),oo(m,E),oo(p.content,E),u.jsx(lk,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Gt(s),onThumbPointerUp:Gt(i),onThumbPositionChange:S,onThumbPointerDown:Gt(a),children:u.jsx(De.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=m.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),j(_))}),onPointerMove:ge(e.onPointerMove,j),onPointerUp:ge(e.onPointerUp,_=>{const P=_.target;P.hasPointerCapture(_.pointerId)&&P.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=w.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),Ci="ScrollAreaThumb",kp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Sp(Ci,e.__scopeScrollArea);return u.jsx(bn,{present:n||o.hasThumb,children:u.jsx(ck,{ref:t,...r})})}),ck=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Tn(Ci,n),i=Sp(Ci,n),{onThumbPositionChange:a}=i,l=Je(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ei(()=>{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=fk(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:ge(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:ge(e.onPointerUp,i.onThumbPointerUp)})});kp.displayName=Ci;var Ol="ScrollAreaCorner",Tp=v.forwardRef((e,t)=>{const n=Tn(Ol,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(uk,{...e,ref:t}):null});Tp.displayName=Ol;var uk=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Tn(Ol,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return oo(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),oo(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 ki(e){return e?parseInt(e,10):0}function Ep(e,t){const n=e/t;return isNaN(n)?0:n}function Ti(e){const t=Ep(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function dk(e,t,n,r="ltr"){const o=Ti(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Np([l,c],f)(e)}function Ip(e,t,n="ltr"){const r=Ti(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=_l(e,l);return Np([0,i],[0,a])(c)}function Np(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Ap(e,t){return e>0&&e<t}var fk=(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 Ei(e,t){const n=Gt(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 oo(e,t){const n=Gt(t);qt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var _p=xp,hk=wp,pk=Tp;const jp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_p,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(hk,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Pp,{}),u.jsx(pk,{})]}));jp.displayName=_p.displayName;const Pp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pl,{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(kp,{className:"relative flex-1 rounded-full bg-border"})}));Pp.displayName=Pl.displayName;const Rp=25;function Ml({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:m}=gs(),{loadThread:g}=ys(),{createThread:y,deleteThread:x,renameThread:w}=m,[C,T]=b.useState(Array.isArray(f)?f:[]),k=b.useRef(C.length>0),S=b.useRef(null),E=b.useRef(0),[j,_]=b.useState(null),[P,D]=b.useState(""),[z,B]=b.useState(!1);b.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]),b.useEffect(()=>{if(!S.current)return;const Z=S.current.querySelector("[data-radix-scroll-area-viewport]");if(!Z)return;let ue=null,ke=null;return ue=requestAnimationFrame(()=>{ke=requestAnimationFrame(()=>{Z.scrollTop=E.current})}),()=>{ue!==null&&cancelAnimationFrame(ue),ke!==null&&cancelAnimationFrame(ke)}},[C]);const O=async Z=>{try{await g(Z),a==null||a(Z),l==null||l(Z)}catch(ue){console.error("Failed to select thread:",ue)}},H=async()=>{try{B(!0);const Z=await y();c==null||c(Z),a==null||a(Z)}catch(Z){console.error("Failed to create thread:",Z)}finally{B(!1)}},R=async(Z,ue)=>{if(ue.stopPropagation(),!!confirm("Delete this thread?")){if(S.current){const ke=S.current.querySelector("[data-radix-scroll-area-viewport]");ke&&(E.current=ke.scrollTop)}try{await x(Z),d==null||d(Z)}catch(ke){console.error("Failed to delete thread:",ke)}}},V=(Z,ue)=>{ue.stopPropagation(),_(Z.threadId),D(Z.title||`Thread ${Z.threadId.slice(0,8)}`)},$=async Z=>{if(P.trim())try{await w(Z,P.trim()),_(null),D("")}catch(ue){console.error("Failed to update title:",ue)}},F=()=>{_(null),D("")},ne=(Z,ue)=>{Z.key==="Enter"?$(ue):Z.key==="Escape"&&F()},Q=Z=>{if(!Z)return"";try{const ue=new Date(Z),te=new Date().getTime()-ue.getTime(),L=Math.floor(te/(1e3*60*60*24));return L===0?ue.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):L===1?"Yesterday":L<7?`${L} days ago`:ue.toLocaleDateString()}catch{return""}},ye=Z=>Z.title||`Thread ${Z.threadId.slice(0,8)}`,Pe=Z=>{const ue=ye(Z);return ue.length<=Rp?ue:`${ue.slice(0,Rp)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(ct,{onClick:H,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(jp,{ref:S,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…"})]}):C.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"})]}):C.slice().sort((Z,ue)=>new Date(ue.updatedAt||ue.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:j===Z.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ue=>ue.stopPropagation(),children:[u.jsx(Si,{value:P,onChange:ue=>D(ue.target.value),onKeyDown:ue=>ne(ue,Z.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(ct,{variant:"ghost",size:"sm",onClick:()=>$(Z.threadId),className:"h-6 w-6 p-0",children:u.jsx(he.Check,{size:12})}),u.jsx(ct,{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:Pe(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:Q(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&&j!==Z.threadId&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:ue=>V(Z,ue),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(he.Edit3,{size:12})}),n&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:ue=>R(Z.threadId,ue),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 so(e){if(!(typeof globalThis>"u"))return globalThis[e]}function mk(e){if(typeof e!="string")return;const t=e.trim();if(t)return Jn(t)}function Op(){const e=[so("__API_BASE_URL__"),so("__CHAT_API_BASE_URL__"),so("__CHAT_API_URL__")];for(const t of e){const n=mk(t);if(n)return n}}function Mp(){const e=[so("__API_AUTH_TOKEN__"),so("__CHAT_API_KEY__"),so("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Dp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Jn(t);return Jn()}function Lp(){const e={},t=Op(),n=Mp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Fp(){const e=Lp(),t=sr.getAuthToken(),n=Op();return{apiBaseUrl:Dp(e.baseUrl,sr.baseUrl,n),apiKey:t||e.apiKey||Mp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const $p="chat-settings";function gk(){try{const e=localStorage.getItem($p);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function yk(e){try{const t={...e,apiBaseUrl:Jn(e.apiBaseUrl)};localStorage.setItem($p,JSON.stringify(t)),t.apiKey&&sr.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function xk(){const e=Fp(),t=gk(),n=sr.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Dp(sr.baseUrl,r,e.apiBaseUrl)}}function vk(e){sr.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),yk(e)}var wk="Label",zp=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())}}));zp.displayName=wk;var Bp=zp;const bk=Yo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),En=v.forwardRef(({className:e,...t},n)=>u.jsx(Bp,{ref:n,className:oe(bk(),e),...t}));En.displayName=Bp.displayName;function Hp(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 Ii="Switch",[Sk,GT]=Zn(Ii),[Ck,kk]=Sk(Ii),Up=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),m=Je(t,C=>p(C)),g=v.useRef(!1),y=h?d||!!h.closest("form"):!0,[x,w]=Kr({prop:o,defaultProp:s??!1,onChange:c,caller:Ii});return u.jsxs(Ck,{scope:n,checked:x,disabled:a,children:[u.jsx(De.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":qp(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ge(e.onClick,C=>{w(T=>!T),y&&(g.current=C.isPropagationStopped(),g.current||C.stopPropagation())})}),y&&u.jsx(Kp,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Up.displayName=Ii;var Wp="SwitchThumb",Vp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=kk(Wp,n);return u.jsx(De.span,{"data-state":qp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Vp.displayName=Wp;var Tk="SwitchBubbleInput",Kp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Je(i,s),l=Hp(n),c=Xu(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 m=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(m)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Kp.displayName=Tk;function qp(e){return e?"checked":"unchecked"}var Gp=Up,Ek=Vp;const mr=v.forwardRef(({className:e,...t},n)=>u.jsx(Gp,{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(Ek,{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")})}));mr.displayName=Gp.displayName;var Yp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),Ik="VisuallyHidden",Nk=v.forwardRef((e,t)=>u.jsx(De.span,{...e,ref:t,style:{...Yp,...e.style}}));Nk.displayName=Ik;var Ak=[" ","Enter","ArrowUp","ArrowDown"],_k=[" ","Enter"],Mr="Select",[Ni,Ai,jk]=pa(Mr),[io,YT]=Zn(Mr,[jk,Ps]),_i=Ps(),[Pk,gr]=io(Mr),[Rk,Ok]=io(Mr),Xp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:h,required:p,form:m}=e,g=_i(t),[y,x]=v.useState(null),[w,C]=v.useState(null),[T,k]=v.useState(!1),S=vs(c),[E,j]=Kr({prop:r,defaultProp:o??!1,onChange:s,caller:Mr}),[_,P]=Kr({prop:i,defaultProp:a,onChange:l,caller:Mr}),D=v.useRef(null),z=y?m||!!y.closest("form"):!0,[B,O]=v.useState(new Set),H=Array.from(B).map(R=>R.props.value).join(";");return u.jsx(id,{...g,children:u.jsxs(Pk,{required:p,scope:t,trigger:y,onTriggerChange:x,valueNode:w,onValueNodeChange:C,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:Qn(),value:_,onValueChange:P,open:E,onOpenChange:j,dir:S,triggerPointerDownPosRef:D,disabled:h,children:[u.jsx(Ni.Provider,{scope:t,children:u.jsx(Rk,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(R=>{O(V=>new Set(V).add(R))},[]),onNativeOptionRemove:v.useCallback(R=>{O(V=>{const $=new Set(V);return $.delete(R),$})},[]),children:n})}),z?u.jsxs(wm,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:R=>P(R.target.value),disabled:h,form:m,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(B)]},H):null]})})};Xp.displayName=Mr;var Jp="SelectTrigger",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=_i(n),i=gr(Jp,n),a=i.disabled||r,l=Je(t,i.onTriggerChange),c=Ai(n),d=v.useRef("touch"),[f,h,p]=Sm(g=>{const y=c().filter(C=>!C.disabled),x=y.find(C=>C.value===i.value),w=Cm(y,g,x);w!==void 0&&i.onValueChange(w.value)}),m=g=>{a||(i.onOpenChange(!0),p()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ad,{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":bm(i.value)?"":void 0,...o,ref:l,onClick:ge(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&m(g)}),onPointerDown:ge(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(m(g),g.preventDefault())}),onKeyDown:ge(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&h(g.key),!(y&&g.key===" ")&&Ak.includes(g.key)&&(m(),g.preventDefault())})})})});Zp.displayName=Jp;var Qp="SelectValue",em=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=gr(Qp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Je(t,l.onValueNodeChange);return qt(()=>{c(d)},[c,d]),u.jsx(De.span,{...a,ref:f,style:{pointerEvents:"none"},children:bm(l.value)?u.jsx(u.Fragment,{children:i}):s})});em.displayName=Qp;var Mk="SelectIcon",tm=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(De.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});tm.displayName=Mk;var Dk="SelectPortal",nm=e=>u.jsx(Rs,{asChild:!0,...e});nm.displayName=Dk;var Dr="SelectContent",rm=v.forwardRef((e,t)=>{const n=gr(Dr,e.__scopeSelect),[r,o]=v.useState();if(qt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Xo.createPortal(u.jsx(om,{scope:e.__scopeSelect,children:u.jsx(Ni.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(sm,{...e,ref:t})});rm.displayName=Dr;var Mn=10,[om,yr]=io(Dr),Lk="SelectContentImpl",Fk=wr.createSlot("SelectContent.RemoveScroll"),sm=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:m,hideWhenDetached:g,avoidCollisions:y,...x}=e,w=gr(Dr,n),[C,T]=v.useState(null),[k,S]=v.useState(null),E=Je(t,te=>T(te)),[j,_]=v.useState(null),[P,D]=v.useState(null),z=Ai(n),[B,O]=v.useState(!1),H=v.useRef(!1);v.useEffect(()=>{if(C)return Da(C)},[C]),ya();const R=v.useCallback(te=>{const[L,...G]=z().map(U=>U.ref.current),[se]=G.slice(-1),le=document.activeElement;for(const U of te)if(U===le||(U==null||U.scrollIntoView({block:"nearest"}),U===L&&k&&(k.scrollTop=0),U===se&&k&&(k.scrollTop=k.scrollHeight),U==null||U.focus(),document.activeElement!==le))return},[z,k]),V=v.useCallback(()=>R([j,C]),[R,j,C]);v.useEffect(()=>{B&&V()},[B,V]);const{onOpenChange:$,triggerPointerDownPosRef:F}=w;v.useEffect(()=>{if(C){let te={x:0,y:0};const L=se=>{var le,U;te={x:Math.abs(Math.round(se.pageX)-(((le=F.current)==null?void 0:le.x)??0)),y:Math.abs(Math.round(se.pageY)-(((U=F.current)==null?void 0:U.y)??0))}},G=se=>{te.x<=10&&te.y<=10?se.preventDefault():C.contains(se.target)||$(!1),document.removeEventListener("pointermove",L),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",G,{capture:!0})}}},[C,$,F]),v.useEffect(()=>{const te=()=>$(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[$]);const[ne,Q]=Sm(te=>{const L=z().filter(le=>!le.disabled),G=L.find(le=>le.ref.current===document.activeElement),se=Cm(L,te,G);se&&setTimeout(()=>se.ref.current.focus())}),ye=v.useCallback((te,L,G)=>{const se=!H.current&&!G;(w.value!==void 0&&w.value===L||se)&&(_(te),se&&(H.current=!0))},[w.value]),Pe=v.useCallback(()=>C==null?void 0:C.focus(),[C]),Z=v.useCallback((te,L,G)=>{const se=!H.current&&!G;(w.value!==void 0&&w.value===L||se)&&D(te)},[w.value]),ue=r==="popper"?Dl:im,ke=ue===Dl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(om,{scope:n,content:C,viewport:k,onViewportChange:S,itemRefCallback:ye,selectedItem:j,onItemLeave:Pe,itemTextRefCallback:Z,focusSelectedItem:V,selectedItemText:P,position:r,isPositioned:B,searchRef:ne,children:u.jsx(Hs,{as:Fk,allowPinchZoom:!0,children:u.jsx(bs,{asChild:!0,trapped:w.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:ge(o,te=>{var L;(L=w.trigger)==null||L.focus({preventScroll:!0}),te.preventDefault()}),children:u.jsx(ws,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(ue,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:te=>te.preventDefault(),...x,...ke,onPlaced:()=>O(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ge(x.onKeyDown,te=>{const L=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!L&&te.key.length===1&&Q(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let se=z().filter(le=>!le.disabled).map(le=>le.ref.current);if(["ArrowUp","End"].includes(te.key)&&(se=se.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const le=te.target,U=se.indexOf(le);se=se.slice(U+1)}setTimeout(()=>R(se)),te.preventDefault()}})})})})})})});sm.displayName=Lk;var $k="SelectItemAlignedPosition",im=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=gr(Dr,n),i=yr(Dr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Je(t,E=>d(E)),h=Ai(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:w}=i,C=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),P=x.getBoundingClientRect();if(s.dir!=="rtl"){const le=P.left-j.left,U=_.left-le,We=E.left-U,re=E.width+We,xe=Math.max(re,j.width),Re=window.innerWidth-Mn,Fe=_l(U,[Mn,Math.max(Mn,Re-xe)]);a.style.minWidth=re+"px",a.style.left=Fe+"px"}else{const le=j.right-P.right,U=window.innerWidth-_.right-le,We=window.innerWidth-E.right-U,re=E.width+We,xe=Math.max(re,j.width),Re=window.innerWidth-Mn,Fe=_l(U,[Mn,Math.max(Mn,Re-xe)]);a.style.minWidth=re+"px",a.style.right=Fe+"px"}const D=h(),z=window.innerHeight-Mn*2,B=g.scrollHeight,O=window.getComputedStyle(c),H=parseInt(O.borderTopWidth,10),R=parseInt(O.paddingTop,10),V=parseInt(O.borderBottomWidth,10),$=parseInt(O.paddingBottom,10),F=H+R+B+$+V,ne=Math.min(y.offsetHeight*5,F),Q=window.getComputedStyle(g),ye=parseInt(Q.paddingTop,10),Pe=parseInt(Q.paddingBottom,10),Z=E.top+E.height/2-Mn,ue=z-Z,ke=y.offsetHeight/2,te=y.offsetTop+ke,L=H+R+te,G=F-L;if(L<=Z){const le=D.length>0&&y===D[D.length-1].ref.current;a.style.bottom="0px";const U=c.clientHeight-g.offsetTop-g.offsetHeight,We=Math.max(ue,ke+(le?Pe:0)+U+V),re=L+We;a.style.height=re+"px"}else{const le=D.length>0&&y===D[0].ref.current;a.style.top="0px";const We=Math.max(Z,H+g.offsetTop+(le?ye:0)+ke)+G;a.style.height=We+"px",g.scrollTop=L-Z+g.offsetTop}a.style.margin=`${Mn}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,g,y,x,s.dir,r]);qt(()=>C(),[C]);const[T,k]=v.useState();qt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const S=v.useCallback(E=>{E&&m.current===!0&&(C(),w==null||w(),m.current=!1)},[C,w]);return u.jsx(Bk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:S,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}})})})});im.displayName=$k;var zk="SelectPopperPosition",Dl=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Mn,...s}=e,i=_i(n);return u.jsx(ld,{...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)"}})});Dl.displayName=zk;var[Bk,Ll]=io(Dr,{}),Fl="SelectViewport",am=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=yr(Fl,n),i=Ll(Fl,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(Ni.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: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 m=window.innerHeight-Mn*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<m){const w=x+p,C=Math.min(m,w),T=w-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});am.displayName=Fl;var lm="SelectGroup",[Hk,Uk]=io(lm),Wk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Qn();return u.jsx(Hk,{scope:n,id:o,children:u.jsx(De.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Wk.displayName=lm;var cm="SelectLabel",um=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Uk(cm,n);return u.jsx(De.div,{id:o.id,...r,ref:t})});um.displayName=cm;var ji="SelectItem",[Vk,dm]=io(ji),fm=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=gr(ji,n),l=yr(ji,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),m=Je(t,w=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,w,r,o)}),g=Qn(),y=v.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(Vk,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:v.useCallback(w=>{f(C=>C||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(Ni.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(De.div,{role:"option","aria-labelledby":g,"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:m,onFocus:ge(i.onFocus,()=>p(!0)),onBlur:ge(i.onBlur,()=>p(!1)),onClick:ge(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:ge(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:ge(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:ge(i.onPointerMove,w=>{var C;y.current=w.pointerType,o?(C=l.onItemLeave)==null||C.call(l):y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ge(i.onPointerLeave,w=>{var C;w.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:ge(i.onKeyDown,w=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&w.key===" "||(_k.includes(w.key)&&x(),w.key===" "&&w.preventDefault())})})})})});fm.displayName=ji;var Vo="SelectItemText",hm=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=gr(Vo,n),a=yr(Vo,n),l=dm(Vo,n),c=Ok(Vo,n),[d,f]=v.useState(null),h=Je(t,x=>f(x),l.onItemTextChange,x=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return qt(()=>(g(m),()=>y(m)),[g,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(De.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Xo.createPortal(s.children,i.valueNode):null]})});hm.displayName=Vo;var pm="SelectItemIndicator",mm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return dm(pm,n).isSelected?u.jsx(De.span,{"aria-hidden":!0,...r,ref:t}):null});mm.displayName=pm;var $l="SelectScrollUpButton",gm=v.forwardRef((e,t)=>{const n=yr($l,e.__scopeSelect),r=Ll($l,e.__scopeSelect),[o,s]=v.useState(!1),i=Je(t,r.onScrollButtonChange);return qt(()=>{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(xm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});gm.displayName=$l;var zl="SelectScrollDownButton",ym=v.forwardRef((e,t)=>{const n=yr(zl,e.__scopeSelect),r=Ll(zl,e.__scopeSelect),[o,s]=v.useState(!1),i=Je(t,r.onScrollButtonChange);return qt(()=>{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(xm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ym.displayName=zl;var xm=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=yr("SelectScrollButton",n),i=v.useRef(null),a=Ai(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),qt(()=>{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: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()})})}),Kk="SelectSeparator",vm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(De.div,{"aria-hidden":!0,...r,ref:t})});vm.displayName=Kk;var Bl="SelectArrow",qk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=_i(n),s=gr(Bl,n),i=yr(Bl,n);return s.open&&i.position==="popper"?u.jsx(cd,{...o,...r,ref:t}):null});qk.displayName=Bl;var Gk="SelectBubbleInput",wm=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Je(r,o),i=Hp(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:{...Yp,...n.style},ref:s,defaultValue:t})});wm.displayName=Gk;function bm(e){return e===""||e===void 0}function Sm(e){const t=Gt(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 Cm(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=Yk(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 Yk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Xk=Xp,km=Zp,Jk=em,Zk=tm,Qk=nm,Tm=rm,eT=am,Em=um,Im=fm,tT=hm,nT=mm,Nm=gm,Am=ym,_m=vm;const jm=Xk,Pm=Jk,Hl=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(km,{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(Zk,{asChild:!0,children:u.jsx(he.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Hl.displayName=km.displayName;const Rm=v.forwardRef(({className:e,...t},n)=>u.jsx(Nm,{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"})}));Rm.displayName=Nm.displayName;const Om=v.forwardRef(({className:e,...t},n)=>u.jsx(Am,{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"})}));Om.displayName=Am.displayName;const Ul=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Qk,{children:u.jsxs(Tm,{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(Rm,{}),u.jsx(eT,{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(Om,{})]})}));Ul.displayName=Tm.displayName;const rT=v.forwardRef(({className:e,...t},n)=>u.jsx(Em,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));rT.displayName=Em.displayName;const Lr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Im,{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(nT,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),u.jsx(tT,{children:t})]}));Lr.displayName=Im.displayName;const oT=v.forwardRef(({className:e,...t},n)=>u.jsx(_m,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));oT.displayName=_m.displayName;var sT="Separator",Mm="horizontal",iT=["horizontal","vertical"],Dm=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Mm,...o}=e,s=aT(r)?r:Mm,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})});Dm.displayName=sT;function aT(e){return iT.includes(e)}var Lm=Dm;const Fm=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Lm,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Fm.displayName=Lm.displayName;const lT=Kh,cT=kC,uT=qh,$m=v.forwardRef(({className:e,...t},n)=>u.jsx(hi,{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}));$m.displayName=hi.displayName;const dT=Yo.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"}}),zm=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(uT,{children:[u.jsx($m,{}),u.jsxs(pi,{ref:o,className:oe(dT({side:e}),t),...r,children:[n,u.jsxs(Gh,{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"})]})]})]}));zm.displayName=pi.displayName;const Bm=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});Bm.displayName="SheetHeader";const Hm=v.forwardRef(({className:e,...t},n)=>u.jsx(Rr,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));Hm.displayName=Rr.displayName;const Um=v.forwardRef(({className:e,...t},n)=>u.jsx(mi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Um.displayName=mi.displayName;const fT={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 hT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,d]=b.useState(!1),{toast:f}=bl();b.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),b.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(fT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(lT,{open:r,onOpenChange:o,children:[u.jsx(cT,{asChild:!0,children:u.jsxs(ct,{variant:"outline",size:"sm",className:n,children:[u.jsx(he.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Ch,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(zm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Bm,{children:[u.jsx(Hm,{children:"Chat Settings"}),u.jsx(Um,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(En,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Si,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(x=>({...x,api:{...x.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(ct,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(En,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(mr,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(x=>({...x,api:{...x.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(En,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Si,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(x=>({...x,api:{...x.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(ct,{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(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(En,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(jm,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Hl,{children:u.jsx(Pm,{})}),u.jsxs(Ul,{children:[u.jsx(Lr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(Lr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(Lr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(En,{htmlFor:"theme",children:"Theme"}),u.jsxs(jm,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Hl,{children:u.jsx(Pm,{})}),u.jsxs(Ul,{children:[u.jsx(Lr,{value:"light",children:"Light"}),u.jsx(Lr,{value:"dark",children:"Dark"}),u.jsx(Lr,{value:"system",children:"System"})]})]})]}),u.jsx(Fm,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(En,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(mr,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(En,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(mr,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(En,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(mr,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(En,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(mr,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(En,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(mr,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(En,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(mr,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(ct,{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(ct,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(ct,{onClick:h,disabled:!c,children:[u.jsx(he.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function pT({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=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(xs,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(bi,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(xs,{...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(Ml,{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(bi,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(xs,{...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(Ml,{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(bi,{onError:s.onError,enableFileUpload:!0})})]})})}_e.ChatApi=zc,_e.ChatInput=pu,_e.ChatInterface=bi,_e.ChatProviders=xs,_e.ChatSettings=hT,_e.MarkdownContent=Wo,_e.MessageComponent=Nl,_e.MessageList=Al,_e.ThreadManager=Ml,_e.applySettings=vk,_e.chatApiClient=sr,_e.default=pT,_e.del=$c,_e.get=vn,_e.getChatToken=Dc,_e.getCurrentSettings=xk,_e.getDefaultApiConfig=Lp,_e.getDefaultChatSettings=Fp,_e.onChatTokenChanged=Lc,_e.post=Yi,_e.put=Fc,_e.registerChatTokenSyncHandler=ky,_e.setChatToken=Gi,_e.useApi=Xi,_e.useChatStream=tu,_e.useMessagesReducer=qc,_e.useStream=fu,_e.useThreadState=ys,_e.useThreads=gs,Object.defineProperties(_e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
133
+ `}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=sp(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=sp(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 up{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 dp{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 pr{constructor(t){this.options=t||Rr,this.options.renderer=this.options.renderer||new Il,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new up,this.slugger=new dp}static parse(t,n){return new pr(n).parse(t)}static parseInline(t,n){return new pr(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,m,g,y,x,w,C,T,k,S;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]&&(S=this.options.extensions.renderers[p.type].call({parser:this},p),S!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=S||"";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,op(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(m=p.ordered,g=p.start,y=p.loose,a=p.items.length,h="",s=0;s<a;s++)w=p.items[s],C=w.checked,T=w.task,x="",w.task&&(k=this.renderer.checkbox(C),y?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=k+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=k+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:k}):x+=k),x+=this.parse(w.tokens,y),h+=this.renderer.listitem(x,T,C);r+=this.renderer.list(h,m,g);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
134
+ `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const j='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(j);return}else throw new Error(j)}}}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 xi{constructor(t){this.options=t||Rr}preprocess(t){return t}postprocess(t){return t}}Xm(xi,"passThroughHooks",new Set(["preprocess","postprocess"]));function qC(e,t,n){return r=>{if(r.message+=`
135
+ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+nn(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 fp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...be.defaults,...s};const i=qC(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(WC(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&&be.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;be.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(be.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&&be.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function be(e,t,n){return fp(hr.lex,pr.parse)(e,t,n)}be.options=be.setOptions=function(e){return be.defaults={...be.defaults,...e},jC(be.defaults),be},be.getDefaults=ep,be.defaults=Rr,be.use=function(...e){const t=be.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=be.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=be.defaults.renderer||new Il;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=be.defaults.tokenizer||new El;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=be.defaults.hooks||new xi;for(const s in n.hooks){const i=o[s];xi.passThroughHooks.has(s)?o[s]=a=>{if(be.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=be.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}}be.setOptions(r)})},be.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(be,r)),r.type){case"table":{for(const o of r.header)n=n.concat(be.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(be.walkTokens(s.tokens,t));break}case"list":{n=n.concat(be.walkTokens(r.items,t));break}default:be.defaults.extensions&&be.defaults.extensions.childTokens&&be.defaults.extensions.childTokens[r.type]?be.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(be.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(be.walkTokens(r.tokens,t)))}return n},be.parseInline=fp(hr.lexInline,pr.parseInline),be.Parser=pr,be.parser=pr.parse,be.Renderer=Il,be.TextRenderer=up,be.Lexer=hr,be.lexer=hr.lex,be.Tokenizer=El,be.Slugger=dp,be.Hooks=xi,be.parse=be,be.options,be.setOptions,be.use,be.walkTokens,be.parseInline,pr.parse,hr.lex;function Wo({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof be.parse=="function"?be.parse(i):be(i)}return typeof be.parse=="function"?be.parse(e):be(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=b.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 GC="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 YC(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function hp(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 vi(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function XC(e){const t=o=>{try{const s=Ho(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
136
+ `)):r=t(e),r||""}function JC(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function pp(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 ZC({className:e}){const[t,n]=b.useState(0);return b.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 Nl=b.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:m,onCancelEdit:g,onCopy:y,activeInterrupt:x,disableInterruptActions:w=!1,onInterruptActionStart:C,onInterruptActionEnd:T,checkpointCandidates:k=[],activeCheckpointId:S=null,onSelectCheckpoint:E,defaultCheckpointId:j=null,messageParentCheckpointId:_=null}){const[P,D]=b.useState(!1),[z,B]=b.useState("preview"),[O,H]=b.useState(!1),{currentThreadId:R}=ms(),{respondToInterrupt:V}=gs(),$=l==="phone"||l==="half-screen",F=t.role,ne=F==="tool",Q=b.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!Q,je=!(r&&F!=="user"),{uploadingFiles:J,handleFileClick:ue,fileViewerOpen:ke,currentFileInfo:te,closeFileViewer:L}=ek({allowFileOpen:je,currentThreadId:R}),q=b.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]),ie=b.useMemo(()=>Q?"":YC(t.content),[Q,t]),ce=b.useMemo(()=>Q?{}:hp(t),[Q,t]),U=b.useMemo(()=>Q?[]:t.content.filter(G=>G.type==="image_url"),[Q,t]),We=b.useMemo(()=>Q?[]:t.content.filter(G=>G.type==="file"),[Q,t]),re=b.useMemo(()=>Q?[]:t.content.filter(G=>G.type==="interrupt"),[Q,t]),xe=(x==null?void 0:x.id)??(x==null?void 0:x.interrupt_id),Pe=vi(xe),$e=x==null?void 0:x.value,rt=b.useMemo(()=>Q?"":XC(t.content),[Q,t]),Se=b.useCallback(async()=>{const G=ne?rt:ie;async function Te(ve){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ve);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const pt=new Blob([ve],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":pt})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Te(G),D(!0),setTimeout(()=>D(!1),2e3),y==null||y(G)}catch(ve){console.error("Failed to copy:",ve)}},[ne,rt,ie,y]),Ye=b.useCallback(()=>{if(!p)return;const G=ne?rt:ie,Te="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};p(t.id,G,Te)},[p,t.id,ne,rt,ie,t]),ot=b.useCallback(()=>{m==null||m(n)},[m,n]),et=b.useCallback(()=>{const Te=oe($?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",q);switch(F){case"user":return u.jsx(he.User,{className:Te});case"assistant":return u.jsx(he.Bot,{className:Te});case"tool":return u.jsx(he.Wrench,{className:Te});default:return u.jsx(he.Bot,{className:Te})}},[$,q,F]),Xe=b.useCallback(()=>{const G="group relative mb-4 flex w-full";switch(F){case"user":return oe(G,"justify-end");case"assistant":case"tool":case"system":return oe(G,"justify-start");default:return G}},[F]),Ke=b.useCallback(()=>{const G=oe("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",$&&"px-3 py-2 text-sm");if(ye)return oe(G,"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(G,"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(G,"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(G,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return oe(G,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return oe(G,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[$,ye,F]);if(ye&&Q)return u.jsx("div",{className:oe(Xe(),h.container),children:u.jsxs("div",{className:oe(Ke(),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",q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(Wo,{content:Q.content,className:"text-current"})]})});const tt=b.useCallback(async G=>{if(w)return;const Te=vi((G==null?void 0:G.id)??(G==null?void 0:G.interrupt_id));if(!Te){console.warn("Interrupt part missing id",G);return}try{C==null||C(),await V(Te,!0)}catch(ve){console.error("Failed to approve interrupt:",ve)}finally{T==null||T()}},[w,T,C,V]),Ot=b.useCallback(async G=>{if(w)return;const Te=vi((G==null?void 0:G.id)??(G==null?void 0:G.interrupt_id));if(!Te){console.warn("Interrupt part missing id",G);return}try{C==null||C(),await V(Te,!1)}catch(ve){console.error("Failed to reject interrupt:",ve)}finally{T==null||T()}},[w,T,C,V]),St=b.useCallback(({part:G,i:Te})=>{if(G.type==="text"){const ve=G.text??"",pt=ve.trim(),mt=Sl(pt);return mt&&F!=="tool"?u.jsx(mp,{data:mt},Te):F==="user"&&c&&pt.length>d?u.jsx(tk,{text:pt,expanded:O,onExpandedChange:H,previewLength:d,isCompact:$},Te):u.jsx(Wo,{content:ve,allowHtml:!1},Te)}if(G.type==="image_url"){const ve=G;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ve.url,alt:ve.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Te)}if(G.type==="file"){const ve=G,pt=ve.name||"file";return u.jsxs("a",{href:ve.url,onClick:mt=>ue(mt,ve,Te),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[J[Te]?u.jsx(he.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[pt,J[Te]?" (processing)":""]})]},Te)}if(G.type==="interrupt"){const ve=G,pt=vi((ve==null?void 0:ve.id)??(ve==null?void 0:ve.interrupt_id)),mt=!!(Pe&&pt&&pt===Pe),ct=mt?$e??(ve==null?void 0:ve.value):ve==null?void 0:ve.value,Me=pt?{...ve,id:pt,interrupt_id:pt}:ve;return u.jsx(QC,{interruptPart:Me,onApprove:tt,onReject:Ot,disabled:w,isActive:mt,payload:ct},Te)}return null},[ue,J,tt,Ot,F,c,d,O,$,Pe,$e,x,w,re]),nt=b.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"})]}),[]),yt=b.useCallback(()=>{const G=ie.trim().length>0||U.length>0||We.length>0||re.length>0;if(!ne&&We.length>0&&!r)return nt();if(!ne&&!G&&!r)return null;if(ne)return u.jsx(nk,{message:t,viewMode:z},t.id);if(!ne&&!Q){const Te=t,ve=u.jsx("div",{className:"space-y-2",children:Te.content.map((pt,mt)=>u.jsx(St,{part:pt,i:mt},mt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ve,u.jsx(ZC,{className:q})]}):ve}},[ie,U.length,We.length,re.length,r,ne,z,nt,q]),Nt=b.useMemo(()=>Q?"Assistant":JC(t),[Q,t]),st=b.useMemo(()=>Q?[]:Array.isArray(k)?k:[],[k,Q]),Gt=b.useMemo(()=>{var G;return st.length?j&&st.some(Te=>Te.id===j)?j:((G=st[0])==null?void 0:G.id)??null:null},[j,st]),Xt=b.useMemo(()=>!st.length||!S?null:st.some(G=>G.id===S)?S:null,[S,st])??Gt,Jt=F==="user"&&st.length>0&&typeof E=="function",ft=b.useCallback(G=>{if(!E)return;const Te=(G==null?void 0:G.id)??null,ve=(G==null?void 0:G.parentId)??_??null;E(Te,ve)},[_,E]),Ve=b.useMemo(()=>Xt?st.findIndex(G=>G.id===Xt):-1,[Xt,st]),Mt=b.useMemo(()=>Ve<0?null:st[Ve]??null,[Ve,st]),_t=b.useCallback(G=>{const Te=[];if(G.step!==null&&Te.push(`Step ${G.step}`),G.source&&Te.push(G.source),!G.createdAt)return Te.length?Te.join(" • "):G.id.slice(0,8);let ve="";try{const pt=new Date(G.createdAt);Number.isNaN(pt.getTime())||(ve=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(pt))}catch{ve=""}return`${ve}`},[]);return ne&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:oe(Xe(),h.container),children:u.jsxs("div",{className:oe(Ke(),h.content),children:[(i||a||ne)&&u.jsxs("div",{className:oe("flex items-center justify-between mb-2 pb-2 border-b border-current/10",$&&"mb-1 pb-1",q,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[et(),a&&Nt&&u.jsx("span",{className:oe("font-medium",$?"text-xs":"text-sm"),children:Nt}),ne&&u.jsxs(kh,{variant:"outline",className:oe("text-xs flex items-center gap-1 cursor-pointer select-none",q,"border border-current/40",$&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":z==="expanded",onClick:()=>B(G=>G==="expanded"?"preview":"expanded"),onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),B(Te=>Te==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ce.name??"Tool Output"}),ce.toolCallId&&u.jsx("span",{className:"opacity-70",children:ce.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:[Jt&&Mt&&Ve>=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",Ve>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ve<=0)return;const G=st[Ve-1];G&&ft(G)},"aria-label":"Previous checkpoint",disabled:Ve<=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:[Ve+1," / ",st.length]}),u.jsx("span",{className:"text-muted-foreground",children:_t(Mt)})]}),u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ve<st.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ve>=st.length-1)return;const G=st[Ve+1];G&&ft(G)},"aria-label":"Next checkpoint",disabled:Ve>=st.length-1,children:u.jsx(he.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:oe("text-xs opacity-60",q,$&&"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:()=>Se(),className:oe("h-6 w-6 p-0 hover:bg-foreground/10",q,$&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(he.Copy,{className:oe(P?"text-success":q,$?"h-3 w-3":"h-4 w-4")})})}),F==="user"&&p&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:Ye,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",q,$&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(he.Edit,{className:oe(q,$?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&m&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:ot,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",q,$&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(he.RotateCcw,{className:oe(q,$?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:yt()}),ne&&z==="expanded"&&(ce.toolCallId||ce.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",$&&"text-xs"),children:[ce.name&&u.jsxs("div",{children:["Function: ",ce.name]}),ce.toolCallId&&u.jsxs("div",{children:["Call ID: ",ce.toolCallId]})]}),!(i||a||ne)&&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:()=>Se(),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(P?"text-success":"text-current",$?"h-3 w-3":"h-4 w-4")})}),F==="user"&&p&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:Ye,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"&&m&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:ot,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")})})]})]})}),te&&u.jsx(_C,{isOpen:ke,onClose:L,fileId:te.id,fileName:te.name,mimeType:te.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&pp(e.message)===pp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),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 mp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:GC,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:Uo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Uo(e)})}function QC({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=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=Uo(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(Lo,{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(Fo,{className:"pb-3",children:[u.jsx($o,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(Th,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(zo,{className:"pt-0 pb-3",children:a}),u.jsx(Eh,{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 ek(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=bl(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(p=>{a(p),c(!0)},[]),h=b.useCallback(async(p,m,g)=>{var y,x;if(!t){p.preventDefault();return}if(o[g]){p.preventDefault();return}try{const w=String(m.url??""),C=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(C){p.preventDefault();const T=C[1],k=m.name||`file_${T}`,S=m.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:S});return}if(w.startsWith("data:")){p.preventDefault(),s(k=>({...k,[g]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await pC(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const S=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(S!=null&&S.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!S.id||!S.filename)throw new Error("Invalid file data received from server");f({id:S.id,name:m.name||S.filename||`file_${S.id}`,mimeType:m.mimeType||S.mime_type||"application/octet-stream"}),(y=T.update)==null||y.call(T,{id:T.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const S=k instanceof Error?k.message:"Unknown error occurred";(x=T.update)==null||x.call(T,{id:T.id,title:"Failed",description:S}),r({title:"Failed to fetch file",description:S,open:!0})}finally{s(k=>({...k,[g]:!1}))}}}catch(w){console.error("File click error:",w),s(C=>({...C,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function tk({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(Wo,{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 nk({message:e,viewMode:t}){const r=hp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Sl(c)??c:c;if(d&&typeof d=="object")return u.jsx(mp,{data:d});const f=typeof d=="string"?d:(()=>{try{return Uo(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}=gC(c);return f?u.jsx(Wo,{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=ci(d);return s(f)}const a=Ho(i),l=ci(a);return s(l)}const gp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,rk=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},Al=b.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:m=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:w,disableInterruptActions:C=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:S=!0,checkpointMetaById:E,checkpointIndexByKey:j,activeCheckpointId:_,onSelectCheckpoint:P,timelineCheckpoints:D},z)=>{const B=b.useRef(null),O=b.useRef(null),H=b.useRef(!1),[R,V]=b.useState(!0),$=b.useMemo(()=>w?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===w.id)):!1,[w,e]),F=b.useMemo(()=>{if(!w||$)return null;const re=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let xe;const Pe=w.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const $e=Pe.title;typeof $e=="string"&&$e.trim()&&(xe=$e.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Pe,title:xe}]}},[w,$]),ne=b.useMemo(()=>F?[...e,F]:e,[e,F]),Q=b.useMemo(()=>S?ne:ne.filter(re=>(re==null?void 0:re.role)!=="tool"),[ne,S]),ye=b.useMemo(()=>{const re=new Set,xe=[];for(let Pe=Q.length-1;Pe>=0;Pe--){const $e=Q[Pe];if(!$e)continue;if("type"in $e&&$e.type==="default_message"){xe.push($e);continue}const rt=$e,Se=rk(rt);re.has(Se)||(re.add(Se),xe.push(rt))}return xe.reverse()},[Q]),je=b.useCallback(re=>{V(re),y&&y(!re),x&&x(re)},[y,x]),J=b.useMemo(()=>{if(a)return async()=>{if(!H.current){H.current=!0;try{await a()}finally{H.current=!1}}}},[a]),ue=b.useMemo(()=>!m||g?!1:R?"auto":!1,[R,m,g]),ke=b.useMemo(()=>D??[],[D]),te=_??(ke.length?ke[ke.length-1].id:null),L=ke.length>0,q=b.useMemo(()=>{if(typeof p!="string")return null;const re=p.trim();return re?{id:"default-message",role:"assistant",type:"default_message",content:re,createdAt:new Date().toISOString()}:null},[p]),ie=L?u.jsxs("div",{className:"hidden w-48 flex-shrink-0 flex-col border-r border-border/40 pr-4 md:flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-5 pb-5 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative z-50",children:[u.jsx(he.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-56 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.'})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-5 top-0 bottom-0 w-px bg-border/50"}),u.jsx("div",{className:"flex flex-col gap-4",children:ke.map(re=>{const xe=te===re.id;return u.jsxs("button",{type:"button",disabled:!P,onClick:()=>P==null?void 0:P(re.id),className:`relative flex items-start gap-3 text-left text-xs transition ${xe?"text-primary":"text-muted-foreground"} ${P?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-4 w-4 items-center justify-center rounded-full border ${xe?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${xe?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:re.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[re.step!==null?`STEP ${re.step}`:"STEP —",re.next?` - ${re.next}`:""]})]})]},re.id)})})]}),P&&u.jsx("button",{type:"button",onClick:()=>P==null?void 0:P(null),className:"mt-auto rounded-md border border-border/70 px-3 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null,ce=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),U=()=>q?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Nl,{message:q,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:p??"No messages yet. Start a conversation!"}),We=ye.length>0;return b.useImperativeHandle(z,()=>({scrollToLatest:()=>{var re,xe;if(B.current&&ye.length>0){const Pe=ye.length-1;(xe=(re=B.current).scrollToIndex)==null||xe.call(re,{index:Pe,align:"end",behavior:"auto"})}else O.current&&(O.current.scrollTop=O.current.scrollHeight)},scrollToTop:()=>{var re,xe;B.current&&ye.length>0?(xe=(re=B.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):O.current&&(O.current.scrollTop=0)}}),[ye]),u.jsxs("div",{className:ce,style:h,children:[ie,u.jsx("div",{className:"relative flex-1 min-h-0",children:We?u.jsx(KS,{ref:re=>{B.current=re},scrollerRef:re=>{O.current=re instanceof HTMLDivElement?re:null},data:ye,followOutput:ue,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{J&&J()},atBottomStateChange:je,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>gp(xe,re),itemContent:(re,xe)=>{var tt;const Pe=gp(xe,re),$e="type"in xe&&xe.type==="default_message";let rt=[],Se=null,Ye={},ot={},et=null,Xe=null;if(!$e){const Ot=xe,St=Ot.checkpointId??null;Ye=Ot.additionalKwargs??{},ot=Ot.responseMetadata??{};const nt=St&&E?E.get(St)??null:null;et=typeof Ye.step=="number"?Ye.step:typeof ot.step=="number"?ot.step:(nt==null?void 0:nt.step)??null;const yt=typeof Ye.source=="string"?Ye.source:typeof ot.source=="string"?ot.source:(nt==null?void 0:nt.source)??null;Xe=yt?String(yt):null;const Nt=et!==null&&Xe?`${et}:${Xe}`:null;Nt&&(j!=null&&j.has(Nt))?rt=j.get(Nt)??[]:St&&nt&&(rt=[nt]),Se=St??((tt=rt[0])==null?void 0:tt.id)??null}const Ke=(()=>{if(typeof Ye.parentCheckpointId=="string")return Ye.parentCheckpointId;if(typeof ot.parentCheckpointId=="string")return ot.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":Pe,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Nl,{message:xe,messageIndex:re,isStreamingMessage:t&&n===xe.id,streamingDebounceMs:r,isEditing:i===xe.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(re),onCancelEdit:d,activeInterrupt:w,disableInterruptActions:C,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:S,checkpointCandidates:rt,activeCheckpointId:_??null,onSelectCheckpoint:P,defaultCheckpointId:Se,messageParentCheckpointId:Ke})})}}):U()})]})});Al.displayName="MessageList";const yp={value:""};function wi({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:m}){const{api:g}=Xi(),{currentThreadId:y}=ms(),{threadId:x,messages:w,hasMore:C,isHistoryLoading:T,isLoading:k,loadOlder:S,navigateToCheckpoint:E,returnToLatest:j,checkpoint:_,checkpoints:P,interrupt:D,metadata:z}=gs(),{isStreaming:B,error:O,connectionState:H,submit:R,stop:V}=hu(),$=x??y??null,F=(_==null?void 0:_.id)??null,ne=(_==null?void 0:_.namespace)??null,Q=(z==null?void 0:z.assemblingMessageId)??null,ye=D,[je,J]=b.useState(!1);b.useEffect(()=>{ye||J(!1)},[ye]);const ue=b.useCallback(()=>{J(!0)},[]),ke=b.useCallback(()=>{J(!1)},[]),te=!!ye||je,[L,q]=b.useState(null),[ie,ce]=b.useState(""),[U,We]=b.useState(null),[re,xe]=b.useState(null),[Pe,$e]=b.useState([]),[rt,Se]=b.useState(0),[Ye,ot]=b.useState(0),[et,Xe]=b.useState(!1),[Ke,tt]=b.useState(null),[Ot,St]=b.useState(null),[nt,yt]=b.useState(!1),[Nt,st]=b.useState(null),[Gt,Yt]=b.useState(!1),Xt=b.useRef(!1),[Jt,ft]=b.useState(()=>yp.value),Ve=b.useRef(Jt),Mt=b.useRef(null),_t=b.useCallback(Z=>{yp.value=Z,ft(Z)},[]),[G,Te]=b.useState(!1),ve=b.useRef(null),pt=b.useCallback(Z=>{if(!Array.isArray(Z))return{text:null,messageId:null};for(let se=Z.length-1;se>=0;se--){const de=Z[se];if(!de||de.role!=="user")continue;const Ie=(de.content??[]).filter(Je=>(Je==null?void 0:Je.type)==="text").map(Je=>Je.text).filter(Je=>typeof Je=="string"&&Je.trim().length>0);return{text:Ie.length?Ie.join(" ").trim():null,messageId:de.id??null}}return{text:null,messageId:null}},[]),mt=b.useCallback((Z,se)=>{if(!Z||typeof Z!="object")return null;const de=Z[se];return typeof de=="number"?de:null},[]),ct=b.useCallback((Z,se)=>{if(!Z||typeof Z!="object")return null;const de=Z[se];return typeof de=="string"&&de.trim()?de:null},[]),Me=b.useMemo(()=>{const Z=Ie=>{if(!Array.isArray(Ie)||Ie.length===0)return null;const lt=Ie.map(Je=>{if(typeof Je=="string")return Je.trim();if(Je&&typeof Je=="object"&&"type"in Je){const it=Je;if(typeof it.type=="string")return it.type}return null}).filter(Je=>!!(Je&&Je.length));return lt.length?lt.join(", "):null},se=Array.isArray(P)?P.map(Ie=>{const lt=Z(Ie.next);return lt?{...Ie,metadata:{...Ie.metadata??{},next:lt}}:Ie}):[];return se.some(Ie=>mt(Ie.metadata,"step")!==null)&&se.sort((Ie,lt)=>{const Je=mt(Ie.metadata,"step"),it=mt(lt.metadata,"step");if(Je!==null||it!==null)return(it??Number.NEGATIVE_INFINITY)-(Je??Number.NEGATIVE_INFINITY);const Bt=Date.parse(Ie.createdAt??""),sn=Date.parse(lt.createdAt??"");return Number.isNaN(Bt)||Number.isNaN(sn)?0:sn-Bt}),se},[P,mt]),{checkpointMetaById:Ut,checkpointIndexByKey:Le}=b.useMemo(()=>{const Z=new Map,se=new Map;for(const de of Me){const Ie=de.checkpointId??null;if(!Ie)continue;const lt=mt(de.metadata,"step"),Je=ct(de.metadata,"source"),it={id:Ie,step:lt,source:Je,createdAt:de.createdAt??null,namespace:de.checkpointNs??null,parentId:de.parentId??null};if(Z.set(Ie,it),lt!==null&&Je){const Bt=`${lt}:${Je}`,sn=se.get(Bt)??[];sn.push(it),se.set(Bt,sn)}}for(const de of se.values())de.sort((Ie,lt)=>{const Je=Ie.createdAt??"";return(lt.createdAt??"").localeCompare(Je)});return{checkpointMetaById:Z,checkpointIndexByKey:se}},[Me,mt,ct]),xt=b.useMemo(()=>{var Je;if(!Me.length)return[];const Z=[...Me].reverse(),se=(it,Bt)=>{const sn=it.checkpointId??null;if(!sn)return null;const Xn=ct(it.metadata,"source");ct(it.metadata,"next");const{text:Ko,messageId:ji}=pt(it.messages),Nn=Ko&&Ko.replace(/\s+/g," ").trim()||ct(it.metadata,"title")||ct(it.metadata,"label")||Bt||Xn||"Checkpoint",Pi=Nn.length>60?`${Nn.slice(0,57)}…`:Nn;return{id:sn,label:Pi,messageId:ji??null,createdAt:it.createdAt??null,step:mt(it.metadata,"step"),source:Xn??null,next:ct(it.metadata,"next")}},de=[],Ie=new Set;for(const it of Z){const Bt=((Je=ct(it.metadata,"source"))==null?void 0:Je.toLowerCase())??null;if(!(Bt==="input"||Bt==="user_input"||Bt==="user"))continue;const Xn=se(it,"User input");Xn&&!Ie.has(Xn.id)&&(de.push(Xn),Ie.add(Xn.id))}if(!de.length)for(const it of Z){const Bt=se(it);Bt&&!Ie.has(Bt.id)&&(de.push(Bt),Ie.add(Bt.id))}const lt=Me.find(it=>{var sn;return(((sn=ct(it.metadata,"source"))==null?void 0:sn.toLowerCase())??null)==="loop"});if(lt){const it=se(lt,"Latest loop");it&&!Ie.has(it.id)&&(de.push(it),Ie.add(it.id))}return de},[Me,pt,mt,ct]),Ln=b.useRef(null),Dt=b.useRef(null),fn=b.useCallback(()=>{Ln.current&&(Ln.current.value=""),Dt.current&&(Dt.current.value=""),Se(Z=>Z+1),ot(Z=>Z+1)},[]),io=b.useCallback(Z=>{_t(Z)},[_t]),ao=b.useRef(!1);b.useEffect(()=>{ao.current&&!B&&($e([]),fn()),ao.current=B},[B,fn]);const[Lr,Fr]=b.useState("desktop");b.useEffect(()=>{const Z=()=>{const se=window.innerWidth;Fr(se<640?"phone":se<1024?"tablet":"desktop")};return Z(),window.addEventListener("resize",Z),()=>window.removeEventListener("resize",Z)},[]),b.useEffect(()=>{Yt(!1),Xt.current=!1},[$]),b.useEffect(()=>{Ve.current=Jt},[Jt]),b.useEffect(()=>{if(!L){Mt.current=null;return}Mt.current===null&&(Mt.current=Ve.current),_t(ie??"")},[ie,L,_t]);const N=b.useCallback(async()=>{if(!(!C||T||!Gt))try{await S()}catch(Z){console.warn("loadOlder failed",Z)}},[C,Gt,T,S]);b.useEffect(()=>{(async()=>{if(!g.baseUrl){st(null);return}try{const de=(await g.getAgent("default")).uiDefaultMessage||"";st(de||null)}catch(se){console.warn("Failed to fetch default message:",se),st(null)}})()},[g.baseUrl]),b.useEffect(()=>{O&&!nt&&(m==null||m(O))},[O,nt,m]);const Y=Z=>{if(Z.length>qs)return`Message too long (${Z.length}/${qs} characters)`;try{return D0(Z),null}catch(se){return(se==null?void 0:se.message)||"Invalid message"}},ae=async Z=>{const se=Z.trim();if(!(!se&&Pe.length===0)){if(se){const de=Y(se);if(de){xe(de);return}}try{const de=F??void 0,Ie=ne??void 0,lt=L?{edit:!0,originalMessageId:L,...U!=null&&U.checkpointId?{originalCheckpointId:U.checkpointId}:{},...U!=null&&U.checkpointNs?{originalCheckpointNs:U.checkpointNs}:{}}:void 0;await R({text:se||"",attachments:Pe,messageAdditionalKwargs:lt},{checkpointId:de,checkpointNs:Ie}),h==null||h(se),_t(""),xe(null),$e([]),fn(),q(null),ce(""),We(null)}catch(de){const Ie=(de==null?void 0:de.message)||"Failed to send message";xe(Ie),m==null||m(Ie)}}},Ce=b.useCallback((Z,se,de)=>{c&&(Mt.current=Jt,q(Z),ce(se),_t(se),xe(null),We({checkpointId:(de==null?void 0:de.checkpointId)??null,checkpointNs:(de==null?void 0:de.checkpointNs)??null}))},[Jt,c,_t]),Ge=b.useCallback(()=>{q(null),ce(""),We(null),xe(null),_t(Mt.current??Jt),Mt.current=null},[Jt,_t]),qe=b.useCallback((Z,se,de)=>{Ce(Z,se,de)},[Ce]),He=b.useCallback(Z=>{for(let se=Z-1;se>=0;se--)if(w[se].role==="user"){const de=w[se].content||[],lt=de.filter(Je=>Je.type==="text").map(Je=>Je.text).join("")||(()=>{try{return JSON.stringify(de,null,2)}catch{return String(de)}})();lt&&R({text:lt},{checkpointId:F??void 0,checkpointNs:ne??void 0});break}},[w,R,F,ne]),Re=Z=>{const se=Array.from(Z.target.files||[]);$e(de=>[...de,...se]),Z.target.value=""},At=Z=>{$e(se=>{const de=se.filter((Ie,lt)=>Z!==lt);return de.length===0&&fn(),de})},gt=async Z=>{const se=(Z.target.files||[])[0];if(se){tt(null),St(null),Xe(!0);try{await R({attachments:[se]},{checkpointId:F??void 0,checkpointNs:ne??void 0});const de=`Uploaded ${se.name} - processing through chat stream`;St(de)}catch(de){const Ie=de instanceof Error?de.message:"Failed to upload Excel file";console.error("Excel upload failed",de),tt(Ie),m==null||m(Ie)}finally{Xe(!1),Z.target.value="",fn()}}},Ct=async Z=>{if(y){Te(!0);try{if(!Z){await j(),Yt(!1),requestAnimationFrame(()=>{var Ie;(Ie=ve.current)==null||Ie.scrollToLatest()});return}const se=Me.find(Ie=>Ie.checkpointId===Z),de=(se==null?void 0:se.checkpointNs)??null;await E(Z,de),Yt(!0),requestAnimationFrame(()=>{var Ie;(Ie=ve.current)==null||Ie.scrollToTop()})}finally{Te(!1)}}},Zt=b.useCallback(async Z=>{await Ct(Z)},[Ct]),Fn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,hn=`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||""}`,zt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,$n=b.useCallback(Z=>{if(!Z)return"Latest";const se=[];Z.step!==null&&se.push(`Step ${Z.step}`),Z.source&&se.push(Z.source);const de=Z.createdAt?new Date(Z.createdAt):null,Ie=de&&!Number.isNaN(de.getTime())?de.toLocaleString():Z.createdAt??Z.id,lt=se.length?` — ${se.join(" • ")}`:"";return`${Ie}${lt}`},[]);return u.jsxs("div",{className:Fn,children:[!!O&&!nt&&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:()=>yt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(he.X,{size:16})})]}),y&&Me.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:Z=>{const se=Z.target.value||null;Ct(se)},children:[u.jsx("option",{value:"",children:"Latest"}),Me.map(Z=>{const se=Ut.get(Z.checkpointId??"")??null;return u.jsx("option",{value:Z.checkpointId??void 0,children:$n(se)},Z.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${hn}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Al,{ref:ve,className:"h-full",style:{height:"100%"},messages:w,isStreaming:B,streamingAssistantId:Q,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Lr,enableMessageEditing:c,editingMessageId:L,onStartReached:()=>{Gt&&N()},onScrollAway:Z=>{if(!Xt.current){Xt.current=!0;return}Z&&Yt(!0)},onEdit:qe,onRegenerate:He,onCancelEdit:Ge,emptyMessage:Nt??void 0,isNavigatingCheckpoint:G,activeInterrupt:ye,disableInterruptActions:je,onInterruptActionStart:ue,onInterruptActionEnd:ke,showToolMessages:d,checkpointMetaById:Ut,checkpointIndexByKey:Le,activeCheckpointId:F,onSelectCheckpoint:Zt,timelineCheckpoints:xt}),(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(he.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(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:zt,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:Ge,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:Ln,type:"file",multiple:!0,onChange:Z=>Re(Z),className:"hidden"},rt),Pe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Pe.map((Z,se)=>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:Z.name}),u.jsx(ut,{variant:"ghost",size:"sm",onClick:()=>At(se),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${Z.name}`,children:u.jsx(he.X,{size:12})})]},se))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Dt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:gt,className:"hidden"},Ye),et&&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..."]}),Ot&&!et&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Ot}),Ke&&!et&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Ke})]})]}),re&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:re}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(E0,{children:[u.jsx(I0,{asChild:!0,children:u.jsx(ut,{type:"button",size:"icon",variant:"outline",disabled:B||te,title:"More input actions",className:f.moreButton||"",children:u.jsx(he.Plus,{size:16})})}),u.jsxs(Tf,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ya,{onClick:()=>{var Z;return(Z=Ln.current)==null?void 0:Z.click()},className:"cursor-pointer",children:[u.jsx(he.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Ya,{onClick:()=>{var Z;et||(Z=Dt.current)==null||Z.click()},className:`cursor-pointer ${et?"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(Ix,{initialValue:ie,editingMessageId:L,value:Jt,onValueChange:io,placeholder:L?"Edit your message...":t,isStreaming:B,disabled:te,maxLength:qs,onSend:ae,onCancelEdit:Ge,onStop:V,allowEmptySend:Pe.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":""} ${re?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const bi=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}));bi.displayName="Input";function _l(e,[t,n]){return Math.min(n,Math.max(t,e))}function ok(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var jl="ScrollArea",[xp,YT]=Qn(jl),[sk,En]=xp(jl),vp=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,m]=v.useState(null),[g,y]=v.useState(null),[x,w]=v.useState(0),[C,T]=v.useState(0),[k,S]=v.useState(!1),[E,j]=v.useState(!1),_=Ze(t,D=>l(D)),P=xs(o);return u.jsx(sk,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:k,onScrollbarXEnabledChange:S,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:w,onCornerHeightChange:T,children:u.jsx(De.div,{dir:P,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});vp.displayName=jl;var wp="ScrollAreaViewport",bp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=En(wp,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})})]})});bp.displayName=wp;var Yn="ScrollAreaScrollbar",Pl=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=En(Yn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(ik,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(ak,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Sp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Rl,{...r,ref:t}):null});Pl.displayName=Yn;var ik=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=En(Yn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Sn,{present:n||s,children:u.jsx(Sp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),ak=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=En(Yn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ti(()=>l("SCROLL_END"),100),[a,l]=ok("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(Sn,{present:n||a!=="hidden",children:u.jsx(Rl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Sp=v.forwardRef((e,t)=>{const n=En(Yn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ti(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return ro(n.viewport,l),ro(n.content,l),u.jsx(Sn,{present:r||s,children:u.jsx(Rl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Rl=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=En(Yn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Ip(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 hk(h,i.current,a,p)}return n==="horizontal"?u.jsx(lk,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Np(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(ck,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Np(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}),lk=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=En(Yn,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(kp,{"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":ki(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),_p(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:Ci(i.paddingLeft),paddingEnd:Ci(i.paddingRight)}})}})}),ck=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=En(Yn,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(kp,{"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":ki(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),_p(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:Ci(i.paddingTop),paddingEnd:Ci(i.paddingBottom)}})}})}),[uk,Cp]=xp(Yn),kp=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=En(Yn,n),[m,g]=v.useState(null),y=Ze(t,_=>g(_)),x=v.useRef(null),w=v.useRef(""),C=p.viewport,T=r.content-r.viewport,k=qt(d),S=qt(l),E=Ti(f,10);function j(_){if(x.current){const P=_.clientX-x.current.left,D=_.clientY-x.current.top;c({x:P,y:D})}}return v.useEffect(()=>{const _=P=>{const D=P.target;(m==null?void 0:m.contains(D))&&k(P,T)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[C,m,T,k]),v.useEffect(S,[r,S]),ro(m,E),ro(p.content,E),u.jsx(uk,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:qt(s),onThumbPointerUp:qt(i),onThumbPositionChange:S,onThumbPointerDown:qt(a),children:u.jsx(De.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=m.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),j(_))}),onPointerMove:ge(e.onPointerMove,j),onPointerUp:ge(e.onPointerUp,_=>{const P=_.target;P.hasPointerCapture(_.pointerId)&&P.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=w.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),Si="ScrollAreaThumb",Tp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Cp(Si,e.__scopeScrollArea);return u.jsx(Sn,{present:n||o.hasThumb,children:u.jsx(dk,{ref:t,...r})})}),dk=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=En(Si,n),i=Cp(Si,n),{onThumbPositionChange:a}=i,l=Ze(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ti(()=>{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=pk(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:ge(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:ge(e.onPointerUp,i.onThumbPointerUp)})});Tp.displayName=Si;var Ol="ScrollAreaCorner",Ep=v.forwardRef((e,t)=>{const n=En(Ol,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(fk,{...e,ref:t}):null});Ep.displayName=Ol;var fk=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=En(Ol,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return ro(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),ro(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 Ci(e){return e?parseInt(e,10):0}function Ip(e,t){const n=e/t;return isNaN(n)?0:n}function ki(e){const t=Ip(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function hk(e,t,n,r="ltr"){const o=ki(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 Ap([l,c],f)(e)}function Np(e,t,n="ltr"){const r=ki(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=_l(e,l);return Ap([0,i],[0,a])(c)}function Ap(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 _p(e,t){return e>0&&e<t}var pk=(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 Ti(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 ro(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 jp=vp,mk=bp,gk=Ep;const Pp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(jp,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(mk,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Rp,{}),u.jsx(gk,{})]}));Pp.displayName=jp.displayName;const Rp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pl,{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(Tp,{className:"relative flex-1 rounded-full bg-border"})}));Rp.displayName=Pl.displayName;const Op=25;function Ml({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:m}=ms(),{loadThread:g}=gs(),{createThread:y,deleteThread:x,renameThread:w}=m,[C,T]=b.useState(Array.isArray(f)?f:[]),k=b.useRef(C.length>0),S=b.useRef(null),E=b.useRef(0),[j,_]=b.useState(null),[P,D]=b.useState(""),[z,B]=b.useState(!1);b.useEffect(()=>{const J=Array.isArray(f)?f:[];if(J.length>0){k.current=!0,T(J);return}p||(k.current=!1,T(J))},[f,p]),b.useEffect(()=>{if(!S.current)return;const J=S.current.querySelector("[data-radix-scroll-area-viewport]");if(!J)return;let ue=null,ke=null;return ue=requestAnimationFrame(()=>{ke=requestAnimationFrame(()=>{J.scrollTop=E.current})}),()=>{ue!==null&&cancelAnimationFrame(ue),ke!==null&&cancelAnimationFrame(ke)}},[C]);const O=async J=>{try{await g(J),a==null||a(J),l==null||l(J)}catch(ue){console.error("Failed to select thread:",ue)}},H=async()=>{try{B(!0);const J=await y();c==null||c(J),a==null||a(J)}catch(J){console.error("Failed to create thread:",J)}finally{B(!1)}},R=async(J,ue)=>{if(ue.stopPropagation(),!!confirm("Delete this thread?")){if(S.current){const ke=S.current.querySelector("[data-radix-scroll-area-viewport]");ke&&(E.current=ke.scrollTop)}try{await x(J),d==null||d(J)}catch(ke){console.error("Failed to delete thread:",ke)}}},V=(J,ue)=>{ue.stopPropagation(),_(J.threadId),D(J.title||`Thread ${J.threadId.slice(0,8)}`)},$=async J=>{if(P.trim())try{await w(J,P.trim()),_(null),D("")}catch(ue){console.error("Failed to update title:",ue)}},F=()=>{_(null),D("")},ne=(J,ue)=>{J.key==="Enter"?$(ue):J.key==="Escape"&&F()},Q=J=>{if(!J)return"";try{const ue=new Date(J),te=new Date().getTime()-ue.getTime(),L=Math.floor(te/(1e3*60*60*24));return L===0?ue.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):L===1?"Yesterday":L<7?`${L} days ago`:ue.toLocaleDateString()}catch{return""}},ye=J=>J.title||`Thread ${J.threadId.slice(0,8)}`,je=J=>{const ue=ye(J);return ue.length<=Op?ue:`${ue.slice(0,Op)}...`};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:H,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(Pp,{ref:S,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…"})]}):C.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"})]}):C.slice().sort((J,ue)=>new Date(ue.updatedAt||ue.createdAt||"").getTime()-new Date(J.updatedAt||J.createdAt||"").getTime()).map(J=>u.jsxs("div",{onClick:()=>O(J.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===J.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:j===J.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ue=>ue.stopPropagation(),children:[u.jsx(bi,{value:P,onChange:ue=>D(ue.target.value),onKeyDown:ue=>ne(ue,J.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(ut,{variant:"ghost",size:"sm",onClick:()=>$(J.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:je(J)}),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:Q(J.updatedAt||J.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&j!==J.threadId&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:ue=>V(J,ue),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:ue=>R(J.threadId,ue),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===J.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},J.threadId))})})]})}function oo(e){if(!(typeof globalThis>"u"))return globalThis[e]}function yk(e){if(typeof e!="string")return;const t=e.trim();if(t)return Zn(t)}function Mp(){const e=[oo("__API_BASE_URL__"),oo("__CHAT_API_BASE_URL__"),oo("__CHAT_API_URL__")];for(const t of e){const n=yk(t);if(n)return n}}function Dp(){const e=[oo("__API_AUTH_TOKEN__"),oo("__CHAT_API_KEY__"),oo("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Lp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Zn(t);return Zn()}function Fp(){const e={},t=Mp(),n=Dp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function $p(){const e=Fp(),t=sr.getAuthToken(),n=Mp();return{apiBaseUrl:Lp(e.baseUrl,sr.baseUrl,n),apiKey:t||e.apiKey||Dp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const zp="chat-settings";function xk(){try{const e=localStorage.getItem(zp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function vk(e){try{const t={...e,apiBaseUrl:Zn(e.apiBaseUrl)};localStorage.setItem(zp,JSON.stringify(t)),t.apiKey&&sr.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function wk(){const e=$p(),t=xk(),n=sr.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Lp(sr.baseUrl,r,e.apiBaseUrl)}}function bk(e){sr.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),vk(e)}var Sk="Label",Bp=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())}}));Bp.displayName=Sk;var Hp=Bp;const Ck=Go.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),In=v.forwardRef(({className:e,...t},n)=>u.jsx(Hp,{ref:n,className:oe(Ck(),e),...t}));In.displayName=Hp.displayName;function Up(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 Ei="Switch",[kk,XT]=Qn(Ei),[Tk,Ek]=kk(Ei),Wp=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),m=Ze(t,C=>p(C)),g=v.useRef(!1),y=h?d||!!h.closest("form"):!0,[x,w]=Vr({prop:o,defaultProp:s??!1,onChange:c,caller:Ei});return u.jsxs(Tk,{scope:n,checked:x,disabled:a,children:[u.jsx(De.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Gp(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ge(e.onClick,C=>{w(T=>!T),y&&(g.current=C.isPropagationStopped(),g.current||C.stopPropagation())})}),y&&u.jsx(qp,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Wp.displayName=Ei;var Vp="SwitchThumb",Kp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=Ek(Vp,n);return u.jsx(De.span,{"data-state":Gp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Kp.displayName=Vp;var Ik="SwitchBubbleInput",qp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Ze(i,s),l=Up(n),c=Ju(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 m=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(m)}},[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}})});qp.displayName=Ik;function Gp(e){return e?"checked":"unchecked"}var Yp=Wp,Nk=Kp;const mr=v.forwardRef(({className:e,...t},n)=>u.jsx(Yp,{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(Nk,{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")})}));mr.displayName=Yp.displayName;var Xp=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"}),Ak="VisuallyHidden",_k=v.forwardRef((e,t)=>u.jsx(De.span,{...e,ref:t,style:{...Xp,...e.style}}));_k.displayName=Ak;var jk=[" ","Enter","ArrowUp","ArrowDown"],Pk=[" ","Enter"],Or="Select",[Ii,Ni,Rk]=pa(Or),[so,JT]=Qn(Or,[Rk,js]),Ai=js(),[Ok,gr]=so(Or),[Mk,Dk]=so(Or),Jp=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:m}=e,g=Ai(t),[y,x]=v.useState(null),[w,C]=v.useState(null),[T,k]=v.useState(!1),S=xs(c),[E,j]=Vr({prop:r,defaultProp:o??!1,onChange:s,caller:Or}),[_,P]=Vr({prop:i,defaultProp:a,onChange:l,caller:Or}),D=v.useRef(null),z=y?m||!!y.closest("form"):!0,[B,O]=v.useState(new Set),H=Array.from(B).map(R=>R.props.value).join(";");return u.jsx(ad,{...g,children:u.jsxs(Ok,{required:p,scope:t,trigger:y,onTriggerChange:x,valueNode:w,onValueNodeChange:C,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:er(),value:_,onValueChange:P,open:E,onOpenChange:j,dir:S,triggerPointerDownPosRef:D,disabled:h,children:[u.jsx(Ii.Provider,{scope:t,children:u.jsx(Mk,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(R=>{O(V=>new Set(V).add(R))},[]),onNativeOptionRemove:v.useCallback(R=>{O(V=>{const $=new Set(V);return $.delete(R),$})},[]),children:n})}),z?u.jsxs(bm,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:R=>P(R.target.value),disabled:h,form:m,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(B)]},H):null]})})};Jp.displayName=Or;var Zp="SelectTrigger",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ai(n),i=gr(Zp,n),a=i.disabled||r,l=Ze(t,i.onTriggerChange),c=Ni(n),d=v.useRef("touch"),[f,h,p]=Cm(g=>{const y=c().filter(C=>!C.disabled),x=y.find(C=>C.value===i.value),w=km(y,g,x);w!==void 0&&i.onValueChange(w.value)}),m=g=>{a||(i.onOpenChange(!0),p()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ld,{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":Sm(i.value)?"":void 0,...o,ref:l,onClick:ge(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&m(g)}),onPointerDown:ge(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(m(g),g.preventDefault())}),onKeyDown:ge(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&h(g.key),!(y&&g.key===" ")&&jk.includes(g.key)&&(m(),g.preventDefault())})})})});Qp.displayName=Zp;var em="SelectValue",tm=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=gr(em,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Ze(t,l.onValueNodeChange);return Kt(()=>{c(d)},[c,d]),u.jsx(De.span,{...a,ref:f,style:{pointerEvents:"none"},children:Sm(l.value)?u.jsx(u.Fragment,{children:i}):s})});tm.displayName=em;var Lk="SelectIcon",nm=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(De.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});nm.displayName=Lk;var Fk="SelectPortal",rm=e=>u.jsx(Ps,{asChild:!0,...e});rm.displayName=Fk;var Mr="SelectContent",om=v.forwardRef((e,t)=>{const n=gr(Mr,e.__scopeSelect),[r,o]=v.useState();if(Kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Yo.createPortal(u.jsx(sm,{scope:e.__scopeSelect,children:u.jsx(Ii.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(im,{...e,ref:t})});om.displayName=Mr;var Dn=10,[sm,yr]=so(Mr),$k="SelectContentImpl",zk=vr.createSlot("SelectContent.RemoveScroll"),im=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:m,hideWhenDetached:g,avoidCollisions:y,...x}=e,w=gr(Mr,n),[C,T]=v.useState(null),[k,S]=v.useState(null),E=Ze(t,te=>T(te)),[j,_]=v.useState(null),[P,D]=v.useState(null),z=Ni(n),[B,O]=v.useState(!1),H=v.useRef(!1);v.useEffect(()=>{if(C)return Da(C)},[C]),ya();const R=v.useCallback(te=>{const[L,...q]=z().map(U=>U.ref.current),[ie]=q.slice(-1),ce=document.activeElement;for(const U of te)if(U===ce||(U==null||U.scrollIntoView({block:"nearest"}),U===L&&k&&(k.scrollTop=0),U===ie&&k&&(k.scrollTop=k.scrollHeight),U==null||U.focus(),document.activeElement!==ce))return},[z,k]),V=v.useCallback(()=>R([j,C]),[R,j,C]);v.useEffect(()=>{B&&V()},[B,V]);const{onOpenChange:$,triggerPointerDownPosRef:F}=w;v.useEffect(()=>{if(C){let te={x:0,y:0};const L=ie=>{var ce,U;te={x:Math.abs(Math.round(ie.pageX)-(((ce=F.current)==null?void 0:ce.x)??0)),y:Math.abs(Math.round(ie.pageY)-(((U=F.current)==null?void 0:U.y)??0))}},q=ie=>{te.x<=10&&te.y<=10?ie.preventDefault():C.contains(ie.target)||$(!1),document.removeEventListener("pointermove",L),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",q,{capture:!0})}}},[C,$,F]),v.useEffect(()=>{const te=()=>$(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[$]);const[ne,Q]=Cm(te=>{const L=z().filter(ce=>!ce.disabled),q=L.find(ce=>ce.ref.current===document.activeElement),ie=km(L,te,q);ie&&setTimeout(()=>ie.ref.current.focus())}),ye=v.useCallback((te,L,q)=>{const ie=!H.current&&!q;(w.value!==void 0&&w.value===L||ie)&&(_(te),ie&&(H.current=!0))},[w.value]),je=v.useCallback(()=>C==null?void 0:C.focus(),[C]),J=v.useCallback((te,L,q)=>{const ie=!H.current&&!q;(w.value!==void 0&&w.value===L||ie)&&D(te)},[w.value]),ue=r==="popper"?Dl:am,ke=ue===Dl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(sm,{scope:n,content:C,viewport:k,onViewportChange:S,itemRefCallback:ye,selectedItem:j,onItemLeave:je,itemTextRefCallback:J,focusSelectedItem:V,selectedItemText:P,position:r,isPositioned:B,searchRef:ne,children:u.jsx(Bs,{as:zk,allowPinchZoom:!0,children:u.jsx(ws,{asChild:!0,trapped:w.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:ge(o,te=>{var L;(L=w.trigger)==null||L.focus({preventScroll:!0}),te.preventDefault()}),children:u.jsx(vs,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(ue,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:te=>te.preventDefault(),...x,...ke,onPlaced:()=>O(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ge(x.onKeyDown,te=>{const L=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!L&&te.key.length===1&&Q(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let ie=z().filter(ce=>!ce.disabled).map(ce=>ce.ref.current);if(["ArrowUp","End"].includes(te.key)&&(ie=ie.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const ce=te.target,U=ie.indexOf(ce);ie=ie.slice(U+1)}setTimeout(()=>R(ie)),te.preventDefault()}})})})})})})});im.displayName=$k;var Bk="SelectItemAlignedPosition",am=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=gr(Mr,n),i=yr(Mr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Ze(t,E=>d(E)),h=Ni(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:w}=i,C=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),P=x.getBoundingClientRect();if(s.dir!=="rtl"){const ce=P.left-j.left,U=_.left-ce,We=E.left-U,re=E.width+We,xe=Math.max(re,j.width),Pe=window.innerWidth-Dn,$e=_l(U,[Dn,Math.max(Dn,Pe-xe)]);a.style.minWidth=re+"px",a.style.left=$e+"px"}else{const ce=j.right-P.right,U=window.innerWidth-_.right-ce,We=window.innerWidth-E.right-U,re=E.width+We,xe=Math.max(re,j.width),Pe=window.innerWidth-Dn,$e=_l(U,[Dn,Math.max(Dn,Pe-xe)]);a.style.minWidth=re+"px",a.style.right=$e+"px"}const D=h(),z=window.innerHeight-Dn*2,B=g.scrollHeight,O=window.getComputedStyle(c),H=parseInt(O.borderTopWidth,10),R=parseInt(O.paddingTop,10),V=parseInt(O.borderBottomWidth,10),$=parseInt(O.paddingBottom,10),F=H+R+B+$+V,ne=Math.min(y.offsetHeight*5,F),Q=window.getComputedStyle(g),ye=parseInt(Q.paddingTop,10),je=parseInt(Q.paddingBottom,10),J=E.top+E.height/2-Dn,ue=z-J,ke=y.offsetHeight/2,te=y.offsetTop+ke,L=H+R+te,q=F-L;if(L<=J){const ce=D.length>0&&y===D[D.length-1].ref.current;a.style.bottom="0px";const U=c.clientHeight-g.offsetTop-g.offsetHeight,We=Math.max(ue,ke+(ce?je:0)+U+V),re=L+We;a.style.height=re+"px"}else{const ce=D.length>0&&y===D[0].ref.current;a.style.top="0px";const We=Math.max(J,H+g.offsetTop+(ce?ye:0)+ke)+q;a.style.height=We+"px",g.scrollTop=L-J+g.offsetTop}a.style.margin=`${Dn}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,g,y,x,s.dir,r]);Kt(()=>C(),[C]);const[T,k]=v.useState();Kt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const S=v.useCallback(E=>{E&&m.current===!0&&(C(),w==null||w(),m.current=!1)},[C,w]);return u.jsx(Uk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:S,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}})})})});am.displayName=Bk;var Hk="SelectPopperPosition",Dl=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Dn,...s}=e,i=Ai(n);return u.jsx(cd,{...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)"}})});Dl.displayName=Hk;var[Uk,Ll]=so(Mr,{}),Fl="SelectViewport",lm=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=yr(Fl,n),i=Ll(Fl,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(Ii.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: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 m=window.innerHeight-Dn*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<m){const w=x+p,C=Math.min(m,w),T=w-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});lm.displayName=Fl;var cm="SelectGroup",[Wk,Vk]=so(cm),Kk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=er();return u.jsx(Wk,{scope:n,id:o,children:u.jsx(De.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Kk.displayName=cm;var um="SelectLabel",dm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vk(um,n);return u.jsx(De.div,{id:o.id,...r,ref:t})});dm.displayName=um;var _i="SelectItem",[qk,fm]=so(_i),hm=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=gr(_i,n),l=yr(_i,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),m=Ze(t,w=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,w,r,o)}),g=er(),y=v.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(qk,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:v.useCallback(w=>{f(C=>C||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(Ii.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(De.div,{role:"option","aria-labelledby":g,"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:m,onFocus:ge(i.onFocus,()=>p(!0)),onBlur:ge(i.onBlur,()=>p(!1)),onClick:ge(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:ge(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:ge(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:ge(i.onPointerMove,w=>{var C;y.current=w.pointerType,o?(C=l.onItemLeave)==null||C.call(l):y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ge(i.onPointerLeave,w=>{var C;w.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:ge(i.onKeyDown,w=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&w.key===" "||(Pk.includes(w.key)&&x(),w.key===" "&&w.preventDefault())})})})})});hm.displayName=_i;var Vo="SelectItemText",pm=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=gr(Vo,n),a=yr(Vo,n),l=fm(Vo,n),c=Dk(Vo,n),[d,f]=v.useState(null),h=Ze(t,x=>f(x),l.onItemTextChange,x=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return Kt(()=>(g(m),()=>y(m)),[g,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(De.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Yo.createPortal(s.children,i.valueNode):null]})});pm.displayName=Vo;var mm="SelectItemIndicator",gm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return fm(mm,n).isSelected?u.jsx(De.span,{"aria-hidden":!0,...r,ref:t}):null});gm.displayName=mm;var $l="SelectScrollUpButton",ym=v.forwardRef((e,t)=>{const n=yr($l,e.__scopeSelect),r=Ll($l,e.__scopeSelect),[o,s]=v.useState(!1),i=Ze(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(vm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ym.displayName=$l;var zl="SelectScrollDownButton",xm=v.forwardRef((e,t)=>{const n=yr(zl,e.__scopeSelect),r=Ll(zl,e.__scopeSelect),[o,s]=v.useState(!1),i=Ze(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(vm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});xm.displayName=zl;var vm=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=yr("SelectScrollButton",n),i=v.useRef(null),a=Ni(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(De.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()})})}),Gk="SelectSeparator",wm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(De.div,{"aria-hidden":!0,...r,ref:t})});wm.displayName=Gk;var Bl="SelectArrow",Yk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ai(n),s=gr(Bl,n),i=yr(Bl,n);return s.open&&i.position==="popper"?u.jsx(ud,{...o,...r,ref:t}):null});Yk.displayName=Bl;var Xk="SelectBubbleInput",bm=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Ze(r,o),i=Up(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:{...Xp,...n.style},ref:s,defaultValue:t})});bm.displayName=Xk;function Sm(e){return e===""||e===void 0}function Cm(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 km(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=Jk(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 Jk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Zk=Jp,Tm=Qp,Qk=tm,eT=nm,tT=rm,Em=om,nT=lm,Im=dm,Nm=hm,rT=pm,oT=gm,Am=ym,_m=xm,jm=wm;const Pm=Zk,Rm=Qk,Hl=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Tm,{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(eT,{asChild:!0,children:u.jsx(he.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Hl.displayName=Tm.displayName;const Om=v.forwardRef(({className:e,...t},n)=>u.jsx(Am,{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"})}));Om.displayName=Am.displayName;const Mm=v.forwardRef(({className:e,...t},n)=>u.jsx(_m,{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"})}));Mm.displayName=_m.displayName;const Ul=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(tT,{children:u.jsxs(Em,{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(Om,{}),u.jsx(nT,{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(Mm,{})]})}));Ul.displayName=Em.displayName;const sT=v.forwardRef(({className:e,...t},n)=>u.jsx(Im,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));sT.displayName=Im.displayName;const Dr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Nm,{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(oT,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),u.jsx(rT,{children:t})]}));Dr.displayName=Nm.displayName;const iT=v.forwardRef(({className:e,...t},n)=>u.jsx(jm,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));iT.displayName=jm.displayName;var aT="Separator",Dm="horizontal",lT=["horizontal","vertical"],Lm=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Dm,...o}=e,s=cT(r)?r:Dm,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})});Lm.displayName=aT;function cT(e){return lT.includes(e)}var Fm=Lm;const $m=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Fm,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));$m.displayName=Fm.displayName;const uT=qh,dT=EC,fT=Gh,zm=v.forwardRef(({className:e,...t},n)=>u.jsx(fi,{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}));zm.displayName=fi.displayName;const hT=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"}}),Bm=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(fT,{children:[u.jsx(zm,{}),u.jsxs(hi,{ref:o,className:oe(hT({side:e}),t),...r,children:[n,u.jsxs(Yh,{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"})]})]})]}));Bm.displayName=hi.displayName;const Hm=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});Hm.displayName="SheetHeader";const Um=v.forwardRef(({className:e,...t},n)=>u.jsx(Pr,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));Um.displayName=Pr.displayName;const Wm=v.forwardRef(({className:e,...t},n)=>u.jsx(pi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Wm.displayName=pi.displayName;const pT={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 mT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,d]=b.useState(!1),{toast:f}=bl();b.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),b.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(pT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(uT,{open:r,onOpenChange:o,children:[u.jsx(dT,{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(kh,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Bm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Hm,{children:[u.jsx(Um,{children:"Chat Settings"}),u.jsx(Wm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(In,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(bi,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(x=>({...x,api:{...x.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(ut,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(In,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(mr,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(x=>({...x,api:{...x.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(In,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(bi,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(x=>({...x,api:{...x.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(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(In,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Pm,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Hl,{children:u.jsx(Rm,{})}),u.jsxs(Ul,{children:[u.jsx(Dr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(Dr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(Dr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(In,{htmlFor:"theme",children:"Theme"}),u.jsxs(Pm,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Hl,{children:u.jsx(Rm,{})}),u.jsxs(Ul,{children:[u.jsx(Dr,{value:"light",children:"Light"}),u.jsx(Dr,{value:"dark",children:"Dark"}),u.jsx(Dr,{value:"system",children:"System"})]})]})]}),u.jsx($m,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(In,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(mr,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(In,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(mr,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(In,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(mr,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(In,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(mr,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(In,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(mr,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(In,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(mr,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(x=>({...x,behavior:{...x.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:m,children:"Cancel"}),u.jsxs(ut,{onClick:h,disabled:!c,children:[u.jsx(he.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function gT({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=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(ys,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(wi,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(ys,{...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(Ml,{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(wi,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(ys,{...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(Ml,{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(wi,{onError:s.onError,enableFileUpload:!0})})]})})}Ae.ChatApi=Bc,Ae.ChatInput=mu,Ae.ChatInterface=wi,Ae.ChatProviders=ys,Ae.ChatSettings=mT,Ae.MarkdownContent=Wo,Ae.MessageComponent=Nl,Ae.MessageList=Al,Ae.ThreadManager=Ml,Ae.applySettings=bk,Ae.chatApiClient=sr,Ae.default=gT,Ae.del=zc,Ae.get=wn,Ae.getChatToken=Dc,Ae.getCurrentSettings=wk,Ae.getDefaultApiConfig=Fp,Ae.getDefaultChatSettings=$p,Ae.onChatTokenChanged=Lc,Ae.post=Yi,Ae.put=$c,Ae.registerChatTokenSyncHandler=ky,Ae.setChatToken=Gi,Ae.useApi=Xi,Ae.useChatStream=nu,Ae.useMessagesReducer=Gc,Ae.useStream=hu,Ae.useThreadState=gs,Ae.useThreads=ms,Object.defineProperties(Ae,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});