teodor-new-chat-ui 4.3.152 → 4.3.154
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.esm.js +4014 -4026
- package/dist/index.umd.js +40 -40
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(_e,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],w):(_e=typeof globalThis<"u"?globalThis:_e||self,w(_e.NewChatUI={},_e.React,_e.LucideReact,_e.reactSlot,_e.classVarianceAuthority,_e.clsx,_e.tailwindMerge,_e.ReactDOM))})(this,function(_e,w,he,br,Go,Qm,eg,Ri){"use strict";var vT=Object.defineProperty;var wT=(_e,w,he)=>w in _e?vT(_e,w,{enumerable:!0,configurable:!0,writable:!0,value:he}):_e[w]=he;var Jm=(_e,w,he)=>wT(_e,typeof w!="symbol"?w+"":w,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(w),Yo=Kl(Ri);var Oi={exports:{}},uo={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ql;function
|
|
9
|
+
*/var ql;function tg(){if(ql)return uo;ql=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},h=null,p=null;c!==void 0&&(h=""+c),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return uo.Fragment=n,uo.jsx=i,uo.jsxs=i,uo}var fo={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,29 +14,29 @@
|
|
|
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
|
|
18
|
-
`+te+N}}var
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var Gl;function ng(){return Gl||(Gl=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),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 b(N){{for(var q=arguments.length,ue=new Array(q>1?q-1:0),ke=1;ke<q;ke++)ue[ke-1]=arguments[ke];C("error",N,ue)}}function C(N,q,ue){{var ke=x.ReactDebugCurrentFrame,qe=ke.getStackAddendum();qe!==""&&(q+="%s",ue=ue.concat([qe]));var tt=ue.map(function(Fe){return String(Fe)});tt.unshift("Warning: "+q),Function.prototype.apply.call(console[N],console,tt)}}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,ue){var ke=N.displayName;if(ke)return ke;var qe=q.displayName||q.name||"";return qe!==""?ue+"("+qe+")":ue}function z(N){return N.displayName||"Context"}function B(N){if(N==null)return null;if(typeof N.tag=="number"&&b("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 ue=N;return z(ue._context)+".Provider";case l:return D(N,N.render,"ForwardRef");case f:var ke=N.displayName||null;return ke!==null?ke:B(N.type)||"Memo";case h:{var qe=N,tt=qe._payload,Fe=qe._init;try{return B(Fe(tt))}catch{return null}}}return null}var O=Object.assign,H=0,R,V,$,F,ne,Q,ye;function Pe(){}Pe.__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:Pe,writable:!0};Object.defineProperties(console,{info:N,log:N,warn:N,error:N,group:N,groupCollapsed:N,groupEnd:N})}H++}}function ce(){{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&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Ce=x.ReactCurrentDispatcher,te;function L(N,q,ue){{if(te===void 0)try{throw Error()}catch(qe){var ke=qe.stack.trim().match(/\n( *(at )?)/);te=ke&&ke[1]||""}return`
|
|
18
|
+
`+te+N}}var G=!1,se;{var ae=typeof WeakMap=="function"?WeakMap:Map;se=new ae}function U(N,q){if(!N||G)return"";{var ue=se.get(N);if(ue!==void 0)return ue}var ke;G=!0;var qe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var tt;tt=Ce.current,Ce.current=null,J();try{if(q){var Fe=function(){throw Error()};if(Object.defineProperty(Fe.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Fe,[])}catch(Wt){ke=Wt}Reflect.construct(N,[],Fe)}else{try{Fe.call()}catch(Wt){ke=Wt}N.call(Fe.prototype)}}else{try{throw Error()}catch(Wt){ke=Wt}N()}}catch(Wt){if(Wt&&ke&&typeof Wt.stack=="string"){for(var ze=Wt.stack.split(`
|
|
19
|
+
`),Ct=ke.stack.split(`
|
|
20
|
+
`),wt=ze.length-1,ct=Ct.length-1;wt>=1&&ct>=0&&ze[wt]!==Ct[ct];)ct--;for(;wt>=1&&ct>=0;wt--,ct--)if(ze[wt]!==Ct[ct]){if(wt!==1||ct!==1)do if(wt--,ct--,ct<0||ze[wt]!==Ct[ct]){var Ft=`
|
|
21
|
+
`+ze[wt].replace(" at new "," at ");return N.displayName&&Ft.includes("<anonymous>")&&(Ft=Ft.replace("<anonymous>",N.displayName)),typeof N=="function"&&se.set(N,Ft),Ft}while(wt>=1&&ct>=0);break}}}finally{G=!1,Ce.current=tt,ce(),Error.prepareStackTrace=qe}var hn=N?N.displayName||N.name:"",Fn=hn?L(hn):"";return typeof N=="function"&&se.set(N,Fn),Fn}function Ue(N,q,ue){return U(N,!1)}function re(N){var q=N.prototype;return!!(q&&q.isReactComponent)}function xe(N,q,ue){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 Ue(N.render);case f:return xe(N.type,q,ue);case h:{var ke=N,qe=ke._payload,tt=ke._init;try{return xe(tt(qe),q,ue)}catch{}}}return""}var Re=Object.prototype.hasOwnProperty,Le={},nt=x.ReactDebugCurrentFrame;function Se(N){if(N){var q=N._owner,ue=xe(N.type,N._source,q?q.type:null);nt.setExtraStackFrame(ue)}else nt.setExtraStackFrame(null)}function Ge(N,q,ue,ke,qe){{var tt=Function.call.bind(Re);for(var Fe in N)if(tt(N,Fe)){var ze=void 0;try{if(typeof N[Fe]!="function"){var Ct=Error((ke||"React class")+": "+ue+" type `"+Fe+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof N[Fe]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Ct.name="Invariant Violation",Ct}ze=N[Fe](q,Fe,ke,ue,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(wt){ze=wt}ze&&!(ze instanceof Error)&&(Se(qe),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",ke||"React class",ue,Fe,typeof ze),Se(null)),ze instanceof Error&&!(ze.message in Le)&&(Le[ze.message]=!0,Se(qe),b("Failed %s type: %s",ue,ze.message),Se(null))}}}var rt=Array.isArray;function Qe(N){return rt(N)}function Ye(N){{var q=typeof Symbol=="function"&&Symbol.toStringTag,ue=q&&N[Symbol.toStringTag]||N.constructor.name||"Object";return ue}}function Ke(N){try{return et(N),!1}catch{return!0}}function et(N){return""+N}function Dt(N){if(Ke(N))return b("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 St=x.ReactCurrentOwner,ft={key:!0,ref:!0,__self:!0,__source:!0},gt,ht;function ot(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 on(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 sn(N,q){typeof N.ref=="string"&&St.current}function Kt(N,q){{var ue=function(){gt||(gt=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",q))};ue.isReactWarning=!0,Object.defineProperty(N,"key",{get:ue,configurable:!0})}}function Bt(N,q){{var ue=function(){ht||(ht=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",q))};ue.isReactWarning=!0,Object.defineProperty(N,"ref",{get:ue,configurable:!0})}}var pt=function(N,q,ue,ke,qe,tt,Fe){var ze={$$typeof:t,type:N,key:q,ref:ue,props:Fe,_owner:tt};return ze._store={},Object.defineProperty(ze._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ze,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ke}),Object.defineProperty(ze,"_source",{configurable:!1,enumerable:!1,writable:!1,value:qe}),Object.freeze&&(Object.freeze(ze.props),Object.freeze(ze)),ze};function We(N,q,ue,ke,qe){{var tt,Fe={},ze=null,Ct=null;ue!==void 0&&(Dt(ue),ze=""+ue),on(q)&&(Dt(q.key),ze=""+q.key),ot(q)&&(Ct=q.ref,sn(q,qe));for(tt in q)Re.call(q,tt)&&!ft.hasOwnProperty(tt)&&(Fe[tt]=q[tt]);if(N&&N.defaultProps){var wt=N.defaultProps;for(tt in wt)Fe[tt]===void 0&&(Fe[tt]=wt[tt])}if(ze||Ct){var ct=typeof N=="function"?N.displayName||N.name||"Unknown":N;ze&&Kt(Fe,ct),Ct&&Bt(Fe,ct)}return pt(N,ze,Ct,qe,ke,St.current,Fe)}}var Lt=x.ReactCurrentOwner,_t=x.ReactDebugCurrentFrame;function Y(N){if(N){var q=N._owner,ue=xe(N.type,N._source,q?q.type:null);_t.setExtraStackFrame(ue)}else _t.setExtraStackFrame(null)}var Ee;Ee=!1;function ve(N){return typeof N=="object"&&N!==null&&N.$$typeof===t}function it(){{if(Lt.current){var N=B(Lt.current.type);if(N)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+N+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+N+"`."}return""}}function yt(N){return""}var It={};function Ne(N){{var q=it();if(!q){var ue=typeof N=="string"?N:N.displayName||N.name;ue&&(q=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+ue+">.")}return q}}function Ut(N,q){{if(!N._store||N._store.validated||N.key!=null)return;N._store.validated=!0;var ue=Ne(q);if(It[ue])return;It[ue]=!0;var ke="";N&&N._owner&&N._owner!==Lt.current&&(ke=" It was passed a child from "+B(N._owner.type)+"."),Y(N),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ue,ke),Y(null)}}function at(N,q){{if(typeof N!="object")return;if(Qe(N))for(var ue=0;ue<N.length;ue++){var ke=N[ue];ve(ke)&&Ut(ke,q)}else if(ve(N))N._store&&(N._store.validated=!0);else if(N){var qe=y(N);if(typeof qe=="function"&&qe!==N.entries)for(var tt=qe.call(N),Fe;!(Fe=tt.next()).done;)ve(Fe.value)&&Ut(Fe.value,q)}}}function At(N){{var q=N.type;if(q==null||typeof q=="string")return;var ue;if(typeof q=="function")ue=q.propTypes;else if(typeof q=="object"&&(q.$$typeof===l||q.$$typeof===f))ue=q.propTypes;else return;if(ue){var ke=B(q);Ge(ue,N.props,"prop",ke,N)}else if(q.PropTypes!==void 0&&!Ee){Ee=!0;var qe=B(q);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",qe||"Unknown")}typeof q.getDefaultProps=="function"&&!q.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function An(N){{for(var q=Object.keys(N.props),ue=0;ue<q.length;ue++){var ke=q[ue];if(ke!=="children"&&ke!=="key"){Y(N),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ke),Y(null);break}}N.ref!==null&&(Y(N),b("Invalid attribute `ref` supplied to `React.Fragment`."),Y(null))}}var jt={};function an(N,q,ue,ke,qe,tt){{var Fe=P(N);if(!Fe){var ze="";(N===void 0||typeof N=="object"&&N!==null&&Object.keys(N).length===0)&&(ze+=" 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 Ct=yt();Ct?ze+=Ct:ze+=it();var wt;N===null?wt="null":Qe(N)?wt="array":N!==void 0&&N.$$typeof===t?(wt="<"+(B(N.type)||"Unknown")+" />",ze=" Did you accidentally export a JSX literal instead of a component?"):wt=typeof N,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",wt,ze)}var ct=We(N,q,ue,qe,tt);if(ct==null)return ct;if(Fe){var Ft=q.children;if(Ft!==void 0)if(ke)if(Qe(Ft)){for(var hn=0;hn<Ft.length;hn++)at(Ft[hn],N);Object.freeze&&Object.freeze(Ft)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else at(Ft,N)}if(Re.call(q,"key")){var Fn=B(N),Wt=Object.keys(q).filter(function(le){return le!=="key"}),xr=Wt.length>0?"{key: someKey, "+Wt.join(": ..., ")+": ...}":"{key: someKey}";if(!jt[Fn+xr]){var Z=Wt.length>0?"{"+Wt.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,$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]&&
|
|
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 :
|
|
30
|
+
<%s key={someKey} {...props} />`,xr,Fn,Z,Fn),jt[Fn+xr]=!0}}return N===r?An(ct):At(ct),ct}}function io(N,q,ue){return an(N,q,ue,!0)}function qt(N,q,ue){return an(N,q,ue,!1)}var nr=qt,ao=io;fo.Fragment=r,fo.jsx=nr,fo.jsxs=ao}()),fo}process.env.NODE_ENV==="production"?Oi.exports=tg():Oi.exports=ng();var u=Oi.exports;function Yl(e,t){return function(){return e.apply(t,arguments)}}const{toString:rg}=Object.prototype,{getPrototypeOf:Mi}=Object,{iterator:Xo,toStringTag:Xl}=Symbol,Jo=(e=>t=>{const n=rg.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),jn=e=>(e=e.toLowerCase(),t=>Jo(t)===e),Zo=e=>t=>typeof t===e,{isArray:Br}=Array,Hr=Zo("undefined");function ho(e){return e!==null&&!Hr(e)&&e.constructor!==null&&!Hr(e.constructor)&&ln(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Jl=jn("ArrayBuffer");function og(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Jl(e.buffer),t}const sg=Zo("string"),ln=Zo("function"),Zl=Zo("number"),po=e=>e!==null&&typeof e=="object",ig=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)},ag=e=>{if(!po(e)||ho(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},lg=jn("Date"),cg=jn("File"),ug=jn("Blob"),dg=jn("FileList"),fg=e=>po(e)&&ln(e.pipe),hg=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||ln(e.append)&&((t=Jo(e))==="formdata"||t==="object"&&ln(e.toString)&&e.toString()==="[object FormData]"))},pg=jn("URLSearchParams"),[mg,gg,yg,xg]=["ReadableStream","Request","Response","Headers"].map(jn),vg=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function mo(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(ho(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(ho(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 Sr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,ec=e=>!Hr(e)&&e!==Sr;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]&&mo(arguments[o],r);return n}const wg=(e,t,n,{allOwnKeys:r}={})=>(mo(t,(o,s)=>{n&&ln(o)?e[s]=Yl(o,n):e[s]=o},{allOwnKeys:r}),e),bg=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Sg=(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)},Cg=(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},kg=(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},Tg=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},Eg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Mi(Uint8Array)),Ig=(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])}},Ng=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Ag=jn("HTMLFormElement"),_g=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),jg=jn("RegExp"),nc=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};mo(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Pg=e=>{nc(e,(t,n)=>{if(ln(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(ln(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+"'")})}})},Rg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Br(e)?r(e):r(String(e).split(t)),n},Og=()=>{},Mg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Dg(e){return!!(e&&ln(e.append)&&e[Xl]==="FormData"&&e[Xo])}const Lg=e=>{const t=new Array(10),n=(r,o)=>{if(po(r)){if(t.indexOf(r)>=0)return;if(ho(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Br(r)?[]:{};return mo(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)},Fg=jn("AsyncFunction"),$g=e=>e&&(po(e)||ln(e))&&ln(e.then)&&ln(e.catch),rc=((e,t)=>e?setImmediate:t?((n,r)=>(Sr.addEventListener("message",({source:o,data:s})=>{o===Sr&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Sr.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",ln(Sr.postMessage)),zg=typeof queueMicrotask<"u"?queueMicrotask.bind(Sr):typeof process<"u"&&process.nextTick||rc,M={isArray:Br,isArrayBuffer:Jl,isBuffer:ho,isFormData:hg,isArrayBufferView:og,isString:sg,isNumber:Zl,isBoolean:ig,isObject:po,isPlainObject:Qo,isEmptyObject:ag,isReadableStream:mg,isRequest:gg,isResponse:yg,isHeaders:xg,isUndefined:Hr,isDate:lg,isFile:cg,isBlob:ug,isRegExp:jg,isFunction:ln,isStream:fg,isURLSearchParams:pg,isTypedArray:Eg,isFileList:dg,forEach:mo,merge:Di,extend:wg,trim:vg,stripBOM:bg,inherits:Sg,toFlatObject:Cg,kindOf:Jo,kindOfTest:jn,endsWith:kg,toArray:Tg,forEachEntry:Ig,matchAll:Ng,isHTMLForm:Ag,hasOwnProperty:tc,hasOwnProp:tc,reduceDescriptors:nc,freezeMethods:Pg,toObjectSet:Rg,toCamelCase:_g,noop:Og,toFiniteNumber:Mg,findKey:Ql,global:Sr,isContextDefined:ec,isSpecCompliantForm:Dg,toJSONObject:Lg,isAsyncFn:Fg,isThenable:$g,setImmediate:rc,asap:zg,isIterable:e=>e!=null&&ln(e[Xo])};function De(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(De,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=De.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(De,sc),Object.defineProperty(oc,"isAxiosError",{value:!0}),De.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 De.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 Bg=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 Hg(e){return M.isArray(e)&&!e.some(Li)}const Ug=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 De("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)&&Hg(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(Ug,{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,b){(!(M.isUndefined(x)||x===null)&&o.call(t,x,M.isString(b)?b.trim():b,g,h))===!0&&p(x,g?g.concat(b):[b])}),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 Wg(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||Wg;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},Vg={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,Kg=$i&&(!zi||["ReactNative","NativeScript","NS"].indexOf(zi.product)<0),qg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Gg=$i&&window.location.href||"http://localhost",Zt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:$i,hasStandardBrowserEnv:Kg,hasStandardBrowserWebWorkerEnv:qg,navigator:zi,origin:Gg},Symbol.toStringTag,{value:"Module"})),...Vg};function Yg(e,t){return es(e,new Zt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Zt.isNode&&M.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Xg(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Jg(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]=Jg(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t(Xg(r),o,n,0)}),n}return null}function Zg(e,t,n){if(M.isString(e))try{return(t||JSON.parse)(e),M.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const go={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 Yg(t,this.formSerializer).toString();if((a=M.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return es(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Zg(t)):t}],transformResponse:[function(t){const n=this.transitional||go.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"?De.from(a,De.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:Zt.classes.FormData,Blob:Zt.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=>{go.headers[e]={}});const Qg=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"]),ey=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]&&Qg[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 yo(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 ty(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 ny=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 ry(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function oy(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 cn=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=yo(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())&&!ny(t))i(ey(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=yo(t),t){const r=M.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return ty(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=yo(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=yo(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?ry(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=yo(i);r[a]||(oy(o,i),r[a]=!0)}return M.isArray(t)?t.forEach(s):s(t),this}};cn.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),M.reduceDescriptors(cn.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),M.freezeMethods(cn);function Hi(e,t){const n=this||go,r=t||n,o=cn.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){De.call(this,e??"canceled",De.ERR_CANCELED,t,n),this.name="CanceledError"}M.inherits(Ur,De,{__CANCEL__:!0});function gc(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new De("Request failed with status code "+n.status,[De.ERR_BAD_REQUEST,De.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function sy(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function iy(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 ay(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=iy(50,250);return ay(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)),ly=Zt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Zt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Zt.origin),Zt.navigator&&/(msie|trident)/i.test(Zt.navigator.userAgent)):()=>!0,cy=Zt.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 uy(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function dy(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function vc(e,t,n){let r=!uy(t);return e&&(r||n==!1)?dy(e,t):t}const wc=e=>e instanceof cn?{...e}:e;function Cr(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=Cr({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=cn.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(Zt.hasStandardBrowserEnv||Zt.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(Zt.hasStandardBrowserEnv&&(r&&M.isFunction(r)&&(r=r(t)),r||r!==!1&&ly(t.url))){const l=o&&s&&cy.read(s);l&&i.set(o,l)}return t},fy=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=bc(e);let s=o.data;const i=cn.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=cn.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 De("Request aborted",De.ECONNABORTED,e,y)),y=null)},y.onerror=function(T){const k=T&&T.message?T.message:"Network Error",S=new De(k,De.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 De(T,k.clarifyTimeoutError?De.ETIMEDOUT:De.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 b=sy(o.url);if(b&&Zt.protocols.indexOf(b)===-1){r(new De("Unsupported protocol "+b+":",De.ERR_BAD_REQUEST,e));return}y.send(s||null)})},hy=(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 De?d:new Ur(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new De(`timeout ${t} of ms exceeded`,De.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}},py=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},my=async function*(e,t){for await(const n of gy(e))yield*py(n,t)},gy=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=my(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,yy=(({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}},xy=e=>{e=M.merge.call({skipUndefined:!0},yy,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(Zt.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 De(`Response type '${m}' is not supported`,De.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(Zt.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:b,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=hy([b,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,J]=yc(H,ns(xc(S)));x=Sc(Q.body,Cc,Pe,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(ce=>{Q[ce]=$[ce]});const ye=M.toFiniteNumber($.headers.get("content-length")),[Pe,J]=k&&yc(ye,ns(xc(k),!0))||[];$=new r(Sc($.body,Cc,Pe,()=>{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:cn.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 De("Network Error",De.ERR_NETWORK,m,B),{cause:R.cause||R}):De.from(R,R&&R.code,m,B)}}},vy=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=vy;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:xy(t)),d=c;return c};Ic();const Ui={http:Bg,xhr:fy,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}`,wy=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,!wy(r)&&(o=Ui[(a=String(r)).toLowerCase()],o===void 0))throw new De(`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
|
|
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(`
|
|
34
|
+
`):" "+Nc(i[0]):"as no adapter specified";throw new De("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=cn.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||go.adapter,e)(e).then(function(r){return Wi(e),r.data=Hi.call(e,e.transformResponse,r),r.headers=cn.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=cn.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 De(o(i," has been removed"+(n?" in "+n:"")),De.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 by(e,t,n){if(typeof e!="object")throw new De("options must be an object",De.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 De("option "+s+" must be "+l,De.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new De("Unknown option "+s,De.ERR_BAD_OPTION)}}const ss={assertOptions:by,validators:os},$n=ss.validators;let kr=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=Cr(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ss.assertOptions(r,{silentJSONParsing:$n.transitional($n.boolean),forcedJSONParsing:$n.transitional($n.boolean),clarifyTimeoutError:$n.transitional($n.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:ss.assertOptions(o,{encode:$n.function,serialize:$n.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ss.assertOptions(n,{baseUrl:$n.spelling("baseURL"),withXsrfToken:$n.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=cn.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=Cr(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){kr.prototype[t]=function(n,r){return this.request(Cr(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(Cr(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}kr.prototype[t]=n(),kr.prototype[t+"Form"]=n(!0)});let Sy=class Zm{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new 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 Zm(function(o){t=o}),cancel:t}}};function Cy(e){return function(n){return e.apply(null,n)}}function ky(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 kr(e),n=Yl(kr.prototype.request,t);return M.extend(n,kr.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Rc(Cr(e,o))},n}const Ot=Rc(go);Ot.Axios=kr,Ot.CanceledError=Ur,Ot.CancelToken=Sy,Ot.isCancel=mc,Ot.VERSION=jc,Ot.toFormData=es,Ot.AxiosError=De,Ot.Cancel=Ot.CanceledError,Ot.all=function(t){return Promise.all(t)},Ot.spread=Cy,Ot.isAxiosError=ky,Ot.mergeConfig=Cr,Ot.AxiosHeaders=cn,Ot.formToJSON=e=>hc(M.isHTMLForm(e)?new FormData(e):e),Ot.getAdapter=Ac.getAdapter,Ot.HttpStatusCode=Vi,Ot.default=Ot;const{Axios:IT,AxiosError:NT,CanceledError:AT,isCancel:_T,CancelToken:jT,VERSION:PT,all:RT,Cancel:OT,isAxiosError:MT,spread:DT,toFormData:LT,AxiosHeaders:FT,HttpStatusCode:$T,formToJSON:zT,getAdapter:BT,mergeConfig:HT}=Ot,Oc=typeof window<"u"?window.__API_BASE_URL__:void 0,Mc=Oc?Xn(Oc):void 0;function Xn(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 Ty(e){qi=e}const Ey=3e4,Iy=9e4,wn=Ot.create({...Mc?{baseURL:Mc}:{},timeout:Ey,withCredentials:!0});wn.interceptors.request.use(e=>(is&&(e.headers.Authorization=`Bearer ${is}`),e)),wn.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));async function bn(e,t){return wn.defaults.baseURL?(await wn.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Yi(e,t,n){return wn.defaults.baseURL?(await wn.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fc(e,t,n){return wn.defaults.baseURL?(await wn.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $c(e,t){return wn.defaults.baseURL?(await wn.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Sn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class zc{get baseUrl(){const t=wn.defaults.baseURL;return t?Xn(String(t)):""}updateConfig(t){t.baseUrl&&(wn.defaults.baseURL=Xn(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 bn("/threads"),n=Sn(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 Sn(r)}async updateThread(t,n){const r=await Fc(`/threads/${t}`,{title:n});return Sn(r)}async deleteThread(t){const n=await $c(`/threads/${t}`);return Sn(n)}async threadInfo(t){const n=await bn(`/threads/${t}/info`);return Sn(n)}async listAgents(){const t=await bn("/agents"),n=Sn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await bn(`/agents/${t}`);return Sn(n)}async getAgentSchema(t){const n=await bn(`/agents/${t}/schema`);return Sn(n)}async getState(t){const n=await bn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Sn(n)}async getStateHistory(t){const n=await bn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Iy});return Sn(n)}async cancelRun(t){const n=await Yi("/runs/cancel",{threadId:t});return Sn(n)}async listCheckpointSummaries(t){const n=await bn(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Sn(n);return(r==null?void 0:r.items)??[]}}const sr=new zc,Bc=w.createContext(null);function Ny({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=w.useContext(Bc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Ay(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 _y(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Ay(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const jy={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 as(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!Ji(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Ry(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)=>zy(_,P)).filter(_=>!!_),d=un(e.config),f=un(d==null?void 0:d.configurable),h=$t(f,["checkpoint_id","checkpointId"]),p=$t(f,["checkpoint_ns","checkpointNs"]),m=un(e==null?void 0:e.parentConfig),g=un(m==null?void 0:m.configurable),y=$t(g,["checkpoint_id","checkpointId"])??null,x=$t(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,C=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),T=c[c.length-1]??null,k=un(e==null?void 0:e.metadata),S=$t(k,["branch_label","branchLabel"]),E=$t(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:Py(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 Py(e,t,n){const r=Fy(e,n);return r||Ly(t,n)}function Ry(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=Wr(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Oy(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 Oy(e,t){return{...e,metadata:ls(e.metadata,t.metadata)??null,config:ls(e.config,t.config)??null,parentConfig:ls(e.parentConfig,t.parentConfig)??null,next:My(e.next,t.next)??null,tasks:Dy(e.tasks,t.tasks)??null,values:ls(e.values,t.values)??null}}function ls(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function My(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 Dy(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 Ly(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 Fy(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=$y(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=xo(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=xo(r.state,`${o}-state`);if(s)return s}}return null}function $y(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=un(e);if(!n)return null;const r=$t(n,["id","task_id","taskId"])??t,o=$t(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function xo(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=xo(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=xo(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=xo(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=$t(n,["type","event","kind"]),o=$t(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=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 zy(e,t){if(!e||typeof e!="object")return null;const n=e,r=un(e)??{},o=un(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=jy[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=un(o.additional_kwargs)??un(o.additionalKwargs),d=un(o.response_metadata)??un(o.responseMetadata),f=$t(c,["createdAt","created_at"])??$t(o,["created_at","createdAt"]),h=$t(c,["checkpointId","checkpoint_id"]),p=$t(c,["checkpointNs","checkpoint_ns"]),m=By(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=Vy(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 b=Hy((c==null?void 0:c.tool_calls)??o.tool_calls);if(b.length&&(g.content=[...g.content,...b]),i==="tool"){const C=Uy(o,g.content);C&&(g.content=C)}return g}function By(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=$t(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=$t(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return 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=$t(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Kc(e,t){var s;const n=$t(e,["id","call_id"])??t,r=$t(e,["name"])??$t(un(e.function),["name"]);if(!n||!r)return null;const o=Wy(e.args??e.arguments??((s=un(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Hy(e){return Array.isArray(e)?e.map((t,n)=>Kc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Uy(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 Wy(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 un(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function $t(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Vy(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 Ky(e){return e.type!=="thread_info"&&e.type!=="token"}const qy={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Gy(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]=w.useReducer(Gy,{...qy,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Gc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Zy(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}=Yy(d.content,t.delta,h,p);if(!y)return e;const x={...d,content:m},b=cs(l,c,x),C={...f,[a]:g};return{...e,messages:b,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?cs(e.messages,k,T):e.messages,E=us(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)},b=us(x,d.length?d:[g]);return{...e,messages:[...e.messages,x],toolIndex:ta(e.toolIndex,m,b)}}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=us(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(),b=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:b},T=c>=0?cs(e.messages,c,C):[...e.messages,C],k=us(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=Jy(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=as(t),l=a.interrupt,c=a.latest,d=l===null?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 cs(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 us(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 Yy(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=Xy(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 Xy(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 Jy(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return cs(e,r,s)}return e}function Zy(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function tu(e={}){const t=w.useMemo(()=>Xn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[c,d]=w.useState(null),[f,h]=w.useState(""),[p,m]=w.useState(null),[g,y]=w.useState(0),[x,b]=w.useState(!1),C=w.useRef(null),T=w.useRef(!0),k=w.useRef(0),S=w.useRef(null),E=w.useRef(null),j=w.useRef(null),_=w.useRef(null),P=w.useCallback(O=>{o(O)},[]),D=w.useCallback(()=>{h(""),m(null),d(null),E.current=null,j.current=null,_.current=null},[]),z=w.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),b(!1),k.current=0,y(0)},[]),B=w.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,J,ce,Ce,te,L,G,se,ae,U,Ue,re,xe,Re,Le,nt,Se;const Q=Ge=>{var rt;try{const Qe=JSON.parse(JSON.stringify(Ge));return(rt=Qe==null?void 0:Qe.payload)!=null&&rt.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 We=window.__AUTH_TOKEN__,Lt=((ye=window.localStorage)==null?void 0:ye.getItem("authToken"))||null;let _t=null;try{const Ee=(Pe=window.localStorage)==null?void 0:Pe.getItem("chat-settings");Ee&&(_t=((J=JSON.parse(Ee))==null?void 0:J.apiKey)||null)}catch{}const Y=We||Lt||_t||null;Y&&(Ge={Authorization:`Bearer ${Y}`})}}catch{}console.debug("[use-chat] POST",t+n,Q(O));let rt={};if(typeof window<"u")try{const pt=(ce=window.localStorage)==null?void 0:ce.getItem("authSessionId");pt&&(rt={"X-Session-Id":pt})}catch{}const Qe={...Ge,...rt,...s.current},Ye={"Content-Type":"application/json",Accept:"text/event-stream",...Qe},Ke=await fetch(t+n,{method:"POST",headers:Ye,body:JSON.stringify(O),signal:V.signal,credentials:i});if(S.current&&(S.current.headers=Qe),!Ke.ok||!Ke.body){const pt=await Ke.text().catch(()=>"");console.debug("[use-chat] non-OK response",Ke.status,pt==null?void 0:pt.slice(0,500));const We=`stream ${Ke.status}${pt?": "+pt:""}`;throw(Ce=R==null?void 0:R.onConnectionError)==null||Ce.call(R,We),ne=!0,$="error",F=We,new Error(We)}b(!0);const et=Ke.body.getReader(),Dt=new TextDecoder;let St="",ft=[];k.current=0,y(0);let gt=0,ht=null;const ot=()=>{if(ft.length){const pt=ft.join("");ft=[],T.current&&h(We=>We+pt)}ht=null},on=()=>{typeof window<"u"&&ht==null&&(ht=requestAnimationFrame(ot))};let sn=Date.now();const Kt=setInterval(()=>{var pt;if(Date.now()-sn>18e5){const We="Stream idle timeout";d(We),$="error",F=We,V.abort(),(pt=R==null?void 0:R.onError)==null||pt.call(R,We)}},5e3),Bt=1024*1024;try{const pt=Ke.headers.get("X-Thread-Id")||Ke.headers.get("x-thread-id"),We=Ke.headers.get("X-Thread-Created")||Ke.headers.get("x-thread-created"),Lt=pt??null,_t=String(We??"").toLowerCase()==="true";for(S.current&&!S.current.threadId&&(S.current={...S.current,threadId:Lt}),(te=R==null?void 0:R.onOpen)==null||te.call(R,{threadId:Lt,created:_t});;){const{value:Y,done:Ee}=await et.read();if(Ee)break;St+=Dt.decode(Y,{stream:!0}),St.length>Bt&&(St="",console.warn("Stream buffer reset: exceeded 1MB"));let ve;for(;(ve=St.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const
|
|
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(
|
|
37
|
+
`))>=0;){const it=St.slice(0,ve);St=St.slice(ve+2);const yt=ex(it);if(!yt)continue;let It;try{It=JSON.parse(yt)}catch{console.debug("[use-chat] malformed SSE:",yt.slice(0,200));continue}const Ne=Qy(It)?It.data:It;sn=Date.now();const Ut=Ne.seq;if(Ut!==void 0){if(Ut<=gt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Ut,lastProcessedSeq:gt,type:Ne.type});continue}gt>0&&Ut>gt+1&&((L=R==null?void 0:R.onGap)==null||L.call(R,{from:gt,to:Ut})),gt=Ut,k.current=Ut,y(Ut)}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(At=>At.type),textLen:(Ne.delta||[]).filter(At=>At.type==="text").map(At=>String(At.text||"").length)}:Ne.content||Ne.delta?{hasContent:!0}:{}}catch(At){return{err:String(At)}}})()}),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 At=as(Ne).latest;At&&(E.current=At.checkpointId??null,j.current=At.checkpointNs??null,m(At.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)ft.push(Ne.content),on();else if(Ne.type==="message_delta"){const at=Ne.delta.filter(At=>At.type==="text").map(At=>At.text).join("");at&&e.autoAppendAssistant!==!1&&(ft.push(at),on())}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(ht!==null&&cancelAnimationFrame(ht),ot(),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"))||((ae=at.message)==null?void 0:ae.includes("401"))||((U=at.message)==null?void 0:U.includes("unauthorized"))||((Ue=at.message)==null?void 0:Ue.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(An){console.warn("[use-chat] onAuthError handler failed",An)}V.abort()}}}}ot(),$===null&&!V.signal.aborted&&($="complete")}catch(pt){if(pt.name==="AbortError")$=$??"aborted";else{const We=pt.message||String(pt);$="error",F=We,d(We),(xe=R==null?void 0:R.onError)==null||xe.call(R,We)}}finally{try{await et.cancel()}catch{}finally{(Re=et.releaseLock)==null||Re.call(et)}ht!==null&&typeof window<"u"&&window.cancelAnimationFrame(ht),clearInterval(Kt)}}catch(Ge){if(Ge.name==="AbortError")$=$??"aborted";else{const rt=Ge.message||String(Ge);$="error",F=rt,d(rt),(Le=R==null?void 0:R.onError)==null||Le.call(R,rt),ne||((nt=R==null?void 0:R.onConnectionError)==null||nt.call(R,rt),ne=!0)}}finally{const Ge=k.current,rt=E.current,Qe=j.current,Ye=_.current,Ke=$??(V.signal.aborted?"aborted":F?"error":"complete");try{(Se=R==null?void 0:R.onClosed)==null||Se.call(R,{reason:Ke,lastSeq:Ge,lastCheckpointId:rt,lastCheckpointNs:Qe,lastStateHistory:Ye,error:F})}catch(et){console.warn("[use-chat] onClosed callback failed",et)}l(!1),b(!1),C.current=null,k.current=0,y(0),S.current=null}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return w.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 Qy(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function ex(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 tx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=w.useRef(null),d=w.useRef(null),f=w.useRef(new Map),h=w.useRef(null),p=w.useCallback(_=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(_)}catch{}try{return JSON.parse(JSON.stringify(_))}catch{return _}},[]),m=w.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=w.useCallback(_=>{_&&f.current.set(_,[])},[]),y=w.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=w.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),Ky(_)){_.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:b,stop:C,isStreaming:T,error:k,setToken:S}=tu({baseUrl:e,token:void 0}),E=w.useCallback((_,P)=>{c.current=null,d.current=_.threadId??null,h.current={request:_,callbacks:P,manualStop:!1,threadIdGuess:_.threadId??null},b(_,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,b]),j=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return w.useMemo(()=>({startStream:E,stop:j,isStreaming:T,error:k,setAuthToken:S,replayBufferedEvents:y}),[E,j,T,k,S,y])}const ru=50,nx=750,na="chat-history@1",rx=5,ox=1e3,sx=15e3,ds=300;function ou(e,t=ds){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function Tr(){return typeof window<"u"&&typeof window.localStorage<"u"}function ra(e){if(!Tr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function oa(e,t){if(!Tr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function sa(e){if(Tr())try{window.localStorage.removeItem(e)}catch{}}function ia(e){return e==null?e:{...e}}function ix(e){return e==null?e:{...e}}function ax(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function lx(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function dn(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=ax(e==null?void 0:e.next),l=lx(e==null?void 0:e.tasks),c=ix(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 cx(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 ux(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:dn(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function dx(e,t,n=100){if(!Tr())return;const r=dn(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 fx(e,t){sa(aa(e,t))}function hx(e){if(Tr())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 fs(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 px(e,t){return fs(e,t)}function mx(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 gx(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=fs(e.metadata,t.metadata),r=fs(e.config,t.config),o=fs(e.parentConfig,t.parentConfig),s=mx(e.next,t.next),i=gx(e.tasks,t.tasks),a=px(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=dn(t,{cloneMessages:!0});return{...n,messages:Array.isArray(n.messages)?n.messages:[],values:n.values??null}}):[]}const yx="cachedThreads",xx="v1",la=200;function vx(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}:${vx(t||"anon")}`}function wx(){const e=ra(yx);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 bx(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=bx(e);if(t.length>0)return t;const n=wx();if(n.length>0)try{ua(e,n.slice(0,la))}catch{}return n}function hs(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 Sx({currentThreadId:e,currentThreadIdRef:t}){const[n,r]=w.useState([]),o=w.useRef(new Map),s=w.useRef(new Map),i=w.useCallback(m=>{if(!m){r([]);return}const g=o.current.get(m);if(!g||!g.length){r([]);return}r(g.map(y=>dn(y,{cloneMessages:!0})))},[]);w.useEffect(()=>{i(e)},[e,i]);const a=w.useCallback((m,g,y)=>{if(!m)return;const x=y==="replace"?[]:o.current.get(m)??[],b=y==="replace"?g:[...g,...x];if(!b.length){y==="replace"&&o.current.set(m,[]),m===t.current&&r([]);return}const C=new Map;for(const k of b){if(!(k!=null&&k.checkpointId))continue;const S=`${k.checkpointId}::${k.checkpointNs??""}`,E=dn(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=w.useCallback((m,g,y)=>{if(!m)return;const x=s.current.get(m),b=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);b.set(k,dn(T,{cloneMessages:!0}))}s.current.set(m,b)},[]),c=w.useCallback((m,g)=>{if(!m)return!1;const y=lu(g);if(!y.length)return!1;const x=o.current.get(m)??[],b=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&&b.has(j)?b.set(j,E):b.has(j)&&S||b.set(j,E))}};C(y,{preferExisting:!1}),C(x,{preferExisting:!0});const T=Array.from(b.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=>dn(k,{cloneMessages:!0}))),!0},[t]),d=w.useCallback(m=>{m&&(o.current.delete(m),s.current.delete(m),m===t.current&&r([]))},[t]),f=w.useCallback(()=>{r([])},[]),h=w.useCallback(m=>m?s.current.get(m)??null:null,[]),p=w.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=w.createContext(null),uu=w.createContext(null),du=w.createContext(null),Cx=w.createContext(!1);function kx({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=w.useMemo(()=>Xn(d),[d]),h=w.useMemo(()=>{try{return new URL(d).host}catch{return"unknown"}},[d]),p=w.useMemo(()=>`threadPayload:${xx}:${h}:`,[h]),m=w.useCallback(I=>ux(p,I),[p]),g=w.useCallback((I,A=100)=>{dx(p,I,A)},[p]),y=w.useCallback(I=>{fx(p,I)},[p]),x=w.useCallback(()=>{hx(p)},[p]),[b,C]=w.useState(()=>{var I;return ca(h,(I=c.getAuthToken)==null?void 0:I.call(c))}),[T,k]=w.useState(()=>{var A;const I=da(ca(h,(A=c.getAuthToken)==null?void 0:A.call(c)));return hs(I)}),S=w.useMemo(()=>fa(T),[T]),[E,j]=w.useState(t),[_,P]=w.useState(!1),[D,z]=w.useState(!1),[B,O]=w.useState(null),[H,R]=w.useState(null),[V,$]=w.useState(null),F=w.useCallback(()=>{const I=da(b);w.startTransition(()=>{k(hs(I))})},[b]),[ne,Q]=w.useState(!1),[ye,Pe]=w.useState(!1),[J,ce]=w.useState(null),[Ce,te]=w.useState(void 0),[L,G]=w.useState(void 0),[se,ae]=w.useState(void 0),{state:U,dispatch:Ue,seed:re,prepend:xe,pushUser:Re,onEvent:Le,reset:nt}=qc(),Se=w.useRef(E);w.useEffect(()=>{Se.current=E},[E]);const Ge=w.useRef(!1),rt=w.useRef([]),Qe=w.useRef(null),Ye=w.useRef(null),Ke=w.useRef(new Map),et=w.useRef(E),Dt=w.useRef(!1),St=w.useRef(null),ft=w.useRef(null),gt=w.useRef(new Map),ht=w.useRef(new Map),{threadCheckpoints:ot,syncActiveThreadCheckpoints:on,updateCheckpointCache:sn,updateCheckpointSnapshots:Kt,applyCheckpointSummaries:Bt,clearThreadCaches:pt,resetThreadCheckpoints:We,getSnapshotCache:Lt,getSnapshotFromCache:_t}=Sx({currentThreadId:E,currentThreadIdRef:Se}),Y=w.useCallback(()=>{var K;const I=ht.current;if(I.size<=ru)return;const A=Array.from(I.entries()).sort((fe,ie)=>fe[1].timestamp-ie[1].timestamp),W=I.size-ru;for(let fe=0;fe<W;fe++){const ie=(K=A[fe])==null?void 0:K[0];ie&&I.delete(ie)}},[]),Ee=w.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=w.useCallback((I,A)=>{const{threadId:W,checkpointId:K=null,checkpointNs:fe=null}=I,ie=iu(W,K,fe);if(A!=null&&A.force)gt.current.delete(ie),ht.current.delete(ie);else{if(A!=null&&A.preferCache){const kt=ht.current.get(ie);if(kt)return Promise.resolve(kt.result)}const Be=gt.current.get(ie);if(Be)return Be}const bt=(async()=>{try{const Be=await c.getStateHistory({threadId:W,checkpointId:K??void 0,checkpointNs:fe??void 0}),kt=Ee(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=>(ht.current.set(ie,{result:Be,timestamp:Date.now()}),Y(),Be)).finally(()=>{gt.current.get(ie)===bt&>.current.delete(ie)});return gt.current.set(ie,bt),bt},[c,Ee,Y]),it=w.useCallback((I,A)=>new Promise((W,K)=>{const fe=async()=>{Ge.current=!0;try{await I(),W()}catch(ie){K(ie)}finally{Ge.current=!1;const ie=rt.current.shift();ie&&ie().catch(()=>{})}};Ge.current?rt.current.push(fe):fe().catch(ie=>{K(ie)})}),[]),yt=w.useRef(S.length),It=w.useRef(!1);w.useEffect(()=>{yt.current=S.length},[S.length]),w.useEffect(()=>{const I=U.pendingInterrupt??cx(U.messages);su(V,I)||$(I??null)},[V,U.messages,U.pendingInterrupt]);const Ne=w.useCallback(async()=>{const I=yt.current>0;I||P(!0);try{const A=await c.listThreads();w.startTransition(()=>{k(W=>{const K=mt=>mt.map(bt=>`${bt.threadId}:${bt.updatedAt??""}:${bt.messageCount??""}`).join("|"),fe=fa(W);return K(fe)===K(A)||A.length===0&&fe.length>0&&!It.current?W:hs(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]),Ut=w.useRef(null),at=w.useCallback(async(I=500)=>(Ut.current&&clearTimeout(Ut.current),new Promise(A=>{Ut.current=setTimeout(async()=>{await Ne(),Ut.current=null,A()},I)})),[Ne]),At=w.useRef(!1),An=w.useRef(null),jt=w.useRef(null),an=w.useRef(""),[io,qt]=w.useState("idle"),nr=w.useRef({attempts:0,timer:null,reason:null}),ao=w.useRef(null),N=w.useRef(0),q=w.useRef(()=>{}),ue=w.useRef(()=>{}),ke=w.useRef(()=>{}),qe=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")},tt=w.useCallback(async I=>{const A=await c.listCheckpointSummaries(I);return lu(A??[])},[c]),Fe=w.useCallback((I,A)=>{if(!Tr())return;jt.current!==null&&(window.clearTimeout(jt.current),jt.current=null);const W=I.map(fe=>`${fe.threadId}:${fe.updatedAt??""}:${fe.messageCount??""}`).join("|");if(I.length===0){try{sa(b)}catch{}an.current="";return}if(W===an.current)return;const K=()=>{try{const fe=I.slice(0,la);ua(b,fe),an.current=W}catch{}finally{jt.current=null}};if(A!=null&&A.immediate){K();return}jt.current=window.setTimeout(()=>{ou(K)},ds)},[b]),ze=w.useCallback(()=>{Fe(S,{immediate:!0})},[Fe,S]),Ct=w.useCallback((I,A,W,K)=>{var Wl;const fe=W??Se.current;if(!fe)return;const ie=dn(I),mt=fe===Se.current,bt=(K==null?void 0:K.persist)!==!1;if(A==="replace"){if(bt){const Yt={threadId:fe,snapshot:dn(I,{cloneMessages:!0})};Ke.current.set(fe,Yt),et.current=fe}if(!mt)return;re(ie.messages,{checkpointId:ie.checkpointId??null,checkpointNs:ie.checkpointNs??null,pendingInterrupt:ie.interrupt??null}),$(ie.interrupt??null),ce(ie.nextCursor??null),Q(!!ie.nextCursor),te(ie.checkpointId??void 0),G(ie.checkpointNs??void 0),ae(ie.nextCursorNs??void 0);return}const Be=Ke.current.get(fe),kt=(Be==null?void 0:Be.snapshot)??null,Vt=Array.isArray(kt==null?void 0:kt.messages)?kt.messages:[],mn=dn(kt),Yn=Array.isArray(I==null?void 0:I.messages)?I.messages:[],Gt=new Set,Rt=[...Yn,...Vt].filter(Yt=>{const Vl=Yt==null?void 0:Yt.id;return Vl?Gt.has(Vl)?!1:(Gt.add(Vl),!0):!0}),or=au(mn,ie),$r={checkpointId:mn.checkpointId??ie.checkpointId??null,checkpointNs:mn.checkpointNs??ie.checkpointNs??null,createdAt:ie.createdAt??mn.createdAt??null,parentId:ie.parentId??mn.parentId??null,branchLabel:ie.branchLabel??mn.branchLabel??null,lastMessageId:((Wl=Rt[Rt.length-1])==null?void 0:Wl.id)??null,messagesLen:Rt.length,hasMessages:Rt.length>0,messages:Rt,nextCursor:ie.nextCursor??mn.nextCursor??null,nextCursorNs:ie.nextCursorNs??mn.nextCursorNs??null,interrupt:mn.interrupt??ie.interrupt??null,...or};if(Ke.current.set(fe,{threadId:fe,snapshot:dn($r,{cloneMessages:!0})}),!mt)return;Yn.length&&xe(Yn);const co=I&&Object.prototype.hasOwnProperty.call(I,"checkpointId")?I.checkpointId:void 0,_n=I&&Object.prototype.hasOwnProperty.call(I,"checkpointNs")?I.checkpointNs:void 0,zr=I&&Object.prototype.hasOwnProperty.call(I,"nextCursor")?I.nextCursor:void 0,wr=I&&Object.prototype.hasOwnProperty.call(I,"nextCursorNs")?I.nextCursorNs:void 0;ce(Yt=>zr!==void 0?zr??Yt??null:Yt??null),Q(Yt=>zr!==void 0?!!zr:Yt),te(Yt=>co!==void 0?co??Yt??void 0:Yt??void 0),G(Yt=>_n!==void 0?_n??Yt??void 0:Yt??void 0),ae(Yt=>wr!==void 0?wr??void 0:Yt)},[xe,re,$]),wt=w.useCallback(I=>{if(I.threadId!=null&&I.threadId!==Se.current)return;const A=dn(I.snapshot,{cloneMessages:!0});re(A.messages,{checkpointId:A.checkpointId??null,checkpointNs:A.checkpointNs??null,pendingInterrupt:A.interrupt??null}),$(A.interrupt??null),ce(A.nextCursor??null),Q(!!A.nextCursor),te(A.checkpointId??void 0),G(A.checkpointNs??void 0),ae(A.nextCursorNs??void 0),et.current=I.threadId,on(I.threadId??Se.current??null)},[re,$,on]),ct=w.useCallback(I=>{if(!I)return;Ke.current.delete(I),y(I),pt(I);const A=`${I}__`;for(const W of gt.current.keys())W.startsWith(A)&>.current.delete(W);for(const W of ht.current.keys())W.startsWith(A)&&ht.current.delete(W);et.current===I&&(et.current=null)},[pt,y]),Ft=w.useCallback(()=>{const I=Se.current;I&&ct(I),nt([]),Q(!1),Pe(!1),ce(null),te(void 0),G(void 0),ae(void 0)},[ct,nt]),hn=w.useCallback(({from:I,to:A})=>{const W=Se.current;W&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${I} -> ${A}) for thread ${W}`)},[]),Fn=w.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)),w.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:Wt,stop:xr,isStreaming:Z,error:le,setAuthToken:de,replayBufferedEvents:Ie}=tx({baseUrl:f,onThreadInfo:Fn,onMessageEvent:Le,onUnhandledEvent:I=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${I.type}`,I)},onSequenceGap:hn,onStreamClosed:I=>{q.current(I)},onConnectionError:I=>{ue.current(I)},onAuthError:a,onHeartbeat:I=>{ke.current(I)}}),Xe=w.useCallback(()=>{const I=nr.current;I.timer!==null&&(window.clearTimeout(I.timer),I.timer=null),I.reason=null},[]),Ve=w.useCallback((I,A)=>{qt("connecting"),Wt(I,{onOpen:W=>{var K;Xe(),nr.current.attempts=0,qt("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)??hn,onConnectionError:W=>{var K;ue.current(W),(K=A==null?void 0:A.onConnectionError)==null||K.call(A,W)},onHeartbeat:W=>{var K;ke.current(W),(K=A==null?void 0:A.onHeartbeat)==null||K.call(A,W)},onClosed:W=>{var K;q.current(W),(K=A==null?void 0:A.onClosed)==null||K.call(A,W)}})},[Xe,hn,qt,Wt]),st=w.useCallback(()=>{const I=Se.current;if(!I)return null;const A=ao.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]),Pt=w.useCallback(I=>{const A=nr.current;if(A.timer!==null)return;if(A.attempts>=rx){qt("error");return}A.attempts+=1,A.reason=I;const W=Math.min(ox*Math.pow(2,A.attempts-1),sx);qt("reconnecting"),A.timer=window.setTimeout(()=>{A.timer=null,A.reason=null;const K=st();if(!K){qt("error");return}Ie(K.threadId??void 0),Ve(K)},W)},[st,Ie,qt,Ve]),pn=w.useCallback(I=>{var A;if(ao.current=I,I.manualStop||I.reason==="complete"){Xe(),nr.current.attempts=0,qt("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}Pt(`closed:${I.reason}`)}},[Xe,Pt,qt,a]),rr=w.useCallback(I=>{console.warn("[ChatSessionProvider] Stream connection error:",I),Pt("connection-error")},[Pt]),_i=w.useCallback(I=>{N.current=Date.now(),qt(A=>A==="reconnecting"?"connected":A)},[qt]);q.current=pn,ue.current=rr,ke.current=_i,w.useEffect(()=>()=>{Xe()},[Xe]);const ji=w.useCallback(()=>{Xe(),nr.current.attempts=0,qt("idle"),xr()},[Xe,qt,xr]);w.useEffect(()=>{At.current=Z},[Z]),w.useEffect(()=>{if(!Tr())return;jt.current!==null&&(window.clearTimeout(jt.current),jt.current=null);const I=S.map(W=>`${W.threadId}:${W.updatedAt??""}:${W.messageCount??""}`).join("|");if(S.length===0){try{sa(b)}catch{}an.current="";return}if(I===an.current)return;const A=()=>{try{const W=S.slice(0,la);ua(b,W),an.current=I}catch{}finally{jt.current=null}};return jt.current=window.setTimeout(()=>{ou(A),jt.current=null},ds),()=>{jt.current!==null&&(window.clearTimeout(jt.current),jt.current=null)}},[S,Fe]),w.useEffect(()=>{var K;const I=c.getAuthToken();de(I);const A=fe=>{const ie=ca(h,fe);St.current!==ie&&(St.current=ie,Dt.current=!1),C(ie);const mt=da(ie);w.startTransition(()=>{k(hs(mt))}),fe&&!Dt.current&&(Dt.current=!0)};A(I);const W=(K=c.onTokenChange)==null?void 0:K.call(c,fe=>{fe!==I&&(de(fe),x(),gt.current.clear(),ht.current.clear(),A(fe))});return()=>{W==null||W()}},[c,h,de,x]);const lo=w.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),ie=typeof fe=="string"?fe:fe.threadId;return k(mt=>{const bt=mt.byId[A];if(!bt)return mt;const Be={...mt.byId};delete Be[A],Be[ie]={...bt,threadId:ie};const kt=mt.order.map(Vt=>Vt===A?ie:Vt);return{byId:Be,order:kt}}),j(ie),ft.current&&clearTimeout(ft.current),ft.current=setTimeout(()=>Ne(),300),O(null),ie}catch(fe){throw k(ie=>{if(!ie.byId[A])return ie;const mt={...ie.byId};delete mt[A];const bt=ie.order.filter(Be=>Be!==A);return{byId:mt,order:bt}}),j(null),O(String(fe)),fe}},[c,Ne]),Pi=w.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(mt=>mt!==I),ie={byId:K,order:fe};return A=fa(ie),ie}),A&&Fe(A,{immediate:!0}),ct(I),Se.current===I&&(Ye.current=I,j(null),Se.current=null,et.current=null,Ft()),at(200),O(null)}catch(A){throw O(String(A)),A}},[c,Ft,ct,at,Fe]),Wm=w.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 at(200),O(String(W)),W}},[c,at]),vr=w.useCallback(async(I,A,W,K=!1)=>{await it(async()=>{if(Ye.current===I&&!K){Ye.current=null;return}if(Qe.current===I&&!K)return;j(Gt=>Gt===I?Gt:I),Se.current=I;const mt=iu(I,A??null,W??null),bt=ht.current.get(mt),Be=!K&&!A&&!W&&bt&&Date.now()-bt.timestamp<nx,kt=!K&&!A&&!W;let Vt=!1;if(kt){const Gt=Ke.current.get(I);if(Gt)wt(Gt),Vt=!0;else{const Rt=m(I);Rt&&(Ke.current.set(I,Rt),wt(Rt),Vt=!0)}}const mn=K||!Vt||!!A||!!W,Yn=async Gt=>{Gt&&z(!0),Qe.current=I;try{const Rt=await ve({threadId:I,checkpointId:A,checkpointNs:W},{force:K}),{latest:or,checkpoints:$r,snapshots:co}=as(Rt.payload);w.startTransition(()=>{Ct(or,"replace",I),sn(I,$r,"replace"),Kt(I,co,"replace"),R(null),Gt&&z(!1)}),Rt.usedHistoryApi||tt(I).then(_n=>{Bt(I,_n)}).catch(_n=>{console.warn("[ChatSessionProvider] Failed to refresh checkpoint summaries:",_n)})}catch(Rt){if(qe(Rt))try{const or=await tt(I),$r=Bt(I,or);if(Q(!1),ce(null),ae(void 0),te(void 0),G(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(!Vt||K||Gt)&&(i==null||i(String(Rt))),R(String(Rt)),Rt}finally{Qe.current=null}};mn?await Yn(!0):kt&&Vt&&!Be&&Yn(!1).catch(Gt=>{console.warn("[ChatSessionProvider] Background refresh failed:",Gt)})},`loadThread-${I}`)},[wt,Bt,Ct,it,tt,ve,qe,i,sn,Kt]),Vm=w.useCallback(async()=>{await it(async()=>{const I=Se.current;I&&ct(I),Ye.current=null,j(null),Se.current=null,et.current=null,Ft(),te(void 0),G(void 0),ae(void 0),We();try{localStorage.removeItem("lastThreadId")}catch(A){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",A)}},"clearCurrentThread")},[Ft,ct,it,We]),Km=w.useCallback(async(I,A)=>{const W=Se.current;if(!W)throw new Error("No active thread");const K=Wr(I,A??null),fe=_t(W,K);if(fe){await it(async()=>{Ct(fe,"replace",W,{persist:!1})},`navigateToCheckpoint-${W}-${K}`);return}await vr(W,I,A??void 0,!0)},[Ct,it,_t,vr]),qm=w.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");await vr(Se.current,void 0,void 0,!0)},[vr]),Gm=w.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");if(ye||!ne)return;const I=J;if(I){Pe(!0);try{const A=Se.current,W=await ve({threadId:A,checkpointId:I??Ce??null,checkpointNs:se??L??null}),{latest:K,checkpoints:fe,snapshots:ie}=as(W.payload),mt=Lt(A);let bt=fe.length>0;if(bt&&mt&&mt.size>0&&(bt=fe.some(Be=>{if(!(Be!=null&&Be.checkpointId))return!1;const kt=Wr(Be.checkpointId,Be.checkpointNs??null);return!mt.has(kt)})),!bt){ce(null),ae(void 0),Q(!1),R(null);return}if(Ct(K,"prepend",A??void 0),A&&(sn(A,fe,"prepend"),Kt(A,ie,"prepend"),!W.usedHistoryApi))try{const Be=await tt(A);Bt(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)}}},[Ct,ve,Lt,ne,Ce,L,se,J,tt,Bt,ye,sn,Kt]),Ym=w.useCallback(I=>{if(I!=null&&I.threadId){if(I.checkpointId){const A=Wr(I.checkpointId,I.checkpointNs??null),W=dn({...I,interrupt:I.interrupt??null},{cloneMessages:!0});Kt(I.threadId,{[A]:W},"prepend")}Ct(I,"replace",I.threadId)}},[Ct,Kt]),qo=w.useCallback(async(I,A)=>{var zr;const W=Se.current,K=(I==null?void 0:I.text)??"",fe=(I==null?void 0:I.attachments)??[],ie=fe.length?fe:(A==null?void 0:A.attachments)??[],mt=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&&ie.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 _y(c,ie),Vt=[...Be];K&&K.trim()&&Vt.push({type:"text",text:K.trim()});const mn=!!W,Yn=mn?(A==null?void 0:A.checkpointId)??U.lastCheckpointId??void 0:void 0,Gt=mn?(A==null?void 0:A.checkpointNs)??U.lastCheckpointNs??void 0:void 0,Rt={id:((zr=crypto.randomUUID)==null?void 0:zr.call(crypto))||`user-${Date.now()}`,role:"user",content:Vt,createdAt:new Date().toISOString(),...Yn!=null?{checkpointId:Yn}:{},...Gt!=null?{checkpointNs:Gt}:{}};mt&&Object.keys(mt).length&&(Rt.additionalKwargs={...Rt.additionalKwargs??{},...mt}),Vt.length>0&&Re(Rt);const or={...Rt,content:Vt},$r=ie.length>0,co={messages:Vt.length>0?[or]:[],files_info:kt,...o&&$r&&s?{active_agent:s}:{},...bt},_n={threadId:W??null,payload:co,checkpointId:Yn??null,checkpointNs:Gt??null,nodeFilter:(A==null?void 0:A.nodeFilter)??null,config:A==null?void 0:A.config,command:(A==null?void 0:A.command)??null};_n.threadId||delete _n.threadId,_n.command||delete _n.command,Ve(_n,{onError:wr=>{console.warn("[ChatSessionProvider] Stream error:",wr)},onOpen:({threadId:wr})=>{!Se.current&&wr&&(U.messages.length<=1&&(Ye.current=wr),j(wr))},onGap:hn})},[c,o,s,hn,U.lastCheckpointId,U.lastCheckpointNs,U.messages.length,Re,Ve]),Xm=w.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{Ue({type:"interrupt_response",payload:{interruptId:I}})}catch(ie){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",ie)}await qo({payload:{}},{checkpointId:U.lastCheckpointId??void 0,checkpointNs:U.lastCheckpointNs??void 0,command:{kind:"resume",value:fe}}),$(null)}catch(ie){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${I}:`,ie),ie}},[Ue,U.lastCheckpointId,U.lastCheckpointNs,qo]);w.useEffect(()=>{if(l==null||l(E),E)try{localStorage.setItem("lastThreadId",E)}catch(I){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",I)}},[E,l]),w.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 vr(A))}catch(A){console.warn("[ChatSessionProvider] Failed to restore last thread:",A)}else t&&n&&await vr(t)}catch(A){console.error("[ChatSessionProvider] Initialization failed:",A),i==null||i(String(A))}})(),()=>{}),[]),w.useEffect(()=>{const I=Se.current;if(!I||et.current!==I)return;U.messages.length&&U.messages[U.messages.length-1];const A=dn({checkpointId:U.lastCheckpointId??null,checkpointNs:U.lastCheckpointNs??null,messages:U.messages.slice(),nextCursor:J??null,nextCursorNs:se??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 Vt;return(Be==null?void 0:Be.id)!==((Vt=A.messages[kt])==null?void 0:Vt.id)}),ie=((K==null?void 0:K.checkpointId)??null)!==A.checkpointId||((K==null?void 0:K.checkpointNs)??null)!==A.checkpointNs,mt=((K==null?void 0:K.nextCursor)??null)!==A.nextCursor||((K==null?void 0:K.nextCursorNs)??null)!==A.nextCursorNs,bt=!su((K==null?void 0:K.interrupt)??null,A.interrupt??null);if(fe||ie||mt||bt){const Be={threadId:I,snapshot:A};Ke.current.set(I,Be),An.current&&window.clearTimeout(An.current),An.current=window.setTimeout(()=>{try{g(Be,100)}catch(kt){console.warn("[ChatSessionProvider] Failed to persist thread payload:",kt)}},ds)}},[J,se,U.lastCheckpointId,U.lastCheckpointNs,U.messages,U.pendingInterrupt,V,g]);const gT=w.useMemo(()=>({threads:S,currentThreadId:E,setCurrentThreadId:j,isLoading:_,error:B,actions:{createThread:lo,deleteThread:Pi,renameThread:Wm,refreshThreads:()=>Ne()},persistThreadsCache:ze,hydrateFromCache:F}),[S,E,_,B,lo,Pi,Wm,Ne,ze,F,j]),yT=w.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:ot,metadata:W,isLoading:D,isHistoryLoading:ye,error:H,hasMore:ne,loadOlder:Gm,seedFromSnapshot:Ym,clearState:Ft,navigateToCheckpoint:Km,returnToLatest:qm,loadThread:vr,clearThread:Vm,respondToInterrupt:Xm}},[Vm,Ft,E,V,ne,ye,D,Gm,vr,U.assemblingId,U.lastBranch,U.lastCheckpointId,U.lastCheckpointNs,U.messages,Km,Xm,qm,Ym,H,ot]),xT=w.useMemo(()=>({isStreaming:Z,error:le,connectionState:io,submit:qo,send:qo,stop:ji,setAuthToken:de}),[io,Z,le,ji,qo,de]);return u.jsx(Cx.Provider,{value:!0,children:u.jsx(du.Provider,{value:xT,children:u.jsx(cu.Provider,{value:gT,children:u.jsx(uu.Provider,{value:yT,children:e})})})})}function ps(){const e=w.useContext(cu);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function ms(){const e=w.useContext(uu);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function fu(){const e=w.useContext(du);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function gs({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onAuthError:l,onThreadChange:c}){return u.jsx(Ny,{apiConfig:t,children:u.jsx(kx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onAuthError:l,onThreadChange:c,children:e})})}function oe(...e){return eg.twMerge(Qm.clsx(e))}const Tx=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?br.Slot:"button";return u.jsx(i,{className:oe(Tx({variant:t,size:n,className:e})),ref:s,...o})});ut.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]=w.useState(e),x=(m?i:g)??"",[b,C]=w.useTransition(),T=w.useRef(null),k=w.useRef(0),S=w.useRef(null);w.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=w.useCallback(()=>{const H=T.current;H&&(H.style.height="auto",H.style.height=`${H.scrollHeight}px`)},[]);w.useEffect(()=>{E()},[E,x]);const j=w.useCallback((H,{fromUser:R})=>{m||y(H),R&&(a==null||a(H))},[m,a]),_=w.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=w.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=w.useCallback(H=>{H.key==="Enter"&&!H.shiftKey?(H.preventDefault(),_()):H.key==="Escape"&&t&&(H.preventDefault(),c==null||c())},[_,t,c]),O=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return u.jsx("form",{onSubmit:H=>void _(H),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(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(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||b,children:u.jsx(he.Send,{size:16})})})]})})}const Ex=w.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 Ix(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 Jn(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,Nx(o,...t)]}function Nx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Xt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},Ax=v[" useInsertionEffect ".trim().toString()]||Xt;function Vr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=_x({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=jx(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 _x({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Ax(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function jx(e){return typeof e=="function"}var Px=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Me=Px.reduce((e,t)=>{const n=br.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&&Yo.flushSync(()=>e.dispatchEvent(t))}function pa(e){const t=e+"CollectionProvider",[n,r]=Jn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,b=w.useRef(null),C=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:C,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=br.createSlot(a),c=w.forwardRef((g,y)=>{const{scope:x,children:b}=g,C=s(a,x),T=Je(y,C.collectionRef);return u.jsx(l,{ref:T,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=br.createSlot(d),p=w.forwardRef((g,y)=>{const{scope:x,children:b,...C}=g,T=w.useRef(null),k=Je(y,T),S=s(d,x);return w.useEffect(()=>(S.itemMap.set(T,{ref:T,...C}),()=>void S.itemMap.delete(T))),u.jsx(h,{[f]:"",ref:k,children:b})});p.displayName=d;function m(g){const y=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const C=Array.from(b.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 Rx=v.createContext(void 0);function ys(e){const t=v.useContext(Rx);return e||t||"ltr"}function Jt(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 Ox(e,t=globalThis==null?void 0:globalThis.document){const n=Jt(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 Mx="DismissableLayer",ma="dismissableLayer.update",Dx="dismissableLayer.pointerDownOutside",Lx="dismissableLayer.focusOutside",yu,xu=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),xs=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),b=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,T=b>=x,k=zx(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=Bx(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 Ox(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(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(Me.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)})});xs.displayName=Mx;var Fx="DismissableLayerBranch",$x=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(Me.div,{...e,ref:o})});$x.displayName=Fx;function zx(e,t=globalThis==null?void 0:globalThis.document){const n=Jt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){wu(Dx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Bx(e,t=globalThis==null?void 0:globalThis.document){const n=Jt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&wu(Lx,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},Hx="FocusScope",vs=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Jt(o),d=Jt(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 b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),b.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||(Ux(Gx(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 b=g.currentTarget,[C,T]=Wx(b);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===b&&g.preventDefault()}},[n,r,p.paused]);return u.jsx(Me.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});vs.displayName=Hx;function Ux(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(ir(r,{select:t}),document.activeElement!==n)return}function Wx(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(!Vx(n,{upTo:t}))return n}function Vx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Kx(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&&Kx(e)&&t&&e.select()}}var Tu=qx();function qx(){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 Gx(e){return e.filter(t=>t.tagName!=="A")}var Yx=v[" useId ".trim().toString()]||(()=>{}),Xx=0;function Zn(e){const[t,n]=v.useState(Yx());return Xt(()=>{n(r=>r??String(Xx++))},[e]),t?`radix-${t}`:""}const Jx=["top","right","bottom","left"],ar=Math.min,gn=Math.max,ws=Math.round,bs=Math.floor,zn=e=>({x:e,y:e}),Zx={left:"right",right:"left",bottom:"top",top:"bottom"},Qx={start:"end",end:"start"};function wa(e,t,n){return gn(e,ar(t,n))}function Qn(e,t){return typeof e=="function"?e(t):e}function er(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 ev=new Set(["top","bottom"]);function Bn(e){return ev.has(er(e))?"y":"x"}function Ca(e){return ba(Bn(e))}function tv(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=Ss(i)),[i,Ss(i)]}function nv(e){const t=Ss(e);return[ka(e),t,ka(t)]}function ka(e){return e.replace(/start|end/g,t=>Qx[t])}const Iu=["left","right"],Nu=["right","left"],rv=["top","bottom"],ov=["bottom","top"];function sv(e,t,n){switch(e){case"top":case"bottom":return n?t?Nu:Iu:t?Iu:Nu;case"left":case"right":return t?rv:ov;default:return[]}}function iv(e,t,n,r){const o=Kr(e);let s=sv(er(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ka)))),s}function Ss(e){return e.replace(/left|right|bottom|top/g,t=>Zx[t])}function av(e){return{top:0,right:0,bottom:0,left:0,...e}}function Au(e){return typeof e!="number"?av(e):{top:e,right:e,bottom:e,left:e}}function Cs(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=Bn(t),i=Ca(t),a=Sa(i),l=er(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 lv=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:b,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=b??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 vo(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}=Qn(t,e),m=Au(p),y=a[h?f==="floating"?"reference":"floating":f],x=Cs(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,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=Cs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:C,strategy:l}):b);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 cv=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}=Qn(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",b=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[b],_),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}}}),uv=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}=Qn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=er(o),b=Bn(a),C=er(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(C||!g?[Ss(a)]:nv(a)),S=m!=="none";!h&&S&&k.push(...iv(a,g,m,T));const E=[a,...k],j=await vo(t,y),_=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(j[x]),f){const O=tv(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"?b!==Bn(H):!1)||P.every($=>Bn($.placement)===b?$.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=Bn($.placement);return F===b||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 Jx.some(t=>e[t]>=0)}const dv=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Qn(e,t);switch(r){case"referenceHidden":{const s=await vo(t,{...o,elementContext:"reference"}),i=ju(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pu(i)}}}case"escaped":{const s=await vo(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 fv(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=er(n),a=Kr(n),l=Bn(n)==="y",c=Ru.has(i)?-1:1,d=s&&l?-1:1,f=Qn(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 hv=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 fv(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}}}}},pv=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:b}=y;return{x,y:b}}},...l}=Qn(e,t),c={x:n,y:r},d=await vo(t,l),f=Bn(er(o)),h=ba(f);let p=c[h],m=c[f];if(s){const y=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=p+d[y],C=p-d[x];p=wa(b,p,C)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=m+d[y],C=m-d[x];m=wa(b,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}}}}}},mv=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}=Qn(e,t),d={x:n,y:r},f=Bn(o),h=ba(f);let p=d[h],m=d[f];const g=Qn(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,b;const C=h==="y"?"width":"height",T=Ru.has(er(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:((b=i.offset)==null?void 0:b[f])||0)-(T?y.crossAxis:0);m<k?m=k:m>S&&(m=S)}return{[h]:p,[f]:m}}}},gv=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}=Qn(e,t),d=await vo(t,c),f=er(o),h=Kr(o),p=Bn(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 b=g-d.top-d.bottom,C=m-d.left-d.right,T=ar(g-d[y],b),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=b),S&&!h){const P=gn(d.left,0),D=gn(d.right,0),z=gn(d.top,0),B=gn(d.bottom,0);p?j=m-2*(P!==0||D!==0?P+D:gn(d.left,d.right)):E=g-2*(z!==0||B!==0?z+B:gn(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 ks(){return typeof window<"u"}function qr(e){return Ou(e)?(e.nodeName||"").toLowerCase():"#document"}function yn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Hn(e){var t;return(t=(Ou(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Ou(e){return ks()?e instanceof Node||e instanceof yn(e).Node:!1}function Pn(e){return ks()?e instanceof Element||e instanceof yn(e).Element:!1}function Un(e){return ks()?e instanceof HTMLElement||e instanceof yn(e).HTMLElement:!1}function Mu(e){return!ks()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof yn(e).ShadowRoot}const yv=new Set(["inline","contents"]);function wo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Rn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!yv.has(o)}const xv=new Set(["table","td","th"]);function vv(e){return xv.has(qr(e))}const wv=[":popover-open",":modal"];function Ts(e){return wv.some(t=>{try{return e.matches(t)}catch{return!1}})}const bv=["transform","translate","scale","rotate","perspective"],Sv=["transform","translate","scale","rotate","perspective","filter"],Cv=["paint","layout","strict","content"];function Ta(e){const t=Ea(),n=Pn(e)?Rn(e):e;return bv.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)||Sv.some(r=>(n.willChange||"").includes(r))||Cv.some(r=>(n.contain||"").includes(r))}function kv(e){let t=lr(e);for(;Un(t)&&!Gr(t);){if(Ta(t))return t;if(Ts(t))return null;t=lr(t)}return null}function Ea(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Tv=new Set(["html","body","#document"]);function Gr(e){return Tv.has(qr(e))}function Rn(e){return yn(e).getComputedStyle(e)}function Es(e){return Pn(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||Mu(e)&&e.host||Hn(e);return Mu(t)?t.host:t}function Du(e){const t=lr(e);return Gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Un(t)&&wo(t)?t:Du(t)}function bo(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=yn(o);if(s){const a=Ia(i);return t.concat(i,i.visualViewport||[],wo(o)?o:[],a&&n?bo(a):[])}return t.concat(o,bo(o,[],n))}function Ia(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Lu(e){const t=Rn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Un(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=ws(n)!==s||ws(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Na(e){return Pn(e)?e:e.contextElement}function Yr(e){const t=Na(e);if(!Un(t))return zn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Lu(t);let i=(s?ws(n.width):n.width)/r,a=(s?ws(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Ev=zn(0);function Fu(e){const t=yn(e);return!Ea()||!t.visualViewport?Ev:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Iv(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==yn(e)?!1:t}function Er(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Na(e);let i=zn(1);t&&(r?Pn(r)&&(i=Yr(r)):i=Yr(e));const a=Iv(s,n,r)?Fu(s):zn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=yn(s),p=r&&Pn(r)?yn(r):r;let m=h,g=Ia(m);for(;g&&r&&p!==m;){const y=Yr(g),x=g.getBoundingClientRect(),b=Rn(g),C=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*y.x,T=x.top+(g.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=C,c+=T,m=yn(g),g=Ia(m)}}return Cs({width:d,height:f,x:l,y:c})}function Is(e,t){const n=Es(e).scrollLeft;return t?t.left+n:Er(Hn(e)).left+n}function $u(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Is(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Nv(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=Hn(r),a=t?Ts(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=zn(1);const d=zn(0),f=Un(r);if((f||!f&&!s)&&((qr(r)!=="body"||wo(i))&&(l=Es(r)),Un(r))){const p=Er(r);c=Yr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?$u(i,l):zn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function Av(e){return Array.from(e.getClientRects())}function _v(e){const t=Hn(e),n=Es(e),r=e.ownerDocument.body,o=gn(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=gn(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Is(e);const a=-n.scrollTop;return Rn(r).direction==="rtl"&&(i+=gn(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const zu=25;function jv(e,t){const n=yn(e),r=Hn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Ea();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Is(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 Pv=new Set(["absolute","fixed"]);function Rv(e,t){const n=Er(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Un(e)?Yr(e):zn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Bu(e,t,n){let r;if(t==="viewport")r=jv(e,n);else if(t==="document")r=_v(Hn(e));else if(Pn(t))r=Rv(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 Cs(r)}function Hu(e,t){const n=lr(e);return n===t||!Pn(n)||Gr(n)?!1:Rn(n).position==="fixed"||Hu(n,t)}function Ov(e,t){const n=t.get(e);if(n)return n;let r=bo(e,[],!1).filter(a=>Pn(a)&&qr(a)!=="body"),o=null;const s=Rn(e).position==="fixed";let i=s?lr(e):e;for(;Pn(i)&&!Gr(i);){const a=Rn(i),l=Ta(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Pv.has(o.position)||wo(i)&&!l&&Hu(e,i))?r=r.filter(d=>d!==i):o=a,i=lr(i)}return t.set(e,r),r}function Mv(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Ts(t)?[]:Ov(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Bu(t,d,o);return c.top=gn(f.top,c.top),c.right=ar(f.right,c.right),c.bottom=ar(f.bottom,c.bottom),c.left=gn(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 Dv(e){const{width:t,height:n}=Lu(e);return{width:t,height:n}}function Lv(e,t,n){const r=Un(t),o=Hn(t),s=n==="fixed",i=Er(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=zn(0);function c(){l.x=Is(o)}if(r||!r&&!s)if((qr(t)!=="body"||wo(o))&&(a=Es(t)),r){const p=Er(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):zn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function Aa(e){return Rn(e).position==="static"}function Uu(e,t){if(!Un(e)||Rn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Hn(e)===n&&(n=n.ownerDocument.body),n}function Wu(e,t){const n=yn(e);if(Ts(e))return n;if(!Un(e)){let o=lr(e);for(;o&&!Gr(o);){if(Pn(o)&&!Aa(o))return o;o=lr(o)}return n}let r=Uu(e,t);for(;r&&vv(r)&&Aa(r);)r=Uu(r,t);return r&&Gr(r)&&Aa(r)&&!Ta(r)?n:r||kv(e)||n}const Fv=async function(e){const t=this.getOffsetParent||Wu,n=this.getDimensions,r=await n(e.floating);return{reference:Lv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function $v(e){return Rn(e).direction==="rtl"}const zv={convertOffsetParentRelativeRectToViewportRelativeRect:Nv,getDocumentElement:Hn,getClippingRect:Mv,getOffsetParent:Wu,getElementRects:Fv,getClientRects:Av,getDimensions:Dv,getScale:Yr,isElement:Pn,isRTL:$v};function Vu(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Bv(e,t){let n=null,r;const o=Hn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=bs(f),g=bs(o.clientWidth-(d+h)),y=bs(o.clientHeight-(f+p)),x=bs(d),C={rootMargin:-m+"px "+-g+"px "+-y+"px "+-x+"px",threshold:gn(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 Hv(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?bo(c):[],...bo(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Bv(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[b]=x;b&&b.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?Er(e):null;l&&y();function y(){const x=Er(e);g&&!Vu(g,x)&&n(),g=x,m=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const Uv=hv,Wv=pv,Vv=uv,Kv=gv,qv=dv,Ku=cv,Gv=mv,Yv=(e,t,n)=>{const r=new Map,o={platform:zv,...n},s={...o.platform,_c:r};return lv(e,t,{...o,platform:s})};var Xv=typeof document<"u",Jv=function(){},Ns=Xv?w.useLayoutEffect:Jv;function As(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(!As(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)&&!As(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 Ns(()=>{t.current=e}),t}function Zv(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);As(h,r)||p(r);const[m,g]=v.useState(null),[y,x]=v.useState(null),b=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),Yv(S.current,E.current,$).then(F=>{const ne={...F,isPositioned:z.current!==!1};O.current&&!As(j.current,ne)&&(j.current=ne,Yo.flushSync(()=>{f(ne)}))})},[h,t,n,D,z]);Ns(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[c]);const O=v.useRef(!1);Ns(()=>(O.current=!0,()=>{O.current=!1}),[]),Ns(()=>{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:b,setFloating:C}),[b,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 Qv=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):{}}}},ew=(e,t)=>({...Uv(e),options:[e,t]}),tw=(e,t)=>({...Wv(e),options:[e,t]}),nw=(e,t)=>({...Gv(e),options:[e,t]}),rw=(e,t)=>({...Vv(e),options:[e,t]}),ow=(e,t)=>({...Kv(e),options:[e,t]}),sw=(e,t)=>({...qv(e),options:[e,t]}),iw=(e,t)=>({...Qv(e),options:[e,t]});var aw="Arrow",Yu=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Me.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=aw;var lw=Yu;function Xu(e){const[t,n]=v.useState(void 0);return Xt(()=>{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,_s]=Jn(ja),[cw,Zu]=Ju(ja),Qu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(cw,{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(Me.div,{...o,ref:a})});td.displayName=ed;var Pa="PopperContent",[uw,dw]=Ju(Pa),nd=v.forwardRef((e,t)=>{var te,L,G,se,ae,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,b]=v.useState(null),C=Je(t,Ue=>b(Ue)),[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(hw),altBoundary:z},{refs:O,floatingStyles:H,placement:R,isPositioned:V,middlewareData:$}=Zv({strategy:"fixed",placement:_,whileElementsMounted:(...Ue)=>Hv(...Ue,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[ew({mainAxis:o+j,alignmentAxis:i}),l&&tw({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?nw():void 0,...B}),l&&rw({...B}),ow({...B,apply:({elements:Ue,rects:re,availableWidth:xe,availableHeight:Re})=>{const{width:Le,height:nt}=re.reference,Se=Ue.floating.style;Se.setProperty("--radix-popper-available-width",`${xe}px`),Se.setProperty("--radix-popper-available-height",`${Re}px`),Se.setProperty("--radix-popper-anchor-width",`${Le}px`),Se.setProperty("--radix-popper-anchor-height",`${nt}px`)}}),T&&iw({element:T,padding:a}),pw({arrowWidth:E,arrowHeight:j}),h&&sw({strategy:"referenceHidden",...B})]}),[F,ne]=sd(R),Q=Jt(m);Xt(()=>{V&&(Q==null||Q())},[V,Q]);const ye=(te=$.arrow)==null?void 0:te.x,Pe=(L=$.arrow)==null?void 0:L.y,J=((G=$.arrow)==null?void 0:G.centerOffset)!==0,[ce,Ce]=v.useState();return Xt(()=>{x&&Ce(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:ce,"--radix-popper-transform-origin":[(se=$.transformOrigin)==null?void 0:se.x,(ae=$.transformOrigin)==null?void 0:ae.y].join(" "),...((U=$.hide)==null?void 0:U.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(uw,{scope:n,placedSide:F,onArrowChange:k,arrowX:ye,arrowY:Pe,shouldHideArrow:J,children:u.jsx(Me.div,{"data-side":F,"data-align":ne,...g,ref:C,style:{...g.style,animation:V?void 0:"none"}})})})});nd.displayName=Pa;var rd="PopperArrow",fw={top:"bottom",right:"left",bottom:"top",left:"right"},od=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=dw(rd,r),i=fw[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(lw,{...o,ref:n,style:{...o.style,display:"block"}})})});od.displayName=rd;function hw(e){return e!==null}var pw=e=>({name:"transformOrigin",options:e,fn(t){var y,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=sd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.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,mw="Portal",js=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Xt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ri.createPortal(u.jsx(Me.div,{...r,ref:t}),i):null});js.displayName=mw;function gw(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Cn=e=>{const{present:t,children:n}=e,r=yw(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Je(r.ref,xw(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Cn.displayName="Presence";function yw(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=gw(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Ps(r.current);s.current=a==="mounted"?c:"none"},[a]),Xt(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=Ps(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]),Xt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const g=Ps(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=Ps(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 Ps(e){return(e==null?void 0:e.animationName)||"none"}function xw(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",vw={bubbles:!1,cancelable:!0},So="RovingFocusGroup",[Oa,ud,ww]=pa(So),[bw,dd]=Jn(So,[ww]),[Sw,Cw]=bw(So),fd=v.forwardRef((e,t)=>u.jsx(Oa.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Oa.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(kw,{...e,ref:t})})}));fd.displayName=So;var kw=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=ys(s),[g,y]=Vr({prop:i,defaultProp:a??null,onChange:l,caller:So}),[x,b]=v.useState(!1),C=Jt(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(Sw,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:v.useCallback(j=>y(j),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>E(j=>j-1),[]),children:u.jsx(Me.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,vw);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,()=>b(!1))})})}),hd="RovingFocusGroupItem",pd=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Zn(),c=s||l,d=Cw(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(Me.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=Iw(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?Nw(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 Tw={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ew(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Iw(e,t,n){const r=Ew(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Tw[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 Nw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Aw=fd,_w=pd,jw=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Xr=new WeakMap,Rs=new WeakMap,Os={},Ma=0,gd=function(e){return e&&(e.host||gd(e.parentNode))},Pw=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})},Rw=function(e,t,n,r){var o=Pw(t,Array.isArray(e)?e:[e]);Os[n]||(Os[n]=new WeakMap);var s=Os[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&&Rs.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||(Rs.has(f)||f.removeAttribute(r),Rs.delete(f)),p||f.removeAttribute(n)}),Ma--,Ma||(Xr=new WeakMap,Xr=new WeakMap,Rs=new WeakMap,Os={})}},Da=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=jw(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Rw(r,o,n,"aria-hidden")):function(){return null}},Wn=function(){return Wn=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},Wn.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 Ow(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 Ms="right-scroll-bar-position",Ds="width-before-scroll-bar",Mw="with-scroll-bars-hidden",Dw="--removed-body-scroll-bar-size";function La(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Lw(e,t){var n=w.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var Fw=typeof window<"u"?v.useLayoutEffect:v.useEffect,xd=new WeakMap;function $w(e,t){var n=Lw(null,function(r){return e.forEach(function(o){return La(o,r)})});return Fw(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 zw(e){return e}function Bw(e,t){t===void 0&&(t=zw);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 Hw(e){e===void 0&&(e={});var t=Bw(null);return t.options=Wn({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,Wn({},n))};vd.isSideCarExport=!0;function Uw(e,t){return e.useMedium(t),vd}var wd=Hw(),Fa=function(){},Ls=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,b=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=$w([n,t]),E=Wn(Wn({},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),Wn(Wn({},E),{ref:S})):v.createElement(b,Wn({},E,{className:l,ref:S}),a))});Ls.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Ls.classNames={fullWidth:Ds,zeroRight:Ms};var Ww=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Vw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Ww();return t&&e.setAttribute("nonce",t),e}function Kw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function qw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Gw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Vw())&&(Kw(t,n),qw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Yw=function(){var e=Gw();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},bd=function(){var e=Yw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Xw={left:0,top:0,right:0,gap:0},$a=function(e){return parseInt(e||"",10)||0},Jw=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)]},Zw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Xw;var t=Jw(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])}},Qw=bd(),Jr="data-scroll-locked",eb=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(Mw,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
42
42
|
}
|
|
@@ -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(
|
|
56
|
+
.`).concat(Ms,` {
|
|
57
57
|
right: `).concat(a,"px ").concat(r,`;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
.`).concat(
|
|
60
|
+
.`).concat(Ds,` {
|
|
61
61
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
.`).concat(
|
|
64
|
+
.`).concat(Ms," .").concat(Ms,` {
|
|
65
65
|
right: 0 `).concat(r,`;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
.`).concat(
|
|
68
|
+
.`).concat(Ds," .").concat(Ds,` {
|
|
69
69
|
margin-right: 0 `).concat(r,`;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
body[`).concat(Jr,`] {
|
|
73
|
-
`).concat(
|
|
73
|
+
`).concat(Dw,": ").concat(a,`px;
|
|
74
74
|
}
|
|
75
|
-
`)},
|
|
75
|
+
`)},Sd=function(){var e=parseInt(document.body.getAttribute(Jr)||"0",10);return isFinite(e)?e:0},tb=function(){v.useEffect(function(){return document.body.setAttribute(Jr,(Sd()+1).toString()),function(){var e=Sd()-1;e<=0?document.body.removeAttribute(Jr):document.body.setAttribute(Jr,e.toString())}},[])},nb=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;tb();var s=v.useMemo(function(){return Zw(o)},[o]);return v.createElement(Qw,{styles:eb(s,!t,o,n?"":"!important")})},za=!1;if(typeof window<"u")try{var Fs=Object.defineProperty({},"passive",{get:function(){return za=!0,!0}});window.addEventListener("test",Fs,Fs),window.removeEventListener("test",Fs,Fs)}catch{za=!1}var Zr=za?{passive:!1}:!1,rb=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&&!rb(e)&&n[t]==="visible")},ob=function(e){return Cd(e,"overflowY")},sb=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},ib=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},ab=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Td=function(e,t){return e==="v"?ob(t):sb(t)},Ed=function(e,t){return e==="v"?ib(t):ab(t)},lb=function(e,t){return e==="h"&&t==="rtl"?-1:1},cb=function(e,t,n,r,o){var s=lb(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 b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(c=!0),c},$s=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},ub=function(e,t){return e[0]===t[0]&&e[1]===t[1]},db=function(e){return`
|
|
76
76
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
77
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
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,`
|
|
78
|
+
`)},fb=0,Qr=[];function hb(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(fb++)[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=Ow([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=$s(g),b=n.current,C="deltaX"in g?g.deltaX:b[0]-x[0],T="deltaY"in g?g.deltaY:b[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 cb(_,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?Id(y):$s(y),b=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&ub(k.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){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,b){var C={name:g,delta:y,target:x,should:b,shadowParent:pb(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=$s(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,$s(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:db(o)}):null,p?v.createElement(nb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function pb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const mb=Uw(wd,hb);var zs=v.forwardRef(function(e,t){return v.createElement(Ls,Wn({},e,{ref:t,sideCar:mb}))});zs.classNames=Ls.classNames;var Ba=["Enter"," "],gb=["ArrowDown","PageUp","Home"],Ad=["ArrowUp","PageDown","End"],yb=[...gb,...Ad],xb={ltr:[...Ba,"ArrowRight"],rtl:[...Ba,"ArrowLeft"]},vb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Co="Menu",[ko,wb,bb]=pa(Co),[Ir,_d]=Jn(Co,[bb,_s,dd]),Bs=_s(),jd=dd(),[Sb,Nr]=Ir(Co),[Cb,To]=Ir(Co),Pd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Bs(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Jt(s),h=ys(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(Sb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Cb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Pd.displayName=Co;var kb="MenuAnchor",Ha=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Bs(n);return u.jsx(ad,{...o,...r,ref:t})});Ha.displayName=kb;var Ua="MenuPortal",[Tb,Rd]=Ir(Ua,{forceMount:void 0}),Od=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Nr(Ua,t);return u.jsx(Tb,{scope:t,forceMount:n,children:u.jsx(Cn,{present:n||s.open,children:u.jsx(js,{asChild:!0,container:o,children:r})})})};Od.displayName=Ua;var kn="MenuContent",[Eb,Wa]=Ir(kn),Md=v.forwardRef((e,t)=>{const n=Rd(kn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Nr(kn,e.__scopeMenu),i=To(kn,e.__scopeMenu);return u.jsx(ko.Provider,{scope:e.__scopeMenu,children:u.jsx(Cn,{present:r||s.open,children:u.jsx(ko.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(Ib,{...o,ref:t}):u.jsx(Nb,{...o,ref:t})})})})}),Ib=v.forwardRef((e,t)=>{const n=Nr(kn,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)})}),Nb=v.forwardRef((e,t)=>{const n=Nr(kn,e.__scopeMenu);return u.jsx(Va,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Ab=br.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=Nr(kn,n),x=To(kn,n),b=Bs(n),C=jd(n),T=wb(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?zs:v.Fragment,R=m?{as:Ab,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,J=Q.map(G=>G.textValue),ce=Bb(J,ne,Pe),Ce=(L=Q.find(G=>G.textValue===ce))==null?void 0:L.ref.current;(function G(se){P.current=se,window.clearTimeout(_.current),se!==""&&(_.current=window.setTimeout(()=>G(""),1e3))})(ne),Ce&&setTimeout(()=>Ce.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)&&Ub(F,(ye=z.current)==null?void 0:ye.area)},[]);return u.jsx(Eb,{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(vs,{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(xs,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(Aw,{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,...b,...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 J=E.current;if(F.target!==J||!yb.includes(F.key))return;F.preventDefault();const Ce=T().filter(te=>!te.disabled).map(te=>te.ref.current);Ad.includes(F.key)&&Ce.reverse(),$b(Ce)}),onBlur:ge(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(_.current),P.current="")}),onPointerMove:ge(e.onPointerMove,Io(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=kn;var _b="MenuGroup",Ka=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Me.div,{role:"group",...r,ref:t})});Ka.displayName=_b;var jb="MenuLabel",Dd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Me.div,{...r,ref:t})});Dd.displayName=jb;var Hs="MenuItem",Ld="menu.itemSelect",Us=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=To(Hs,e.__scopeMenu),a=Wa(Hs,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())})})});Us.displayName=Hs;var Fd=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Wa(Hs,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(ko.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(_w,{asChild:!0,...a,focusable:!r,children:u.jsx(Me.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,Io(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,Io(m=>i.onItemLeave(m))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),Pb="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(Us,{role:"menuitemcheckbox","aria-checked":Ws(n)?"mixed":n,...o,ref:t,"data-state":Ga(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(Ws(n)?!0:!n),{checkForDefaultPrevented:!1})})})});$d.displayName=Pb;var zd="MenuRadioGroup",[Rb,Ob]=Ir(zd,{value:void 0,onValueChange:()=>{}}),Bd=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Jt(r);return u.jsx(Rb,{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=Ob(Hd,e.__scopeMenu),s=n===o.value;return u.jsx(Wd,{scope:e.__scopeMenu,checked:s,children:u.jsx(Us,{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,Mb]=Ir(qa,{checked:!1}),Vd=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Mb(qa,n);return u.jsx(Cn,{present:r||Ws(s.checked)||s.checked===!0,children:u.jsx(Me.span,{...o,ref:t,"data-state":Ga(s.checked)})})});Vd.displayName=qa;var Db="MenuSeparator",Kd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Me.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Kd.displayName=Db;var Lb="MenuArrow",qd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Bs(n);return u.jsx(cd,{...o,...r,ref:t})});qd.displayName=Lb;var Fb="MenuSub",[UT,Gd]=Ir(Fb),Eo="MenuSubTrigger",Yd=v.forwardRef((e,t)=>{const n=Nr(Eo,e.__scopeMenu),r=To(Eo,e.__scopeMenu),o=Gd(Eo,e.__scopeMenu),s=Wa(Eo,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,Io(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,Io(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,b=h[y?"left":"right"],C=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:C,y:h.top},{x:C,y:h.bottom},{x:b,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===" "||xb[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Yd.displayName=Eo;var Xd="MenuSubContent",Jd=v.forwardRef((e,t)=>{const n=Rd(kn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Nr(kn,e.__scopeMenu),i=To(kn,e.__scopeMenu),a=Gd(Xd,e.__scopeMenu),l=v.useRef(null),c=Je(t,l);return u.jsx(ko.Provider,{scope:e.__scopeMenu,children:u.jsx(Cn,{present:r||s.open,children:u.jsx(ko.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=vb[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 Ws(e){return e==="indeterminate"}function Ga(e){return Ws(e)?"indeterminate":e?"checked":"unchecked"}function $b(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function zb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Bb(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=zb(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 Hb(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 Ub(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Hb(n,t)}function Io(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Wb=Pd,Vb=Ha,Kb=Od,qb=Md,Gb=Ka,Yb=Dd,Xb=Us,Jb=$d,Zb=Bd,Qb=Ud,e0=Vd,t0=Kd,n0=qd,r0=Yd,o0=Jd,Vs="DropdownMenu",[s0,WT]=Jn(Vs,[_d]),nn=_d(),[i0,Qd]=s0(Vs),ef=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=nn(t),c=v.useRef(null),[d,f]=Vr({prop:o,defaultProp:s??!1,onChange:i,caller:Vs});return u.jsx(i0,{scope:t,triggerId:Zn(),triggerRef:c,contentId:Zn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(Wb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};ef.displayName=Vs;var tf="DropdownMenuTrigger",nf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Qd(tf,n),i=nn(n);return u.jsx(Vb,{asChild:!0,...i,children:u.jsx(Me.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 a0="DropdownMenuPortal",rf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=nn(t);return u.jsx(Kb,{...r,...n})};rf.displayName=a0;var of="DropdownMenuContent",sf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Qd(of,n),s=nn(n),i=v.useRef(!1);return u.jsx(qb,{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 l0="DropdownMenuGroup",c0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(Gb,{...o,...r,ref:t})});c0.displayName=l0;var u0="DropdownMenuLabel",af=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(Yb,{...o,...r,ref:t})});af.displayName=u0;var d0="DropdownMenuItem",lf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(Xb,{...o,...r,ref:t})});lf.displayName=d0;var f0="DropdownMenuCheckboxItem",cf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(Jb,{...o,...r,ref:t})});cf.displayName=f0;var h0="DropdownMenuRadioGroup",p0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(Zb,{...o,...r,ref:t})});p0.displayName=h0;var m0="DropdownMenuRadioItem",uf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(Qb,{...o,...r,ref:t})});uf.displayName=m0;var g0="DropdownMenuItemIndicator",df=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(e0,{...o,...r,ref:t})});df.displayName=g0;var y0="DropdownMenuSeparator",ff=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(t0,{...o,...r,ref:t})});ff.displayName=y0;var x0="DropdownMenuArrow",v0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(n0,{...o,...r,ref:t})});v0.displayName=x0;var w0="DropdownMenuSubTrigger",hf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(r0,{...o,...r,ref:t})});hf.displayName=w0;var b0="DropdownMenuSubContent",pf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(o0,{...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=b0;var S0=ef,C0=nf,k0=rf,mf=sf,gf=af,yf=lf,xf=cf,vf=uf,wf=df,bf=ff,Sf=hf,Cf=pf;const T0=S0,E0=C0,I0=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"})]}));I0.displayName=Sf.displayName;const N0=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}));N0.displayName=Cf.displayName;const kf=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(k0,{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 A0=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]}));A0.displayName=xf.displayName;const _0=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]}));_0.displayName=vf.displayName;const j0=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}));j0.displayName=gf.displayName;const P0=v.forwardRef(({className:e,...t},n)=>u.jsx(bf,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));P0.displayName=bf.displayName;const Ks=1e4;function R0(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,"<").replace(/>/g,">").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.
|
|
86
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function O0(e,t=Ks){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 M0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),O0(t),R0(t)}const qs=0,cr=1,eo=2,Tf=4;function Ef(e){return()=>e}function D0(e){e()}function If(e,t){return n=>e(t(n))}function Nf(e,t){return()=>e(t)}function L0(e,t){return n=>e(t,n)}function Xa(e){return e!==void 0}function F0(...e){return()=>{e.map(D0)}}function to(){}function Gs(e,t){return t(e),e}function $0(e,t){return t(e)}function Tt(...e){return e}function dt(e,t){return e(cr,t)}function $e(e,t){e(qs,t)}function Ja(e){e(eo)}function Mt(e){return e(Tf)}function we(e,t){return dt(e,L0(t,qs))}function On(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 Vn(e){return t=>()=>{t(e)}}function X(e,...t){const n=z0(...t);return(r,o)=>{switch(r){case eo:Ja(e);return;case cr:return dt(e,n(o))}}}function Kn(e,t){return n=>r=>{n(t=e(t,r))}}function Ar(e){return t=>n=>{e>0?e--:t(n)}}function tr(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function He(...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 z0(...e){return t=>e.reduceRight($0,t)}function B0(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=Ze();return(r,o)=>{switch(r){case qs:t=o;break;case cr:{o(t);break}case Tf:return t}return n(r,o)}}function Qt(e,t){return Gs(ee(t),n=>we(e,n))}function Ze(){const e=[];return(t,n)=>{switch(t){case qs: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 xn(e){return Gs(Ze(),t=>we(e,t))}function lt(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:H0(),singleton:n}}const H0=()=>Symbol();function U0(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function zt(...e){const t=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);dt(s,l=>{n[i]=l,r=r|a,r===o&&$e(t,n)})}),function(s,i){switch(s){case eo:{Ja(t);return}case cr:return r===o&&i(n),dt(t,i)}}}function Ae(e,t=_f){return X(e,Et(t))}function Za(...e){return function(t,n){switch(t){case eo:return;case cr:return F0(...e.map(r=>dt(r,n)))}}}var fn=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(fn||{});const W0={0:"debug",3:"error",1:"log",2:"warn"},V0=()=>typeof globalThis>"u"?window:globalThis,ur=lt(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=V0().VIRTUOSO_LOG_LEVEL)!=null?o:Mt(e);r>=s&&console[W0[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function _r(e,t,n){return Qa(e,t,n).callbackRef}function Qa(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function K0(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=q0(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 q0(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},fn.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,fn.WARN),t==="normal"?0:parseInt(t??"0",10)}function Pf(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),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=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const rn=lt(()=>{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}),No={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 xt(e){return e===No}function Ao(e,t){if(!xt(e))return t===e.k?e.v:t<e.k?Ao(e.l,t):Ao(e.r,t)}function Mn(e,t,n="k"){if(xt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Mn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Mn(e.l,t,n)}function vn(e,t,n){return xt(e)?Df(t,n,1):t===e.k?Ht(e,{k:t,v:n}):t<e.k?Lf(Ht(e,{l:vn(e.l,t,n)})):Lf(Ht(e,{r:vn(e.r,t,n)}))}function no(){return No}function Ys(e,t,n){if(xt(e))return[];const r=Mn(e,t)[0];return G0(tl(e,r,n))}function el(e,t){if(xt(e))return No;const{k:n,l:r,r:o}=e;if(t===n){if(xt(r))return o;if(xt(o))return r;{const[s,i]=Mf(r);return Xs(Ht(e,{k:s,l:Of(r),v:i}))}}else return t<n?Xs(Ht(e,{l:el(r,t)})):Xs(Ht(e,{r:el(o,t)}))}function jr(e){return xt(e)?[]:[...jr(e.l),{k:e.k,v:e.v},...jr(e.r)]}function tl(e,t,n){if(xt(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 Xs(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(Ht(e,{lvl:n-1}));if(!xt(t)&&!xt(t.r))return Ht(t.r,{l:Ht(t,{r:t.r.l}),lvl:n,r:Ht(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(nl(e))return rl(Ht(e,{lvl:n-1}));if(!xt(r)&&!xt(r.l)){const o=r.l,s=nl(o)?r.lvl-1:r.lvl;return Ht(o,{l:Ht(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:rl(Ht(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ht(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 xt(e.r)?e.l:Xs(Ht(e,{r:Of(e.r)}))}function nl(e){return xt(e)||e.lvl>e.r.lvl}function Mf(e){return xt(e.r)?[e.k,e.v]:Mf(e.r)}function Df(e,t,n,r=No,o=No){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!xt(t)&&t.lvl===e.lvl?Ht(t,{r:Ht(e,{l:t.r})}):e}function rl(e){const{lvl:t,r:n}=e;return!xt(n)&&!xt(n.r)&&n.lvl===t&&n.r.lvl===t?Ht(n,{l:Ht(e,{r:n.l}),lvl:t+1}):e}function G0(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 _o(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ol=lt(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function zf(e,t,n){return e[Js(e,t,n)]}function Js(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 Y0(e,t,n,r){const o=Js(e,t,r),s=Js(e,n,r,o);return e.slice(o,s+1)}function dr(e,t){return Math.round(e.getBoundingClientRect()[t])}function Zs(e){return!xt(e.groupOffsetTree)}function sl({index:e},t){return t===e?0:t<e?-1:1}function X0(){return{groupIndices:[],groupOffsetTree:no(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:no()}}function J0(e,t){let n=xt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),xt(e)){e=vn(e,0,s);continue}const a=Ys(e,i-1,o+1);if(a.some(oS(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=vn(e,o+1,h));c&&(e=vn(e,i,s))}return[e,n]}function Z0(e){return typeof e.groupIndex<"u"}function Q0({offset:e},t){return t===e?0:t<e?-1:1}function jo(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(!Zs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Hf(e,t,n){if(Z0(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 eS(e,t,n,r=0){return r>0&&(t=Math.max(t,zf(e,r,sl).offset)),Rf(Y0(e,t,n,Q0),rS)}function tS(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,fn.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&xt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,g)=>vn(vn(m,g,h),g+1,p),i)}else[i,a]=J0(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)=>vn(h,p,jo(p,f,o)),no()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function nS(e){return jr(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=Js(o,t-1,sl),a=o[l].offset;const c=Mn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===Mn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of Ys(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 rS(e){return{index:e.index,value:e}}function oS(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 sS={offsetHeight:"height",offsetWidth:"width"},qn=lt(([{log:e},{recalcInProgress:t}])=>{const n=Ze(),r=Ze(),o=Qt(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,sS[S])),h=ee(void 0),p=ee(0),m=X0(),g=Qt(X(n,He(l,e,p),Kn(tS,m),Et()),m),y=Qt(X(l,Et(),Kn((k,S)=>({current:S,prev:k.current}),{current:[],prev:[]}),pe(({prev:k})=>k)),[]);we(X(l,je(k=>k.length>0),He(g,p),pe(([k,S,E])=>{const j=k.reduce((_,P,D)=>vn(_,P,jo(P,S.offsetTree,E)||D),no());return{...S,groupIndices:k,groupOffsetTree:j}})),g),we(X(r,He(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=Qt(X(c,pe(k=>k===void 0)),!0);we(X(d,je(k=>k!==void 0&&xt(Mt(g).sizeTree)),pe(k=>[{endIndex:0,size:k,startIndex:0}])),n);const b=xn(X(n,He(g),Kn(({sizes:k},[S,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:m}),pe(k=>k.changed)));dt(X(a,Kn((k,S)=>({diff:k.prev-S,prev:S}),{diff:0,prev:0}),pe(k=>k.diff)),k=>{const{groupIndices:S}=Mt(g);if(k>0)$e(t,!0),$e(s,k+Uf(k,S));else if(k<0){const E=Mt(y);E.length>0&&(k-=Uf(-k,E)),$e(i,k)}}),dt(X(a,He(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},fn.ERROR)});const C=xn(s);we(X(s,He(g),pe(([k,S])=>{const E=S.groupIndices.length>0,j=[],_=S.lastSize;if(E){const P=Ao(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=jr(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 jr(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=xn(X(i,He(g,p),pe(([k,{offsetTree:S},E])=>{const j=-k;return jo(j,S,E)})));return we(X(i,He(g,p),pe(([k,S,E])=>{if(S.groupIndices.length>0){if(xt(S.sizeTree))return S;let j=no();const _=Mt(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=jr(S.sizeTree).reduce((B,{k:O,v:H})=>vn(B,Math.max(0,O+k),H),j),P!==-k){const B=Ao(S.sizeTree,z);j=vn(j,0,B);const O=Mn(S.sizeTree,-k+1)[1];j=vn(j,1,O)}return{...S,sizeTree:j,...il(S.offsetTree,0,j,E)}}else{const j=jr(S.sizeTree).reduce((_,{k:P,v:D})=>vn(_,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:b,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Tt(ur,ol),{singleton:!0});function iS(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Wf=lt(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ze(),i=Ze(),a=xn(X(s,pe(iS)));return we(X(a,pe(l=>l.totalCount)),n),we(X(a,pe(l=>l.groupIndices)),e),we(X(zt(o,t,r),je(([l,c])=>Zs(c)),pe(([l,c,d])=>Mn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),Et(),pe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},Tt(qn,rn)),fr=lt(([{log:e}])=>{const t=ee(!1),n=xn(X(t,je(r=>r),Et()));return dt(t,r=>{r&&Mt(e)("props updated",{},fn.DEBUG)}),{didMount:n,propsReady:t}},Tt(ur),{singleton:!0}),aS=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||!aS)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Po=lt(([{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,b=null;function C(){y&&(y(),y=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),$e(l,!1)}return we(X(p,He(n,f,r,g,a,i,h),He(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=jo(ne,k.offsetTree,z)+_;R==="end"?(Q+=B+Mn(k.sizeTree,ne)[1]-S+O,ne===F&&(Q+=P)):R==="center"?Q+=(B+Mn(k.sizeTree,ne)[1]-S+O)/2:Q-=j,$&&(Q+=$);const ye=Pe=>{C(),Pe?(D("retrying to scroll to",{location:T},fn.DEBUG),$e(p,T)):($e(m,!0),D("list did not change, scroll successful",{},fn.DEBUG))};if(C(),V==="smooth"){let Pe=!1;b=dt(t,J=>{Pe=Pe||J}),y=On(d,()=>{ye(Pe)})}else y=On(X(t,lS(150)),ye);return x=setTimeout(()=>{C()},1200),$e(l,!0),D("scrolling from index to",{behavior:V,index:ne,top:Q},fn.DEBUG),{behavior:V,top:Q}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:g}},Tt(qn,rn,ur),{singleton:!0});function lS(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 Ro=lt(([{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,He(l),je(([d,f])=>!!f),Vn(!1)),a),we(X(i,He(l),je(([d,f])=>!!f),Vn(!1)),c),dt(X(zt(t,i),He(a,n,e,c),je(([[,d],f,{sizeTree:h},p,m])=>d&&(!xt(h)||Xa(p))&&!f&&!m),He(l)),([,d])=>{On(o,()=>{$e(c,!0)}),al(4,()=>{On(r,()=>{$e(a,!0)}),$e(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},Tt(qn,rn,Po,fr),{singleton:!0});function Kf(e,t){return Math.abs(e-t)<1.01}const Oo="up",Mo="down",cS="none",uS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},dS=0,Do=lt(([{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(dS),h=Qt(X(Za(X(Ae(o),Ar(1),Vn(!0)),X(Ae(o),Ar(1),Vn(!1),Af(100))),Et()),!1),p=Qt(X(Za(X(n,Vn(!0)),X(n,Vn(!1),Af(200))),Et()),!1);we(X(zt(Ae(o),Ae(f)),pe(([b,C])=>b<=C),Et()),a),we(X(a,tr(50)),c);const m=xn(X(zt(r,Ae(s),Ae(t),Ae(e),Ae(d)),Kn((b,[{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>b.state.scrollTop?(z="SCROLLED_DOWN",B=b.state.scrollTop-T):(z="SIZE_DECREASED",B=b.state.scrollTop-T||b.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:B,state:P}}let D;return P.scrollHeight>b.state.scrollHeight?D="SIZE_INCREASED":k<b.state.viewportHeight?D="VIEWPORT_HEIGHT_DECREASING":T<b.state.scrollTop?D="SCROLLING_UPWARDS":D="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:D,state:P}},uS),Et((b,C)=>b&&b.atBottom===C.atBottom))),g=Qt(X(r,Kn((b,{scrollHeight:C,scrollTop:T,viewportHeight:k})=>{if(Kf(b.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:T};{const S=C-(T+k)<1;return b.scrollTop!==T&&S?{changed:!0,jump:b.scrollTop-T,scrollHeight:C,scrollTop:T}:{changed:!0,jump:0,scrollHeight:C,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),je(b=>b.changed),pe(b=>b.jump)),0);we(X(m,pe(b=>b.atBottom)),i),we(X(i,tr(50)),l);const y=ee(Mo);we(X(r,pe(({scrollTop:b})=>b),Et(),Kn((b,C)=>Mt(p)?{direction:b.direction,prevScrollTop:C}:{direction:C<b.prevScrollTop?Oo:Mo,prevScrollTop:C},{direction:Mo,prevScrollTop:0}),pe(b=>b.direction)),y),we(X(r,tr(50),Vn(cS)),y);const x=ee(0);return we(X(h,je(b=>!b),Vn(0)),x),we(X(o,tr(100),He(h),je(([b,C])=>!!C),Kn(([b,C],[T])=>[C,T],[0,0]),pe(([b,C])=>C-b)),x),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},Tt(rn)),Qs="top",ei="bottom",qf="none";function Gf(e,t,n){return typeof e=="number"?n===Oo&&t===Qs||n===Mo&&t===ei?e:0:n===Oo?t===Qs?e.main:e.reverse:t===ei?e.main:e.reverse}function Yf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const cl=lt(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ze(),i=ee(0),a=ee(0),l=ee(0),c=Qt(X(zt(Ae(r),Ae(o),Ae(n),Ae(s,_o),Ae(l),Ae(i),Ae(t),Ae(e),Ae(a)),pe(([d,f,h,[p,m],g,y,x,b,C])=>{const T=d-b,k=y+x,S=Math.max(h-T,0);let E=qf;const j=Yf(C,Qs),_=Yf(C,ei);return p-=b,p+=h+x,m+=h+x,m-=b,p>d+k-j&&(E=Oo),m<d-S+f+_&&(E=Mo),E!==qf?[Math.max(T-h-Gf(g,Qs,E)-j,0),T-S-x+f+Gf(g,ei,E)+_]:null}),je(d=>d!=null),Et(_o)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},Tt(rn),{singleton:!0});function fS(e,t,n){if(Zs(t)){const r=Bf(e,t);return[{index:Mn(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 ti(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 ti(c,[],a,o,n,r)}function Jf(e,t,n){if(e.length===0)return[];if(!Zs(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=Ys(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 Pr=lt(([{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 b=Qt(X(zt(p,m,Ae(l,_o),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=Mt(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(xt($))return F>0?null:ti(fS(ll(P,j),R,H),[],j,O,R,B);const ne=[];if(z.length>0){const ce=z[0],Ce=z[z.length-1];let te=0;for(const L of Ys($,ce,Ce)){const G=L.value,se=Math.max(L.start,ce),ae=Math.min(L.end,Ce);for(let U=se;U<=ae;U++)ne.push({data:H==null?void 0:H[U],index:U,offset:te,size:G}),te+=G}}if(!D)return ti([],ne,j,O,R,B);const Q=z.length>0?z[z.length-1]+1:0,ye=eS(V,S,E,Q);if(ye.length===0)return null;const Pe=j-1,J=Gs([],ce=>{for(const Ce of ye){const te=Ce.value;let L=te.offset,G=Ce.start;const se=te.size;if(te.offset<S){G+=Math.floor((S-te.offset+O)/(se+O));const U=G-Ce.start;L+=U*se+U*O}G<Q&&(L+=(Q-G)*se,G=Q);const ae=Math.min(Ce.end,Pe);for(let U=G;U<=ae&&!(L>=E);U++)ce.push({data:H==null?void 0:H[U],index:U,offset:L,size:se}),L+=se+O}});return ti(J,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(b,pe(S=>S.topListHeight)),f),we(f,a),we(X(b,pe(S=>[S.top,S.bottom])),i),we(X(b,pe(S=>S.items)),x);const C=xn(X(b,je(({items:S})=>S.length>0),He(o,e),je(([{items:S},E])=>S[S.length-1].originalIndex===E-1),pe(([,S,E])=>[S-1,E]),Et(_o),pe(([S])=>S))),T=xn(X(b,tr(200),je(({items:S,topItems:E})=>S.length>0&&S[0].originalIndex===E.length),pe(({items:S})=>S[0].index),Et())),k=xn(X(b,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:b,rangeChanged:k,startReached:T,topItemsIndexes:g,...h}},Tt(qn,Wf,cl,Ro,Po,Do,fr,ol),{singleton:!0}),Zf=lt(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ze(),i=Qt(X(zt(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(rn,Pr),{singleton:!0}),hS=lt(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Qt(X(zt(n,e,t),je(([o])=>o),pe(([,o,s])=>Math.max(0,o-s)),tr(0),Et()),0);return{alignToBottom:n,paddingTopAddition:r}},Tt(rn,Zf),{singleton:!0}),Qf=lt(()=>({context:ee(null)})),pS=({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=lt(([{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,He(t,l,n,s,o,r,a),He(e),pe(([[f,h,p,m,g,y,x,b],C])=>{const{align:T,behavior:k,calculateViewLocation:S=pS,done:E,...j}=f,_=Hf(f,h,m-1),P=jo(_,h.offsetTree,C)+g+y,D=P+Mn(h.sizeTree,_)[1],z=b+y,B=b+p-x,O=S({itemBottom:D,itemTop:P,locationParams:{align:T,behavior:k,...j},viewportBottom:B,viewportTop:z});return O?E&&On(X(i,je(H=>!H),Ar(Mt(i)?1:2)),E):E&&E(),O}),je(f=>f!==null)),c),{scrollIntoView:d}},Tt(qn,rn,Po,Pr,ur),{singleton:!0});function th(e){return e?e==="smooth"?"smooth":"auto":!1}const mS=(e,t)=>typeof e=="function"?th(e(t)):t&&th(e),gS=lt(([{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){$e(i,{align:"end",behavior:k,index:"LAST"})}dt(X(zt(X(Ae(t),Ar(1)),l),He(Ae(m),s,a,f),pe(([[k,S],E,j,_,P])=>{let D=S&&_,z="auto";return D&&(z=mS(E,j||P),D=D&&!!z),{followOutputBehavior:z,shouldFollow:D,totalCount:k}}),je(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:S})=>{y&&(y(),y=null),Mt(n)?requestAnimationFrame(()=>{Mt(d)("following output to ",{totalCount:S},fn.DEBUG),x(k)}):y=On(e,()=>{Mt(d)("following output to ",{totalCount:S},fn.DEBUG),x(k),y=null})});function b(k){const S=On(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(Mt(d)("scrolling to bottom due to increased size",{},fn.DEBUG),x("auto"))});setTimeout(S,100)}dt(X(zt(Ae(m),t,c),je(([k,,S])=>k&&S),Kn(({value:k},[,S])=>({refreshed:k===S,value:S}),{refreshed:!1,value:0}),je(({refreshed:k})=>k),He(m,t)),([,k])=>{Mt(a)&&b(k!==!1)}),dt(g,()=>{b(Mt(m)!==!1)}),dt(zt(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),dt(X(zt(X(T,Ar(1)),l),He(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),tr(0)),k=>{y&&(y(),y=null),Mt(n)?requestAnimationFrame(()=>{Mt(d)("scrolling into view",{}),$e(p,k)}):y=On(e,()=>{Mt(d)("scrolling into view",{}),$e(p,k),y=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:C}},Tt(qn,Do,Po,Ro,fr,ur,rn,Qf,eh)),yS=lt(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(we(X(a,He(s),je(([,l])=>l!==0),He(o,r,t,n,e),pe(([[,l],c,d,f,h,p=[]])=>Xf(l,c,d,f,h,p))),i),{}),Tt(qn,Ro,Pr,fr),{singleton:!0}),xS=lt(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return dt(X(e,He(r),je(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{On(X(n,Ar(1),je(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{$e(t,o)})})}),{initialScrollTop:r}},Tt(fr,rn,Pr),{singleton:!0}),nh=lt(([{scrollVelocity:e}])=>{const t=ee(!1),n=Ze(),r=ee(!1);return we(X(e,He(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),dt(X(zt(t,e,n),He(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Tt(Do),{singleton:!0}),dl=lt(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ze(),r=Ze(),o=Ze(),s=ee(!1),i=ee(void 0);return we(X(zt(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,He(r),pe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Tt(rn)),vS=lt(([{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),dt(X(c,He(t,r,i,f,h,n)),([p,m,g,y,x,b,C])=>{const T=nS(m.sizeTree);y&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=C,p({ranges:T,scrollTop:g})}),we(X(d,je(Xa),pe(wS)),o),we(X(s,He(d),je(([,p])=>p!==void 0),Et(),pe(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},Tt(qn,rn,Ro,fr,dl));function wS(e){return{align:"start",index:0,offset:e.scrollTop}}const bS=lt(([{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(Pr));function rh(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const SS=rh(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),CS=lt(([{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=xn(X(l,He(i),Kn(([,x,b,C],[{bottom:T,items:k,offsetBottom:S,totalCount:E},j])=>{const _=T+S;let P=0;return b===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),He(r,a,n,o,p,m),je(([,x,b,C,,,T])=>!T&&!C&&x!==0&&b===Oo),pe(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},fn.DEBUG),x))));function y(x){x>0?($e(t,{behavior:"auto",top:-x}),$e(e,0)):($e(e,0),$e(t,{behavior:"auto",top:-x}))}return dt(X(g,He(e,s)),([x,b,C])=>{C&&SS()?$e(e,b-x):y(-x)}),dt(X(zt(Qt(s,!1),e,m),je(([x,b,C])=>!x&&!C&&b!==0),pe(([x,b])=>b),tr(1)),y),we(X(f,pe(x=>({top:-x}))),t),dt(X(c,He(h,d),pe(([x,{groupIndices:b,lastSize:C,sizeTree:T},k])=>{function S(E){return E*(C+k)}if(b.length===0)return S(x);{let E=0;const j=Ao(T,0);let _=0,P=0;for(;_<x;){_++,E+=j;let D=b.length===P+1?1/0:b[P+1]-b[P]-1;_+D>x&&(E-=j,D=x-_+1),_+=D,E+=S(D),P++}return E}})),x=>{$e(e,x),requestAnimationFrame(()=>{$e(t,{top:x}),requestAnimationFrame(()=>{$e(e,0),$e(m,!1)})})}),{deviation:e}},Tt(rn,Do,Pr,qn,ur,ol)),kS=lt(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),Tt(cl,yS,fr,nh,Zf,xS,hS,dl,eh,ur,Qf)),oh=lt(([{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:b,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:b,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,..._,...g,sizes:l,...y}),Tt(qn,Ro,rn,vS,gS,Pr,Po,CS,bS,Wf,kS));function TS(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 ni=typeof document<"u"?w.useLayoutEffect:w.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=w.createContext({});function l(y,x){y.propsReady&&$e(y.propsReady,!1);for(const b of r){const C=y[t.required[b]];$e(C,x[b])}for(const b of o)if(b in x){const C=y[t.optional[b]];$e(C,x[b])}y.propsReady&&$e(y.propsReady,!0)}function c(y){return s.reduce((x,b)=>(x[b]=C=>{const T=y[t.methods[b]];$e(T,C)},x),{})}function d(y){return i.reduce((x,b)=>(x[b]=B0(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...C}=y,[T]=w.useState(()=>Gs(U0(e),E=>{l(E,C)})),[k]=w.useState(Nf(d,T));ni(()=>{for(const E of i)E in C&&dt(k[E],C[E]);return()=>{Object.values(k).map(Ja)}},[C,k,T]),ni(()=>{l(T,C)}),w.useImperativeHandle(x,Ef(c(T)));const S=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(S,{...TS([...r,...o,...i],C),children:b}):b})}),h=y=>{const x=w.useContext(a);return w.useCallback(b=>{$e(x[y],b)},[x,y])},p=y=>{const x=w.useContext(a)[y],b=w.useCallback(C=>dt(x,C),[x]);return w.useSyncExternalStore(b,()=>Mt(x),()=>Mt(x))},m=y=>{const x=w.useContext(a)[y],[b,C]=w.useState(Nf(Mt,x));return ni(()=>dt(x,T=>{T!==b&&C(Ef(T))}),[x,b]),b},g=w.version.startsWith("18")?p:m;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];ni(()=>dt(b,x),[x,b])},useEmitterValue:g,usePublisher:h}}const ih=w.createContext(void 0),ah=w.createContext(void 0),lh=typeof document<"u"?w.useLayoutEffect:w.useEffect;function fl(e){return"self"in e}function ES(e){return"body"in e}function ch(e,t,n,r=to,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(h=>{let p,m,g;const y=h.target;if(ES(y)||fl(y)){const b=fl(y)?y:y.defaultView;g=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,m=s?b.innerWidth:b.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]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const 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 b=y-g;if(h.top=Math.ceil(Math.max(Math.min(b,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 IS=lt(()=>{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)=>Qt(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")}}),NS=lt(([e,t])=>({...e,...t}),Tt(oh,IS)),AS=({height:e})=>u.jsx("div",{style:{height:e}}),_S={overflowAnchor:"none",position:pl(),zIndex:1},dh={overflowAnchor:"none"},jS={...dh,display:"inline-block",height:"100%"},fh=w.memo(function({showTopList:e=!1}){const t=Oe("listState"),n=Tn("sizeRanges"),r=Oe("useWindowScroll"),o=Oe("customScrollParent"),s=Tn("windowScrollContainerState"),i=Tn("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=Tn("gap"),g=Oe("horizontalDirection"),{callbackRef:y}=K0(n,h,f,e?to:a,p,m,o,g,Oe("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);gl("deviation",O=>{x!==O&&b(O)});const C=Oe("EmptyPlaceholder"),T=Oe("ScrollSeekPlaceholder")||AS,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,{...en(C,c)}):u.jsx(k,{...en(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 _?w.createElement(T,{...en(T,c),height:O.size,index:O.index,key:R,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?w.createElement(E,{...en(E,c),"data-index":H,"data-item-index":O.index,"data-known-size":O.size,key:R,style:_S},d(O.index,c)):w.createElement(S,{...en(S,c),...MS(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?jS:dh},P?l(O.index,O.groupIndex,O.data,c):l(O.index,O.data,c))})})}),PS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},RS={outline:"none",overflowX:"auto",position:"relative"},ri=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),OS={position:pl(),top:0,width:"100%",zIndex:1};function en(e,t){if(typeof e!="string")return{context:t}}function MS(e,t){return{item:typeof e=="string"?void 0:t}}const DS=w.memo(function(){const e=Oe("HeaderComponent"),t=Tn("headerHeight"),n=Oe("HeaderFooterTag"),r=_r(w.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,Oe("skipAnimationFrameInResizeObserver")),o=Oe("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...en(e,o)})}):null}),LS=w.memo(function(){const e=Oe("FooterComponent"),t=Tn("footerHeight"),n=Oe("HeaderFooterTag"),r=_r(w.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,Oe("skipAnimationFrameInResizeObserver")),o=Oe("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...en(e,o)})}):null});function hh({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback: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?RS:PS,...o},tabIndex:0,...i,...en(l,s),children:r})})}function ph({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=w.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=ch(a,c,l,m,h);return lh(()=>{var b;return y.current=h||((b=p.current)==null?void 0:b.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,...en(l,s),children:r})})}const FS=({children:e})=>{const t=w.useContext(ih),n=Tn("viewportHeight"),r=Tn("fixedItemHeight"),o=Oe("alignToBottom"),s=Oe("horizontalDirection"),i=w.useMemo(()=>If(n,l=>dr(l,s?"width":"height")),[n,s]),a=_r(i,!0,Oe("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:ri(o),children:e})},$S=({children:e})=>{const t=w.useContext(ih),n=Tn("windowViewportRect"),r=Tn("fixedItemHeight"),o=Oe("customScrollParent"),s=Pf(n,o,Oe("skipAnimationFrameInResizeObserver")),i=Oe("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:ri(i),children:e})},zS=({children:e})=>{const t=Oe("TopItemListComponent")||"div",n=Oe("headerHeight"),r={...OS,marginTop:`${n}px`},o=Oe("context");return u.jsx(t,{style:r,...en(t,o),children:e})},BS=w.memo(function(e){const t=Oe("useWindowScroll"),n=Oe("topItemsIndexes").length>0,r=Oe("customScrollParent"),o=Oe("context");return u.jsxs(r||t?WS:US,{...e,context:o,children:[n&&u.jsx(zS,{children:u.jsx(fh,{showTopList:!0})}),u.jsxs(r||t?$S:FS,{children:[u.jsx(DS,{}),u.jsx(fh,{}),u.jsx(LS,{})]})]})}),{Component:HS,useEmitter:gl,useEmitterValue:Oe,usePublisher:Tn}=sh(NS,{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"}},BS),US=hh({useEmitter:gl,useEmitterValue:Oe,usePublisher:Tn}),WS=ph({useEmitter:gl,useEmitterValue:Oe,usePublisher:Tn}),VS=HS;Tt(oh,lt(()=>{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)=>Qt(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},KS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:gh,floor:oi,max:Lo,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 qS(e){return{...KS,items:e}}function si(e,t){return e&&e.width===t.width&&e.height===t.height}function GS(e,t){return e&&e.column===t.column&&e.row===t.row}const YS=lt(([{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:b,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);dt(X(m,He(F),je(([L,G])=>!!G)),()=>{$e(ne,!1)}),dt(X(zt(m,ne,P,_,F,Q),je(([L,G,se,ae,,U])=>L&&!G&&se.height!==0&&ae.height!==0&&!U)),([,,,,L])=>{$e(Q,!0),al(1,()=>{$e(D,L)}),On(X(c),()=>{$e(t,[0,0]),$e(ne,!0)})}),we(X(V,je(L=>L!=null&&L.scrollTop>0),Vn(0)),E),dt(X(m,He(V),je(([,L])=>L!=null)),([,L])=>{L&&($e(_,L.viewport),$e(P,L.item),$e(H,L.gap),L.scrollTop>0&&($e($,!0),On(X(c,Ar(1)),G=>{$e($,!1)}),$e(l,{top:L.scrollTop})))}),we(X(_,pe(({height:L})=>L)),f),we(X(zt(Ae(_,si),Ae(P,si),Ae(H,(L,G)=>L&&L.column===G.column&&L.row===G.row),Ae(c)),pe(([L,G,se,ae])=>({gap:se,item:G,scrollTop:ae,viewport:L}))),R),we(X(zt(Ae(S),r,Ae(H,GS),Ae(P,si),Ae(_,si),Ae(O),Ae(E),Ae($),Ae(ne),Ae(F)),je(([,,,,,,,L])=>!L),pe(([L,[G,se],ae,U,Ue,re,xe,,Re,Le])=>{const{column:nt,row:Se}=ae,{height:Ge,width:rt}=U,{width:Qe}=Ue;if(xe===0&&(L===0||Qe===0))return mh;if(rt===0){const ot=ll(Le,L),on=ot+Math.max(xe-1,0);return qS(xh(ot,on,re))}const Ye=vh(Qe,rt,nt);let Ke,et;Re?G===0&&se===0&&xe>0?(Ke=0,et=xe-1):(Ke=Ye*oi((G+Se)/(Ge+Se)),et=Ye*gh((se+Se)/(Ge+Se))-1,et=yl(L-1,Lo(et,Ye-1)),Ke=yl(et,Lo(0,Ke))):(Ke=0,et=-1);const Dt=xh(Ke,et,re),{bottom:St,top:ft}=wh(Ue,ae,U,Dt),gt=gh(L/Ye),ht=gt*Ge+(gt-1)*Se-St;return{bottom:St,itemHeight:Ge,items:Dt,itemWidth:rt,offsetBottom:ht,offsetTop:ft,top:ft}})),j),we(X(O,je(L=>L!==null),pe(L=>L.length)),S),we(X(zt(_,P,j,H),je(([L,G,{items:se}])=>se.length>0&&G.height!==0&&L.height!==0),pe(([L,G,{items:se},ae])=>{const{bottom:U,top:Ue}=wh(L,ae,G,se);return[Ue,U]}),Et(_o)),t);const Pe=ee(!1);we(X(c,He(Pe),pe(([L,G])=>G||L!==0)),Pe);const J=xn(X(zt(j,S),je(([{items:L}])=>L.length>0),He(Pe),je(([[L,G],se])=>{const ae=L.items[L.items.length-1].index===G-1;return(se||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===G)&&ae}),pe(([[,L]])=>L-1),Et())),ce=xn(X(Ae(j),je(({items:L})=>L.length>0&&L[0].index===0),Vn(0),Et())),Ce=xn(X(Ae(j),He($),je(([{items:L},G])=>L.length>0&&!G),pe(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),Et($f),tr(0)));we(Ce,p.scrollSeekRangeChanged),we(X(D,He(_,P,S,H),pe(([L,G,se,ae,U])=>{const Ue=Vf(L),{align:re,behavior:xe,offset:Re}=Ue;let Le=Ue.index;Le==="LAST"&&(Le=ae-1),Le=Lo(0,Le,yl(ae-1,Le));let nt=xl(G,U,se,Le);return re==="end"?nt=yh(nt-G.height+se.height):re==="center"&&(nt=yh(nt-G.height/2+se.height/2)),Re&&(nt+=Re),{behavior:xe,top:nt}})),l);const te=Qt(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:b,windowScrollTo:C,windowViewportRect:T,...p,gridState:j,horizontalDirection:ye,initialTopMostItemIndex:F,totalListHeight:te,...h,endReached:J,propsReady:g,rangeChanged:Ce,startReached:ce,stateChanged:R,stateRestoreInProgress:$,...k}},Tt(cl,rn,Do,nh,fr,dl,ur));function vh(e,t,n){return Lo(1,oi((e+n)/(oi(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=oi(r/o),i=s*n.height+Lo(0,s-1)*t.row;return i>0?i+t.row:i}const XS=lt(()=>{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)=>Qt(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")}}),JS=lt(([e,t])=>({...e,...t}),Tt(YS,XS)),ZS=w.memo(function(){const e=Nt("gridState"),t=Nt("listClassName"),n=Nt("itemClassName"),r=Nt("itemContent"),o=Nt("computeItemKey"),s=Nt("isSeeking"),i=En("scrollHeight"),a=Nt("ItemComponent"),l=Nt("ListComponent"),c=Nt("ScrollSeekPlaceholder"),d=Nt("context"),f=En("itemDimensions"),h=En("gap"),p=Nt("log"),m=Nt("stateRestoreInProgress"),g=En("reportReadyState"),y=_r(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);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,...en(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?u.jsx(c,{...en(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{...en(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),QS=w.memo(function(){const e=Nt("HeaderComponent"),t=En("headerHeight"),n=Nt("headerFooterTag"),r=_r(w.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,!1),o=Nt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...en(e,o)})}):null}),eC=w.memo(function(){const e=Nt("FooterComponent"),t=En("footerHeight"),n=Nt("headerFooterTag"),r=_r(w.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,!1),o=Nt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...en(e,o)})}):null}),tC=({children:e})=>{const t=w.useContext(ah),n=En("itemDimensions"),r=En("viewportDimensions"),o=_r(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:ri(!1),children:e})},nC=({children:e})=>{const t=w.useContext(ah),n=En("windowViewportRect"),r=En("itemDimensions"),o=Nt("customScrollParent"),s=Pf(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:ri(!1),children:e})},rC=w.memo(function({...e}){const t=Nt("useWindowScroll"),n=Nt("customScrollParent"),r=n||t?sC:oC,o=n||t?nC:tC,s=Nt("context");return u.jsx(r,{...e,...en(r,s),children:u.jsxs(o,{children:[u.jsx(QS,{}),u.jsx(ZS,{}),u.jsx(eC,{})]})})}),{useEmitter:bh,useEmitterValue:Nt,usePublisher:En}=sh(JS,{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"}},rC),oC=hh({useEmitter:bh,useEmitterValue:Nt,usePublisher:En}),sC=ph({useEmitter:bh,useEmitterValue:Nt,usePublisher:En});function Sh(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,fn.WARN),t==="normal"?0:parseInt(t??"0",10)}const iC=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 Ch({className:e,variant:t,...n}){return u.jsx("div",{className:oe(iC({variant:t}),e),...n})}const Fo=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}));Fo.displayName="Card";const $o=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));$o.displayName="CardHeader";const zo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));zo.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 Bo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));Bo.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 aC=1,lC=1e6;let vl=0;function cC(){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),Ho({type:"REMOVE_TOAST",toastId:e})},lC);wl.set(e,t)},uC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,aC)};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)}}},ii=[];let ai={toasts:[]};function Ho(e){ai=uC(ai,e),ii.forEach(t=>{t(ai)})}function dC({...e}){const t=cC(),n=o=>Ho({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Ho({type:"DISMISS_TOAST",toastId:t});return Ho({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(ai);return v.useEffect(()=>(ii.push(t),()=>{const n=ii.indexOf(t);n>-1&&ii.splice(n,1)}),[e]),{...e,toast:dC,dismiss:n=>Ho({type:"DISMISS_TOAST",toastId:n})}}async function Ih(e,t){return await bn(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 fC(e,t){const n=await Ih(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await bn(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function hC(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await bn("/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 Uo(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Uo).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=Uo(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 Wo(e){if(typeof e=="string")return e;if(Ah(e))return"";try{const t=Uo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function pC(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function mC(e){const t=Wo(e);return typeof e=="string"&&pC(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function li(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 li(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?li(e.content):e}var ci="Dialog",[_h,KT]=Jn(ci),[gC,Dn]=_h(ci),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]=Vr({prop:r,defaultProp:o??!1,onChange:s,caller:ci});return u.jsx(gC,{scope:t,triggerRef:a,contentRef:l,contentId:Zn(),titleId:Zn(),descriptionId:Zn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};jh.displayName=ci;var Ph="DialogTrigger",Rh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(Ph,n),s=Je(t,o.triggerRef);return u.jsx(Me.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",[yC,Oh]=_h(Cl,{forceMount:void 0}),Mh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Dn(Cl,t);return u.jsx(yC,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Cn,{present:n||s.open,children:u.jsx(js,{asChild:!0,container:o,children:i})}))})};Mh.displayName=Cl;var ui="DialogOverlay",Dh=v.forwardRef((e,t)=>{const n=Oh(ui,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Dn(ui,e.__scopeDialog);return s.modal?u.jsx(Cn,{present:r||s.open,children:u.jsx(vC,{...o,ref:t})}):null});Dh.displayName=ui;var xC=br.createSlot("DialogOverlay.RemoveScroll"),vC=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(ui,n);return u.jsx(zs,{as:xC,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Me.div,{"data-state":Tl(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Rr="DialogContent",Lh=v.forwardRef((e,t)=>{const n=Oh(Rr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Dn(Rr,e.__scopeDialog);return u.jsx(Cn,{present:r||s.open,children:s.modal?u.jsx(wC,{...o,ref:t}):u.jsx(bC,{...o,ref:t})})});Lh.displayName=Rr;var wC=v.forwardRef((e,t)=>{const n=Dn(Rr,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())})}),bC=v.forwardRef((e,t)=>{const n=Dn(Rr,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=Dn(Rr,n),l=v.useRef(null),c=Je(t,l);return ya(),u.jsxs(u.Fragment,{children:[u.jsx(vs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(xs,{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(SC,{titleId:a.titleId}),u.jsx(kC,{contentRef:l,descriptionId:a.descriptionId})]})]})}),kl="DialogTitle",$h=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(kl,n);return u.jsx(Me.h2,{id:o.titleId,...r,ref:t})});$h.displayName=kl;var zh="DialogDescription",Bh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(zh,n);return u.jsx(Me.p,{id:o.descriptionId,...r,ref:t})});Bh.displayName=zh;var Hh="DialogClose",Uh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(Hh,n);return u.jsx(Me.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",[qT,Vh]=Ix(Wh,{contentName:Rr,titleName:kl,docsSlug:"dialog"}),SC=({titleId:e})=>{const t=Vh(Wh),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},
|
|
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},CC="DialogDescriptionWarning",kC=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Vh(CC).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,TC=Rh,qh=Mh,di=Dh,fi=Lh,Or=$h,hi=Bh,Gh=Uh;const EC=Kh,IC=qh,Yh=v.forwardRef(({className:e,...t},n)=>u.jsx(di,{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=di.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===Or||(c==null?void 0:c.displayName)===Or.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(IC,{children:[u.jsx(Yh,{}),u.jsxs(fi,{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(Or,{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=fi.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(Or,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",e),...t}));Zh.displayName=Or.displayName;const NC=v.forwardRef(({className:e,...t},n)=>u.jsx(hi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));NC.displayName=hi.displayName;function AC({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=bl(),h=w.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]);w.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await fC(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),b=new Blob([x],{type:o}),C=URL.createObjectURL(b);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(EC,{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(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 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 Mr=Qh();function _C(e){Mr=e}const ep=/[&<>"']/,jC=new RegExp(ep.source,"g"),tp=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,PC=new RegExp(tp.source,"g"),RC={"&":"&","<":"<",">":">",'"':""","'":"'"},np=e=>RC[e];function tn(e,t){if(t){if(ep.test(e))return e.replace(jC,np)}else if(tp.test(e))return e.replace(PC,np);return e}const OC=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function rp(e){return e.replace(OC,(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 MC=/(^|[^\[])\^/g;function vt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(MC,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const DC=/[^\w:]/g,LC=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function op(e,t,n){if(e){let r;try{r=decodeURIComponent(rp(n)).replace(DC,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!LC.test(n)&&(n=BC(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const pi={},FC=/^[^:]+:\/*[^/]*$/,$C=/^([^:]+:)[\s\S]*$/,zC=/^([^:]+:\/*[^/]*)[\s\S]*$/;function BC(e,t){pi[" "+e]||(FC.test(e)?pi[" "+e]=e+"/":pi[" "+e]=gi(e,"/",!0)),e=pi[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace($C,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(zC,"$1")+t:e+t}const mi={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 gi(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 HC(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 UC(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?tn(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:tn(i)}}function WC(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||
|
|
93
|
-
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=
|
|
92
|
+
`)}class El{constructor(t){this.options=t||Mr}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:gi(r,`
|
|
93
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=WC(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=gi(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 b=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(m=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
94
94
|
`,1)[0].replace(/^\t+/,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]):
|
|
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]=
|
|
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:
|
|
103
|
-
]`).replace("lheading",
|
|
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]):tn(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:tn(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]):tn(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=gi(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=HC(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=tn(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=tn(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=tn(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=tn(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=tn(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]):tn(r[0]):r[0]:o=tn(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const Te={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:mi,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};Te._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Te._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,Te.def=vt(Te.def).replace("label",Te._label).replace("title",Te._title).getRegex(),Te.bullet=/(?:[*+-]|\d{1,9}[.)])/,Te.listItemStart=vt(/^( *)(bull) */).replace("bull",Te.bullet).getRegex(),Te.list=vt(Te.list).replace(/bull/g,Te.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+Te.def.source+")").getRegex(),Te._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Te._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,Te.html=vt(Te.html,"i").replace("comment",Te._comment).replace("tag",Te._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Te.paragraph=vt(Te._paragraph).replace("hr",Te.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Te._tag).getRegex(),Te.blockquote=vt(Te.blockquote).replace("paragraph",Te.paragraph).getRegex(),Te.normal={...Te},Te.gfm={...Te.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},Te.gfm.table=vt(Te.gfm.table).replace("hr",Te.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Te._tag).getRegex(),Te.gfm.paragraph=vt(Te._paragraph).replace("hr",Te.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",Te.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Te._tag).getRegex(),Te.pedantic={...Te.normal,html:vt(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Te._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:mi,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:vt(Te.normal._paragraph).replace("hr",Te.hr).replace("heading",` *#{1,6} *[^
|
|
103
|
+
]`).replace("lheading",Te.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const me={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:mi,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:mi,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};me._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",me.punctuation=vt(me.punctuation).replace(/punctuation/g,me._punctuation).getRegex(),me.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,me.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,me._comment=vt(Te._comment).replace("(?:-->|$)","-->").getRegex(),me.emStrong.lDelim=vt(me.emStrong.lDelim).replace(/punct/g,me._punctuation).getRegex(),me.emStrong.rDelimAst=vt(me.emStrong.rDelimAst,"g").replace(/punct/g,me._punctuation).getRegex(),me.emStrong.rDelimUnd=vt(me.emStrong.rDelimUnd,"g").replace(/punct/g,me._punctuation).getRegex(),me._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,me._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,me._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,me.autolink=vt(me.autolink).replace("scheme",me._scheme).replace("email",me._email).getRegex(),me._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,me.tag=vt(me.tag).replace("comment",me._comment).replace("attribute",me._attribute).getRegex(),me._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,me._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,me._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,me.link=vt(me.link).replace("label",me._label).replace("href",me._href).replace("title",me._title).getRegex(),me.reflink=vt(me.reflink).replace("label",me._label).replace("ref",Te._label).getRegex(),me.nolink=vt(me.nolink).replace("ref",Te._label).getRegex(),me.reflinkSearch=vt(me.reflinkSearch,"g").replace("reflink",me.reflink).replace("nolink",me.nolink).getRegex(),me.normal={...me},me.pedantic={...me.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:vt(/^!?\[(label)\]\((.*?)\)/).replace("label",me._label).getRegex(),reflink:vt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",me._label).getRegex()},me.gfm={...me.normal,escape:vt(me.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},me.gfm.url=vt(me.gfm.url,"i").replace("email",me.gfm._extended_email).getRegex(),me.breaks={...me.gfm,br:vt(me.br).replace("{2,}","*").getRegex(),text:vt(me.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function VC(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||Mr,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:Te.normal,inline:me.normal};this.options.pedantic?(n.block=Te.pedantic,n.inline=me.pedantic):this.options.gfm&&(n.block=Te.gfm,this.options.breaks?n.inline=me.breaks:n.inline=me.gfm),this.tokenizer.rules=n}static get rules(){return{block:Te,inline:me}}static lex(t,n){return new 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)+"["+
|
|
114
|
-
`,o?'<pre><code class="'+this.options.langPrefix+
|
|
115
|
-
`:"<pre><code>"+(r?t:
|
|
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,VC)){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||Mr}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+tn(o)+'">'+(r?t:tn(t,!0))+`</code></pre>
|
|
115
|
+
`:"<pre><code>"+(r?t:tn(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=
|
|
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
|
|
135
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+
|
|
136
|
-
`)):r=t(e),r||""}function
|
|
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"}})});
|
|
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||Mr,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,b,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++)b=p.items[s],C=b.checked,T=b.task,x="",b.task&&(k=this.renderer.checkbox(C),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=k+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=k+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:k}):x+=k),x+=this.parse(b.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 yi{constructor(t){this.options=t||Mr}preprocess(t){return t}postprocess(t){return t}}Jm(yi,"passThroughHooks",new Set(["preprocess","postprocess"]));function KC(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>"+tn(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=KC(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(UC(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},_C(be.defaults),be},be.getDefaults=Qh,be.defaults=Mr,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 yi;for(const s in n.hooks){const i=o[s];yi.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=yi,be.parse=be,be.options,be.setOptions,be.use,be.walkTokens,be.parseInline,pr.parse,hr.lex;function Vo({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof 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=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:oe("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const qC="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 GC(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 xi(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function YC(e){const t=o=>{try{const s=Uo(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 XC(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 JC({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:oe("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Nl=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,customStyles:h={},onEdit:p,onRegenerate:m,onCancelEdit:g,onCopy:y,activeInterrupt:x,disableInterruptActions:b=!1,onInterruptActionStart:C,onInterruptActionEnd:T,checkpointCandidates:k=[],activeCheckpointId:S=null,onSelectCheckpoint:E,defaultCheckpointId:j=null,messageParentCheckpointId:_=null}){const[P,D]=w.useState(!1),[z,B]=w.useState("preview"),[O,H]=w.useState(!1),{currentThreadId:R}=ps(),{respondToInterrupt:V}=ms(),$=l==="phone"||l==="half-screen",F=t.role,ne=F==="tool",Q=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!Q,Pe=!(r&&F!=="user"),{uploadingFiles:J,handleFileClick:ce,fileViewerOpen:Ce,currentFileInfo:te,closeFileViewer:L}=QC({allowFileOpen:Pe,currentThreadId:R}),G=w.useMemo(()=>{switch(F){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[F]),se=w.useMemo(()=>Q?"":GC(t.content),[Q,t]),ae=w.useMemo(()=>Q?{}:fp(t),[Q,t]),U=w.useMemo(()=>Q?[]:t.content.filter(Y=>Y.type==="image_url"),[Q,t]),Ue=w.useMemo(()=>Q?[]:t.content.filter(Y=>Y.type==="file"),[Q,t]),re=w.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=xi(xe),Le=x==null?void 0:x.value,nt=w.useMemo(()=>Q?"":YC(t.content),[Q,t]),Se=w.useCallback(async()=>{const Y=ne?nt:se;async function Ee(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 it=new Blob([ve],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":it})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Ee(Y),D(!0),setTimeout(()=>D(!1),2e3),y==null||y(Y)}catch(ve){console.error("Failed to copy:",ve)}},[ne,nt,se,y]),Ge=w.useCallback(()=>{if(!p)return;const Y=ne?nt:se,Ee="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};p(t.id,Y,Ee)},[p,t.id,ne,nt,se,t]),rt=w.useCallback(()=>{m==null||m(n)},[m,n]),Qe=w.useCallback(()=>{const Ee=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:Ee});case"assistant":return u.jsx(he.Bot,{className:Ee});case"tool":return u.jsx(he.Wrench,{className:Ee});default:return u.jsx(he.Bot,{className:Ee})}},[$,G,F]),Ye=w.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]),Ke=w.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(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",G)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(Vo,{content:Q.content,className:"text-current"})]})});const et=w.useCallback(async Y=>{if(b)return;const Ee=xi((Y==null?void 0:Y.id)??(Y==null?void 0:Y.interrupt_id));if(!Ee){console.warn("Interrupt part missing id",Y);return}try{C==null||C(),await V(Ee,!0)}catch(ve){console.error("Failed to approve interrupt:",ve)}finally{T==null||T()}},[b,T,C,V]),Dt=w.useCallback(async Y=>{if(b)return;const Ee=xi((Y==null?void 0:Y.id)??(Y==null?void 0:Y.interrupt_id));if(!Ee){console.warn("Interrupt part missing id",Y);return}try{C==null||C(),await V(Ee,!1)}catch(ve){console.error("Failed to reject interrupt:",ve)}finally{T==null||T()}},[b,T,C,V]),St=w.useCallback(({part:Y,i:Ee})=>{if(Y.type==="text"){const ve=Y.text??"",it=ve.trim(),yt=Sl(it);return yt&&F!=="tool"?u.jsx(pp,{data:yt},Ee):F==="user"&&c&&it.length>d?u.jsx(ek,{text:it,expanded:O,onExpandedChange:H,previewLength:d,isCompact:$},Ee):u.jsx(Vo,{content:ve,allowHtml:!1},Ee)}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"})},Ee)}if(Y.type==="file"){const ve=Y,it=ve.name||"file";return u.jsxs("a",{href:ve.url,onClick:yt=>ce(yt,ve,Ee),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[Ee]?u.jsx(he.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[it,J[Ee]?" (processing)":""]})]},Ee)}if(Y.type==="interrupt"){const ve=Y,it=xi((ve==null?void 0:ve.id)??(ve==null?void 0:ve.interrupt_id)),yt=!!(Re&&it&&it===Re),It=yt?Le??(ve==null?void 0:ve.value):ve==null?void 0:ve.value,Ne=it?{...ve,id:it,interrupt_id:it}:ve;return u.jsx(ZC,{interruptPart:Ne,onApprove:et,onReject:Dt,disabled:b,isActive:yt,payload:It},Ee)}return null},[ce,J,et,Dt,F,c,d,O,$,Re,Le,x,b,re]),ft=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(he.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),gt=w.useCallback(()=>{const Y=se.trim().length>0||U.length>0||Ue.length>0||re.length>0;if(!ne&&Ue.length>0&&!r)return ft();if(!ne&&!Y&&!r)return null;if(ne)return u.jsx(tk,{message:t,viewMode:z},t.id);if(!ne&&!Q){const Ee=t,ve=u.jsx("div",{className:"space-y-2",children:Ee.content.map((it,yt)=>u.jsx(St,{part:it,i:yt},yt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ve,u.jsx(JC,{className:G})]}):ve}},[se,U.length,Ue.length,re.length,r,ne,z,ft,G]),ht=w.useMemo(()=>Q?"Assistant":XC(t),[Q,t]),ot=w.useMemo(()=>Q?[]:Array.isArray(k)?k:[],[k,Q]),on=w.useMemo(()=>{var Y;return ot.length?j&&ot.some(Ee=>Ee.id===j)?j:((Y=ot[0])==null?void 0:Y.id)??null:null},[j,ot]),Kt=w.useMemo(()=>!ot.length||!S?null:ot.some(Y=>Y.id===S)?S:null,[S,ot])??on,Bt=F==="user"&&ot.length>0&&typeof E=="function",pt=w.useCallback(Y=>{if(!E)return;const Ee=(Y==null?void 0:Y.id)??null,ve=(Y==null?void 0:Y.parentId)??_??null;E(Ee,ve)},[_,E]),We=w.useMemo(()=>Kt?ot.findIndex(Y=>Y.id===Kt):-1,[Kt,ot]),Lt=w.useMemo(()=>We<0?null:ot[We]??null,[We,ot]),_t=w.useCallback(Y=>{const Ee=[];if(Y.step!==null&&Ee.push(`Step ${Y.step}`),Y.source&&Ee.push(Y.source),!Y.createdAt)return Ee.length?Ee.join(" • "):Y.id.slice(0,8);let ve="";try{const it=new Date(Y.createdAt);Number.isNaN(it.getTime())||(ve=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(it))}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(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",G,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Qe(),a&&ht&&u.jsx("span",{className:oe("font-medium",$?"text-xs":"text-sm"),children:ht}),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(Ee=>Ee==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ae.name??"Tool Output"}),ae.toolCallId&&u.jsx("span",{className:"opacity-70",children:ae.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:[Bt&&Lt&&We>=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",We>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(We<=0)return;const Y=ot[We-1];Y&&pt(Y)},"aria-label":"Previous checkpoint",disabled:We<=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:[We+1," / ",ot.length]}),u.jsx("span",{className:"text-muted-foreground",children:_t(Lt)})]}),u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",We<ot.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(We>=ot.length-1)return;const Y=ot[We+1];Y&&pt(Y)},"aria-label":"Next checkpoint",disabled:We>=ot.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(ut,{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(ut,{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(ut,{variant:"ghost",size:"sm",onClick:rt,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:gt()}),ne&&z==="expanded"&&(ae.toolCallId||ae.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",$&&"text-xs"),children:[ae.name&&u.jsxs("div",{children:["Function: ",ae.name]}),ae.toolCallId&&u.jsxs("div",{children:["Call ID: ",ae.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: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(ut,{variant:"ghost",size:"sm",onClick:rt,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(AC,{isOpen:Ce,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:qC,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:Wo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Wo(e)})}function ZC({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=Wo(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(Fo,{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($o,{className:"pb-3",children:[u.jsx(zo,{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(Bo,{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(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 QC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=bl(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,m,g)=>{var y,x;if(!t){p.preventDefault();return}if(o[g]){p.preventDefault();return}try{const b=String(m.url??""),C=b.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(b.startsWith("data:")){p.preventDefault(),s(k=>({...k,[g]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await hC(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(b){console.error("File click error:",b),s(C=>({...C,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function ek({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(Vo,{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 tk({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 Wo(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}=mC(c);return f?u.jsx(Vo,{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=li(d);return s(f)}const a=Uo(i),l=li(a);return s(l)}const mp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,nk=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=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:m=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:S=!0,checkpointMetaById:E,checkpointIndexByKey:j,activeCheckpointId:_,onSelectCheckpoint:P,timelineCheckpoints:D},z)=>{const B=w.useRef(null),O=w.useRef(null),H=w.useRef(!1),[R,V]=w.useState(!0),$=w.useMemo(()=>b?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),F=w.useMemo(()=>{if(!b||$)return null;const re=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const Re=b.value;if(Re&&typeof Re=="object"&&!Array.isArray(Re)){const Le=Re.title;typeof Le=="string"&&Le.trim()&&(xe=Le.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Re,title:xe}]}},[b,$]),ne=w.useMemo(()=>F?[...e,F]:e,[e,F]),Q=w.useMemo(()=>S?ne:ne.filter(re=>(re==null?void 0:re.role)!=="tool"),[ne,S]),ye=w.useMemo(()=>{const re=new Set,xe=[];for(let Re=Q.length-1;Re>=0;Re--){const Le=Q[Re];if(!Le)continue;if("type"in Le&&Le.type==="default_message"){xe.push(Le);continue}const nt=Le,Se=nk(nt);re.has(Se)||(re.add(Se),xe.push(nt))}return xe.reverse()},[Q]),Pe=w.useCallback(re=>{V(re),y&&y(!re),x&&x(re)},[y,x]),J=w.useMemo(()=>{if(a)return async()=>{if(!H.current){H.current=!0;try{await a()}finally{H.current=!1}}}},[a]),ce=w.useMemo(()=>!m||g?!1:R?"auto":!1,[R,m,g]),Ce=w.useMemo(()=>D??[],[D]),te=_??(Ce.length?Ce[Ce.length-1].id:null),L=Ce.length>0,G=w.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:Ce.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,ae=["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!"}),Ue=ye.length>0;return w.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:ae,style:h,children:[se,u.jsx("div",{className:"relative flex-1 min-h-0",children:Ue?u.jsx(VS,{ref:re=>{B.current=re},scrollerRef:re=>{O.current=re instanceof HTMLDivElement?re:null},data:ye,followOutput:ce,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{J&&J()},atBottomStateChange:Pe,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>mp(xe,re),itemContent:(re,xe)=>{var et;const Re=mp(xe,re),Le="type"in xe&&xe.type==="default_message";let nt=[],Se=null,Ge={},rt={},Qe=null,Ye=null;if(!Le){const Dt=xe,St=Dt.checkpointId??null;Ge=Dt.additionalKwargs??{},rt=Dt.responseMetadata??{};const ft=St&&E?E.get(St)??null:null;Qe=typeof Ge.step=="number"?Ge.step:typeof rt.step=="number"?rt.step:(ft==null?void 0:ft.step)??null;const gt=typeof Ge.source=="string"?Ge.source:typeof rt.source=="string"?rt.source:(ft==null?void 0:ft.source)??null;Ye=gt?String(gt):null;const ht=Qe!==null&&Ye?`${Qe}:${Ye}`:null;ht&&(j!=null&&j.has(ht))?nt=j.get(ht)??[]:St&&ft&&(nt=[ft]),Se=St??((et=nt[0])==null?void 0:et.id)??null}const Ke=(()=>{if(typeof Ge.parentCheckpointId=="string")return Ge.parentCheckpointId;if(typeof rt.parentCheckpointId=="string")return rt.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:b,disableInterruptActions:C,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:S,checkpointCandidates:nt,activeCheckpointId:_??null,onSelectCheckpoint:P,defaultCheckpointId:Se,messageParentCheckpointId:Ke})})}}):U()})]})});Al.displayName="MessageList";const gp={value:""};function vi({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,customStyles:f={},onMessageSent:h,onExcelUploadSuccess:p,onError:m}){const{api:g}=Xi(),{currentThreadId:y}=ps(),{threadId:x,messages:b,hasMore:C,isHistoryLoading:T,isLoading:k,loadOlder:S,navigateToCheckpoint:E,returnToLatest:j,checkpoint:_,checkpoints:P,interrupt:D,metadata:z}=ms(),{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,J]=w.useState(!1);w.useEffect(()=>{ye||J(!1)},[ye]);const ce=w.useCallback(()=>{J(!0)},[]),Ce=w.useCallback(()=>{J(!1)},[]),te=!!ye||Pe,[L,G]=w.useState(null),[se,ae]=w.useState(""),[U,Ue]=w.useState(null),[re,xe]=w.useState(null),[Re,Le]=w.useState([]),[nt,Se]=w.useState(0),[Ge,rt]=w.useState(0),[Qe,Ye]=w.useState(!1),[Ke,et]=w.useState(null),[Dt,St]=w.useState(null),[ft,gt]=w.useState(!1),[ht,ot]=w.useState(null),[on,sn]=w.useState(!1),Kt=w.useRef(!1),[Bt,pt]=w.useState(()=>gp.value),We=w.useRef(Bt),Lt=w.useRef(null),_t=w.useCallback(Z=>{gp.value=Z,pt(Z)},[]),[Y,Ee]=w.useState(!1),ve=w.useRef(null),it=w.useCallback(Z=>{if(!Array.isArray(Z))return{text:null,messageId:null};for(let le=Z.length-1;le>=0;le--){const de=Z[le];if(!de||de.role!=="user")continue;const Ie=(de.content??[]).filter(Ve=>(Ve==null?void 0:Ve.type)==="text").map(Ve=>Ve.text).filter(Ve=>typeof Ve=="string"&&Ve.trim().length>0);return{text:Ie.length?Ie.join(" ").trim():null,messageId:de.id??null}}return{text:null,messageId:null}},[]),yt=w.useCallback((Z,le)=>{if(!Z||typeof Z!="object")return null;const de=Z[le];return typeof de=="number"?de:null},[]),It=w.useCallback((Z,le)=>{if(!Z||typeof Z!="object")return null;const de=Z[le];return typeof de=="string"&&de.trim()?de:null},[]),Ne=w.useMemo(()=>{const Z=Ie=>{if(!Array.isArray(Ie)||Ie.length===0)return null;const Xe=Ie.map(Ve=>{if(typeof Ve=="string")return Ve.trim();if(Ve&&typeof Ve=="object"&&"type"in Ve){const st=Ve;if(typeof st.type=="string")return st.type}return null}).filter(Ve=>!!(Ve&&Ve.length));return Xe.length?Xe.join(", "):null},le=Array.isArray(P)?P.map(Ie=>{const Xe=Z(Ie.next);return Xe?{...Ie,metadata:{...Ie.metadata??{},next:Xe}}:Ie}):[];return le.some(Ie=>yt(Ie.metadata,"step")!==null)&&le.sort((Ie,Xe)=>{const Ve=yt(Ie.metadata,"step"),st=yt(Xe.metadata,"step");if(Ve!==null||st!==null)return(st??Number.NEGATIVE_INFINITY)-(Ve??Number.NEGATIVE_INFINITY);const Pt=Date.parse(Ie.createdAt??""),pn=Date.parse(Xe.createdAt??"");return Number.isNaN(Pt)||Number.isNaN(pn)?0:pn-Pt}),le},[P,yt]),{checkpointMetaById:Ut,checkpointIndexByKey:at}=w.useMemo(()=>{const Z=new Map,le=new Map;for(const de of Ne){const Ie=de.checkpointId??null;if(!Ie)continue;const Xe=yt(de.metadata,"step"),Ve=It(de.metadata,"source"),st={id:Ie,step:Xe,source:Ve,createdAt:de.createdAt??null,namespace:de.checkpointNs??null,parentId:de.parentId??null};if(Z.set(Ie,st),Xe!==null&&Ve){const Pt=`${Xe}:${Ve}`,pn=le.get(Pt)??[];pn.push(st),le.set(Pt,pn)}}for(const de of le.values())de.sort((Ie,Xe)=>{const Ve=Ie.createdAt??"";return(Xe.createdAt??"").localeCompare(Ve)});return{checkpointMetaById:Z,checkpointIndexByKey:le}},[Ne,yt,It]),At=w.useMemo(()=>{var Ve;if(!Ne.length)return[];const Z=[...Ne].reverse(),le=(st,Pt)=>{const pn=st.checkpointId??null;if(!pn)return null;const rr=It(st.metadata,"source");It(st.metadata,"next");const{text:_i,messageId:ji}=it(st.messages),lo=_i&&_i.replace(/\s+/g," ").trim()||It(st.metadata,"title")||It(st.metadata,"label")||Pt||rr||"Checkpoint",Pi=lo.length>60?`${lo.slice(0,57)}…`:lo;return{id:pn,label:Pi,messageId:ji??null,createdAt:st.createdAt??null,step:yt(st.metadata,"step"),source:rr??null,next:It(st.metadata,"next")}},de=[],Ie=new Set;for(const st of Z){const Pt=((Ve=It(st.metadata,"source"))==null?void 0:Ve.toLowerCase())??null;if(!(Pt==="input"||Pt==="user_input"||Pt==="user"))continue;const rr=le(st,"User input");rr&&!Ie.has(rr.id)&&(de.push(rr),Ie.add(rr.id))}if(!de.length)for(const st of Z){const Pt=le(st);Pt&&!Ie.has(Pt.id)&&(de.push(Pt),Ie.add(Pt.id))}const Xe=Ne.find(st=>{var pn;return(((pn=It(st.metadata,"source"))==null?void 0:pn.toLowerCase())??null)==="loop"});if(Xe){const st=le(Xe,"Latest loop");st&&!Ie.has(st.id)&&(de.push(st),Ie.add(st.id))}return de},[Ne,it,yt,It]),An=w.useRef(null),jt=w.useRef(null),an=w.useCallback(()=>{An.current&&(An.current.value=""),jt.current&&(jt.current.value=""),Se(Z=>Z+1),rt(Z=>Z+1)},[]),io=w.useCallback(Z=>{_t(Z)},[_t]),qt=w.useRef(!1);w.useEffect(()=>{qt.current&&!B&&(Le([]),an()),qt.current=B},[B,an]);const[nr,ao]=w.useState("desktop");w.useEffect(()=>{const Z=()=>{const le=window.innerWidth;ao(le<640?"phone":le<1024?"tablet":"desktop")};return Z(),window.addEventListener("resize",Z),()=>window.removeEventListener("resize",Z)},[]),w.useEffect(()=>{sn(!1),Kt.current=!1},[$]),w.useEffect(()=>{We.current=Bt},[Bt]),w.useEffect(()=>{if(!L){Lt.current=null;return}Lt.current===null&&(Lt.current=We.current),_t(se??"")},[se,L,_t]);const N=w.useCallback(async()=>{if(!(!C||T||!on))try{await S()}catch(Z){console.warn("loadOlder failed",Z)}},[C,on,T,S]);w.useEffect(()=>{(async()=>{if(!g.baseUrl){ot(null);return}try{const de=(await g.getAgent("default")).uiDefaultMessage||"";ot(de||null)}catch(le){console.warn("Failed to fetch default message:",le),ot(null)}})()},[g.baseUrl]),w.useEffect(()=>{O&&!ft&&(m==null||m(O))},[O,ft,m]);const q=Z=>{if(Z.length>Ks)return`Message too long (${Z.length}/${Ks} characters)`;try{return M0(Z),null}catch(le){return(le==null?void 0:le.message)||"Invalid message"}},ue=async Z=>{const le=Z.trim();if(!(!le&&Re.length===0)){if(le){const de=q(le);if(de){xe(de);return}}try{const de=F??void 0,Ie=ne??void 0,Xe=L?{edit:!0,originalMessageId:L,...U!=null&&U.checkpointId?{originalCheckpointId:U.checkpointId}:{},...U!=null&&U.checkpointNs?{originalCheckpointNs:U.checkpointNs}:{}}:void 0;await R({text:le||"",attachments:Re,messageAdditionalKwargs:Xe},{checkpointId:de,checkpointNs:Ie}),h==null||h(le),_t(""),xe(null),Le([]),an(),G(null),ae(""),Ue(null)}catch(de){const Ie=(de==null?void 0:de.message)||"Failed to send message";xe(Ie),m==null||m(Ie)}}},ke=w.useCallback((Z,le,de)=>{c&&(Lt.current=Bt,G(Z),ae(le),_t(le),xe(null),Ue({checkpointId:(de==null?void 0:de.checkpointId)??null,checkpointNs:(de==null?void 0:de.checkpointNs)??null}))},[Bt,c,_t]),qe=w.useCallback(()=>{G(null),ae(""),Ue(null),xe(null),_t(Lt.current??Bt),Lt.current=null},[Bt,_t]),tt=w.useCallback((Z,le,de)=>{ke(Z,le,de)},[ke]),Fe=w.useCallback(Z=>{for(let le=Z-1;le>=0;le--)if(b[le].role==="user"){const de=b[le].content||[],Xe=de.filter(Ve=>Ve.type==="text").map(Ve=>Ve.text).join("")||(()=>{try{return JSON.stringify(de,null,2)}catch{return String(de)}})();Xe&&R({text:Xe},{checkpointId:F??void 0,checkpointNs:ne??void 0});break}},[b,R,F,ne]),ze=Z=>{const le=Array.from(Z.target.files||[]);Le(de=>[...de,...le]),Z.target.value=""},Ct=Z=>{Le(le=>{const de=le.filter((Ie,Xe)=>Z!==Xe);return de.length===0&&an(),de})},wt=async Z=>{const le=(Z.target.files||[])[0];if(le){et(null),St(null),Ye(!0);try{await R({attachments:[le]},{checkpointId:F??void 0,checkpointNs:ne??void 0});const de=`Uploaded ${le.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),et(Ie),m==null||m(Ie)}finally{Ye(!1),Z.target.value="",an()}}},ct=async Z=>{if(y){Ee(!0);try{if(!Z){await j(),sn(!1),requestAnimationFrame(()=>{var Ie;(Ie=ve.current)==null||Ie.scrollToLatest()});return}const le=Ne.find(Ie=>Ie.checkpointId===Z),de=(le==null?void 0:le.checkpointNs)??null;await E(Z,de),sn(!0),requestAnimationFrame(()=>{var Ie;(Ie=ve.current)==null||Ie.scrollToTop()})}finally{Ee(!1)}}},Ft=w.useCallback(async Z=>{await ct(Z)},[ct]),hn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,Fn=`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||""}`,Wt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,xr=w.useCallback(Z=>{if(!Z)return"Latest";const le=[];Z.step!==null&&le.push(`Step ${Z.step}`),Z.source&&le.push(Z.source);const de=Z.createdAt?new Date(Z.createdAt):null,Ie=de&&!Number.isNaN(de.getTime())?de.toLocaleString():Z.createdAt??Z.id,Xe=le.length?` — ${le.join(" • ")}`:"";return`${Ie}${Xe}`},[]);return u.jsxs("div",{className:hn,children:[!!O&&!ft&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:O}),u.jsx(ut,{variant:"ghost",size:"sm",onClick:()=>gt(!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:Z=>{const le=Z.target.value||null;ct(le)},children:[u.jsx("option",{value:"",children:"Latest"}),Ne.map(Z=>{const le=Ut.get(Z.checkpointId??"")??null;return u.jsx("option",{value:Z.checkpointId??void 0,children:xr(le)},Z.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${Fn}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Al,{ref:ve,className:"h-full",style:{height:"100%"},messages:b,isStreaming:B,streamingAssistantId:Q,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:nr,enableMessageEditing:c,editingMessageId:L,onStartReached:()=>{on&&N()},onScrollAway:Z=>{if(!Kt.current){Kt.current=!0;return}Z&&sn(!0)},onEdit:tt,onRegenerate:Fe,onCancelEdit:qe,emptyMessage:ht??void 0,isNavigatingCheckpoint:Y,activeInterrupt:ye,disableInterruptActions:Pe,onInterruptActionStart:ce,onInterruptActionEnd:Ce,showToolMessages:d,checkpointMetaById:Ut,checkpointIndexByKey:at,activeCheckpointId:F,onSelectCheckpoint:Ft,timelineCheckpoints:At}),(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:Wt,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:qe,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:An,type:"file",multiple:!0,onChange:Z=>ze(Z),className:"hidden"},nt),Re.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Re.map((Z,le)=>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:()=>Ct(le),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})})]},le))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:jt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:wt,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..."]}),Dt&&!Qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Dt}),Ke&&!Qe&&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(T0,{children:[u.jsx(E0,{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(kf,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ya,{onClick:()=>{var Z;return(Z=An.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;Qe||(Z=jt.current)==null||Z.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(Ex,{initialValue:se,editingMessageId:L,value:Bt,onValueChange:io,placeholder:L?"Edit your message...":t,isStreaming:B,disabled:te,maxLength:Ks,onSend:ue,onCancelEdit:qe,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 wi=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:oe("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));wi.displayName="Input";function _l(e,[t,n]){return Math.min(n,Math.max(t,e))}function rk(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var jl="ScrollArea",[yp,GT]=Jn(jl),[ok,In]=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,b]=v.useState(0),[C,T]=v.useState(0),[k,S]=v.useState(!1),[E,j]=v.useState(!1),_=Je(t,D=>l(D)),P=ys(o);return u.jsx(ok,{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:b,onCornerHeightChange:T,children:u.jsx(Me.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=In(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(Me.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 Gn="ScrollAreaScrollbar",Pl=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=In(Gn,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(sk,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(ik,{...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=Gn;var sk=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=In(Gn,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(Cn,{present:n||s,children:u.jsx(bp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),ik=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=In(Gn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ki(()=>l("SCROLL_END"),100),[a,l]=rk("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(Cn,{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=In(Gn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=ki(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return ro(n.viewport,l),ro(n.content,l),u.jsx(Cn,{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=In(Gn,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 fk(h,i.current,a,p)}return n==="horizontal"?u.jsx(ak,{...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(lk,{...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}),ak=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=In(Gn,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":Ci(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),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:Si(i.paddingLeft),paddingEnd:Si(i.paddingRight)}})}})}),lk=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=In(Gn,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":Ci(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),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:Si(i.paddingTop),paddingEnd:Si(i.paddingBottom)}})}})}),[ck,Sp]=yp(Gn),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=In(Gn,n),[m,g]=v.useState(null),y=Je(t,_=>g(_)),x=v.useRef(null),b=v.useRef(""),C=p.viewport,T=r.content-r.viewport,k=Jt(d),S=Jt(l),E=ki(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(ck,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Jt(s),onThumbPointerUp:Jt(i),onThumbPositionChange:S,onThumbPointerDown:Jt(a),children:u.jsx(Me.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=m.getBoundingClientRect(),b.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=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),bi="ScrollAreaThumb",kp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Sp(bi,e.__scopeScrollArea);return u.jsx(Cn,{present:n||o.hasThumb,children:u.jsx(uk,{ref:t,...r})})}),uk=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=In(bi,n),i=Sp(bi,n),{onThumbPositionChange:a}=i,l=Je(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=ki(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=hk(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(Me.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=bi;var Ol="ScrollAreaCorner",Tp=v.forwardRef((e,t)=>{const n=In(Ol,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(dk,{...e,ref:t}):null});Tp.displayName=Ol;var dk=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=In(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(Me.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Si(e){return e?parseInt(e,10):0}function Ep(e,t){const n=e/t;return isNaN(n)?0:n}function Ci(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 fk(e,t,n,r="ltr"){const o=Ci(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Np([l,c],f)(e)}function Ip(e,t,n="ltr"){const r=Ci(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=_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 hk=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function ki(e,t){const n=Jt(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=Jt(t);Xt(()=>{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,pk=wp,mk=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(pk,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Pp,{}),u.jsx(mk,{})]}));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}=ps(),{loadThread:g}=ms(),{createThread:y,deleteThread:x,renameThread:b}=m,[C,T]=w.useState(Array.isArray(f)?f:[]),k=w.useRef(C.length>0),S=w.useRef(null),E=w.useRef(0),[j,_]=w.useState(null),[P,D]=w.useState(""),[z,B]=w.useState(!1);w.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]),w.useEffect(()=>{if(!S.current)return;const J=S.current.querySelector("[data-radix-scroll-area-viewport]");if(!J)return;let ce=null,Ce=null;return ce=requestAnimationFrame(()=>{Ce=requestAnimationFrame(()=>{J.scrollTop=E.current})}),()=>{ce!==null&&cancelAnimationFrame(ce),Ce!==null&&cancelAnimationFrame(Ce)}},[C]);const O=async J=>{try{await g(J),a==null||a(J),l==null||l(J)}catch(ce){console.error("Failed to select thread:",ce)}},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,ce)=>{if(ce.stopPropagation(),!!confirm("Delete this thread?")){if(S.current){const Ce=S.current.querySelector("[data-radix-scroll-area-viewport]");Ce&&(E.current=Ce.scrollTop)}try{await x(J),d==null||d(J)}catch(Ce){console.error("Failed to delete thread:",Ce)}}},V=(J,ce)=>{ce.stopPropagation(),_(J.threadId),D(J.title||`Thread ${J.threadId.slice(0,8)}`)},$=async J=>{if(P.trim())try{await b(J,P.trim()),_(null),D("")}catch(ce){console.error("Failed to update title:",ce)}},F=()=>{_(null),D("")},ne=(J,ce)=>{J.key==="Enter"?$(ce):J.key==="Escape"&&F()},Q=J=>{if(!J)return"";try{const ce=new Date(J),te=new Date().getTime()-ce.getTime(),L=Math.floor(te/(1e3*60*60*24));return L===0?ce.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):L===1?"Yesterday":L<7?`${L} days ago`:ce.toLocaleDateString()}catch{return""}},ye=J=>J.title||`Thread ${J.threadId.slice(0,8)}`,Pe=J=>{const ce=ye(J);return ce.length<=Rp?ce:`${ce.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(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(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((J,ce)=>new Date(ce.updatedAt||ce.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:ce=>ce.stopPropagation(),children:[u.jsx(wi,{value:P,onChange:ce=>D(ce.target.value),onKeyDown:ce=>ne(ce,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:Pe(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:ce=>V(J,ce),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:ce=>R(J.threadId,ce),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 gk(e){if(typeof e!="string")return;const t=e.trim();if(t)return Xn(t)}function Op(){const e=[oo("__API_BASE_URL__"),oo("__CHAT_API_BASE_URL__"),oo("__CHAT_API_URL__")];for(const t of e){const n=gk(t);if(n)return n}}function Mp(){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 Dp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Xn(t);return Xn()}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 yk(){try{const e=localStorage.getItem($p);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function xk(e){try{const t={...e,apiBaseUrl:Xn(e.apiBaseUrl)};localStorage.setItem($p,JSON.stringify(t)),t.apiKey&&sr.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function vk(){const e=Fp(),t=yk(),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 wk(e){sr.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),xk(e)}var bk="Label",zp=v.forwardRef((e,t)=>u.jsx(Me.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=bk;var Bp=zp;const Sk=Go.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Nn=v.forwardRef(({className:e,...t},n)=>u.jsx(Bp,{ref:n,className:oe(Sk(),e),...t}));Nn.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 Ti="Switch",[Ck,YT]=Jn(Ti),[kk,Tk]=Ck(Ti),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,b]=Vr({prop:o,defaultProp:s??!1,onChange:c,caller:Ti});return u.jsxs(kk,{scope:n,checked:x,disabled:a,children:[u.jsx(Me.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=>{b(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=Ti;var Wp="SwitchThumb",Vp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=Tk(Wp,n);return u.jsx(Me.span,{"data-state":qp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Vp.displayName=Wp;var Ek="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=Ek;function qp(e){return e?"checked":"unchecked"}var Gp=Up,Ik=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(Ik,{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"}),Nk="VisuallyHidden",Ak=v.forwardRef((e,t)=>u.jsx(Me.span,{...e,ref:t,style:{...Yp,...e.style}}));Ak.displayName=Nk;var _k=[" ","Enter","ArrowUp","ArrowDown"],jk=[" ","Enter"],Dr="Select",[Ei,Ii,Pk]=pa(Dr),[so,XT]=Jn(Dr,[Pk,_s]),Ni=_s(),[Rk,gr]=so(Dr),[Ok,Mk]=so(Dr),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=Ni(t),[y,x]=v.useState(null),[b,C]=v.useState(null),[T,k]=v.useState(!1),S=ys(c),[E,j]=Vr({prop:r,defaultProp:o??!1,onChange:s,caller:Dr}),[_,P]=Vr({prop:i,defaultProp:a,onChange:l,caller:Dr}),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(Rk,{required:p,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:C,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:Zn(),value:_,onValueChange:P,open:E,onOpenChange:j,dir:S,triggerPointerDownPosRef:D,disabled:h,children:[u.jsx(Ei.Provider,{scope:t,children:u.jsx(Ok,{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=Dr;var Jp="SelectTrigger",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ni(n),i=gr(Jp,n),a=i.disabled||r,l=Je(t,i.onTriggerChange),c=Ii(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),b=Cm(y,g,x);b!==void 0&&i.onValueChange(b.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(Me.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===" ")&&_k.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 Xt(()=>{c(d)},[c,d]),u.jsx(Me.span,{...a,ref:f,style:{pointerEvents:"none"},children:bm(l.value)?u.jsx(u.Fragment,{children:i}):s})});em.displayName=Qp;var Dk="SelectIcon",tm=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Me.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});tm.displayName=Dk;var Lk="SelectPortal",nm=e=>u.jsx(js,{asChild:!0,...e});nm.displayName=Lk;var Lr="SelectContent",rm=v.forwardRef((e,t)=>{const n=gr(Lr,e.__scopeSelect),[r,o]=v.useState();if(Xt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Yo.createPortal(u.jsx(om,{scope:e.__scopeSelect,children:u.jsx(Ei.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(sm,{...e,ref:t})});rm.displayName=Lr;var Ln=10,[om,yr]=so(Lr),Fk="SelectContentImpl",$k=br.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,b=gr(Lr,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=Ii(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),ae=document.activeElement;for(const U of te)if(U===ae||(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!==ae))return},[z,k]),V=v.useCallback(()=>R([j,C]),[R,j,C]);v.useEffect(()=>{B&&V()},[B,V]);const{onOpenChange:$,triggerPointerDownPosRef:F}=b;v.useEffect(()=>{if(C){let te={x:0,y:0};const L=se=>{var ae,U;te={x:Math.abs(Math.round(se.pageX)-(((ae=F.current)==null?void 0:ae.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(ae=>!ae.disabled),G=L.find(ae=>ae.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;(b.value!==void 0&&b.value===L||se)&&(_(te),se&&(H.current=!0))},[b.value]),Pe=v.useCallback(()=>C==null?void 0:C.focus(),[C]),J=v.useCallback((te,L,G)=>{const se=!H.current&&!G;(b.value!==void 0&&b.value===L||se)&&D(te)},[b.value]),ce=r==="popper"?Dl:im,Ce=ce===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:J,focusSelectedItem:V,selectedItemText:P,position:r,isPositioned:B,searchRef:ne,children:u.jsx(zs,{as:$k,allowPinchZoom:!0,children:u.jsx(vs,{asChild:!0,trapped:b.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:ge(o,te=>{var L;(L=b.trigger)==null||L.focus({preventScroll:!0}),te.preventDefault()}),children:u.jsx(xs,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(ce,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:te=>te.preventDefault(),...x,...Ce,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(ae=>!ae.disabled).map(ae=>ae.ref.current);if(["ArrowUp","End"].includes(te.key)&&(se=se.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const ae=te.target,U=se.indexOf(ae);se=se.slice(U+1)}setTimeout(()=>R(se)),te.preventDefault()}})})})})})})});sm.displayName=Fk;var zk="SelectItemAlignedPosition",im=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=gr(Lr,n),i=yr(Lr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Je(t,E=>d(E)),h=Ii(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=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 ae=P.left-j.left,U=_.left-ae,Ue=E.left-U,re=E.width+Ue,xe=Math.max(re,j.width),Re=window.innerWidth-Ln,Le=_l(U,[Ln,Math.max(Ln,Re-xe)]);a.style.minWidth=re+"px",a.style.left=Le+"px"}else{const ae=j.right-P.right,U=window.innerWidth-_.right-ae,Ue=window.innerWidth-E.right-U,re=E.width+Ue,xe=Math.max(re,j.width),Re=window.innerWidth-Ln,Le=_l(U,[Ln,Math.max(Ln,Re-xe)]);a.style.minWidth=re+"px",a.style.right=Le+"px"}const D=h(),z=window.innerHeight-Ln*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),J=E.top+E.height/2-Ln,ce=z-J,Ce=y.offsetHeight/2,te=y.offsetTop+Ce,L=H+R+te,G=F-L;if(L<=J){const ae=D.length>0&&y===D[D.length-1].ref.current;a.style.bottom="0px";const U=c.clientHeight-g.offsetTop-g.offsetHeight,Ue=Math.max(ce,Ce+(ae?Pe:0)+U+V),re=L+Ue;a.style.height=re+"px"}else{const ae=D.length>0&&y===D[0].ref.current;a.style.top="0px";const Ue=Math.max(J,H+g.offsetTop+(ae?ye:0)+Ce)+G;a.style.height=Ue+"px",g.scrollTop=L-J+g.offsetTop}a.style.margin=`${Ln}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]);Xt(()=>C(),[C]);const[T,k]=v.useState();Xt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const S=v.useCallback(E=>{E&&m.current===!0&&(C(),b==null||b(),m.current=!1)},[C,b]);return u.jsx(Hk,{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(Me.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});im.displayName=zk;var Bk="SelectPopperPosition",Dl=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Ln,...s}=e,i=Ni(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=Bk;var[Hk,Ll]=so(Lr,{}),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(Ei.Slot,{scope:n,children:u.jsx(Me.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-Ln*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<m){const b=x+p,C=Math.min(m,b),T=b-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",[Uk,Wk]=so(lm),Vk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Zn();return u.jsx(Uk,{scope:n,id:o,children:u.jsx(Me.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Vk.displayName=lm;var cm="SelectLabel",um=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Wk(cm,n);return u.jsx(Me.div,{id:o.id,...r,ref:t})});um.displayName=cm;var Ai="SelectItem",[Kk,dm]=so(Ai),fm=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=gr(Ai,n),l=yr(Ai,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),m=Je(t,b=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,b,r,o)}),g=Zn(),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(Kk,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:v.useCallback(b=>{f(C=>C||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Ei.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Me.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,b=>{y.current=b.pointerType}),onPointerMove:ge(i.onPointerMove,b=>{var C;y.current=b.pointerType,o?(C=l.onItemLeave)==null||C.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ge(i.onPointerLeave,b=>{var C;b.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:ge(i.onKeyDown,b=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&b.key===" "||(jk.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});fm.displayName=Ai;var Ko="SelectItemText",hm=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=gr(Ko,n),a=yr(Ko,n),l=dm(Ko,n),c=Mk(Ko,n),[d,f]=v.useState(null),h=Je(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.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 Xt(()=>(g(m),()=>y(m)),[g,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Me.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Yo.createPortal(s.children,i.valueNode):null]})});hm.displayName=Ko;var pm="SelectItemIndicator",mm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return dm(pm,n).isSelected?u.jsx(Me.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 Xt(()=>{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 Xt(()=>{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=Ii(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Xt(()=>{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(Me.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()})})}),qk="SelectSeparator",vm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Me.div,{"aria-hidden":!0,...r,ref:t})});vm.displayName=qk;var Bl="SelectArrow",Gk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ni(n),s=gr(Bl,n),i=yr(Bl,n);return s.open&&i.position==="popper"?u.jsx(cd,{...o,...r,ref:t}):null});Gk.displayName=Bl;var Yk="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(Me.select,{...n,style:{...Yp,...n.style},ref:s,defaultValue:t})});wm.displayName=Yk;function bm(e){return e===""||e===void 0}function Sm(e){const t=Jt(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=Xk(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 Xk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Jk=Xp,km=Zp,Zk=em,Qk=tm,eT=nm,Tm=rm,tT=am,Em=um,Im=fm,nT=hm,rT=mm,Nm=gm,Am=ym,_m=vm;const jm=Jk,Pm=Zk,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(Qk,{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(eT,{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(tT,{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 oT=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}));oT.displayName=Em.displayName;const Fr=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(rT,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),u.jsx(nT,{children:t})]}));Fr.displayName=Im.displayName;const sT=v.forwardRef(({className:e,...t},n)=>u.jsx(_m,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));sT.displayName=_m.displayName;var iT="Separator",Mm="horizontal",aT=["horizontal","vertical"],Dm=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Mm,...o}=e,s=lT(r)?r:Mm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Me.div,{"data-orientation":s,...a,...o,ref:t})});Dm.displayName=iT;function lT(e){return aT.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 cT=Kh,uT=TC,dT=qh,$m=v.forwardRef(({className:e,...t},n)=>u.jsx(di,{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=di.displayName;const fT=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"}}),zm=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(dT,{children:[u.jsx($m,{}),u.jsxs(fi,{ref:o,className:oe(fT({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=fi.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(Or,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));Hm.displayName=Or.displayName;const Um=v.forwardRef(({className:e,...t},n)=>u.jsx(hi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Um.displayName=hi.displayName;const hT={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 pT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=bl();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(hT),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(cT,{open:r,onOpenChange:o,children:[u.jsx(uT,{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(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(Fo,{children:[u.jsx($o,{className:"pb-3",children:u.jsxs(zo,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(Bo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Nn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(wi,{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(Nn,{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(Nn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(wi,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(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(Fo,{children:[u.jsx($o,{className:"pb-3",children:u.jsxs(zo,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(Bo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Nn,{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(Fr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(Fr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(Fr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Nn,{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(Fr,{value:"light",children:"Light"}),u.jsx(Fr,{value:"dark",children:"Dark"}),u.jsx(Fr,{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(Nn,{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(Nn,{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(Nn,{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(Fo,{children:[u.jsx($o,{className:"pb-3",children:u.jsxs(zo,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(Bo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Nn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(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(Nn,{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(Nn,{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 mT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(gs,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(vi,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(gs,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(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(vi,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(gs,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(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(vi,{onError:s.onError,enableFileUpload:!0})})]})})}_e.ChatApi=zc,_e.ChatInput=pu,_e.ChatInterface=vi,_e.ChatProviders=gs,_e.ChatSettings=pT,_e.MarkdownContent=Vo,_e.MessageComponent=Nl,_e.MessageList=Al,_e.ThreadManager=Ml,_e.applySettings=wk,_e.chatApiClient=sr,_e.default=mT,_e.del=$c,_e.get=bn,_e.getChatToken=Dc,_e.getCurrentSettings=vk,_e.getDefaultApiConfig=Lp,_e.getDefaultChatSettings=Fp,_e.onChatTokenChanged=Lc,_e.post=Yi,_e.put=Fc,_e.registerChatTokenSyncHandler=Ty,_e.setChatToken=Gi,_e.useApi=Xi,_e.useChatStream=tu,_e.useMessagesReducer=qc,_e.useStream=fu,_e.useThreadState=ms,_e.useThreads=ps,Object.defineProperties(_e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|