teodor-new-chat-ui 4.3.150 → 4.3.151
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 +4509 -4498
- package/dist/index.umd.js +43 -43
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(_e,
|
|
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,tg,ng,Oi){"use strict";var CT=Object.defineProperty;var kT=(_e,w,he)=>w in _e?CT(_e,w,{enumerable:!0,configurable:!0,writable:!0,value:he}):_e[w]=he;var Qm=(_e,w,he)=>kT(_e,typeof w!="symbol"?w+"":w,he);function ql(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=ql(w),Yo=ql(Oi);var Mi={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
|
|
9
|
+
*/var Gl;function rg(){if(Gl)return uo;Gl=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,33 +14,33 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+te+N}}var G=!1,se;{var
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
|
|
17
|
+
*/var Yl;function og(){return Yl||(Yl=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} />`,xr,In,J,In),qn[In+xr]=!0}}return N===r?sn(mt):Xe(mt),mt}}function rr(N,q,de){return jt(N,q,de,!0)}function Fr(N,q,de){return jt(N,q,de,!1)}var Ko=Fr,$r=rr;uo.Fragment=r,uo.jsx=Ko,uo.jsxs=$r}()),uo}process.env.NODE_ENV==="production"?Oi.exports=eg():Oi.exports=tg();var u=Oi.exports;function Yl(e,t){return function(){return e.apply(t,arguments)}}const{toString:ng}=Object.prototype,{getPrototypeOf:Mi}=Object,{iterator:Jo,toStringTag:Xl}=Symbol,Zo=(e=>t=>{const n=ng.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),An=e=>(e=e.toLowerCase(),t=>Zo(t)===e),Qo=e=>t=>typeof t===e,{isArray:Hr}=Array,Ur=Qo("undefined");function fo(e){return e!==null&&!Ur(e)&&e.constructor!==null&&!Ur(e.constructor)&&an(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Jl=An("ArrayBuffer");function rg(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Jl(e.buffer),t}const og=Qo("string"),an=Qo("function"),Zl=Qo("number"),ho=e=>e!==null&&typeof e=="object",sg=e=>e===!0||e===!1,es=e=>{if(Zo(e)!=="object")return!1;const t=Mi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xl in e)&&!(Jo in e)},ig=e=>{if(!ho(e)||fo(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},ag=An("Date"),lg=An("File"),cg=An("Blob"),ug=An("FileList"),dg=e=>ho(e)&&an(e.pipe),fg=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||an(e.append)&&((t=Zo(e))==="formdata"||t==="object"&&an(e.toString)&&e.toString()==="[object FormData]"))},hg=An("URLSearchParams"),[pg,mg,gg,yg]=["ReadableStream","Request","Response","Headers"].map(An),xg=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function po(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Hr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(fo(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function Ql(e,t){if(fo(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const br=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,ec=e=>!Ur(e)&&e!==br;function Di(){const{caseless:e,skipUndefined:t}=ec(this)&&this||{},n={},r=(o,s)=>{const i=e&&Ql(n,s)||s;es(n[i])&&es(o)?n[i]=Di(n[i],o):es(o)?n[i]=Di({},o):Hr(o)?n[i]=o.slice():(!t||!Ur(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&po(arguments[o],r);return n}const vg=(e,t,n,{allOwnKeys:r}={})=>(po(t,(o,s)=>{n&&an(o)?e[s]=Yl(o,n):e[s]=o},{allOwnKeys:r}),e),wg=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),bg=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Sg=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&Mi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Cg=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},kg=e=>{if(!e)return null;if(Hr(e))return e;let t=e.length;if(!Zl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Tg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Mi(Uint8Array)),Eg=(e,t)=>{const r=(e&&e[Jo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Ig=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Ng=An("HTMLFormElement"),Ag=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tc=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),_g=An("RegExp"),nc=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};po(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},jg=e=>{nc(e,(t,n)=>{if(an(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(an(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Pg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Hr(e)?r(e):r(String(e).split(t)),n},Rg=()=>{},Og=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Mg(e){return!!(e&&an(e.append)&&e[Xl]==="FormData"&&e[Jo])}const Dg=e=>{const t=new Array(10),n=(r,o)=>{if(ho(r)){if(t.indexOf(r)>=0)return;if(fo(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Hr(r)?[]:{};return po(r,(i,a)=>{const l=n(i,o+1);!Ur(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Lg=An("AsyncFunction"),Fg=e=>e&&(ho(e)||an(e))&&an(e.then)&&an(e.catch),rc=((e,t)=>e?setImmediate:t?((n,r)=>(br.addEventListener("message",({source:o,data:s})=>{o===br&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),br.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",an(br.postMessage)),$g=typeof queueMicrotask<"u"?queueMicrotask.bind(br):typeof process<"u"&&process.nextTick||rc,M={isArray:Hr,isArrayBuffer:Jl,isBuffer:fo,isFormData:fg,isArrayBufferView:rg,isString:og,isNumber:Zl,isBoolean:sg,isObject:ho,isPlainObject:es,isEmptyObject:ig,isReadableStream:pg,isRequest:mg,isResponse:gg,isHeaders:yg,isUndefined:Ur,isDate:ag,isFile:lg,isBlob:cg,isRegExp:_g,isFunction:an,isStream:dg,isURLSearchParams:hg,isTypedArray:Tg,isFileList:ug,forEach:po,merge:Di,extend:vg,trim:xg,stripBOM:wg,inherits:bg,toFlatObject:Sg,kindOf:Zo,kindOfTest:An,endsWith:Cg,toArray:kg,forEachEntry:Eg,matchAll:Ig,isHTMLForm:Ng,hasOwnProperty:tc,hasOwnProp:tc,reduceDescriptors:nc,freezeMethods:jg,toObjectSet:Pg,toCamelCase:Ag,noop:Rg,toFiniteNumber:Og,findKey:Ql,global:br,isContextDefined:ec,isSpecCompliantForm:Mg,toJSONObject:Dg,isAsyncFn:Lg,isThenable:Fg,setImmediate:rc,asap:$g,isIterable:e=>e!=null&&an(e[Jo])};function Le(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}M.inherits(Le,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:M.toJSONObject(this.config),code:this.code,status:this.status}}});const oc=Le.prototype,sc={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{sc[e]={value:e}}),Object.defineProperties(Le,sc),Object.defineProperty(oc,"isAxiosError",{value:!0}),Le.from=(e,t,n,r,o,s)=>{const i=Object.create(oc);M.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Le.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const zg=null;function Li(e){return M.isPlainObject(e)||M.isArray(e)}function ic(e){return M.endsWith(e,"[]")?e.slice(0,-2):e}function ac(e,t,n){return e?e.concat(t).map(function(o,s){return o=ic(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Bg(e){return M.isArray(e)&&!e.some(Li)}const Hg=M.toFlatObject(M,{},null,function(t){return/^is[A-Z]/.test(t)});function ts(e,t,n){if(!M.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=M.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,y){return!M.isUndefined(y[g])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&M.isSpecCompliantForm(t);if(!M.isFunction(o))throw new TypeError("visitor must be a function");function c(m){if(m===null)return"";if(M.isDate(m))return m.toISOString();if(M.isBoolean(m))return m.toString();if(!l&&M.isBlob(m))throw new Le("Blob is not supported. Use a Buffer instead.");return M.isArrayBuffer(m)||M.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function d(m,g,y){let x=m;if(m&&!y&&typeof m=="object"){if(M.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(M.isArray(m)&&Bg(m)||(M.isFileList(m)||M.endsWith(g,"[]"))&&(x=M.toArray(m)))return g=ic(g),x.forEach(function(C,T){!(M.isUndefined(C)||C===null)&&t.append(i===!0?ac([g],T,s):i===null?g:g+"[]",c(C))}),!1}return Li(m)?!0:(t.append(ac(y,g,s),c(m)),!1)}const f=[],h=Object.assign(Hg,{defaultVisitor:d,convertValue:c,isVisitable:Li});function p(m,g){if(!M.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),M.forEach(m,function(x,w){(!(M.isUndefined(x)||x===null)&&o.call(t,x,M.isString(w)?w.trim():w,g,h))===!0&&p(x,g?g.concat(w):[w])}),f.pop()}}if(!M.isObject(e))throw new TypeError("data must be an object");return p(e),t}function lc(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Fi(e,t){this._pairs=[],e&&ts(e,this,t)}const cc=Fi.prototype;cc.append=function(t,n){this._pairs.push([t,n])},cc.toString=function(t){const n=t?function(r){return t.call(this,r,lc)}:lc;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Ug(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function uc(e,t,n){if(!t)return e;const r=n&&n.encode||Ug;M.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=M.isURLSearchParams(t)?t.toString():new Fi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dc{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){M.forEach(this.handlers,function(r){r!==null&&t(r)})}}const fc={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Wg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Fi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},$i=typeof window<"u"&&typeof document<"u",zi=typeof navigator=="object"&&navigator||void 0,Vg=$i&&(!zi||["ReactNative","NativeScript","NS"].indexOf(zi.product)<0),Kg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",qg=$i&&window.location.href||"http://localhost",Yt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:$i,hasStandardBrowserEnv:Vg,hasStandardBrowserWebWorkerEnv:Kg,navigator:zi,origin:qg},Symbol.toStringTag,{value:"Module"})),...Wg};function Gg(e,t){return ts(e,new Yt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Yt.isNode&&M.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Yg(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Xg(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function hc(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&M.isArray(o)?o.length:i,l?(M.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!M.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&M.isArray(o[i])&&(o[i]=Xg(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t(Yg(r),o,n,0)}),n}return null}function Jg(e,t,n){if(M.isString(e))try{return(t||JSON.parse)(e),M.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const mo={transitional:fc,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=M.isObject(t);if(s&&M.isHTMLForm(t)&&(t=new FormData(t)),M.isFormData(t))return o?JSON.stringify(hc(t)):t;if(M.isArrayBuffer(t)||M.isBuffer(t)||M.isStream(t)||M.isFile(t)||M.isBlob(t)||M.isReadableStream(t))return t;if(M.isArrayBufferView(t))return t.buffer;if(M.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Gg(t,this.formSerializer).toString();if((a=M.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return ts(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Jg(t)):t}],transformResponse:[function(t){const n=this.transitional||mo.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(M.isResponse(t)||M.isReadableStream(t))return t;if(t&&M.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Le.from(a,Le.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Yt.classes.FormData,Blob:Yt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};M.forEach(["delete","get","head","post","put","patch"],e=>{mo.headers[e]={}});const Zg=M.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Qg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
|
-
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&
|
|
32
|
-
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[pc]=this[pc]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=go(i);r[a]||(ry(o,i),r[a]=!0)}return M.isArray(t)?t.forEach(s):s(t),this}};ln.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),M.reduceDescriptors(ln.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),M.freezeMethods(ln);function Hi(e,t){const n=this||mo,r=t||n,o=ln.from(r.headers);let s=r.data;return M.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function mc(e){return!!(e&&e.__CANCEL__)}function Wr(e,t,n){Le.call(this,e??"canceled",Le.ERR_CANCELED,t,n),this.name="CanceledError"}M.inherits(Wr,Le,{__CANCEL__:!0});function gc(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Le("Request failed with status code "+n.status,[Le.ERR_BAD_REQUEST,Le.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function oy(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function sy(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=d&&c-d;return p?Math.round(h*1e3/p):void 0}}function iy(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const rs=(e,t,n=3)=>{let r=0;const o=sy(50,250);return iy(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},yc=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},xc=e=>(...t)=>M.asap(()=>e(...t)),ay=Yt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Yt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Yt.origin),Yt.navigator&&/(msie|trident)/i.test(Yt.navigator.userAgent)):()=>!0,ly=Yt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];M.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),M.isString(r)&&i.push("path="+r),M.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function cy(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function uy(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function vc(e,t,n){let r=!cy(t);return e&&(r||n==!1)?uy(e,t):t}const wc=e=>e instanceof ln?{...e}:e;function Sr(e,t){t=t||{};const n={};function r(c,d,f,h){return M.isPlainObject(c)&&M.isPlainObject(d)?M.merge.call({caseless:h},c,d):M.isPlainObject(d)?M.merge({},d):M.isArray(d)?d.slice():d}function o(c,d,f,h){if(M.isUndefined(d)){if(!M.isUndefined(c))return r(void 0,c,f,h)}else return r(c,d,f,h)}function s(c,d){if(!M.isUndefined(d))return r(void 0,d)}function i(c,d){if(M.isUndefined(d)){if(!M.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(wc(c),wc(d),f,!0)};return M.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);M.isUndefined(h)&&f!==a||(n[d]=h)}),n}const bc=e=>{const t=Sr({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=ln.from(i),t.url=uc(vc(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),M.isFormData(n)){if(Yt.hasStandardBrowserEnv||Yt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(M.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Yt.hasStandardBrowserEnv&&(r&&M.isFunction(r)&&(r=r(t)),r||r!==!1&&ay(t.url))){const l=o&&s&&ly.read(s);l&&i.set(o,l)}return t},dy=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=bc(e);let s=o.data;const i=ln.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,m;function g(){p&&p(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function x(){if(!y)return;const C=ln.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:C,config:e,request:y};gc(function(E){n(E),g()},function(E){r(E),g()},k),y=null}"onloadend"in y?y.onloadend=x:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(x)},y.onabort=function(){y&&(r(new Le("Request aborted",Le.ECONNABORTED,e,y)),y=null)},y.onerror=function(T){const k=T&&T.message?T.message:"Network Error",S=new Le(k,Le.ERR_NETWORK,e,y);S.event=T||null,r(S),y=null},y.ontimeout=function(){let T=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||fc;o.timeoutErrorMessage&&(T=o.timeoutErrorMessage),r(new Le(T,k.clarifyTimeoutError?Le.ETIMEDOUT:Le.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&M.forEach(i.toJSON(),function(T,k){y.setRequestHeader(k,T)}),M.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([h,m]=rs(c,!0),y.addEventListener("progress",h)),l&&y.upload&&([f,p]=rs(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=C=>{y&&(r(!C||C.type?new Wr(null,e,y):C),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const w=oy(o.url);if(w&&Yt.protocols.indexOf(w)===-1){r(new Le("Unsupported protocol "+w+":",Le.ERR_BAD_REQUEST,e));return}y.send(s||null)})},fy=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Le?d:new Wr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Le(`timeout ${t} of ms exceeded`,Le.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>M.asap(a),l}},hy=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},py=async function*(e,t){for await(const n of my(e))yield*hy(n,t)},my=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Sc=(e,t,n,r)=>{const o=py(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Cc=64*1024,{isFunction:os}=M,gy=(({Request:e,Response:t})=>({Request:e,Response:t}))(M.global),{ReadableStream:kc,TextEncoder:Tc}=M.global,Ec=(e,...t)=>{try{return!!e(...t)}catch{return!1}},yy=e=>{e=M.merge.call({skipUndefined:!0},gy,e);const{fetch:t,Request:n,Response:r}=e,o=t?os(t):typeof fetch=="function",s=os(n),i=os(r);if(!o)return!1;const a=o&&os(kc),l=o&&(typeof Tc=="function"?(m=>g=>m.encode(g))(new Tc):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Ec(()=>{let m=!1;const g=new n(Yt.origin,{body:new kc,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),d=i&&a&&Ec(()=>M.isReadableStream(new r("").body)),f={stream:d&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,y)=>{let x=g&&g[m];if(x)return x.call(g);throw new Le(`Response type '${m}' is not supported`,Le.ERR_NOT_SUPPORT,y)})});const h=async m=>{if(m==null)return 0;if(M.isBlob(m))return m.size;if(M.isSpecCompliantForm(m))return(await new n(Yt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(M.isArrayBufferView(m)||M.isArrayBuffer(m))return m.byteLength;if(M.isURLSearchParams(m)&&(m=m+""),M.isString(m))return(await l(m)).byteLength},p=async(m,g)=>{const y=M.toFiniteNumber(m.getContentLength());return y??h(g)};return async m=>{let{url:g,method:y,data:x,signal:w,cancelToken:C,timeout:T,onDownloadProgress:k,onUploadProgress:S,responseType:E,headers:j,withCredentials:_="same-origin",fetchOptions:P}=bc(m),D=t||fetch;E=E?(E+"").toLowerCase():"text";let z=fy([w,C&&C.toAbortSignal()],T),B=null;const O=z&&z.unsubscribe&&(()=>{z.unsubscribe()});let H;try{if(S&&c&&y!=="get"&&y!=="head"&&(H=await p(j,x))!==0){let Q=new n(g,{method:"POST",body:x,duplex:"half"}),ye;if(M.isFormData(x)&&(ye=Q.headers.get("content-type"))&&j.setContentType(ye),Q.body){const[Pe,Z]=yc(H,rs(xc(S)));x=Sc(Q.body,Cc,Pe,Z)}}M.isString(_)||(_=_?"include":"omit");const R=s&&"credentials"in n.prototype,V={...P,signal:z,method:y.toUpperCase(),headers:j.normalize().toJSON(),body:x,duplex:"half",credentials:R?_:void 0};B=s&&new n(g,V);let $=await(s?D(B,P):D(g,V));const F=d&&(E==="stream"||E==="response");if(d&&(k||F&&O)){const Q={};["status","statusText","headers"].forEach(ue=>{Q[ue]=$[ue]});const ye=M.toFiniteNumber($.headers.get("content-length")),[Pe,Z]=k&&yc(ye,rs(xc(k),!0))||[];$=new r(Sc($.body,Cc,Pe,()=>{Z&&Z(),O&&O()}),Q)}E=E||"text";let ne=await f[M.findKey(f,E)||"text"]($,m);return!F&&O&&O(),await new Promise((Q,ye)=>{gc(Q,ye,{data:ne,headers:ln.from($.headers),status:$.status,statusText:$.statusText,config:m,request:B})})}catch(R){throw O&&O(),R&&R.name==="TypeError"&&/Load failed|fetch/i.test(R.message)?Object.assign(new Le("Network Error",Le.ERR_NETWORK,m,B),{cause:R.cause||R}):Le.from(R,R&&R.code,m,B)}}},xy=new Map,Ic=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=xy;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:yy(t)),d=c;return c};Ic();const Ui={http:zg,xhr:dy,fetch:{get:Ic}};M.forEach(Ui,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Nc=e=>`- ${e}`,vy=e=>M.isFunction(e)||e===null||e===!1,Ac={getAdapter:(e,t)=>{e=M.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!vy(r)&&(o=Ui[(a=String(r)).toLowerCase()],o===void 0))throw new Le(`Unknown adapter '${a}'`);if(o&&(M.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
|
-
`+i.map(
|
|
34
|
-
`):" "+
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Sr(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&is.assertOptions(r,{silentJSONParsing:Ln.transitional(Ln.boolean),forcedJSONParsing:Ln.transitional(Ln.boolean),clarifyTimeoutError:Ln.transitional(Ln.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:is.assertOptions(o,{encode:Ln.function,serialize:Ln.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),is.assertOptions(n,{baseUrl:Ln.spelling("baseURL"),withXsrfToken:Ln.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&M.merge(s.common,s[n.method]);s&&M.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=ln.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,h;if(!l){const m=[_c.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,d=Promise.resolve(n);f<h;)d=d.then(m[f++],m[f++]);return d}h=a.length;let p=n;for(;f<h;){const m=a[f++],g=a[f++];try{p=m(p)}catch(y){g.call(this,y);break}}try{d=_c.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Sr(this.defaults,t);const n=vc(t.baseURL,t.url,t.allowAbsoluteUrls);return uc(n,t.params,t.paramsSerializer)}};M.forEach(["delete","get","head","options"],function(t){Cr.prototype[t]=function(n,r){return this.request(Sr(r||{},{method:t,url:n,data:(r||{}).data}))}}),M.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Sr(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Cr.prototype[t]=n(),Cr.prototype[t+"Form"]=n(!0)});let by=class Jm{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new Wr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Jm(function(o){t=o}),cancel:t}}};function Sy(e){return function(n){return e.apply(null,n)}}function Cy(e){return M.isObject(e)&&e.isAxiosError===!0}const Vi={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Vi).forEach(([e,t])=>{Vi[t]=e});function Rc(e){const t=new Cr(e),n=Yl(Cr.prototype.request,t);return M.extend(n,Cr.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Rc(Sr(e,o))},n}const Rt=Rc(mo);Rt.Axios=Cr,Rt.CanceledError=Wr,Rt.CancelToken=by,Rt.isCancel=mc,Rt.VERSION=jc,Rt.toFormData=ts,Rt.AxiosError=Le,Rt.Cancel=Rt.CanceledError,Rt.all=function(t){return Promise.all(t)},Rt.spread=Sy,Rt.isAxiosError=Cy,Rt.mergeConfig=Sr,Rt.AxiosHeaders=ln,Rt.formToJSON=e=>hc(M.isHTMLForm(e)?new FormData(e):e),Rt.getAdapter=Ac.getAdapter,Rt.HttpStatusCode=Vi,Rt.default=Rt;const{Axios:ET,AxiosError:IT,CanceledError:NT,isCancel:AT,CancelToken:_T,VERSION:jT,all:PT,Cancel:RT,isAxiosError:OT,spread:MT,toFormData:DT,AxiosHeaders:LT,HttpStatusCode:FT,formToJSON:$T,getAdapter:zT,mergeConfig:BT}=Rt,Oc=typeof window<"u"?window.__API_BASE_URL__:void 0,Mc=Oc?Jn(Oc):void 0;function Jn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let as=null;const Ki=new Set;let qi=null;function Dc(){return as}function Gi(e){as=e,Ki.forEach(t=>t(e))}function Lc(e){return Ki.add(e),()=>Ki.delete(e)}function ky(e){qi=e}const Ty=3e4,Ey=9e4,xn=Rt.create({...Mc?{baseURL:Mc}:{},timeout:Ty,withCredentials:!0});xn.interceptors.request.use(e=>(as&&(e.headers.Authorization=`Bearer ${as}`),e)),xn.interceptors.response.use(e=>{if(qi&&(e!=null&&e.data))try{qi(e.data)}catch(t){console.warn("[chat-api] Error in token sync handler:",t)}return e},e=>Promise.reject(e));const ls=new Map;async function vn(e,t){if(!xn.defaults.baseURL)return Promise.reject(new Error("API base URL is not configured"));const n=`GET:${e}`,r=ls.get(n);if(r)return r;const o=xn.get(e,t).then(s=>(ls.delete(n),s.data)).catch(s=>{throw ls.delete(n),s});return ls.set(n,o),o}async function Yi(e,t,n){return xn.defaults.baseURL?(await xn.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fc(e,t,n){return xn.defaults.baseURL?(await xn.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $c(e,t){return xn.defaults.baseURL?(await xn.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function wn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class zc{get baseUrl(){const t=xn.defaults.baseURL;return t?Jn(String(t)):""}updateConfig(t){t.baseUrl&&(xn.defaults.baseURL=Jn(String(t.baseUrl))),t.authToken!==void 0&&Gi(t.authToken)}getAuthToken(){return Dc()}setAuthToken(t){Gi(t)}onTokenChange(t){return Lc(t)}async listThreads(){const t=await vn("/threads"),n=wn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Yi("/threads",t?{title:t}:void 0);return wn(r)}async updateThread(t,n){const r=await Fc(`/threads/${t}`,{title:n});return wn(r)}async deleteThread(t){const n=await $c(`/threads/${t}`);return wn(n)}async threadInfo(t){const n=await vn(`/threads/${t}/info`);return wn(n)}async listAgents(){const t=await vn("/agents"),n=wn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await vn(`/agents/${t}`);return wn(n)}async getAgentSchema(t){const n=await vn(`/agents/${t}/schema`);return wn(n)}async getState(t){const n=await vn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return wn(n)}async getStateHistory(t){const n=await vn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Ey});return wn(n)}async cancelRun(t){const n=await Yi("/runs/cancel",{threadId:t});return wn(n)}async listCheckpointSummaries(t){const n=await vn(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=wn(n);return(r==null?void 0:r.items)??[]}}const sr=new zc,Bc=b.createContext(null);function Iy({children:e,apiConfig:t}){const n=sr;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Bc.Provider,{value:r,children:e})}function Xi(){const e=b.useContext(Bc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Ny(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Ay(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Ny(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const _y={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Ji(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Vr(e,t){return`${e??""}::${t??""}`}function cs(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!Ji(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Py(t),i=Hc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Hc(e,t){if(!Ji(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(_=>!!_&&typeof _=="object").map(_=>({..._})):a===null?null:void 0,c=r.map((_,P)=>$y(_,P)).filter(_=>!!_),d=cn(e.config),f=cn(d==null?void 0:d.configurable),h=Ft(f,["checkpoint_id","checkpointId"]),p=Ft(f,["checkpoint_ns","checkpointNs"]),m=cn(e==null?void 0:e.parentConfig),g=cn(m==null?void 0:m.configurable),y=Ft(g,["checkpoint_id","checkpointId"])??null,x=Ft(g,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,C=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),T=c[c.length-1]??null,k=cn(e==null?void 0:e.metadata),S=Ft(k,["branch_label","branchLabel"]),E=Ft(g,["checkpoint_id","checkpointId"]),j=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:y,nextCursorNs:x,interrupt:jy(a,c,t),createdAt:C,parentId:E??null,branchLabel:S??null,lastMessageId:(T==null?void 0:T.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:k??null,config:d??null,parentConfig:m??null,next:j??null,tasks:l??null,values:i??null}}function jy(e,t,n){const r=Ly(e,n);return r||Dy(t,n)}function Py(e){const t=new Map;e.forEach((o,s)=>{if(!Ji(o))return;const i=Hc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Vr(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ry(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Wc(s.createdAt??"")-Wc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Ry(e,t){return{...e,metadata:us(e.metadata,t.metadata)??null,config:us(e.config,t.config)??null,parentConfig:us(e.parentConfig,t.parentConfig)??null,next:Oy(e.next,t.next)??null,tasks:My(e.tasks,t.tasks)??null,values:us(e.values,t.values)??null}}function us(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Oy(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function My(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Dy(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function Ly(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Fy(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=yo(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=yo(r.state,`${o}-state`);if(s)return s}}return null}function Fy(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=h.length?h[h.length-1]:void 0;return{id:p,name:m,interrupts:g,state:y!==void 0?y:f}}const n=cn(e);if(!n)return null;const r=Ft(n,["id","task_id","taskId"])??t,o=Ft(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function yo(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Uc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=yo(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=yo(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=yo(l,t,n+1,r);if(c)return c}}return null}function Uc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=Ft(n,["type","event","kind"]),o=Ft(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Uc(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Wc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function $y(e,t){if(!e||typeof e!="object")return null;const n=e,r=cn(e)??{},o=cn(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=_y[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=cn(o.additional_kwargs)??cn(o.additionalKwargs),d=cn(o.response_metadata)??cn(o.responseMetadata),f=Ft(c,["createdAt","created_at"])??Ft(o,["created_at","createdAt"]),h=Ft(c,["checkpointId","checkpoint_id"]),p=Ft(c,["checkpointNs","checkpoint_ns"]),m=zy(o.content),g={id:l,role:i,content:m};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),h&&(g.checkpointId=h),p&&(g.checkpointNs=p);const y=Wy(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),x=d?{...d}:void 0;y&&Object.keys(y).length&&(g.additionalKwargs=y),x&&Object.keys(x).length&&(g.responseMetadata=x);const w=By((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(g.content=[...g.content,...w]),i==="tool"){const C=Hy(o,g.content);C&&(g.content=C)}return g}function zy(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Vc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Vc(e);return t?[t]:[]}return[]}function Vc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=Ft(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=Ft(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Kc(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=Ft(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Kc(e,t){var s;const n=Ft(e,["id","call_id"])??t,r=Ft(e,["name"])??Ft(cn(e.function),["name"]);if(!n||!r)return null;const o=Uy(e.args??e.arguments??((s=cn(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function By(e){return Array.isArray(e)?e.map((t,n)=>Kc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Hy(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function Uy(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function cn(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Ft(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Wy(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function Vy(e){return e.type!=="thread_info"&&e.type!=="token"}const Ky={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function qy(e,t){var n;switch(t.type){case"reset":return{messages:Zi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=Zi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=Zi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Gc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Gc(o,s),e):e}case"interrupt_response":return{...e,messages:Yc(e.messages),pendingInterrupt:null};default:return e}}function qc(e=[]){const[t,n]=b.useReducer(qy,{...Ky,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=b.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Gc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Jy(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??Xc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(T=>T.id===a&&T.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:Qc(d.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:m,newMeta:g,changed:y}=Gy(d.content,t.delta,h,p);if(!y)return e;const x={...d,content:m},w=ds(l,c,x),C={...f,[a]:g};return{...e,messages:w,messagesStreamMeta:C}}if(t.type==="message_end"){const a=e.assemblingId??Xc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=d.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=Jc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=Zc(e,d,c),h=f>=0?e.messages[f]:null,p=l??d[0]??`${c}-${Date.now()}`,m=(h==null?void 0:h.id)??`tool-${p}`,g=d[0]??p,y={type:"tool_call",id:g,name:c,args:t.args};if(h){const C=ea(h,d,c,t.args),T={...h,name:h.name??c,additionalKwargs:C},k=f,S=k>=0?ds(e.messages,k,T):e.messages,E=fs(T,d),j=ta(e.toolIndex,m,E);return{...e,messages:S,toolIndex:j}}const x={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:ea(void 0,d.length?d:[g],c,t.args)},w=fs(x,d.length?d:[g]);return{...e,messages:[...e.messages,x],toolIndex:ta(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=Jc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=Zc(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",h=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,p=(d==null?void 0:d.id)??`tool-${h}`,m=fs(d,a);let g=t.output;if(typeof t.output=="string")try{const S=t.output.trim();(S.startsWith("{")||S.startsWith("["))&&(g=JSON.parse(S))}catch{g=t.output}const y={type:"text",text:typeof g=="string"?g:JSON.stringify(g)},x=(d==null?void 0:d.createdAt)??new Date().toISOString(),w=ea(d??void 0,m.length?m:a,f),C={id:p,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[y],createdAt:x,additionalKwargs:w},T=c>=0?ds(e.messages,c,C):[...e.messages,C],k=fs(C,a.length?a:m);return{...e,messages:T,toolIndex:ta(e.toolIndex,p,k)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Xy(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=cs(t),l=a.interrupt,c=a.latest,d=l===null?Yc(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return e}function Zi(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function ds(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Yc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function Xc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Jc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function Qi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function ea(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=Qi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function fs(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Qi(e);for(const o of r)n.add(o);return Array.from(n)}function ta(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function Zc(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(Qi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function Qc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Gy(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Qc(e);let l="",c=e.slice();if(s){const f=Yy(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function eu(e){return e.replace(/\s+/g," ").trim()}function Yy(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=eu(e),o=eu(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Xy(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return ds(e,r,s)}return e}function Jy(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function tu(e={}){const t=b.useMemo(()=>Jn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[f,h]=b.useState(""),[p,m]=b.useState(null),[g,y]=b.useState(0),[x,w]=b.useState(!1),C=b.useRef(null),T=b.useRef(!0),k=b.useRef(0),S=b.useRef(null),E=b.useRef(null),j=b.useRef(null),_=b.useRef(null),P=b.useCallback(O=>{o(O)},[]),D=b.useCallback(()=>{h(""),m(null),d(null),E.current=null,j.current=null,_.current=null},[]),z=b.useCallback(()=>{var O;console.debug("[use-chat] stop() invoked - aborting stream"),(O=C.current)==null||O.abort(),C.current=null,S.current=null,l(!1),w(!1),k.current=0,y(0)},[]),B=b.useCallback((O,H,R)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),m(null),E.current=null,j.current=null,_.current=null;const V=new AbortController;C.current=V;let $=null,F=null,ne=!1;return S.current={threadId:O.threadId??null,headers:{}},(async()=>{var ye,Pe,Z,ue,ke,te,L,G,se,le,U,We,re,xe,Re,Fe,tt,Se;const Q=Ge=>{var nt;try{const Qe=JSON.parse(JSON.stringify(Ge));return(nt=Qe==null?void 0:Qe.payload)!=null&&nt.files_info&&Array.isArray(Qe.payload.files_info)&&(Qe.payload.files_info=Qe.payload.files_info.map(Ye=>({...Ye,data:Ye!=null&&Ye.data?`<base64 ${String(Ye.data).length} chars>`:Ye==null?void 0:Ye.data}))),Qe}catch{return Ge}};try{let Ge={};try{if(r)Ge={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ve=window.__AUTH_TOKEN__,Dt=((ye=window.localStorage)==null?void 0:ye.getItem("authToken"))||null;let _t=null;try{const Ie=(Pe=window.localStorage)==null?void 0:Pe.getItem("chat-settings");Ie&&(_t=((Z=JSON.parse(Ie))==null?void 0:Z.apiKey)||null)}catch{}const Y=Ve||Dt||_t||null;Y&&(Ge={Authorization:`Bearer ${Y}`})}}catch{}console.debug("[use-chat] POST",t+n,Q(O));let nt={};if(typeof window<"u")try{const ht=(ue=window.localStorage)==null?void 0:ue.getItem("authSessionId");ht&&(nt={"X-Session-Id":ht})}catch{}const Qe={...Ge,...nt,...s.current},Ye={"Content-Type":"application/json",Accept:"text/event-stream",...Qe},qe=await fetch(t+n,{method:"POST",headers:Ye,body:JSON.stringify(O),signal:V.signal,credentials:i});if(S.current&&(S.current.headers=Qe),!qe.ok||!qe.body){const ht=await qe.text().catch(()=>"");console.debug("[use-chat] non-OK response",qe.status,ht==null?void 0:ht.slice(0,500));const Ve=`stream ${qe.status}${ht?": "+ht:""}`;throw(ke=R==null?void 0:R.onConnectionError)==null||ke.call(R,Ve),ne=!0,$="error",F=Ve,new Error(Ve)}w(!0);const et=qe.body.getReader(),Mt=new TextDecoder;let Ct="",dt=[];k.current=0,y(0);let xt=0,ft=null;const rt=()=>{if(dt.length){const ht=dt.join("");dt=[],T.current&&h(Ve=>Ve+ht)}ft=null},rn=()=>{typeof window<"u"&&ft==null&&(ft=requestAnimationFrame(rt))};let on=Date.now();const Wt=setInterval(()=>{var ht;if(Date.now()-on>18e5){const Ve="Stream idle timeout";d(Ve),$="error",F=Ve,V.abort(),(ht=R==null?void 0:R.onError)==null||ht.call(R,Ve)}},5e3),zt=1024*1024;try{const ht=qe.headers.get("X-Thread-Id")||qe.headers.get("x-thread-id"),Ve=qe.headers.get("X-Thread-Created")||qe.headers.get("x-thread-created"),Dt=ht??null,_t=String(Ve??"").toLowerCase()==="true";for(S.current&&!S.current.threadId&&(S.current={...S.current,threadId:Dt}),(te=R==null?void 0:R.onOpen)==null||te.call(R,{threadId:Dt,created:_t});;){const{value:Y,done:Ie}=await et.read();if(Ie)break;Ct+=Mt.decode(Y,{stream:!0}),Ct.length>zt&&(Ct="",console.warn("Stream buffer reset: exceeded 1MB"));let ve;for(;(ve=Ct.indexOf(`
|
|
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"?Mi.exports=rg():Mi.exports=og();var u=Mi.exports;function Xl(e,t){return function(){return e.apply(t,arguments)}}const{toString:sg}=Object.prototype,{getPrototypeOf:Di}=Object,{iterator:Xo,toStringTag:Jl}=Symbol,Jo=(e=>t=>{const n=sg.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 Zl=jn("ArrayBuffer");function ig(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Zl(e.buffer),t}const ag=Zo("string"),ln=Zo("function"),Ql=Zo("number"),po=e=>e!==null&&typeof e=="object",lg=e=>e===!0||e===!1,Qo=e=>{if(Jo(e)!=="object")return!1;const t=Di(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Jl in e)&&!(Xo in e)},cg=e=>{if(!po(e)||ho(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},ug=jn("Date"),dg=jn("File"),fg=jn("Blob"),hg=jn("FileList"),pg=e=>po(e)&&ln(e.pipe),mg=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]"))},gg=jn("URLSearchParams"),[yg,xg,vg,wg]=["ReadableStream","Request","Response","Headers"].map(jn),bg=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 ec(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,tc=e=>!Hr(e)&&e!==Sr;function Li(){const{caseless:e,skipUndefined:t}=tc(this)&&this||{},n={},r=(o,s)=>{const i=e&&ec(n,s)||s;Qo(n[i])&&Qo(o)?n[i]=Li(n[i],o):Qo(o)?n[i]=Li({},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 Sg=(e,t,n,{allOwnKeys:r}={})=>(mo(t,(o,s)=>{n&&ln(o)?e[s]=Xl(o,n):e[s]=o},{allOwnKeys:r}),e),Cg=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),kg=(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)},Tg=(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&&Di(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Eg=(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},Ig=e=>{if(!e)return null;if(Br(e))return e;let t=e.length;if(!Ql(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Ng=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Di(Uint8Array)),Ag=(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])}},_g=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},jg=jn("HTMLFormElement"),Pg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),nc=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Rg=jn("RegExp"),rc=(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)},Og=e=>{rc(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+"'")})}})},Mg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Br(e)?r(e):r(String(e).split(t)),n},Dg=()=>{},Lg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Fg(e){return!!(e&&ln(e.append)&&e[Jl]==="FormData"&&e[Xo])}const $g=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)},zg=jn("AsyncFunction"),Bg=e=>e&&(po(e)||ln(e))&&ln(e.then)&&ln(e.catch),oc=((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)),Hg=typeof queueMicrotask<"u"?queueMicrotask.bind(Sr):typeof process<"u"&&process.nextTick||oc,M={isArray:Br,isArrayBuffer:Zl,isBuffer:ho,isFormData:mg,isArrayBufferView:ig,isString:ag,isNumber:Ql,isBoolean:lg,isObject:po,isPlainObject:Qo,isEmptyObject:cg,isReadableStream:yg,isRequest:xg,isResponse:vg,isHeaders:wg,isUndefined:Hr,isDate:ug,isFile:dg,isBlob:fg,isRegExp:Rg,isFunction:ln,isStream:pg,isURLSearchParams:gg,isTypedArray:Ng,isFileList:hg,forEach:mo,merge:Li,extend:Sg,trim:bg,stripBOM:Cg,inherits:kg,toFlatObject:Tg,kindOf:Jo,kindOfTest:jn,endsWith:Eg,toArray:Ig,forEachEntry:Ag,matchAll:_g,isHTMLForm:jg,hasOwnProperty:nc,hasOwnProp:nc,reduceDescriptors:rc,freezeMethods:Og,toObjectSet:Mg,toCamelCase:Pg,noop:Dg,toFiniteNumber:Lg,findKey:ec,global:Sr,isContextDefined:tc,isSpecCompliantForm:Fg,toJSONObject:$g,isAsyncFn:zg,isThenable:Bg,setImmediate:oc,asap:Hg,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 sc=De.prototype,ic={};["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=>{ic[e]={value:e}}),Object.defineProperties(De,ic),Object.defineProperty(sc,"isAxiosError",{value:!0}),De.from=(e,t,n,r,o,s)=>{const i=Object.create(sc);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 Ug=null;function Fi(e){return M.isPlainObject(e)||M.isArray(e)}function ac(e){return M.endsWith(e,"[]")?e.slice(0,-2):e}function lc(e,t,n){return e?e.concat(t).map(function(o,s){return o=ac(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Wg(e){return M.isArray(e)&&!e.some(Fi)}const Vg=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)&&Wg(m)||(M.isFileList(m)||M.endsWith(g,"[]"))&&(x=M.toArray(m)))return g=ac(g),x.forEach(function(C,T){!(M.isUndefined(C)||C===null)&&t.append(i===!0?lc([g],T,s):i===null?g:g+"[]",c(C))}),!1}return Fi(m)?!0:(t.append(lc(y,g,s),c(m)),!1)}const f=[],h=Object.assign(Vg,{defaultVisitor:d,convertValue:c,isVisitable:Fi});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 cc(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function $i(e,t){this._pairs=[],e&&es(e,this,t)}const uc=$i.prototype;uc.append=function(t,n){this._pairs.push([t,n])},uc.toString=function(t){const n=t?function(r){return t.call(this,r,cc)}:cc;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Kg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function dc(e,t,n){if(!t)return e;const r=n&&n.encode||Kg;M.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=M.isURLSearchParams(t)?t.toString():new $i(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class fc{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 hc={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},qg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:$i,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},zi=typeof window<"u"&&typeof document<"u",Bi=typeof navigator=="object"&&navigator||void 0,Gg=zi&&(!Bi||["ReactNative","NativeScript","NS"].indexOf(Bi.product)<0),Yg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Xg=zi&&window.location.href||"http://localhost",Zt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:zi,hasStandardBrowserEnv:Gg,hasStandardBrowserWebWorkerEnv:Yg,navigator:Bi,origin:Xg},Symbol.toStringTag,{value:"Module"})),...qg};function Jg(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 Zg(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Qg(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 pc(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]=Qg(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t(Zg(r),o,n,0)}),n}return null}function ey(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:hc,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(pc(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 Jg(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),ey(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 ty=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"]),ny=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]&&ty[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},mc=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 ry(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 oy=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Hi(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 sy(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function iy(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())&&!oy(t))i(ny(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 ry(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||Hi(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||Hi(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||Hi(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?sy(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[mc]=this[mc]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=yo(i);r[a]||(iy(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 Ui(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 gc(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 yc(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 ay(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function ly(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 cy(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=ly(50,250);return cy(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)},xc=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},vc=e=>(...t)=>M.asap(()=>e(...t)),uy=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,dy=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 fy(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function hy(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function wc(e,t,n){let r=!fy(t);return e&&(r||n==!1)?hy(e,t):t}const bc=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(bc(c),bc(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 Sc=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=dc(wc(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&&uy(t.url))){const l=o&&s&&dy.read(s);l&&i.set(o,l)}return t},py=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Sc(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};yc(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||hc;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=ay(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)})},my=(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}},gy=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},yy=async function*(e,t){for await(const n of xy(e))yield*gy(n,t)},xy=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()}},Cc=(e,t,n,r)=>{const o=yy(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})},kc=64*1024,{isFunction:rs}=M,vy=(({Request:e,Response:t})=>({Request:e,Response:t}))(M.global),{ReadableStream:Tc,TextEncoder:Ec}=M.global,Ic=(e,...t)=>{try{return!!e(...t)}catch{return!1}},wy=e=>{e=M.merge.call({skipUndefined:!0},vy,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(Tc),l=o&&(typeof Ec=="function"?(m=>g=>m.encode(g))(new Ec):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Ic(()=>{let m=!1;const g=new n(Zt.origin,{body:new Tc,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),d=i&&a&&Ic(()=>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}=Sc(m),D=t||fetch;E=E?(E+"").toLowerCase():"text";let z=my([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]=xc(H,ns(vc(S)));x=Cc(Q.body,kc,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&&xc(ye,ns(vc(k),!0))||[];$=new r(Cc($.body,kc,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)=>{yc(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)}}},by=new Map,Nc=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=by;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:wy(t)),d=c;return c};Nc();const Wi={http:Ug,xhr:py,fetch:{get:Nc}};M.forEach(Wi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Ac=e=>`- ${e}`,Sy=e=>M.isFunction(e)||e===null||e===!1,_c={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,!Sy(r)&&(o=Wi[(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
|
+
`+i.map(Ac).join(`
|
|
34
|
+
`):" "+Ac(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:Wi};function Vi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Ur(null,e)}function jc(e){return Vi(e),e.headers=cn.from(e.headers),e.data=Ui.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),_c.getAdapter(e.adapter||go.adapter,e)(e).then(function(r){return Vi(e),r.data=Ui.call(e,e.transformResponse,r),r.headers=cn.from(r.headers),r},function(r){return gc(r)||(Vi(e),r&&r.response&&(r.response.data=Ui.call(e,e.transformResponse,r.response),r.response.headers=cn.from(r.response.headers))),Promise.reject(r)})}const Pc="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 Rc={};os.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Pc+"] 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&&!Rc[i]&&(Rc[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 Cy(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:Cy,validators:os},$n=ss.validators;let kr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new fc,response:new fc}}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=[jc.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=jc.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=wc(t.baseURL,t.url,t.allowAbsoluteUrls);return dc(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 ky=class eg{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 eg(function(o){t=o}),cancel:t}}};function Ty(e){return function(n){return e.apply(null,n)}}function Ey(e){return M.isObject(e)&&e.isAxiosError===!0}const Ki={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(Ki).forEach(([e,t])=>{Ki[t]=e});function Oc(e){const t=new kr(e),n=Xl(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 Oc(Cr(e,o))},n}const Ot=Oc(go);Ot.Axios=kr,Ot.CanceledError=Ur,Ot.CancelToken=ky,Ot.isCancel=gc,Ot.VERSION=Pc,Ot.toFormData=es,Ot.AxiosError=De,Ot.Cancel=Ot.CanceledError,Ot.all=function(t){return Promise.all(t)},Ot.spread=Ty,Ot.isAxiosError=Ey,Ot.mergeConfig=Cr,Ot.AxiosHeaders=cn,Ot.formToJSON=e=>pc(M.isHTMLForm(e)?new FormData(e):e),Ot.getAdapter=_c.getAdapter,Ot.HttpStatusCode=Ki,Ot.default=Ot;const{Axios:jT,AxiosError:PT,CanceledError:RT,isCancel:OT,CancelToken:MT,VERSION:DT,all:LT,Cancel:FT,isAxiosError:$T,spread:zT,toFormData:BT,AxiosHeaders:HT,HttpStatusCode:UT,formToJSON:WT,getAdapter:VT,mergeConfig:KT}=Ot,Mc=typeof window<"u"?window.__API_BASE_URL__:void 0,Dc=Mc?Xn(Mc):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 qi=new Set;let Gi=null;function Lc(){return is}function Yi(e){is=e,qi.forEach(t=>t(e))}function Fc(e){return qi.add(e),()=>qi.delete(e)}function Iy(e){Gi=e}const Ny=3e4,Ay=9e4,wn=Ot.create({...Dc?{baseURL:Dc}:{},timeout:Ny,withCredentials:!0});wn.interceptors.request.use(e=>(is&&(e.headers.Authorization=`Bearer ${is}`),e)),wn.interceptors.response.use(e=>{if(Gi&&(e!=null&&e.data))try{Gi(e.data)}catch(t){console.warn("[chat-api] Error in token sync handler:",t)}return e},e=>Promise.reject(e));const as=new Map,$c=new Map,_y=5e3;function jy(e,t){const n=t==null?void 0:t.params,r=n?JSON.stringify(n):"";return`GET:${e}:${r}`}async function bn(e,t){if(!wn.defaults.baseURL)return Promise.reject(new Error("API base URL is not configured"));const n=jy(e,t),r=$c.get(n);if(r&&Date.now()-r.timestamp<_y)return r.data;const o=as.get(n);if(o)return o;const s=wn.get(e,t).then(i=>(as.delete(n),$c.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 Xi(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 zc(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 Bc(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 Hc{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&&Yi(t.authToken)}getAuthToken(){return Lc()}setAuthToken(t){Yi(t)}onTokenChange(t){return Fc(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 Xi("/threads",t?{title:t}:void 0);return Sn(r)}async updateThread(t,n){const r=await zc(`/threads/${t}`,{title:n});return Sn(r)}async deleteThread(t){const n=await Bc(`/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:Ay});return Sn(n)}async cancelRun(t){const n=await Xi("/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 Hc,Uc=w.createContext(null);function Py({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(Uc.Provider,{value:r,children:e})}function Ji(){const e=w.useContext(Uc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Ry(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 Oy(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Ry(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const My={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Zi(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(!Zi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Ly(t),i=Wc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Wc(e,t){if(!Zi(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)=>Wy(_,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:Dy(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 Dy(e,t,n){const r=Hy(e,n);return r||By(t,n)}function Ly(e){const t=new Map;e.forEach((o,s)=>{if(!Zi(o))return;const i=Wc(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,Fy(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Kc(s.createdAt??"")-Kc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Fy(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:$y(e.next,t.next)??null,tasks:zy(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 $y(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 zy(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 By(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 Hy(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Uy(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 Uy(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=Vc(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 Vc(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=Vc(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 Kc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Wy(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=My[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=Vy(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=Yy(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=Ky((c==null?void 0:c.tool_calls)??o.tool_calls);if(b.length&&(g.content=[...g.content,...b]),i==="tool"){const C=qy(o,g.content);C&&(g.content=C)}return g}function Vy(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>qc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=qc(e);return t?[t]:[]}return[]}function qc(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 Gc(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 Gc(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=Gy(e.args??e.arguments??((s=un(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Ky(e){return Array.isArray(e)?e.map((t,n)=>Gc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function qy(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 Gy(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 Yy(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 Xy(e){return e.type!=="thread_info"&&e.type!=="token"}const Jy={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Zy(e,t){var n;switch(t.type){case"reset":return{messages:Qi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=Qi(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=Qi(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 Xc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Xc(o,s),e):e}case"interrupt_response":return{...e,messages:Jc(e.messages),pendingInterrupt:null};default:return e}}function Yc(e=[]){const[t,n]=w.useReducer(Zy,{...Jy,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 Xc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=nx(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??Zc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(T=>T.id===a&&T.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:tu(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}=Qy(d.content,t.delta,h,p);if(!y)return e;const x={...d,content:m},b=us(l,c,x),C={...f,[a]:g};return{...e,messages:b,messagesStreamMeta:C}}if(t.type==="message_end"){const a=e.assemblingId??Zc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=d.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=Qc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=eu(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=ta(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=na(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:ta(void 0,d.length?d:[g],c,t.args)},b=ds(x,d.length?d:[g]);return{...e,messages:[...e.messages,x],toolIndex:na(e.toolIndex,m,b)}}if(t.type==="tool_end"){const a=Qc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=eu(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(),b=ta(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?us(e.messages,c,C):[...e.messages,C],k=ds(C,a.length?a:m);return{...e,messages:T,toolIndex:na(e.toolIndex,p,k)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=tx(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?Jc(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 Qi(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 Jc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function Zc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Qc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function ea(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 ta(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=ea(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=ea(e);for(const o of r)n.add(o);return Array.from(n)}function na(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 eu(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(ea(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 tu(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Qy(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??tu(e);let l="",c=e.slice();if(s){const f=ex(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 nu(e){return e.replace(/\s+/g," ").trim()}function ex(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=nu(e),o=nu(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 tx(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 nx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function ru(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 nu=200;function ex({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),h=b.useRef(null),p=b.useCallback(_=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(_)}catch{}try{return JSON.parse(JSON.stringify(_))}catch{return _}},[]),m=b.useCallback((_,P)=>{if(!_)return;const D=f.current.get(_)??[],z=p(P),B=D.length>=nu?[...D.slice(D.length-nu+1),z]:[...D,z];f.current.set(_,B)},[p]),g=b.useCallback(_=>{_&&f.current.set(_,[])},[]),y=b.useCallback(_=>{const P=_??d.current;if(!P)return;const D=f.current.get(P);D!=null&&D.length&&D.forEach(z=>{try{n(z)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),x=b.useCallback(_=>{var z,B,O,H,R;const P=_.seq??null;if(P!==null){const V=c.current;if(V!==null){if(P<=V)return;P>V+1&&(o==null||o({from:V,to:P}))}c.current=P}if(_.type==="thread_info"){d.current=_.threadId,h.current&&(h.current.threadIdGuess=_.threadId),g(_.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",_);try{t(_)}catch(V){console.error("[useChatStreamingService] Error in onThreadInfo handler:",V)}return}if(_.type==="heartbeat"){try{l==null||l(_)}catch(V){console.error("[useChatStreamingService] Error in onHeartbeat handler:",V)}return}if(_.type==="error"){const V=_;if(V.error_type==="auth_error"||V.code==="TOKEN_EXPIRED"||((z=V.message)==null?void 0:z.includes("token"))||((B=V.message)==null?void 0:B.includes("401"))||((O=V.message)==null?void 0:O.includes("unauthorized"))||((H=V.message)==null?void 0:H.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",V.message);try{a==null||a(V.message)}catch(F){console.warn("[useChatStreamingService] onAuthError handler failed",F)}}}const D=_.threadId??(_.type==="state_history"?_.threadId:void 0)??d.current??((R=h.current)==null?void 0:R.threadIdGuess)??null;if(_.type==="state_history"&&(d.current=D??d.current),Vy(_)){_.type==="checkpoint"||_.type==="state_history"?g(D??null):m(D??null,_);try{n(_)}catch(V){console.error("[useChatStreamingService] Error in onMessageEvent handler:",V)}return}try{r==null||r(_)}catch(V){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",V)}},[m,g,n,o,t,r]),{stream:w,stop:C,isStreaming:T,error:k,setToken:S}=tu({baseUrl:e,token:void 0}),E=b.useCallback((_,P)=>{c.current=null,d.current=_.threadId??null,h.current={request:_,callbacks:P,manualStop:!1,threadIdGuess:_.threadId??null},w(_,x,{onOpen:P==null?void 0:P.onOpen,onError:D=>{var z;(z=P==null?void 0:P.onError)==null||z.call(P,D)},onGap:(P==null?void 0:P.onGap)??o,onConnectionError:D=>{var z;i==null||i(D),(z=P==null?void 0:P.onConnectionError)==null||z.call(P,D)},onAuthError:D=>{var z;a==null||a(D),(z=P==null?void 0:P.onAuthError)==null||z.call(P,D)},onHeartbeat:D=>{var z;try{l==null||l(D)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(z=P==null?void 0:P.onHeartbeat)==null||z.call(P,D)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:D=>{var H,R,V,$;const z=((H=h.current)==null?void 0:H.manualStop)??!1,B=d.current??((R=h.current)==null?void 0:R.threadIdGuess)??((V=D.lastStateHistory)==null?void 0:V.threadId)??null;(D.reason==="complete"||D.reason==="aborted"&&z)&&g(B);const O={...D,threadId:B,manualStop:z};try{s==null||s(O)}catch(F){console.warn("[useChatStreamingService] onStreamClosed handler failed",F)}try{($=P==null?void 0:P.onClosed)==null||$.call(P,O)}catch(F){console.warn("[useChatStreamingService] downstream onClosed handler failed",F)}h.current&&(h.current=null)}})},[g,x,a,i,l,o,s,w]),j=b.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return b.useMemo(()=>({startStream:E,stop:j,isStreaming:T,error:k,setAuthToken:S,replayBufferedEvents:y}),[E,j,T,k,S,y])}const ru=50,tx=750,na="chat-history@1",nx=5,rx=1e3,ox=15e3,hs=300;function ou(e,t=hs){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function kr(){return typeof window<"u"&&typeof window.localStorage<"u"}function ra(e){if(!kr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function oa(e,t){if(!kr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function sa(e){if(kr())try{window.localStorage.removeItem(e)}catch{}}function ia(e){return e==null?e:{...e}}function sx(e){return e==null?e:{...e}}function ix(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function ax(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function un(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=ia(e==null?void 0:e.metadata),s=ia(e==null?void 0:e.config),i=ia(e==null?void 0:e.parentConfig),a=ix(e==null?void 0:e.next),l=ax(e==null?void 0:e.tasks),c=sx(e==null?void 0:e.values),d={checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??null,parentId:(e==null?void 0:e.parentId)??null,branchLabel:(e==null?void 0:e.branchLabel)??null,lastMessageId:(e==null?void 0:e.lastMessageId)??null,messagesLen:typeof(e==null?void 0:e.messagesLen)=="number"?e.messagesLen:r.length,hasMessages:typeof(e==null?void 0:e.hasMessages)=="boolean"?e.hasMessages:r.length>0,messages:n?r.slice():r,nextCursor:(e==null?void 0:e.nextCursor)??null,nextCursorNs:(e==null?void 0:e.nextCursorNs)??null,interrupt:(e==null?void 0:e.interrupt)??null};return o!==void 0&&(d.metadata=o),s!==void 0&&(d.config=s),i!==void 0&&(d.parentConfig=i),a!==void 0&&(d.next=a),l!==void 0&&(d.tasks=l),c!==void 0&&(d.values=c),d}function lx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function su(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}function aa(e,t){return`${e}${t}`}function cx(e,t){const n=ra(aa(e,t));if(!n)return null;try{const r=JSON.parse(n);return typeof(r==null?void 0:r.threadId)!="string"?null:{threadId:r.threadId,snapshot:un(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function ux(e,t,n=100){if(!kr())return;const r=un(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=aa(e,t.threadId),i=JSON.stringify(o);if(!oa(s,i))try{const a=[];for(let l=0;l<window.localStorage.length;l++){const c=window.localStorage.key(l);if(!c||c===s||!c.startsWith(e))continue;const d=window.localStorage.getItem(c);if(!d){a.push({key:c,updatedAt:0});continue}try{const f=JSON.parse(d),h=typeof(f==null?void 0:f.updatedAt)=="number"&&Number.isFinite(f.updatedAt)?f.updatedAt:0;a.push({key:c,updatedAt:h})}catch{a.push({key:c,updatedAt:0})}}a.sort((l,c)=>l.updatedAt-c.updatedAt);for(const l of a)if(window.localStorage.removeItem(l.key),oa(s,i))break}catch{}}function dx(e,t){sa(aa(e,t))}function fx(e){if(kr())try{for(let t=0;t<window.localStorage.length;t++){const n=window.localStorage.key(t);n&&n.startsWith(e)&&window.localStorage.removeItem(n)}}catch{}}function iu(e,t,n){return`${e}__${t??""}__${n??""}`}function ps(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?{...e}:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function hx(e,t){return ps(e,t)}function px(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function mx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function au(e,t){const n=ps(e.metadata,t.metadata),r=ps(e.config,t.config),o=ps(e.parentConfig,t.parentConfig),s=px(e.next,t.next),i=mx(e.tasks,t.tasks),a=hx(e.values,t.values),l={};return n!==void 0&&(l.metadata=n??null),r!==void 0&&(l.config=r??null),o!==void 0&&(l.parentConfig=o??null),s!==void 0&&(l.next=s??null),i!==void 0&&(l.tasks=i??null),a!==void 0&&(l.values=a??null),l}function lu(e){return Array.isArray(e)?e.filter(t=>!!(t&&(t.checkpointId||t.checkpointNs))).map(t=>{const n=un(t,{cloneMessages:!0});return{...n,messages:Array.isArray(n.messages)?n.messages:[],values:n.values??null}}):[]}const gx="cachedThreads",yx="v1",la=200;function xx(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function ca(e,t){return`cachedThreads:v1:${e}:${xx(t||"anon")}`}function vx(){const e=ra(gx);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function wx(e){const t=ra(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function ua(e,t){oa(e,JSON.stringify(t))}function da(e){const t=wx(e);if(t.length>0)return t;const n=vx();if(n.length>0)try{ua(e,n.slice(0,la))}catch{}return n}function ms(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function fa(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function bx({currentThreadId:e,currentThreadIdRef:t}){const[n,r]=b.useState([]),o=b.useRef(new Map),s=b.useRef(new Map),i=b.useCallback(m=>{if(!m){r([]);return}const g=o.current.get(m);if(!g||!g.length){r([]);return}r(g.map(y=>un(y,{cloneMessages:!0})))},[]);b.useEffect(()=>{i(e)},[e,i]);const a=b.useCallback((m,g,y)=>{if(!m)return;const x=y==="replace"?[]:o.current.get(m)??[],w=y==="replace"?g:[...g,...x];if(!w.length){y==="replace"&&o.current.set(m,[]),m===t.current&&r([]);return}const C=new Map;for(const k of w){if(!(k!=null&&k.checkpointId))continue;const S=`${k.checkpointId}::${k.checkpointNs??""}`,E=un(k,{cloneMessages:!0}),j=C.get(S);if(!j){C.set(S,E);continue}const _=au(j,E);C.set(S,{...j,..._})}const T=Array.from(C.values()).sort((k,S)=>{const E=Number.isFinite(Date.parse(k.createdAt??""))?Date.parse(k.createdAt??""):0;return(Number.isFinite(Date.parse(S.createdAt??""))?Date.parse(S.createdAt??""):0)-E});o.current.set(m,T),m===t.current&&i(m)},[t,i]),l=b.useCallback((m,g,y)=>{if(!m)return;const x=s.current.get(m),w=y==="replace"||!x?new Map:new Map(x);if(g&&typeof g=="object")for(const[C,T]of Object.entries(g)){if(!(T!=null&&T.checkpointId))continue;const k=C||Vr(T.checkpointId,T.checkpointNs??null);w.set(k,un(T,{cloneMessages:!0}))}s.current.set(m,w)},[]),c=b.useCallback((m,g)=>{if(!m)return!1;const y=lu(g);if(!y.length)return!1;const x=o.current.get(m)??[],w=new Map,C=(k,{preferExisting:S})=>{for(const E of k){if(!(E!=null&&E.checkpointId)&&!(E!=null&&E.checkpointNs))continue;const j=Vr(E.checkpointId??null,E.checkpointNs??null);j&&(S&&w.has(j)?w.set(j,E):w.has(j)&&S||w.set(j,E))}};C(y,{preferExisting:!1}),C(x,{preferExisting:!0});const T=Array.from(w.values()).sort((k,S)=>{const E=Number.isFinite(Date.parse(k.createdAt??""))?Date.parse(k.createdAt??""):0;return(Number.isFinite(Date.parse(S.createdAt??""))?Date.parse(S.createdAt??""):0)-E});return o.current.set(m,T),m===t.current&&r(T.map(k=>un(k,{cloneMessages:!0}))),!0},[t]),d=b.useCallback(m=>{m&&(o.current.delete(m),s.current.delete(m),m===t.current&&r([]))},[t]),f=b.useCallback(()=>{r([])},[]),h=b.useCallback(m=>m?s.current.get(m)??null:null,[]),p=b.useCallback((m,g)=>{var y;if(m)return(y=s.current.get(m))==null?void 0:y.get(g)},[]);return{threadCheckpoints:n,syncActiveThreadCheckpoints:i,updateCheckpointCache:a,updateCheckpointSnapshots:l,applyCheckpointSummaries:c,clearThreadCaches:d,resetThreadCheckpoints:f,getSnapshotCache:h,getSnapshotFromCache:p}}const cu=b.createContext(null),uu=b.createContext(null),du=b.createContext(null),Sx=b.createContext(!1);function Cx({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onAuthError:a,onThreadChange:l}){const{api:c,baseUrl:d}=Xi(),f=b.useMemo(()=>Jn(d),[d]),h=b.useMemo(()=>{try{return new URL(d).host}catch{return"unknown"}},[d]),p=b.useMemo(()=>`threadPayload:${yx}:${h}:`,[h]),m=b.useCallback(I=>cx(p,I),[p]),g=b.useCallback((I,A=100)=>{ux(p,I,A)},[p]),y=b.useCallback(I=>{dx(p,I)},[p]),x=b.useCallback(()=>{fx(p)},[p]),[w,C]=b.useState(()=>{var I;return ca(h,(I=c.getAuthToken)==null?void 0:I.call(c))}),[T,k]=b.useState(()=>{var A;const I=da(ca(h,(A=c.getAuthToken)==null?void 0:A.call(c)));return ms(I)}),S=b.useMemo(()=>fa(T),[T]),[E,j]=b.useState(t),[_,P]=b.useState(!1),[D,z]=b.useState(!1),[B,O]=b.useState(null),[H,R]=b.useState(null),[V,$]=b.useState(null),F=b.useCallback(()=>{const I=da(w);b.startTransition(()=>{k(ms(I))})},[w]),[ne,Q]=b.useState(!1),[ye,Pe]=b.useState(!1),[Z,ue]=b.useState(null),[ke,te]=b.useState(void 0),[L,G]=b.useState(void 0),[se,le]=b.useState(void 0),{state:U,dispatch:We,seed:re,prepend:xe,pushUser:Re,onEvent:Fe,reset:tt}=qc(),Se=b.useRef(E);b.useEffect(()=>{Se.current=E},[E]);const Ge=b.useRef(!1),nt=b.useRef([]),Qe=b.useRef(null),Ye=b.useRef(null),qe=b.useRef(new Map),et=b.useRef(E),Mt=b.useRef(!1),Ct=b.useRef(null),dt=b.useRef(null),xt=b.useRef(new Map),ft=b.useRef(new Map),{threadCheckpoints:rt,syncActiveThreadCheckpoints:rn,updateCheckpointCache:on,updateCheckpointSnapshots:Wt,applyCheckpointSummaries:zt,clearThreadCaches:ht,resetThreadCheckpoints:Ve,getSnapshotCache:Dt,getSnapshotFromCache:_t}=bx({currentThreadId:E,currentThreadIdRef:Se}),Y=b.useCallback(()=>{var K;const I=ft.current;if(I.size<=ru)return;const A=Array.from(I.entries()).sort((fe,ae)=>fe[1].timestamp-ae[1].timestamp),W=I.size-ru;for(let fe=0;fe<W;fe++){const ae=(K=A[fe])==null?void 0:K[0];ae&&I.delete(ae)}},[]),Ie=b.useCallback((I,A)=>{if(!I)return null;const W=Array.isArray(I.checkpoints)?I.checkpoints:[];return W.length===0?null:{version:I.version===na?I.version:na,threadId:I.threadId??A,checkpoints:W}},[]),ve=b.useCallback((I,A)=>{const{threadId:W,checkpointId:K=null,checkpointNs:fe=null}=I,ae=iu(W,K,fe);if(A!=null&&A.force)xt.current.delete(ae),ft.current.delete(ae);else{if(A!=null&&A.preferCache){const kt=ft.current.get(ae);if(kt)return Promise.resolve(kt.result)}const Be=xt.current.get(ae);if(Be)return Be}const St=(async()=>{try{const Be=await c.getStateHistory({threadId:W,checkpointId:K??void 0,checkpointNs:fe??void 0}),kt=Ie(Be,W);if(kt)return{payload:kt,usedHistoryApi:!0};throw new Error("History response missing checkpoints")}catch(Be){console.warn("[ChatSessionProvider] getStateHistory failed, falling back to getState:",Be);const kt=await c.getState({threadId:W,checkpointId:K??void 0,checkpointNs:fe??void 0});return{payload:{version:na,threadId:W,checkpoints:[kt]},usedHistoryApi:!1}}})().then(Be=>(ft.current.set(ae,{result:Be,timestamp:Date.now()}),Y(),Be)).finally(()=>{xt.current.get(ae)===St&&xt.current.delete(ae)});return xt.current.set(ae,St),St},[c,Ie,Y]),ot=b.useCallback((I,A)=>new Promise((W,K)=>{const fe=async()=>{Ge.current=!0;try{await I(),W()}catch(ae){K(ae)}finally{Ge.current=!1;const ae=nt.current.shift();ae&&ae().catch(()=>{})}};Ge.current?nt.current.push(fe):fe().catch(ae=>{K(ae)})}),[]),vt=b.useRef(S.length),It=b.useRef(!1);b.useEffect(()=>{vt.current=S.length},[S.length]),b.useEffect(()=>{const I=U.pendingInterrupt??lx(U.messages);su(V,I)||$(I??null)},[V,U.messages,U.pendingInterrupt]);const Ne=b.useCallback(async()=>{const I=vt.current>0;I||P(!0);try{const A=await c.listThreads();b.startTransition(()=>{k(W=>{const K=yt=>yt.map(St=>`${St.threadId}:${St.updatedAt??""}:${St.messageCount??""}`).join("|"),fe=fa(W);return K(fe)===K(A)||A.length===0&&fe.length>0&&!It.current?W:ms(A)}),I||P(!1)}),O(null),It.current||(It.current=!0)}catch(A){i==null||i(String(A)),console.error("[ChatSessionProvider] Failed to refresh threads:",A),O(String(A)),I||P(!1)}},[c,i]),Qt=b.useRef(!1),at=b.useRef(null),Xe=b.useRef(null),sn=b.useRef(""),[qn,jt]=b.useState("idle"),rr=b.useRef({attempts:0,timer:null,reason:null}),Fr=b.useRef(null),Ko=b.useRef(0),$r=b.useRef(()=>{}),N=b.useRef(()=>{}),q=b.useRef(()=>{}),de=I=>{if(!I||typeof I!="object")return!1;const A=I;return A.code==="ECONNABORTED"?!0:(typeof A.message=="string"?A.message.toLowerCase():"").includes("timeout")},Ce=b.useCallback(async I=>{const A=await c.listCheckpointSummaries(I);return lu(A??[])},[c]),He=b.useCallback((I,A)=>{if(!kr())return;Xe.current!==null&&(window.clearTimeout(Xe.current),Xe.current=null);const W=I.map(fe=>`${fe.threadId}:${fe.updatedAt??""}:${fe.messageCount??""}`).join("|");if(I.length===0){try{sa(w)}catch{}sn.current="";return}if(W===sn.current)return;const K=()=>{try{const fe=I.slice(0,la);ua(w,fe),sn.current=W}catch{}finally{Xe.current=null}};if(A!=null&&A.immediate){K();return}Xe.current=window.setTimeout(()=>{ou(K)},hs)},[w]),lt=b.useCallback(()=>{He(S,{immediate:!0})},[He,S]),Oe=b.useCallback((I,A,W,K)=>{var Wl;const fe=W??Se.current;if(!fe)return;const ae=un(I),yt=fe===Se.current,St=(K==null?void 0:K.persist)!==!1;if(A==="replace"){if(St){const Kt={threadId:fe,snapshot:un(I,{cloneMessages:!0})};qe.current.set(fe,Kt),et.current=fe}if(!yt)return;re(ae.messages,{checkpointId:ae.checkpointId??null,checkpointNs:ae.checkpointNs??null,pendingInterrupt:ae.interrupt??null}),$(ae.interrupt??null),ue(ae.nextCursor??null),Q(!!ae.nextCursor),te(ae.checkpointId??void 0),G(ae.checkpointNs??void 0),le(ae.nextCursorNs??void 0);return}const Be=qe.current.get(fe),kt=(Be==null?void 0:Be.snapshot)??null,Ut=Array.isArray(kt==null?void 0:kt.messages)?kt.messages:[],hn=un(kt),Xn=Array.isArray(I==null?void 0:I.messages)?I.messages:[],Vt=new Set,Pt=[...Xn,...Ut].filter(Kt=>{const Vl=Kt==null?void 0:Kt.id;return Vl?Vt.has(Vl)?!1:(Vt.add(Vl),!0):!0}),or=au(hn,ae),zr={checkpointId:hn.checkpointId??ae.checkpointId??null,checkpointNs:hn.checkpointNs??ae.checkpointNs??null,createdAt:ae.createdAt??hn.createdAt??null,parentId:ae.parentId??hn.parentId??null,branchLabel:ae.branchLabel??hn.branchLabel??null,lastMessageId:((Wl=Pt[Pt.length-1])==null?void 0:Wl.id)??null,messagesLen:Pt.length,hasMessages:Pt.length>0,messages:Pt,nextCursor:ae.nextCursor??hn.nextCursor??null,nextCursorNs:ae.nextCursorNs??hn.nextCursorNs??null,interrupt:hn.interrupt??ae.interrupt??null,...or};if(qe.current.set(fe,{threadId:fe,snapshot:un(zr,{cloneMessages:!0})}),!yt)return;Xn.length&&xe(Xn);const lo=I&&Object.prototype.hasOwnProperty.call(I,"checkpointId")?I.checkpointId:void 0,Nn=I&&Object.prototype.hasOwnProperty.call(I,"checkpointNs")?I.checkpointNs:void 0,Br=I&&Object.prototype.hasOwnProperty.call(I,"nextCursor")?I.nextCursor:void 0,vr=I&&Object.prototype.hasOwnProperty.call(I,"nextCursorNs")?I.nextCursorNs:void 0;ue(Kt=>Br!==void 0?Br??Kt??null:Kt??null),Q(Kt=>Br!==void 0?!!Br:Kt),te(Kt=>lo!==void 0?lo??Kt??void 0:Kt??void 0),G(Kt=>Nn!==void 0?Nn??Kt??void 0:Kt??void 0),le(Kt=>vr!==void 0?vr??void 0:Kt)},[xe,re,$]),$e=b.useCallback(I=>{if(I.threadId!=null&&I.threadId!==Se.current)return;const A=un(I.snapshot,{cloneMessages:!0});re(A.messages,{checkpointId:A.checkpointId??null,checkpointNs:A.checkpointNs??null,pendingInterrupt:A.interrupt??null}),$(A.interrupt??null),ue(A.nextCursor??null),Q(!!A.nextCursor),te(A.checkpointId??void 0),G(A.checkpointNs??void 0),le(A.nextCursorNs??void 0),et.current=I.threadId,rn(I.threadId??Se.current??null)},[re,$,rn]),At=b.useCallback(I=>{if(!I)return;qe.current.delete(I),y(I),ht(I);const A=`${I}__`;for(const W of xt.current.keys())W.startsWith(A)&&xt.current.delete(W);for(const W of ft.current.keys())W.startsWith(A)&&ft.current.delete(W);et.current===I&&(et.current=null)},[ht,y]),pt=b.useCallback(()=>{const I=Se.current;I&&At(I),tt([]),Q(!1),Pe(!1),ue(null),te(void 0),G(void 0),le(void 0)},[At,tt]),mt=b.useCallback(({from:I,to:A})=>{const W=Se.current;W&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${I} -> ${A}) for thread ${W}`)},[]),en=b.useCallback(I=>{const A=I.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:A,title:I.title,created:I.created,currentThreads:S.length});const W={threadId:A,title:I.title||`Thread ${A.slice(0,8)}`,createdAt:I.createdAt||new Date().toISOString(),updatedAt:I.updatedAt||new Date().toISOString(),messageCount:I.messageCount||0};Se.current!==A&&(!Se.current&&U.messages.length<=1&&(Ye.current=A),j(A)),b.startTransition(()=>{k(K=>{const fe=K.byId[A];return fe?fe.title===W.title&&fe.updatedAt===W.updatedAt&&fe.messageCount===W.messageCount?K:{byId:{...K.byId,[A]:W},order:K.order}:{byId:{...K.byId,[A]:W},order:[A,...K.order]}})})},[U.messages.length]),{startStream:Dn,stop:In,isStreaming:Lt,error:xr,setAuthToken:J,replayBufferedEvents:ce}=ex({baseUrl:f,onThreadInfo:en,onMessageEvent:Fe,onUnhandledEvent:I=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${I.type}`,I)},onSequenceGap:mt,onStreamClosed:I=>{$r.current(I)},onConnectionError:I=>{N.current(I)},onAuthError:a,onHeartbeat:I=>{q.current(I)}}),ie=b.useCallback(()=>{const I=rr.current;I.timer!==null&&(window.clearTimeout(I.timer),I.timer=null),I.reason=null},[]),Te=b.useCallback((I,A)=>{jt("connecting"),Dn(I,{onOpen:W=>{var K;ie(),rr.current.attempts=0,jt("connected"),(K=A==null?void 0:A.onOpen)==null||K.call(A,W)},onError:W=>{var K;(K=A==null?void 0:A.onError)==null||K.call(A,W)},onGap:(A==null?void 0:A.onGap)??mt,onConnectionError:W=>{var K;N.current(W),(K=A==null?void 0:A.onConnectionError)==null||K.call(A,W)},onHeartbeat:W=>{var K;q.current(W),(K=A==null?void 0:A.onHeartbeat)==null||K.call(A,W)},onClosed:W=>{var K;$r.current(W),(K=A==null?void 0:A.onClosed)==null||K.call(A,W)}})},[ie,mt,jt,Dn]),gt=b.useCallback(()=>{const I=Se.current;if(!I)return null;const A=Fr.current,W=U.lastCheckpointId??(A==null?void 0:A.lastCheckpointId)??null,K=U.lastCheckpointNs??(A==null?void 0:A.lastCheckpointNs)??null,fe={};return W&&(fe.checkpointId=W),K&&(fe.checkpointNs=K),{threadId:I,checkpointId:W,checkpointNs:K,command:{kind:"resume",value:fe}}},[U.lastCheckpointId,U.lastCheckpointNs]),Ke=b.useCallback(I=>{const A=rr.current;if(A.timer!==null)return;if(A.attempts>=nx){jt("error");return}A.attempts+=1,A.reason=I;const W=Math.min(rx*Math.pow(2,A.attempts-1),ox);jt("reconnecting"),A.timer=window.setTimeout(()=>{A.timer=null,A.reason=null;const K=gt();if(!K){jt("error");return}ce(K.threadId??void 0),Te(K)},W)},[gt,ce,jt,Te]),st=b.useCallback(I=>{var A;if(Fr.current=I,I.manualStop||I.reason==="complete"){ie(),rr.current.attempts=0,jt("idle");return}if(I.error&&(I.error.includes("token")||I.error.includes("401")||I.error.includes("unauthorized")||I.error.includes("Unauthorized")||I.error.includes("TOKEN_EXPIRED")||I.error.includes("auth_error"))){console.error("[ChatSessionProvider] Auth error detected:",I.error);try{a==null||a(I.error)}catch(K){console.error("[ChatSessionProvider] Error in onAuthError handler:",K)}return}if(I.reason==="error"||I.reason==="aborted"){if((A=I.error)!=null&&A.includes("Stream idle timeout")){console.warn("[ChatSessionProvider] Idle timeout - not scheduling resume (watchdog is generous)");return}Ke(`closed:${I.reason}`)}},[ie,Ke,jt,a]),Ht=b.useCallback(I=>{console.warn("[ChatSessionProvider] Stream connection error:",I),Ke("connection-error")},[Ke]),fn=b.useCallback(I=>{Ko.current=Date.now(),jt(A=>A==="reconnecting"?"connected":A)},[jt]);$r.current=st,N.current=Ht,q.current=fn,b.useEffect(()=>()=>{ie()},[ie]);const Gn=b.useCallback(()=>{ie(),rr.current.attempts=0,jt("idle"),In()},[ie,jt,In]);b.useEffect(()=>{Qt.current=Lt},[Lt]),b.useEffect(()=>{if(!kr())return;Xe.current!==null&&(window.clearTimeout(Xe.current),Xe.current=null);const I=S.map(W=>`${W.threadId}:${W.updatedAt??""}:${W.messageCount??""}`).join("|");if(S.length===0){try{sa(w)}catch{}sn.current="";return}if(I===sn.current)return;const A=()=>{try{const W=S.slice(0,la);ua(w,W),sn.current=I}catch{}finally{Xe.current=null}};return Xe.current=window.setTimeout(()=>{ou(A),Xe.current=null},hs),()=>{Xe.current!==null&&(window.clearTimeout(Xe.current),Xe.current=null)}},[S,He]),b.useEffect(()=>{var K;const I=c.getAuthToken();J(I);const A=fe=>{const ae=ca(h,fe);Ct.current!==ae&&(Ct.current=ae,Mt.current=!1),C(ae);const yt=da(ae);b.startTransition(()=>{k(ms(yt))}),fe&&!Mt.current&&(Mt.current=!0)};A(I);const W=(K=c.onTokenChange)==null?void 0:K.call(c,fe=>{fe!==I&&(J(fe),x(),xt.current.clear(),ft.current.clear(),A(fe))});return()=>{W==null||W()}},[c,h,J,x]);const qo=b.useCallback(async I=>{var K;const A=`Thread ${(K=crypto.randomUUID)==null?void 0:K.call(crypto)}`,W={threadId:A,title:I||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(fe=>({byId:{...fe.byId,[A]:W},order:[A,...fe.order]})),j(A);try{const fe=await c.createThread(I),ae=typeof fe=="string"?fe:fe.threadId;return k(yt=>{const St=yt.byId[A];if(!St)return yt;const Be={...yt.byId};delete Be[A],Be[ae]={...St,threadId:ae};const kt=yt.order.map(Ut=>Ut===A?ae:Ut);return{byId:Be,order:kt}}),j(ae),dt.current&&clearTimeout(dt.current),dt.current=setTimeout(()=>Ne(),300),O(null),ae}catch(fe){throw k(ae=>{if(!ae.byId[A])return ae;const yt={...ae.byId};delete yt[A];const St=ae.order.filter(Be=>Be!==A);return{byId:yt,order:St}}),j(null),O(String(fe)),fe}},[c,Ne]),Pi=b.useCallback(async I=>{try{await c.deleteThread(I);let A=null;k(W=>{if(!W.byId[I])return W;const K={...W.byId};delete K[I];const fe=W.order.filter(yt=>yt!==I),ae={byId:K,order:fe};return A=fa(ae),ae}),A&&He(A,{immediate:!0}),At(I),Se.current===I&&(Ye.current=I,j(null),Se.current=null,et.current=null,pt()),await Ne(),O(null)}catch(A){throw O(String(A)),A}},[c,pt,At,Ne,He]),ao=b.useCallback(async(I,A)=>{try{await c.updateThread(I,A),k(W=>{const K=W.byId[I];return K?{byId:{...W.byId,[I]:{...K,title:A}},order:W.order}:W}),O(null)}catch(W){throw await Ne(),O(String(W)),W}},[c,Ne]),Yn=b.useCallback(async(I,A,W,K=!1)=>{await ot(async()=>{if(Ye.current===I&&!K){Ye.current=null;return}if(Qe.current===I&&!K)return;j(Vt=>Vt===I?Vt:I),Se.current=I;const yt=iu(I,A??null,W??null),St=ft.current.get(yt),Be=!K&&!A&&!W&&St&&Date.now()-St.timestamp<tx,kt=!K&&!A&&!W;let Ut=!1;if(kt){const Vt=qe.current.get(I);if(Vt)$e(Vt),Ut=!0;else{const Pt=m(I);Pt&&(qe.current.set(I,Pt),$e(Pt),Ut=!0)}}const hn=K||!Ut||!!A||!!W,Xn=async Vt=>{Vt&&z(!0),Qe.current=I;try{const Pt=await ve({threadId:I,checkpointId:A,checkpointNs:W},{force:K}),{latest:or,checkpoints:zr,snapshots:lo}=cs(Pt.payload);b.startTransition(()=>{Oe(or,"replace",I),on(I,zr,"replace"),Wt(I,lo,"replace"),R(null),Vt&&z(!1)}),Pt.usedHistoryApi||Ce(I).then(Nn=>{zt(I,Nn)}).catch(Nn=>{console.warn("[ChatSessionProvider] Failed to refresh checkpoint summaries:",Nn)})}catch(Pt){if(de(Pt))try{const or=await Ce(I),zr=zt(I,or);if(Q(!1),ue(null),le(void 0),te(void 0),G(void 0),zr){R("History request timed out. Select a checkpoint to load manually.");return}}catch(or){console.warn("[ChatSessionProvider] Failed to fetch checkpoint summaries after timeout:",or)}throw(!Ut||K||Vt)&&(i==null||i(String(Pt))),R(String(Pt)),Pt}finally{Qe.current=null}};hn?await Xn(!0):kt&&Ut&&!Be&&Xn(!1).catch(Vt=>{console.warn("[ChatSessionProvider] Background refresh failed:",Vt)})},`loadThread-${I}`)},[$e,zt,Oe,ot,Ce,ve,de,i,on,Wt]),Wm=b.useCallback(async()=>{await ot(async()=>{const I=Se.current;I&&At(I),Ye.current=null,j(null),Se.current=null,et.current=null,pt(),te(void 0),G(void 0),le(void 0),Ve();try{localStorage.removeItem("lastThreadId")}catch(A){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",A)}},"clearCurrentThread")},[pt,At,ot,Ve]),Vm=b.useCallback(async(I,A)=>{const W=Se.current;if(!W)throw new Error("No active thread");const K=Vr(I,A??null),fe=_t(W,K);if(fe){await ot(async()=>{Oe(fe,"replace",W,{persist:!1})},`navigateToCheckpoint-${W}-${K}`);return}await Yn(W,I,A??void 0,!0)},[Oe,ot,_t,Yn]),Km=b.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");await Yn(Se.current,void 0,void 0,!0)},[Yn]),qm=b.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");if(ye||!ne)return;const I=Z;if(I){Pe(!0);try{const A=Se.current,W=await ve({threadId:A,checkpointId:I??ke??null,checkpointNs:se??L??null}),{latest:K,checkpoints:fe,snapshots:ae}=cs(W.payload),yt=Dt(A);let St=fe.length>0;if(St&&yt&&yt.size>0&&(St=fe.some(Be=>{if(!(Be!=null&&Be.checkpointId))return!1;const kt=Vr(Be.checkpointId,Be.checkpointNs??null);return!yt.has(kt)})),!St){ue(null),le(void 0),Q(!1),R(null);return}if(Oe(K,"prepend",A??void 0),A&&(on(A,fe,"prepend"),Wt(A,ae,"prepend"),!W.usedHistoryApi))try{const Be=await Ce(A);zt(A,Be)}catch(Be){console.warn("[ChatSessionProvider] Failed to refresh checkpoint summaries during prepend:",Be)}R(null)}catch(A){throw R(String(A)),A}finally{Pe(!1)}}},[Oe,ve,Dt,ne,ke,L,se,Z,Ce,zt,ye,on,Wt]),Gm=b.useCallback(I=>{if(I!=null&&I.threadId){if(I.checkpointId){const A=Vr(I.checkpointId,I.checkpointNs??null),W=un({...I,interrupt:I.interrupt??null},{cloneMessages:!0});Wt(I.threadId,{[A]:W},"prepend")}Oe(I,"replace",I.threadId)}},[Oe,Wt]),Go=b.useCallback(async(I,A)=>{var Br;const W=Se.current,K=(I==null?void 0:I.text)??"",fe=(I==null?void 0:I.attachments)??[],ae=fe.length?fe:(A==null?void 0:A.attachments)??[],yt=I==null?void 0:I.messageAdditionalKwargs,St={...(A==null?void 0:A.payloadExtras)??{},...(I==null?void 0:I.payload)??{}};if(!W&&!Object.keys(St).length&&ae.length===0&&!K.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!W&&!St.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Be,filesInfo:kt}=await Ay(c,ae),Ut=[...Be];K&&K.trim()&&Ut.push({type:"text",text:K.trim()});const hn=!!W,Xn=hn?(A==null?void 0:A.checkpointId)??U.lastCheckpointId??void 0:void 0,Vt=hn?(A==null?void 0:A.checkpointNs)??U.lastCheckpointNs??void 0:void 0,Pt={id:((Br=crypto.randomUUID)==null?void 0:Br.call(crypto))||`user-${Date.now()}`,role:"user",content:Ut,createdAt:new Date().toISOString(),...Xn!=null?{checkpointId:Xn}:{},...Vt!=null?{checkpointNs:Vt}:{}};yt&&Object.keys(yt).length&&(Pt.additionalKwargs={...Pt.additionalKwargs??{},...yt}),Ut.length>0&&Re(Pt);const or={...Pt,content:Ut},zr=ae.length>0,lo={messages:Ut.length>0?[or]:[],files_info:kt,...o&&zr&&s?{active_agent:s}:{},...St},Nn={threadId:W??null,payload:lo,checkpointId:Xn??null,checkpointNs:Vt??null,nodeFilter:(A==null?void 0:A.nodeFilter)??null,config:A==null?void 0:A.config,command:(A==null?void 0:A.command)??null};Nn.threadId||delete Nn.threadId,Nn.command||delete Nn.command,Te(Nn,{onError:vr=>{console.warn("[ChatSessionProvider] Stream error:",vr)},onOpen:({threadId:vr})=>{!Se.current&&vr&&(U.messages.length<=1&&(Ye.current=vr),j(vr))},onGap:mt})},[c,o,s,mt,U.lastCheckpointId,U.lastCheckpointNs,U.messages.length,Re,Te]),Ym=b.useCallback(async(I,A,W)=>{if(!Se.current)throw new Error("No active thread to handle interrupt");const fe=A?W??!0:!1;try{try{We({type:"interrupt_response",payload:{interruptId:I}})}catch(ae){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",ae)}await Go({payload:{}},{checkpointId:U.lastCheckpointId??void 0,checkpointNs:U.lastCheckpointNs??void 0,command:{kind:"resume",value:fe}}),$(null)}catch(ae){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${I}:`,ae),ae}},[We,U.lastCheckpointId,U.lastCheckpointNs,Go]);b.useEffect(()=>{if(l==null||l(E),E)try{localStorage.setItem("lastThreadId",E)}catch(I){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",I)}},[E,l]),b.useEffect(()=>((async()=>{try{if(Ne().catch(A=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",A),i==null||i(String(A))}),!r&&!t)try{const A=localStorage.getItem("lastThreadId");A&&(j(A),n&&await Yn(A))}catch(A){console.warn("[ChatSessionProvider] Failed to restore last thread:",A)}else t&&n&&await Yn(t)}catch(A){console.error("[ChatSessionProvider] Initialization failed:",A),i==null||i(String(A))}})(),()=>{}),[]),b.useEffect(()=>{const I=Se.current;if(!I||et.current!==I)return;U.messages.length&&U.messages[U.messages.length-1];const A=un({checkpointId:U.lastCheckpointId??null,checkpointNs:U.lastCheckpointNs??null,messages:U.messages.slice(),nextCursor:Z??null,nextCursorNs:se??null,interrupt:U.pendingInterrupt??V??null}),W=qe.current.get(I),K=W==null?void 0:W.snapshot,fe=!K||K.messages.length!==A.messages.length||K.messages.some((Be,kt)=>{var Ut;return(Be==null?void 0:Be.id)!==((Ut=A.messages[kt])==null?void 0:Ut.id)}),ae=((K==null?void 0:K.checkpointId)??null)!==A.checkpointId||((K==null?void 0:K.checkpointNs)??null)!==A.checkpointNs,yt=((K==null?void 0:K.nextCursor)??null)!==A.nextCursor||((K==null?void 0:K.nextCursorNs)??null)!==A.nextCursorNs,St=!su((K==null?void 0:K.interrupt)??null,A.interrupt??null);if(fe||ae||yt||St){const Be={threadId:I,snapshot:A};qe.current.set(I,Be),at.current&&window.clearTimeout(at.current),at.current=window.setTimeout(()=>{try{g(Be,100)}catch(kt){console.warn("[ChatSessionProvider] Failed to persist thread payload:",kt)}},hs)}},[Z,se,U.lastCheckpointId,U.lastCheckpointNs,U.messages,U.pendingInterrupt,V,g]);const mT=b.useMemo(()=>({threads:S,currentThreadId:E,setCurrentThreadId:j,isLoading:_,error:B,actions:{createThread:qo,deleteThread:Pi,renameThread:ao,refreshThreads:()=>Ne()},persistThreadsCache:lt,hydrateFromCache:F}),[S,E,_,B,qo,Pi,ao,Ne,lt,F,j]),gT=b.useMemo(()=>{const I=U.lastBranch??null,A=U.assemblingId??null,W=I||A?{branchLabel:(I==null?void 0:I.branchLabel)??null,lastBranch:I,assemblingMessageId:A}:null;return{threadId:E,messages:U.messages,interrupt:V,checkpoint:{id:U.lastCheckpointId??null,namespace:U.lastCheckpointNs??null},checkpoints:rt,metadata:W,isLoading:D,isHistoryLoading:ye,error:H,hasMore:ne,loadOlder:qm,seedFromSnapshot:Gm,clearState:pt,navigateToCheckpoint:Vm,returnToLatest:Km,loadThread:Yn,clearThread:Wm,respondToInterrupt:Ym}},[Wm,pt,E,V,ne,ye,D,qm,Yn,U.assemblingId,U.lastBranch,U.lastCheckpointId,U.lastCheckpointNs,U.messages,Vm,Ym,Km,Gm,H,rt]),yT=b.useMemo(()=>({isStreaming:Lt,error:xr,connectionState:qn,submit:Go,send:Go,stop:Gn,setAuthToken:J}),[qn,Lt,xr,Gn,Go,J]);return u.jsx(Sx.Provider,{value:!0,children:u.jsx(du.Provider,{value:yT,children:u.jsx(cu.Provider,{value:mT,children:u.jsx(uu.Provider,{value:gT,children:e})})})})}function gs(){const e=b.useContext(cu);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function ys(){const e=b.useContext(uu);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function fu(){const e=b.useContext(du);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function xs({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onAuthError:l,onThreadChange:c}){return u.jsx(Iy,{apiConfig:t,children:u.jsx(Cx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onAuthError:l,onThreadChange:c,children:e})})}function oe(...e){return Qm.twMerge(Zm.clsx(e))}const kx=Yo.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),ct=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?wr.Slot:"button";return u.jsx(i,{className:oe(kx({variant:t,size:n,className:e})),ref:s,...o})});ct.displayName="Button";const hu=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:oe("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));hu.displayName="Textarea";function pu({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const m=i!==void 0,[g,y]=b.useState(e),x=(m?i:g)??"",[w,C]=b.useTransition(),T=b.useRef(null),k=b.useRef(0),S=b.useRef(null);b.useEffect(()=>{m||(y(e??""),S.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const H=T.current;H&&(H.style.height="auto",H.style.height=`${H.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,x]);const j=b.useCallback((H,{fromUser:R})=>{m||y(H),R&&(a==null||a(H))},[m,a]),_=b.useCallback(async H=>{H&&H.preventDefault();const R=(x??"").trim();if(!R&&!p)return;const V=++k.current;S.current={id:V,shouldClear:!0},C(()=>{var $,F,ne;try{const Q=l(R);Q&&typeof Q.then=="function"?Q.then(()=>{var ye,Pe;((ye=S.current)==null?void 0:ye.id)===V&&S.current.shouldClear&&(m||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((Pe=S.current)==null?void 0:Pe.id)===V&&(S.current=null)}).catch(()=>{var ye;((ye=S.current)==null?void 0:ye.id)===V&&(S.current=null)}):((($=S.current)==null?void 0:$.id)===V&&S.current.shouldClear&&(m||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((F=S.current)==null?void 0:F.id)===V&&(S.current=null))}catch{((ne=S.current)==null?void 0:ne.id)===V&&(S.current=null)}})},[x,l,p,m,a]),P=b.useCallback(H=>{const R=H.target.value;j(R,{fromUser:!0}),S.current&&(S.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[j]),D=b.useCallback(H=>{H.key==="Enter"&&!H.shiftKey?(H.preventDefault(),_()):H.key==="Escape"&&t&&(H.preventDefault(),c==null||c())},[_,t,c]),O=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return u.jsx("form",{onSubmit:H=>void _(H),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(hu,{ref:T,value:x,onChange:P,onKeyDown:D,placeholder:t?"Edit your message...":n,className:O,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(ct,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(he.Square,{size:16})}):u.jsx(ct,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!p||w,children:u.jsx(he.Send,{size:16})})})]})})}const Tx=b.memo(pu);function ge(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function mu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ha(...e){return t=>{let n=!1;const r=e.map(o=>{const s=mu(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():mu(e[o],null)}}}}function Je(...e){return v.useCallback(ha(...e),e)}function Ex(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Zn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:h,children:p,...m}=f,g=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(g.Provider,{value:y,children:p})};c.displayName=s+"Provider";function d(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,m=v.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Ix(o,...t)]}function Ix(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var qt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},Nx=v[" useInsertionEffect ".trim().toString()]||qt;function Kr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Ax({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const h=_x(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function Ax({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Nx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function _x(e){return typeof e=="function"}var jx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],De=jx.reduce((e,t)=>{const n=wr.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function gu(e,t){e&&Xo.flushSync(()=>e.dispatchEvent(t))}function pa(e){const t=e+"CollectionProvider",[n,r]=Zn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,w=b.useRef(null),C=b.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:C,collectionRef:w,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=wr.createSlot(a),c=b.forwardRef((g,y)=>{const{scope:x,children:w}=g,C=s(a,x),T=Je(y,C.collectionRef);return u.jsx(l,{ref:T,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=wr.createSlot(d),p=b.forwardRef((g,y)=>{const{scope:x,children:w,...C}=g,T=b.useRef(null),k=Je(y,T),S=s(d,x);return b.useEffect(()=>(S.itemMap.set(T,{ref:T,...C}),()=>void S.itemMap.delete(T))),u.jsx(h,{[f]:"",ref:k,children:w})});p.displayName=d;function m(g){const y=s(e+"CollectionConsumer",g);return b.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const C=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((S,E)=>C.indexOf(S.ref.current)-C.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},m,r]}var Px=v.createContext(void 0);function vs(e){const t=v.useContext(Px);return e||t||"ltr"}function Gt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Rx(e,t=globalThis==null?void 0:globalThis.document){const n=Gt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var Ox="DismissableLayer",ma="dismissableLayer.update",Mx="dismissableLayer.pointerDownOutside",Dx="dismissableLayer.focusOutside",yu,xu=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),ws=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(xu),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),m=Je(t,E=>f(E)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),w=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,T=w>=x,k=$x(E=>{const j=E.target,_=[...c.branches].some(P=>P.contains(j));!T||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),S=zx(E=>{const j=E.target;[...c.branches].some(P=>P.contains(j))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return Rx(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(yu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),vu(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=yu)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),vu())},[d,c]),v.useEffect(()=>{const E=()=>p({});return document.addEventListener(ma,E),()=>document.removeEventListener(ma,E)},[]),u.jsx(De.div,{...l,ref:m,style:{pointerEvents:C?T?"auto":"none":void 0,...e.style},onFocusCapture:ge(e.onFocusCapture,S.onFocusCapture),onBlurCapture:ge(e.onBlurCapture,S.onBlurCapture),onPointerDownCapture:ge(e.onPointerDownCapture,k.onPointerDownCapture)})});ws.displayName=Ox;var Lx="DismissableLayerBranch",Fx=v.forwardRef((e,t)=>{const n=v.useContext(xu),r=v.useRef(null),o=Je(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(De.div,{...e,ref:o})});Fx.displayName=Lx;function $x(e,t=globalThis==null?void 0:globalThis.document){const n=Gt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){wu(Mx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function zx(e,t=globalThis==null?void 0:globalThis.document){const n=Gt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&wu(Dx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function vu(){const e=new CustomEvent(ma);document.dispatchEvent(e)}function wu(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?gu(o,s):o.dispatchEvent(s)}var ga=0;function ya(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??bu()),document.body.insertAdjacentElement("beforeend",e[1]??bu()),ga++,()=>{ga===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ga--}},[])}function bu(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var xa="focusScope.autoFocusOnMount",va="focusScope.autoFocusOnUnmount",Su={bubbles:!1,cancelable:!0},Bx="FocusScope",bs=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Gt(o),d=Gt(s),f=v.useRef(null),h=Je(t,g=>l(g)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let g=function(C){if(p.paused||!a)return;const T=C.target;a.contains(T)?f.current=T:ir(f.current,{select:!0})},y=function(C){if(p.paused||!a)return;const T=C.relatedTarget;T!==null&&(a.contains(T)||ir(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const k of C)k.removedNodes.length>0&&ir(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const w=new MutationObserver(x);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),w.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){Tu.add(p);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(xa,Su);a.addEventListener(xa,c),a.dispatchEvent(x),x.defaultPrevented||(Hx(qx(Cu(a)),{select:!0}),document.activeElement===g&&ir(a))}return()=>{a.removeEventListener(xa,c),setTimeout(()=>{const x=new CustomEvent(va,Su);a.addEventListener(va,d),a.dispatchEvent(x),x.defaultPrevented||ir(g??document.body,{select:!0}),a.removeEventListener(va,d),Tu.remove(p)},0)}}},[a,c,d,p]);const m=v.useCallback(g=>{if(!n&&!r||p.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const w=g.currentTarget,[C,T]=Ux(w);C&&T?!g.shiftKey&&x===T?(g.preventDefault(),n&&ir(C,{select:!0})):g.shiftKey&&x===C&&(g.preventDefault(),n&&ir(T,{select:!0})):x===w&&g.preventDefault()}},[n,r,p.paused]);return u.jsx(De.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});bs.displayName=Bx;function Hx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(ir(r,{select:t}),document.activeElement!==n)return}function Ux(e){const t=Cu(e),n=ku(t,e),r=ku(t.reverse(),e);return[n,r]}function Cu(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function ku(e,t){for(const n of e)if(!Wx(n,{upTo:t}))return n}function Wx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Vx(e){return e instanceof HTMLInputElement&&"select"in e}function ir(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Vx(e)&&t&&e.select()}}var Tu=Kx();function Kx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Eu(e,t),e.unshift(t)},remove(t){var n;e=Eu(e,t),(n=e[0])==null||n.resume()}}}function Eu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function qx(e){return e.filter(t=>t.tagName!=="A")}var Gx=v[" useId ".trim().toString()]||(()=>{}),Yx=0;function Qn(e){const[t,n]=v.useState(Gx());return qt(()=>{n(r=>r??String(Yx++))},[e]),t?`radix-${t}`:""}const Xx=["top","right","bottom","left"],ar=Math.min,pn=Math.max,Ss=Math.round,Cs=Math.floor,Fn=e=>({x:e,y:e}),Jx={left:"right",right:"left",bottom:"top",top:"bottom"},Zx={start:"end",end:"start"};function wa(e,t,n){return pn(e,ar(t,n))}function er(e,t){return typeof e=="function"?e(t):e}function tr(e){return e.split("-")[0]}function qr(e){return e.split("-")[1]}function ba(e){return e==="x"?"y":"x"}function Sa(e){return e==="y"?"height":"width"}const Qx=new Set(["top","bottom"]);function $n(e){return Qx.has(tr(e))?"y":"x"}function Ca(e){return ba($n(e))}function ev(e,t,n){n===void 0&&(n=!1);const r=qr(e),o=Ca(e),s=Sa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=ks(i)),[i,ks(i)]}function tv(e){const t=ks(e);return[ka(e),t,ka(t)]}function ka(e){return e.replace(/start|end/g,t=>Zx[t])}const Iu=["left","right"],Nu=["right","left"],nv=["top","bottom"],rv=["bottom","top"];function ov(e,t,n){switch(e){case"top":case"bottom":return n?t?Nu:Iu:t?Iu:Nu;case"left":case"right":return t?nv:rv;default:return[]}}function sv(e,t,n,r){const o=qr(e);let s=ov(tr(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ka)))),s}function ks(e){return e.replace(/left|right|bottom|top/g,t=>Jx[t])}function iv(e){return{top:0,right:0,bottom:0,left:0,...e}}function Au(e){return typeof e!="number"?iv(e):{top:e,right:e,bottom:e,left:e}}function Ts(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function _u(e,t,n){let{reference:r,floating:o}=e;const s=$n(t),i=Ca(t),a=Sa(i),l=tr(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(qr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const av=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=_u(c,r,l),h=r,p={},m=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:w,y:C,data:T,reset:k}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=C??f,p={...p,[y]:{...p[y],...T}},k&&m<=50&&(m++,typeof k=="object"&&(k.placement&&(h=k.placement),k.rects&&(c=k.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):k.rects),{x:d,y:f}=_u(c,h,l)),g=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function xo(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=er(t,e),m=Au(p),y=a[h?f==="floating"?"reference":"floating":f],x=Ts(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),T=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},k=Ts(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:C,strategy:l}):w);return{top:(x.top-k.top+m.top)/T.y,bottom:(k.bottom-x.bottom+m.bottom)/T.y,left:(x.left-k.left+m.left)/T.x,right:(k.right-x.right+m.right)/T.x}}const lv=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=er(e,t)||{};if(c==null)return{};const f=Au(d),h={x:n,y:r},p=Ca(o),m=Sa(p),g=await i.getDimensions(c),y=p==="y",x=y?"top":"left",w=y?"bottom":"right",C=y?"clientHeight":"clientWidth",T=s.reference[m]+s.reference[p]-h[p]-s.floating[m],k=h[p]-s.reference[p],S=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=S?S[C]:0;(!E||!await(i.isElement==null?void 0:i.isElement(S)))&&(E=a.floating[C]||s.floating[m]);const j=T/2-k/2,_=E/2-g[m]/2-1,P=ar(f[x],_),D=ar(f[w],_),z=P,B=E-g[m]-D,O=E/2-g[m]/2+j,H=wa(z,O,B),R=!l.arrow&&qr(o)!=null&&O!==H&&s.reference[m]/2-(O<z?P:D)-g[m]/2<0,V=R?O<z?O-z:O-B:0;return{[p]:h[p]+V,data:{[p]:H,centerOffset:O-H-V,...R&&{alignmentOffset:V}},reset:R}}}),cv=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=er(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=tr(o),w=$n(a),C=tr(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(C||!g?[ks(a)]:tv(a)),S=m!=="none";!h&&S&&k.push(...sv(a,g,m,T));const E=[a,...k],j=await xo(t,y),_=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(j[x]),f){const O=ev(o,i,T);_.push(j[O[0]],j[O[1]])}if(P=[...P,{placement:o,overflows:_}],!_.every(O=>O<=0)){var D,z;const O=(((D=s.flip)==null?void 0:D.index)||0)+1,H=E[O];if(H&&(!(f==="alignment"?w!==$n(H):!1)||P.every($=>$n($.placement)===w?$.overflows[0]>0:!0)))return{data:{index:O,overflows:P},reset:{placement:H}};let R=(z=P.filter(V=>V.overflows[0]<=0).sort((V,$)=>V.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!R)switch(p){case"bestFit":{var B;const V=(B=P.filter($=>{if(S){const F=$n($.placement);return F===w||F==="y"}return!0}).map($=>[$.placement,$.overflows.filter(F=>F>0).reduce((F,ne)=>F+ne,0)]).sort(($,F)=>$[1]-F[1])[0])==null?void 0:B[0];V&&(R=V);break}case"initialPlacement":R=a;break}if(o!==R)return{reset:{placement:R}}}return{}}}};function ju(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pu(e){return Xx.some(t=>e[t]>=0)}const uv=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=er(e,t);switch(r){case"referenceHidden":{const s=await xo(t,{...o,elementContext:"reference"}),i=ju(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pu(i)}}}case"escaped":{const s=await xo(t,{...o,altBoundary:!0}),i=ju(s,n.floating);return{data:{escapedOffsets:i,escaped:Pu(i)}}}default:return{}}}}},Ru=new Set(["left","top"]);async function dv(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=tr(n),a=qr(n),l=$n(n)==="y",c=Ru.has(i)?-1:1,d=s&&l?-1:1,f=er(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const fv=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await dv(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},hv=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x,y:w}=y;return{x,y:w}}},...l}=er(e,t),c={x:n,y:r},d=await xo(t,l),f=$n(tr(o)),h=ba(f);let p=c[h],m=c[f];if(s){const y=h==="y"?"top":"left",x=h==="y"?"bottom":"right",w=p+d[y],C=p-d[x];p=wa(w,p,C)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",w=m+d[y],C=m-d[x];m=wa(w,m,C)}const g=a.fn({...t,[h]:p,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},pv=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=er(e,t),d={x:n,y:r},f=$n(o),h=ba(f);let p=d[h],m=d[f];const g=er(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=h==="y"?"height":"width",T=s.reference[h]-s.floating[C]+y.mainAxis,k=s.reference[h]+s.reference[C]-y.mainAxis;p<T?p=T:p>k&&(p=k)}if(c){var x,w;const C=h==="y"?"width":"height",T=Ru.has(tr(o)),k=s.reference[f]-s.floating[C]+(T&&((x=i.offset)==null?void 0:x[f])||0)+(T?0:y.crossAxis),S=s.reference[f]+s.reference[C]+(T?0:((w=i.offset)==null?void 0:w[f])||0)-(T?y.crossAxis:0);m<k?m=k:m>S&&(m=S)}return{[h]:p,[f]:m}}}},mv=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=er(e,t),d=await xo(t,c),f=tr(o),h=qr(o),p=$n(o)==="y",{width:m,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=h==="end"?"top":"bottom");const w=g-d.top-d.bottom,C=m-d.left-d.right,T=ar(g-d[y],w),k=ar(m-d[x],C),S=!t.middlewareData.shift;let E=T,j=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),S&&!h){const P=pn(d.left,0),D=pn(d.right,0),z=pn(d.top,0),B=pn(d.bottom,0);p?j=m-2*(P!==0||D!==0?P+D:pn(d.left,d.right)):E=g-2*(z!==0||B!==0?z+B:pn(d.top,d.bottom))}await l({...t,availableWidth:j,availableHeight:E});const _=await i.getDimensions(a.floating);return m!==_.width||g!==_.height?{reset:{rects:!0}}:{}}}};function Es(){return typeof window<"u"}function Gr(e){return Ou(e)?(e.nodeName||"").toLowerCase():"#document"}function mn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function zn(e){var t;return(t=(Ou(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Ou(e){return Es()?e instanceof Node||e instanceof mn(e).Node:!1}function _n(e){return Es()?e instanceof Element||e instanceof mn(e).Element:!1}function Bn(e){return Es()?e instanceof HTMLElement||e instanceof mn(e).HTMLElement:!1}function Mu(e){return!Es()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof mn(e).ShadowRoot}const gv=new Set(["inline","contents"]);function vo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=jn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!gv.has(o)}const yv=new Set(["table","td","th"]);function xv(e){return yv.has(Gr(e))}const vv=[":popover-open",":modal"];function Is(e){return vv.some(t=>{try{return e.matches(t)}catch{return!1}})}const wv=["transform","translate","scale","rotate","perspective"],bv=["transform","translate","scale","rotate","perspective","filter"],Sv=["paint","layout","strict","content"];function Ta(e){const t=Ea(),n=_n(e)?jn(e):e;return wv.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||bv.some(r=>(n.willChange||"").includes(r))||Sv.some(r=>(n.contain||"").includes(r))}function Cv(e){let t=lr(e);for(;Bn(t)&&!Yr(t);){if(Ta(t))return t;if(Is(t))return null;t=lr(t)}return null}function Ea(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const kv=new Set(["html","body","#document"]);function Yr(e){return kv.has(Gr(e))}function jn(e){return mn(e).getComputedStyle(e)}function Ns(e){return _n(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function lr(e){if(Gr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Mu(e)&&e.host||zn(e);return Mu(t)?t.host:t}function Du(e){const t=lr(e);return Yr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Bn(t)&&vo(t)?t:Du(t)}function wo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Du(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=mn(o);if(s){const a=Ia(i);return t.concat(i,i.visualViewport||[],vo(o)?o:[],a&&n?wo(a):[])}return t.concat(o,wo(o,[],n))}function Ia(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Lu(e){const t=jn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Bn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Ss(n)!==s||Ss(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Na(e){return _n(e)?e:e.contextElement}function Xr(e){const t=Na(e);if(!Bn(t))return Fn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Lu(t);let i=(s?Ss(n.width):n.width)/r,a=(s?Ss(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Tv=Fn(0);function Fu(e){const t=mn(e);return!Ea()||!t.visualViewport?Tv:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ev(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==mn(e)?!1:t}function Tr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Na(e);let i=Fn(1);t&&(r?_n(r)&&(i=Xr(r)):i=Xr(e));const a=Ev(s,n,r)?Fu(s):Fn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=mn(s),p=r&&_n(r)?mn(r):r;let m=h,g=Ia(m);for(;g&&r&&p!==m;){const y=Xr(g),x=g.getBoundingClientRect(),w=jn(g),C=x.left+(g.clientLeft+parseFloat(w.paddingLeft))*y.x,T=x.top+(g.clientTop+parseFloat(w.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=C,c+=T,m=mn(g),g=Ia(m)}}return Ts({width:d,height:f,x:l,y:c})}function As(e,t){const n=Ns(e).scrollLeft;return t?t.left+n:Tr(zn(e)).left+n}function $u(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-As(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Iv(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=zn(r),a=t?Is(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=Fn(1);const d=Fn(0),f=Bn(r);if((f||!f&&!s)&&((Gr(r)!=="body"||vo(i))&&(l=Ns(r)),Bn(r))){const p=Tr(r);c=Xr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?$u(i,l):Fn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function Nv(e){return Array.from(e.getClientRects())}function Av(e){const t=zn(e),n=Ns(e),r=e.ownerDocument.body,o=pn(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=pn(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+As(e);const a=-n.scrollTop;return jn(r).direction==="rtl"&&(i+=pn(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const zu=25;function _v(e,t){const n=mn(e),r=zn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Ea();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=As(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=zu&&(s-=m)}else c<=zu&&(s+=c);return{width:s,height:i,x:a,y:l}}const jv=new Set(["absolute","fixed"]);function Pv(e,t){const n=Tr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Bn(e)?Xr(e):Fn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Bu(e,t,n){let r;if(t==="viewport")r=_v(e,n);else if(t==="document")r=Av(zn(e));else if(_n(t))r=Pv(t,n);else{const o=Fu(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ts(r)}function Hu(e,t){const n=lr(e);return n===t||!_n(n)||Yr(n)?!1:jn(n).position==="fixed"||Hu(n,t)}function Rv(e,t){const n=t.get(e);if(n)return n;let r=wo(e,[],!1).filter(a=>_n(a)&&Gr(a)!=="body"),o=null;const s=jn(e).position==="fixed";let i=s?lr(e):e;for(;_n(i)&&!Yr(i);){const a=jn(i),l=Ta(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&jv.has(o.position)||vo(i)&&!l&&Hu(e,i))?r=r.filter(d=>d!==i):o=a,i=lr(i)}return t.set(e,r),r}function Ov(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Is(t)?[]:Rv(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Bu(t,d,o);return c.top=pn(f.top,c.top),c.right=ar(f.right,c.right),c.bottom=ar(f.bottom,c.bottom),c.left=pn(f.left,c.left),c},Bu(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Mv(e){const{width:t,height:n}=Lu(e);return{width:t,height:n}}function Dv(e,t,n){const r=Bn(t),o=zn(t),s=n==="fixed",i=Tr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=Fn(0);function c(){l.x=As(o)}if(r||!r&&!s)if((Gr(t)!=="body"||vo(o))&&(a=Ns(t)),r){const p=Tr(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?$u(o,a):Fn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function Aa(e){return jn(e).position==="static"}function Uu(e,t){if(!Bn(e)||jn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return zn(e)===n&&(n=n.ownerDocument.body),n}function Wu(e,t){const n=mn(e);if(Is(e))return n;if(!Bn(e)){let o=lr(e);for(;o&&!Yr(o);){if(_n(o)&&!Aa(o))return o;o=lr(o)}return n}let r=Uu(e,t);for(;r&&xv(r)&&Aa(r);)r=Uu(r,t);return r&&Yr(r)&&Aa(r)&&!Ta(r)?n:r||Cv(e)||n}const Lv=async function(e){const t=this.getOffsetParent||Wu,n=this.getDimensions,r=await n(e.floating);return{reference:Dv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Fv(e){return jn(e).direction==="rtl"}const $v={convertOffsetParentRelativeRectToViewportRelativeRect:Iv,getDocumentElement:zn,getClippingRect:Ov,getOffsetParent:Wu,getElementRects:Lv,getClientRects:Nv,getDimensions:Mv,getScale:Xr,isElement:_n,isRTL:Fv};function Vu(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function zv(e,t){let n=null,r;const o=zn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=Cs(f),g=Cs(o.clientWidth-(d+h)),y=Cs(o.clientHeight-(f+p)),x=Cs(d),C={rootMargin:-m+"px "+-g+"px "+-y+"px "+-x+"px",threshold:pn(0,ar(1,l))||1};let T=!0;function k(S){const E=S[0].intersectionRatio;if(E!==l){if(!T)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Vu(c,e.getBoundingClientRect())&&i(),T=!1}try{n=new IntersectionObserver(k,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,C)}n.observe(e)}return i(!0),s}function Bv(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Na(e),d=o||s?[...c?wo(c):[],...wo(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?zv(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[w]=x;w&&w.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var C;(C=p)==null||C.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let m,g=l?Tr(e):null;l&&y();function y(){const x=Tr(e);g&&!Vu(g,x)&&n(),g=x,m=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const Hv=fv,Uv=hv,Wv=cv,Vv=mv,Kv=uv,Ku=lv,qv=pv,Gv=(e,t,n)=>{const r=new Map,o={platform:$v,...n},s={...o.platform,_c:r};return av(e,t,{...o,platform:s})};var Yv=typeof document<"u",Xv=function(){},_s=Yv?b.useLayoutEffect:Xv;function js(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!js(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!js(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function qu(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Gu(e,t){const n=qu(e);return Math.round(t*n)/n}function _a(e){const t=v.useRef(e);return _s(()=>{t.current=e}),t}function Jv(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=v.useState(r);js(h,r)||p(r);const[m,g]=v.useState(null),[y,x]=v.useState(null),w=v.useCallback($=>{$!==S.current&&(S.current=$,g($))},[]),C=v.useCallback($=>{$!==E.current&&(E.current=$,x($))},[]),T=s||m,k=i||y,S=v.useRef(null),E=v.useRef(null),j=v.useRef(d),_=l!=null,P=_a(l),D=_a(o),z=_a(c),B=v.useCallback(()=>{if(!S.current||!E.current)return;const $={placement:t,strategy:n,middleware:h};D.current&&($.platform=D.current),Gv(S.current,E.current,$).then(F=>{const ne={...F,isPositioned:z.current!==!1};O.current&&!js(j.current,ne)&&(j.current=ne,Xo.flushSync(()=>{f(ne)}))})},[h,t,n,D,z]);_s(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[c]);const O=v.useRef(!1);_s(()=>(O.current=!0,()=>{O.current=!1}),[]),_s(()=>{if(T&&(S.current=T),k&&(E.current=k),T&&k){if(P.current)return P.current(T,k,B);B()}},[T,k,B,P,_]);const H=v.useMemo(()=>({reference:S,floating:E,setReference:w,setFloating:C}),[w,C]),R=v.useMemo(()=>({reference:T,floating:k}),[T,k]),V=v.useMemo(()=>{const $={position:n,left:0,top:0};if(!R.floating)return $;const F=Gu(R.floating,d.x),ne=Gu(R.floating,d.y);return a?{...$,transform:"translate("+F+"px, "+ne+"px)",...qu(R.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:ne}},[n,a,R.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:B,refs:H,elements:R,floatingStyles:V}),[d,B,H,R,V])}const Zv=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?Ku({element:r.current,padding:o}).fn(n):{}:r?Ku({element:r,padding:o}).fn(n):{}}}},Qv=(e,t)=>({...Hv(e),options:[e,t]}),ew=(e,t)=>({...Uv(e),options:[e,t]}),tw=(e,t)=>({...qv(e),options:[e,t]}),nw=(e,t)=>({...Wv(e),options:[e,t]}),rw=(e,t)=>({...Vv(e),options:[e,t]}),ow=(e,t)=>({...Kv(e),options:[e,t]}),sw=(e,t)=>({...Zv(e),options:[e,t]});var iw="Arrow",Yu=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(De.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Yu.displayName=iw;var aw=Yu;function Xu(e){const[t,n]=v.useState(void 0);return qt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var ja="Popper",[Ju,Ps]=Zn(ja),[lw,Zu]=Ju(ja),Qu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(lw,{scope:t,anchor:r,onAnchorChange:o,children:n})};Qu.displayName=ja;var ed="PopperAnchor",td=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Zu(ed,n),i=v.useRef(null),a=Je(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(De.div,{...o,ref:a})});td.displayName=ed;var Pa="PopperContent",[cw,uw]=Ju(Pa),nd=v.forwardRef((e,t)=>{var te,L,G,se,le,U;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...g}=e,y=Zu(Pa,n),[x,w]=v.useState(null),C=Je(t,We=>w(We)),[T,k]=v.useState(null),S=Xu(T),E=(S==null?void 0:S.width)??0,j=(S==null?void 0:S.height)??0,_=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},D=Array.isArray(c)?c:[c],z=D.length>0,B={padding:P,boundary:D.filter(fw),altBoundary:z},{refs:O,floatingStyles:H,placement:R,isPositioned:V,middlewareData:$}=Jv({strategy:"fixed",placement:_,whileElementsMounted:(...We)=>Bv(...We,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[Qv({mainAxis:o+j,alignmentAxis:i}),l&&ew({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?tw():void 0,...B}),l&&nw({...B}),rw({...B,apply:({elements:We,rects:re,availableWidth:xe,availableHeight:Re})=>{const{width:Fe,height:tt}=re.reference,Se=We.floating.style;Se.setProperty("--radix-popper-available-width",`${xe}px`),Se.setProperty("--radix-popper-available-height",`${Re}px`),Se.setProperty("--radix-popper-anchor-width",`${Fe}px`),Se.setProperty("--radix-popper-anchor-height",`${tt}px`)}}),T&&sw({element:T,padding:a}),hw({arrowWidth:E,arrowHeight:j}),h&&ow({strategy:"referenceHidden",...B})]}),[F,ne]=sd(R),Q=Gt(m);qt(()=>{V&&(Q==null||Q())},[V,Q]);const ye=(te=$.arrow)==null?void 0:te.x,Pe=(L=$.arrow)==null?void 0:L.y,Z=((G=$.arrow)==null?void 0:G.centerOffset)!==0,[ue,ke]=v.useState();return qt(()=>{x&&ke(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...H,transform:V?H.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ue,"--radix-popper-transform-origin":[(se=$.transformOrigin)==null?void 0:se.x,(le=$.transformOrigin)==null?void 0:le.y].join(" "),...((U=$.hide)==null?void 0:U.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(cw,{scope:n,placedSide:F,onArrowChange:k,arrowX:ye,arrowY:Pe,shouldHideArrow:Z,children:u.jsx(De.div,{"data-side":F,"data-align":ne,...g,ref:C,style:{...g.style,animation:V?void 0:"none"}})})})});nd.displayName=Pa;var rd="PopperArrow",dw={top:"bottom",right:"left",bottom:"top",left:"right"},od=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=uw(rd,r),i=dw[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(aw,{...o,ref:n,style:{...o.style,display:"block"}})})});od.displayName=rd;function fw(e){return e!==null}var hw=e=>({name:"transformOrigin",options:e,fn(t){var y,x,w;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=sd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",g="";return c==="bottom"?(m=i?f:`${h}px`,g=`${-l}px`):c==="top"?(m=i?f:`${h}px`,g=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,g=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,g=i?f:`${p}px`),{data:{x:m,y:g}}}});function sd(e){const[t,n="center"]=e.split("-");return[t,n]}var id=Qu,ad=td,ld=nd,cd=od,pw="Portal",Rs=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);qt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ri.createPortal(u.jsx(De.div,{...r,ref:t}),i):null});Rs.displayName=pw;function mw(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var bn=e=>{const{present:t,children:n}=e,r=gw(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Je(r.ref,yw(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};bn.displayName="Presence";function gw(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=mw(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Os(r.current);s.current=a==="mounted"?c:"none"},[a]),qt(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=Os(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),qt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const g=Os(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},h=p=>{p.target===t&&(s.current=Os(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Os(e){return(e==null?void 0:e.animationName)||"none"}function yw(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Ra="rovingFocusGroup.onEntryFocus",xw={bubbles:!1,cancelable:!0},bo="RovingFocusGroup",[Oa,ud,vw]=pa(bo),[ww,dd]=Zn(bo,[vw]),[bw,Sw]=ww(bo),fd=v.forwardRef((e,t)=>u.jsx(Oa.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Oa.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Cw,{...e,ref:t})})}));fd.displayName=bo;var Cw=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,h=v.useRef(null),p=Je(t,h),m=vs(s),[g,y]=Kr({prop:i,defaultProp:a??null,onChange:l,caller:bo}),[x,w]=v.useState(!1),C=Gt(c),T=ud(n),k=v.useRef(!1),[S,E]=v.useState(0);return v.useEffect(()=>{const j=h.current;if(j)return j.addEventListener(Ra,C),()=>j.removeEventListener(Ra,C)},[C]),u.jsx(bw,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:v.useCallback(j=>y(j),[y]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>E(j=>j-1),[]),children:u.jsx(De.div,{tabIndex:x||S===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ge(e.onMouseDown,()=>{k.current=!0}),onFocus:ge(e.onFocus,j=>{const _=!k.current;if(j.target===j.currentTarget&&_&&!x){const P=new CustomEvent(Ra,xw);if(j.currentTarget.dispatchEvent(P),!P.defaultPrevented){const D=T().filter(R=>R.focusable),z=D.find(R=>R.active),B=D.find(R=>R.id===g),H=[z,B,...D].filter(Boolean).map(R=>R.ref.current);md(H,d)}}k.current=!1}),onBlur:ge(e.onBlur,()=>w(!1))})})}),hd="RovingFocusGroupItem",pd=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Qn(),c=s||l,d=Sw(hd,n),f=d.currentTabStopId===c,h=ud(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:g}=d;return v.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),u.jsx(Oa.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(De.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ge(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:ge(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ge(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=Ew(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let C=h().filter(T=>T.focusable).map(T=>T.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const T=C.indexOf(y.currentTarget);C=d.loop?Iw(C,T+1):C.slice(T+1)}setTimeout(()=>md(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});pd.displayName=hd;var kw={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Tw(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Ew(e,t,n){const r=Tw(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return kw[r]}function md(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Iw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Nw=fd,Aw=pd,_w=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Jr=new WeakMap,Ms=new WeakMap,Ds={},Ma=0,gd=function(e){return e&&(e.host||gd(e.parentNode))},jw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=gd(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},Pw=function(e,t,n,r){var o=jw(t,Array.isArray(e)?e:[e]);Ds[n]||(Ds[n]=new WeakMap);var s=Ds[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),m=p!==null&&p!=="false",g=(Jr.get(h)||0)+1,y=(s.get(h)||0)+1;Jr.set(h,g),s.set(h,y),i.push(h),g===1&&m&&Ms.set(h,!0),y===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),Ma++,function(){i.forEach(function(f){var h=Jr.get(f)-1,p=s.get(f)-1;Jr.set(f,h),s.set(f,p),h||(Ms.has(f)||f.removeAttribute(r),Ms.delete(f)),p||f.removeAttribute(n)}),Ma--,Ma||(Jr=new WeakMap,Jr=new WeakMap,Ms=new WeakMap,Ds={})}},Da=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=_w(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Pw(r,o,n,"aria-hidden")):function(){return null}},Hn=function(){return Hn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Hn.apply(this,arguments)};function yd(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function Rw(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var Ls="right-scroll-bar-position",Fs="width-before-scroll-bar",Ow="with-scroll-bars-hidden",Mw="--removed-body-scroll-bar-size";function La(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Dw(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var Lw=typeof window<"u"?v.useLayoutEffect:v.useEffect,xd=new WeakMap;function Fw(e,t){var n=Dw(null,function(r){return e.forEach(function(o){return La(o,r)})});return Lw(function(){var r=xd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||La(a,null)}),s.forEach(function(a){o.has(a)||La(a,i)})}xd.set(n,e)},[e]),n}function $w(e){return e}function zw(e,t){t===void 0&&(t=$w);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function Bw(e){e===void 0&&(e={});var t=zw(null);return t.options=Hn({async:!0,ssr:!1},e),t}var vd=function(e){var t=e.sideCar,n=yd(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,Hn({},n))};vd.isSideCarExport=!0;function Hw(e,t){return e.useMedium(t),vd}var wd=Bw(),Fa=function(){},$s=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Fa,onWheelCapture:Fa,onTouchMoveCapture:Fa}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,w=x===void 0?"div":x,C=e.gapMode,T=yd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,S=Fw([n,t]),E=Hn(Hn({},T),o);return v.createElement(v.Fragment,null,d&&v.createElement(k,{sideCar:wd,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:C}),i?v.cloneElement(v.Children.only(a),Hn(Hn({},E),{ref:S})):v.createElement(w,Hn({},E,{className:l,ref:S}),a))});$s.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},$s.classNames={fullWidth:Fs,zeroRight:Ls};var Uw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ww(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Uw();return t&&e.setAttribute("nonce",t),e}function Vw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Kw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var qw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Ww())&&(Vw(t,n),Kw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Gw=function(){var e=qw();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},bd=function(){var e=Gw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Yw={left:0,top:0,right:0,gap:0},$a=function(e){return parseInt(e||"",10)||0},Xw=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[$a(n),$a(r),$a(o)]},Jw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Yw;var t=Xw(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Zw=bd(),Zr="data-scroll-locked",Qw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
39
|
-
.`.concat(
|
|
37
|
+
`))>=0;){const it=St.slice(0,ve);St=St.slice(ve+2);const yt=ox(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=rx(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=ls(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 rx(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function ox(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 ou=200;function sx({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>=ou?[...D.slice(D.length-ou+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),Xy(_)){_.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}=ru({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 su=50,ix=750,ra="chat-history@1",ax=5,lx=1e3,cx=15e3,fs=300;function iu(e,t=fs){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 oa(e){if(!Tr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function sa(e,t){if(!Tr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function ia(e){if(Tr())try{window.localStorage.removeItem(e)}catch{}}function aa(e){return e==null?e:{...e}}function ux(e){return e==null?e:{...e}}function dx(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function fx(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=aa(e==null?void 0:e.metadata),s=aa(e==null?void 0:e.config),i=aa(e==null?void 0:e.parentConfig),a=dx(e==null?void 0:e.next),l=fx(e==null?void 0:e.tasks),c=ux(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 hx(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 au(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 la(e,t){return`${e}${t}`}function px(e,t){const n=oa(la(e,t));if(!n)return null;try{const r=JSON.parse(n);return typeof(r==null?void 0:r.threadId)!="string"?null:{threadId:r.threadId,snapshot:dn(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function mx(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=la(e,t.threadId),i=JSON.stringify(o);if(!sa(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),sa(s,i))break}catch{}}function gx(e,t){ia(la(e,t))}function yx(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 lu(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 xx(e,t){return hs(e,t)}function vx(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 wx(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 cu(e,t){const n=hs(e.metadata,t.metadata),r=hs(e.config,t.config),o=hs(e.parentConfig,t.parentConfig),s=vx(e.next,t.next),i=wx(e.tasks,t.tasks),a=xx(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 uu(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 bx="cachedThreads",Sx="v1",ca=200;function Cx(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 ua(e,t){return`cachedThreads:v1:${e}:${Cx(t||"anon")}`}function kx(){const e=oa(bx);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 Tx(e){const t=oa(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 da(e,t){sa(e,JSON.stringify(t))}function fa(e){const t=Tx(e);if(t.length>0)return t;const n=kx();if(n.length>0)try{da(e,n.slice(0,ca))}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 ha(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Ex({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 _=cu(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=uu(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 du=w.createContext(null),fu=w.createContext(null),hu=w.createContext(null),Ix=w.createContext(!1);function Nx({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}=Ji(),f=w.useMemo(()=>Xn(d),[d]),h=w.useMemo(()=>{try{return new URL(d).host}catch{return"unknown"}},[d]),p=w.useMemo(()=>`threadPayload:${Sx}:${h}:`,[h]),m=w.useCallback(I=>px(p,I),[p]),g=w.useCallback((I,A=100)=>{mx(p,I,A)},[p]),y=w.useCallback(I=>{gx(p,I)},[p]),x=w.useCallback(()=>{yx(p)},[p]),[b,C]=w.useState(()=>{var I;return ua(h,(I=c.getAuthToken)==null?void 0:I.call(c))}),[T,k]=w.useState(()=>{var A;const I=fa(ua(h,(A=c.getAuthToken)==null?void 0:A.call(c)));return ps(I)}),S=w.useMemo(()=>ha(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=fa(b);w.startTransition(()=>{k(ps(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}=Yc(),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}=Ex({currentThreadId:E,currentThreadIdRef:Se}),Y=w.useCallback(()=>{var K;const I=ht.current;if(I.size<=su)return;const A=Array.from(I.entries()).sort((fe,ie)=>fe[1].timestamp-ie[1].timestamp),W=I.size-su;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===ra?I.version:ra,threadId:I.threadId??A,checkpoints:W}},[]),ve=w.useCallback((I,A)=>{const{threadId:W,checkpointId:K=null,checkpointNs:fe=null}=I,ie=lu(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:ra,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??hx(U.messages);au(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=ha(W);return K(fe)===K(A)||A.length===0&&fe.length>0&&!It.current?W:ps(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 uu(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{ia(b)}catch{}an.current="";return}if(W===an.current)return;const K=()=>{try{const fe=I.slice(0,ca);da(b,fe),an.current=W}catch{}finally{jt.current=null}};if(A!=null&&A.immediate){K();return}jt.current=window.setTimeout(()=>{iu(K)},fs)},[b]),ze=w.useCallback(()=>{Fe(S,{immediate:!0})},[Fe,S]),Ct=w.useCallback((I,A,W,K)=>{var Vl;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 Kl=Yt==null?void 0:Yt.id;return Kl?Gt.has(Kl)?!1:(Gt.add(Kl),!0):!0}),or=cu(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:((Vl=Rt[Rt.length-1])==null?void 0:Vl.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}=sx({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>=ax){qt("error");return}A.attempts+=1,A.reason=I;const W=Math.min(lx*Math.pow(2,A.attempts-1),cx);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]),ji=w.useCallback(I=>{N.current=Date.now(),qt(A=>A==="reconnecting"?"connected":A)},[qt]);q.current=pn,ue.current=rr,ke.current=ji,w.useEffect(()=>()=>{Xe()},[Xe]);const Pi=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{ia(b)}catch{}an.current="";return}if(I===an.current)return;const A=()=>{try{const W=S.slice(0,ca);da(b,W),an.current=I}catch{}finally{jt.current=null}};return jt.current=window.setTimeout(()=>{iu(A),jt.current=null},fs),()=>{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=ua(h,fe);St.current!==ie&&(St.current=ie,Dt.current=!1),C(ie);const mt=fa(ie);w.startTransition(()=>{k(ps(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]),Ri=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=ha(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]),Km=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=lu(I,A??null,W??null),bt=ht.current.get(mt),Be=!K&&!A&&!W&&bt&&Date.now()-bt.timestamp<ix,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}=ls(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]),qm=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]),Gm=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]),Ym=w.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");await vr(Se.current,void 0,void 0,!0)},[vr]),Xm=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}=ls(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]),Jm=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 Oy(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]),Zm=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=!au((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)}},fs)}},[J,se,U.lastCheckpointId,U.lastCheckpointNs,U.messages,U.pendingInterrupt,V,g]);const wT=w.useMemo(()=>({threads:S,currentThreadId:E,setCurrentThreadId:j,isLoading:_,error:B,actions:{createThread:lo,deleteThread:Ri,renameThread:Km,refreshThreads:()=>Ne()},persistThreadsCache:ze,hydrateFromCache:F}),[S,E,_,B,lo,Ri,Km,Ne,ze,F,j]),bT=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:Xm,seedFromSnapshot:Jm,clearState:Ft,navigateToCheckpoint:Gm,returnToLatest:Ym,loadThread:vr,clearThread:qm,respondToInterrupt:Zm}},[qm,Ft,E,V,ne,ye,D,Xm,vr,U.assemblingId,U.lastBranch,U.lastCheckpointId,U.lastCheckpointNs,U.messages,Gm,Zm,Ym,Jm,H,ot]),ST=w.useMemo(()=>({isStreaming:Z,error:le,connectionState:io,submit:qo,send:qo,stop:Pi,setAuthToken:de}),[io,Z,le,Pi,qo,de]);return u.jsx(Ix.Provider,{value:!0,children:u.jsx(hu.Provider,{value:ST,children:u.jsx(du.Provider,{value:wT,children:u.jsx(fu.Provider,{value:bT,children:e})})})})}function ms(){const e=w.useContext(du);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function gs(){const e=w.useContext(fu);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function pu(){const e=w.useContext(hu);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(Py,{apiConfig:t,children:u.jsx(Nx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onAuthError:l,onThreadChange:c,children:e})})}function oe(...e){return ng.twMerge(tg.clsx(e))}const Ax=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(Ax({variant:t,size:n,className:e})),ref:s,...o})});ut.displayName="Button";const mu=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}));mu.displayName="Textarea";function gu({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(mu,{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 _x=w.memo(gu);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 yu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function pa(...e){return t=>{let n=!1;const r=e.map(o=>{const s=yu(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():yu(e[o],null)}}}}function Je(...e){return v.useCallback(pa(...e),e)}function jx(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,Px(o,...t)]}function Px(...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:()=>{},Rx=v[" useInsertionEffect ".trim().toString()]||Xt;function Vr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Ox({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const h=Mx(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 Ox({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Rx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Mx(e){return typeof e=="function"}var Dx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Me=Dx.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 xu(e,t){e&&Yo.flushSync(()=>e.dispatchEvent(t))}function ma(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 Lx=v.createContext(void 0);function xs(e){const t=v.useContext(Lx);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 Fx(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 $x="DismissableLayer",ga="dismissableLayer.update",zx="dismissableLayer.pointerDownOutside",Bx="dismissableLayer.focusOutside",vu,wu=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(wu),[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=Wx(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=Vx(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 Fx(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&&(vu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),bu(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=vu)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),bu())},[d,c]),v.useEffect(()=>{const E=()=>p({});return document.addEventListener(ga,E),()=>document.removeEventListener(ga,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)})});vs.displayName=$x;var Hx="DismissableLayerBranch",Ux=v.forwardRef((e,t)=>{const n=v.useContext(wu),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})});Ux.displayName=Hx;function Wx(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(){Su(zx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Vx(e,t=globalThis==null?void 0:globalThis.document){const n=Jt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&Su(Bx,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 bu(){const e=new CustomEvent(ga);document.dispatchEvent(e)}function Su(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?xu(o,s):o.dispatchEvent(s)}var ya=0;function xa(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Cu()),document.body.insertAdjacentElement("beforeend",e[1]??Cu()),ya++,()=>{ya===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ya--}},[])}function Cu(){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 va="focusScope.autoFocusOnMount",wa="focusScope.autoFocusOnUnmount",ku={bubbles:!1,cancelable:!0},Kx="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=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){Iu.add(p);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(va,ku);a.addEventListener(va,c),a.dispatchEvent(x),x.defaultPrevented||(qx(Zx(Tu(a)),{select:!0}),document.activeElement===g&&ir(a))}return()=>{a.removeEventListener(va,c),setTimeout(()=>{const x=new CustomEvent(wa,ku);a.addEventListener(wa,d),a.dispatchEvent(x),x.defaultPrevented||ir(g??document.body,{select:!0}),a.removeEventListener(wa,d),Iu.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]=Gx(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})});ws.displayName=Kx;function qx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(ir(r,{select:t}),document.activeElement!==n)return}function Gx(e){const t=Tu(e),n=Eu(t,e),r=Eu(t.reverse(),e);return[n,r]}function Tu(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 Eu(e,t){for(const n of e)if(!Yx(n,{upTo:t}))return n}function Yx(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 Xx(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&&Xx(e)&&t&&e.select()}}var Iu=Jx();function Jx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Nu(e,t),e.unshift(t)},remove(t){var n;e=Nu(e,t),(n=e[0])==null||n.resume()}}}function Nu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Zx(e){return e.filter(t=>t.tagName!=="A")}var Qx=v[" useId ".trim().toString()]||(()=>{}),ev=0;function Zn(e){const[t,n]=v.useState(Qx());return Xt(()=>{n(r=>r??String(ev++))},[e]),t?`radix-${t}`:""}const tv=["top","right","bottom","left"],ar=Math.min,gn=Math.max,bs=Math.round,Ss=Math.floor,zn=e=>({x:e,y:e}),nv={left:"right",right:"left",bottom:"top",top:"bottom"},rv={start:"end",end:"start"};function ba(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 Sa(e){return e==="x"?"y":"x"}function Ca(e){return e==="y"?"height":"width"}const ov=new Set(["top","bottom"]);function Bn(e){return ov.has(er(e))?"y":"x"}function ka(e){return Sa(Bn(e))}function sv(e,t,n){n===void 0&&(n=!1);const r=Kr(e),o=ka(e),s=Ca(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 iv(e){const t=Cs(e);return[Ta(e),t,Ta(t)]}function Ta(e){return e.replace(/start|end/g,t=>rv[t])}const Au=["left","right"],_u=["right","left"],av=["top","bottom"],lv=["bottom","top"];function cv(e,t,n){switch(e){case"top":case"bottom":return n?t?_u:Au:t?Au:_u;case"left":case"right":return t?av:lv;default:return[]}}function uv(e,t,n,r){const o=Kr(e);let s=cv(er(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ta)))),s}function Cs(e){return e.replace(/left|right|bottom|top/g,t=>nv[t])}function dv(e){return{top:0,right:0,bottom:0,left:0,...e}}function ju(e){return typeof e!="number"?dv(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 Pu(e,t,n){let{reference:r,floating:o}=e;const s=Bn(t),i=ka(t),a=Ca(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 fv=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}=Pu(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}=Pu(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=ju(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})),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=ks(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 hv=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=ju(d),h={x:n,y:r},p=ka(o),m=Ca(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=ba(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}}}),pv=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?[Cs(a)]:iv(a)),S=m!=="none";!h&&S&&k.push(...uv(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=sv(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 Ru(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ou(e){return tv.some(t=>e[t]>=0)}const mv=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=Ru(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ou(i)}}}case"escaped":{const s=await vo(t,{...o,altBoundary:!0}),i=Ru(s,n.floating);return{data:{escapedOffsets:i,escaped:Ou(i)}}}default:return{}}}}},Mu=new Set(["left","top"]);async function gv(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=Mu.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 yv=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 gv(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}}}}},xv=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=Sa(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=ba(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=ba(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}}}}}},vv=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=Sa(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=Mu.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}}}},wv=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 Ts(){return typeof window<"u"}function qr(e){return Du(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=(Du(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Du(e){return Ts()?e instanceof Node||e instanceof yn(e).Node:!1}function Pn(e){return Ts()?e instanceof Element||e instanceof yn(e).Element:!1}function Un(e){return Ts()?e instanceof HTMLElement||e instanceof yn(e).HTMLElement:!1}function Lu(e){return!Ts()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof yn(e).ShadowRoot}const bv=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)&&!bv.has(o)}const Sv=new Set(["table","td","th"]);function Cv(e){return Sv.has(qr(e))}const kv=[":popover-open",":modal"];function Es(e){return kv.some(t=>{try{return e.matches(t)}catch{return!1}})}const Tv=["transform","translate","scale","rotate","perspective"],Ev=["transform","translate","scale","rotate","perspective","filter"],Iv=["paint","layout","strict","content"];function Ea(e){const t=Ia(),n=Pn(e)?Rn(e):e;return Tv.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)||Ev.some(r=>(n.willChange||"").includes(r))||Iv.some(r=>(n.contain||"").includes(r))}function Nv(e){let t=lr(e);for(;Un(t)&&!Gr(t);){if(Ea(t))return t;if(Es(t))return null;t=lr(t)}return null}function Ia(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Av=new Set(["html","body","#document"]);function Gr(e){return Av.has(qr(e))}function Rn(e){return yn(e).getComputedStyle(e)}function Is(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||Lu(e)&&e.host||Hn(e);return Lu(t)?t.host:t}function Fu(e){const t=lr(e);return Gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Un(t)&&wo(t)?t:Fu(t)}function bo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Fu(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=yn(o);if(s){const a=Na(i);return t.concat(i,i.visualViewport||[],wo(o)?o:[],a&&n?bo(a):[])}return t.concat(o,bo(o,[],n))}function Na(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function $u(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=bs(n)!==s||bs(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Aa(e){return Pn(e)?e:e.contextElement}function Yr(e){const t=Aa(e);if(!Un(t))return zn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=$u(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 _v=zn(0);function zu(e){const t=yn(e);return!Ia()||!t.visualViewport?_v:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function jv(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=Aa(e);let i=zn(1);t&&(r?Pn(r)&&(i=Yr(r)):i=Yr(e));const a=jv(s,n,r)?zu(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=Na(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=Na(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:Er(Hn(e)).left+n}function Bu(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 Pv(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=Hn(r),a=t?Es(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=Is(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?Bu(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 Rv(e){return Array.from(e.getClientRects())}function Ov(e){const t=Hn(e),n=Is(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+Ns(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 Hu=25;function Mv(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=Ia();(!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<=Hu&&(s-=m)}else c<=Hu&&(s+=c);return{width:s,height:i,x:a,y:l}}const Dv=new Set(["absolute","fixed"]);function Lv(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 Uu(e,t,n){let r;if(t==="viewport")r=Mv(e,n);else if(t==="document")r=Ov(Hn(e));else if(Pn(t))r=Lv(t,n);else{const o=zu(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ks(r)}function Wu(e,t){const n=lr(e);return n===t||!Pn(n)||Gr(n)?!1:Rn(n).position==="fixed"||Wu(n,t)}function Fv(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=Ea(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Dv.has(o.position)||wo(i)&&!l&&Wu(e,i))?r=r.filter(d=>d!==i):o=a,i=lr(i)}return t.set(e,r),r}function $v(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Es(t)?[]:Fv(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Uu(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},Uu(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function zv(e){const{width:t,height:n}=$u(e);return{width:t,height:n}}function Bv(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=Ns(o)}if(r||!r&&!s)if((qr(t)!=="body"||wo(o))&&(a=Is(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?Bu(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 _a(e){return Rn(e).position==="static"}function Vu(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 Ku(e,t){const n=yn(e);if(Es(e))return n;if(!Un(e)){let o=lr(e);for(;o&&!Gr(o);){if(Pn(o)&&!_a(o))return o;o=lr(o)}return n}let r=Vu(e,t);for(;r&&Cv(r)&&_a(r);)r=Vu(r,t);return r&&Gr(r)&&_a(r)&&!Ea(r)?n:r||Nv(e)||n}const Hv=async function(e){const t=this.getOffsetParent||Ku,n=this.getDimensions,r=await n(e.floating);return{reference:Bv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Uv(e){return Rn(e).direction==="rtl"}const Wv={convertOffsetParentRelativeRectToViewportRelativeRect:Pv,getDocumentElement:Hn,getClippingRect:$v,getOffsetParent:Ku,getElementRects:Hv,getClientRects:Rv,getDimensions:zv,getScale:Yr,isElement:Pn,isRTL:Uv};function qu(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Vv(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=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: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&&!qu(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 Kv(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=Aa(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?Vv(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&&!qu(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 qv=yv,Gv=xv,Yv=pv,Xv=wv,Jv=mv,Gu=hv,Zv=vv,Qv=(e,t,n)=>{const r=new Map,o={platform:Wv,...n},s={...o.platform,_c:r};return fv(e,t,{...o,platform:s})};var ew=typeof document<"u",tw=function(){},As=ew?w.useLayoutEffect:tw;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 Yu(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Xu(e,t){const n=Yu(e);return Math.round(t*n)/n}function ja(e){const t=v.useRef(e);return As(()=>{t.current=e}),t}function nw(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),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=ja(l),D=ja(o),z=ja(c),B=v.useCallback(()=>{if(!S.current||!E.current)return;const $={placement:t,strategy:n,middleware:h};D.current&&($.platform=D.current),Qv(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: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=Xu(R.floating,d.x),ne=Xu(R.floating,d.y);return a?{...$,transform:"translate("+F+"px, "+ne+"px)",...Yu(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 rw=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?Gu({element:r.current,padding:o}).fn(n):{}:r?Gu({element:r,padding:o}).fn(n):{}}}},ow=(e,t)=>({...qv(e),options:[e,t]}),sw=(e,t)=>({...Gv(e),options:[e,t]}),iw=(e,t)=>({...Zv(e),options:[e,t]}),aw=(e,t)=>({...Yv(e),options:[e,t]}),lw=(e,t)=>({...Xv(e),options:[e,t]}),cw=(e,t)=>({...Jv(e),options:[e,t]}),uw=(e,t)=>({...rw(e),options:[e,t]});var dw="Arrow",Ju=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"})})});Ju.displayName=dw;var fw=Ju;function Zu(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 Pa="Popper",[Qu,js]=Jn(Pa),[hw,ed]=Qu(Pa),td=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(hw,{scope:t,anchor:r,onAnchorChange:o,children:n})};td.displayName=Pa;var nd="PopperAnchor",rd=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=ed(nd,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})});rd.displayName=nd;var Ra="PopperContent",[pw,mw]=Qu(Ra),od=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=ed(Ra,n),[x,b]=v.useState(null),C=Je(t,Ue=>b(Ue)),[T,k]=v.useState(null),S=Zu(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(yw),altBoundary:z},{refs:O,floatingStyles:H,placement:R,isPositioned:V,middlewareData:$}=nw({strategy:"fixed",placement:_,whileElementsMounted:(...Ue)=>Kv(...Ue,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[ow({mainAxis:o+j,alignmentAxis:i}),l&&sw({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?iw():void 0,...B}),l&&aw({...B}),lw({...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&&uw({element:T,padding:a}),xw({arrowWidth:E,arrowHeight:j}),h&&cw({strategy:"referenceHidden",...B})]}),[F,ne]=ad(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(pw,{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"}})})})});od.displayName=Ra;var sd="PopperArrow",gw={top:"bottom",right:"left",bottom:"top",left:"right"},id=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=mw(sd,r),i=gw[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(fw,{...o,ref:n,style:{...o.style,display:"block"}})})});id.displayName=sd;function yw(e){return e!==null}var xw=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]=ad(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 ad(e){const[t,n="center"]=e.split("-");return[t,n]}var ld=td,cd=rd,ud=od,dd=id,vw="Portal",Ps=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?Oi.createPortal(u.jsx(Me.div,{...r,ref:t}),i):null});Ps.displayName=vw;function ww(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Cn=e=>{const{present:t,children:n}=e,r=bw(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Je(r.ref,Sw(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Cn.displayName="Presence";function bw(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=ww(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]),Xt(()=>{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]),Xt(()=>{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 Sw(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Oa="rovingFocusGroup.onEntryFocus",Cw={bubbles:!1,cancelable:!0},So="RovingFocusGroup",[Ma,fd,kw]=ma(So),[Tw,hd]=Jn(So,[kw]),[Ew,Iw]=Tw(So),pd=v.forwardRef((e,t)=>u.jsx(Ma.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Ma.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Nw,{...e,ref:t})})}));pd.displayName=So;var Nw=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=xs(s),[g,y]=Vr({prop:i,defaultProp:a??null,onChange:l,caller:So}),[x,b]=v.useState(!1),C=Jt(c),T=fd(n),k=v.useRef(!1),[S,E]=v.useState(0);return v.useEffect(()=>{const j=h.current;if(j)return j.addEventListener(Oa,C),()=>j.removeEventListener(Oa,C)},[C]),u.jsx(Ew,{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(Oa,Cw);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);yd(H,d)}}k.current=!1}),onBlur:ge(e.onBlur,()=>b(!1))})})}),md="RovingFocusGroupItem",gd=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=Iw(md,n),f=d.currentTabStopId===c,h=fd(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:g}=d;return v.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),u.jsx(Ma.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=jw(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?Pw(C,T+1):C.slice(T+1)}setTimeout(()=>yd(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});gd.displayName=md;var Aw={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function _w(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function jw(e,t,n){const r=_w(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Aw[r]}function yd(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Pw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Rw=pd,Ow=gd,Mw=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={},Da=0,xd=function(e){return e&&(e.host||xd(e.parentNode))},Dw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=xd(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})},Lw=function(e,t,n,r){var o=Dw(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(),Da++,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)}),Da--,Da||(Xr=new WeakMap,Xr=new WeakMap,Os=new WeakMap,Ms={})}},La=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Mw(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Lw(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 vd(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 Fw(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",$w="with-scroll-bars-hidden",zw="--removed-body-scroll-bar-size";function Fa(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Bw(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 Hw=typeof window<"u"?v.useLayoutEffect:v.useEffect,wd=new WeakMap;function Uw(e,t){var n=Bw(null,function(r){return e.forEach(function(o){return Fa(o,r)})});return Hw(function(){var r=wd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Fa(a,null)}),s.forEach(function(a){o.has(a)||Fa(a,i)})}wd.set(n,e)},[e]),n}function Ww(e){return e}function Vw(e,t){t===void 0&&(t=Ww);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 Kw(e){e===void 0&&(e={});var t=Vw(null);return t.options=Wn({async:!0,ssr:!1},e),t}var bd=function(e){var t=e.sideCar,n=vd(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))};bd.isSideCarExport=!0;function qw(e,t){return e.useMedium(t),bd}var Sd=Kw(),$a=function(){},Fs=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:$a,onWheelCapture:$a,onTouchMoveCapture:$a}),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=vd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,S=Uw([n,t]),E=Wn(Wn({},T),o);return v.createElement(v.Fragment,null,d&&v.createElement(k,{sideCar:Sd,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))});Fs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Fs.classNames={fullWidth:Ls,zeroRight:Ds};var Gw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Yw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Gw();return t&&e.setAttribute("nonce",t),e}function Xw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Jw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Zw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Yw())&&(Xw(t,n),Jw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Qw=function(){var e=Zw();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Cd=function(){var e=Qw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},eb={left:0,top:0,right:0,gap:0},za=function(e){return parseInt(e||"",10)||0},tb=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[za(n),za(r),za(o)]},nb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return eb;var t=tb(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])}},rb=Cd(),Jr="data-scroll-locked",ob=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($w,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
42
42
|
}
|
|
43
|
-
body[`).concat(
|
|
43
|
+
body[`).concat(Jr,`] {
|
|
44
44
|
overflow: hidden `).concat(r,`;
|
|
45
45
|
overscroll-behavior: contain;
|
|
46
46
|
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
@@ -53,29 +53,29 @@ React keys must be passed directly to JSX without using spread:
|
|
|
53
53
|
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
.`).concat(
|
|
56
|
+
.`).concat(Ds,` {
|
|
57
57
|
right: `).concat(a,"px ").concat(r,`;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
.`).concat(
|
|
60
|
+
.`).concat(Ls,` {
|
|
61
61
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
.`).concat(
|
|
64
|
+
.`).concat(Ds," .").concat(Ds,` {
|
|
65
65
|
right: 0 `).concat(r,`;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
.`).concat(
|
|
68
|
+
.`).concat(Ls," .").concat(Ls,` {
|
|
69
69
|
margin-right: 0 `).concat(r,`;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
body[`).concat(
|
|
73
|
-
`).concat(
|
|
72
|
+
body[`).concat(Jr,`] {
|
|
73
|
+
`).concat(zw,": ").concat(a,`px;
|
|
74
74
|
}
|
|
75
|
-
`)},
|
|
75
|
+
`)},kd=function(){var e=parseInt(document.body.getAttribute(Jr)||"0",10);return isFinite(e)?e:0},sb=function(){v.useEffect(function(){return document.body.setAttribute(Jr,(kd()+1).toString()),function(){var e=kd()-1;e<=0?document.body.removeAttribute(Jr):document.body.setAttribute(Jr,e.toString())}},[])},ib=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;sb();var s=v.useMemo(function(){return nb(o)},[o]);return v.createElement(rb,{styles:ob(s,!t,o,n?"":"!important")})},Ba=!1;if(typeof window<"u")try{var $s=Object.defineProperty({},"passive",{get:function(){return Ba=!0,!0}});window.addEventListener("test",$s,$s),window.removeEventListener("test",$s,$s)}catch{Ba=!1}var Zr=Ba?{passive:!1}:!1,ab=function(e){return e.tagName==="TEXTAREA"},Td=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!ab(e)&&n[t]==="visible")},lb=function(e){return Td(e,"overflowY")},cb=function(e){return Td(e,"overflowX")},Ed=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Id(e,r);if(o){var s=Nd(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},ub=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},db=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Id=function(e,t){return e==="v"?lb(t):cb(t)},Nd=function(e,t){return e==="v"?ub(t):db(t)},fb=function(e,t){return e==="h"&&t==="rtl"?-1:1},hb=function(e,t,n,r,o){var s=fb(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=Nd(e,a),m=p[0],g=p[1],y=p[2],x=g-y-s*m;(m||x)&&Id(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},zs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Ad=function(e){return[e.deltaX,e.deltaY]},_d=function(e){return e&&"current"in e?e.current:e},pb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},mb=function(e){return`
|
|
76
76
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
77
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
78
|
-
`)},db=0,eo=[];function fb(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(db++)[0],s=v.useState(bd)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=Rw([e.lockRef.current],(e.shards||[]).map(Nd),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=Bs(g),w=n.current,C="deltaX"in g?g.deltaX:w[0]-x[0],T="deltaY"in g?g.deltaY:w[1]-x[1],k,S=g.target,E=Math.abs(C)>Math.abs(T)?"h":"v";if("touches"in g&&E==="h"&&S.type==="range")return!1;var j=kd(E,S);if(!j)return!0;if(j?k=E:(k=E==="v"?"h":"v",j=kd(E,S)),!j)return!1;if(!r.current&&"changedTouches"in g&&(C||T)&&(r.current=k),!k)return!0;var _=r.current||k;return lb(_,y,g,_==="h"?C:T)},[]),l=v.useCallback(function(g){var y=g;if(!(!eo.length||eo[eo.length-1]!==s)){var x="deltaY"in y?Id(y):Bs(y),w=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&cb(k.delta,x)})[0];if(w&&w.should){y.cancelable&&y.preventDefault();return}if(!w){var C=(i.current.shards||[]).map(Nd).filter(Boolean).filter(function(k){return k.contains(y.target)}),T=C.length>0?a(y,C[0]):!i.current.noIsolation;T&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(g,y,x,w){var C={name:g,delta:y,target:x,should:w,shadowParent:hb(x)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(T){return T!==C})},1)},[]),d=v.useCallback(function(g){n.current=Bs(g),r.current=void 0},[]),f=v.useCallback(function(g){c(g.type,Id(g),g.target,a(g,e.lockRef.current))},[]),h=v.useCallback(function(g){c(g.type,Bs(g),g.target,a(g,e.lockRef.current))},[]);v.useEffect(function(){return eo.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Qr),document.addEventListener("touchmove",l,Qr),document.addEventListener("touchstart",d,Qr),function(){eo=eo.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,Qr),document.removeEventListener("touchmove",l,Qr),document.removeEventListener("touchstart",d,Qr)}},[]);var p=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:ub(o)}):null,p?v.createElement(tb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function hb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const pb=Hw(wd,fb);var Hs=v.forwardRef(function(e,t){return v.createElement($s,Hn({},e,{ref:t,sideCar:pb}))});Hs.classNames=$s.classNames;var Ba=["Enter"," "],mb=["ArrowDown","PageUp","Home"],Ad=["ArrowUp","PageDown","End"],gb=[...mb,...Ad],yb={ltr:[...Ba,"ArrowRight"],rtl:[...Ba,"ArrowLeft"]},xb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},So="Menu",[Co,vb,wb]=pa(So),[Er,_d]=Zn(So,[wb,Ps,dd]),Us=Ps(),jd=dd(),[bb,Ir]=Er(So),[Sb,ko]=Er(So),Pd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Us(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Gt(s),h=vs(o);return v.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(id,{...a,children:u.jsx(bb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Sb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Pd.displayName=So;var Cb="MenuAnchor",Ha=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Us(n);return u.jsx(ad,{...o,...r,ref:t})});Ha.displayName=Cb;var Ua="MenuPortal",[kb,Rd]=Er(Ua,{forceMount:void 0}),Od=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Ir(Ua,t);return u.jsx(kb,{scope:t,forceMount:n,children:u.jsx(bn,{present:n||s.open,children:u.jsx(Rs,{asChild:!0,container:o,children:r})})})};Od.displayName=Ua;var Sn="MenuContent",[Tb,Wa]=Er(Sn),Md=v.forwardRef((e,t)=>{const n=Rd(Sn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Ir(Sn,e.__scopeMenu),i=ko(Sn,e.__scopeMenu);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(bn,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(Eb,{...o,ref:t}):u.jsx(Ib,{...o,ref:t})})})})}),Eb=v.forwardRef((e,t)=>{const n=Ir(Sn,e.__scopeMenu),r=v.useRef(null),o=Je(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),u.jsx(Va,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Ib=v.forwardRef((e,t)=>{const n=Ir(Sn,e.__scopeMenu);return u.jsx(Va,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Nb=wr.createSlot("MenuContent.ScrollLock"),Va=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...g}=e,y=Ir(Sn,n),x=ko(Sn,n),w=Us(n),C=jd(n),T=vb(n),[k,S]=v.useState(null),E=v.useRef(null),j=Je(t,E,y.onContentChange),_=v.useRef(0),P=v.useRef(""),D=v.useRef(0),z=v.useRef(null),B=v.useRef("right"),O=v.useRef(0),H=m?Hs:v.Fragment,R=m?{as:Nb,allowPinchZoom:!0}:void 0,V=F=>{var te,L;const ne=P.current+F,Q=T().filter(G=>!G.disabled),ye=document.activeElement,Pe=(te=Q.find(G=>G.ref.current===ye))==null?void 0:te.textValue,Z=Q.map(G=>G.textValue),ue=zb(Z,ne,Pe),ke=(L=Q.find(G=>G.textValue===ue))==null?void 0:L.ref.current;(function G(se){P.current=se,window.clearTimeout(_.current),se!==""&&(_.current=window.setTimeout(()=>G(""),1e3))})(ne),ke&&setTimeout(()=>ke.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),ya();const $=v.useCallback(F=>{var Q,ye;return B.current===((Q=z.current)==null?void 0:Q.side)&&Hb(F,(ye=z.current)==null?void 0:ye.area)},[]);return u.jsx(Tb,{scope:n,searchRef:P,onItemEnter:v.useCallback(F=>{$(F)&&F.preventDefault()},[$]),onItemLeave:v.useCallback(F=>{var ne;$(F)||((ne=E.current)==null||ne.focus(),S(null))},[$]),onTriggerLeave:v.useCallback(F=>{$(F)&&F.preventDefault()},[$]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(F=>{z.current=F},[]),children:u.jsx(H,{...R,children:u.jsx(bs,{asChild:!0,trapped:o,onMountAutoFocus:ge(s,F=>{var ne;F.preventDefault(),(ne=E.current)==null||ne.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(ws,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(Nw,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:S,onEntryFocus:ge(l,F=>{x.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ld,{role:"menu","aria-orientation":"vertical","data-state":Zd(y.open),"data-radix-menu-content":"",dir:x.dir,...w,...g,ref:j,style:{outline:"none",...g.style},onKeyDown:ge(g.onKeyDown,F=>{const Q=F.target.closest("[data-radix-menu-content]")===F.currentTarget,ye=F.ctrlKey||F.altKey||F.metaKey,Pe=F.key.length===1;Q&&(F.key==="Tab"&&F.preventDefault(),!ye&&Pe&&V(F.key));const Z=E.current;if(F.target!==Z||!gb.includes(F.key))return;F.preventDefault();const ke=T().filter(te=>!te.disabled).map(te=>te.ref.current);Ad.includes(F.key)&&ke.reverse(),Fb(ke)}),onBlur:ge(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(_.current),P.current="")}),onPointerMove:ge(e.onPointerMove,Eo(F=>{const ne=F.target,Q=O.current!==F.clientX;if(F.currentTarget.contains(ne)&&Q){const ye=F.clientX>O.current?"right":"left";B.current=ye,O.current=F.clientX}}))})})})})})})});Md.displayName=Sn;var Ab="MenuGroup",Ka=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{role:"group",...r,ref:t})});Ka.displayName=Ab;var _b="MenuLabel",Dd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{...r,ref:t})});Dd.displayName=_b;var Ws="MenuItem",Ld="menu.itemSelect",Vs=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=ko(Ws,e.__scopeMenu),a=Wa(Ws,e.__scopeMenu),l=Je(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Ld,{bubbles:!0,cancelable:!0});f.addEventListener(Ld,p=>r==null?void 0:r(p),{once:!0}),gu(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Fd,{...o,ref:l,disabled:n,onClick:ge(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:ge(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ge(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ba.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Vs.displayName=Ws;var Fd=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Wa(Ws,n),a=jd(n),l=v.useRef(null),c=Je(t,l),[d,f]=v.useState(!1),[h,p]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),u.jsx(Co.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(Aw,{asChild:!0,...a,focusable:!r,children:u.jsx(De.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ge(e.onPointerMove,Eo(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,Eo(m=>i.onItemLeave(m))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),jb="MenuCheckboxItem",$d=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Wd,{scope:e.__scopeMenu,checked:n,children:u.jsx(Vs,{role:"menuitemcheckbox","aria-checked":Ks(n)?"mixed":n,...o,ref:t,"data-state":Ga(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(Ks(n)?!0:!n),{checkForDefaultPrevented:!1})})})});$d.displayName=jb;var zd="MenuRadioGroup",[Pb,Rb]=Er(zd,{value:void 0,onValueChange:()=>{}}),Bd=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Gt(r);return u.jsx(Pb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Ka,{...o,ref:t})})});Bd.displayName=zd;var Hd="MenuRadioItem",Ud=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=Rb(Hd,e.__scopeMenu),s=n===o.value;return u.jsx(Wd,{scope:e.__scopeMenu,checked:s,children:u.jsx(Vs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ga(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Ud.displayName=Hd;var qa="MenuItemIndicator",[Wd,Ob]=Er(qa,{checked:!1}),Vd=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Ob(qa,n);return u.jsx(bn,{present:r||Ks(s.checked)||s.checked===!0,children:u.jsx(De.span,{...o,ref:t,"data-state":Ga(s.checked)})})});Vd.displayName=qa;var Mb="MenuSeparator",Kd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Kd.displayName=Mb;var Db="MenuArrow",qd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Us(n);return u.jsx(cd,{...o,...r,ref:t})});qd.displayName=Db;var Lb="MenuSub",[HT,Gd]=Er(Lb),To="MenuSubTrigger",Yd=v.forwardRef((e,t)=>{const n=Ir(To,e.__scopeMenu),r=ko(To,e.__scopeMenu),o=Gd(To,e.__scopeMenu),s=Wa(To,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Ha,{asChild:!0,...c,children:u.jsx(Fd,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Zd(n.open),...e,ref:ha(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ge(e.onPointerMove,Eo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ge(e.onPointerLeave,Eo(f=>{var p,m;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(m=n.content)==null?void 0:m.dataset.side,y=g==="right",x=y?-5:5,w=h[y?"left":"right"],C=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:w,y:h.top},{x:C,y:h.top},{x:C,y:h.bottom},{x:w,y:h.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ge(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||yb[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Yd.displayName=To;var Xd="MenuSubContent",Jd=v.forwardRef((e,t)=>{const n=Rd(Sn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Ir(Sn,e.__scopeMenu),i=ko(Sn,e.__scopeMenu),a=Gd(Xd,e.__scopeMenu),l=v.useRef(null),c=Je(t,l);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(bn,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:u.jsx(Va,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ge(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ge(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ge(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=xb[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Jd.displayName=Xd;function Zd(e){return e?"open":"closed"}function Ks(e){return e==="indeterminate"}function Ga(e){return Ks(e)?"indeterminate":e?"checked":"unchecked"}function Fb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function $b(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function zb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=$b(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Bb(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function Hb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Bb(n,t)}function Eo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Ub=Pd,Wb=Ha,Vb=Od,Kb=Md,qb=Ka,Gb=Dd,Yb=Vs,Xb=$d,Jb=Bd,Zb=Ud,Qb=Vd,e0=Kd,t0=qd,n0=Yd,r0=Jd,qs="DropdownMenu",[o0,UT]=Zn(qs,[_d]),tn=_d(),[s0,Qd]=o0(qs),ef=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=tn(t),c=v.useRef(null),[d,f]=Kr({prop:o,defaultProp:s??!1,onChange:i,caller:qs});return u.jsx(s0,{scope:t,triggerId:Qn(),triggerRef:c,contentId:Qn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(Ub,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};ef.displayName=qs;var tf="DropdownMenuTrigger",nf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Qd(tf,n),i=tn(n);return u.jsx(Wb,{asChild:!0,...i,children:u.jsx(De.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:ha(t,s.triggerRef),onPointerDown:ge(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ge(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});nf.displayName=tf;var i0="DropdownMenuPortal",rf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=tn(t);return u.jsx(Vb,{...r,...n})};rf.displayName=i0;var of="DropdownMenuContent",sf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Qd(of,n),s=tn(n),i=v.useRef(!1);return u.jsx(Kb,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ge(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ge(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});sf.displayName=of;var a0="DropdownMenuGroup",l0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(qb,{...o,...r,ref:t})});l0.displayName=a0;var c0="DropdownMenuLabel",af=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Gb,{...o,...r,ref:t})});af.displayName=c0;var u0="DropdownMenuItem",lf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Yb,{...o,...r,ref:t})});lf.displayName=u0;var d0="DropdownMenuCheckboxItem",cf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Xb,{...o,...r,ref:t})});cf.displayName=d0;var f0="DropdownMenuRadioGroup",h0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Jb,{...o,...r,ref:t})});h0.displayName=f0;var p0="DropdownMenuRadioItem",uf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Zb,{...o,...r,ref:t})});uf.displayName=p0;var m0="DropdownMenuItemIndicator",df=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(Qb,{...o,...r,ref:t})});df.displayName=m0;var g0="DropdownMenuSeparator",ff=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(e0,{...o,...r,ref:t})});ff.displayName=g0;var y0="DropdownMenuArrow",x0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(t0,{...o,...r,ref:t})});x0.displayName=y0;var v0="DropdownMenuSubTrigger",hf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(n0,{...o,...r,ref:t})});hf.displayName=v0;var w0="DropdownMenuSubContent",pf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(r0,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});pf.displayName=w0;var b0=ef,S0=nf,C0=rf,mf=sf,gf=af,yf=lf,xf=cf,vf=uf,wf=df,bf=ff,Sf=hf,Cf=pf;const k0=b0,T0=S0,E0=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(Sf,{ref:o,className:oe("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(he.ChevronRight,{className:"ml-auto h-4 w-4"})]}));E0.displayName=Sf.displayName;const I0=v.forwardRef(({className:e,...t},n)=>u.jsx(Cf,{ref:n,className:oe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));I0.displayName=Cf.displayName;const kf=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(C0,{children:u.jsx(mf,{ref:r,sideOffset:t,className:oe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));kf.displayName=mf.displayName;const Ya=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(yf,{ref:r,className:oe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ya.displayName=yf.displayName;const N0=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(xf,{ref:o,className:oe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wf,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),t]}));N0.displayName=xf.displayName;const A0=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vf,{ref:r,className:oe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wf,{children:u.jsx(he.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));A0.displayName=vf.displayName;const _0=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(gf,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));_0.displayName=gf.displayName;const j0=v.forwardRef(({className:e,...t},n)=>u.jsx(bf,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));j0.displayName=bf.displayName;const Gs=1e4;function P0(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
78
|
+
`)},gb=0,Qr=[];function yb(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(gb++)[0],s=v.useState(Cd)[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=Fw([e.lockRef.current],(e.shards||[]).map(_d),!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),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=Ed(E,S);if(!j)return!0;if(j?k=E:(k=E==="v"?"h":"v",j=Ed(E,S)),!j)return!1;if(!r.current&&"changedTouches"in g&&(C||T)&&(r.current=k),!k)return!0;var _=r.current||k;return hb(_,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?Ad(y):zs(y),b=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&pb(k.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var C=(i.current.shards||[]).map(_d).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:xb(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,Ad(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:mb(o)}):null,p?v.createElement(ib,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function xb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const vb=qw(Sd,yb);var Bs=v.forwardRef(function(e,t){return v.createElement(Fs,Wn({},e,{ref:t,sideCar:vb}))});Bs.classNames=Fs.classNames;var Ha=["Enter"," "],wb=["ArrowDown","PageUp","Home"],jd=["ArrowUp","PageDown","End"],bb=[...wb,...jd],Sb={ltr:[...Ha,"ArrowRight"],rtl:[...Ha,"ArrowLeft"]},Cb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Co="Menu",[ko,kb,Tb]=ma(Co),[Ir,Pd]=Jn(Co,[Tb,js,hd]),Hs=js(),Rd=hd(),[Eb,Nr]=Ir(Co),[Ib,To]=Ir(Co),Od=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=Jt(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(ld,{...a,children:u.jsx(Eb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Ib,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Od.displayName=Co;var Nb="MenuAnchor",Ua=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Hs(n);return u.jsx(cd,{...o,...r,ref:t})});Ua.displayName=Nb;var Wa="MenuPortal",[Ab,Md]=Ir(Wa,{forceMount:void 0}),Dd=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Nr(Wa,t);return u.jsx(Ab,{scope:t,forceMount:n,children:u.jsx(Cn,{present:n||s.open,children:u.jsx(Ps,{asChild:!0,container:o,children:r})})})};Dd.displayName=Wa;var kn="MenuContent",[_b,Va]=Ir(kn),Ld=v.forwardRef((e,t)=>{const n=Md(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(jb,{...o,ref:t}):u.jsx(Pb,{...o,ref:t})})})})}),jb=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 La(s)},[]),u.jsx(Ka,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Pb=v.forwardRef((e,t)=>{const n=Nr(kn,e.__scopeMenu);return u.jsx(Ka,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Rb=br.createSlot("MenuContent.ScrollLock"),Ka=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=Hs(n),C=Rd(n),T=kb(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?Bs:v.Fragment,R=m?{as:Rb,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=Vb(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),[]),xa();const $=v.useCallback(F=>{var Q,ye;return B.current===((Q=z.current)==null?void 0:Q.side)&&qb(F,(ye=z.current)==null?void 0:ye.area)},[]);return u.jsx(_b,{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(Rw,{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(ud,{role:"menu","aria-orientation":"vertical","data-state":ef(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||!bb.includes(F.key))return;F.preventDefault();const Ce=T().filter(te=>!te.disabled).map(te=>te.ref.current);jd.includes(F.key)&&Ce.reverse(),Ub(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}}))})})})})})})});Ld.displayName=kn;var Ob="MenuGroup",qa=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Me.div,{role:"group",...r,ref:t})});qa.displayName=Ob;var Mb="MenuLabel",Fd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Me.div,{...r,ref:t})});Fd.displayName=Mb;var Us="MenuItem",$d="menu.itemSelect",Ws=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=To(Us,e.__scopeMenu),a=Va(Us,e.__scopeMenu),l=Je(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent($d,{bubbles:!0,cancelable:!0});f.addEventListener($d,p=>r==null?void 0:r(p),{once:!0}),xu(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(zd,{...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===" "||Ha.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Ws.displayName=Us;var zd=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Va(Us,n),a=Rd(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(Ow,{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))})})})}),Db="MenuCheckboxItem",Bd=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Kd,{scope:e.__scopeMenu,checked:n,children:u.jsx(Ws,{role:"menuitemcheckbox","aria-checked":Vs(n)?"mixed":n,...o,ref:t,"data-state":Ya(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(Vs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Bd.displayName=Db;var Hd="MenuRadioGroup",[Lb,Fb]=Ir(Hd,{value:void 0,onValueChange:()=>{}}),Ud=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Jt(r);return u.jsx(Lb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(qa,{...o,ref:t})})});Ud.displayName=Hd;var Wd="MenuRadioItem",Vd=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=Fb(Wd,e.__scopeMenu),s=n===o.value;return u.jsx(Kd,{scope:e.__scopeMenu,checked:s,children:u.jsx(Ws,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ya(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Vd.displayName=Wd;var Ga="MenuItemIndicator",[Kd,$b]=Ir(Ga,{checked:!1}),qd=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=$b(Ga,n);return u.jsx(Cn,{present:r||Vs(s.checked)||s.checked===!0,children:u.jsx(Me.span,{...o,ref:t,"data-state":Ya(s.checked)})})});qd.displayName=Ga;var zb="MenuSeparator",Gd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Me.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Gd.displayName=zb;var Bb="MenuArrow",Yd=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Hs(n);return u.jsx(dd,{...o,...r,ref:t})});Yd.displayName=Bb;var Hb="MenuSub",[qT,Xd]=Ir(Hb),Eo="MenuSubTrigger",Jd=v.forwardRef((e,t)=>{const n=Nr(Eo,e.__scopeMenu),r=To(Eo,e.__scopeMenu),o=Xd(Eo,e.__scopeMenu),s=Va(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(Ua,{asChild:!0,...c,children:u.jsx(zd,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":ef(n.open),...e,ref:pa(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===" "||Sb[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Jd.displayName=Eo;var Zd="MenuSubContent",Qd=v.forwardRef((e,t)=>{const n=Md(kn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Nr(kn,e.__scopeMenu),i=To(kn,e.__scopeMenu),a=Xd(Zd,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(Ka,{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=Cb[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Qd.displayName=Zd;function ef(e){return e?"open":"closed"}function Vs(e){return e==="indeterminate"}function Ya(e){return Vs(e)?"indeterminate":e?"checked":"unchecked"}function Ub(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Wb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Vb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Wb(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 Kb(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 qb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Kb(n,t)}function Io(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Gb=Od,Yb=Ua,Xb=Dd,Jb=Ld,Zb=qa,Qb=Fd,e0=Ws,t0=Bd,n0=Ud,r0=Vd,o0=qd,s0=Gd,i0=Yd,a0=Jd,l0=Qd,Ks="DropdownMenu",[c0,GT]=Jn(Ks,[Pd]),nn=Pd(),[u0,tf]=c0(Ks),nf=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:Ks});return u.jsx(u0,{scope:t,triggerId:Zn(),triggerRef:c,contentId:Zn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(Gb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};nf.displayName=Ks;var rf="DropdownMenuTrigger",of=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=tf(rf,n),i=nn(n);return u.jsx(Yb,{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:pa(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())})})})});of.displayName=rf;var d0="DropdownMenuPortal",sf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=nn(t);return u.jsx(Xb,{...r,...n})};sf.displayName=d0;var af="DropdownMenuContent",lf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tf(af,n),s=nn(n),i=v.useRef(!1);return u.jsx(Jb,{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)"}})});lf.displayName=af;var f0="DropdownMenuGroup",h0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(Zb,{...o,...r,ref:t})});h0.displayName=f0;var p0="DropdownMenuLabel",cf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(Qb,{...o,...r,ref:t})});cf.displayName=p0;var m0="DropdownMenuItem",uf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(e0,{...o,...r,ref:t})});uf.displayName=m0;var g0="DropdownMenuCheckboxItem",df=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(t0,{...o,...r,ref:t})});df.displayName=g0;var y0="DropdownMenuRadioGroup",x0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(n0,{...o,...r,ref:t})});x0.displayName=y0;var v0="DropdownMenuRadioItem",ff=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(r0,{...o,...r,ref:t})});ff.displayName=v0;var w0="DropdownMenuItemIndicator",hf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(o0,{...o,...r,ref:t})});hf.displayName=w0;var b0="DropdownMenuSeparator",pf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(s0,{...o,...r,ref:t})});pf.displayName=b0;var S0="DropdownMenuArrow",C0=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(i0,{...o,...r,ref:t})});C0.displayName=S0;var k0="DropdownMenuSubTrigger",mf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(a0,{...o,...r,ref:t})});mf.displayName=k0;var T0="DropdownMenuSubContent",gf=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=nn(n);return u.jsx(l0,{...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)"}})});gf.displayName=T0;var E0=nf,I0=of,N0=sf,yf=lf,xf=cf,vf=uf,wf=df,bf=ff,Sf=hf,Cf=pf,kf=mf,Tf=gf;const A0=E0,_0=I0,j0=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(kf,{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"})]}));j0.displayName=kf.displayName;const P0=v.forwardRef(({className:e,...t},n)=>u.jsx(Tf,{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}));P0.displayName=Tf.displayName;const Ef=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(N0,{children:u.jsx(yf,{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})}));Ef.displayName=yf.displayName;const Xa=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(vf,{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}));Xa.displayName=vf.displayName;const R0=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(wf,{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(Sf,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),t]}));R0.displayName=wf.displayName;const O0=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(bf,{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(Sf,{children:u.jsx(he.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));O0.displayName=bf.displayName;const M0=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(xf,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));M0.displayName=xf.displayName;const D0=v.forwardRef(({className:e,...t},n)=>u.jsx(Cf,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));D0.displayName=Cf.displayName;const qs=1e4;function L0(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 R0(e,t=Gs){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function O0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),R0(t),P0(t)}const Ys=0,cr=1,to=2,Tf=4;function Ef(e){return()=>e}function M0(e){e()}function If(e,t){return n=>e(t(n))}function Nf(e,t){return()=>e(t)}function D0(e,t){return n=>e(t,n)}function Xa(e){return e!==void 0}function L0(...e){return()=>{e.map(M0)}}function no(){}function Xs(e,t){return t(e),e}function F0(e,t){return t(e)}function Tt(...e){return e}function ut(e,t){return e(cr,t)}function ze(e,t){e(Ys,t)}function Ja(e){e(to)}function Ot(e){return e(Tf)}function we(e,t){return ut(e,D0(t,Ys))}function Pn(e,t){const n=e(cr,r=>{n(),t(r)});return n}function Af(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function _f(e,t){return e===t}function Et(e=_f){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function je(e){return t=>n=>{e(n)&&t(n)}}function pe(e){return t=>If(t,e)}function Un(e){return t=>()=>{t(e)}}function X(e,...t){const n=$0(...t);return(r,o)=>{switch(r){case to:Ja(e);return;case cr:return ut(e,n(o))}}}function Wn(e,t){return n=>r=>{n(t=e(t,r))}}function Nr(e){return t=>n=>{e>0?e--:t(n)}}function nr(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ue(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);ut(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function $0(...e){return t=>e.reduceRight(F0,t)}function z0(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case cr:return s?n===s?void 0:(r(),n=s,t=ut(e,s),t):(r(),no);case to:r(),n=null;return}}}function ee(e){let t=e;const n=Ze();return(r,o)=>{switch(r){case Ys:t=o;break;case cr:{o(t);break}case Tf:return t}return n(r,o)}}function Xt(e,t){return Xs(ee(t),n=>we(e,n))}function Ze(){const e=[];return(t,n)=>{switch(t){case Ys:e.slice().forEach(r=>{r(n)});return;case to:e.splice(0,e.length);return;case cr:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function gn(e){return Xs(Ze(),t=>we(e,t))}function it(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:B0(),singleton:n}}const B0=()=>Symbol();function H0(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function $t(...e){const t=Ze(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);ut(s,l=>{n[i]=l,r=r|a,r===o&&ze(t,n)})}),function(s,i){switch(s){case to:{Ja(t);return}case cr:return r===o&&i(n),ut(t,i)}}}function Ae(e,t=_f){return X(e,Et(t))}function Za(...e){return function(t,n){switch(t){case to:return;case cr:return L0(...e.map(r=>ut(r,n)))}}}var dn=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(dn||{});const U0={0:"debug",3:"error",1:"log",2:"warn"},W0=()=>typeof globalThis>"u"?window:globalThis,ur=it(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=W0().VIRTUOSO_LOG_LEVEL)!=null?o:Ot(e);r>=s&&console[U0[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Ar(e,t,n){return Qa(e,t,n).callbackRef}function Qa(e,t,n){const r=b.useRef(null);let o=i=>{};const s=b.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function V0(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const f=K0(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let m;p&&(m=h.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:p?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?jf("column-gap",getComputedStyle(d).columnGap,o):jf("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Qa(c,n,l)}function K0(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},dn.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function jf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,dn.WARN),t==="normal"?0:parseInt(t??"0",10)}function Pf(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=c.top-p.top;h=p.height-Math.max(0,m),f=m+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Qa(o,!0,n),a=b.useCallback(()=>{o(i.current)},[o,i]);return b.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const nn=it(()=>{const e=Ze(),t=Ze(),n=ee(0),r=Ze(),o=ee(0),s=Ze(),i=Ze(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Ze(),h=Ze(),p=ee(!1),m=ee(!1),g=ee(!1);return we(X(e,pe(({scrollTop:y})=>y)),t),we(X(e,pe(({scrollHeight:y})=>y)),i),we(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Io={lvl:0};function Rf(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function wt(e){return e===Io}function No(e,t){if(!wt(e))return t===e.k?e.v:t<e.k?No(e.l,t):No(e.r,t)}function Rn(e,t,n="k"){if(wt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Rn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Rn(e.l,t,n)}function yn(e,t,n){return wt(e)?Df(t,n,1):t===e.k?Bt(e,{k:t,v:n}):t<e.k?Lf(Bt(e,{l:yn(e.l,t,n)})):Lf(Bt(e,{r:yn(e.r,t,n)}))}function ro(){return Io}function Js(e,t,n){if(wt(e))return[];const r=Rn(e,t)[0];return q0(tl(e,r,n))}function el(e,t){if(wt(e))return Io;const{k:n,l:r,r:o}=e;if(t===n){if(wt(r))return o;if(wt(o))return r;{const[s,i]=Mf(r);return Zs(Bt(e,{k:s,l:Of(r),v:i}))}}else return t<n?Zs(Bt(e,{l:el(r,t)})):Zs(Bt(e,{r:el(o,t)}))}function _r(e){return wt(e)?[]:[..._r(e.l),{k:e.k,v:e.v},..._r(e.r)]}function tl(e,t,n){if(wt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(tl(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(tl(s,t,n))),a}function Zs(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(nl(t))return Ff(Bt(e,{lvl:n-1}));if(!wt(t)&&!wt(t.r))return Bt(t.r,{l:Bt(t,{r:t.r.l}),lvl:n,r:Bt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(nl(e))return rl(Bt(e,{lvl:n-1}));if(!wt(r)&&!wt(r.l)){const o=r.l,s=nl(o)?r.lvl-1:r.lvl;return Bt(o,{l:Bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:rl(Bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Bt(e,t){return Df(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Of(e){return wt(e.r)?e.l:Zs(Bt(e,{r:Of(e.r)}))}function nl(e){return wt(e)||e.lvl>e.r.lvl}function Mf(e){return wt(e.r)?[e.k,e.v]:Mf(e.r)}function Df(e,t,n,r=Io,o=Io){return{k:e,l:r,lvl:n,r:o,v:t}}function Lf(e){return rl(Ff(e))}function Ff(e){const{l:t}=e;return!wt(t)&&t.lvl===e.lvl?Bt(t,{r:Bt(e,{l:t.r})}):e}function rl(e){const{lvl:t,r:n}=e;return!wt(n)&&!wt(n.r)&&n.lvl===t&&n.r.lvl===t?Bt(n,{l:Bt(e,{r:n.l}),lvl:t+1}):e}function q0(e){return Rf(e,({k:t,v:n})=>({index:t,value:n}))}function $f(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Ao(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ol=it(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function zf(e,t,n){return e[Qs(e,t,n)]}function Qs(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function G0(e,t,n,r){const o=Qs(e,t,r),s=Qs(e,n,r,o);return e.slice(o,s+1)}function dr(e,t){return Math.round(e.getBoundingClientRect()[t])}function ei(e){return!wt(e.groupOffsetTree)}function sl({index:e},t){return t===e?0:t<e?-1:1}function Y0(){return{groupIndices:[],groupOffsetTree:ro(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ro()}}function X0(e,t){let n=wt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),wt(e)){e=yn(e,0,s);continue}const a=Js(e,i-1,o+1);if(a.some(rS(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=el(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=yn(e,o+1,h));c&&(e=yn(e,i,s))}return[e,n]}function J0(e){return typeof e.groupIndex<"u"}function Z0({offset:e},t){return t===e?0:t<e?-1:1}function _o(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=zf(t,e,sl),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Bf(e,t){if(!ei(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Hf(e,t,n){if(J0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Bf(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Q0(e,t,n,r=0){return r>0&&(t=Math.max(t,zf(e,r,sl).offset)),Rf(G0(e,t,n,Z0),nS)}function eS(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,dn.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&wt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,g)=>yn(yn(m,g,h),g+1,p),i)}else[i,a]=X0(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=il(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>yn(h,p,_o(p,f,o)),ro()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function tS(e){return _r(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function Uf(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function il(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Qs(o,t-1,sl),a=o[l].offset;const c=Rn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===Rn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of Js(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:d}),s=c,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function nS(e){return{index:e.index,value:e}}function rS(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const oS={offsetHeight:"height",offsetWidth:"width"},Vn=it(([{log:e},{recalcInProgress:t}])=>{const n=Ze(),r=Ze(),o=Xt(r,0),s=Ze(),i=Ze(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((k,S)=>dr(k,oS[S])),h=ee(void 0),p=ee(0),m=Y0(),g=Xt(X(n,Ue(l,e,p),Wn(eS,m),Et()),m),y=Xt(X(l,Et(),Wn((k,S)=>({current:S,prev:k.current}),{current:[],prev:[]}),pe(({prev:k})=>k)),[]);we(X(l,je(k=>k.length>0),Ue(g,p),pe(([k,S,E])=>{const j=k.reduce((_,P,D)=>yn(_,P,_o(P,S.offsetTree,E)||D),ro());return{...S,groupIndices:k,groupOffsetTree:j}})),g),we(X(r,Ue(g),je(([k,{lastIndex:S}])=>k<S),pe(([k,{lastIndex:S,lastSize:E}])=>[{endIndex:S,size:E,startIndex:k}])),n),we(c,d);const x=Xt(X(c,pe(k=>k===void 0)),!0);we(X(d,je(k=>k!==void 0&&wt(Ot(g).sizeTree)),pe(k=>[{endIndex:0,size:k,startIndex:0}])),n);const w=gn(X(n,Ue(g),Wn(({sizes:k},[S,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:m}),pe(k=>k.changed)));ut(X(a,Wn((k,S)=>({diff:k.prev-S,prev:S}),{diff:0,prev:0}),pe(k=>k.diff)),k=>{const{groupIndices:S}=Ot(g);if(k>0)ze(t,!0),ze(s,k+Uf(k,S));else if(k<0){const E=Ot(y);E.length>0&&(k-=Uf(-k,E)),ze(i,k)}}),ut(X(a,Ue(e)),([k,S])=>{k<0&&S("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},dn.ERROR)});const C=gn(s);we(X(s,Ue(g),pe(([k,S])=>{const E=S.groupIndices.length>0,j=[],_=S.lastSize;if(E){const P=No(S.sizeTree,0);let D=0,z=0;for(;D<k;){const O=S.groupIndices[z],H=S.groupIndices.length===z+1?1/0:S.groupIndices[z+1]-O-1;j.push({endIndex:O,size:P,startIndex:O}),j.push({endIndex:O+1+H-1,size:_,startIndex:O+1}),z++,D+=H+1}const B=_r(S.sizeTree);return D!==k&&B.shift(),B.reduce((O,{k:H,v:R})=>{let V=O.ranges;return O.prevSize!==0&&(V=[...O.ranges,{endIndex:H+k-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:H+k,prevSize:R,ranges:V}},{prevIndex:k,prevSize:0,ranges:j}).ranges}return _r(S.sizeTree).reduce((P,{k:D,v:z})=>({prevIndex:D+k,prevSize:z,ranges:[...P.ranges,{endIndex:D+k-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const T=gn(X(i,Ue(g,p),pe(([k,{offsetTree:S},E])=>{const j=-k;return _o(j,S,E)})));return we(X(i,Ue(g,p),pe(([k,S,E])=>{if(S.groupIndices.length>0){if(wt(S.sizeTree))return S;let j=ro();const _=Ot(y);let P=0,D=0,z=0;for(;P<-k;){z=_[D];const B=_[D+1]-z-1;D++,P+=B+1}if(j=_r(S.sizeTree).reduce((B,{k:O,v:H})=>yn(B,Math.max(0,O+k),H),j),P!==-k){const B=No(S.sizeTree,z);j=yn(j,0,B);const O=Rn(S.sizeTree,-k+1)[1];j=yn(j,1,O)}return{...S,sizeTree:j,...il(S.offsetTree,0,j,E)}}else{const j=_r(S.sizeTree).reduce((_,{k:P,v:D})=>yn(_,Math.max(0,P+k),D),ro());return{...S,sizeTree:j,...il(S.offsetTree,0,j,E)}}})),g),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Tt(ur,ol),{singleton:!0});function sS(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Wf=it(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ze(),i=Ze(),a=gn(X(s,pe(sS)));return we(X(a,pe(l=>l.totalCount)),n),we(X(a,pe(l=>l.groupIndices)),e),we(X($t(o,t,r),je(([l,c])=>ei(c)),pe(([l,c,d])=>Rn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),Et(),pe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},Tt(Vn,nn)),fr=it(([{log:e}])=>{const t=ee(!1),n=gn(X(t,je(r=>r),Et()));return ut(t,r=>{r&&Ot(e)("props updated",{},dn.DEBUG)}),{didMount:n,propsReady:t}},Tt(ur),{singleton:!0}),iS=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Vf(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!iS)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const jo=it(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ze(),m=Ze(),g=ee(0);let y=null,x=null,w=null;function C(){y&&(y(),y=null),w&&(w(),w=null),x&&(clearTimeout(x),x=null),ze(l,!1)}return we(X(p,Ue(n,f,r,g,a,i,h),Ue(e,s,o),pe(([[T,k,S,E,j,_,P,D],z,B,O])=>{const H=Vf(T),{align:R,behavior:V,offset:$}=H,F=E-1,ne=Hf(H,k,F);let Q=_o(ne,k.offsetTree,z)+_;R==="end"?(Q+=B+Rn(k.sizeTree,ne)[1]-S+O,ne===F&&(Q+=P)):R==="center"?Q+=(B+Rn(k.sizeTree,ne)[1]-S+O)/2:Q-=j,$&&(Q+=$);const ye=Pe=>{C(),Pe?(D("retrying to scroll to",{location:T},dn.DEBUG),ze(p,T)):(ze(m,!0),D("list did not change, scroll successful",{},dn.DEBUG))};if(C(),V==="smooth"){let Pe=!1;w=ut(t,Z=>{Pe=Pe||Z}),y=Pn(d,()=>{ye(Pe)})}else y=Pn(X(t,aS(150)),ye);return x=setTimeout(()=>{C()},1200),ze(l,!0),D("scrolling from index to",{behavior:V,index:ne,top:Q},dn.DEBUG),{behavior:V,top:Q}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:g}},Tt(Vn,nn,ur),{singleton:!0});function aS(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function al(e,t){e==0?t():requestAnimationFrame(()=>{al(e-1,t)})}function ll(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Po=it(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return we(X(i,Ue(l),je(([d,f])=>!!f),Un(!1)),a),we(X(i,Ue(l),je(([d,f])=>!!f),Un(!1)),c),ut(X($t(t,i),Ue(a,n,e,c),je(([[,d],f,{sizeTree:h},p,m])=>d&&(!wt(h)||Xa(p))&&!f&&!m),Ue(l)),([,d])=>{Pn(o,()=>{ze(c,!0)}),al(4,()=>{Pn(r,()=>{ze(a,!0)}),ze(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},Tt(Vn,nn,jo,fr),{singleton:!0});function Kf(e,t){return Math.abs(e-t)<1.01}const Ro="up",Oo="down",lS="none",cS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},uS=0,Mo=it(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Ze(),c=Ze(),d=ee(4),f=ee(uS),h=Xt(X(Za(X(Ae(o),Nr(1),Un(!0)),X(Ae(o),Nr(1),Un(!1),Af(100))),Et()),!1),p=Xt(X(Za(X(n,Un(!0)),X(n,Un(!1),Af(200))),Et()),!1);we(X($t(Ae(o),Ae(f)),pe(([w,C])=>w<=C),Et()),a),we(X(a,nr(50)),c);const m=gn(X($t(r,Ae(s),Ae(t),Ae(e),Ae(d)),Wn((w,[{scrollHeight:C,scrollTop:T},k,S,E,j])=>{const _=T+k-C>-j,P={scrollHeight:C,scrollTop:T,viewportHeight:k};if(_){let z,B;return T>w.state.scrollTop?(z="SCROLLED_DOWN",B=w.state.scrollTop-T):(z="SIZE_DECREASED",B=w.state.scrollTop-T||w.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:B,state:P}}let D;return P.scrollHeight>w.state.scrollHeight?D="SIZE_INCREASED":k<w.state.viewportHeight?D="VIEWPORT_HEIGHT_DECREASING":T<w.state.scrollTop?D="SCROLLING_UPWARDS":D="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:D,state:P}},cS),Et((w,C)=>w&&w.atBottom===C.atBottom))),g=Xt(X(r,Wn((w,{scrollHeight:C,scrollTop:T,viewportHeight:k})=>{if(Kf(w.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:T};{const S=C-(T+k)<1;return w.scrollTop!==T&&S?{changed:!0,jump:w.scrollTop-T,scrollHeight:C,scrollTop:T}:{changed:!0,jump:0,scrollHeight:C,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),je(w=>w.changed),pe(w=>w.jump)),0);we(X(m,pe(w=>w.atBottom)),i),we(X(i,nr(50)),l);const y=ee(Oo);we(X(r,pe(({scrollTop:w})=>w),Et(),Wn((w,C)=>Ot(p)?{direction:w.direction,prevScrollTop:C}:{direction:C<w.prevScrollTop?Ro:Oo,prevScrollTop:C},{direction:Oo,prevScrollTop:0}),pe(w=>w.direction)),y),we(X(r,nr(50),Un(lS)),y);const x=ee(0);return we(X(h,je(w=>!w),Un(0)),x),we(X(o,nr(100),Ue(h),je(([w,C])=>!!C),Wn(([w,C],[T])=>[C,T],[0,0]),pe(([w,C])=>C-w)),x),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},Tt(nn)),ti="top",ni="bottom",qf="none";function Gf(e,t,n){return typeof e=="number"?n===Ro&&t===ti||n===Oo&&t===ni?e:0:n===Ro?t===ti?e.main:e.reverse:t===ni?e.main:e.reverse}function Yf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const cl=it(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ze(),i=ee(0),a=ee(0),l=ee(0),c=Xt(X($t(Ae(r),Ae(o),Ae(n),Ae(s,Ao),Ae(l),Ae(i),Ae(t),Ae(e),Ae(a)),pe(([d,f,h,[p,m],g,y,x,w,C])=>{const T=d-w,k=y+x,S=Math.max(h-T,0);let E=qf;const j=Yf(C,ti),_=Yf(C,ni);return p-=w,p+=h+x,m+=h+x,m-=w,p>d+k-j&&(E=Ro),m<d-S+f+_&&(E=Oo),E!==qf?[Math.max(T-h-Gf(g,ti,E)-j,0),T-S-x+f+Gf(g,ni,E)+_]:null}),je(d=>d!=null),Et(Ao)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},Tt(nn),{singleton:!0});function dS(e,t,n){if(ei(t)){const r=Bf(e,t);return[{index:Rn(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const ul={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ri(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,m=h-d;return{bottom:d,firstItemIndex:s,items:Jf(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:Jf(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function Xf(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=ll(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ri(c,[],a,o,n,r)}function Jf(e,t,n){if(e.length===0)return[];if(!ei(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Js(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const jr=it(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:m}])=>{const g=ee([]),y=ee(0),x=Ze();we(s.topItemsIndexes,g);const w=Xt(X($t(p,m,Ae(l,Ao),Ae(o),Ae(r),Ae(c),d,Ae(g),Ae(t),Ae(n),e),je(([S,E,,j,,,,,,,_])=>{const P=_&&_.length!==j;return S&&!E&&!P}),pe(([,,[S,E],j,_,P,D,z,B,O,H])=>{const R=_,{offsetTree:V,sizeTree:$}=R,F=Ot(y);if(j===0)return{...ul,totalCount:j};if(S===0&&E===0)return F===0?{...ul,totalCount:j}:Xf(F,P,_,B,O,H||[]);if(wt($))return F>0?null:ri(dS(ll(P,j),R,H),[],j,O,R,B);const ne=[];if(z.length>0){const ue=z[0],ke=z[z.length-1];let te=0;for(const L of Js($,ue,ke)){const G=L.value,se=Math.max(L.start,ue),le=Math.min(L.end,ke);for(let U=se;U<=le;U++)ne.push({data:H==null?void 0:H[U],index:U,offset:te,size:G}),te+=G}}if(!D)return ri([],ne,j,O,R,B);const Q=z.length>0?z[z.length-1]+1:0,ye=Q0(V,S,E,Q);if(ye.length===0)return null;const Pe=j-1,Z=Xs([],ue=>{for(const ke of ye){const te=ke.value;let L=te.offset,G=ke.start;const se=te.size;if(te.offset<S){G+=Math.floor((S-te.offset+O)/(se+O));const U=G-ke.start;L+=U*se+U*O}G<Q&&(L+=(Q-G)*se,G=Q);const le=Math.min(ke.end,Pe);for(let U=G;U<=le&&!(L>=E);U++)ue.push({data:H==null?void 0:H[U],index:U,offset:L,size:se}),L+=se+O}});return ri(Z,ne,j,O,R,B)}),je(S=>S!==null),Et()),ul);we(X(e,je(Xa),pe(S=>S==null?void 0:S.length)),o),we(X(w,pe(S=>S.topListHeight)),f),we(f,a),we(X(w,pe(S=>[S.top,S.bottom])),i),we(X(w,pe(S=>S.items)),x);const C=gn(X(w,je(({items:S})=>S.length>0),Ue(o,e),je(([{items:S},E])=>S[S.length-1].originalIndex===E-1),pe(([,S,E])=>[S-1,E]),Et(Ao),pe(([S])=>S))),T=gn(X(w,nr(200),je(({items:S,topItems:E})=>S.length>0&&S[0].originalIndex===E.length),pe(({items:S})=>S[0].index),Et())),k=gn(X(w,je(({items:S})=>S.length>0),pe(({items:S})=>{let E=0,j=S.length-1;for(;S[E].type==="group"&&E<j;)E++;for(;S[j].type==="group"&&j>E;)j--;return{endIndex:S[j].index,startIndex:S[E].index}}),Et($f)));return{endReached:C,initialItemCount:y,itemsRendered:x,listState:w,rangeChanged:k,startReached:T,topItemsIndexes:g,...h}},Tt(Vn,Wf,cl,Po,jo,Mo,fr,ol),{singleton:!0}),Zf=it(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ze(),i=Xt(X($t(n,e,r,t,o),pe(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return we(Ae(i),s),{totalListHeight:i,totalListHeightChanged:s}},Tt(nn,jr),{singleton:!0}),fS=it(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Xt(X($t(n,e,t),je(([o])=>o),pe(([,o,s])=>Math.max(0,o-s)),nr(0),Et()),0);return{alignToBottom:n,paddingTopAddition:r}},Tt(nn,Zf),{singleton:!0}),Qf=it(()=>({context:ee(null)})),hS=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,eh=it(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ze();return we(X(d,Ue(t,l,n,s,o,r,a),Ue(e),pe(([[f,h,p,m,g,y,x,w],C])=>{const{align:T,behavior:k,calculateViewLocation:S=hS,done:E,...j}=f,_=Hf(f,h,m-1),P=_o(_,h.offsetTree,C)+g+y,D=P+Rn(h.sizeTree,_)[1],z=w+y,B=w+p-x,O=S({itemBottom:D,itemTop:P,locationParams:{align:T,behavior:k,...j},viewportBottom:B,viewportTop:z});return O?E&&Pn(X(i,je(H=>!H),Nr(Ot(i)?1:2)),E):E&&E(),O}),je(f=>f!==null)),c),{scrollIntoView:d}},Tt(Vn,nn,jo,jr,ur),{singleton:!0});function th(e){return e?e==="smooth"?"smooth":"auto":!1}const pS=(e,t)=>typeof e=="function"?th(e(t)):t&&th(e),mS=it(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const m=ee(!1),g=Ze();let y=null;function x(k){ze(i,{align:"end",behavior:k,index:"LAST"})}ut(X($t(X(Ae(t),Nr(1)),l),Ue(Ae(m),s,a,f),pe(([[k,S],E,j,_,P])=>{let D=S&&_,z="auto";return D&&(z=pS(E,j||P),D=D&&!!z),{followOutputBehavior:z,shouldFollow:D,totalCount:k}}),je(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:S})=>{y&&(y(),y=null),Ot(n)?requestAnimationFrame(()=>{Ot(d)("following output to ",{totalCount:S},dn.DEBUG),x(k)}):y=Pn(e,()=>{Ot(d)("following output to ",{totalCount:S},dn.DEBUG),x(k),y=null})});function w(k){const S=Pn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(Ot(d)("scrolling to bottom due to increased size",{},dn.DEBUG),x("auto"))});setTimeout(S,100)}ut(X($t(Ae(m),t,c),je(([k,,S])=>k&&S),Wn(({value:k},[,S])=>({refreshed:k===S,value:S}),{refreshed:!1,value:0}),je(({refreshed:k})=>k),Ue(m,t)),([,k])=>{Ot(a)&&w(k!==!1)}),ut(g,()=>{w(Ot(m)!==!1)}),ut($t(Ae(m),o),([k,S])=>{k&&!S.atBottom&&S.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=ee(null),T=Ze();return we(Za(X(Ae(r),pe(k=>{var S;return(S=k==null?void 0:k.length)!=null?S:0})),X(Ae(t))),T),ut(X($t(X(T,Nr(1)),l),Ue(Ae(C),a,f,h),pe(([[k,S],E,j,_,P])=>S&&j&&(E==null?void 0:E({context:P,totalCount:k,scrollingInProgress:_}))),je(k=>!!k),nr(0)),k=>{y&&(y(),y=null),Ot(n)?requestAnimationFrame(()=>{Ot(d)("scrolling into view",{}),ze(p,k)}):y=Pn(e,()=>{Ot(d)("scrolling into view",{}),ze(p,k),y=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:C}},Tt(Vn,Mo,jo,Po,fr,ur,nn,Qf,eh)),gS=it(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(we(X(a,Ue(s),je(([,l])=>l!==0),Ue(o,r,t,n,e),pe(([[,l],c,d,f,h,p=[]])=>Xf(l,c,d,f,h,p))),i),{}),Tt(Vn,Po,jr,fr),{singleton:!0}),yS=it(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return ut(X(e,Ue(r),je(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{Pn(X(n,Nr(1),je(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ze(t,o)})})}),{initialScrollTop:r}},Tt(fr,nn,jr),{singleton:!0}),nh=it(([{scrollVelocity:e}])=>{const t=ee(!1),n=Ze(),r=ee(!1);return we(X(e,Ue(r,t,n),je(([o,s])=>!!s),pe(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),Et()),t),ut(X($t(t,e,n),Ue(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Tt(Mo),{singleton:!0}),dl=it(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ze(),r=Ze(),o=Ze(),s=ee(!1),i=ee(void 0);return we(X($t(n,r),pe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),we(X(t,Ue(r),pe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Tt(nn)),xS=it(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ze(),d=ee(void 0),f=ee(null),h=ee(null);return we(a,f),we(l,h),ut(X(c,Ue(t,r,i,f,h,n)),([p,m,g,y,x,w,C])=>{const T=tS(m.sizeTree);y&&x!==null&&w!==null&&(g=x.scrollTop-w.offsetTop),g-=C,p({ranges:T,scrollTop:g})}),we(X(d,je(Xa),pe(vS)),o),we(X(s,Ue(d),je(([,p])=>p!==void 0),Et(),pe(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},Tt(Vn,nn,Po,fr,dl));function vS(e){return{align:"start",index:0,offset:e.scrollTop}}const wS=it(([{topItemsIndexes:e}])=>{const t=ee(0);return we(X(t,je(n=>n>=0),pe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Tt(jr));function rh(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const bS=rh(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),SS=it(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:m}])=>{const g=gn(X(l,Ue(i),Wn(([,x,w,C],[{bottom:T,items:k,offsetBottom:S,totalCount:E},j])=>{const _=T+S;let P=0;return w===E&&x.length>0&&k.length>0&&(k[0].originalIndex===0&&x[0].originalIndex===0||(P=_-C,P!==0&&(P+=j))),[P,k,E,_]},[0,[],0,0]),je(([x])=>x!==0),Ue(r,a,n,o,p,m),je(([,x,w,C,,,T])=>!T&&!C&&x!==0&&w===Ro),pe(([[x],,,,,w])=>(w("Upward scrolling compensation",{amount:x},dn.DEBUG),x))));function y(x){x>0?(ze(t,{behavior:"auto",top:-x}),ze(e,0)):(ze(e,0),ze(t,{behavior:"auto",top:-x}))}return ut(X(g,Ue(e,s)),([x,w,C])=>{C&&bS()?ze(e,w-x):y(-x)}),ut(X($t(Xt(s,!1),e,m),je(([x,w,C])=>!x&&!C&&w!==0),pe(([x,w])=>w),nr(1)),y),we(X(f,pe(x=>({top:-x}))),t),ut(X(c,Ue(h,d),pe(([x,{groupIndices:w,lastSize:C,sizeTree:T},k])=>{function S(E){return E*(C+k)}if(w.length===0)return S(x);{let E=0;const j=No(T,0);let _=0,P=0;for(;_<x;){_++,E+=j;let D=w.length===P+1?1/0:w[P+1]-w[P]-1;_+D>x&&(E-=j,D=x-_+1),_+=D,E+=S(D),P++}return E}})),x=>{ze(e,x),requestAnimationFrame(()=>{ze(t,{top:x}),requestAnimationFrame(()=>{ze(e,0),ze(m,!1)})})}),{deviation:e}},Tt(nn,Mo,jr,Vn,ur,ol)),CS=it(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),Tt(cl,gS,fr,nh,Zf,yS,fS,dl,eh,ur,Qf)),oh=it(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m},g,y,x,{listState:w,topItemsIndexes:C,...T},{scrollToIndex:k},S,{topItemCount:E},{groupCounts:j},_])=>(we(T.rangeChanged,_.scrollSeekRangeChanged),we(X(_.windowViewportRect,pe(P=>P.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:j,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m,sizeRanges:a,topItemCount:E,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:w,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,..._,...g,sizes:l,...y}),Tt(Vn,Po,nn,xS,mS,jr,jo,SS,wS,Wf,CS));function kS(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const oi=typeof document<"u"?b.useLayoutEffect:b.useEffect;function sh(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=b.createContext({});function l(y,x){y.propsReady&&ze(y.propsReady,!1);for(const w of r){const C=y[t.required[w]];ze(C,x[w])}for(const w of o)if(w in x){const C=y[t.optional[w]];ze(C,x[w])}y.propsReady&&ze(y.propsReady,!0)}function c(y){return s.reduce((x,w)=>(x[w]=C=>{const T=y[t.methods[w]];ze(T,C)},x),{})}function d(y){return i.reduce((x,w)=>(x[w]=z0(y[t.events[w]]),x),{})}const f=b.forwardRef((y,x)=>{const{children:w,...C}=y,[T]=b.useState(()=>Xs(H0(e),E=>{l(E,C)})),[k]=b.useState(Nf(d,T));oi(()=>{for(const E of i)E in C&&ut(k[E],C[E]);return()=>{Object.values(k).map(Ja)}},[C,k,T]),oi(()=>{l(T,C)}),b.useImperativeHandle(x,Ef(c(T)));const S=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(S,{...kS([...r,...o,...i],C),children:w}):w})}),h=y=>{const x=b.useContext(a);return b.useCallback(w=>{ze(x[y],w)},[x,y])},p=y=>{const x=b.useContext(a)[y],w=b.useCallback(C=>ut(x,C),[x]);return b.useSyncExternalStore(w,()=>Ot(x),()=>Ot(x))},m=y=>{const x=b.useContext(a)[y],[w,C]=b.useState(Nf(Ot,x));return oi(()=>ut(x,T=>{T!==w&&C(Ef(T))}),[x,w]),w},g=b.version.startsWith("18")?p:m;return{Component:f,useEmitter:(y,x)=>{const w=b.useContext(a)[y];oi(()=>ut(w,x),[x,w])},useEmitterValue:g,usePublisher:h}}const ih=b.createContext(void 0),ah=b.createContext(void 0),lh=typeof document<"u"?b.useLayoutEffect:b.useEffect;function fl(e){return"self"in e}function TS(e){return"body"in e}function ch(e,t,n,r=no,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(h=>{let p,m,g;const y=h.target;if(TS(y)||fl(y)){const w=fl(y)?y:y.defaultView;g=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else g=s?y.scrollLeft:y.scrollTop,p=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:m})};h.suppressFlushSync?x():Ri.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===p-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const m=h.behavior==="smooth";let g,y,x;fl(p)?(y=Math.max(dr(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(y=p[s?"scrollWidth":"scrollHeight"],g=dr(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const w=y-g;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),Kf(g,y)||h.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),m&&t(!0);return}m?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const hl="-webkit-sticky",uh="sticky",pl=rh(()=>{if(typeof document>"u")return uh;const e=document.createElement("div");return e.style.position=hl,e.style.position===hl?hl:uh});function ml(e){return e}const ES=it(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ml),o=ee("div"),s=ee(no),i=(a,l=null)=>Xt(X(n,pe(c=>c[a]),Et()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),IS=it(([e,t])=>({...e,...t}),Tt(oh,ES)),NS=({height:e})=>u.jsx("div",{style:{height:e}}),AS={overflowAnchor:"none",position:pl(),zIndex:1},dh={overflowAnchor:"none"},_S={...dh,display:"inline-block",height:"100%"},fh=b.memo(function({showTopList:e=!1}){const t=Me("listState"),n=Cn("sizeRanges"),r=Me("useWindowScroll"),o=Me("customScrollParent"),s=Cn("windowScrollContainerState"),i=Cn("scrollContainerState"),a=o||r?s:i,l=Me("itemContent"),c=Me("context"),d=Me("groupContent"),f=Me("trackItemSizes"),h=Me("itemSize"),p=Me("log"),m=Cn("gap"),g=Me("horizontalDirection"),{callbackRef:y}=V0(n,h,f,e?no:a,p,m,o,g,Me("skipAnimationFrameInResizeObserver")),[x,w]=b.useState(0);gl("deviation",O=>{x!==O&&w(O)});const C=Me("EmptyPlaceholder"),T=Me("ScrollSeekPlaceholder")||NS,k=Me("ListComponent"),S=Me("ItemComponent"),E=Me("GroupComponent"),j=Me("computeItemKey"),_=Me("isSeeking"),P=Me("groupIndices").length>0,D=Me("alignToBottom"),z=Me("initialItemFinalLocationReached"),B=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:x!==0?x:D?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:D?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...z?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?u.jsx(C,{...Jt(C,c)}):u.jsx(k,{...Jt(k,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:B,children:(e?t.topItems:t.items).map(O=>{const H=O.originalIndex,R=j(H+t.firstItemIndex,O.data,c);return _?b.createElement(T,{...Jt(T,c),height:O.size,index:O.index,key:R,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?b.createElement(E,{...Jt(E,c),"data-index":H,"data-item-index":O.index,"data-known-size":O.size,key:R,style:AS},d(O.index,c)):b.createElement(S,{...Jt(S,c),...OS(S,O.data),"data-index":H,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:R,style:g?_S:dh},P?l(O.index,O.groupIndex,O.data,c):l(O.index,O.data,c))})})}),jS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},PS={outline:"none",overflowX:"auto",position:"relative"},si=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),RS={position:pl(),top:0,width:"100%",zIndex:1};function Jt(e,t){if(typeof e!="string")return{context:t}}function OS(e,t){return{item:typeof e=="string"?void 0:t}}const MS=b.memo(function(){const e=Me("HeaderComponent"),t=Cn("headerHeight"),n=Me("HeaderFooterTag"),r=Ar(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,Me("skipAnimationFrameInResizeObserver")),o=Me("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),DS=b.memo(function(){const e=Me("FooterComponent"),t=Cn("footerHeight"),n=Me("HeaderFooterTag"),r=Ar(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,Me("skipAnimationFrameInResizeObserver")),o=Me("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null});function hh({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:m}=ch(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?PS:jS,...o},tabIndex:0,...i,...Jt(l,s),children:r})})}function ph({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=b.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=ch(a,c,l,m,h);return lh(()=>{var w;return y.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{y.current=null}},[y,h]),e("windowScrollTo",x),e("scrollBy",g),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Jt(l,s),children:r})})}const LS=({children:e})=>{const t=b.useContext(ih),n=Cn("viewportHeight"),r=Cn("fixedItemHeight"),o=Me("alignToBottom"),s=Me("horizontalDirection"),i=b.useMemo(()=>If(n,l=>dr(l,s?"width":"height")),[n,s]),a=Ar(i,!0,Me("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:si(o),children:e})},FS=({children:e})=>{const t=b.useContext(ih),n=Cn("windowViewportRect"),r=Cn("fixedItemHeight"),o=Me("customScrollParent"),s=Pf(n,o,Me("skipAnimationFrameInResizeObserver")),i=Me("alignToBottom");return b.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:si(i),children:e})},$S=({children:e})=>{const t=Me("TopItemListComponent")||"div",n=Me("headerHeight"),r={...RS,marginTop:`${n}px`},o=Me("context");return u.jsx(t,{style:r,...Jt(t,o),children:e})},zS=b.memo(function(e){const t=Me("useWindowScroll"),n=Me("topItemsIndexes").length>0,r=Me("customScrollParent"),o=Me("context");return u.jsxs(r||t?US:HS,{...e,context:o,children:[n&&u.jsx($S,{children:u.jsx(fh,{showTopList:!0})}),u.jsxs(r||t?FS:LS,{children:[u.jsx(MS,{}),u.jsx(fh,{}),u.jsx(DS,{})]})]})}),{Component:BS,useEmitter:gl,useEmitterValue:Me,usePublisher:Cn}=sh(IS,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},zS),HS=hh({useEmitter:gl,useEmitterValue:Me,usePublisher:Cn}),US=ph({useEmitter:gl,useEmitterValue:Me,usePublisher:Cn}),WS=BS;Tt(oh,it(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ml),a=ee(no),l=(c,d=null)=>Xt(X(s,pe(f=>f[c]),Et()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),pl();const mh={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},VS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:gh,floor:ii,max:Do,min:yl,round:yh}=Math;function xh(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function KS(e){return{...VS,items:e}}function ai(e,t){return e&&e.width===t.width&&e.height===t.height}function qS(e,t){return e&&e.column===t.column&&e.row===t.row}const GS=it(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:m,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:w,windowScrollTo:C,windowViewportRect:T},k])=>{const S=ee(0),E=ee(0),j=ee(mh),_=ee({height:0,width:0}),P=ee({height:0,width:0}),D=Ze(),z=Ze(),B=ee(0),O=ee(null),H=ee({column:0,row:0}),R=Ze(),V=Ze(),$=ee(!1),F=ee(0),ne=ee(!0),Q=ee(!1),ye=ee(!1);ut(X(m,Ue(F),je(([L,G])=>!!G)),()=>{ze(ne,!1)}),ut(X($t(m,ne,P,_,F,Q),je(([L,G,se,le,,U])=>L&&!G&&se.height!==0&&le.height!==0&&!U)),([,,,,L])=>{ze(Q,!0),al(1,()=>{ze(D,L)}),Pn(X(c),()=>{ze(t,[0,0]),ze(ne,!0)})}),we(X(V,je(L=>L!=null&&L.scrollTop>0),Un(0)),E),ut(X(m,Ue(V),je(([,L])=>L!=null)),([,L])=>{L&&(ze(_,L.viewport),ze(P,L.item),ze(H,L.gap),L.scrollTop>0&&(ze($,!0),Pn(X(c,Nr(1)),G=>{ze($,!1)}),ze(l,{top:L.scrollTop})))}),we(X(_,pe(({height:L})=>L)),f),we(X($t(Ae(_,ai),Ae(P,ai),Ae(H,(L,G)=>L&&L.column===G.column&&L.row===G.row),Ae(c)),pe(([L,G,se,le])=>({gap:se,item:G,scrollTop:le,viewport:L}))),R),we(X($t(Ae(S),r,Ae(H,qS),Ae(P,ai),Ae(_,ai),Ae(O),Ae(E),Ae($),Ae(ne),Ae(F)),je(([,,,,,,,L])=>!L),pe(([L,[G,se],le,U,We,re,xe,,Re,Fe])=>{const{column:tt,row:Se}=le,{height:Ge,width:nt}=U,{width:Qe}=We;if(xe===0&&(L===0||Qe===0))return mh;if(nt===0){const rt=ll(Fe,L),rn=rt+Math.max(xe-1,0);return KS(xh(rt,rn,re))}const Ye=vh(Qe,nt,tt);let qe,et;Re?G===0&&se===0&&xe>0?(qe=0,et=xe-1):(qe=Ye*ii((G+Se)/(Ge+Se)),et=Ye*gh((se+Se)/(Ge+Se))-1,et=yl(L-1,Do(et,Ye-1)),qe=yl(et,Do(0,qe))):(qe=0,et=-1);const Mt=xh(qe,et,re),{bottom:Ct,top:dt}=wh(We,le,U,Mt),xt=gh(L/Ye),ft=xt*Ge+(xt-1)*Se-Ct;return{bottom:Ct,itemHeight:Ge,items:Mt,itemWidth:nt,offsetBottom:ft,offsetTop:dt,top:dt}})),j),we(X(O,je(L=>L!==null),pe(L=>L.length)),S),we(X($t(_,P,j,H),je(([L,G,{items:se}])=>se.length>0&&G.height!==0&&L.height!==0),pe(([L,G,{items:se},le])=>{const{bottom:U,top:We}=wh(L,le,G,se);return[We,U]}),Et(Ao)),t);const Pe=ee(!1);we(X(c,Ue(Pe),pe(([L,G])=>G||L!==0)),Pe);const Z=gn(X($t(j,S),je(([{items:L}])=>L.length>0),Ue(Pe),je(([[L,G],se])=>{const le=L.items[L.items.length-1].index===G-1;return(se||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===G)&&le}),pe(([[,L]])=>L-1),Et())),ue=gn(X(Ae(j),je(({items:L})=>L.length>0&&L[0].index===0),Un(0),Et())),ke=gn(X(Ae(j),Ue($),je(([{items:L},G])=>L.length>0&&!G),pe(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),Et($f),nr(0)));we(ke,p.scrollSeekRangeChanged),we(X(D,Ue(_,P,S,H),pe(([L,G,se,le,U])=>{const We=Vf(L),{align:re,behavior:xe,offset:Re}=We;let Fe=We.index;Fe==="LAST"&&(Fe=le-1),Fe=Do(0,Fe,yl(le-1,Fe));let tt=xl(G,U,se,Fe);return re==="end"?tt=yh(tt-G.height+se.height):re==="center"&&(tt=yh(tt-G.height/2+se.height/2)),Re&&(tt+=Re),{behavior:xe,top:tt}})),l);const te=Xt(X(j,pe(L=>L.offsetBottom+L.bottom)),0);return we(X(T,pe(L=>({height:L.visibleHeight,width:L.visibleWidth}))),_),{customScrollParent:y,data:O,deviation:B,footerHeight:o,gap:H,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:z,scrollTo:l,scrollToIndex:D,scrollTop:c,smoothScrollTargetReached:d,totalCount:S,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:w,windowScrollTo:C,windowViewportRect:T,...p,gridState:j,horizontalDirection:ye,initialTopMostItemIndex:F,totalListHeight:te,...h,endReached:Z,propsReady:g,rangeChanged:ke,startReached:ue,stateChanged:R,stateRestoreInProgress:$,...k}},Tt(cl,nn,Mo,nh,fr,dl,ur));function vh(e,t,n){return Do(1,ii((e+n)/(ii(t)+n)))}function wh(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=xl(e,t,n,r[0].index);return{bottom:xl(e,t,n,r[r.length-1].index)+o,top:s}}function xl(e,t,n,r){const o=vh(e.width,n.width,t.column),s=ii(r/o),i=s*n.height+Do(0,s-1)*t.row;return i>0?i+t.row:i}const YS=it(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ml),i=ee("div"),a=ee(no),l=(f,h=null)=>Xt(X(t,pe(p=>p[f]),Et()),h),c=ee(!1),d=ee(!1);return we(Ae(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),XS=it(([e,t])=>({...e,...t}),Tt(GS,YS)),JS=b.memo(function(){const e=Nt("gridState"),t=Nt("listClassName"),n=Nt("itemClassName"),r=Nt("itemContent"),o=Nt("computeItemKey"),s=Nt("isSeeking"),i=kn("scrollHeight"),a=Nt("ItemComponent"),l=Nt("ListComponent"),c=Nt("ScrollSeekPlaceholder"),d=Nt("context"),f=kn("itemDimensions"),h=kn("gap"),p=Nt("log"),m=Nt("stateRestoreInProgress"),g=kn("reportReadyState"),y=Ar(b.useMemo(()=>x=>{const w=x.parentElement.parentElement.scrollHeight;i(w);const C=x.firstChild;if(C){const{height:T,width:k}=C.getBoundingClientRect();f({height:T,width:k})}h({column:Sh("column-gap",getComputedStyle(x).columnGap,p),row:Sh("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return lh(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?null:u.jsx(l,{className:t,ref:y,...Jt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const w=o(x.index,x.data,d);return s?u.jsx(c,{...Jt(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},w):b.createElement(a,{...Jt(a,d),className:n,"data-index":x.index,key:w},r(x.index,x.data,d))})})}),ZS=b.memo(function(){const e=Nt("HeaderComponent"),t=kn("headerHeight"),n=Nt("headerFooterTag"),r=Ar(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,!1),o=Nt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),QS=b.memo(function(){const e=Nt("FooterComponent"),t=kn("footerHeight"),n=Nt("headerFooterTag"),r=Ar(b.useMemo(()=>s=>{t(dr(s,"height"))},[t]),!0,!1),o=Nt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),eC=({children:e})=>{const t=b.useContext(ah),n=kn("itemDimensions"),r=kn("viewportDimensions"),o=Ar(b.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return b.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:si(!1),children:e})},tC=({children:e})=>{const t=b.useContext(ah),n=kn("windowViewportRect"),r=kn("itemDimensions"),o=Nt("customScrollParent"),s=Pf(n,o,!1);return b.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:si(!1),children:e})},nC=b.memo(function({...e}){const t=Nt("useWindowScroll"),n=Nt("customScrollParent"),r=n||t?oC:rC,o=n||t?tC:eC,s=Nt("context");return u.jsx(r,{...e,...Jt(r,s),children:u.jsxs(o,{children:[u.jsx(ZS,{}),u.jsx(JS,{}),u.jsx(QS,{})]})})}),{useEmitter:bh,useEmitterValue:Nt,usePublisher:kn}=sh(XS,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},nC),rC=hh({useEmitter:bh,useEmitterValue:Nt,usePublisher:kn}),oC=ph({useEmitter:bh,useEmitterValue:Nt,usePublisher:kn});function Sh(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,dn.WARN),t==="normal"?0:parseInt(t??"0",10)}const sC=Yo.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ch({className:e,variant:t,...n}){return u.jsx("div",{className:oe(sC({variant:t}),e),...n})}const Lo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Lo.displayName="Card";const Fo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));Fo.displayName="CardHeader";const $o=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));$o.displayName="CardTitle";const kh=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));kh.displayName="CardDescription";const zo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));zo.displayName="CardContent";const Th=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));Th.displayName="CardFooter";const iC=1,aC=1e6;let vl=0;function lC(){return vl=(vl+1)%Number.MAX_SAFE_INTEGER,vl.toString()}const wl=new Map,Eh=e=>{if(wl.has(e))return;const t=setTimeout(()=>{wl.delete(e),Bo({type:"REMOVE_TOAST",toastId:e})},aC);wl.set(e,t)},cC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,iC)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?Eh(n):e.toasts.forEach(r=>{Eh(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},li=[];let ci={toasts:[]};function Bo(e){ci=cC(ci,e),li.forEach(t=>{t(ci)})}function uC({...e}){const t=lC(),n=o=>Bo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Bo({type:"DISMISS_TOAST",toastId:t});return Bo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function bl(){const[e,t]=v.useState(ci);return v.useEffect(()=>(li.push(t),()=>{const n=li.indexOf(t);n>-1&&li.splice(n,1)}),[e]),{...e,toast:uC,dismiss:n=>Bo({type:"DISMISS_TOAST",toastId:n})}}async function Ih(e,t){return await vn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Nh(e,t){return await(await Ih(`/files/${e}/view`,t)).text()}async function dC(e,t){const n=await Ih(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await vn(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function fC(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await vn("/files",{params:r})}function Sl(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function Ah(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Ho(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Ho).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(Ah(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=Ho(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function Uo(e){if(typeof e=="string")return e;if(Ah(e))return"";try{const t=Ho(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function hC(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function pC(e){const t=Uo(e);return typeof e=="string"&&hC(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function ui(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Sl(t);if(n!==null)return ui(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?ui(e.content):e}var di="Dialog",[_h,VT]=Zn(di),[mC,On]=_h(di),jh=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=Kr({prop:r,defaultProp:o??!1,onChange:s,caller:di});return u.jsx(mC,{scope:t,triggerRef:a,contentRef:l,contentId:Qn(),titleId:Qn(),descriptionId:Qn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};jh.displayName=di;var Ph="DialogTrigger",Rh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(Ph,n),s=Je(t,o.triggerRef);return u.jsx(De.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Tl(o.open),...r,ref:s,onClick:ge(e.onClick,o.onOpenToggle)})});Rh.displayName=Ph;var Cl="DialogPortal",[gC,Oh]=_h(Cl,{forceMount:void 0}),Mh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=On(Cl,t);return u.jsx(gC,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(bn,{present:n||s.open,children:u.jsx(Rs,{asChild:!0,container:o,children:i})}))})};Mh.displayName=Cl;var fi="DialogOverlay",Dh=v.forwardRef((e,t)=>{const n=Oh(fi,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=On(fi,e.__scopeDialog);return s.modal?u.jsx(bn,{present:r||s.open,children:u.jsx(xC,{...o,ref:t})}):null});Dh.displayName=fi;var yC=wr.createSlot("DialogOverlay.RemoveScroll"),xC=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(fi,n);return u.jsx(Hs,{as:yC,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(De.div,{"data-state":Tl(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Pr="DialogContent",Lh=v.forwardRef((e,t)=>{const n=Oh(Pr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=On(Pr,e.__scopeDialog);return u.jsx(bn,{present:r||s.open,children:s.modal?u.jsx(vC,{...o,ref:t}):u.jsx(wC,{...o,ref:t})})});Lh.displayName=Pr;var vC=v.forwardRef((e,t)=>{const n=On(Pr,e.__scopeDialog),r=v.useRef(null),o=Je(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),u.jsx(Fh,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ge(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ge(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault())})}),wC=v.forwardRef((e,t)=>{const n=On(Pr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Fh,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Fh=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=On(Pr,n),l=v.useRef(null),c=Je(t,l);return ya(),u.jsxs(u.Fragment,{children:[u.jsx(bs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(ws,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Tl(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(bC,{titleId:a.titleId}),u.jsx(CC,{contentRef:l,descriptionId:a.descriptionId})]})]})}),kl="DialogTitle",$h=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(kl,n);return u.jsx(De.h2,{id:o.titleId,...r,ref:t})});$h.displayName=kl;var zh="DialogDescription",Bh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(zh,n);return u.jsx(De.p,{id:o.descriptionId,...r,ref:t})});Bh.displayName=zh;var Hh="DialogClose",Uh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=On(Hh,n);return u.jsx(De.button,{type:"button",...r,ref:t,onClick:ge(e.onClick,()=>o.onOpenChange(!1))})});Uh.displayName=Hh;function Tl(e){return e?"open":"closed"}var Wh="DialogTitleWarning",[KT,Vh]=Ex(Wh,{contentName:Pr,titleName:kl,docsSlug:"dialog"}),bC=({titleId:e})=>{const t=Vh(Wh),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
86
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function F0(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 $0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),F0(t),L0(t)}const Gs=0,cr=1,eo=2,If=4;function Nf(e){return()=>e}function z0(e){e()}function Af(e,t){return n=>e(t(n))}function _f(e,t){return()=>e(t)}function B0(e,t){return n=>e(t,n)}function Ja(e){return e!==void 0}function H0(...e){return()=>{e.map(z0)}}function to(){}function Ys(e,t){return t(e),e}function U0(e,t){return t(e)}function Tt(...e){return e}function dt(e,t){return e(cr,t)}function $e(e,t){e(Gs,t)}function Za(e){e(eo)}function Mt(e){return e(If)}function we(e,t){return dt(e,B0(t,Gs))}function On(e,t){const n=e(cr,r=>{n(),t(r)});return n}function jf(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Pf(e,t){return e===t}function Et(e=Pf){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=>Af(t,e)}function Vn(e){return t=>()=>{t(e)}}function X(e,...t){const n=W0(...t);return(r,o)=>{switch(r){case eo:Za(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 W0(...e){return t=>e.reduceRight(U0,t)}function V0(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 Gs:t=o;break;case cr:{o(t);break}case If:return t}return n(r,o)}}function Qt(e,t){return Ys(ee(t),n=>we(e,n))}function Ze(){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 xn(e){return Ys(Ze(),t=>we(e,t))}function lt(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:K0(),singleton:n}}const K0=()=>Symbol();function q0(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:{Za(t);return}case cr:return r===o&&i(n),dt(t,i)}}}function Ae(e,t=Pf){return X(e,Et(t))}function Qa(...e){return function(t,n){switch(t){case eo:return;case cr:return H0(...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 G0={0:"debug",3:"error",1:"log",2:"warn"},Y0=()=>typeof globalThis>"u"?window:globalThis,ur=lt(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Y0().VIRTUOSO_LOG_LEVEL)!=null?o:Mt(e);r>=s&&console[G0[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 el(e,t,n).callbackRef}function el(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 X0(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=J0(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?Rf("column-gap",getComputedStyle(d).columnGap,o):Rf("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return el(c,n,l)}function J0(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 Rf(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 Of(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}=el(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 Mf(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)?Ff(t,n,1):t===e.k?Ht(e,{k:t,v:n}):t<e.k?$f(Ht(e,{l:vn(e.l,t,n)})):$f(Ht(e,{r:vn(e.r,t,n)}))}function no(){return No}function Xs(e,t,n){if(xt(e))return[];const r=Mn(e,t)[0];return Z0(nl(e,r,n))}function tl(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]=Lf(r);return Js(Ht(e,{k:s,l:Df(r),v:i}))}}else return t<n?Js(Ht(e,{l:tl(r,t)})):Js(Ht(e,{r:tl(o,t)}))}function jr(e){return xt(e)?[]:[...jr(e.l),{k:e.k,v:e.v},...jr(e.r)]}function nl(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(nl(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(nl(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(rl(t))return zf(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(rl(e))return ol(Ht(e,{lvl:n-1}));if(!xt(r)&&!xt(r.l)){const o=r.l,s=rl(o)?r.lvl-1:r.lvl;return Ht(o,{l:Ht(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ol(Ht(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ht(e,t){return Ff(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 Df(e){return xt(e.r)?e.l:Js(Ht(e,{r:Df(e.r)}))}function rl(e){return xt(e)||e.lvl>e.r.lvl}function Lf(e){return xt(e.r)?[e.k,e.v]:Lf(e.r)}function Ff(e,t,n,r=No,o=No){return{k:e,l:r,lvl:n,r:o,v:t}}function $f(e){return ol(zf(e))}function zf(e){const{l:t}=e;return!xt(t)&&t.lvl===e.lvl?Ht(t,{r:Ht(e,{l:t.r})}):e}function ol(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 Z0(e){return Mf(e,({k:t,v:n})=>({index:t,value:n}))}function Bf(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 sl=lt(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Hf(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 Q0(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!xt(e.groupOffsetTree)}function il({index:e},t){return t===e?0:t<e?-1:1}function eS(){return{groupIndices:[],groupOffsetTree:no(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:no()}}function tS(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=Xs(e,i-1,o+1);if(a.some(lS(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=tl(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 nS(e){return typeof e.groupIndex<"u"}function rS({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}=Hf(t,e,il),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Uf(e,t){if(!Qs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Wf(e,t,n){if(nS(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Uf(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function oS(e,t,n,r=0){return r>0&&(t=Math.max(t,Hf(e,r,il).offset)),Mf(Q0(e,t,n,rS),aS)}function sS(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]=tS(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=al(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 iS(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 Vf(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 al(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Zs(o,t-1,il),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 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 aS(e){return{index:e.index,value:e}}function lS(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 cS={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,cS[S])),h=ee(void 0),p=ee(0),m=eS(),g=Qt(X(n,He(l,e,p),Kn(sS,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+Vf(k,S));else if(k<0){const E=Mt(y);E.length>0&&(k-=Vf(-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,...al(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,...al(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,sl),{singleton:!0});function uS(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Kf=lt(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ze(),i=Ze(),a=xn(X(s,pe(uS)));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])=>Qs(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}),dS=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function qf(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!dS)&&(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=qf(T),{align:R,behavior:V,offset:$}=H,F=E-1,ne=Wf(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,fS(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 fS(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ll(e,t){e==0?t():requestAnimationFrame(()=>{ll(e-1,t)})}function cl(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)||Ja(p))&&!f&&!m),He(l)),([,d])=>{On(o,()=>{$e(c,!0)}),ll(4,()=>{On(r,()=>{$e(a,!0)}),$e(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},Tt(qn,rn,Po,fr),{singleton:!0});function Gf(e,t){return Math.abs(e-t)<1.01}const Oo="up",Mo="down",hS="none",pS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},mS=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(mS),h=Qt(X(Qa(X(Ae(o),Ar(1),Vn(!0)),X(Ae(o),Ar(1),Vn(!1),jf(100))),Et()),!1),p=Qt(X(Qa(X(n,Vn(!0)),X(n,Vn(!1),jf(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}},pS),Et((b,C)=>b&&b.atBottom===C.atBottom))),g=Qt(X(r,Kn((b,{scrollHeight:C,scrollTop:T,viewportHeight:k})=>{if(Gf(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(hS)),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)),ei="top",ti="bottom",Yf="none";function Xf(e,t,n){return typeof e=="number"?n===Oo&&t===ei||n===Mo&&t===ti?e:0:n===Oo?t===ei?e.main:e.reverse:t===ti?e.main:e.reverse}function Jf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ul=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=Yf;const j=Jf(C,ei),_=Jf(C,ti);return p-=b,p+=h+x,m+=h+x,m-=b,p>d+k-j&&(E=Oo),m<d-S+f+_&&(E=Mo),E!==Yf?[Math.max(T-h-Xf(g,ei,E)-j,0),T-S-x+f+Xf(g,ti,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 gS(e,t,n){if(Qs(t)){const r=Uf(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 dl={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:Qf(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:Qf(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function Zf(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=cl(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 Qf(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 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{...dl,totalCount:j};if(S===0&&E===0)return F===0?{...dl,totalCount:j}:Zf(F,P,_,B,O,H||[]);if(xt($))return F>0?null:ni(gS(cl(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 Xs($,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 ni([],ne,j,O,R,B);const Q=z.length>0?z[z.length-1]+1:0,ye=oS(V,S,E,Q);if(ye.length===0)return null;const Pe=j-1,J=Ys([],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 ni(J,ne,j,O,R,B)}),je(S=>S!==null),Et()),dl);we(X(e,je(Ja),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(Bf)));return{endReached:C,initialItemCount:y,itemsRendered:x,listState:b,rangeChanged:k,startReached:T,topItemsIndexes:g,...h}},Tt(qn,Kf,ul,Ro,Po,Do,fr,sl),{singleton:!0}),eh=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}),yS=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,eh),{singleton:!0}),th=lt(()=>({context:ee(null)})),xS=({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,nh=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=xS,done:E,...j}=f,_=Wf(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 rh(e){return e?e==="smooth"?"smooth":"auto":!1}const vS=(e,t)=>typeof e=="function"?rh(e(t)):t&&rh(e),wS=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=vS(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(Qa(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,th,nh)),bS=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=[]])=>Zf(l,c,d,f,h,p))),i),{}),Tt(qn,Ro,Pr,fr),{singleton:!0}),SS=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}),oh=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}),fl=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)),CS=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=iS(m.sizeTree);y&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=C,p({ranges:T,scrollTop:g})}),we(X(d,je(Ja),pe(kS)),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,fl));function kS(e){return{align:"start",index:0,offset:e.scrollTop}}const TS=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 sh(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const ES=sh(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),IS=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&&ES()?$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,sl)),NS=lt(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),Tt(ul,bS,fr,oh,eh,SS,yS,fl,nh,ur,th)),ih=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,CS,wS,Pr,Po,IS,TS,Kf,NS));function AS(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"?w.useLayoutEffect:w.useEffect;function ah(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]=V0(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...C}=y,[T]=w.useState(()=>Ys(q0(e),E=>{l(E,C)})),[k]=w.useState(_f(d,T));ri(()=>{for(const E of i)E in C&&dt(k[E],C[E]);return()=>{Object.values(k).map(Za)}},[C,k,T]),ri(()=>{l(T,C)}),w.useImperativeHandle(x,Nf(c(T)));const S=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(S,{...AS([...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(_f(Mt,x));return ri(()=>dt(x,T=>{T!==b&&C(Nf(T))}),[x,b]),b},g=w.version.startsWith("18")?p:m;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];ri(()=>dt(b,x),[x,b])},useEmitterValue:g,usePublisher:h}}const lh=w.createContext(void 0),ch=w.createContext(void 0),uh=typeof document<"u"?w.useLayoutEffect:w.useEffect;function hl(e){return"self"in e}function _S(e){return"body"in e}function dh(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(_S(y)||hl(y)){const b=hl(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():Oi.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;hl(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)),Gf(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 pl="-webkit-sticky",fh="sticky",ml=sh(()=>{if(typeof document>"u")return fh;const e=document.createElement("div");return e.style.position=pl,e.style.position===pl?pl:fh});function gl(e){return e}const jS=lt(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(gl),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")}}),PS=lt(([e,t])=>({...e,...t}),Tt(ih,jS)),RS=({height:e})=>u.jsx("div",{style:{height:e}}),OS={overflowAnchor:"none",position:ml(),zIndex:1},hh={overflowAnchor:"none"},MS={...hh,display:"inline-block",height:"100%"},ph=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}=X0(n,h,f,e?to:a,p,m,o,g,Oe("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);yl("deviation",O=>{x!==O&&b(O)});const C=Oe("EmptyPlaceholder"),T=Oe("ScrollSeekPlaceholder")||RS,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:OS},d(O.index,c)):w.createElement(S,{...en(S,c),...$S(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?MS:hh},P?l(O.index,O.groupIndex,O.data,c):l(O.index,O.data,c))})})}),DS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},LS={outline:"none",overflowX:"auto",position:"relative"},oi=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),FS={position:ml(),top:0,width:"100%",zIndex:1};function en(e,t){if(typeof e!="string")return{context:t}}function $S(e,t){return{item:typeof e=="string"?void 0:t}}const zS=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}),BS=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 mh({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}=dh(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?LS:DS,...o},tabIndex:0,...i,...en(l,s),children:r})})}function gh({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}=dh(a,c,l,m,h);return uh(()=>{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 HS=({children:e})=>{const t=w.useContext(lh),n=Tn("viewportHeight"),r=Tn("fixedItemHeight"),o=Oe("alignToBottom"),s=Oe("horizontalDirection"),i=w.useMemo(()=>Af(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:oi(o),children:e})},US=({children:e})=>{const t=w.useContext(lh),n=Tn("windowViewportRect"),r=Tn("fixedItemHeight"),o=Oe("customScrollParent"),s=Of(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:oi(i),children:e})},WS=({children:e})=>{const t=Oe("TopItemListComponent")||"div",n=Oe("headerHeight"),r={...FS,marginTop:`${n}px`},o=Oe("context");return u.jsx(t,{style:r,...en(t,o),children:e})},VS=w.memo(function(e){const t=Oe("useWindowScroll"),n=Oe("topItemsIndexes").length>0,r=Oe("customScrollParent"),o=Oe("context");return u.jsxs(r||t?GS:qS,{...e,context:o,children:[n&&u.jsx(WS,{children:u.jsx(ph,{showTopList:!0})}),u.jsxs(r||t?US:HS,{children:[u.jsx(zS,{}),u.jsx(ph,{}),u.jsx(BS,{})]})]})}),{Component:KS,useEmitter:yl,useEmitterValue:Oe,usePublisher:Tn}=ah(PS,{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"}},VS),qS=mh({useEmitter:yl,useEmitterValue:Oe,usePublisher:Tn}),GS=gh({useEmitter:yl,useEmitterValue:Oe,usePublisher:Tn}),YS=KS;Tt(ih,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(gl),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")}})),ml();const yh={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},XS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:xh,floor:si,max:Lo,min:xl,round:vh}=Math;function wh(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function JS(e){return{...XS,items:e}}function ii(e,t){return e&&e.width===t.width&&e.height===t.height}function ZS(e,t){return e&&e.column===t.column&&e.row===t.row}const QS=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(yh),_=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),ll(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(_,ii),Ae(P,ii),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,ZS),Ae(P,ii),Ae(_,ii),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 yh;if(rt===0){const ot=cl(Le,L),on=ot+Math.max(xe-1,0);return JS(wh(ot,on,re))}const Ye=bh(Qe,rt,nt);let Ke,et;Re?G===0&&se===0&&xe>0?(Ke=0,et=xe-1):(Ke=Ye*si((G+Se)/(Ge+Se)),et=Ye*xh((se+Se)/(Ge+Se))-1,et=xl(L-1,Lo(et,Ye-1)),Ke=xl(et,Lo(0,Ke))):(Ke=0,et=-1);const Dt=wh(Ke,et,re),{bottom:St,top:ft}=Sh(Ue,ae,U,Dt),gt=xh(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}=Sh(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(Bf),tr(0)));we(Ce,p.scrollSeekRangeChanged),we(X(D,He(_,P,S,H),pe(([L,G,se,ae,U])=>{const Ue=qf(L),{align:re,behavior:xe,offset:Re}=Ue;let Le=Ue.index;Le==="LAST"&&(Le=ae-1),Le=Lo(0,Le,xl(ae-1,Le));let nt=vl(G,U,se,Le);return re==="end"?nt=vh(nt-G.height+se.height):re==="center"&&(nt=vh(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(ul,rn,Do,oh,fr,fl,ur));function bh(e,t,n){return Lo(1,si((e+n)/(si(t)+n)))}function Sh(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=vl(e,t,n,r[0].index);return{bottom:vl(e,t,n,r[r.length-1].index)+o,top:s}}function vl(e,t,n,r){const o=bh(e.width,n.width,t.column),s=si(r/o),i=s*n.height+Lo(0,s-1)*t.row;return i>0?i+t.row:i}const eC=lt(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(gl),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")}}),tC=lt(([e,t])=>({...e,...t}),Tt(QS,eC)),nC=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:kh("column-gap",getComputedStyle(x).columnGap,p),row:kh("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return uh(()=>{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))})})}),rC=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}),oC=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}),sC=({children:e})=>{const t=w.useContext(ch),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:oi(!1),children:e})},iC=({children:e})=>{const t=w.useContext(ch),n=En("windowViewportRect"),r=En("itemDimensions"),o=Nt("customScrollParent"),s=Of(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:oi(!1),children:e})},aC=w.memo(function({...e}){const t=Nt("useWindowScroll"),n=Nt("customScrollParent"),r=n||t?cC:lC,o=n||t?iC:sC,s=Nt("context");return u.jsx(r,{...e,...en(r,s),children:u.jsxs(o,{children:[u.jsx(rC,{}),u.jsx(nC,{}),u.jsx(oC,{})]})})}),{useEmitter:Ch,useEmitterValue:Nt,usePublisher:En}=ah(tC,{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"}},aC),lC=mh({useEmitter:Ch,useEmitterValue:Nt,usePublisher:En}),cC=gh({useEmitter:Ch,useEmitterValue:Nt,usePublisher:En});function kh(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 uC=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 Th({className:e,variant:t,...n}){return u.jsx("div",{className:oe(uC({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 Eh=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Eh.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 Ih=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));Ih.displayName="CardFooter";const dC=1,fC=1e6;let wl=0;function hC(){return wl=(wl+1)%Number.MAX_SAFE_INTEGER,wl.toString()}const bl=new Map,Nh=e=>{if(bl.has(e))return;const t=setTimeout(()=>{bl.delete(e),Ho({type:"REMOVE_TOAST",toastId:e})},fC);bl.set(e,t)},pC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,dC)};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?Nh(n):e.toasts.forEach(r=>{Nh(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 Ho(e){li=pC(li,e),ai.forEach(t=>{t(li)})}function mC({...e}){const t=hC(),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 Sl(){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:mC,dismiss:n=>Ho({type:"DISMISS_TOAST",toastId:n})}}async function Ah(e,t){return await bn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function _h(e,t){return await(await Ah(`/files/${e}/view`,t)).text()}async function gC(e,t){const n=await Ah(`/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 yC(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await bn("/files",{params:r})}function Cl(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 jh(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(jh(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(jh(e))return"";try{const t=Uo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function xC(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function vC(e){const t=Wo(e);return typeof e=="string"&&xC(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=Cl(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",[Ph,XT]=Jn(ui),[wC,Dn]=Ph(ui),Rh=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(wC,{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})};Rh.displayName=ui;var Oh="DialogTrigger",Mh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(Oh,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":El(o.open),...r,ref:s,onClick:ge(e.onClick,o.onOpenToggle)})});Mh.displayName=Oh;var kl="DialogPortal",[bC,Dh]=Ph(kl,{forceMount:void 0}),Lh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Dn(kl,t);return u.jsx(bC,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Cn,{present:n||s.open,children:u.jsx(Ps,{asChild:!0,container:o,children:i})}))})};Lh.displayName=kl;var di="DialogOverlay",Fh=v.forwardRef((e,t)=>{const n=Dh(di,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Dn(di,e.__scopeDialog);return s.modal?u.jsx(Cn,{present:r||s.open,children:u.jsx(CC,{...o,ref:t})}):null});Fh.displayName=di;var SC=br.createSlot("DialogOverlay.RemoveScroll"),CC=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(di,n);return u.jsx(Bs,{as:SC,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Me.div,{"data-state":El(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Rr="DialogContent",$h=v.forwardRef((e,t)=>{const n=Dh(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(kC,{...o,ref:t}):u.jsx(TC,{...o,ref:t})})});$h.displayName=Rr;var kC=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 La(s)},[]),u.jsx(zh,{...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())})}),TC=v.forwardRef((e,t)=>{const n=Dn(Rr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(zh,{...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()}})}),zh=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 xa(),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":El(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(EC,{titleId:a.titleId}),u.jsx(NC,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Tl="DialogTitle",Bh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(Tl,n);return u.jsx(Me.h2,{id:o.titleId,...r,ref:t})});Bh.displayName=Tl;var Hh="DialogDescription",Uh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(Hh,n);return u.jsx(Me.p,{id:o.descriptionId,...r,ref:t})});Uh.displayName=Hh;var Wh="DialogClose",Vh=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Dn(Wh,n);return u.jsx(Me.button,{type:"button",...r,ref:t,onClick:ge(e.onClick,()=>o.onOpenChange(!1))})});Vh.displayName=Wh;function El(e){return e?"open":"closed"}var Kh="DialogTitleWarning",[JT,qh]=jx(Kh,{contentName:Rr,titleName:Tl,docsSlug:"dialog"}),EC=({titleId:e})=>{const t=qh(Kh),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},IC="DialogDescriptionWarning",NC=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${qh(IC).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},Gh=Rh,AC=Mh,Yh=Lh,fi=Fh,hi=$h,Or=Bh,pi=Uh,Xh=Vh;const _C=Gh,jC=Yh,Jh=v.forwardRef(({className:e,...t},n)=>u.jsx(fi,{ref:n,className:oe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Jh.displayName=fi.displayName;const Zh=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(jC,{children:[u.jsx(Jh,{}),u.jsxs(hi,{ref:r,className:oe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(Or,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Xh,{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"})]})]})]})});Zh.displayName=hi.displayName;const Qh=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Qh.displayName="DialogHeader";const ep=v.forwardRef(({className:e,...t},n)=>u.jsx(Or,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",e),...t}));ep.displayName=Or.displayName;const PC=v.forwardRef(({className:e,...t},n)=>u.jsx(pi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));PC.displayName=pi.displayName;function RC({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}=Sl(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await _h(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 gC(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 _h(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(_C,{open:e,onOpenChange:t,children:u.jsxs(Zh,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Qh,{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(ep,{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 tp(){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=tp();function OC(e){Mr=e}const np=/[&<>"']/,MC=new RegExp(np.source,"g"),rp=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,DC=new RegExp(rp.source,"g"),LC={"&":"&","<":"<",">":">",'"':""","'":"'"},op=e=>LC[e];function tn(e,t){if(t){if(np.test(e))return e.replace(MC,op)}else if(rp.test(e))return e.replace(DC,op);return e}const FC=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function sp(e){return e.replace(FC,(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 $C=/(^|[^\[])\^/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($C,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const zC=/[^\w:]/g,BC=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function ip(e,t,n){if(e){let r;try{r=decodeURIComponent(sp(n)).replace(zC,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!BC.test(n)&&(n=VC(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const mi={},HC=/^[^:]+:\/*[^/]*$/,UC=/^([^:]+:)[\s\S]*$/,WC=/^([^:]+:\/*[^/]*)[\s\S]*$/;function VC(e,t){mi[" "+e]||(HC.test(e)?mi[" "+e]=e+"/":mi[" "+e]=yi(e,"/",!0)),e=mi[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(UC,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(WC,"$1")+t:e+t}const gi={exec:function(){}};function ap(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function yi(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function KC(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 qC(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 lp(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function cp(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 GC(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
|
|
93
|
-
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=
|
|
92
|
+
`)}class Il{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:yi(r,`
|
|
93
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=GC(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:o}}}heading(t){const n=this.rules.block.heading.exec(t);if(n){let r=n[2].trim();if(/#$/.test(r)){const o=yi(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,h,p,m,g=n[1].trim();const y=g.length>1,x={type:"list",raw:"",ordered:y,start:y?+g.slice(0,-1):"",loose:!1,items:[]};g=y?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=y?g:"[*+-]");const 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:ap(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]=ap(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=yi(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=KC(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)),cp(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 cp(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:gi,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:gi,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:gi,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:gi,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};me._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",me.punctuation=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 YC(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 up(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 Il,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)+"["+lp("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)+"["+lp("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,up)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,up))){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,YC)){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 Nl{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:[Z[Ie]?u.jsx(he.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ot,Z[Ie]?" (processing)":""]})]},Ie)}if(Y.type==="interrupt"){const ve=Y,ot=wi((ve==null?void 0:ve.id)??(ve==null?void 0:ve.interrupt_id)),vt=!!(Re&&ot&&ot===Re),It=vt?Fe??(ve==null?void 0:ve.value):ve==null?void 0:ve.value,Ne=ot?{...ve,id:ot,interrupt_id:ot}:ve;return u.jsx(JC,{interruptPart:Ne,onApprove:et,onReject:Mt,disabled:w,isActive:vt,payload:It},Ie)}return null},[ue,Z,et,Mt,F,c,d,O,$,Re,Fe,x,w,re]),dt=b.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(he.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),xt=b.useCallback(()=>{const Y=se.trim().length>0||U.length>0||We.length>0||re.length>0;if(!ne&&We.length>0&&!r)return dt();if(!ne&&!Y&&!r)return null;if(ne)return u.jsx(ek,{message:t,viewMode:z},t.id);if(!ne&&!Q){const Ie=t,ve=u.jsx("div",{className:"space-y-2",children:Ie.content.map((ot,vt)=>u.jsx(Ct,{part:ot,i:vt},vt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ve,u.jsx(XC,{className:G})]}):ve}},[se,U.length,We.length,re.length,r,ne,z,dt,G]),ft=b.useMemo(()=>Q?"Assistant":YC(t),[Q,t]),rt=b.useMemo(()=>Q?[]:Array.isArray(k)?k:[],[k,Q]),rn=b.useMemo(()=>{var Y;return rt.length?j&&rt.some(Ie=>Ie.id===j)?j:((Y=rt[0])==null?void 0:Y.id)??null:null},[j,rt]),Wt=b.useMemo(()=>!rt.length||!S?null:rt.some(Y=>Y.id===S)?S:null,[S,rt])??rn,zt=F==="user"&&rt.length>0&&typeof E=="function",ht=b.useCallback(Y=>{if(!E)return;const Ie=(Y==null?void 0:Y.id)??null,ve=(Y==null?void 0:Y.parentId)??_??null;E(Ie,ve)},[_,E]),Ve=b.useMemo(()=>Wt?rt.findIndex(Y=>Y.id===Wt):-1,[Wt,rt]),Dt=b.useMemo(()=>Ve<0?null:rt[Ve]??null,[Ve,rt]),_t=b.useCallback(Y=>{const Ie=[];if(Y.step!==null&&Ie.push(`Step ${Y.step}`),Y.source&&Ie.push(Y.source),!Y.createdAt)return Ie.length?Ie.join(" • "):Y.id.slice(0,8);let ve="";try{const ot=new Date(Y.createdAt);Number.isNaN(ot.getTime())||(ve=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(ot))}catch{ve=""}return`${ve}`},[]);return ne&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:oe(Ye(),h.container),children:u.jsxs("div",{className:oe(qe(),h.content),children:[(i||a||ne)&&u.jsxs("div",{className:oe("flex items-center justify-between mb-2 pb-2 border-b border-current/10",$&&"mb-1 pb-1",G,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Qe(),a&&ft&&u.jsx("span",{className:oe("font-medium",$?"text-xs":"text-sm"),children:ft}),ne&&u.jsxs(Ch,{variant:"outline",className:oe("text-xs flex items-center gap-1 cursor-pointer select-none",G,"border border-current/40",$&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":z==="expanded",onClick:()=>B(Y=>Y==="expanded"?"preview":"expanded"),onKeyDown:Y=>{(Y.key==="Enter"||Y.key===" ")&&(Y.preventDefault(),B(Ie=>Ie==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:le.name??"Tool Output"}),le.toolCallId&&u.jsx("span",{className:"opacity-70",children:le.toolCallId.slice(0,8)}),z==="expanded"?u.jsx(he.ChevronUp,{className:"h-3 w-3"}):u.jsx(he.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[zt&&Dt&&Ve>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ve>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ve<=0)return;const Y=rt[Ve-1];Y&&ht(Y)},"aria-label":"Previous checkpoint",disabled:Ve<=0,children:u.jsx(he.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[Ve+1," / ",rt.length]}),u.jsx("span",{className:"text-muted-foreground",children:_t(Dt)})]}),u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ve<rt.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ve>=rt.length-1)return;const Y=rt[Ve+1];Y&&ht(Y)},"aria-label":"Next checkpoint",disabled:Ve>=rt.length-1,children:u.jsx(he.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:oe("text-xs opacity-60",G,$&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:oe("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(ct,{variant:"ghost",size:"sm",onClick:()=>Se(),className:oe("h-6 w-6 p-0 hover:bg-foreground/10",G,$&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(he.Copy,{className:oe(P?"text-success":G,$?"h-3 w-3":"h-4 w-4")})})}),F==="user"&&p&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:Ge,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",G,$&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(he.Edit,{className:oe(G,$?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&m&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:nt,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",G,$&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(he.RotateCcw,{className:oe(G,$?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:xt()}),ne&&z==="expanded"&&(le.toolCallId||le.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",$&&"text-xs"),children:[le.name&&u.jsxs("div",{children:["Function: ",le.name]}),le.toolCallId&&u.jsxs("div",{children:["Call ID: ",le.toolCallId]})]}),!(i||a||ne)&&s&&!o&&u.jsxs("div",{className:oe("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(ct,{variant:"ghost",size:"sm",onClick:()=>Se(),className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",$&&"h-5 w-5"),children:u.jsx(he.Copy,{className:oe(P?"text-success":"text-current",$?"h-3 w-3":"h-4 w-4")})}),F==="user"&&p&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:Ge,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",$&&"h-5 w-5"),children:u.jsx(he.Edit,{className:oe("text-current",$?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&m&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:nt,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",$&&"h-5 w-5"),children:u.jsx(he.RotateCcw,{className:oe("text-current",$?"h-3 w-3":"h-4 w-4")})})]})]})}),te&&u.jsx(NC,{isOpen:ke,onClose:L,fileId:te.id,fileName:te.name,mimeType:te.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&hp(e.message)===hp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function pp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:KC,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Uo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Uo(e)})}function JC({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=Uo(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(Lo,{className:oe("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(Fo,{className:"pb-3",children:[u.jsx($o,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(kh,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(zo,{className:"pt-0 pb-3",children:a}),u.jsx(Th,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(ct,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(ct,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function ZC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=bl(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(p=>{a(p),c(!0)},[]),h=b.useCallback(async(p,m,g)=>{var y,x;if(!t){p.preventDefault();return}if(o[g]){p.preventDefault();return}try{const w=String(m.url??""),C=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(C){p.preventDefault();const T=C[1],k=m.name||`file_${T}`,S=m.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:S});return}if(w.startsWith("data:")){p.preventDefault(),s(k=>({...k,[g]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await fC(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const S=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(S!=null&&S.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!S.id||!S.filename)throw new Error("Invalid file data received from server");f({id:S.id,name:m.name||S.filename||`file_${S.id}`,mimeType:m.mimeType||S.mime_type||"application/octet-stream"}),(y=T.update)==null||y.call(T,{id:T.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const S=k instanceof Error?k.message:"Unknown error occurred";(x=T.update)==null||x.call(T,{id:T.id,title:"Failed",description:S}),r({title:"Failed to fetch file",description:S,open:!0})}finally{s(k=>({...k,[g]:!1}))}}}catch(w){console.error("File click error:",w),s(C=>({...C,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function QC({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:oe("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(Wo,{content:e,allowHtml:!1}):u.jsxs("pre",{className:oe("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(ct,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(he.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(he.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function ek({message:e,viewMode:t}){const r=fp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Sl(c)??c:c;if(d&&typeof d=="object")return u.jsx(pp,{data:d});const f=typeof d=="string"?d:(()=>{try{return Uo(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=pC(c);return f?u.jsx(Wo,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(he.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=ui(d);return s(f)}const a=Ho(i),l=ui(a);return s(l)}const mp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,tk=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},Al=b.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:m=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:w,disableInterruptActions:C=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:S=!0,checkpointMetaById:E,checkpointIndexByKey:j,activeCheckpointId:_,onSelectCheckpoint:P,timelineCheckpoints:D},z)=>{const B=b.useRef(null),O=b.useRef(null),H=b.useRef(!1),[R,V]=b.useState(!0),$=b.useMemo(()=>w?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===w.id)):!1,[w,e]),F=b.useMemo(()=>{if(!w||$)return null;const re=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let xe;const Re=w.value;if(Re&&typeof Re=="object"&&!Array.isArray(Re)){const Fe=Re.title;typeof Fe=="string"&&Fe.trim()&&(xe=Fe.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Re,title:xe}]}},[w,$]),ne=b.useMemo(()=>F?[...e,F]:e,[e,F]),Q=b.useMemo(()=>S?ne:ne.filter(re=>(re==null?void 0:re.role)!=="tool"),[ne,S]),ye=b.useMemo(()=>{const re=new Set,xe=[];for(let Re=Q.length-1;Re>=0;Re--){const Fe=Q[Re];if(!Fe)continue;if("type"in Fe&&Fe.type==="default_message"){xe.push(Fe);continue}const tt=Fe,Se=tk(tt);re.has(Se)||(re.add(Se),xe.push(tt))}return xe.reverse()},[Q]),Pe=b.useCallback(re=>{V(re),y&&y(!re),x&&x(re)},[y,x]),Z=b.useMemo(()=>{if(a)return async()=>{if(!H.current){H.current=!0;try{await a()}finally{H.current=!1}}}},[a]),ue=b.useMemo(()=>!m||g?!1:R?"auto":!1,[R,m,g]),ke=b.useMemo(()=>D??[],[D]),te=_??(ke.length?ke[ke.length-1].id:null),L=ke.length>0,G=b.useMemo(()=>{if(typeof p!="string")return null;const re=p.trim();return re?{id:"default-message",role:"assistant",type:"default_message",content:re,createdAt:new Date().toISOString()}:null},[p]),se=L?u.jsxs("div",{className:"hidden w-48 flex-shrink-0 flex-col border-r border-border/40 pr-4 md:flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-5 pb-5 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative z-50",children:[u.jsx(he.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-56 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.'})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-5 top-0 bottom-0 w-px bg-border/50"}),u.jsx("div",{className:"flex flex-col gap-4",children:ke.map(re=>{const xe=te===re.id;return u.jsxs("button",{type:"button",disabled:!P,onClick:()=>P==null?void 0:P(re.id),className:`relative flex items-start gap-3 text-left text-xs transition ${xe?"text-primary":"text-muted-foreground"} ${P?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-4 w-4 items-center justify-center rounded-full border ${xe?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${xe?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:re.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[re.step!==null?`STEP ${re.step}`:"STEP —",re.next?` - ${re.next}`:""]})]})]},re.id)})})]}),P&&u.jsx("button",{type:"button",onClick:()=>P==null?void 0:P(null),className:"mt-auto rounded-md border border-border/70 px-3 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null,le=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),U=()=>G?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Nl,{message:G,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:p??"No messages yet. Start a conversation!"}),We=ye.length>0;return b.useImperativeHandle(z,()=>({scrollToLatest:()=>{var re,xe;if(B.current&&ye.length>0){const Re=ye.length-1;(xe=(re=B.current).scrollToIndex)==null||xe.call(re,{index:Re,align:"end",behavior:"auto"})}else O.current&&(O.current.scrollTop=O.current.scrollHeight)},scrollToTop:()=>{var re,xe;B.current&&ye.length>0?(xe=(re=B.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):O.current&&(O.current.scrollTop=0)}}),[ye]),u.jsxs("div",{className:le,style:h,children:[se,u.jsx("div",{className:"relative flex-1 min-h-0",children:We?u.jsx(WS,{ref:re=>{B.current=re},scrollerRef:re=>{O.current=re instanceof HTMLDivElement?re:null},data:ye,followOutput:ue,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{Z&&Z()},atBottomStateChange:Pe,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>mp(xe,re),itemContent:(re,xe)=>{var et;const Re=mp(xe,re),Fe="type"in xe&&xe.type==="default_message";let tt=[],Se=null,Ge={},nt={},Qe=null,Ye=null;if(!Fe){const Mt=xe,Ct=Mt.checkpointId??null;Ge=Mt.additionalKwargs??{},nt=Mt.responseMetadata??{};const dt=Ct&&E?E.get(Ct)??null:null;Qe=typeof Ge.step=="number"?Ge.step:typeof nt.step=="number"?nt.step:(dt==null?void 0:dt.step)??null;const xt=typeof Ge.source=="string"?Ge.source:typeof nt.source=="string"?nt.source:(dt==null?void 0:dt.source)??null;Ye=xt?String(xt):null;const ft=Qe!==null&&Ye?`${Qe}:${Ye}`:null;ft&&(j!=null&&j.has(ft))?tt=j.get(ft)??[]:Ct&&dt&&(tt=[dt]),Se=Ct??((et=tt[0])==null?void 0:et.id)??null}const qe=(()=>{if(typeof Ge.parentCheckpointId=="string")return Ge.parentCheckpointId;if(typeof nt.parentCheckpointId=="string")return nt.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":Re,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Nl,{message:xe,messageIndex:re,isStreamingMessage:t&&n===xe.id,streamingDebounceMs:r,isEditing:i===xe.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(re),onCancelEdit:d,activeInterrupt:w,disableInterruptActions:C,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:S,checkpointCandidates:tt,activeCheckpointId:_??null,onSelectCheckpoint:P,defaultCheckpointId:Se,messageParentCheckpointId:qe})})}}):U()})]})});Al.displayName="MessageList";const gp={value:""};function bi({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,customStyles:f={},onMessageSent:h,onExcelUploadSuccess:p,onError:m}){const{api:g}=Xi(),{currentThreadId:y}=gs(),{threadId:x,messages:w,hasMore:C,isHistoryLoading:T,isLoading:k,loadOlder:S,navigateToCheckpoint:E,returnToLatest:j,checkpoint:_,checkpoints:P,interrupt:D,metadata:z}=ys(),{isStreaming:B,error:O,connectionState:H,submit:R,stop:V}=fu(),$=x??y??null,F=(_==null?void 0:_.id)??null,ne=(_==null?void 0:_.namespace)??null,Q=(z==null?void 0:z.assemblingMessageId)??null,ye=D,[Pe,Z]=b.useState(!1);b.useEffect(()=>{ye||Z(!1)},[ye]);const ue=b.useCallback(()=>{Z(!0)},[]),ke=b.useCallback(()=>{Z(!1)},[]),te=!!ye||Pe,[L,G]=b.useState(null),[se,le]=b.useState(""),[U,We]=b.useState(null),[re,xe]=b.useState(null),[Re,Fe]=b.useState([]),[tt,Se]=b.useState(0),[Ge,nt]=b.useState(0),[Qe,Ye]=b.useState(!1),[qe,et]=b.useState(null),[Mt,Ct]=b.useState(null),[dt,xt]=b.useState(!1),[ft,rt]=b.useState(null),[rn,on]=b.useState(!1),Wt=b.useRef(!1),[zt,ht]=b.useState(()=>gp.value),Ve=b.useRef(zt),Dt=b.useRef(null),_t=b.useCallback(J=>{gp.value=J,ht(J)},[]),[Y,Ie]=b.useState(!1),ve=b.useRef(null),ot=b.useCallback(J=>{if(!Array.isArray(J))return{text:null,messageId:null};for(let ce=J.length-1;ce>=0;ce--){const ie=J[ce];if(!ie||ie.role!=="user")continue;const Te=(ie.content??[]).filter(Ke=>(Ke==null?void 0:Ke.type)==="text").map(Ke=>Ke.text).filter(Ke=>typeof Ke=="string"&&Ke.trim().length>0);return{text:Te.length?Te.join(" ").trim():null,messageId:ie.id??null}}return{text:null,messageId:null}},[]),vt=b.useCallback((J,ce)=>{if(!J||typeof J!="object")return null;const ie=J[ce];return typeof ie=="number"?ie:null},[]),It=b.useCallback((J,ce)=>{if(!J||typeof J!="object")return null;const ie=J[ce];return typeof ie=="string"&&ie.trim()?ie:null},[]),Ne=b.useMemo(()=>{const J=Te=>{if(!Array.isArray(Te)||Te.length===0)return null;const gt=Te.map(Ke=>{if(typeof Ke=="string")return Ke.trim();if(Ke&&typeof Ke=="object"&&"type"in Ke){const st=Ke;if(typeof st.type=="string")return st.type}return null}).filter(Ke=>!!(Ke&&Ke.length));return gt.length?gt.join(", "):null},ce=Array.isArray(P)?P.map(Te=>{const gt=J(Te.next);return gt?{...Te,metadata:{...Te.metadata??{},next:gt}}:Te}):[];return ce.some(Te=>vt(Te.metadata,"step")!==null)&&ce.sort((Te,gt)=>{const Ke=vt(Te.metadata,"step"),st=vt(gt.metadata,"step");if(Ke!==null||st!==null)return(st??Number.NEGATIVE_INFINITY)-(Ke??Number.NEGATIVE_INFINITY);const Ht=Date.parse(Te.createdAt??""),fn=Date.parse(gt.createdAt??"");return Number.isNaN(Ht)||Number.isNaN(fn)?0:fn-Ht}),ce},[P,vt]),{checkpointMetaById:Qt,checkpointIndexByKey:at}=b.useMemo(()=>{const J=new Map,ce=new Map;for(const ie of Ne){const Te=ie.checkpointId??null;if(!Te)continue;const gt=vt(ie.metadata,"step"),Ke=It(ie.metadata,"source"),st={id:Te,step:gt,source:Ke,createdAt:ie.createdAt??null,namespace:ie.checkpointNs??null,parentId:ie.parentId??null};if(J.set(Te,st),gt!==null&&Ke){const Ht=`${gt}:${Ke}`,fn=ce.get(Ht)??[];fn.push(st),ce.set(Ht,fn)}}for(const ie of ce.values())ie.sort((Te,gt)=>{const Ke=Te.createdAt??"";return(gt.createdAt??"").localeCompare(Ke)});return{checkpointMetaById:J,checkpointIndexByKey:ce}},[Ne,vt,It]),Xe=b.useMemo(()=>{var Ke;if(!Ne.length)return[];const J=[...Ne].reverse(),ce=(st,Ht)=>{const fn=st.checkpointId??null;if(!fn)return null;const Gn=It(st.metadata,"source");It(st.metadata,"next");const{text:qo,messageId:Pi}=ot(st.messages),ao=qo&&qo.replace(/\s+/g," ").trim()||It(st.metadata,"title")||It(st.metadata,"label")||Ht||Gn||"Checkpoint",Yn=ao.length>60?`${ao.slice(0,57)}…`:ao;return{id:fn,label:Yn,messageId:Pi??null,createdAt:st.createdAt??null,step:vt(st.metadata,"step"),source:Gn??null,next:It(st.metadata,"next")}},ie=[],Te=new Set;for(const st of J){const Ht=((Ke=It(st.metadata,"source"))==null?void 0:Ke.toLowerCase())??null;if(!(Ht==="input"||Ht==="user_input"||Ht==="user"))continue;const Gn=ce(st,"User input");Gn&&!Te.has(Gn.id)&&(ie.push(Gn),Te.add(Gn.id))}if(!ie.length)for(const st of J){const Ht=ce(st);Ht&&!Te.has(Ht.id)&&(ie.push(Ht),Te.add(Ht.id))}const gt=Ne.find(st=>{var fn;return(((fn=It(st.metadata,"source"))==null?void 0:fn.toLowerCase())??null)==="loop"});if(gt){const st=ce(gt,"Latest loop");st&&!Te.has(st.id)&&(ie.push(st),Te.add(st.id))}return ie},[Ne,ot,vt,It]),sn=b.useRef(null),qn=b.useRef(null),jt=b.useCallback(()=>{sn.current&&(sn.current.value=""),qn.current&&(qn.current.value=""),Se(J=>J+1),nt(J=>J+1)},[]),rr=b.useCallback(J=>{_t(J)},[_t]),Fr=b.useRef(!1);b.useEffect(()=>{Fr.current&&!B&&(Fe([]),jt()),Fr.current=B},[B,jt]);const[Ko,$r]=b.useState("desktop");b.useEffect(()=>{const J=()=>{const ce=window.innerWidth;$r(ce<640?"phone":ce<1024?"tablet":"desktop")};return J(),window.addEventListener("resize",J),()=>window.removeEventListener("resize",J)},[]),b.useEffect(()=>{on(!1),Wt.current=!1},[$]),b.useEffect(()=>{Ve.current=zt},[zt]),b.useEffect(()=>{if(!L){Dt.current=null;return}Dt.current===null&&(Dt.current=Ve.current),_t(se??"")},[se,L,_t]);const N=b.useCallback(async()=>{if(!(!C||T||!rn))try{await S()}catch(J){console.warn("loadOlder failed",J)}},[C,rn,T,S]);b.useEffect(()=>{(async()=>{if(!g.baseUrl){rt(null);return}try{const ie=(await g.getAgent("default")).uiDefaultMessage||"";rt(ie||null)}catch(ce){console.warn("Failed to fetch default message:",ce),rt(null)}})()},[g.baseUrl]),b.useEffect(()=>{O&&!dt&&(m==null||m(O))},[O,dt,m]);const q=J=>{if(J.length>Gs)return`Message too long (${J.length}/${Gs} characters)`;try{return O0(J),null}catch(ce){return(ce==null?void 0:ce.message)||"Invalid message"}},de=async J=>{const ce=J.trim();if(!(!ce&&Re.length===0)){if(ce){const ie=q(ce);if(ie){xe(ie);return}}try{const ie=F??void 0,Te=ne??void 0,gt=L?{edit:!0,originalMessageId:L,...U!=null&&U.checkpointId?{originalCheckpointId:U.checkpointId}:{},...U!=null&&U.checkpointNs?{originalCheckpointNs:U.checkpointNs}:{}}:void 0;await R({text:ce||"",attachments:Re,messageAdditionalKwargs:gt},{checkpointId:ie,checkpointNs:Te}),h==null||h(ce),_t(""),xe(null),Fe([]),jt(),G(null),le(""),We(null)}catch(ie){const Te=(ie==null?void 0:ie.message)||"Failed to send message";xe(Te),m==null||m(Te)}}},Ce=b.useCallback((J,ce,ie)=>{c&&(Dt.current=zt,G(J),le(ce),_t(ce),xe(null),We({checkpointId:(ie==null?void 0:ie.checkpointId)??null,checkpointNs:(ie==null?void 0:ie.checkpointNs)??null}))},[zt,c,_t]),He=b.useCallback(()=>{G(null),le(""),We(null),xe(null),_t(Dt.current??zt),Dt.current=null},[zt,_t]),lt=b.useCallback((J,ce,ie)=>{Ce(J,ce,ie)},[Ce]),Oe=b.useCallback(J=>{for(let ce=J-1;ce>=0;ce--)if(w[ce].role==="user"){const ie=w[ce].content||[],gt=ie.filter(Ke=>Ke.type==="text").map(Ke=>Ke.text).join("")||(()=>{try{return JSON.stringify(ie,null,2)}catch{return String(ie)}})();gt&&R({text:gt},{checkpointId:F??void 0,checkpointNs:ne??void 0});break}},[w,R,F,ne]),$e=J=>{const ce=Array.from(J.target.files||[]);Fe(ie=>[...ie,...ce]),J.target.value=""},At=J=>{Fe(ce=>{const ie=ce.filter((Te,gt)=>J!==gt);return ie.length===0&&jt(),ie})},pt=async J=>{const ce=(J.target.files||[])[0];if(ce){et(null),Ct(null),Ye(!0);try{await R({attachments:[ce]},{checkpointId:F??void 0,checkpointNs:ne??void 0});const ie=`Uploaded ${ce.name} - processing through chat stream`;Ct(ie)}catch(ie){const Te=ie instanceof Error?ie.message:"Failed to upload Excel file";console.error("Excel upload failed",ie),et(Te),m==null||m(Te)}finally{Ye(!1),J.target.value="",jt()}}},mt=async J=>{if(y){Ie(!0);try{if(!J){await j(),on(!1),requestAnimationFrame(()=>{var Te;(Te=ve.current)==null||Te.scrollToLatest()});return}const ce=Ne.find(Te=>Te.checkpointId===J),ie=(ce==null?void 0:ce.checkpointNs)??null;await E(J,ie),on(!0),requestAnimationFrame(()=>{var Te;(Te=ve.current)==null||Te.scrollToTop()})}finally{Ie(!1)}}},en=b.useCallback(async J=>{await mt(J)},[mt]),Dn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,In=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${f.messagesArea||""}`,Lt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,xr=b.useCallback(J=>{if(!J)return"Latest";const ce=[];J.step!==null&&ce.push(`Step ${J.step}`),J.source&&ce.push(J.source);const ie=J.createdAt?new Date(J.createdAt):null,Te=ie&&!Number.isNaN(ie.getTime())?ie.toLocaleString():J.createdAt??J.id,gt=ce.length?` — ${ce.join(" • ")}`:"";return`${Te}${gt}`},[]);return u.jsxs("div",{className:Dn,children:[!!O&&!dt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:O}),u.jsx(ct,{variant:"ghost",size:"sm",onClick:()=>xt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(he.X,{size:16})})]}),y&&Ne.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:F??"",onChange:J=>{const ce=J.target.value||null;mt(ce)},children:[u.jsx("option",{value:"",children:"Latest"}),Ne.map(J=>{const ce=Qt.get(J.checkpointId??"")??null;return u.jsx("option",{value:J.checkpointId??void 0,children:xr(ce)},J.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${In}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Al,{ref:ve,className:"h-full",style:{height:"100%"},messages:w,isStreaming:B,streamingAssistantId:Q,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Ko,enableMessageEditing:c,editingMessageId:L,onStartReached:()=>{rn&&N()},onScrollAway:J=>{if(!Wt.current){Wt.current=!0;return}J&&on(!0)},onEdit:lt,onRegenerate:Oe,onCancelEdit:He,emptyMessage:ft??void 0,isNavigatingCheckpoint:Y,activeInterrupt:ye,disableInterruptActions:Pe,onInterruptActionStart:ue,onInterruptActionEnd:ke,showToolMessages:d,checkpointMetaById:Qt,checkpointIndexByKey:at,activeCheckpointId:F,onSelectCheckpoint:en,timelineCheckpoints:Xe}),(H==="reconnecting"||H==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(he.Loader2,{className:"h-3 w-3 animate-spin"}),H==="reconnecting"?"Reconnecting…":"Connecting…"]})}),H==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),k&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(he.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),u.jsxs("div",{className:Lt,children:[L&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(he.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(ct,{variant:"ghost",size:"sm",onClick:He,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(he.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:sn,type:"file",multiple:!0,onChange:J=>$e(J),className:"hidden"},tt),Re.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Re.map((J,ce)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(he.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:J.name}),u.jsx(ct,{variant:"ghost",size:"sm",onClick:()=>At(ce),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${J.name}`,children:u.jsx(he.X,{size:12})})]},ce))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:qn,type:"file",accept:".xls,.xlsx,.xlsm",onChange:pt,className:"hidden"},Ge),Qe&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(he.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Mt&&!Qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Mt}),qe&&!Qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:qe})]})]}),re&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:re}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(k0,{children:[u.jsx(T0,{asChild:!0,children:u.jsx(ct,{type:"button",size:"icon",variant:"outline",disabled:B||te,title:"More input actions",className:f.moreButton||"",children:u.jsx(he.Plus,{size:16})})}),u.jsxs(kf,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ya,{onClick:()=>{var J;return(J=sn.current)==null?void 0:J.click()},className:"cursor-pointer",children:[u.jsx(he.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Ya,{onClick:()=>{var J;Qe||(J=qn.current)==null||J.click()},className:`cursor-pointer ${Qe?"opacity-60 pointer-events-none":""}`,children:[u.jsx(he.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(Tx,{initialValue:se,editingMessageId:L,value:zt,onValueChange:rr,placeholder:L?"Edit your message...":t,isStreaming:B,disabled:te,maxLength:Gs,onSend:de,onCancelEdit:He,onStop:V,allowEmptySend:Re.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${L?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${re?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const Si=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:oe("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Si.displayName="Input";function _l(e,[t,n]){return Math.min(n,Math.max(t,e))}function nk(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var jl="ScrollArea",[yp,qT]=Zn(jl),[rk,Tn]=yp(jl),xp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,h]=v.useState(null),[p,m]=v.useState(null),[g,y]=v.useState(null),[x,w]=v.useState(0),[C,T]=v.useState(0),[k,S]=v.useState(!1),[E,j]=v.useState(!1),_=Je(t,D=>l(D)),P=vs(o);return u.jsx(rk,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:k,onScrollbarXEnabledChange:S,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:w,onCornerHeightChange:T,children:u.jsx(De.div,{dir:P,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});xp.displayName=jl;var vp="ScrollAreaViewport",wp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Tn(vp,n),a=v.useRef(null),l=Je(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(De.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});wp.displayName=vp;var Kn="ScrollAreaScrollbar",Pl=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Tn(Kn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(ok,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(sk,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(bp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Rl,{...r,ref:t}):null});Pl.displayName=Kn;var ok=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Tn(Kn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(bn,{present:n||s,children:u.jsx(bp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),sk=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Tn(Kn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ei(()=>l("SCROLL_END"),100),[a,l]=nk("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(bn,{present:n||a!=="hidden",children:u.jsx(Rl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),bp=v.forwardRef((e,t)=>{const n=Tn(Kn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ei(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return oo(n.viewport,l),oo(n.content,l),u.jsx(bn,{present:r||s,children:u.jsx(Rl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Rl=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Tn(Kn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Ep(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return dk(h,i.current,a,p)}return n==="horizontal"?u.jsx(ik,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Ip(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(ak,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Ip(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),ik=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Tn(Kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Je(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Cp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ti(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),Ap(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:ki(i.paddingLeft),paddingEnd:ki(i.paddingRight)}})}})}),ak=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Tn(Kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Je(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Cp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ti(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),Ap(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:ki(i.paddingTop),paddingEnd:ki(i.paddingBottom)}})}})}),[lk,Sp]=yp(Kn),Cp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...h}=e,p=Tn(Kn,n),[m,g]=v.useState(null),y=Je(t,_=>g(_)),x=v.useRef(null),w=v.useRef(""),C=p.viewport,T=r.content-r.viewport,k=Gt(d),S=Gt(l),E=Ei(f,10);function j(_){if(x.current){const P=_.clientX-x.current.left,D=_.clientY-x.current.top;c({x:P,y:D})}}return v.useEffect(()=>{const _=P=>{const D=P.target;(m==null?void 0:m.contains(D))&&k(P,T)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[C,m,T,k]),v.useEffect(S,[r,S]),oo(m,E),oo(p.content,E),u.jsx(lk,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Gt(s),onThumbPointerUp:Gt(i),onThumbPositionChange:S,onThumbPointerDown:Gt(a),children:u.jsx(De.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=m.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),j(_))}),onPointerMove:ge(e.onPointerMove,j),onPointerUp:ge(e.onPointerUp,_=>{const P=_.target;P.hasPointerCapture(_.pointerId)&&P.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=w.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),Ci="ScrollAreaThumb",kp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Sp(Ci,e.__scopeScrollArea);return u.jsx(bn,{present:n||o.hasThumb,children:u.jsx(ck,{ref:t,...r})})}),ck=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Tn(Ci,n),i=Sp(Ci,n),{onThumbPositionChange:a}=i,l=Je(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ei(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=fk(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(De.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ge(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:ge(e.onPointerUp,i.onThumbPointerUp)})});kp.displayName=Ci;var Ol="ScrollAreaCorner",Tp=v.forwardRef((e,t)=>{const n=Tn(Ol,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(uk,{...e,ref:t}):null});Tp.displayName=Ol;var uk=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Tn(Ol,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return oo(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),oo(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(De.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function ki(e){return e?parseInt(e,10):0}function Ep(e,t){const n=e/t;return isNaN(n)?0:n}function Ti(e){const t=Ep(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function dk(e,t,n,r="ltr"){const o=Ti(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Np([l,c],f)(e)}function Ip(e,t,n="ltr"){const r=Ti(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=_l(e,l);return Np([0,i],[0,a])(c)}function Np(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Ap(e,t){return e>0&&e<t}var fk=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Ei(e,t){const n=Gt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function oo(e,t){const n=Gt(t);qt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var _p=xp,hk=wp,pk=Tp;const jp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_p,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(hk,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Pp,{}),u.jsx(pk,{})]}));jp.displayName=_p.displayName;const Pp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pl,{ref:r,orientation:t,className:oe("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(kp,{className:"relative flex-1 rounded-full bg-border"})}));Pp.displayName=Pl.displayName;const Rp=25;function Ml({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:h,isLoading:p,actions:m}=gs(),{loadThread:g}=ys(),{createThread:y,deleteThread:x,renameThread:w}=m,[C,T]=b.useState(Array.isArray(f)?f:[]),k=b.useRef(C.length>0),S=b.useRef(null),E=b.useRef(0),[j,_]=b.useState(null),[P,D]=b.useState(""),[z,B]=b.useState(!1);b.useEffect(()=>{const Z=Array.isArray(f)?f:[];if(Z.length>0){k.current=!0,T(Z);return}p||(k.current=!1,T(Z))},[f,p]),b.useEffect(()=>{if(!S.current)return;const Z=S.current.querySelector("[data-radix-scroll-area-viewport]");if(!Z)return;let ue=null,ke=null;return ue=requestAnimationFrame(()=>{ke=requestAnimationFrame(()=>{Z.scrollTop=E.current})}),()=>{ue!==null&&cancelAnimationFrame(ue),ke!==null&&cancelAnimationFrame(ke)}},[C]);const O=async Z=>{try{await g(Z),a==null||a(Z),l==null||l(Z)}catch(ue){console.error("Failed to select thread:",ue)}},H=async()=>{try{B(!0);const Z=await y();c==null||c(Z),a==null||a(Z)}catch(Z){console.error("Failed to create thread:",Z)}finally{B(!1)}},R=async(Z,ue)=>{if(ue.stopPropagation(),!!confirm("Delete this thread?")){if(S.current){const ke=S.current.querySelector("[data-radix-scroll-area-viewport]");ke&&(E.current=ke.scrollTop)}try{await x(Z),d==null||d(Z)}catch(ke){console.error("Failed to delete thread:",ke)}}},V=(Z,ue)=>{ue.stopPropagation(),_(Z.threadId),D(Z.title||`Thread ${Z.threadId.slice(0,8)}`)},$=async Z=>{if(P.trim())try{await w(Z,P.trim()),_(null),D("")}catch(ue){console.error("Failed to update title:",ue)}},F=()=>{_(null),D("")},ne=(Z,ue)=>{Z.key==="Enter"?$(ue):Z.key==="Escape"&&F()},Q=Z=>{if(!Z)return"";try{const ue=new Date(Z),te=new Date().getTime()-ue.getTime(),L=Math.floor(te/(1e3*60*60*24));return L===0?ue.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):L===1?"Yesterday":L<7?`${L} days ago`:ue.toLocaleDateString()}catch{return""}},ye=Z=>Z.title||`Thread ${Z.threadId.slice(0,8)}`,Pe=Z=>{const ue=ye(Z);return ue.length<=Rp?ue:`${ue.slice(0,Rp)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(ct,{onClick:H,disabled:z||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:z?"Creating...":"New Chat",children:u.jsx(he.MessageSquarePlus,{size:20})})}),u.jsx(jp,{ref:S,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:p?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(he.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):C.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(he.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):C.slice().sort((Z,ue)=>new Date(ue.updatedAt||ue.createdAt||"").getTime()-new Date(Z.updatedAt||Z.createdAt||"").getTime()).map(Z=>u.jsxs("div",{onClick:()=>O(Z.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===Z.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:j===Z.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ue=>ue.stopPropagation(),children:[u.jsx(Si,{value:P,onChange:ue=>D(ue.target.value),onKeyDown:ue=>ne(ue,Z.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(ct,{variant:"ghost",size:"sm",onClick:()=>$(Z.threadId),className:"h-6 w-6 p-0",children:u.jsx(he.Check,{size:12})}),u.jsx(ct,{variant:"ghost",size:"sm",onClick:F,className:"h-6 w-6 p-0",children:u.jsx(he.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Pe(Z)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(he.Calendar,{size:10}),u.jsx("span",{children:Q(Z.updatedAt||Z.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&j!==Z.threadId&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:ue=>V(Z,ue),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(he.Edit3,{size:12})}),n&&u.jsx(ct,{variant:"ghost",size:"sm",onClick:ue=>R(Z.threadId,ue),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(he.Trash2,{size:12})})]})]}),i===Z.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Z.threadId))})})]})}function so(e){if(!(typeof globalThis>"u"))return globalThis[e]}function mk(e){if(typeof e!="string")return;const t=e.trim();if(t)return Jn(t)}function Op(){const e=[so("__API_BASE_URL__"),so("__CHAT_API_BASE_URL__"),so("__CHAT_API_URL__")];for(const t of e){const n=mk(t);if(n)return n}}function Mp(){const e=[so("__API_AUTH_TOKEN__"),so("__CHAT_API_KEY__"),so("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Dp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Jn(t);return Jn()}function Lp(){const e={},t=Op(),n=Mp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Fp(){const e=Lp(),t=sr.getAuthToken(),n=Op();return{apiBaseUrl:Dp(e.baseUrl,sr.baseUrl,n),apiKey:t||e.apiKey||Mp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const $p="chat-settings";function gk(){try{const e=localStorage.getItem($p);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function yk(e){try{const t={...e,apiBaseUrl:Jn(e.apiBaseUrl)};localStorage.setItem($p,JSON.stringify(t)),t.apiKey&&sr.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function xk(){const e=Fp(),t=gk(),n=sr.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Dp(sr.baseUrl,r,e.apiBaseUrl)}}function vk(e){sr.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),yk(e)}var wk="Label",zp=v.forwardRef((e,t)=>u.jsx(De.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));zp.displayName=wk;var Bp=zp;const bk=Yo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),En=v.forwardRef(({className:e,...t},n)=>u.jsx(Bp,{ref:n,className:oe(bk(),e),...t}));En.displayName=Bp.displayName;function Hp(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Ii="Switch",[Sk,GT]=Zn(Ii),[Ck,kk]=Sk(Ii),Up=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[h,p]=v.useState(null),m=Je(t,C=>p(C)),g=v.useRef(!1),y=h?d||!!h.closest("form"):!0,[x,w]=Kr({prop:o,defaultProp:s??!1,onChange:c,caller:Ii});return u.jsxs(Ck,{scope:n,checked:x,disabled:a,children:[u.jsx(De.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":qp(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ge(e.onClick,C=>{w(T=>!T),y&&(g.current=C.isPropagationStopped(),g.current||C.stopPropagation())})}),y&&u.jsx(Kp,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Up.displayName=Ii;var Wp="SwitchThumb",Vp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=kk(Wp,n);return u.jsx(De.span,{"data-state":qp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Vp.displayName=Wp;var Tk="SwitchBubbleInput",Kp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Je(i,s),l=Hp(n),c=Xu(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const m=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(m)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Kp.displayName=Tk;function qp(e){return e?"checked":"unchecked"}var Gp=Up,Ek=Vp;const mr=v.forwardRef(({className:e,...t},n)=>u.jsx(Gp,{className:oe("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(Ek,{className:oe("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));mr.displayName=Gp.displayName;var Yp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),Ik="VisuallyHidden",Nk=v.forwardRef((e,t)=>u.jsx(De.span,{...e,ref:t,style:{...Yp,...e.style}}));Nk.displayName=Ik;var Ak=[" ","Enter","ArrowUp","ArrowDown"],_k=[" ","Enter"],Mr="Select",[Ni,Ai,jk]=pa(Mr),[io,YT]=Zn(Mr,[jk,Ps]),_i=Ps(),[Pk,gr]=io(Mr),[Rk,Ok]=io(Mr),Xp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:h,required:p,form:m}=e,g=_i(t),[y,x]=v.useState(null),[w,C]=v.useState(null),[T,k]=v.useState(!1),S=vs(c),[E,j]=Kr({prop:r,defaultProp:o??!1,onChange:s,caller:Mr}),[_,P]=Kr({prop:i,defaultProp:a,onChange:l,caller:Mr}),D=v.useRef(null),z=y?m||!!y.closest("form"):!0,[B,O]=v.useState(new Set),H=Array.from(B).map(R=>R.props.value).join(";");return u.jsx(id,{...g,children:u.jsxs(Pk,{required:p,scope:t,trigger:y,onTriggerChange:x,valueNode:w,onValueNodeChange:C,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:Qn(),value:_,onValueChange:P,open:E,onOpenChange:j,dir:S,triggerPointerDownPosRef:D,disabled:h,children:[u.jsx(Ni.Provider,{scope:t,children:u.jsx(Rk,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(R=>{O(V=>new Set(V).add(R))},[]),onNativeOptionRemove:v.useCallback(R=>{O(V=>{const $=new Set(V);return $.delete(R),$})},[]),children:n})}),z?u.jsxs(wm,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:R=>P(R.target.value),disabled:h,form:m,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(B)]},H):null]})})};Xp.displayName=Mr;var Jp="SelectTrigger",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=_i(n),i=gr(Jp,n),a=i.disabled||r,l=Je(t,i.onTriggerChange),c=Ai(n),d=v.useRef("touch"),[f,h,p]=Sm(g=>{const y=c().filter(C=>!C.disabled),x=y.find(C=>C.value===i.value),w=Cm(y,g,x);w!==void 0&&i.onValueChange(w.value)}),m=g=>{a||(i.onOpenChange(!0),p()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ad,{asChild:!0,...s,children:u.jsx(De.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":bm(i.value)?"":void 0,...o,ref:l,onClick:ge(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&m(g)}),onPointerDown:ge(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(m(g),g.preventDefault())}),onKeyDown:ge(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&h(g.key),!(y&&g.key===" ")&&Ak.includes(g.key)&&(m(),g.preventDefault())})})})});Zp.displayName=Jp;var Qp="SelectValue",em=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=gr(Qp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Je(t,l.onValueNodeChange);return qt(()=>{c(d)},[c,d]),u.jsx(De.span,{...a,ref:f,style:{pointerEvents:"none"},children:bm(l.value)?u.jsx(u.Fragment,{children:i}):s})});em.displayName=Qp;var Mk="SelectIcon",tm=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(De.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});tm.displayName=Mk;var Dk="SelectPortal",nm=e=>u.jsx(Rs,{asChild:!0,...e});nm.displayName=Dk;var Dr="SelectContent",rm=v.forwardRef((e,t)=>{const n=gr(Dr,e.__scopeSelect),[r,o]=v.useState();if(qt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Xo.createPortal(u.jsx(om,{scope:e.__scopeSelect,children:u.jsx(Ni.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(sm,{...e,ref:t})});rm.displayName=Dr;var Mn=10,[om,yr]=io(Dr),Lk="SelectContentImpl",Fk=wr.createSlot("SelectContent.RemoveScroll"),sm=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:g,avoidCollisions:y,...x}=e,w=gr(Dr,n),[C,T]=v.useState(null),[k,S]=v.useState(null),E=Je(t,te=>T(te)),[j,_]=v.useState(null),[P,D]=v.useState(null),z=Ai(n),[B,O]=v.useState(!1),H=v.useRef(!1);v.useEffect(()=>{if(C)return Da(C)},[C]),ya();const R=v.useCallback(te=>{const[L,...G]=z().map(U=>U.ref.current),[se]=G.slice(-1),le=document.activeElement;for(const U of te)if(U===le||(U==null||U.scrollIntoView({block:"nearest"}),U===L&&k&&(k.scrollTop=0),U===se&&k&&(k.scrollTop=k.scrollHeight),U==null||U.focus(),document.activeElement!==le))return},[z,k]),V=v.useCallback(()=>R([j,C]),[R,j,C]);v.useEffect(()=>{B&&V()},[B,V]);const{onOpenChange:$,triggerPointerDownPosRef:F}=w;v.useEffect(()=>{if(C){let te={x:0,y:0};const L=se=>{var le,U;te={x:Math.abs(Math.round(se.pageX)-(((le=F.current)==null?void 0:le.x)??0)),y:Math.abs(Math.round(se.pageY)-(((U=F.current)==null?void 0:U.y)??0))}},G=se=>{te.x<=10&&te.y<=10?se.preventDefault():C.contains(se.target)||$(!1),document.removeEventListener("pointermove",L),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",G,{capture:!0})}}},[C,$,F]),v.useEffect(()=>{const te=()=>$(!1);return window.addEventListener("blur",te),window.addEventListener("resize",te),()=>{window.removeEventListener("blur",te),window.removeEventListener("resize",te)}},[$]);const[ne,Q]=Sm(te=>{const L=z().filter(le=>!le.disabled),G=L.find(le=>le.ref.current===document.activeElement),se=Cm(L,te,G);se&&setTimeout(()=>se.ref.current.focus())}),ye=v.useCallback((te,L,G)=>{const se=!H.current&&!G;(w.value!==void 0&&w.value===L||se)&&(_(te),se&&(H.current=!0))},[w.value]),Pe=v.useCallback(()=>C==null?void 0:C.focus(),[C]),Z=v.useCallback((te,L,G)=>{const se=!H.current&&!G;(w.value!==void 0&&w.value===L||se)&&D(te)},[w.value]),ue=r==="popper"?Dl:im,ke=ue===Dl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(om,{scope:n,content:C,viewport:k,onViewportChange:S,itemRefCallback:ye,selectedItem:j,onItemLeave:Pe,itemTextRefCallback:Z,focusSelectedItem:V,selectedItemText:P,position:r,isPositioned:B,searchRef:ne,children:u.jsx(Hs,{as:Fk,allowPinchZoom:!0,children:u.jsx(bs,{asChild:!0,trapped:w.open,onMountAutoFocus:te=>{te.preventDefault()},onUnmountAutoFocus:ge(o,te=>{var L;(L=w.trigger)==null||L.focus({preventScroll:!0}),te.preventDefault()}),children:u.jsx(ws,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:te=>te.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(ue,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:te=>te.preventDefault(),...x,...ke,onPlaced:()=>O(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ge(x.onKeyDown,te=>{const L=te.ctrlKey||te.altKey||te.metaKey;if(te.key==="Tab"&&te.preventDefault(),!L&&te.key.length===1&&Q(te.key),["ArrowUp","ArrowDown","Home","End"].includes(te.key)){let se=z().filter(le=>!le.disabled).map(le=>le.ref.current);if(["ArrowUp","End"].includes(te.key)&&(se=se.slice().reverse()),["ArrowUp","ArrowDown"].includes(te.key)){const le=te.target,U=se.indexOf(le);se=se.slice(U+1)}setTimeout(()=>R(se)),te.preventDefault()}})})})})})})});sm.displayName=Lk;var $k="SelectItemAlignedPosition",im=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=gr(Dr,n),i=yr(Dr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Je(t,E=>d(E)),h=Ai(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:w}=i,C=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),P=x.getBoundingClientRect();if(s.dir!=="rtl"){const le=P.left-j.left,U=_.left-le,We=E.left-U,re=E.width+We,xe=Math.max(re,j.width),Re=window.innerWidth-Mn,Fe=_l(U,[Mn,Math.max(Mn,Re-xe)]);a.style.minWidth=re+"px",a.style.left=Fe+"px"}else{const le=j.right-P.right,U=window.innerWidth-_.right-le,We=window.innerWidth-E.right-U,re=E.width+We,xe=Math.max(re,j.width),Re=window.innerWidth-Mn,Fe=_l(U,[Mn,Math.max(Mn,Re-xe)]);a.style.minWidth=re+"px",a.style.right=Fe+"px"}const D=h(),z=window.innerHeight-Mn*2,B=g.scrollHeight,O=window.getComputedStyle(c),H=parseInt(O.borderTopWidth,10),R=parseInt(O.paddingTop,10),V=parseInt(O.borderBottomWidth,10),$=parseInt(O.paddingBottom,10),F=H+R+B+$+V,ne=Math.min(y.offsetHeight*5,F),Q=window.getComputedStyle(g),ye=parseInt(Q.paddingTop,10),Pe=parseInt(Q.paddingBottom,10),Z=E.top+E.height/2-Mn,ue=z-Z,ke=y.offsetHeight/2,te=y.offsetTop+ke,L=H+R+te,G=F-L;if(L<=Z){const le=D.length>0&&y===D[D.length-1].ref.current;a.style.bottom="0px";const U=c.clientHeight-g.offsetTop-g.offsetHeight,We=Math.max(ue,ke+(le?Pe:0)+U+V),re=L+We;a.style.height=re+"px"}else{const le=D.length>0&&y===D[0].ref.current;a.style.top="0px";const We=Math.max(Z,H+g.offsetTop+(le?ye:0)+ke)+G;a.style.height=We+"px",g.scrollTop=L-Z+g.offsetTop}a.style.margin=`${Mn}px 0`,a.style.minHeight=ne+"px",a.style.maxHeight=z+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,g,y,x,s.dir,r]);qt(()=>C(),[C]);const[T,k]=v.useState();qt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const S=v.useCallback(E=>{E&&m.current===!0&&(C(),w==null||w(),m.current=!1)},[C,w]);return u.jsx(Bk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:S,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:u.jsx(De.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});im.displayName=$k;var zk="SelectPopperPosition",Dl=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Mn,...s}=e,i=_i(n);return u.jsx(ld,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Dl.displayName=zk;var[Bk,Ll]=io(Dr,{}),Fl="SelectViewport",am=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=yr(Fl,n),i=Ll(Fl,n),a=Je(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Ni.Slot,{scope:n,children:u.jsx(De.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ge(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const m=window.innerHeight-Mn*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<m){const w=x+p,C=Math.min(m,w),T=w-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});am.displayName=Fl;var lm="SelectGroup",[Hk,Uk]=io(lm),Wk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Qn();return u.jsx(Hk,{scope:n,id:o,children:u.jsx(De.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Wk.displayName=lm;var cm="SelectLabel",um=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Uk(cm,n);return u.jsx(De.div,{id:o.id,...r,ref:t})});um.displayName=cm;var ji="SelectItem",[Vk,dm]=io(ji),fm=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=gr(ji,n),l=yr(ji,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),m=Je(t,w=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,w,r,o)}),g=Qn(),y=v.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(Vk,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:v.useCallback(w=>{f(C=>C||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(Ni.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(De.div,{role:"option","aria-labelledby":g,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:ge(i.onFocus,()=>p(!0)),onBlur:ge(i.onBlur,()=>p(!1)),onClick:ge(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:ge(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:ge(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:ge(i.onPointerMove,w=>{var C;y.current=w.pointerType,o?(C=l.onItemLeave)==null||C.call(l):y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ge(i.onPointerLeave,w=>{var C;w.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:ge(i.onKeyDown,w=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&w.key===" "||(_k.includes(w.key)&&x(),w.key===" "&&w.preventDefault())})})})})});fm.displayName=ji;var Vo="SelectItemText",hm=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=gr(Vo,n),a=yr(Vo,n),l=dm(Vo,n),c=Ok(Vo,n),[d,f]=v.useState(null),h=Je(t,x=>f(x),l.onItemTextChange,x=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return qt(()=>(g(m),()=>y(m)),[g,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(De.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Xo.createPortal(s.children,i.valueNode):null]})});hm.displayName=Vo;var pm="SelectItemIndicator",mm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return dm(pm,n).isSelected?u.jsx(De.span,{"aria-hidden":!0,...r,ref:t}):null});mm.displayName=pm;var $l="SelectScrollUpButton",gm=v.forwardRef((e,t)=>{const n=yr($l,e.__scopeSelect),r=Ll($l,e.__scopeSelect),[o,s]=v.useState(!1),i=Je(t,r.onScrollButtonChange);return qt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(xm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});gm.displayName=$l;var zl="SelectScrollDownButton",ym=v.forwardRef((e,t)=>{const n=yr(zl,e.__scopeSelect),r=Ll(zl,e.__scopeSelect),[o,s]=v.useState(!1),i=Je(t,r.onScrollButtonChange);return qt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(xm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ym.displayName=zl;var xm=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=yr("SelectScrollButton",n),i=v.useRef(null),a=Ai(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),qt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(De.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ge(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ge(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ge(o.onPointerLeave,()=>{l()})})}),Kk="SelectSeparator",vm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(De.div,{"aria-hidden":!0,...r,ref:t})});vm.displayName=Kk;var Bl="SelectArrow",qk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=_i(n),s=gr(Bl,n),i=yr(Bl,n);return s.open&&i.position==="popper"?u.jsx(cd,{...o,...r,ref:t}):null});qk.displayName=Bl;var Gk="SelectBubbleInput",wm=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Je(r,o),i=Hp(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(De.select,{...n,style:{...Yp,...n.style},ref:s,defaultValue:t})});wm.displayName=Gk;function bm(e){return e===""||e===void 0}function Sm(e){const t=Gt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Cm(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Yk(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Yk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Xk=Xp,km=Zp,Jk=em,Zk=tm,Qk=nm,Tm=rm,eT=am,Em=um,Im=fm,tT=hm,nT=mm,Nm=gm,Am=ym,_m=vm;const jm=Xk,Pm=Jk,Hl=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(km,{ref:r,className:oe("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(Zk,{asChild:!0,children:u.jsx(he.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Hl.displayName=km.displayName;const Rm=v.forwardRef(({className:e,...t},n)=>u.jsx(Nm,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(he.ChevronUp,{className:"h-4 w-4"})}));Rm.displayName=Nm.displayName;const Om=v.forwardRef(({className:e,...t},n)=>u.jsx(Am,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(he.ChevronDown,{className:"h-4 w-4"})}));Om.displayName=Am.displayName;const Ul=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Qk,{children:u.jsxs(Tm,{ref:o,className:oe("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Rm,{}),u.jsx(eT,{className:oe("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Om,{})]})}));Ul.displayName=Tm.displayName;const rT=v.forwardRef(({className:e,...t},n)=>u.jsx(Em,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));rT.displayName=Em.displayName;const Lr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Im,{ref:r,className:oe("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(nT,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),u.jsx(tT,{children:t})]}));Lr.displayName=Im.displayName;const oT=v.forwardRef(({className:e,...t},n)=>u.jsx(_m,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));oT.displayName=_m.displayName;var sT="Separator",Mm="horizontal",iT=["horizontal","vertical"],Dm=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Mm,...o}=e,s=aT(r)?r:Mm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(De.div,{"data-orientation":s,...a,...o,ref:t})});Dm.displayName=sT;function aT(e){return iT.includes(e)}var Lm=Dm;const Fm=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Lm,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Fm.displayName=Lm.displayName;const lT=Kh,cT=kC,uT=qh,$m=v.forwardRef(({className:e,...t},n)=>u.jsx(hi,{className:oe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));$m.displayName=hi.displayName;const dT=Yo.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),zm=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(uT,{children:[u.jsx($m,{}),u.jsxs(pi,{ref:o,className:oe(dT({side:e}),t),...r,children:[n,u.jsxs(Gh,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(he.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));zm.displayName=pi.displayName;const Bm=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});Bm.displayName="SheetHeader";const Hm=v.forwardRef(({className:e,...t},n)=>u.jsx(Rr,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));Hm.displayName=Rr.displayName;const Um=v.forwardRef(({className:e,...t},n)=>u.jsx(mi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Um.displayName=mi.displayName;const fT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function hT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,d]=b.useState(!1),{toast:f}=bl();b.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),b.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(fT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(lT,{open:r,onOpenChange:o,children:[u.jsx(cT,{asChild:!0,children:u.jsxs(ct,{variant:"outline",size:"sm",className:n,children:[u.jsx(he.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Ch,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(zm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Bm,{children:[u.jsx(Hm,{children:"Chat Settings"}),u.jsx(Um,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(En,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Si,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(x=>({...x,api:{...x.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(ct,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(En,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(mr,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(x=>({...x,api:{...x.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(En,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Si,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(x=>({...x,api:{...x.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(ct,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(he.EyeOff,{className:"h-4 w-4"}):u.jsx(he.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(En,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(jm,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Hl,{children:u.jsx(Pm,{})}),u.jsxs(Ul,{children:[u.jsx(Lr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(Lr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(Lr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(En,{htmlFor:"theme",children:"Theme"}),u.jsxs(jm,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Hl,{children:u.jsx(Pm,{})}),u.jsxs(Ul,{children:[u.jsx(Lr,{value:"light",children:"Light"}),u.jsx(Lr,{value:"dark",children:"Dark"}),u.jsx(Lr,{value:"system",children:"System"})]})]})]}),u.jsx(Fm,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(En,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(mr,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(En,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(mr,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(En,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(mr,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(Lo,{children:[u.jsx(Fo,{className:"pb-3",children:u.jsxs($o,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(zo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(En,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(mr,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(En,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(mr,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(En,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(mr,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(ct,{variant:"outline",onClick:p,children:[u.jsx(he.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(ct,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(ct,{onClick:h,disabled:!c,children:[u.jsx(he.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function pT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(xs,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(bi,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(xs,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Ml,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(bi,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(xs,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Ml,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(bi,{onError:s.onError,enableFileUpload:!0})})]})})}_e.ChatApi=zc,_e.ChatInput=pu,_e.ChatInterface=bi,_e.ChatProviders=xs,_e.ChatSettings=hT,_e.MarkdownContent=Wo,_e.MessageComponent=Nl,_e.MessageList=Al,_e.ThreadManager=Ml,_e.applySettings=vk,_e.chatApiClient=sr,_e.default=pT,_e.del=$c,_e.get=vn,_e.getChatToken=Dc,_e.getCurrentSettings=xk,_e.getDefaultApiConfig=Lp,_e.getDefaultChatSettings=Fp,_e.onChatTokenChanged=Lc,_e.post=Yi,_e.put=Fc,_e.registerChatTokenSyncHandler=ky,_e.setChatToken=Gi,_e.useApi=Xi,_e.useChatStream=tu,_e.useMessagesReducer=qc,_e.useStream=fu,_e.useThreadState=ys,_e.useThreads=gs,Object.defineProperties(_e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
133
|
+
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=ip(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=ip(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 dp{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 fp{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 Nl,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new dp,this.slugger=new fp}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,sp(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 xi{constructor(t){this.options=t||Mr}preprocess(t){return t}postprocess(t){return t}}Qm(xi,"passThroughHooks",new Set(["preprocess","postprocess"]));function XC(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 hp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...be.defaults,...s};const i=XC(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(qC(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 hp(hr.lex,pr.parse)(e,t,n)}be.options=be.setOptions=function(e){return be.defaults={...be.defaults,...e},OC(be.defaults),be},be.getDefaults=tp,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 Nl;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 Il;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=be.defaults.hooks||new xi;for(const s in n.hooks){const i=o[s];xi.passThroughHooks.has(s)?o[s]=a=>{if(be.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=be.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}be.setOptions(r)})},be.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(be,r)),r.type){case"table":{for(const o of r.header)n=n.concat(be.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(be.walkTokens(s.tokens,t));break}case"list":{n=n.concat(be.walkTokens(r.items,t));break}default:be.defaults.extensions&&be.defaults.extensions.childTokens&&be.defaults.extensions.childTokens[r.type]?be.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(be.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(be.walkTokens(r.tokens,t)))}return n},be.parseInline=hp(hr.lexInline,pr.parseInline),be.Parser=pr,be.parser=pr.parse,be.Renderer=Nl,be.TextRenderer=dp,be.Lexer=hr,be.lexer=hr.lex,be.Tokenizer=Il,be.Slugger=fp,be.Hooks=xi,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 JC="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 ZC(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function pp(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function vi(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function QC(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 ek(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function mp(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 tk({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 Al=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}=ms(),{respondToInterrupt:V}=gs(),$=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}=rk({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?"":ZC(t.content),[Q,t]),ae=w.useMemo(()=>Q?{}:pp(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=vi(xe),Le=x==null?void 0:x.value,nt=w.useMemo(()=>Q?"":QC(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=vi((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=vi((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=Cl(it);return yt&&F!=="tool"?u.jsx(gp,{data:yt},Ee):F==="user"&&c&&it.length>d?u.jsx(ok,{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=vi((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(nk,{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(sk,{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(tk,{className:G})]}):ve}},[se,U.length,Ue.length,re.length,r,ne,z,ft,G]),ht=w.useMemo(()=>Q?"Assistant":ek(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(Th,{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(RC,{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&&mp(e.message)===mp(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 gp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:JC,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 nk({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(Eh,{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(Ih,{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 rk(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Sl(),[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 yC(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 ok({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 sk({message:e,viewMode:t}){const r=pp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Cl(c)??c:c;if(d&&typeof d=="object")return u.jsx(gp,{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}=vC(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=ci(d);return s(f)}const a=Uo(i),l=ci(a);return s(l)}const yp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,ik=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},_l=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=ik(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(Al,{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(YS,{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)=>yp(xe,re),itemContent:(re,xe)=>{var et;const Re=yp(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(Al,{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()})]})});_l.displayName="MessageList";const xp={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}=Ji(),{currentThreadId:y}=ms(),{threadId:x,messages:b,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}=pu(),$=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(()=>xp.value),We=w.useRef(Bt),Lt=w.useRef(null),_t=w.useCallback(Z=>{xp.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:ji,messageId:Pi}=it(st.messages),lo=ji&&ji.replace(/\s+/g," ").trim()||It(st.metadata,"title")||It(st.metadata,"label")||Pt||rr||"Checkpoint",Ri=lo.length>60?`${lo.slice(0,57)}…`:lo;return{id:pn,label:Ri,messageId:Pi??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>qs)return`Message too long (${Z.length}/${qs} characters)`;try{return $0(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(_l,{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(A0,{children:[u.jsx(_0,{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(Ef,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Xa,{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(Xa,{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(_x,{initialValue:se,editingMessageId:L,value:Bt,onValueChange:io,placeholder:L?"Edit your message...":t,isStreaming:B,disabled:te,maxLength:qs,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 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 jl(e,[t,n]){return Math.min(n,Math.max(t,e))}function ak(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Pl="ScrollArea",[vp,ZT]=Jn(Pl),[lk,In]=vp(Pl),wp=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=xs(o);return u.jsx(lk,{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}})})});wp.displayName=Pl;var bp="ScrollAreaViewport",Sp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=In(bp,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})})]})});Sp.displayName=bp;var Gn="ScrollAreaScrollbar",Rl=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(ck,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(uk,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Cp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Ol,{...r,ref:t}):null});Rl.displayName=Gn;var ck=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(Cp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),uk=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=In(Gn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ti(()=>l("SCROLL_END"),100),[a,l]=ak("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(Ol,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Cp=v.forwardRef((e,t)=>{const n=In(Gn,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(Cn,{present:r||s,children:u.jsx(Ol,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ol=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=Np(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 gk(h,i.current,a,p)}return n==="horizontal"?u.jsx(dk,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Ap(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(fk,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Ap(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}),dk=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(Tp,{"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),jp(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)}})}})}),fk=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(Tp,{"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),jp(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)}})}})}),[hk,kp]=vp(Gn),Tp=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=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(hk,{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})})})}),Si="ScrollAreaThumb",Ep=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=kp(Si,e.__scopeScrollArea);return u.jsx(Cn,{present:n||o.hasThumb,children:u.jsx(pk,{ref:t,...r})})}),pk=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=In(Si,n),i=kp(Si,n),{onThumbPositionChange:a}=i,l=Je(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=yk(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)})});Ep.displayName=Si;var Ml="ScrollAreaCorner",Ip=v.forwardRef((e,t)=>{const n=In(Ml,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(mk,{...e,ref:t}):null});Ip.displayName=Ml;var mk=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=In(Ml,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 Ci(e){return e?parseInt(e,10):0}function Np(e,t){const n=e/t;return isNaN(n)?0:n}function ki(e){const t=Np(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function gk(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 _p([l,c],f)(e)}function Ap(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=jl(e,l);return _p([0,i],[0,a])(c)}function _p(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 jp(e,t){return e>0&&e<t}var yk=(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=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 Pp=wp,xk=Sp,vk=Ip;const Rp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Pp,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(xk,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Op,{}),u.jsx(vk,{})]}));Rp.displayName=Pp.displayName;const Op=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Rl,{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(Ep,{className:"relative flex-1 rounded-full bg-border"})}));Op.displayName=Rl.displayName;const Mp=25;function Dl({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: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<=Mp?ce:`${ce.slice(0,Mp)}...`};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(Rp,{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(bi,{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 wk(e){if(typeof e!="string")return;const t=e.trim();if(t)return Xn(t)}function Dp(){const e=[oo("__API_BASE_URL__"),oo("__CHAT_API_BASE_URL__"),oo("__CHAT_API_URL__")];for(const t of e){const n=wk(t);if(n)return n}}function Lp(){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 Fp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Xn(t);return Xn()}function $p(){const e={},t=Dp(),n=Lp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function zp(){const e=$p(),t=sr.getAuthToken(),n=Dp();return{apiBaseUrl:Fp(e.baseUrl,sr.baseUrl,n),apiKey:t||e.apiKey||Lp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Bp="chat-settings";function bk(){try{const e=localStorage.getItem(Bp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function Sk(e){try{const t={...e,apiBaseUrl:Xn(e.apiBaseUrl)};localStorage.setItem(Bp,JSON.stringify(t)),t.apiKey&&sr.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function Ck(){const e=zp(),t=bk(),n=sr.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Fp(sr.baseUrl,r,e.apiBaseUrl)}}function kk(e){sr.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),Sk(e)}var Tk="Label",Hp=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())}}));Hp.displayName=Tk;var Up=Hp;const Ek=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(Up,{ref:n,className:oe(Ek(),e),...t}));Nn.displayName=Up.displayName;function Wp(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",[Ik,QT]=Jn(Ei),[Nk,Ak]=Ik(Ei),Vp=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:Ei});return u.jsxs(Nk,{scope:n,checked:x,disabled:a,children:[u.jsx(Me.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Yp(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(Gp,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Vp.displayName=Ei;var Kp="SwitchThumb",qp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=Ak(Kp,n);return u.jsx(Me.span,{"data-state":Yp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});qp.displayName=Kp;var _k="SwitchBubbleInput",Gp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Je(i,s),l=Wp(n),c=Zu(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}})});Gp.displayName=_k;function Yp(e){return e?"checked":"unchecked"}var Xp=Vp,jk=qp;const mr=v.forwardRef(({className:e,...t},n)=>u.jsx(Xp,{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(jk,{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=Xp.displayName;var Jp=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"}),Pk="VisuallyHidden",Rk=v.forwardRef((e,t)=>u.jsx(Me.span,{...e,ref:t,style:{...Jp,...e.style}}));Rk.displayName=Pk;var Ok=[" ","Enter","ArrowUp","ArrowDown"],Mk=[" ","Enter"],Dr="Select",[Ii,Ni,Dk]=ma(Dr),[so,eE]=Jn(Dr,[Dk,js]),Ai=js(),[Lk,gr]=so(Dr),[Fk,$k]=so(Dr),Zp=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),[b,C]=v.useState(null),[T,k]=v.useState(!1),S=xs(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(ld,{...g,children:u.jsxs(Lk,{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(Ii.Provider,{scope:t,children:u.jsx(Fk,{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(Sm,{"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]})})};Zp.displayName=Dr;var Qp="SelectTrigger",em=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ai(n),i=gr(Qp,n),a=i.disabled||r,l=Je(t,i.onTriggerChange),c=Ni(n),d=v.useRef("touch"),[f,h,p]=km(g=>{const y=c().filter(C=>!C.disabled),x=y.find(C=>C.value===i.value),b=Tm(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(cd,{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":Cm(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===" ")&&Ok.includes(g.key)&&(m(),g.preventDefault())})})})});em.displayName=Qp;var tm="SelectValue",nm=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=gr(tm,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:Cm(l.value)?u.jsx(u.Fragment,{children:i}):s})});nm.displayName=tm;var zk="SelectIcon",rm=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Me.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});rm.displayName=zk;var Bk="SelectPortal",om=e=>u.jsx(Ps,{asChild:!0,...e});om.displayName=Bk;var Lr="SelectContent",sm=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(im,{scope:e.__scopeSelect,children:u.jsx(Ii.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(am,{...e,ref:t})});sm.displayName=Lr;var Ln=10,[im,yr]=so(Lr),Hk="SelectContentImpl",Uk=br.createSlot("SelectContent.RemoveScroll"),am=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=Ni(n),[B,O]=v.useState(!1),H=v.useRef(!1);v.useEffect(()=>{if(C)return La(C)},[C]),xa();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]=km(te=>{const L=z().filter(ae=>!ae.disabled),G=L.find(ae=>ae.ref.current===document.activeElement),se=Tm(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"?Ll:lm,Ce=ce===Ll?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(im,{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(Bs,{as:Uk,allowPinchZoom:!0,children:u.jsx(ws,{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(vs,{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()}})})})})})})});am.displayName=Hk;var Wk="SelectItemAlignedPosition",lm=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=Ni(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=jl(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=jl(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(Kk,{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}})})})});lm.displayName=Wk;var Vk="SelectPopperPosition",Ll=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Ln,...s}=e,i=Ai(n);return u.jsx(ud,{...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)"}})});Ll.displayName=Vk;var[Kk,Fl]=so(Lr,{}),$l="SelectViewport",cm=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=yr($l,n),i=Fl($l,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(Ii.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})})})]})});cm.displayName=$l;var um="SelectGroup",[qk,Gk]=so(um),Yk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Zn();return u.jsx(qk,{scope:n,id:o,children:u.jsx(Me.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Yk.displayName=um;var dm="SelectLabel",fm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Gk(dm,n);return u.jsx(Me.div,{id:o.id,...r,ref:t})});fm.displayName=dm;var _i="SelectItem",[Xk,hm]=so(_i),pm=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=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(Xk,{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(Ii.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===" "||(Mk.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});pm.displayName=_i;var Ko="SelectItemText",mm=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=gr(Ko,n),a=yr(Ko,n),l=hm(Ko,n),c=$k(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]})});mm.displayName=Ko;var gm="SelectItemIndicator",ym=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return hm(gm,n).isSelected?u.jsx(Me.span,{"aria-hidden":!0,...r,ref:t}):null});ym.displayName=gm;var zl="SelectScrollUpButton",xm=v.forwardRef((e,t)=>{const n=yr(zl,e.__scopeSelect),r=Fl(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.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(wm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});xm.displayName=zl;var Bl="SelectScrollDownButton",vm=v.forwardRef((e,t)=>{const n=yr(Bl,e.__scopeSelect),r=Fl(Bl,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(wm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});vm.displayName=Bl;var wm=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]),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()})})}),Jk="SelectSeparator",bm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Me.div,{"aria-hidden":!0,...r,ref:t})});bm.displayName=Jk;var Hl="SelectArrow",Zk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ai(n),s=gr(Hl,n),i=yr(Hl,n);return s.open&&i.position==="popper"?u.jsx(dd,{...o,...r,ref:t}):null});Zk.displayName=Hl;var Qk="SelectBubbleInput",Sm=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Je(r,o),i=Wp(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:{...Jp,...n.style},ref:s,defaultValue:t})});Sm.displayName=Qk;function Cm(e){return e===""||e===void 0}function km(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 Tm(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=eT(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 eT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var tT=Zp,Em=em,nT=nm,rT=rm,oT=om,Im=sm,sT=cm,Nm=fm,Am=pm,iT=mm,aT=ym,_m=xm,jm=vm,Pm=bm;const Rm=tT,Om=nT,Ul=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Em,{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(rT,{asChild:!0,children:u.jsx(he.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ul.displayName=Em.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.ChevronUp,{className:"h-4 w-4"})}));Mm.displayName=_m.displayName;const Dm=v.forwardRef(({className:e,...t},n)=>u.jsx(jm,{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"})}));Dm.displayName=jm.displayName;const Wl=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(oT,{children:u.jsxs(Im,{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(Mm,{}),u.jsx(sT,{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(Dm,{})]})}));Wl.displayName=Im.displayName;const lT=v.forwardRef(({className:e,...t},n)=>u.jsx(Nm,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));lT.displayName=Nm.displayName;const Fr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Am,{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(aT,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),u.jsx(iT,{children:t})]}));Fr.displayName=Am.displayName;const cT=v.forwardRef(({className:e,...t},n)=>u.jsx(Pm,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));cT.displayName=Pm.displayName;var uT="Separator",Lm="horizontal",dT=["horizontal","vertical"],Fm=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Lm,...o}=e,s=fT(r)?r:Lm,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})});Fm.displayName=uT;function fT(e){return dT.includes(e)}var $m=Fm;const zm=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx($m,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));zm.displayName=$m.displayName;const hT=Gh,pT=AC,mT=Yh,Bm=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}));Bm.displayName=fi.displayName;const gT=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"}}),Hm=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(mT,{children:[u.jsx(Bm,{}),u.jsxs(hi,{ref:o,className:oe(gT({side:e}),t),...r,children:[n,u.jsxs(Xh,{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"})]})]})]}));Hm.displayName=hi.displayName;const Um=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});Um.displayName="SheetHeader";const Wm=v.forwardRef(({className:e,...t},n)=>u.jsx(Or,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));Wm.displayName=Or.displayName;const Vm=v.forwardRef(({className:e,...t},n)=>u.jsx(pi,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Vm.displayName=pi.displayName;const yT={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 xT({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}=Sl();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(yT),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(hT,{open:r,onOpenChange:o,children:[u.jsx(pT,{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(Th,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Hm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Um,{children:[u.jsx(Wm,{children:"Chat Settings"}),u.jsx(Vm,{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(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(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(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(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(Rm,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Ul,{children:u.jsx(Om,{})}),u.jsxs(Wl,{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(Rm,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Ul,{children:u.jsx(Om,{})}),u.jsxs(Wl,{children:[u.jsx(Fr,{value:"light",children:"Light"}),u.jsx(Fr,{value:"dark",children:"Dark"}),u.jsx(Fr,{value:"system",children:"System"})]})]})]}),u.jsx(zm,{}),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 vT({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(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(Dl,{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(Dl,{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})})]})})}_e.ChatApi=Hc,_e.ChatInput=gu,_e.ChatInterface=wi,_e.ChatProviders=ys,_e.ChatSettings=xT,_e.MarkdownContent=Vo,_e.MessageComponent=Al,_e.MessageList=_l,_e.ThreadManager=Dl,_e.applySettings=kk,_e.chatApiClient=sr,_e.default=vT,_e.del=Bc,_e.get=bn,_e.getChatToken=Lc,_e.getCurrentSettings=Ck,_e.getDefaultApiConfig=$p,_e.getDefaultChatSettings=zp,_e.onChatTokenChanged=Fc,_e.post=Xi,_e.put=zc,_e.registerChatTokenSyncHandler=Iy,_e.setChatToken=Yi,_e.useApi=Ji,_e.useChatStream=ru,_e.useMessagesReducer=Yc,_e.useStream=pu,_e.useThreadState=gs,_e.useThreads=ms,Object.defineProperties(_e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|