teodor-new-chat-ui 4.0.21 → 4.0.23
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 +625 -631
- package/dist/index.umd.js +14 -14
- package/dist/lib/chat-api.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -14,28 +14,28 @@
|
|
|
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 $a;function Tp(){return $a||($a=1,process.env.NODE_ENV!=="production"&&function(){var e=y,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"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),w=Symbol.iterator,v="@@iterator";function g(E){if(E===null||typeof E!="object")return null;var U=w&&E[w]||E[v];return typeof U=="function"?U:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var U=arguments.length,re=new Array(U>1?U-1:0),Se=1;Se<U;Se++)re[Se-1]=arguments[Se];S("error",E,re)}}function S(E,U,re){{var Se=x.ReactDebugCurrentFrame,Ve=Se.getStackAddendum();Ve!==""&&(U+="%s",re=re.concat([Ve]));var Ze=re.map(function(Fe){return String(Fe)});Ze.unshift("Warning: "+U),Function.prototype.apply.call(console[E],console,Ze)}}var k=!1,C=!1,T=!1,I=!1,N=!1,_;_=Symbol.for("react.module.reference");function
|
|
17
|
+
*/var $a;function Tp(){return $a||($a=1,process.env.NODE_ENV!=="production"&&function(){var e=y,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"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),w=Symbol.iterator,v="@@iterator";function g(E){if(E===null||typeof E!="object")return null;var U=w&&E[w]||E[v];return typeof U=="function"?U:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var U=arguments.length,re=new Array(U>1?U-1:0),Se=1;Se<U;Se++)re[Se-1]=arguments[Se];S("error",E,re)}}function S(E,U,re){{var Se=x.ReactDebugCurrentFrame,Ve=Se.getStackAddendum();Ve!==""&&(U+="%s",re=re.concat([Ve]));var Ze=re.map(function(Fe){return String(Fe)});Ze.unshift("Warning: "+U),Function.prototype.apply.call(console[E],console,Ze)}}var k=!1,C=!1,T=!1,I=!1,N=!1,_;_=Symbol.for("react.module.reference");function R(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||N||E===o||E===u||E===d||I||E===m||k||C||T||typeof E=="object"&&E!==null&&(E.$$typeof===h||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===c||E.$$typeof===_||E.getModuleId!==void 0))}function j(E,U,re){var Se=E.displayName;if(Se)return Se;var Ve=U.displayName||U.name||"";return Ve!==""?re+"("+Ve+")":re}function $(E){return E.displayName||"Context"}function z(E){if(E==null)return null;if(typeof E.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case d:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var U=E;return $(U)+".Consumer";case i:var re=E;return $(re._context)+".Provider";case c:return j(E,E.render,"ForwardRef");case f:var Se=E.displayName||null;return Se!==null?Se:z(E.type)||"Memo";case h:{var Ve=E,Ze=Ve._payload,Fe=Ve._init;try{return z(Fe(Ze))}catch{return null}}}return null}var O=Object.assign,V=0,B,K,L,A,D,H,Y;function Z(){}Z.__reactDisabledLog=!0;function le(){{if(V===0){B=console.log,K=console.info,L=console.warn,A=console.error,D=console.group,H=console.groupCollapsed,Y=console.groupEnd;var E={configurable:!0,enumerable:!0,value:Z,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}V++}}function xe(){{if(V--,V===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},E,{value:B}),info:O({},E,{value:K}),warn:O({},E,{value:L}),error:O({},E,{value:A}),group:O({},E,{value:D}),groupCollapsed:O({},E,{value:H}),groupEnd:O({},E,{value:Y})})}V<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Ee=x.ReactCurrentDispatcher,W;function M(E,U,re){{if(W===void 0)try{throw Error()}catch(Ve){var Se=Ve.stack.trim().match(/\n( *(at )?)/);W=Se&&Se[1]||""}return`
|
|
18
18
|
`+W+E}}var G=!1,te;{var de=typeof WeakMap=="function"?WeakMap:Map;te=new de}function ce(E,U){if(!E||G)return"";{var re=te.get(E);if(re!==void 0)return re}var Se;G=!0;var Ve=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Ze;Ze=Ee.current,Ee.current=null,le();try{if(U){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(St){Se=St}Reflect.construct(E,[],Fe)}else{try{Fe.call()}catch(St){Se=St}E.call(Fe.prototype)}}else{try{throw Error()}catch(St){Se=St}E()}}catch(St){if(St&&Se&&typeof St.stack=="string"){for(var Oe=St.stack.split(`
|
|
19
19
|
`),xt=Se.stack.split(`
|
|
20
20
|
`),st=Oe.length-1,at=xt.length-1;st>=1&&at>=0&&Oe[st]!==xt[at];)at--;for(;st>=1&&at>=0;st--,at--)if(Oe[st]!==xt[at]){if(st!==1||at!==1)do if(st--,at--,at<0||Oe[st]!==xt[at]){var Lt=`
|
|
21
|
-
`+Oe[st].replace(" at new "," at ");return E.displayName&&Lt.includes("<anonymous>")&&(Lt=Lt.replace("<anonymous>",E.displayName)),typeof E=="function"&&te.set(E,Lt),Lt}while(st>=1&&at>=0);break}}}finally{G=!1,Ee.current=Ze,xe(),Error.prepareStackTrace=Ve}var ar=E?E.displayName||E.name:"",Un=ar?M(ar):"";return typeof E=="function"&&te.set(E,Un),Un}function $e(E,U,re){return ce(E,!1)}function Ge(E){var U=E.prototype;return!!(U&&U.isReactComponent)}function _e(E,U,re){if(E==null)return"";if(typeof E=="function")return ce(E,Ge(E));if(typeof E=="string")return M(E);switch(E){case u:return M("Suspense");case d:return M("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case c:return $e(E.render);case f:return _e(E.type,U,re);case h:{var Se=E,Ve=Se._payload,Ze=Se._init;try{return _e(Ze(Ve),U,re)}catch{}}}return""}var Re=Object.prototype.hasOwnProperty,We={},
|
|
21
|
+
`+Oe[st].replace(" at new "," at ");return E.displayName&&Lt.includes("<anonymous>")&&(Lt=Lt.replace("<anonymous>",E.displayName)),typeof E=="function"&&te.set(E,Lt),Lt}while(st>=1&&at>=0);break}}}finally{G=!1,Ee.current=Ze,xe(),Error.prepareStackTrace=Ve}var ar=E?E.displayName||E.name:"",Un=ar?M(ar):"";return typeof E=="function"&&te.set(E,Un),Un}function $e(E,U,re){return ce(E,!1)}function Ge(E){var U=E.prototype;return!!(U&&U.isReactComponent)}function _e(E,U,re){if(E==null)return"";if(typeof E=="function")return ce(E,Ge(E));if(typeof E=="string")return M(E);switch(E){case u:return M("Suspense");case d:return M("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case c:return $e(E.render);case f:return _e(E.type,U,re);case h:{var Se=E,Ve=Se._payload,Ze=Se._init;try{return _e(Ze(Ve),U,re)}catch{}}}return""}var Re=Object.prototype.hasOwnProperty,We={},Q=x.ReactDebugCurrentFrame;function X(E){if(E){var U=E._owner,re=_e(E.type,E._source,U?U.type:null);Q.setExtraStackFrame(re)}else Q.setExtraStackFrame(null)}function Ne(E,U,re,Se,Ve){{var Ze=Function.call.bind(Re);for(var Fe in E)if(Ze(E,Fe)){var Oe=void 0;try{if(typeof E[Fe]!="function"){var xt=Error((Se||"React class")+": "+re+" type `"+Fe+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[Fe]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw xt.name="Invariant Violation",xt}Oe=E[Fe](U,Fe,Se,re,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(st){Oe=st}Oe&&!(Oe instanceof Error)&&(X(Ve),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).",Se||"React class",re,Fe,typeof Oe),X(null)),Oe instanceof Error&&!(Oe.message in We)&&(We[Oe.message]=!0,X(Ve),b("Failed %s type: %s",re,Oe.message),X(null))}}}var He=Array.isArray;function ee(E){return He(E)}function se(E){{var U=typeof Symbol=="function"&&Symbol.toStringTag,re=U&&E[Symbol.toStringTag]||E.constructor.name||"Object";return re}}function he(E){try{return ge(E),!1}catch{return!0}}function ge(E){return""+E}function ke(E){if(he(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",se(E)),ge(E)}var De=x.ReactCurrentOwner,Ye={key:!0,ref:!0,__self:!0,__source:!0},Xe,Je;function yt(E){if(Re.call(E,"ref")){var U=Object.getOwnPropertyDescriptor(E,"ref").get;if(U&&U.isReactWarning)return!1}return E.ref!==void 0}function ln(E){if(Re.call(E,"key")){var U=Object.getOwnPropertyDescriptor(E,"key").get;if(U&&U.isReactWarning)return!1}return E.key!==void 0}function _a(E,U){typeof E.ref=="string"&&De.current}function ja(E,U){{var re=function(){Xe||(Xe=!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)",U))};re.isReactWarning=!0,Object.defineProperty(E,"key",{get:re,configurable:!0})}}function ys(E,U){{var re=function(){Je||(Je=!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)",U))};re.isReactWarning=!0,Object.defineProperty(E,"ref",{get:re,configurable:!0})}}var Br=function(E,U,re,Se,Ve,Ze,Fe){var Oe={$$typeof:t,type:E,key:U,ref:re,props:Fe,_owner:Ze};return Oe._store={},Object.defineProperty(Oe._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Oe,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Se}),Object.defineProperty(Oe,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ve}),Object.freeze&&(Object.freeze(Oe.props),Object.freeze(Oe)),Oe};function Ra(E,U,re,Se,Ve){{var Ze,Fe={},Oe=null,xt=null;re!==void 0&&(ke(re),Oe=""+re),ln(U)&&(ke(U.key),Oe=""+U.key),yt(U)&&(xt=U.ref,_a(U,Ve));for(Ze in U)Re.call(U,Ze)&&!Ye.hasOwnProperty(Ze)&&(Fe[Ze]=U[Ze]);if(E&&E.defaultProps){var st=E.defaultProps;for(Ze in st)Fe[Ze]===void 0&&(Fe[Ze]=st[Ze])}if(Oe||xt){var at=typeof E=="function"?E.displayName||E.name||"Unknown":E;Oe&&ja(Fe,at),xt&&ys(Fe,at)}return Br(E,Oe,xt,Ve,Se,De.current,Fe)}}var Hr=x.ReactCurrentOwner,Ss=x.ReactDebugCurrentFrame;function Cn(E){if(E){var U=E._owner,re=_e(E.type,E._source,U?U.type:null);Ss.setExtraStackFrame(re)}else Ss.setExtraStackFrame(null)}var Ur;Ur=!1;function Wr(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function Cs(){{if(Hr.current){var E=z(Hr.current.type);if(E)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+E+"`."}return""}}function Pa(E){return""}var Ts={};function Oa(E){{var U=Cs();if(!U){var re=typeof E=="string"?E:E.displayName||E.name;re&&(U=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+re+">.")}return U}}function ue(E,U){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var re=Oa(U);if(Ts[re])return;Ts[re]=!0;var Se="";E&&E._owner&&E._owner!==Hr.current&&(Se=" It was passed a child from "+z(E._owner.type)+"."),Cn(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',re,Se),Cn(null)}}function ve(E,U){{if(typeof E!="object")return;if(ee(E))for(var re=0;re<E.length;re++){var Se=E[re];Wr(Se)&&ue(Se,U)}else if(Wr(E))E._store&&(E._store.validated=!0);else if(E){var Ve=g(E);if(typeof Ve=="function"&&Ve!==E.entries)for(var Ze=Ve.call(E),Fe;!(Fe=Ze.next()).done;)Wr(Fe.value)&&ue(Fe.value,U)}}}function Le(E){{var U=E.type;if(U==null||typeof U=="string")return;var re;if(typeof U=="function")re=U.propTypes;else if(typeof U=="object"&&(U.$$typeof===c||U.$$typeof===f))re=U.propTypes;else return;if(re){var Se=z(U);Ne(re,E.props,"prop",Se,E)}else if(U.PropTypes!==void 0&&!Ur){Ur=!0;var Ve=z(U);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ve||"Unknown")}typeof U.getDefaultProps=="function"&&!U.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function nt(E){{for(var U=Object.keys(E.props),re=0;re<U.length;re++){var Se=U[re];if(Se!=="children"&&Se!=="key"){Cn(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Se),Cn(null);break}}E.ref!==null&&(Cn(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),Cn(null))}}var _t={};function rn(E,U,re,Se,Ve,Ze){{var Fe=
|
|
25
|
+
Check the top-level render call using <`+re+">.")}return U}}function ue(E,U){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var re=Oa(U);if(Ts[re])return;Ts[re]=!0;var Se="";E&&E._owner&&E._owner!==Hr.current&&(Se=" It was passed a child from "+z(E._owner.type)+"."),Cn(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',re,Se),Cn(null)}}function ve(E,U){{if(typeof E!="object")return;if(ee(E))for(var re=0;re<E.length;re++){var Se=E[re];Wr(Se)&&ue(Se,U)}else if(Wr(E))E._store&&(E._store.validated=!0);else if(E){var Ve=g(E);if(typeof Ve=="function"&&Ve!==E.entries)for(var Ze=Ve.call(E),Fe;!(Fe=Ze.next()).done;)Wr(Fe.value)&&ue(Fe.value,U)}}}function Le(E){{var U=E.type;if(U==null||typeof U=="string")return;var re;if(typeof U=="function")re=U.propTypes;else if(typeof U=="object"&&(U.$$typeof===c||U.$$typeof===f))re=U.propTypes;else return;if(re){var Se=z(U);Ne(re,E.props,"prop",Se,E)}else if(U.PropTypes!==void 0&&!Ur){Ur=!0;var Ve=z(U);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ve||"Unknown")}typeof U.getDefaultProps=="function"&&!U.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function nt(E){{for(var U=Object.keys(E.props),re=0;re<U.length;re++){var Se=U[re];if(Se!=="children"&&Se!=="key"){Cn(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Se),Cn(null);break}}E.ref!==null&&(Cn(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),Cn(null))}}var _t={};function rn(E,U,re,Se,Ve,Ze){{var Fe=R(E);if(!Fe){var Oe="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).length===0)&&(Oe+=" 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 xt=Pa();xt?Oe+=xt:Oe+=Cs();var st;E===null?st="null":ee(E)?st="array":E!==void 0&&E.$$typeof===t?(st="<"+(z(E.type)||"Unknown")+" />",Oe=" Did you accidentally export a JSX literal instead of a component?"):st=typeof E,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",st,Oe)}var at=Ra(E,U,re,Ve,Ze);if(at==null)return at;if(Fe){var Lt=U.children;if(Lt!==void 0)if(Se)if(ee(Lt)){for(var ar=0;ar<Lt.length;ar++)ve(Lt[ar],E);Object.freeze&&Object.freeze(Lt)}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 ve(Lt,E)}if(Re.call(U,"key")){var Un=z(E),St=Object.keys(U).filter(function(vC){return vC!=="key"}),Ma=St.length>0?"{key: someKey, "+St.join(": ..., ")+": ...}":"{key: someKey}";if(!_t[Un+Ma]){var xC=St.length>0?"{"+St.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
30
|
<%s key={someKey} {...props} />`,Ma,Un,xC,Un),_t[Un+Ma]=!0}}return E===r?nt(at):Le(at),at}}function Vr(E,U,re){return rn(E,U,re,!0)}function Es(E,U,re){return rn(E,U,re,!1)}var ks=Es,cn=Vr;cr.Fragment=r,cr.jsx=ks,cr.jsxs=cn}()),cr}process.env.NODE_ENV==="production"?As.exports=Cp():As.exports=Tp();var l=As.exports;function Fa(e,t){return function(){return e.apply(t,arguments)}}const{toString:Ep}=Object.prototype,{getPrototypeOf:_s}=Object,{iterator:Gr,toStringTag:za}=Symbol,Yr=(e=>t=>{const n=Ep.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),$t=e=>(e=e.toLowerCase(),t=>Yr(t)===e),Xr=e=>t=>typeof t===e,{isArray:Wn}=Array,Vn=Xr("undefined");function ur(e){return e!==null&&!Vn(e)&&e.constructor!==null&&!Vn(e.constructor)&&vt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ba=$t("ArrayBuffer");function kp(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ba(e.buffer),t}const Ip=Xr("string"),vt=Xr("function"),Ha=Xr("number"),dr=e=>e!==null&&typeof e=="object",Np=e=>e===!0||e===!1,Jr=e=>{if(Yr(e)!=="object")return!1;const t=_s(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(za in e)&&!(Gr in e)},Ap=e=>{if(!dr(e)||ur(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},_p=$t("Date"),jp=$t("File"),Rp=$t("Blob"),Pp=$t("FileList"),Op=e=>dr(e)&&vt(e.pipe),Mp=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||vt(e.append)&&((t=Yr(e))==="formdata"||t==="object"&&vt(e.toString)&&e.toString()==="[object FormData]"))},Dp=$t("URLSearchParams"),[Lp,$p,Fp,zp]=["ReadableStream","Request","Response","Headers"].map($t),Bp=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function fr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Wn(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(ur(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 Ua(e,t){if(ur(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 En=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Wa=e=>!Vn(e)&&e!==En;function js(){const{caseless:e,skipUndefined:t}=Wa(this)&&this||{},n={},r=(o,s)=>{const i=e&&Ua(n,s)||s;Jr(n[i])&&Jr(o)?n[i]=js(n[i],o):Jr(o)?n[i]=js({},o):Wn(o)?n[i]=o.slice():(!t||!Vn(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&fr(arguments[o],r);return n}const Hp=(e,t,n,{allOwnKeys:r}={})=>(fr(t,(o,s)=>{n&&vt(o)?e[s]=Fa(o,n):e[s]=o},{allOwnKeys:r}),e),Up=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Wp=(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)},Vp=(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&&_s(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Kp=(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},qp=e=>{if(!e)return null;if(Wn(e))return e;let t=e.length;if(!Ha(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Gp=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&_s(Uint8Array)),Yp=(e,t)=>{const r=(e&&e[Gr]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Xp=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Jp=$t("HTMLFormElement"),Zp=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Va=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Qp=$t("RegExp"),Ka=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};fr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},em=e=>{Ka(e,(t,n)=>{if(vt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(vt(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+"'")})}})},tm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Wn(e)?r(e):r(String(e).split(t)),n},nm=()=>{},rm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function om(e){return!!(e&&vt(e.append)&&e[za]==="FormData"&&e[Gr])}const sm=e=>{const t=new Array(10),n=(r,o)=>{if(dr(r)){if(t.indexOf(r)>=0)return;if(ur(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Wn(r)?[]:{};return fr(r,(i,a)=>{const c=n(i,o+1);!Vn(c)&&(s[a]=c)}),t[o]=void 0,s}}return r};return n(e,0)},im=$t("AsyncFunction"),am=e=>e&&(dr(e)||vt(e))&&vt(e.then)&&vt(e.catch),qa=((e,t)=>e?setImmediate:t?((n,r)=>(En.addEventListener("message",({source:o,data:s})=>{o===En&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),En.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",vt(En.postMessage)),lm=typeof queueMicrotask<"u"?queueMicrotask.bind(En):typeof process<"u"&&process.nextTick||qa,P={isArray:Wn,isArrayBuffer:Ba,isBuffer:ur,isFormData:Mp,isArrayBufferView:kp,isString:Ip,isNumber:Ha,isBoolean:Np,isObject:dr,isPlainObject:Jr,isEmptyObject:Ap,isReadableStream:Lp,isRequest:$p,isResponse:Fp,isHeaders:zp,isUndefined:Vn,isDate:_p,isFile:jp,isBlob:Rp,isRegExp:Qp,isFunction:vt,isStream:Op,isURLSearchParams:Dp,isTypedArray:Gp,isFileList:Pp,forEach:fr,merge:js,extend:Hp,trim:Bp,stripBOM:Up,inherits:Wp,toFlatObject:Vp,kindOf:Yr,kindOfTest:$t,endsWith:Kp,toArray:qp,forEachEntry:Yp,matchAll:Xp,isHTMLForm:Jp,hasOwnProperty:Va,hasOwnProp:Va,reduceDescriptors:Ka,freezeMethods:em,toObjectSet:tm,toCamelCase:Zp,noop:nm,toFiniteNumber:rm,findKey:Ua,global:En,isContextDefined:Wa,isSpecCompliantForm:om,toJSONObject:sm,isAsyncFn:im,isThenable:am,setImmediate:qa,asap:lm,isIterable:e=>e!=null&&vt(e[Gr])};function Ie(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)}P.inherits(Ie,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:P.toJSONObject(this.config),code:this.code,status:this.status}}});const Ga=Ie.prototype,Ya={};["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=>{Ya[e]={value:e}}),Object.defineProperties(Ie,Ya),Object.defineProperty(Ga,"isAxiosError",{value:!0}),Ie.from=(e,t,n,r,o,s)=>{const i=Object.create(Ga);P.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",c=t==null&&e?e.code:t;return Ie.call(i,a,c,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 cm=null;function Rs(e){return P.isPlainObject(e)||P.isArray(e)}function Xa(e){return P.endsWith(e,"[]")?e.slice(0,-2):e}function Ja(e,t,n){return e?e.concat(t).map(function(o,s){return o=Xa(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function um(e){return P.isArray(e)&&!e.some(Rs)}const dm=P.toFlatObject(P,{},null,function(t){return/^is[A-Z]/.test(t)});function Zr(e,t,n){if(!P.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=P.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(v,g){return!P.isUndefined(g[v])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,c=(n.Blob||typeof Blob<"u"&&Blob)&&P.isSpecCompliantForm(t);if(!P.isFunction(o))throw new TypeError("visitor must be a function");function u(w){if(w===null)return"";if(P.isDate(w))return w.toISOString();if(P.isBoolean(w))return w.toString();if(!c&&P.isBlob(w))throw new Ie("Blob is not supported. Use a Buffer instead.");return P.isArrayBuffer(w)||P.isTypedArray(w)?c&&typeof Blob=="function"?new Blob([w]):Buffer.from(w):w}function d(w,v,g){let x=w;if(w&&!g&&typeof w=="object"){if(P.endsWith(v,"{}"))v=r?v:v.slice(0,-2),w=JSON.stringify(w);else if(P.isArray(w)&&um(w)||(P.isFileList(w)||P.endsWith(v,"[]"))&&(x=P.toArray(w)))return v=Xa(v),x.forEach(function(S,k){!(P.isUndefined(S)||S===null)&&t.append(i===!0?Ja([v],k,s):i===null?v:v+"[]",u(S))}),!1}return Rs(w)?!0:(t.append(Ja(g,v,s),u(w)),!1)}const f=[],h=Object.assign(dm,{defaultVisitor:d,convertValue:u,isVisitable:Rs});function m(w,v){if(!P.isUndefined(w)){if(f.indexOf(w)!==-1)throw Error("Circular reference detected in "+v.join("."));f.push(w),P.forEach(w,function(x,b){(!(P.isUndefined(x)||x===null)&&o.call(t,x,P.isString(b)?b.trim():b,v,h))===!0&&m(x,v?v.concat(b):[b])}),f.pop()}}if(!P.isObject(e))throw new TypeError("data must be an object");return m(e),t}function Za(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Ps(e,t){this._pairs=[],e&&Zr(e,this,t)}const Qa=Ps.prototype;Qa.append=function(t,n){this._pairs.push([t,n])},Qa.toString=function(t){const n=t?function(r){return t.call(this,r,Za)}:Za;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function fm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function el(e,t,n){if(!t)return e;const r=n&&n.encode||fm;P.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=P.isURLSearchParams(t)?t.toString():new Ps(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class tl{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){P.forEach(this.handlers,function(r){r!==null&&t(r)})}}const nl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},hm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Ps,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Os=typeof window<"u"&&typeof document<"u",Ms=typeof navigator=="object"&&navigator||void 0,pm=Os&&(!Ms||["ReactNative","NativeScript","NS"].indexOf(Ms.product)<0),mm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",gm=Os&&window.location.href||"http://localhost",dt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Os,hasStandardBrowserEnv:pm,hasStandardBrowserWebWorkerEnv:mm,navigator:Ms,origin:gm},Symbol.toStringTag,{value:"Module"})),...hm};function xm(e,t){return Zr(e,new dt.classes.URLSearchParams,{visitor:function(n,r,o,s){return dt.isNode&&P.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function vm(e){return P.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function wm(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 rl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),c=s>=n.length;return i=!i&&P.isArray(o)?o.length:i,c?(P.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!P.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&P.isArray(o[i])&&(o[i]=wm(o[i])),!a)}if(P.isFormData(e)&&P.isFunction(e.entries)){const n={};return P.forEachEntry(e,(r,o)=>{t(vm(r),o,n,0)}),n}return null}function bm(e,t,n){if(P.isString(e))try{return(t||JSON.parse)(e),P.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const hr={transitional:nl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=P.isObject(t);if(s&&P.isHTMLForm(t)&&(t=new FormData(t)),P.isFormData(t))return o?JSON.stringify(rl(t)):t;if(P.isArrayBuffer(t)||P.isBuffer(t)||P.isStream(t)||P.isFile(t)||P.isBlob(t)||P.isReadableStream(t))return t;if(P.isArrayBufferView(t))return t.buffer;if(P.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 xm(t,this.formSerializer).toString();if((a=P.isFileList(t))||r.indexOf("multipart/form-data")>-1){const c=this.env&&this.env.FormData;return Zr(a?{"files[]":t}:t,c&&new c,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),bm(t)):t}],transformResponse:[function(t){const n=this.transitional||hr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(P.isResponse(t)||P.isReadableStream(t))return t;if(t&&P.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"?Ie.from(a,Ie.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:dt.classes.FormData,Blob:dt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};P.forEach(["delete","get","head","post","put","patch"],e=>{hr.headers[e]={}});const ym=P.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"]),Sm=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
31
|
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&ym[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},ol=Symbol("internals");function pr(e){return e&&String(e).trim().toLowerCase()}function Qr(e){return e===!1||e==null?e:P.isArray(e)?e.map(Qr):String(e)}function Cm(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 Tm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Ds(e,t,n,r,o){if(P.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!P.isString(t)){if(P.isString(r))return t.indexOf(r)!==-1;if(P.isRegExp(r))return r.test(t)}}function Em(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function km(e,t){const n=P.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 wt=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,c,u){const d=pr(c);if(!d)throw new Error("header name must be a non-empty string");const f=P.findKey(o,d);(!f||o[f]===void 0||u===!0||u===void 0&&o[f]!==!1)&&(o[f||c]=Qr(a))}const i=(a,c)=>P.forEach(a,(u,d)=>s(u,d,c));if(P.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(P.isString(t)&&(t=t.trim())&&!Tm(t))i(Sm(t),n);else if(P.isObject(t)&&P.isIterable(t)){let a={},c,u;for(const d of t){if(!P.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[u=d[0]]=(c=a[u])?P.isArray(c)?[...c,d[1]]:[c,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=pr(t),t){const r=P.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Cm(o);if(P.isFunction(n))return n.call(this,o,r);if(P.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=pr(t),t){const r=P.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Ds(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=pr(i),i){const a=P.findKey(r,i);a&&(!n||Ds(r,r[a],a,n))&&(delete r[a],o=!0)}}return P.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||Ds(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return P.forEach(this,(o,s)=>{const i=P.findKey(r,s);if(i){n[i]=Qr(o),delete n[s];return}const a=t?Em(s):String(s).trim();a!==s&&delete n[s],n[a]=Qr(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return P.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&P.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[ol]=this[ol]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=pr(i);r[a]||(km(o,i),r[a]=!0)}return P.isArray(t)?t.forEach(s):s(t),this}};wt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),P.reduceDescriptors(wt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),P.freezeMethods(wt);function Ls(e,t){const n=this||hr,r=t||n,o=wt.from(r.headers);let s=r.data;return P.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function sl(e){return!!(e&&e.__CANCEL__)}function Kn(e,t,n){Ie.call(this,e??"canceled",Ie.ERR_CANCELED,t,n),this.name="CanceledError"}P.inherits(Kn,Ie,{__CANCEL__:!0});function il(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Ie("Request failed with status code "+n.status,[Ie.ERR_BAD_REQUEST,Ie.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Im(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Nm(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(c){const u=Date.now(),d=r[s];i||(i=u),n[o]=c,r[o]=u;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),u-i<t)return;const m=d&&u-d;return m?Math.round(h*1e3/m):void 0}}function Am(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const eo=(e,t,n=3)=>{let r=0;const o=Nm(50,250);return Am(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,c=i-r,u=o(c),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:c,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},al=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},ll=e=>(...t)=>P.asap(()=>e(...t)),_m=dt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,dt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(dt.origin),dt.navigator&&/(msie|trident)/i.test(dt.navigator.userAgent)):()=>!0,jm=dt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];P.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),P.isString(r)&&i.push("path="+r),P.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 Rm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Pm(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function cl(e,t,n){let r=!Rm(t);return e&&(r||n==!1)?Pm(e,t):t}const ul=e=>e instanceof wt?{...e}:e;function kn(e,t){t=t||{};const n={};function r(u,d,f,h){return P.isPlainObject(u)&&P.isPlainObject(d)?P.merge.call({caseless:h},u,d):P.isPlainObject(d)?P.merge({},d):P.isArray(d)?d.slice():d}function o(u,d,f,h){if(P.isUndefined(d)){if(!P.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!P.isUndefined(d))return r(void 0,d)}function i(u,d){if(P.isUndefined(d)){if(!P.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const c={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:(u,d,f)=>o(ul(u),ul(d),f,!0)};return P.forEach(Object.keys({...e,...t}),function(d){const f=c[d]||o,h=f(e[d],t[d],d);P.isUndefined(h)&&f!==a||(n[d]=h)}),n}const dl=e=>{const t=kn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=wt.from(i),t.url=el(cl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),P.isFormData(n)){if(dt.hasStandardBrowserEnv||dt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(P.isFunction(n.getHeaders)){const c=n.getHeaders(),u=["content-type","content-length"];Object.entries(c).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(dt.hasStandardBrowserEnv&&(r&&P.isFunction(r)&&(r=r(t)),r||r!==!1&&_m(t.url))){const c=o&&s&&jm.read(s);c&&i.set(o,c)}return t},Om=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=dl(e);let s=o.data;const i=wt.from(o.headers).normalize();let{responseType:a,onUploadProgress:c,onDownloadProgress:u}=o,d,f,h,m,w;function v(){m&&m(),w&&w(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function x(){if(!g)return;const S=wt.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};il(function(I){n(I),v()},function(I){r(I),v()},C),g=null}"onloadend"in g?g.onloadend=x:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(x)},g.onabort=function(){g&&(r(new Ie("Request aborted",Ie.ECONNABORTED,e,g)),g=null)},g.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new Ie(C,Ie.ERR_NETWORK,e,g);T.event=k||null,r(T),g=null},g.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||nl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Ie(k,C.clarifyTimeoutError?Ie.ETIMEDOUT:Ie.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&P.forEach(i.toJSON(),function(k,C){g.setRequestHeader(C,k)}),P.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,w]=eo(u,!0),g.addEventListener("progress",h)),c&&g.upload&&([f,m]=eo(c),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",m)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new Kn(null,e,g):S),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Im(o.url);if(b&&dt.protocols.indexOf(b)===-1){r(new Ie("Unsupported protocol "+b+":",Ie.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Mm=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof Ie?d:new Kn(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Ie(`timeout ${t} of ms exceeded`,Ie.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:c}=r;return c.unsubscribe=()=>P.asap(a),c}},Dm=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},Lm=async function*(e,t){for await(const n of $m(e))yield*Dm(n,t)},$m=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()}},fl=(e,t,n,r)=>{const o=Lm(e,t);let s=0,i,a=c=>{i||(i=!0,r&&r(c))};return new ReadableStream({async pull(c){try{const{done:u,value:d}=await o.next();if(u){a(),c.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}c.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(c){return a(c),o.return()}},{highWaterMark:2})},hl=64*1024,{isFunction:to}=P,Fm=(({Request:e,Response:t})=>({Request:e,Response:t}))(P.global),{ReadableStream:pl,TextEncoder:ml}=P.global,gl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},zm=e=>{e=P.merge.call({skipUndefined:!0},Fm,e);const{fetch:t,Request:n,Response:r}=e,o=t?to(t):typeof fetch=="function",s=to(n),i=to(r);if(!o)return!1;const a=o&&to(pl),c=o&&(typeof ml=="function"?(w=>v=>w.encode(v))(new ml):async w=>new Uint8Array(await new n(w).arrayBuffer())),u=s&&a&&gl(()=>{let w=!1;const v=new n(dt.origin,{body:new pl,method:"POST",get duplex(){return w=!0,"half"}}).headers.has("Content-Type");return w&&!v}),d=i&&a&&gl(()=>P.isReadableStream(new r("").body)),f={stream:d&&(w=>w.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(w=>{!f[w]&&(f[w]=(v,g)=>{let x=v&&v[w];if(x)return x.call(v);throw new Ie(`Response type '${w}' is not supported`,Ie.ERR_NOT_SUPPORT,g)})});const h=async w=>{if(w==null)return 0;if(P.isBlob(w))return w.size;if(P.isSpecCompliantForm(w))return(await new n(dt.origin,{method:"POST",body:w}).arrayBuffer()).byteLength;if(P.isArrayBufferView(w)||P.isArrayBuffer(w))return w.byteLength;if(P.isURLSearchParams(w)&&(w=w+""),P.isString(w))return(await c(w)).byteLength},m=async(w,v)=>{const g=P.toFiniteNumber(w.getContentLength());return g??h(v)};return async w=>{let{url:v,method:g,data:x,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:N,withCredentials:_="same-origin",fetchOptions:j}=dl(w),R=t||fetch;I=I?(I+"").toLowerCase():"text";let $=Mm([b,S&&S.toAbortSignal()],k),z=null;const O=$&&$.unsubscribe&&(()=>{$.unsubscribe()});let V;try{if(T&&u&&g!=="get"&&g!=="head"&&(V=await m(N,x))!==0){let H=new n(v,{method:"POST",body:x,duplex:"half"}),Y;if(P.isFormData(x)&&(Y=H.headers.get("content-type"))&&N.setContentType(Y),H.body){const[Q,le]=al(V,eo(ll(T)));x=fl(H.body,hl,Q,le)}}P.isString(_)||(_=_?"include":"omit");const B=s&&"credentials"in n.prototype,K={...j,signal:$,method:g.toUpperCase(),headers:N.normalize().toJSON(),body:x,duplex:"half",credentials:B?_:void 0};z=s&&new n(v,K);let L=await(s?R(z,j):R(v,K));const A=d&&(I==="stream"||I==="response");if(d&&(C||A&&O)){const H={};["status","statusText","headers"].forEach(xe=>{H[xe]=L[xe]});const Y=P.toFiniteNumber(L.headers.get("content-length")),[Q,le]=C&&al(Y,eo(ll(C),!0))||[];L=new r(fl(L.body,hl,Q,()=>{le&&le(),O&&O()}),H)}I=I||"text";let D=await f[P.findKey(f,I)||"text"](L,w);return!A&&O&&O(),await new Promise((H,Y)=>{il(H,Y,{data:D,headers:wt.from(L.headers),status:L.status,statusText:L.statusText,config:w,request:z})})}catch(B){throw O&&O(),B&&B.name==="TypeError"&&/Load failed|fetch/i.test(B.message)?Object.assign(new Ie("Network Error",Ie.ERR_NETWORK,w,z),{cause:B.cause||B}):Ie.from(B,B&&B.code,w,z)}}},Bm=new Map,xl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,c,u,d=Bm;for(;a--;)c=s[a],u=d.get(c),u===void 0&&d.set(c,u=a?new Map:zm(t)),d=u;return u};xl();const $s={http:cm,xhr:Om,fetch:{get:xl}};P.forEach($s,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const vl=e=>`- ${e}`,Hm=e=>P.isFunction(e)||e===null||e===!1,wl={getAdapter:(e,t)=>{e=P.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,!Hm(r)&&(o=$s[(a=String(r)).toLowerCase()],o===void 0))throw new Ie(`Unknown adapter '${a}'`);if(o&&(P.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([c,u])=>`adapter ${c} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
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[ol]=this[ol]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=pr(i);r[a]||(km(o,i),r[a]=!0)}return P.isArray(t)?t.forEach(s):s(t),this}};wt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),P.reduceDescriptors(wt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),P.freezeMethods(wt);function Ls(e,t){const n=this||hr,r=t||n,o=wt.from(r.headers);let s=r.data;return P.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function sl(e){return!!(e&&e.__CANCEL__)}function Kn(e,t,n){Ie.call(this,e??"canceled",Ie.ERR_CANCELED,t,n),this.name="CanceledError"}P.inherits(Kn,Ie,{__CANCEL__:!0});function il(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Ie("Request failed with status code "+n.status,[Ie.ERR_BAD_REQUEST,Ie.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Im(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Nm(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(c){const u=Date.now(),d=r[s];i||(i=u),n[o]=c,r[o]=u;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),u-i<t)return;const m=d&&u-d;return m?Math.round(h*1e3/m):void 0}}function Am(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const eo=(e,t,n=3)=>{let r=0;const o=Nm(50,250);return Am(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,c=i-r,u=o(c),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:c,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},al=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},ll=e=>(...t)=>P.asap(()=>e(...t)),_m=dt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,dt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(dt.origin),dt.navigator&&/(msie|trident)/i.test(dt.navigator.userAgent)):()=>!0,jm=dt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];P.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),P.isString(r)&&i.push("path="+r),P.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 Rm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Pm(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function cl(e,t,n){let r=!Rm(t);return e&&(r||n==!1)?Pm(e,t):t}const ul=e=>e instanceof wt?{...e}:e;function kn(e,t){t=t||{};const n={};function r(u,d,f,h){return P.isPlainObject(u)&&P.isPlainObject(d)?P.merge.call({caseless:h},u,d):P.isPlainObject(d)?P.merge({},d):P.isArray(d)?d.slice():d}function o(u,d,f,h){if(P.isUndefined(d)){if(!P.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!P.isUndefined(d))return r(void 0,d)}function i(u,d){if(P.isUndefined(d)){if(!P.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const c={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:(u,d,f)=>o(ul(u),ul(d),f,!0)};return P.forEach(Object.keys({...e,...t}),function(d){const f=c[d]||o,h=f(e[d],t[d],d);P.isUndefined(h)&&f!==a||(n[d]=h)}),n}const dl=e=>{const t=kn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=wt.from(i),t.url=el(cl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),P.isFormData(n)){if(dt.hasStandardBrowserEnv||dt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(P.isFunction(n.getHeaders)){const c=n.getHeaders(),u=["content-type","content-length"];Object.entries(c).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(dt.hasStandardBrowserEnv&&(r&&P.isFunction(r)&&(r=r(t)),r||r!==!1&&_m(t.url))){const c=o&&s&&jm.read(s);c&&i.set(o,c)}return t},Om=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=dl(e);let s=o.data;const i=wt.from(o.headers).normalize();let{responseType:a,onUploadProgress:c,onDownloadProgress:u}=o,d,f,h,m,w;function v(){m&&m(),w&&w(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function x(){if(!g)return;const S=wt.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};il(function(I){n(I),v()},function(I){r(I),v()},C),g=null}"onloadend"in g?g.onloadend=x:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(x)},g.onabort=function(){g&&(r(new Ie("Request aborted",Ie.ECONNABORTED,e,g)),g=null)},g.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new Ie(C,Ie.ERR_NETWORK,e,g);T.event=k||null,r(T),g=null},g.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||nl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Ie(k,C.clarifyTimeoutError?Ie.ETIMEDOUT:Ie.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&P.forEach(i.toJSON(),function(k,C){g.setRequestHeader(C,k)}),P.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,w]=eo(u,!0),g.addEventListener("progress",h)),c&&g.upload&&([f,m]=eo(c),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",m)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new Kn(null,e,g):S),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Im(o.url);if(b&&dt.protocols.indexOf(b)===-1){r(new Ie("Unsupported protocol "+b+":",Ie.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Mm=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof Ie?d:new Kn(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Ie(`timeout ${t} of ms exceeded`,Ie.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:c}=r;return c.unsubscribe=()=>P.asap(a),c}},Dm=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},Lm=async function*(e,t){for await(const n of $m(e))yield*Dm(n,t)},$m=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()}},fl=(e,t,n,r)=>{const o=Lm(e,t);let s=0,i,a=c=>{i||(i=!0,r&&r(c))};return new ReadableStream({async pull(c){try{const{done:u,value:d}=await o.next();if(u){a(),c.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}c.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(c){return a(c),o.return()}},{highWaterMark:2})},hl=64*1024,{isFunction:to}=P,Fm=(({Request:e,Response:t})=>({Request:e,Response:t}))(P.global),{ReadableStream:pl,TextEncoder:ml}=P.global,gl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},zm=e=>{e=P.merge.call({skipUndefined:!0},Fm,e);const{fetch:t,Request:n,Response:r}=e,o=t?to(t):typeof fetch=="function",s=to(n),i=to(r);if(!o)return!1;const a=o&&to(pl),c=o&&(typeof ml=="function"?(w=>v=>w.encode(v))(new ml):async w=>new Uint8Array(await new n(w).arrayBuffer())),u=s&&a&&gl(()=>{let w=!1;const v=new n(dt.origin,{body:new pl,method:"POST",get duplex(){return w=!0,"half"}}).headers.has("Content-Type");return w&&!v}),d=i&&a&&gl(()=>P.isReadableStream(new r("").body)),f={stream:d&&(w=>w.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(w=>{!f[w]&&(f[w]=(v,g)=>{let x=v&&v[w];if(x)return x.call(v);throw new Ie(`Response type '${w}' is not supported`,Ie.ERR_NOT_SUPPORT,g)})});const h=async w=>{if(w==null)return 0;if(P.isBlob(w))return w.size;if(P.isSpecCompliantForm(w))return(await new n(dt.origin,{method:"POST",body:w}).arrayBuffer()).byteLength;if(P.isArrayBufferView(w)||P.isArrayBuffer(w))return w.byteLength;if(P.isURLSearchParams(w)&&(w=w+""),P.isString(w))return(await c(w)).byteLength},m=async(w,v)=>{const g=P.toFiniteNumber(w.getContentLength());return g??h(v)};return async w=>{let{url:v,method:g,data:x,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:N,withCredentials:_="same-origin",fetchOptions:R}=dl(w),j=t||fetch;I=I?(I+"").toLowerCase():"text";let $=Mm([b,S&&S.toAbortSignal()],k),z=null;const O=$&&$.unsubscribe&&(()=>{$.unsubscribe()});let V;try{if(T&&u&&g!=="get"&&g!=="head"&&(V=await m(N,x))!==0){let H=new n(v,{method:"POST",body:x,duplex:"half"}),Y;if(P.isFormData(x)&&(Y=H.headers.get("content-type"))&&N.setContentType(Y),H.body){const[Z,le]=al(V,eo(ll(T)));x=fl(H.body,hl,Z,le)}}P.isString(_)||(_=_?"include":"omit");const B=s&&"credentials"in n.prototype,K={...R,signal:$,method:g.toUpperCase(),headers:N.normalize().toJSON(),body:x,duplex:"half",credentials:B?_:void 0};z=s&&new n(v,K);let L=await(s?j(z,R):j(v,K));const A=d&&(I==="stream"||I==="response");if(d&&(C||A&&O)){const H={};["status","statusText","headers"].forEach(xe=>{H[xe]=L[xe]});const Y=P.toFiniteNumber(L.headers.get("content-length")),[Z,le]=C&&al(Y,eo(ll(C),!0))||[];L=new r(fl(L.body,hl,Z,()=>{le&&le(),O&&O()}),H)}I=I||"text";let D=await f[P.findKey(f,I)||"text"](L,w);return!A&&O&&O(),await new Promise((H,Y)=>{il(H,Y,{data:D,headers:wt.from(L.headers),status:L.status,statusText:L.statusText,config:w,request:z})})}catch(B){throw O&&O(),B&&B.name==="TypeError"&&/Load failed|fetch/i.test(B.message)?Object.assign(new Ie("Network Error",Ie.ERR_NETWORK,w,z),{cause:B.cause||B}):Ie.from(B,B&&B.code,w,z)}}},Bm=new Map,xl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,c,u,d=Bm;for(;a--;)c=s[a],u=d.get(c),u===void 0&&d.set(c,u=a?new Map:zm(t)),d=u;return u};xl();const $s={http:cm,xhr:Om,fetch:{get:xl}};P.forEach($s,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const vl=e=>`- ${e}`,Hm=e=>P.isFunction(e)||e===null||e===!1,wl={getAdapter:(e,t)=>{e=P.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,!Hm(r)&&(o=$s[(a=String(r)).toLowerCase()],o===void 0))throw new Ie(`Unknown adapter '${a}'`);if(o&&(P.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([c,u])=>`adapter ${c} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
33
|
`+i.map(vl).join(`
|
|
34
34
|
`):" "+vl(i[0]):"as no adapter specified";throw new Ie("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:$s};function Fs(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Kn(null,e)}function bl(e){return Fs(e),e.headers=wt.from(e.headers),e.data=Ls.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),wl.getAdapter(e.adapter||hr.adapter,e)(e).then(function(r){return Fs(e),r.data=Ls.call(e,e.transformResponse,r),r.headers=wt.from(r.headers),r},function(r){return sl(r)||(Fs(e),r&&r.response&&(r.response.data=Ls.call(e,e.transformResponse,r.response),r.response.headers=wt.from(r.response.headers))),Promise.reject(r)})}const yl="1.12.2",no={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{no[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Sl={};no.transitional=function(t,n,r){function o(s,i){return"[Axios v"+yl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Ie(o(i," has been removed"+(n?" in "+n:"")),Ie.ERR_DEPRECATED);return n&&!Sl[i]&&(Sl[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}},no.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Um(e,t,n){if(typeof e!="object")throw new Ie("options must be an object",Ie.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],c=a===void 0||i(a,s,e);if(c!==!0)throw new Ie("option "+s+" must be "+c,Ie.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Ie("Unknown option "+s,Ie.ERR_BAD_OPTION)}}const ro={assertOptions:Um,validators:no},Vt=ro.validators;let In=class{constructor(t){this.defaults=t||{},this.interceptors={request:new tl,response:new tl}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=kn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ro.assertOptions(r,{silentJSONParsing:Vt.transitional(Vt.boolean),forcedJSONParsing:Vt.transitional(Vt.boolean),clarifyTimeoutError:Vt.transitional(Vt.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:ro.assertOptions(o,{encode:Vt.function,serialize:Vt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ro.assertOptions(n,{baseUrl:Vt.spelling("baseURL"),withXsrfToken:Vt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=wt.concat(i,s);const a=[];let c=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(n)===!1||(c=c&&v.synchronous,a.unshift(v.fulfilled,v.rejected))});const u=[];this.interceptors.response.forEach(function(v){u.push(v.fulfilled,v.rejected)});let d,f=0,h;if(!c){const w=[bl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let m=n;for(;f<h;){const w=a[f++],v=a[f++];try{m=w(m)}catch(g){v.call(this,g);break}}try{d=bl.call(this,m)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=kn(this.defaults,t);const n=cl(t.baseURL,t.url,t.allowAbsoluteUrls);return el(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){In.prototype[t]=function(n,r){return this.request(kn(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(kn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}In.prototype[t]=n(),In.prototype[t+"Form"]=n(!0)});let Wm=class bp{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 Kn(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 bp(function(o){t=o}),cancel:t}}};function Vm(e){return function(n){return e.apply(null,n)}}function Km(e){return P.isObject(e)&&e.isAxiosError===!0}const zs={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(zs).forEach(([e,t])=>{zs[t]=e});function Cl(e){const t=new In(e),n=Fa(In.prototype.request,t);return P.extend(n,In.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Cl(kn(e,o))},n}const rt=Cl(hr);rt.Axios=In,rt.CanceledError=Kn,rt.CancelToken=Wm,rt.isCancel=sl,rt.VERSION=yl,rt.toFormData=Zr,rt.AxiosError=Ie,rt.Cancel=rt.CanceledError,rt.all=function(t){return Promise.all(t)},rt.spread=Vm,rt.isAxiosError=Km,rt.mergeConfig=kn,rt.AxiosHeaders=wt,rt.formToJSON=e=>rl(P.isHTMLForm(e)?new FormData(e):e),rt.getAdapter=wl.getAdapter,rt.HttpStatusCode=zs,rt.default=rt;const{Axios:IC,AxiosError:NC,CanceledError:AC,isCancel:_C,CancelToken:jC,VERSION:RC,all:PC,Cancel:OC,isAxiosError:MC,spread:DC,toFormData:LC,AxiosHeaders:$C,HttpStatusCode:FC,formToJSON:zC,getAdapter:BC,mergeConfig:HC}=rt,Tl=typeof window<"u"?window.__API_BASE_URL__:void 0,El=Tl?Tl.replace(/\/+$/,""):void 0;let oo=null;const Bs=new Set;function kl(){return oo}function Hs(e){oo=e,Bs.forEach(t=>t(e))}function Il(e){return Bs.add(e),()=>Bs.delete(e)}const jt=rt.create({...El?{baseURL:El}:{},timeout:3e4,withCredentials:!0});jt.interceptors.request.use(e=>(oo&&(e.headers.Authorization=`Bearer ${oo}`),e)),jt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Ct(e,t){return jt.defaults.baseURL?(await jt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Us(e,t,n){return jt.defaults.baseURL?(await jt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Nl(e,t,n){return jt.defaults.baseURL?(await jt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Al(e,t){return jt.defaults.baseURL?(await jt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Tt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class _l{get baseUrl(){const t=jt.defaults.baseURL||"";return String(t).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(t){t.baseUrl&&(jt.defaults.baseURL=String(t.baseUrl).replace(/\/+$/g,"")),t.authToken!==void 0&&Hs(t.authToken)}getAuthToken(){return kl()}setAuthToken(t){Hs(t)}onTokenChange(t){return Il(t)}async listThreads(){const t=await Ct("/chat/threads"),n=Tt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Us("/chat/threads",t?{title:t}:void 0);return Tt(r)}async updateThread(t,n){const r=await Nl(`/chat/threads/${t}`,{title:n});return Tt(r)}async deleteThread(t){const n=await Al(`/chat/threads/${t}`);return Tt(n)}async threadInfo(t){const n=await Ct(`/chat/threads/${t}/info`);return Tt(n)}async listAgents(){const t=await Ct("/chat/agents"),n=Tt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Ct(`/chat/agents/${t}`);return Tt(n)}async getAgentSchema(t){const n=await Ct(`/chat/agents/${t}/schema`);return Tt(n)}async getMessages(t){const n=await Ct(`/chat/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return Tt(n)}async getState(t){const n=await Ct(`/chat/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Tt(n)}async getStateHistory(t){const n=await Ct(`/chat/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Tt(n)}async listCheckpoints(t){const n=await Ct(`/chat/threads/${t}/checkpoints`,{params:{thread_id:t}});return Tt(n)}async resume(t){const n=await Us("/chat/runs/resume",{thread_id:t.threadId,value:t.value});return Tt(n)}}const un=new _l,jl=y.createContext(null);function qm({children:e,apiConfig:t}){const n=un;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 l.jsx(jl.Provider,{value:r,children:e})}function so(){const e=y.useContext(jl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}const Rl=y.createContext(null),Pl=y.createContext(null);function Gm(e,t){switch(t.type){case"STREAM_START":return{...e,isStreaming:!0,error:null,streamingAssistantId:t.assistantId??null};case"STREAM_END":return{...e,isStreaming:!1,streamingAssistantId:null};case"STREAM_ERROR":return{...e,isStreaming:!1,error:t.error};case"UPDATE_CHECKPOINT":return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:t.checkpointNs??e.lastCheckpointNs};case"UPDATE_ASSEMBLING_ID":return{...e,streamingAssistantId:t.assistantId};case"CLEAR_ERROR":return{...e,error:null};default:return e}}const Ym={isStreaming:!1,error:null,streamingAssistantId:null,lastCheckpointId:null,lastCheckpointNs:null};function Xm({children:e}){const[t,n]=y.useReducer(Gm,Ym);return l.jsx(Pl.Provider,{value:n,children:l.jsx(Rl.Provider,{value:t,children:e})})}function Ol(){const e=y.useContext(Rl);if(!e)throw new Error("useStream must be used within StreamProvider");return e}function Jm(){const e=y.useContext(Pl);if(!e)throw new Error("useStreamDispatch must be used within StreamProvider");return e}function Zm(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function Qm(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 c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function eg(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await Qm(c);a.push({filename:c.name,data:u,mime_type:c.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Ml=y.createContext(null),Dl=y.createContext(null);function tg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,onThreadChange:o,onError:s}){const{api:i}=so(),[a,c]=y.useState([]),[u,d]=y.useState(t),[f,h]=y.useState(!1),[m,w]=y.useState(!1),[v,g]=y.useState(void 0),[x,b]=y.useState(void 0),S=y.useRef(!1),k=y.useRef([]),C=y.useRef(null),T=y.useRef(null);y.useRef(!1);const I=y.useRef(u);y.useEffect(()=>{I.current=u},[u]);const N=y.useContext(Dl),_=y.useCallback((D,H)=>new Promise((Y,Q)=>{const le=async()=>{S.current=!0;try{console.log(`[ThreadProvider] Executing operation: ${H||"unnamed"}`),await D(),Y()}catch(xe){console.error(`[ThreadProvider] Operation "${H}" failed:`,xe),Q(xe)}finally{S.current=!1;const xe=k.current.shift();xe&&xe().catch(()=>{})}};S.current?(k.current.push(le),console.log(`[ThreadProvider] Queued operation: ${H||"unnamed"}`)):le().catch(xe=>{Q(xe)})}),[]),j=y.useCallback(async()=>{h(!0);try{const D=await i.listThreads();c(D)}catch(D){console.error("[ThreadProvider] Failed to refresh threads:",D),s==null||s(String(D))}finally{h(!1)}},[i,s]),R=y.useCallback(async D=>{const H=await i.createThread(D),Y=typeof H=="string"?H:H.threadId;return await j(),d(Y),Y},[i,j]),$=y.useCallback(async D=>{await i.deleteThread(D),u===D&&(d(null),N==null||N.onThreadCleared()),await j()},[i,u,j,N]),z=y.useCallback(async(D,H)=>{try{await i.updateThread(D,H),c(Y=>Y.map(Q=>Q.threadId===D?{...Q,title:H}:Q))}catch(Y){throw await j(),Y}},[i,j]),O=y.useCallback(async(D,H,Y,Q=!1)=>{await _(async()=>{if(T.current===D&&!Q){console.log("[ThreadProvider] Skipping load for thread:",D),T.current=null;return}if(C.current===D&&!Q){console.log("[ThreadProvider] Load already in progress for thread:",D);return}d(le=>le===D?le:D),C.current=D,w(!0);try{const le=await i.getMessages({threadId:D,checkpointId:H,checkpointNs:Y});N==null||N.onThreadLoaded(D,le),g((le==null?void 0:le.checkpointId)??void 0),b((le==null?void 0:le.checkpointNs)??void 0)}finally{C.current=null,w(!1)}},`loadThread-${D}`)},[i,_,N,d]),V=y.useCallback(async()=>{console.log("[ThreadProvider] 🔄 clearCurrentThread called"),await _(async()=>{u&&(T.current=u),N==null||N.onThreadCleared(),d(null),g(void 0),b(void 0);try{localStorage.removeItem("lastThreadId")}catch(D){console.warn("[ThreadProvider] Failed to clear localStorage:",D)}},"clearCurrentThread")},[u,_,N]),B=y.useCallback(async D=>{const H=await i.listCheckpoints(D);return Zm(H,D)},[i]),K=y.useCallback(async(D,H)=>{if(!u)throw new Error("No active thread");await O(u,D,H??void 0,!0)},[u,O]),L=y.useCallback(async()=>{if(!u)throw new Error("No active thread");await O(u,void 0,void 0,!0)},[u,O]);y.useEffect(()=>{if(o==null||o(u),u)try{localStorage.setItem("lastThreadId",u)}catch(D){console.warn("[ThreadProvider] Failed to persist thread ID:",D)}},[u,o]),y.useEffect(()=>{let D=!0;return(async()=>{try{if(await j(),!D)return;if(!r&&!t)try{const Y=localStorage.getItem("lastThreadId");Y&&(d(Y),n&&await O(Y))}catch(Y){console.warn("[ThreadProvider] Failed to restore from localStorage:",Y)}else t&&n&&await O(t)}catch(Y){console.error("[ThreadProvider] Initialization failed:",Y),s==null||s(String(Y))}})(),()=>{D=!1}},[]);const A={threads:a,currentThreadId:u,isLoadingThreads:f,isLoadingThread:m,setCurrentThreadId:d,createThread:R,deleteThread:$,renameThread:z,refreshThreads:j,loadThread:O,clearCurrentThread:V,listCheckpoints:B,navigateToCheckpoint:K,returnToLatest:L};return l.jsx(Ml.Provider,{value:A,children:e})}function mr(){const e=y.useContext(Ml);if(!e)throw new Error("useThreads must be used within ThreadProvider");return e}function ng({children:e,onThreadLoaded:t,onThreadCleared:n,...r}){return l.jsx(Dl.Provider,{value:{onThreadLoaded:t,onThreadCleared:n},children:l.jsx(tg,{...r,children:e})})}function rg(e){return e.type!=="thread_info"&&e.type!=="token"}const og={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function sg(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:Ws(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=Ws(t.payload.messages),o={...e,messages:r,assemblingId: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),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Ws(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),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 $l(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>$l(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function Ll(e=[]){const[t,n]=y.useReducer(sg,{...og,messages:e}),r=y.useRef([]),o=y.useRef(null),s=y.useRef(null),i=y.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=y.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]),c=y.useCallback(d=>{r.current.push(d),a()},[a]);y.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=y.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:c}),[c]);return{state:t,dispatch:n,...u}}function $l(e,t){var n,r;if(t.type==="message_start"&&t.role==="assistant"){const o=t.id,s=dg(t.model);if(e.messages.some(c=>c.id===o))return{...e,assemblingId:o};const a={id:o,role:"assistant",name:s||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:o,messages:[...e.messages,a]}}if(t.type==="message_delta"){const o=e.assemblingId??Vs(e.messages);return o?{...e,messages:Ks(e.messages,o,t.delta)}:e}if(t.type==="message_end"){const o=e.assemblingId??Vs(e.messages);if(!o)return{...e,assemblingId:null};const s=e.messages,i=s.findIndex(a=>a.id===o&&a.role==="assistant");if(i>=0&&!((n=s[i].content)==null?void 0:n.some(u=>{var d;return(u==null?void 0:u.type)==="text"&&((d=u.text)==null?void 0:d.trim())}))){const u=[...s.slice(0,i),...s.slice(i+1)];return{...e,assemblingId:null,messages:u}}return e}if(t.type==="tool_start"){const o=t.id??t.call_id,s=t.name??t.tool??"tool";if(!o)return e;const i=`tool-${o}`,a={type:"tool_call",id:o,name:s,args:t.args};if(e.messages.find(d=>d.id===i))return{...e,toolIndex:{...e.toolIndex,[o]:i}};const u={id:i,role:"tool",name:s,createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,u],toolIndex:{...e.toolIndex,[o]:i}}}if(t.type==="tool_end"){const o=t.id??t.call_id;if(!o)return e;const s=e.toolIndex[o]??`tool-${o}`,i={type:"tool_end",toolCallId:o,output:t.output,error:t.error},a=e.messages.find(d=>d.id===s),c={id:s,role:"tool",name:t.name??((r=e.messages.find(d=>d.id===s))==null?void 0:r.name),content:[i],createdAt:new Date().toISOString()},u=a?Ks(e.messages,s,[i]):[...e.messages,c];return{...e,messages:u,toolIndex:{...e.toolIndex,[o]:s}}}if(t.type==="checkpoint"){const o=t.checkpointNs??e.lastCheckpointNs??null,s=ug(e.messages,t.checkpointId,o);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:o,messages:s}}if(t.type==="branch"){const o=t.checkpointId??e.lastCheckpointId,s=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:o??null,lastCheckpointNs:s??null}}if(t.type==="error"){const o={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,o]}}if(t.type==="interrupt"){const o=e.assemblingId??Vs(e.messages),s={type:"interrupt",value:t.value};if(o)return{...e,assemblingId:null,messages:Ks(e.messages,o,[s]),pendingInterrupt:{id:t.id,value:t.value}};const i={id:`interrupt-${t.id}`,role:"system",createdAt:new Date().toISOString(),content:[s]};return{...e,messages:[...e.messages,i],pendingInterrupt:{id:t.id,value:t.value}}}return e}function Ws(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 ig(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Vs(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function ag(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function Ks(e,t,n){return ag(e,t,r=>({...r,content:lg(r.content,n)}))}function lg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){const i=o,a=i.text??"",c=cg(a,s);if(!c){s.length<a.length&&(i.text=s);continue}const u=Fl(a),d=Fl(s);c===s&&(s.length<=a.length||!!a&&!!s&&s[0]===a[0]||!!u&&u===d)?i.text=s:i.text=a+c}else n.push({type:"text",text:s})}else n.push(r);return n}function cg(e,t){if(!t)return"";if(!e)return t;if(t===e)return"";const n=t.indexOf(e);if(n===0)return t.slice(e.length);if(n>0){const o=t.slice(n+e.length);if(o)return o}if(e.endsWith(t)||e.includes(t))return"";const r=Math.min(e.length,t.length);for(let o=r;o>0;o--)if(e.slice(-o)===t.slice(0,o))return t.slice(o);return t}function Fl(e){return e.replace(/[\s\.,;:!?"'`-]/g,"").toLowerCase()}function ug(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 ig(e,r,s)}return e}function dg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const fg={MODE:"library"};function hg(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ns&&Ns.tagName.toUpperCase()==="SCRIPT"&&Ns.src||new URL("index.umd.js",document.baseURI).href}<"u"?fg:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function pg(){return!hg()}function mg({onThreadInfo:e,onMessageEvent:t,onUnhandledEvent:n,onSequenceGap:r}){const o=y.useRef(null),s=y.useCallback(a=>{const c=a.seq;if(c!=null){const u=o.current;if(u!==null){if(c<=u){pg()&&console.debug("[StreamEventCoordinator] drop out-of-order seq",{prev:u,seq:c,type:a.type});return}c>u+1&&(r==null||r({from:u,to:c}))}o.current=c}if(a.type==="thread_info"){e==null||e(a);return}if(rg(a)){t(a);return}n==null||n(a)},[t,r,e,n]),i=y.useCallback(()=>{o.current=null},[]);return{handleEvent:s,reset:i}}function zl(e={}){const t=y.useMemo(()=>{const j=(e.baseUrl??"/api/chat").replace(/\/+$/,"");return j.endsWith("/chat")?j:`${j}/chat`},[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=y.useState(e.token??null),s=y.useRef(e.headers??{}),[i,a]=y.useState(!1),[c,u]=y.useState(null),[d,f]=y.useState(""),[h,m]=y.useState(null),[w,v]=y.useState(0),[g,x]=y.useState(!1),b=y.useRef(null),S=y.useRef(!0),k=y.useRef(0),C=y.useCallback(_=>{o(_)},[]),T=y.useCallback(()=>{var _;(_=b.current)==null||_.abort(),b.current=null,a(!1),x(!1)},[]),I=y.useCallback(()=>{f(""),m(null),u(null)},[]),N=y.useCallback((_,j,R)=>{b.current&&(b.current.abort(),b.current=null),a(!0),u(null),e.autoAppendAssistant!==!1&&f("");const $=new AbortController;return b.current=$,(async()=>{var O,V,B,K,L,A,D,H;const z=Y=>{var Q;try{const le=JSON.parse(JSON.stringify(Y));return(Q=le==null?void 0:le.payload)!=null&&Q.files_info&&Array.isArray(le.payload.files_info)&&(le.payload.files_info=le.payload.files_info.map(xe=>({...xe,data:xe!=null&&xe.data?`<base64 ${String(xe.data).length} chars>`:xe==null?void 0:xe.data}))),le}catch{return Y}};try{let Y={};try{if(r)Y={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Re=window.__AUTH_TOKEN__,We=((O=window.localStorage)==null?void 0:O.getItem("authToken"))||null;let J=null;try{const Ne=(V=window.localStorage)==null?void 0:V.getItem("chat-settings");Ne&&(J=((B=JSON.parse(Ne))==null?void 0:B.apiKey)||null)}catch{}const X=Re||We||J||null;X&&(Y={Authorization:`Bearer ${X}`})}}catch{}console.debug("[use-chat] POST",t+n,z(_));const Q=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...Y,...s.current},body:JSON.stringify(_),signal:$.signal});if(!Q.ok||!Q.body){const _e=await Q.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",Q.status,_e==null?void 0:_e.slice(0,500)),new Error(`stream ${Q.status}${_e?": "+_e:""}`)}x(!0);const le=Q.body.getReader(),xe=new TextDecoder;let Ee="",W=[],M=k.current,G=null;const te=()=>{if(W.length){const _e=W.join("");W=[],S.current&&f(Re=>Re+_e)}G=null},de=()=>{typeof window<"u"&&G==null&&(G=requestAnimationFrame(te))};let ce=Date.now();const $e=setInterval(()=>{var _e;if(Date.now()-ce>2e4){const Re="Stream idle timeout";u(Re),$.abort(),(_e=R==null?void 0:R.onError)==null||_e.call(R,Re)}},5e3),Ge=1024*1024;try{const _e=Q.headers.get("X-Thread-Id")||Q.headers.get("x-thread-id"),Re=Q.headers.get("X-Thread-Created")||Q.headers.get("x-thread-created"),We=_e??null,J=String(Re??"").toLowerCase()==="true";for((K=R==null?void 0:R.onOpen)==null||K.call(R,{threadId:We,created:J});;){const{value:X,done:Ne}=await le.read();if(Ne)break;Ee+=xe.decode(X,{stream:!0}),Ee.length>Ge&&(Ee="",console.warn("Stream buffer reset: exceeded 1MB"));let He;for(;(He=Ee.indexOf(`
|
|
35
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=kn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ro.assertOptions(r,{silentJSONParsing:Vt.transitional(Vt.boolean),forcedJSONParsing:Vt.transitional(Vt.boolean),clarifyTimeoutError:Vt.transitional(Vt.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:ro.assertOptions(o,{encode:Vt.function,serialize:Vt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ro.assertOptions(n,{baseUrl:Vt.spelling("baseURL"),withXsrfToken:Vt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=wt.concat(i,s);const a=[];let c=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(n)===!1||(c=c&&v.synchronous,a.unshift(v.fulfilled,v.rejected))});const u=[];this.interceptors.response.forEach(function(v){u.push(v.fulfilled,v.rejected)});let d,f=0,h;if(!c){const w=[bl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let m=n;for(;f<h;){const w=a[f++],v=a[f++];try{m=w(m)}catch(g){v.call(this,g);break}}try{d=bl.call(this,m)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=kn(this.defaults,t);const n=cl(t.baseURL,t.url,t.allowAbsoluteUrls);return el(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){In.prototype[t]=function(n,r){return this.request(kn(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(kn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}In.prototype[t]=n(),In.prototype[t+"Form"]=n(!0)});let Wm=class bp{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 Kn(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 bp(function(o){t=o}),cancel:t}}};function Vm(e){return function(n){return e.apply(null,n)}}function Km(e){return P.isObject(e)&&e.isAxiosError===!0}const zs={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(zs).forEach(([e,t])=>{zs[t]=e});function Cl(e){const t=new In(e),n=Fa(In.prototype.request,t);return P.extend(n,In.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Cl(kn(e,o))},n}const rt=Cl(hr);rt.Axios=In,rt.CanceledError=Kn,rt.CancelToken=Wm,rt.isCancel=sl,rt.VERSION=yl,rt.toFormData=Zr,rt.AxiosError=Ie,rt.Cancel=rt.CanceledError,rt.all=function(t){return Promise.all(t)},rt.spread=Vm,rt.isAxiosError=Km,rt.mergeConfig=kn,rt.AxiosHeaders=wt,rt.formToJSON=e=>rl(P.isHTMLForm(e)?new FormData(e):e),rt.getAdapter=wl.getAdapter,rt.HttpStatusCode=zs,rt.default=rt;const{Axios:IC,AxiosError:NC,CanceledError:AC,isCancel:_C,CancelToken:jC,VERSION:RC,all:PC,Cancel:OC,isAxiosError:MC,spread:DC,toFormData:LC,AxiosHeaders:$C,HttpStatusCode:FC,formToJSON:zC,getAdapter:BC,mergeConfig:HC}=rt,Tl=typeof window<"u"?window.__API_BASE_URL__:void 0,El=Tl?Tl.replace(/\/+$/,""):void 0;function kl(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let oo=null;const Bs=new Set;function Il(){return oo}function Hs(e){oo=e,Bs.forEach(t=>t(e))}function Nl(e){return Bs.add(e),()=>Bs.delete(e)}const jt=rt.create({...El?{baseURL:El}:{},timeout:3e4,withCredentials:!0});jt.interceptors.request.use(e=>(oo&&(e.headers.Authorization=`Bearer ${oo}`),e)),jt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Ct(e,t){return jt.defaults.baseURL?(await jt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Us(e,t,n){return jt.defaults.baseURL?(await jt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Al(e,t,n){return jt.defaults.baseURL?(await jt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function _l(e,t){return jt.defaults.baseURL?(await jt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Tt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class jl{get baseUrl(){const t=jt.defaults.baseURL||"";return String(t).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(t){t.baseUrl&&(jt.defaults.baseURL=String(t.baseUrl).replace(/\/+$/g,"")),t.authToken!==void 0&&Hs(t.authToken)}getAuthToken(){return Il()}setAuthToken(t){Hs(t)}onTokenChange(t){return Nl(t)}async listThreads(){const t=await Ct("/chat/threads"),n=Tt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Us("/chat/threads",t?{title:t}:void 0);return Tt(r)}async updateThread(t,n){const r=await Al(`/chat/threads/${t}`,{title:n});return Tt(r)}async deleteThread(t){const n=await _l(`/chat/threads/${t}`);return Tt(n)}async threadInfo(t){const n=await Ct(`/chat/threads/${t}/info`);return Tt(n)}async listAgents(){const t=await Ct("/chat/agents"),n=Tt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Ct(`/chat/agents/${t}`);return Tt(n)}async getAgentSchema(t){const n=await Ct(`/chat/agents/${t}/schema`);return Tt(n)}async getMessages(t){const n=await Ct(`/chat/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return Tt(n)}async getState(t){const n=await Ct(`/chat/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Tt(n)}async getStateHistory(t){const n=await Ct(`/chat/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Tt(n)}async listCheckpoints(t){const n=await Ct(`/chat/threads/${t}/checkpoints`,{params:{thread_id:t}});return Tt(n)}async resume(t){const n=await Us("/chat/runs/resume",{thread_id:t.threadId,value:t.value});return Tt(n)}}const un=new jl,Rl=y.createContext(null);function qm({children:e,apiConfig:t}){const n=un;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 l.jsx(Rl.Provider,{value:r,children:e})}function so(){const e=y.useContext(Rl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}const Pl=y.createContext(null),Ol=y.createContext(null);function Gm(e,t){switch(t.type){case"STREAM_START":return{...e,isStreaming:!0,error:null,streamingAssistantId:t.assistantId??null};case"STREAM_END":return{...e,isStreaming:!1,streamingAssistantId:null};case"STREAM_ERROR":return{...e,isStreaming:!1,error:t.error};case"UPDATE_CHECKPOINT":return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:t.checkpointNs??e.lastCheckpointNs};case"UPDATE_ASSEMBLING_ID":return{...e,streamingAssistantId:t.assistantId};case"CLEAR_ERROR":return{...e,error:null};default:return e}}const Ym={isStreaming:!1,error:null,streamingAssistantId:null,lastCheckpointId:null,lastCheckpointNs:null};function Xm({children:e}){const[t,n]=y.useReducer(Gm,Ym);return l.jsx(Ol.Provider,{value:n,children:l.jsx(Pl.Provider,{value:t,children:e})})}function Ml(){const e=y.useContext(Pl);if(!e)throw new Error("useStream must be used within StreamProvider");return e}function Jm(){const e=y.useContext(Ol);if(!e)throw new Error("useStreamDispatch must be used within StreamProvider");return e}function Zm(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function Qm(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 c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function eg(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await Qm(c);a.push({filename:c.name,data:u,mime_type:c.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Dl=y.createContext(null),Ll=y.createContext(null);function tg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,onThreadChange:o,onError:s}){const{api:i}=so(),[a,c]=y.useState([]),[u,d]=y.useState(t),[f,h]=y.useState(!1),[m,w]=y.useState(!1),[v,g]=y.useState(void 0),[x,b]=y.useState(void 0),S=y.useRef(!1),k=y.useRef([]),C=y.useRef(null),T=y.useRef(null);y.useRef(!1);const I=y.useRef(u);y.useEffect(()=>{I.current=u},[u]);const N=y.useContext(Ll),_=y.useCallback((D,H)=>new Promise((Y,Z)=>{const le=async()=>{S.current=!0;try{console.log(`[ThreadProvider] Executing operation: ${H||"unnamed"}`),await D(),Y()}catch(xe){console.error(`[ThreadProvider] Operation "${H}" failed:`,xe),Z(xe)}finally{S.current=!1;const xe=k.current.shift();xe&&xe().catch(()=>{})}};S.current?(k.current.push(le),console.log(`[ThreadProvider] Queued operation: ${H||"unnamed"}`)):le().catch(xe=>{Z(xe)})}),[]),R=y.useCallback(async()=>{h(!0);try{const D=await i.listThreads();c(D)}catch(D){console.error("[ThreadProvider] Failed to refresh threads:",D),s==null||s(String(D))}finally{h(!1)}},[i,s]),j=y.useCallback(async D=>{const H=await i.createThread(D),Y=typeof H=="string"?H:H.threadId;return await R(),d(Y),Y},[i,R]),$=y.useCallback(async D=>{await i.deleteThread(D),u===D&&(d(null),N==null||N.onThreadCleared()),await R()},[i,u,R,N]),z=y.useCallback(async(D,H)=>{try{await i.updateThread(D,H),c(Y=>Y.map(Z=>Z.threadId===D?{...Z,title:H}:Z))}catch(Y){throw await R(),Y}},[i,R]),O=y.useCallback(async(D,H,Y,Z=!1)=>{await _(async()=>{if(T.current===D&&!Z){console.log("[ThreadProvider] Skipping load for thread:",D),T.current=null;return}if(C.current===D&&!Z){console.log("[ThreadProvider] Load already in progress for thread:",D);return}d(le=>le===D?le:D),C.current=D,w(!0);try{const le=await i.getMessages({threadId:D,checkpointId:H,checkpointNs:Y});N==null||N.onThreadLoaded(D,le),g((le==null?void 0:le.checkpointId)??void 0),b((le==null?void 0:le.checkpointNs)??void 0)}finally{C.current=null,w(!1)}},`loadThread-${D}`)},[i,_,N,d]),V=y.useCallback(async()=>{console.log("[ThreadProvider] 🔄 clearCurrentThread called"),await _(async()=>{u&&(T.current=u),N==null||N.onThreadCleared(),d(null),g(void 0),b(void 0);try{localStorage.removeItem("lastThreadId")}catch(D){console.warn("[ThreadProvider] Failed to clear localStorage:",D)}},"clearCurrentThread")},[u,_,N]),B=y.useCallback(async D=>{const H=await i.listCheckpoints(D);return Zm(H,D)},[i]),K=y.useCallback(async(D,H)=>{if(!u)throw new Error("No active thread");await O(u,D,H??void 0,!0)},[u,O]),L=y.useCallback(async()=>{if(!u)throw new Error("No active thread");await O(u,void 0,void 0,!0)},[u,O]);y.useEffect(()=>{if(o==null||o(u),u)try{localStorage.setItem("lastThreadId",u)}catch(D){console.warn("[ThreadProvider] Failed to persist thread ID:",D)}},[u,o]),y.useEffect(()=>{let D=!0;return(async()=>{try{if(await R(),!D)return;if(!r&&!t)try{const Y=localStorage.getItem("lastThreadId");Y&&(d(Y),n&&await O(Y))}catch(Y){console.warn("[ThreadProvider] Failed to restore from localStorage:",Y)}else t&&n&&await O(t)}catch(Y){console.error("[ThreadProvider] Initialization failed:",Y),s==null||s(String(Y))}})(),()=>{D=!1}},[]);const A={threads:a,currentThreadId:u,isLoadingThreads:f,isLoadingThread:m,setCurrentThreadId:d,createThread:j,deleteThread:$,renameThread:z,refreshThreads:R,loadThread:O,clearCurrentThread:V,listCheckpoints:B,navigateToCheckpoint:K,returnToLatest:L};return l.jsx(Dl.Provider,{value:A,children:e})}function mr(){const e=y.useContext(Dl);if(!e)throw new Error("useThreads must be used within ThreadProvider");return e}function ng({children:e,onThreadLoaded:t,onThreadCleared:n,...r}){return l.jsx(Ll.Provider,{value:{onThreadLoaded:t,onThreadCleared:n},children:l.jsx(tg,{...r,children:e})})}function rg(e){return e.type!=="thread_info"&&e.type!=="token"}const og={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function sg(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:Ws(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=Ws(t.payload.messages),o={...e,messages:r,assemblingId: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),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Ws(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),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 Fl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Fl(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function $l(e=[]){const[t,n]=y.useReducer(sg,{...og,messages:e}),r=y.useRef([]),o=y.useRef(null),s=y.useRef(null),i=y.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=y.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]),c=y.useCallback(d=>{r.current.push(d),a()},[a]);y.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=y.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:c}),[c]);return{state:t,dispatch:n,...u}}function Fl(e,t){var n,r;if(t.type==="message_start"&&t.role==="assistant"){const o=t.id,s=dg(t.model);if(e.messages.some(c=>c.id===o))return{...e,assemblingId:o};const a={id:o,role:"assistant",name:s||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:o,messages:[...e.messages,a]}}if(t.type==="message_delta"){const o=e.assemblingId??Vs(e.messages);return o?{...e,messages:Ks(e.messages,o,t.delta)}:e}if(t.type==="message_end"){const o=e.assemblingId??Vs(e.messages);if(!o)return{...e,assemblingId:null};const s=e.messages,i=s.findIndex(a=>a.id===o&&a.role==="assistant");if(i>=0&&!((n=s[i].content)==null?void 0:n.some(u=>{var d;return(u==null?void 0:u.type)==="text"&&((d=u.text)==null?void 0:d.trim())}))){const u=[...s.slice(0,i),...s.slice(i+1)];return{...e,assemblingId:null,messages:u}}return e}if(t.type==="tool_start"){const o=t.id??t.call_id,s=t.name??t.tool??"tool";if(!o)return e;const i=`tool-${o}`,a={type:"tool_call",id:o,name:s,args:t.args};if(e.messages.find(d=>d.id===i))return{...e,toolIndex:{...e.toolIndex,[o]:i}};const u={id:i,role:"tool",name:s,createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,u],toolIndex:{...e.toolIndex,[o]:i}}}if(t.type==="tool_end"){const o=t.id??t.call_id;if(!o)return e;const s=e.toolIndex[o]??`tool-${o}`,i={type:"tool_end",toolCallId:o,output:t.output,error:t.error},a=e.messages.find(d=>d.id===s),c={id:s,role:"tool",name:t.name??((r=e.messages.find(d=>d.id===s))==null?void 0:r.name),content:[i],createdAt:new Date().toISOString()},u=a?Ks(e.messages,s,[i]):[...e.messages,c];return{...e,messages:u,toolIndex:{...e.toolIndex,[o]:s}}}if(t.type==="checkpoint"){const o=t.checkpointNs??e.lastCheckpointNs??null,s=ug(e.messages,t.checkpointId,o);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:o,messages:s}}if(t.type==="branch"){const o=t.checkpointId??e.lastCheckpointId,s=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:o??null,lastCheckpointNs:s??null}}if(t.type==="error"){const o={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,o]}}if(t.type==="interrupt"){const o=e.assemblingId??Vs(e.messages),s={type:"interrupt",value:t.value};if(o)return{...e,assemblingId:null,messages:Ks(e.messages,o,[s]),pendingInterrupt:{id:t.id,value:t.value}};const i={id:`interrupt-${t.id}`,role:"system",createdAt:new Date().toISOString(),content:[s]};return{...e,messages:[...e.messages,i],pendingInterrupt:{id:t.id,value:t.value}}}return e}function Ws(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 ig(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Vs(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function ag(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function Ks(e,t,n){return ag(e,t,r=>({...r,content:lg(r.content,n)}))}function lg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){const i=o,a=i.text??"";if(!a){i.text=s;continue}if(s.startsWith(a)){i.text=s;continue}if(a.startsWith(s)){i.text=s;continue}const c=cg(a,s);c?i.text=a+c:s.length!==a.length&&(i.text=s)}else n.push({type:"text",text:s})}else n.push(r);return n}function cg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let r=n;r>0;r--)if(e.slice(-r)===t.slice(0,r))return t.slice(r);return t}function ug(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 ig(e,r,s)}return e}function dg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const fg={MODE:"library"};function hg(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ns&&Ns.tagName.toUpperCase()==="SCRIPT"&&Ns.src||new URL("index.umd.js",document.baseURI).href}<"u"?fg:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function pg(){return!hg()}function mg({onThreadInfo:e,onMessageEvent:t,onUnhandledEvent:n,onSequenceGap:r}){const o=y.useRef(null),s=y.useCallback(a=>{const c=a.seq;if(c!=null){const u=o.current;if(u!==null){if(c<=u){pg()&&console.debug("[StreamEventCoordinator] drop out-of-order seq",{prev:u,seq:c,type:a.type});return}c>u+1&&(r==null||r({from:u,to:c}))}o.current=c}if(a.type==="thread_info"){e==null||e(a);return}if(rg(a)){t(a);return}n==null||n(a)},[t,r,e,n]),i=y.useCallback(()=>{o.current=null},[]);return{handleEvent:s,reset:i}}function zl(e={}){const t=y.useMemo(()=>kl(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=y.useState(e.token??null),s=y.useRef(e.headers??{}),[i,a]=y.useState(!1),[c,u]=y.useState(null),[d,f]=y.useState(""),[h,m]=y.useState(null),[w,v]=y.useState(0),[g,x]=y.useState(!1),b=y.useRef(null),S=y.useRef(!0),k=y.useRef(0),C=y.useCallback(_=>{o(_)},[]),T=y.useCallback(()=>{var _;(_=b.current)==null||_.abort(),b.current=null,a(!1),x(!1)},[]),I=y.useCallback(()=>{f(""),m(null),u(null)},[]),N=y.useCallback((_,R,j)=>{b.current&&(b.current.abort(),b.current=null),a(!0),u(null),e.autoAppendAssistant!==!1&&f("");const $=new AbortController;return b.current=$,(async()=>{var O,V,B,K,L,A,D,H;const z=Y=>{var Z;try{const le=JSON.parse(JSON.stringify(Y));return(Z=le==null?void 0:le.payload)!=null&&Z.files_info&&Array.isArray(le.payload.files_info)&&(le.payload.files_info=le.payload.files_info.map(xe=>({...xe,data:xe!=null&&xe.data?`<base64 ${String(xe.data).length} chars>`:xe==null?void 0:xe.data}))),le}catch{return Y}};try{let Y={};try{if(r)Y={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Re=window.__AUTH_TOKEN__,We=((O=window.localStorage)==null?void 0:O.getItem("authToken"))||null;let Q=null;try{const Ne=(V=window.localStorage)==null?void 0:V.getItem("chat-settings");Ne&&(Q=((B=JSON.parse(Ne))==null?void 0:B.apiKey)||null)}catch{}const X=Re||We||Q||null;X&&(Y={Authorization:`Bearer ${X}`})}}catch{}console.debug("[use-chat] POST",t+n,z(_));const Z=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...Y,...s.current},body:JSON.stringify(_),signal:$.signal});if(!Z.ok||!Z.body){const _e=await Z.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",Z.status,_e==null?void 0:_e.slice(0,500)),new Error(`stream ${Z.status}${_e?": "+_e:""}`)}x(!0);const le=Z.body.getReader(),xe=new TextDecoder;let Ee="",W=[],M=k.current,G=null;const te=()=>{if(W.length){const _e=W.join("");W=[],S.current&&f(Re=>Re+_e)}G=null},de=()=>{typeof window<"u"&&G==null&&(G=requestAnimationFrame(te))};let ce=Date.now();const $e=setInterval(()=>{var _e;if(Date.now()-ce>2e4){const Re="Stream idle timeout";u(Re),$.abort(),(_e=j==null?void 0:j.onError)==null||_e.call(j,Re)}},5e3),Ge=1024*1024;try{const _e=Z.headers.get("X-Thread-Id")||Z.headers.get("x-thread-id"),Re=Z.headers.get("X-Thread-Created")||Z.headers.get("x-thread-created"),We=_e??null,Q=String(Re??"").toLowerCase()==="true";for((K=j==null?void 0:j.onOpen)==null||K.call(j,{threadId:We,created:Q});;){const{value:X,done:Ne}=await le.read();if(Ne)break;Ee+=xe.decode(X,{stream:!0}),Ee.length>Ge&&(Ee="",console.warn("Stream buffer reset: exceeded 1MB"));let He;for(;(He=Ee.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const ee=Ee.slice(0,He);Ee=Ee.slice(He+2);const se=xg(ee);if(!se)continue;let he;try{he=JSON.parse(se)}catch{console.debug("[use-chat] malformed SSE:",se.slice(0,200));continue}const ge=gg(he)?he.data:he;ce=Date.now();const ke=ge.seq;if(ke!==void 0){if(ke<=M){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:ke,lastProcessedSeq:M,type:ge.type});continue}M>0&&ke>M+1&&((L=
|
|
38
|
-
`)}const Bl=y.createContext(null);function vg({children:e,enableFileAgentRouting:t=!1,fileAgentId:n="invoice_reader",onRegisterThreadCallbacks:r}){const{api:o,baseUrl:s}=so(),i=y.useMemo(()=>{const J=(s??"").replace(/\/+$/,"");return J?J.endsWith("/chat")?J:`${J}/chat`:"/api/chat"},[s]),{currentThreadId:a,setCurrentThreadId:c,isLoadingThread:u,refreshThreads:d}=mr(),f=Jm(),{state:h,dispatch:m,seed:w,prepend:v,pushUser:g,onEvent:x,reset:b}=Ll(),[S,k]=y.useState(!1),[C,T]=y.useState(!1),[I,N]=y.useState(null),[_,j]=y.useState(void 0),[R,$]=y.useState(void 0),z=20,O=y.useRef(a);y.useEffect(()=>{O.current=a},[a]);const V=y.useRef(null),B=y.useRef(!1),K=y.useCallback(async()=>{if(B.current){B.current=!1;try{await d()}catch(J){console.error("[MessagesProvider] Failed to refresh threads:",J)}}},[d]),{isStreaming:L,error:A,stream:D,stop:H,setToken:Y}=zl({baseUrl:i,token:null}),Q=y.useRef(L);y.useEffect(()=>{Q.current=L,L||K()},[L,K]);const le=y.useCallback(()=>{B.current=!0,Q.current||K()},[K]);y.useEffect(()=>{var Ne;const J=o.getAuthToken();Y(J);const X=(Ne=o.onTokenChange)==null?void 0:Ne.call(o,He=>{Y(He)});return()=>{X==null||X()}},[o,Y]),y.useEffect(()=>{f(L?{type:"STREAM_START",assistantId:h.assemblingId??void 0}:{type:"STREAM_END"})},[L,h.assemblingId,f]),y.useEffect(()=>{f(A?{type:"STREAM_ERROR",error:A}:{type:"CLEAR_ERROR"})},[A,f]),y.useEffect(()=>{h.lastCheckpointId&&f({type:"UPDATE_CHECKPOINT",checkpointId:h.lastCheckpointId,checkpointNs:h.lastCheckpointNs??void 0})},[h.lastCheckpointId,h.lastCheckpointNs,f]),y.useEffect(()=>{f({type:"UPDATE_ASSEMBLING_ID",assistantId:h.assemblingId})},[h.assemblingId,f]);const xe=y.useCallback((J,X)=>{const Ne=Array.isArray(J==null?void 0:J.messages)?J.messages:[];X==="replace"?(console.log("[MessagesProvider] Replacing messages, count:",Ne.length),w(Ne,{checkpointId:(J==null?void 0:J.checkpointId)??null,checkpointNs:(J==null?void 0:J.checkpointNs)??null})):X==="prepend"&&Ne.length&&(console.log("[MessagesProvider] Prepending messages, count:",Ne.length),v(Ne)),N((J==null?void 0:J.nextCursor)??null),k(!!(J!=null&&J.hasMore)),j(He=>(J==null?void 0:J.checkpointId)??He??void 0),$(He=>(J==null?void 0:J.checkpointNs)??He??void 0)},[w,v]),Ee=y.useCallback(J=>{const X=J.threadId,Ne=!!J.created,He=!!J.ready;if(a!==X){const ee=!a&&h.messages.length<=1;ee&&(V.current=X),c(X),(He||Ne||ee)&&le();return}(He||Ne)&&le()},[a,h.messages.length,c,le]),W=y.useCallback(({from:J,to:X})=>{const Ne=O.current;Ne&&console.warn(`[MessagesProvider] Stream sequence gap detected (${J} -> ${X}) for thread ${Ne}`)},[]),{handleEvent:M,reset:G}=mg({onThreadInfo:Ee,onMessageEvent:x,onUnhandledEvent:J=>{console.warn(`[MessagesProvider] Unhandled stream event type: ${J.type}`,J)},onSequenceGap:W}),te=y.useCallback(async J=>{if(!a)throw new Error("No active thread");if(C||!S)return;const X=I;if(X){T(!0);try{const Ne=await o.getMessages({threadId:a,checkpointId:_,checkpointNs:R,limit:(J==null?void 0:J.limit)??z,beforeId:X});xe(Ne,"prepend")}finally{T(!1)}}},[o,a,_,R,I,S,C,xe,z]),de=y.useCallback(()=>{console.log("[MessagesProvider] Clearing messages"),b([]),k(!1),T(!1),N(null),j(void 0),$(void 0)},[b]),ce=y.useCallback((J,X)=>{console.log("[MessagesProvider] Handling thread load for",J),B.current=!1,xe(X,"replace")},[xe]),$e=y.useCallback(()=>{console.log("[MessagesProvider] Handling thread clear"),B.current=!1,de()},[de]),Ge=y.useMemo(()=>({onThreadLoaded:ce,onThreadCleared:$e}),[ce,$e]);y.useEffect(()=>{if(r)return r(Ge),()=>{r({onThreadLoaded:()=>{},onThreadCleared:()=>{}})}},[r,Ge]);const _e=y.useCallback(async(J,X)=>{var Xe;!a&&!(X!=null&&X.payloadExtras)&&console.warn("[MessagesProvider] No thread ID - message will create new thread");const Ne=(X==null?void 0:X.attachments)||[],{contentParts:He,filesInfo:ee}=await eg(o,Ne),se=[...He];J&&J.trim()&&se.push({type:"text",text:J.trim()});const he={id:((Xe=crypto.randomUUID)==null?void 0:Xe.call(crypto))||`user-${Date.now()}`,role:"user",content:se,createdAt:new Date().toISOString(),checkpointId:(X==null?void 0:X.checkpointId)??h.lastCheckpointId??void 0,checkpointNs:(X==null?void 0:X.checkpointNs)??h.lastCheckpointNs??void 0};g(he);const ge={...he,content:se},ke={...(X==null?void 0:X.payloadExtras)??{}},De=Ne&&Ne.length>0,Ye={...a?{threadId:a}:{},payload:{messages:[ge],files_info:ee,...t&&De&&n?{active_agent:n}:{},...ke},checkpointId:(X==null?void 0:X.checkpointId)??h.lastCheckpointId??void 0,checkpointNs:(X==null?void 0:X.checkpointNs)??h.lastCheckpointNs??void 0,nodeFilter:X==null?void 0:X.nodeFilter,config:X==null?void 0:X.config};G(),le(),D(Ye,Je=>{M(Je)},{onError:Je=>console.warn("[MessagesProvider] Stream error:",Je),onOpen:({threadId:Je,created:yt})=>{if(!a&&Je){const ln=h.messages.length<=1;ln&&(V.current=Je),c(Je),(yt||ln)&&le()}},onGap:W})},[a,g,D,M,G,W,h.lastCheckpointId,h.lastCheckpointNs,h.messages.length,o,le,c,t,n]),Re=y.useCallback(async(J,X,Ne)=>{const He=O.current;if(!He)throw new Error("No active thread to handle interrupt");try{console.log(`[MessagesProvider] Handling interrupt ${J}: ${X?"approved":"rejected"}`);const ee=X?Ne??!0:!1;await o.resume({threadId:He,value:ee}),console.log(`[MessagesProvider] Interrupt ${J} handled successfully`)}catch(ee){throw console.error(`[MessagesProvider] Failed to handle interrupt ${J}:`,ee),ee}},[o]),We={messages:h.messages,assemblingId:h.assemblingId,lastUserMessage:null,hasMoreHistory:S,isLoadingHistory:C,send:_e,stop:H,loadOlderMessages:te,clearMessages:de,handleInterrupt:Re};return l.jsx(Bl.Provider,{value:We,children:e})}function wg(e){return l.jsx(vg,{...e})}function qs(){const e=y.useContext(Bl);if(!e)throw new Error("useMessages must be used within MessagesProvider");return e}function io({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:c}){const u=y.useRef({onThreadLoaded:()=>{},onThreadCleared:()=>{}}),d=y.useCallback(m=>{u.current=m},[]),f=y.useCallback((m,w)=>{u.current.onThreadLoaded(m,w)},[]),h=y.useCallback(()=>{u.current.onThreadCleared()},[]);return l.jsx(qm,{apiConfig:t,children:l.jsx(Xm,{children:l.jsx(ng,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,onError:a,onThreadChange:c,onThreadLoaded:f,onThreadCleared:h,children:l.jsx(wg,{enableFileAgentRouting:s,fileAgentId:i,onRegisterThreadCallbacks:d,children:e})})})})}function Z(...e){return Sp.twMerge(yp.clsx(e))}const bg=Kr.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),ze=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Tn.Slot:"button";return l.jsx(i,{className:Z(bg({variant:t,size:n,className:e})),ref:s,...o})});ze.displayName="Button";const Hl=p.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:Z("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}));Hl.displayName="Textarea";function yg({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:c,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,m]=y.useState(e),[w,v]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{m(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=y.useCallback(()=>{const N=g.current;N&&(N.style.height="auto",N.style.height=`${N.scrollHeight}px`)},[]);y.useEffect(()=>{x()},[x]);const b=y.useCallback(async N=>{N&&N.preventDefault();const _=(h??"").trim();!_&&!f||v(()=>{try{const j=i(_);j&&typeof j.then=="function"?j.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(N=>{m(N.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),k=y.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),b()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[b,t,a]),I=`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))]":""} ${d}`;return l.jsx("form",{onSubmit:N=>void b(N),className:`w-full ${u}`,children:l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(Hl,{ref:g,value:h,onChange:S,onKeyDown:k,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(ze,{type:"button",onClick:()=>{c==null||c()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!c,children:l.jsx(ne.Square,{size:16})}):l.jsx(ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:l.jsx(ne.Send,{size:16})})})]})})}const Sg=y.memo(yg),ao=0,dn=1,qn=2,Ul=4;function Wl(e){return()=>e}function Cg(e){e()}function Vl(e,t){return n=>e(t(n))}function Kl(e,t){return()=>e(t)}function Tg(e,t){return n=>e(t,n)}function Gs(e){return e!==void 0}function Eg(...e){return()=>{e.map(Cg)}}function Gn(){}function lo(e,t){return t(e),e}function kg(e,t){return t(e)}function Qe(...e){return e}function Ue(e,t){return e(dn,t)}function Ae(e,t){e(ao,t)}function Ys(e){e(qn)}function ot(e){return e(Ul)}function fe(e,t){return Ue(e,Tg(t,ao))}function Ft(e,t){const n=e(dn,r=>{n(),t(r)});return n}function ql(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Gl(e,t){return e===t}function et(e=Gl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function be(e){return t=>n=>{e(n)&&t(n)}}function oe(e){return t=>Vl(t,e)}function Kt(e){return t=>()=>{t(e)}}function F(e,...t){const n=Ig(...t);return(r,o)=>{switch(r){case qn:Ys(e);return;case dn:return Ue(e,n(o))}}}function qt(e,t){return n=>r=>{n(t=e(t,r))}}function Nn(e){return t=>n=>{e>0?e--:t(n)}}function on(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function je(...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);Ue(s,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Ig(...e){return t=>e.reduceRight(kg,t)}function Ng(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case dn:return s?n===s?void 0:(r(),n=s,t=Ue(e,s),t):(r(),Gn);case qn:r(),n=null;return}}}function q(e){let t=e;const n=Me();return(r,o)=>{switch(r){case ao:t=o;break;case dn:{o(t);break}case Ul:return t}return n(r,o)}}function ft(e,t){return lo(q(t),n=>fe(e,n))}function Me(){const e=[];return(t,n)=>{switch(t){case ao:e.slice().forEach(r=>{r(n)});return;case qn:e.splice(0,e.length);return;case dn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Et(e){return lo(Me(),t=>fe(e,t))}function Be(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Ag(),singleton:n}}const Ag=()=>Symbol();function _g(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(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function it(...e){const t=Me(),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);Ue(s,c=>{n[i]=c,r=r|a,r===o&&Ae(t,n)})}),function(s,i){switch(s){case qn:{Ys(t);return}case dn:return r===o&&i(n),Ue(t,i)}}}function we(e,t=Gl){return F(e,et(t))}function Xs(...e){return function(t,n){switch(t){case qn:return;case dn:return Eg(...e.map(r=>Ue(r,n)))}}}var bt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(bt||{});const jg={0:"debug",3:"error",1:"log",2:"warn"},Rg=()=>typeof globalThis>"u"?window:globalThis,fn=Be(()=>{const e=q(3);return{log:q((t,n,r=1)=>{var o;const s=(o=Rg().VIRTUOSO_LOG_LEVEL)!=null?o:ot(e);r>=s&&console[jg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function An(e,t,n){return Js(e,t,n).callbackRef}function Js(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};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 Pg(e,t,n,r,o,s,i,a,c){const u=y.useCallback(d=>{const f=Og(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const m=h.lastElementChild.dataset.viewportType==="window";let w;m&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:m?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:m?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:m?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?Yl("column-gap",getComputedStyle(d).columnGap,o):Yl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Js(u,n,c)}function Og(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 c=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},bt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==c-1?s.push({endIndex:c,size:d,startIndex:c}):s[s.length-1].endIndex++}return s}function Yl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,bt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Xl(e,t,n){const r=y.useRef(null),o=y.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),d=u.width;let f,h;if(t){const m=t.getBoundingClientRect(),w=u.top-m.top;h=m.height-Math.max(0,w),f=w+t.scrollTop}else{const m=i.current.ownerDocument.defaultView;h=m.innerHeight-Math.max(0,u.top),f=u.top+m.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Js(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var c;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const mt=Be(()=>{const e=Me(),t=Me(),n=q(0),r=Me(),o=q(0),s=Me(),i=Me(),a=q(0),c=q(0),u=q(0),d=q(0),f=Me(),h=Me(),m=q(!1),w=q(!1),v=q(!1);return fe(F(e,oe(({scrollTop:g})=>g)),t),fe(F(e,oe(({scrollHeight:g})=>g)),i),fe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:m,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),gr={lvl:0};function Jl(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:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Ke(e){return e===gr}function xr(e,t){if(!Ke(e))return t===e.k?e.v:t<e.k?xr(e.l,t):xr(e.r,t)}function zt(e,t,n="k"){if(Ke(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=zt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return zt(e.l,t,n)}function kt(e,t,n){return Ke(e)?ec(t,n,1):t===e.k?lt(e,{k:t,v:n}):t<e.k?tc(lt(e,{l:kt(e.l,t,n)})):tc(lt(e,{r:kt(e.r,t,n)}))}function Yn(){return gr}function co(e,t,n){if(Ke(e))return[];const r=zt(e,t)[0];return Mg(Qs(e,r,n))}function Zs(e,t){if(Ke(e))return gr;const{k:n,l:r,r:o}=e;if(t===n){if(Ke(r))return o;if(Ke(o))return r;{const[s,i]=Ql(r);return uo(lt(e,{k:s,l:Zl(r),v:i}))}}else return t<n?uo(lt(e,{l:Zs(r,t)})):uo(lt(e,{r:Zs(o,t)}))}function _n(e){return Ke(e)?[]:[..._n(e.l),{k:e.k,v:e.v},..._n(e.r)]}function Qs(e,t,n){if(Ke(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Qs(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Qs(s,t,n))),a}function uo(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(ei(t))return nc(lt(e,{lvl:n-1}));if(!Ke(t)&&!Ke(t.r))return lt(t.r,{l:lt(t,{r:t.r.l}),lvl:n,r:lt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ei(e))return ti(lt(e,{lvl:n-1}));if(!Ke(r)&&!Ke(r.l)){const o=r.l,s=ei(o)?r.lvl-1:r.lvl;return lt(o,{l:lt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ti(lt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function lt(e,t){return ec(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 Zl(e){return Ke(e.r)?e.l:uo(lt(e,{r:Zl(e.r)}))}function ei(e){return Ke(e)||e.lvl>e.r.lvl}function Ql(e){return Ke(e.r)?[e.k,e.v]:Ql(e.r)}function ec(e,t,n,r=gr,o=gr){return{k:e,l:r,lvl:n,r:o,v:t}}function tc(e){return ti(nc(e))}function nc(e){const{l:t}=e;return!Ke(t)&&t.lvl===e.lvl?lt(t,{r:lt(e,{l:t.r})}):e}function ti(e){const{lvl:t,r:n}=e;return!Ke(n)&&!Ke(n.r)&&n.lvl===t&&n.r.lvl===t?lt(n,{l:lt(e,{r:n.l}),lvl:t+1}):e}function Mg(e){return Jl(e,({k:t,v:n})=>({index:t,value:n}))}function rc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function vr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ni=Be(()=>({recalcInProgress:q(!1)}),[],{singleton:!0});function oc(e,t,n){return e[fo(e,t,n)]}function fo(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 Dg(e,t,n,r){const o=fo(e,t,r),s=fo(e,n,r,o);return e.slice(o,s+1)}function hn(e,t){return Math.round(e.getBoundingClientRect()[t])}function ho(e){return!Ke(e.groupOffsetTree)}function ri({index:e},t){return t===e?0:t<e?-1:1}function Lg(){return{groupIndices:[],groupOffsetTree:Yn(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Yn()}}function $g(e,t){let n=Ke(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ke(e)){e=kt(e,0,s);continue}const a=co(e,i-1,o+1);if(a.some(Vg(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:h}of a)c?(o>=f||s===h)&&(e=Zs(e,f)):(u=h!==s,c=!0),d>o&&o>=f&&h!==s&&(e=kt(e,o+1,h));u&&(e=kt(e,i,s))}return[e,n]}function Fg(e){return typeof e.groupIndex<"u"}function zg({offset:e},t){return t===e?0:t<e?-1:1}function wr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=oc(t,e,ri),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function sc(e,t){if(!ho(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function ic(e,t,n){if(Fg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=sc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Bg(e,t,n,r=0){return r>0&&(t=Math.max(t,oc(e,r,ri).offset)),Jl(Dg(e,t,n,zg),Wg)}function Hg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,bt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ke(s)&&t.length===2){const h=t[0].size,m=t[1].size;i=n.reduce((w,v)=>kt(kt(w,v,h),v+1,m),i)}else[i,a]=$g(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=oi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,m)=>kt(h,m,wr(m,f,o)),Yn()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Ug(e){return _n(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 ac(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 oi(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=fo(o,t-1,ri),a=o[c].offset;const u=zt(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===zt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of co(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Wg(e){return{index:e.index,value:e}}function Vg(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 Kg={offsetHeight:"height",offsetWidth:"width"},Gt=Be(([{log:e},{recalcInProgress:t}])=>{const n=Me(),r=Me(),o=ft(r,0),s=Me(),i=Me(),a=q(0),c=q([]),u=q(void 0),d=q(void 0),f=q((C,T)=>hn(C,Kg[T])),h=q(void 0),m=q(0),w=Lg(),v=ft(F(n,je(c,e,m),qt(Hg,w),et()),w),g=ft(F(c,et(),qt((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),oe(({prev:C})=>C)),[]);fe(F(c,be(C=>C.length>0),je(v,m),oe(([C,T,I])=>{const N=C.reduce((_,j,R)=>kt(_,j,wr(j,T.offsetTree,I)||R),Yn());return{...T,groupIndices:C,groupOffsetTree:N}})),v),fe(F(r,je(v),be(([C,{lastIndex:T}])=>C<T),oe(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),fe(u,d);const x=ft(F(u,oe(C=>C===void 0)),!0);fe(F(d,be(C=>C!==void 0&&Ke(ot(v).sizeTree)),oe(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Et(F(n,je(v),qt(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),oe(C=>C.changed)));Ue(F(a,qt((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),oe(C=>C.diff)),C=>{const{groupIndices:T}=ot(v);if(C>0)Ae(t,!0),Ae(s,C+ac(C,T));else if(C<0){const I=ot(g);I.length>0&&(C-=ac(-C,I)),Ae(i,C)}}),Ue(F(a,je(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},bt.ERROR)});const S=Et(s);fe(F(s,je(v),oe(([C,T])=>{const I=T.groupIndices.length>0,N=[],_=T.lastSize;if(I){const j=xr(T.sizeTree,0);let R=0,$=0;for(;R<C;){const O=T.groupIndices[$],V=T.groupIndices.length===$+1?1/0:T.groupIndices[$+1]-O-1;N.push({endIndex:O,size:j,startIndex:O}),N.push({endIndex:O+1+V-1,size:_,startIndex:O+1}),$++,R+=V+1}const z=_n(T.sizeTree);return R!==C&&z.shift(),z.reduce((O,{k:V,v:B})=>{let K=O.ranges;return O.prevSize!==0&&(K=[...O.ranges,{endIndex:V+C-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:V+C,prevSize:B,ranges:K}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return _n(T.sizeTree).reduce((j,{k:R,v:$})=>({prevIndex:R+C,prevSize:$,ranges:[...j.ranges,{endIndex:R+C-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Et(F(i,je(v,m),oe(([C,{offsetTree:T},I])=>{const N=-C;return wr(N,T,I)})));return fe(F(i,je(v,m),oe(([C,T,I])=>{if(T.groupIndices.length>0){if(Ke(T.sizeTree))return T;let N=Yn();const _=ot(g);let j=0,R=0,$=0;for(;j<-C;){$=_[R];const z=_[R+1]-$-1;R++,j+=z+1}if(N=_n(T.sizeTree).reduce((z,{k:O,v:V})=>kt(z,Math.max(0,O+C),V),N),j!==-C){const z=xr(T.sizeTree,$);N=kt(N,0,z);const O=zt(T.sizeTree,-C+1)[1];N=kt(N,1,O)}return{...T,sizeTree:N,...oi(T.offsetTree,0,N,I)}}else{const N=_n(T.sizeTree).reduce((_,{k:j,v:R})=>kt(_,Math.max(0,j+C),R),Yn());return{...T,sizeTree:N,...oi(T.offsetTree,0,N,I)}}})),v),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:m,groupIndices:c,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Qe(fn,ni),{singleton:!0});function qg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const lc=Be(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Me(),i=Me(),a=Et(F(s,oe(qg)));return fe(F(a,oe(c=>c.totalCount)),n),fe(F(a,oe(c=>c.groupIndices)),e),fe(F(it(o,t,r),be(([c,u])=>ho(u)),oe(([c,u,d])=>zt(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),et(),oe(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Qe(Gt,mt)),pn=Be(([{log:e}])=>{const t=q(!1),n=Et(F(t,be(r=>r),et()));return Ue(t,r=>{r&&ot(e)("props updated",{},bt.DEBUG)}),{didMount:n,propsReady:t}},Qe(fn),{singleton:!0}),Gg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function cc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Gg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const br=Be(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const m=Me(),w=Me(),v=q(0);let g=null,x=null,b=null;function S(){g&&(g(),g=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Ae(c,!1)}return fe(F(m,je(n,f,r,v,a,i,h),je(e,s,o),oe(([[k,C,T,I,N,_,j,R],$,z,O])=>{const V=cc(k),{align:B,behavior:K,offset:L}=V,A=I-1,D=ic(V,C,A);let H=wr(D,C.offsetTree,$)+_;B==="end"?(H+=z+zt(C.sizeTree,D)[1]-T+O,D===A&&(H+=j)):B==="center"?H+=(z+zt(C.sizeTree,D)[1]-T+O)/2:H-=N,L&&(H+=L);const Y=Q=>{S(),Q?(R("retrying to scroll to",{location:k},bt.DEBUG),Ae(m,k)):(Ae(w,!0),R("list did not change, scroll successful",{},bt.DEBUG))};if(S(),K==="smooth"){let Q=!1;b=Ue(t,le=>{Q=Q||le}),g=Ft(d,()=>{Y(Q)})}else g=Ft(F(t,Yg(150)),Y);return x=setTimeout(()=>{S()},1200),Ae(c,!0),R("scrolling from index to",{behavior:K,index:D,top:H},bt.DEBUG),{behavior:K,top:H}})),u),{scrollTargetReached:w,scrollToIndex:m,topListHeight:v}},Qe(Gt,mt,fn),{singleton:!0});function Yg(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function si(e,t){e==0?t():requestAnimationFrame(()=>{si(e-1,t)})}function ii(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const yr=Be(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=q(!0),c=q(0),u=q(!0);return fe(F(i,je(c),be(([d,f])=>!!f),Kt(!1)),a),fe(F(i,je(c),be(([d,f])=>!!f),Kt(!1)),u),Ue(F(it(t,i),je(a,n,e,u),be(([[,d],f,{sizeTree:h},m,w])=>d&&(!Ke(h)||Gs(m))&&!f&&!w),je(c)),([,d])=>{Ft(o,()=>{Ae(u,!0)}),si(4,()=>{Ft(r,()=>{Ae(a,!0)}),Ae(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Qe(Gt,mt,br,pn),{singleton:!0});function uc(e,t){return Math.abs(e-t)<1.01}const Sr="up",Cr="down",Xg="none",Jg={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Zg=0,Tr=Be(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=q(!1),a=q(!0),c=Me(),u=Me(),d=q(4),f=q(Zg),h=ft(F(Xs(F(we(o),Nn(1),Kt(!0)),F(we(o),Nn(1),Kt(!1),ql(100))),et()),!1),m=ft(F(Xs(F(n,Kt(!0)),F(n,Kt(!1),ql(200))),et()),!1);fe(F(it(we(o),we(f)),oe(([b,S])=>b<=S),et()),a),fe(F(a,on(50)),u);const w=Et(F(it(r,we(s),we(t),we(e),we(d)),qt((b,[{scrollHeight:S,scrollTop:k},C,T,I,N])=>{const _=k+C-S>-N,j={scrollHeight:S,scrollTop:k,viewportHeight:C};if(_){let $,z;return k>b.state.scrollTop?($="SCROLLED_DOWN",z=b.state.scrollTop-k):($="SIZE_DECREASED",z=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:$,scrollTopDelta:z,state:j}}let R;return j.scrollHeight>b.state.scrollHeight?R="SIZE_INCREASED":C<b.state.viewportHeight?R="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?R="SCROLLING_UPWARDS":R="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:R,state:j}},Jg),et((b,S)=>b&&b.atBottom===S.atBottom))),v=ft(F(r,qt((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(uc(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),be(b=>b.changed),oe(b=>b.jump)),0);fe(F(w,oe(b=>b.atBottom)),i),fe(F(i,on(50)),c);const g=q(Cr);fe(F(r,oe(({scrollTop:b})=>b),et(),qt((b,S)=>ot(m)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Sr:Cr,prevScrollTop:S},{direction:Cr,prevScrollTop:0}),oe(b=>b.direction)),g),fe(F(r,on(50),Kt(Xg)),g);const x=q(0);return fe(F(h,be(b=>!b),Kt(0)),x),fe(F(o,on(100),je(h),be(([b,S])=>!!S),qt(([b,S],[k])=>[S,k],[0,0]),oe(([b,S])=>S-b)),x),{atBottomState:w,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},Qe(mt)),po="top",mo="bottom",dc="none";function fc(e,t,n){return typeof e=="number"?n===Sr&&t===po||n===Cr&&t===mo?e:0:n===Sr?t===po?e.main:e.reverse:t===mo?e.main:e.reverse}function hc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ai=Be(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Me(),i=q(0),a=q(0),c=q(0),u=ft(F(it(we(r),we(o),we(n),we(s,vr),we(c),we(i),we(t),we(e),we(a)),oe(([d,f,h,[m,w],v,g,x,b,S])=>{const k=d-b,C=g+x,T=Math.max(h-k,0);let I=dc;const N=hc(S,po),_=hc(S,mo);return m-=b,m+=h+x,w+=h+x,w-=b,m>d+C-N&&(I=Sr),w<d-T+f+_&&(I=Cr),I!==dc?[Math.max(k-h-fc(v,po,I)-N,0),k-T-x+f+fc(v,mo,I)+_]:null}),be(d=>d!=null),et(vr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},Qe(mt),{singleton:!0});function Qg(e,t,n){if(ho(t)){const r=sc(e,t);return[{index:zt(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 li={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function go(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const v=e[e.length-1];d=v.offset+v.size}const f=n-i,h=a+f*c+(f-1)*r,m=u,w=h-d;return{bottom:d,firstItemIndex:s,items:mc(e,o,s),offsetBottom:w,offsetTop:u,top:m,topItems:mc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function pc(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,c=ii(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return go(u,[],a,o,n,r)}function mc(e,t,n){if(e.length===0)return[];if(!ho(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=co(t.groupOffsetTree,r,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const jn=Be(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:m},{recalcInProgress:w}])=>{const v=q([]),g=q(0),x=Me();fe(s.topItemsIndexes,v);const b=ft(F(it(m,w,we(c,vr),we(o),we(r),we(u),d,we(v),we(t),we(n),e),be(([T,I,,N,,,,,,,_])=>{const j=_&&_.length!==N;return T&&!I&&!j}),oe(([,,[T,I],N,_,j,R,$,z,O,V])=>{const B=_,{offsetTree:K,sizeTree:L}=B,A=ot(g);if(N===0)return{...li,totalCount:N};if(T===0&&I===0)return A===0?{...li,totalCount:N}:pc(A,j,_,z,O,V||[]);if(Ke(L))return A>0?null:go(Qg(ii(j,N),B,V),[],N,O,B,z);const D=[];if($.length>0){const xe=$[0],Ee=$[$.length-1];let W=0;for(const M of co(L,xe,Ee)){const G=M.value,te=Math.max(M.start,xe),de=Math.min(M.end,Ee);for(let ce=te;ce<=de;ce++)D.push({data:V==null?void 0:V[ce],index:ce,offset:W,size:G}),W+=G}}if(!R)return go([],D,N,O,B,z);const H=$.length>0?$[$.length-1]+1:0,Y=Bg(K,T,I,H);if(Y.length===0)return null;const Q=N-1,le=lo([],xe=>{for(const Ee of Y){const W=Ee.value;let M=W.offset,G=Ee.start;const te=W.size;if(W.offset<T){G+=Math.floor((T-W.offset+O)/(te+O));const ce=G-Ee.start;M+=ce*te+ce*O}G<H&&(M+=(H-G)*te,G=H);const de=Math.min(Ee.end,Q);for(let ce=G;ce<=de&&!(M>=I);ce++)xe.push({data:V==null?void 0:V[ce],index:ce,offset:M,size:te}),M+=te+O}});return go(le,D,N,O,B,z)}),be(T=>T!==null),et()),li);fe(F(e,be(Gs),oe(T=>T==null?void 0:T.length)),o),fe(F(b,oe(T=>T.topListHeight)),f),fe(f,a),fe(F(b,oe(T=>[T.top,T.bottom])),i),fe(F(b,oe(T=>T.items)),x);const S=Et(F(b,be(({items:T})=>T.length>0),je(o,e),be(([{items:T},I])=>T[T.length-1].originalIndex===I-1),oe(([,T,I])=>[T-1,I]),et(vr),oe(([T])=>T))),k=Et(F(b,on(200),be(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),oe(({items:T})=>T[0].index),et())),C=Et(F(b,be(({items:T})=>T.length>0),oe(({items:T})=>{let I=0,N=T.length-1;for(;T[I].type==="group"&&I<N;)I++;for(;T[N].type==="group"&&N>I;)N--;return{endIndex:T[N].index,startIndex:T[I].index}}),et(rc)));return{endReached:S,initialItemCount:g,itemsRendered:x,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:v,...h}},Qe(Gt,lc,ai,yr,br,Tr,pn,ni),{singleton:!0}),gc=Be(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Me(),i=ft(F(it(n,e,r,t,o),oe(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return fe(we(i),s),{totalListHeight:i,totalListHeightChanged:s}},Qe(mt,jn),{singleton:!0}),ex=Be(([{viewportHeight:e},{totalListHeight:t}])=>{const n=q(!1),r=ft(F(it(n,e,t),be(([o])=>o),oe(([,o,s])=>Math.max(0,o-s)),on(0),et()),0);return{alignToBottom:n,paddingTopAddition:r}},Qe(mt,gc),{singleton:!0}),xc=Be(()=>({context:q(null)})),tx=({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,vc=Be(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=Me();return fe(F(d,je(t,c,n,s,o,r,a),je(e),oe(([[f,h,m,w,v,g,x,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=tx,done:I,...N}=f,_=ic(f,h,w-1),j=wr(_,h.offsetTree,S)+v+g,R=j+zt(h.sizeTree,_)[1],$=b+g,z=b+m-x,O=T({itemBottom:R,itemTop:j,locationParams:{align:k,behavior:C,...N},viewportBottom:z,viewportTop:$});return O?I&&Ft(F(i,be(V=>!V),Nn(ot(i)?1:2)),I):I&&I(),O}),be(f=>f!==null)),u),{scrollIntoView:d}},Qe(Gt,mt,br,jn,fn),{singleton:!0});function wc(e){return e?e==="smooth"?"smooth":"auto":!1}const nx=(e,t)=>typeof e=="function"?wc(e(t)):t&&wc(e),rx=Be(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:m}])=>{const w=q(!1),v=Me();let g=null;function x(C){Ae(i,{align:"end",behavior:C,index:"LAST"})}Ue(F(it(F(we(t),Nn(1)),c),je(we(w),s,a,f),oe(([[C,T],I,N,_,j])=>{let R=T&&_,$="auto";return R&&($=nx(I,N||j),R=R&&!!$),{followOutputBehavior:$,shouldFollow:R,totalCount:C}}),be(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{g&&(g(),g=null),ot(n)?requestAnimationFrame(()=>{ot(d)("following output to ",{totalCount:T},bt.DEBUG),x(C)}):g=Ft(e,()=>{ot(d)("following output to ",{totalCount:T},bt.DEBUG),x(C),g=null})});function b(C){const T=Ft(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(ot(d)("scrolling to bottom due to increased size",{},bt.DEBUG),x("auto"))});setTimeout(T,100)}Ue(F(it(we(w),t,u),be(([C,,T])=>C&&T),qt(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),be(({refreshed:C})=>C),je(w,t)),([,C])=>{ot(a)&&b(C!==!1)}),Ue(v,()=>{b(ot(w)!==!1)}),Ue(it(we(w),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=q(null),k=Me();return fe(Xs(F(we(r),oe(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),F(we(t))),k),Ue(F(it(F(k,Nn(1)),c),je(we(S),a,f,h),oe(([[C,T],I,N,_,j])=>T&&N&&(I==null?void 0:I({context:j,totalCount:C,scrollingInProgress:_}))),be(C=>!!C),on(0)),C=>{g&&(g(),g=null),ot(n)?requestAnimationFrame(()=>{ot(d)("scrolling into view",{}),Ae(m,C)}):g=Ft(e,()=>{ot(d)("scrolling into view",{}),Ae(m,C),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:S}},Qe(Gt,Tr,br,yr,pn,fn,mt,xc,vc)),ox=Be(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(F(a,je(s),be(([,c])=>c!==0),je(o,r,t,n,e),oe(([[,c],u,d,f,h,m=[]])=>pc(c,u,d,f,h,m))),i),{}),Qe(Gt,yr,jn,pn),{singleton:!0}),sx=Be(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=q(0);return Ue(F(e,je(r),be(([,o])=>o!==0),oe(([,o])=>({top:o}))),o=>{Ft(F(n,Nn(1),be(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Ae(t,o)})})}),{initialScrollTop:r}},Qe(pn,mt,jn),{singleton:!0}),bc=Be(([{scrollVelocity:e}])=>{const t=q(!1),n=Me(),r=q(!1);return fe(F(e,je(r,t,n),be(([o,s])=>!!s),oe(([o,s,i,a])=>{const{enter:c,exit:u}=s;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),et()),t),Ue(F(it(t,e,n),je(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Qe(Tr),{singleton:!0}),ci=Be(([{scrollContainerState:e,scrollTo:t}])=>{const n=Me(),r=Me(),o=Me(),s=q(!1),i=q(void 0);return fe(F(it(n,r),oe(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),fe(F(t,je(r),oe(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Qe(mt)),ix=Be(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=Me(),d=q(void 0),f=q(null),h=q(null);return fe(a,f),fe(c,h),Ue(F(u,je(t,r,i,f,h,n)),([m,w,v,g,x,b,S])=>{const k=Ug(w.sizeTree);g&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=S,m({ranges:k,scrollTop:v})}),fe(F(d,be(Gs),oe(ax)),o),fe(F(s,je(d),be(([,m])=>m!==void 0),et(),oe(([,m])=>m.ranges)),e),{getState:u,restoreStateFrom:d}},Qe(Gt,mt,yr,pn,ci));function ax(e){return{align:"start",index:0,offset:e.scrollTop}}const lx=Be(([{topItemsIndexes:e}])=>{const t=q(0);return fe(F(t,be(n=>n>=0),oe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Qe(jn));function yc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const cx=yc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),ux=Be(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:m},{recalcInProgress:w}])=>{const v=Et(F(c,je(i),qt(([,x,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},N])=>{const _=k+T;let j=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(j=_-S,j!==0&&(j+=N))),[j,C,I,_]},[0,[],0,0]),be(([x])=>x!==0),je(r,a,n,o,m,w),be(([,x,b,S,,,k])=>!k&&!S&&x!==0&&b===Sr),oe(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},bt.DEBUG),x))));function g(x){x>0?(Ae(t,{behavior:"auto",top:-x}),Ae(e,0)):(Ae(e,0),Ae(t,{behavior:"auto",top:-x}))}return Ue(F(v,je(e,s)),([x,b,S])=>{S&&cx()?Ae(e,b-x):g(-x)}),Ue(F(it(ft(s,!1),e,w),be(([x,b,S])=>!x&&!S&&b!==0),oe(([x,b])=>b),on(1)),g),fe(F(f,oe(x=>({top:-x}))),t),Ue(F(u,je(h,d),oe(([x,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(x);{let I=0;const N=xr(k,0);let _=0,j=0;for(;_<x;){_++,I+=N;let R=b.length===j+1?1/0:b[j+1]-b[j]-1;_+R>x&&(I-=N,R=x-_+1),_+=R,I+=T(R),j++}return I}})),x=>{Ae(e,x),requestAnimationFrame(()=>{Ae(t,{top:x}),requestAnimationFrame(()=>{Ae(e,0),Ae(w,!1)})})}),{deviation:e}},Qe(mt,Tr,jn,Gt,fn,ni)),dx=Be(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),Qe(ai,ox,pn,bc,gc,sx,ex,ci,vc,fn,xc)),Sc=Be(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:m,scrolledToInitialItem:w},v,g,x,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:N},_])=>(fe(k.rangeChanged,_.scrollSeekRangeChanged),fe(F(_.windowViewportRect,oe(j=>j.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:m,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...k,..._,...v,sizes:c,...g}),Qe(Gt,yr,mt,ix,rx,jn,br,ux,lx,lc,dx));function fx(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 xo=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Cc(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=y.createContext({});function c(g,x){g.propsReady&&Ae(g.propsReady,!1);for(const b of r){const S=g[t.required[b]];Ae(S,x[b])}for(const b of o)if(b in x){const S=g[t.optional[b]];Ae(S,x[b])}g.propsReady&&Ae(g.propsReady,!0)}function u(g){return s.reduce((x,b)=>(x[b]=S=>{const k=g[t.methods[b]];Ae(k,S)},x),{})}function d(g){return i.reduce((x,b)=>(x[b]=Ng(g[t.events[b]]),x),{})}const f=y.forwardRef((g,x)=>{const{children:b,...S}=g,[k]=y.useState(()=>lo(_g(e),I=>{c(I,S)})),[C]=y.useState(Kl(d,k));xo(()=>{for(const I of i)I in S&&Ue(C[I],S[I]);return()=>{Object.values(C).map(Ys)}},[S,C,k]),xo(()=>{c(k,S)}),y.useImperativeHandle(x,Wl(u(k)));const T=n;return l.jsx(a.Provider,{value:k,children:n?l.jsx(T,{...fx([...r,...o,...i],S),children:b}):b})}),h=g=>{const x=y.useContext(a);return y.useCallback(b=>{Ae(x[g],b)},[x,g])},m=g=>{const x=y.useContext(a)[g],b=y.useCallback(S=>Ue(x,S),[x]);return y.useSyncExternalStore(b,()=>ot(x),()=>ot(x))},w=g=>{const x=y.useContext(a)[g],[b,S]=y.useState(Kl(ot,x));return xo(()=>Ue(x,k=>{k!==b&&S(Wl(k))}),[x,b]),b},v=y.version.startsWith("18")?m:w;return{Component:f,useEmitter:(g,x)=>{const b=y.useContext(a)[g];xo(()=>Ue(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const Tc=y.createContext(void 0),Ec=y.createContext(void 0),kc=typeof document<"u"?y.useLayoutEffect:y.useEffect;function ui(e){return"self"in e}function hx(e){return"body"in e}function Ic(e,t,n,r=Gn,o,s){const i=y.useRef(null),a=y.useRef(null),c=y.useRef(null),u=y.useCallback(h=>{let m,w,v;const g=h.target;if(hx(g)||ui(g)){const b=ui(g)?g:g.defaultView;v=s?b.scrollX:b.scrollY,m=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?g.scrollLeft:g.scrollTop,m=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:m,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Is.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===m-w)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const m=i.current;if(!m||(s?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;ui(m)?(g=Math.max(hn(m.document.documentElement,s?"width":"height"),s?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),v=s?m.innerWidth:m.innerHeight,x=s?window.scrollX:window.scrollY):(g=m[s?"scrollWidth":"scrollHeight"],v=hn(m,s?"width":"height"),x=m[s?"scrollLeft":"scrollTop"]);const b=g-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),uc(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),m.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 di="-webkit-sticky",Nc="sticky",fi=yc(()=>{if(typeof document>"u")return Nc;const e=document.createElement("div");return e.style.position=di,e.style.position===di?di:Nc});function hi(e){return e}const px=Be(()=>{const e=q(a=>`Item ${a}`),t=q(a=>`Group ${a}`),n=q({}),r=q(hi),o=q("div"),s=q(Gn),i=(a,c=null)=>ft(F(n,oe(u=>u[a]),et()),c);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")}}),mx=Be(([e,t])=>({...e,...t}),Qe(Sc,px)),gx=({height:e})=>l.jsx("div",{style:{height:e}}),xx={overflowAnchor:"none",position:fi(),zIndex:1},Ac={overflowAnchor:"none"},vx={...Ac,display:"inline-block",height:"100%"},_c=y.memo(function({showTopList:e=!1}){const t=Te("listState"),n=Rt("sizeRanges"),r=Te("useWindowScroll"),o=Te("customScrollParent"),s=Rt("windowScrollContainerState"),i=Rt("scrollContainerState"),a=o||r?s:i,c=Te("itemContent"),u=Te("context"),d=Te("groupContent"),f=Te("trackItemSizes"),h=Te("itemSize"),m=Te("log"),w=Rt("gap"),v=Te("horizontalDirection"),{callbackRef:g}=Pg(n,h,f,e?Gn:a,m,w,o,v,Te("skipAnimationFrameInResizeObserver")),[x,b]=y.useState(0);pi("deviation",O=>{x!==O&&b(O)});const S=Te("EmptyPlaceholder"),k=Te("ScrollSeekPlaceholder")||gx,C=Te("ListComponent"),T=Te("ItemComponent"),I=Te("GroupComponent"),N=Te("computeItemKey"),_=Te("isSeeking"),j=Te("groupIndices").length>0,R=Te("alignToBottom"),$=Te("initialItemFinalLocationReached"),z=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:R?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:R?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...$?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?l.jsx(S,{...ht(S,u)}):l.jsx(C,{...ht(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:z,children:(e?t.topItems:t.items).map(O=>{const V=O.originalIndex,B=N(V+t.firstItemIndex,O.data,u);return _?y.createElement(k,{...ht(k,u),height:O.size,index:O.index,key:B,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?y.createElement(I,{...ht(I,u),"data-index":V,"data-item-index":O.index,"data-known-size":O.size,key:B,style:xx},d(O.index,u)):y.createElement(T,{...ht(T,u),...Sx(T,O.data),"data-index":V,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:B,style:v?vx:Ac},j?c(O.index,O.groupIndex,O.data,u):c(O.index,O.data,u))})})}),wx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},bx={outline:"none",overflowX:"auto",position:"relative"},vo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),yx={position:fi(),top:0,width:"100%",zIndex:1};function ht(e,t){if(typeof e!="string")return{context:t}}function Sx(e,t){return{item:typeof e=="string"?void 0:t}}const Cx=y.memo(function(){const e=Te("HeaderComponent"),t=Rt("headerHeight"),n=Te("HeaderFooterTag"),r=An(y.useMemo(()=>s=>{t(hn(s,"height"))},[t]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...ht(e,o)})}):null}),Tx=y.memo(function(){const e=Te("FooterComponent"),t=Rt("footerHeight"),n=Te("HeaderFooterTag"),r=An(y.useMemo(()=>s=>{t(hn(s,"height"))},[t]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...ht(e,o)})}):null});function jc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:m,scrollToCallback:w}=Ic(a,u,c,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),l.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{...f?bx:wx,...o},tabIndex:0,...i,...ht(c,s),children:r})})}function Rc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),m=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Ic(a,u,c,w,h);return kc(()=>{var b;return g.current=h||((b=m.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),l.jsx(c,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...ht(c,s),children:r})})}const Ex=({children:e})=>{const t=y.useContext(Tc),n=Rt("viewportHeight"),r=Rt("fixedItemHeight"),o=Te("alignToBottom"),s=Te("horizontalDirection"),i=y.useMemo(()=>Vl(n,c=>hn(c,s?"width":"height")),[n,s]),a=An(i,!0,Te("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:vo(o),children:e})},kx=({children:e})=>{const t=y.useContext(Tc),n=Rt("windowViewportRect"),r=Rt("fixedItemHeight"),o=Te("customScrollParent"),s=Xl(n,o,Te("skipAnimationFrameInResizeObserver")),i=Te("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),l.jsx("div",{"data-viewport-type":"window",ref:s,style:vo(i),children:e})},Ix=({children:e})=>{const t=Te("TopItemListComponent")||"div",n=Te("headerHeight"),r={...yx,marginTop:`${n}px`},o=Te("context");return l.jsx(t,{style:r,...ht(t,o),children:e})},Nx=y.memo(function(e){const t=Te("useWindowScroll"),n=Te("topItemsIndexes").length>0,r=Te("customScrollParent"),o=Te("context");return l.jsxs(r||t?jx:_x,{...e,context:o,children:[n&&l.jsx(Ix,{children:l.jsx(_c,{showTopList:!0})}),l.jsxs(r||t?kx:Ex,{children:[l.jsx(Cx,{}),l.jsx(_c,{}),l.jsx(Tx,{})]})]})}),{Component:Ax,useEmitter:pi,useEmitterValue:Te,usePublisher:Rt}=Cc(mx,{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"}},Nx),_x=jc({useEmitter:pi,useEmitterValue:Te,usePublisher:Rt}),jx=Rc({useEmitter:pi,useEmitterValue:Te,usePublisher:Rt}),Rx=Ax;Qe(Sc,Be(()=>{const e=q(u=>l.jsxs("td",{children:["Item $",u]})),t=q(null),n=q(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=q(null),o=q(null),s=q({}),i=q(hi),a=q(Gn),c=(u,d=null)=>ft(F(s,oe(f=>f[u]),et()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),fi();const Pc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Px={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Oc,floor:wo,max:Er,min:mi,round:Mc}=Math;function Dc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Ox(e){return{...Px,items:e}}function bo(e,t){return e&&e.width===t.width&&e.height===t.height}function Mx(e,t){return e&&e.column===t.column&&e.row===t.row}const Dx=Be(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,m,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=q(0),I=q(0),N=q(Pc),_=q({height:0,width:0}),j=q({height:0,width:0}),R=Me(),$=Me(),z=q(0),O=q(null),V=q({column:0,row:0}),B=Me(),K=Me(),L=q(!1),A=q(0),D=q(!0),H=q(!1),Y=q(!1);Ue(F(w,je(A),be(([M,G])=>!!G)),()=>{Ae(D,!1)}),Ue(F(it(w,D,j,_,A,H),be(([M,G,te,de,,ce])=>M&&!G&&te.height!==0&&de.height!==0&&!ce)),([,,,,M])=>{Ae(H,!0),si(1,()=>{Ae(R,M)}),Ft(F(u),()=>{Ae(t,[0,0]),Ae(D,!0)})}),fe(F(K,be(M=>M!=null&&M.scrollTop>0),Kt(0)),I),Ue(F(w,je(K),be(([,M])=>M!=null)),([,M])=>{M&&(Ae(_,M.viewport),Ae(j,M.item),Ae(V,M.gap),M.scrollTop>0&&(Ae(L,!0),Ft(F(u,Nn(1)),G=>{Ae(L,!1)}),Ae(c,{top:M.scrollTop})))}),fe(F(_,oe(({height:M})=>M)),f),fe(F(it(we(_,bo),we(j,bo),we(V,(M,G)=>M&&M.column===G.column&&M.row===G.row),we(u)),oe(([M,G,te,de])=>({gap:te,item:G,scrollTop:de,viewport:M}))),B),fe(F(it(we(T),r,we(V,Mx),we(j,bo),we(_,bo),we(O),we(I),we(L),we(D),we(A)),be(([,,,,,,,M])=>!M),oe(([M,[G,te],de,ce,$e,Ge,_e,,Re,We])=>{const{column:J,row:X}=de,{height:Ne,width:He}=ce,{width:ee}=$e;if(_e===0&&(M===0||ee===0))return Pc;if(He===0){const yt=ii(We,M),ln=yt+Math.max(_e-1,0);return Ox(Dc(yt,ln,Ge))}const se=Lc(ee,He,J);let he,ge;Re?G===0&&te===0&&_e>0?(he=0,ge=_e-1):(he=se*wo((G+X)/(Ne+X)),ge=se*Oc((te+X)/(Ne+X))-1,ge=mi(M-1,Er(ge,se-1)),he=mi(ge,Er(0,he))):(he=0,ge=-1);const ke=Dc(he,ge,Ge),{bottom:De,top:Ye}=$c($e,de,ce,ke),Xe=Oc(M/se),Je=Xe*Ne+(Xe-1)*X-De;return{bottom:De,itemHeight:Ne,items:ke,itemWidth:He,offsetBottom:Je,offsetTop:Ye,top:Ye}})),N),fe(F(O,be(M=>M!==null),oe(M=>M.length)),T),fe(F(it(_,j,N,V),be(([M,G,{items:te}])=>te.length>0&&G.height!==0&&M.height!==0),oe(([M,G,{items:te},de])=>{const{bottom:ce,top:$e}=$c(M,de,G,te);return[$e,ce]}),et(vr)),t);const Q=q(!1);fe(F(u,je(Q),oe(([M,G])=>G||M!==0)),Q);const le=Et(F(it(N,T),be(([{items:M}])=>M.length>0),je(Q),be(([[M,G],te])=>{const de=M.items[M.items.length-1].index===G-1;return(te||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===G)&&de}),oe(([[,M]])=>M-1),et())),xe=Et(F(we(N),be(({items:M})=>M.length>0&&M[0].index===0),Kt(0),et())),Ee=Et(F(we(N),je(L),be(([{items:M},G])=>M.length>0&&!G),oe(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),et(rc),on(0)));fe(Ee,m.scrollSeekRangeChanged),fe(F(R,je(_,j,T,V),oe(([M,G,te,de,ce])=>{const $e=cc(M),{align:Ge,behavior:_e,offset:Re}=$e;let We=$e.index;We==="LAST"&&(We=de-1),We=Er(0,We,mi(de-1,We));let J=gi(G,ce,te,We);return Ge==="end"?J=Mc(J-G.height+te.height):Ge==="center"&&(J=Mc(J-G.height/2+te.height/2)),Re&&(J+=Re),{behavior:_e,top:J}})),c);const W=ft(F(N,oe(M=>M.offsetBottom+M.bottom)),0);return fe(F(k,oe(M=>({height:M.visibleHeight,width:M.visibleWidth}))),_),{customScrollParent:g,data:O,deviation:z,footerHeight:o,gap:V,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:j,overscan:n,restoreStateFrom:K,scrollBy:i,scrollContainerState:a,scrollHeight:$,scrollTo:c,scrollToIndex:R,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...m,gridState:N,horizontalDirection:Y,initialTopMostItemIndex:A,totalListHeight:W,...h,endReached:le,propsReady:v,rangeChanged:Ee,startReached:xe,stateChanged:B,stateRestoreInProgress:L,...C}},Qe(ai,mt,Tr,bc,pn,ci,fn));function Lc(e,t,n){return Er(1,wo((e+n)/(wo(t)+n)))}function $c(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=gi(e,t,n,r[0].index);return{bottom:gi(e,t,n,r[r.length-1].index)+o,top:s}}function gi(e,t,n,r){const o=Lc(e.width,n.width,t.column),s=wo(r/o),i=s*n.height+Er(0,s-1)*t.row;return i>0?i+t.row:i}const Lx=Be(()=>{const e=q(f=>`Item ${f}`),t=q({}),n=q(null),r=q("virtuoso-grid-item"),o=q("virtuoso-grid-list"),s=q(hi),i=q("div"),a=q(Gn),c=(f,h=null)=>ft(F(t,oe(m=>m[f]),et()),h),u=q(!1),d=q(!1);return fe(we(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),$x=Be(([e,t])=>({...e,...t}),Qe(Dx,Lx)),Fx=y.memo(function(){const e=tt("gridState"),t=tt("listClassName"),n=tt("itemClassName"),r=tt("itemContent"),o=tt("computeItemKey"),s=tt("isSeeking"),i=Pt("scrollHeight"),a=tt("ItemComponent"),c=tt("ListComponent"),u=tt("ScrollSeekPlaceholder"),d=tt("context"),f=Pt("itemDimensions"),h=Pt("gap"),m=tt("log"),w=tt("stateRestoreInProgress"),v=Pt("reportReadyState"),g=An(y.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const S=x.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}h({column:zc("column-gap",getComputedStyle(x).columnGap,m),row:zc("row-gap",getComputedStyle(x).rowGap,m)})},[i,f,h,m]),!0,!1);return kc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:l.jsx(c,{className:t,ref:g,...ht(c,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?l.jsx(u,{...ht(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):y.createElement(a,{...ht(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),zx=y.memo(function(){const e=tt("HeaderComponent"),t=Pt("headerHeight"),n=tt("headerFooterTag"),r=An(y.useMemo(()=>s=>{t(hn(s,"height"))},[t]),!0,!1),o=tt("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...ht(e,o)})}):null}),Bx=y.memo(function(){const e=tt("FooterComponent"),t=Pt("footerHeight"),n=tt("headerFooterTag"),r=An(y.useMemo(()=>s=>{t(hn(s,"height"))},[t]),!0,!1),o=tt("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...ht(e,o)})}):null}),Hx=({children:e})=>{const t=y.useContext(Ec),n=Pt("itemDimensions"),r=Pt("viewportDimensions"),o=An(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),l.jsx("div",{ref:o,style:vo(!1),children:e})},Ux=({children:e})=>{const t=y.useContext(Ec),n=Pt("windowViewportRect"),r=Pt("itemDimensions"),o=tt("customScrollParent"),s=Xl(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),l.jsx("div",{ref:s,style:vo(!1),children:e})},Wx=y.memo(function({...e}){const t=tt("useWindowScroll"),n=tt("customScrollParent"),r=n||t?Kx:Vx,o=n||t?Ux:Hx,s=tt("context");return l.jsx(r,{...e,...ht(r,s),children:l.jsxs(o,{children:[l.jsx(zx,{}),l.jsx(Fx,{}),l.jsx(Bx,{})]})})}),{useEmitter:Fc,useEmitterValue:tt,usePublisher:Pt}=Cc($x,{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"}},Wx),Vx=jc({useEmitter:Fc,useEmitterValue:tt,usePublisher:Pt}),Kx=Rc({useEmitter:Fc,useEmitterValue:tt,usePublisher:Pt});function zc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,bt.WARN),t==="normal"?0:parseInt(t??"0",10)}const qx=Kr.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 xi({className:e,variant:t,...n}){return l.jsx("div",{className:Z(qx({variant:t}),e),...n})}function ae(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 Gx(e,t){const n=p.createContext(t),r=s=>{const{children:i,...a}=s,c=p.useMemo(()=>a,Object.values(a));return l.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=p.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 Yt(e,t=[]){let n=[];function r(s,i){const a=p.createContext(i),c=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:m,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[c])||a,g=p.useMemo(()=>w,Object.values(w));return l.jsx(v.Provider,{value:g,children:m})};u.displayName=s+"Provider";function d(f,h){var v;const m=((v=h==null?void 0:h[e])==null?void 0:v[c])||a,w=p.useContext(m);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>p.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return p.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,Yx(o,...t)]}function Yx(...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:c,scopeName:u})=>{const f=c(s)[`__scope${u}`];return{...a,...f}},{});return p.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var ct=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},Xx=p[" useInsertionEffect ".trim().toString()]||ct;function Rn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Jx({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const d=p.useRef(e!==void 0);p.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 u=p.useCallback(d=>{var f;if(a){const h=Zx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[c,u]}function Jx({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return Xx(()=>{s.current=t},[t]),p.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Zx(e){return typeof e=="function"}function Bc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function vi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Bc(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():Bc(e[o],null)}}}}function Pe(...e){return p.useCallback(vi(...e),e)}var Qx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ye=Qx.reduce((e,t)=>{const n=Tn.createSlot(`Primitive.${t}`),r=p.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),l.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Hc(e,t){e&&qr.flushSync(()=>e.dispatchEvent(t))}function ev(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var It=e=>{const{present:t,children:n}=e,r=tv(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Pe(r.ref,nv(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};It.displayName="Presence";function tv(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,c]=ev(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const u=yo(r.current);s.current=a==="mounted"?u:"none"},[a]),ct(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,m=yo(u);e?c("MOUNT"):m==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&h!==m?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),ct(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=m=>{const v=yo(r.current).includes(CSS.escape(m.animationName));if(m.target===t&&v&&(c("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=m=>{m.target===t&&(s.current=yo(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:p.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function yo(e){return(e==null?void 0:e.animationName)||"none"}function nv(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 rv=p[" useId ".trim().toString()]||(()=>{}),ov=0;function Xt(e){const[t,n]=p.useState(rv());return ct(()=>{n(r=>r??String(ov++))},[e]),e||(t?`radix-${t}`:"")}var So="Collapsible",[sv,WC]=Yt(So),[iv,wi]=sv(So),Uc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=Rn({prop:r,defaultProp:o??!1,onChange:i,caller:So});return l.jsx(iv,{scope:n,disabled:s,contentId:Xt(),open:c,onOpenToggle:p.useCallback(()=>u(d=>!d),[u]),children:l.jsx(ye.div,{"data-state":yi(c),"data-disabled":s?"":void 0,...a,ref:t})})});Uc.displayName=So;var Wc="CollapsibleTrigger",Vc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=wi(Wc,n);return l.jsx(ye.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":yi(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ae(e.onClick,o.onOpenToggle)})});Vc.displayName=Wc;var bi="CollapsibleContent",av=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=wi(bi,e.__scopeCollapsible);return l.jsx(It,{present:n||o.open,children:({present:s})=>l.jsx(lv,{...r,ref:t,present:s})})});av.displayName=bi;var lv=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=wi(bi,n),[a,c]=p.useState(r),u=p.useRef(null),d=Pe(t,u),f=p.useRef(0),h=f.current,m=p.useRef(0),w=m.current,v=i.open||a,g=p.useRef(v),x=p.useRef(void 0);return p.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),ct(()=>{const b=u.current;if(b){x.current=x.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const S=b.getBoundingClientRect();f.current=S.height,m.current=S.width,g.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(ye.div,{"data-state":yi(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!v,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:v&&o})});function yi(e){return e?"open":"closed"}var cv=Uc;const Kc=cv,qc=Vc,kr=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));kr.displayName="Card";const Ir=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 p-6",e),...t}));Ir.displayName="CardHeader";const Nr=p.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:Z("text-2xl font-semibold leading-none tracking-tight",e),...t}));Nr.displayName="CardTitle";const Gc=p.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));Gc.displayName="CardDescription";const Co=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("p-6 pt-0",e),...t}));Co.displayName="CardContent";const Yc=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("flex items-center p-6 pt-0",e),...t}));Yc.displayName="CardFooter";function Xc(){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 Pn=Xc();function uv(e){Pn=e}const Jc=/[&<>"']/,dv=new RegExp(Jc.source,"g"),Zc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,fv=new RegExp(Zc.source,"g"),hv={"&":"&","<":"<",">":">",'"':""","'":"'"},Qc=e=>hv[e];function pt(e,t){if(t){if(Jc.test(e))return e.replace(dv,Qc)}else if(Zc.test(e))return e.replace(fv,Qc);return e}const pv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function eu(e){return e.replace(pv,(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 mv=/(^|[^\[])\^/g;function qe(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(mv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const gv=/[^\w:]/g,xv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function tu(e,t,n){if(e){let r;try{r=decodeURIComponent(eu(n)).replace(gv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!xv.test(n)&&(n=yv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const To={},vv=/^[^:]+:\/*[^/]*$/,wv=/^([^:]+:)[\s\S]*$/,bv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function yv(e,t){To[" "+e]||(vv.test(e)?To[" "+e]=e+"/":To[" "+e]=ko(e,"/",!0)),e=To[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(wv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(bv,"$1")+t:e+t}const Eo={exec:function(){}};function nu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,u=i;for(;--u>=0&&a[u]==="\\";)c=!c;return c?"|":" |"}),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 ko(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 Sv(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 Cv(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 ru(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function ou(e,t,n,r){const o=t.href,s=t.title?pt(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:pt(i)}}function Tv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
37
|
+
`))>=0;){const ee=Ee.slice(0,He);Ee=Ee.slice(He+2);const se=xg(ee);if(!se)continue;let he;try{he=JSON.parse(se)}catch{console.debug("[use-chat] malformed SSE:",se.slice(0,200));continue}const ge=gg(he)?he.data:he;ce=Date.now();const ke=ge.seq;if(ke!==void 0){if(ke<=M){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:ke,lastProcessedSeq:M,type:ge.type});continue}M>0&&ke>M+1&&((L=j==null?void 0:j.onGap)==null||L.call(j,{from:M,to:ke})),M=ke,k.current=ke,v(ke)}if(R==null||R(ge),ge.type==="token"&&e.autoAppendAssistant!==!1)W.push(ge.content),de();else if(ge.type==="message_delta"){const De=ge.delta.filter(Ye=>Ye.type==="text").map(Ye=>Ye.text).join("");De&&e.autoAppendAssistant!==!1&&(W.push(De),de())}else G!==null&&cancelAnimationFrame(G),te(),ge.type==="checkpoint"?m(ge.checkpointId):ge.type==="error"&&u(ge.message)}}te()}catch(_e){if(_e.name!=="AbortError"){const Re=_e.message||String(_e);u(Re),(A=j==null?void 0:j.onError)==null||A.call(j,Re)}}finally{try{await le.cancel()}catch{}finally{(D=le.releaseLock)==null||D.call(le)}G!==null&&typeof window<"u"&&window.cancelAnimationFrame(G),clearInterval($e),a(!1),x(!1),b.current=null}}catch(Y){if(Y.name!=="AbortError"){const Z=Y.message||String(Y);u(Z),(H=j==null?void 0:j.onError)==null||H.call(j,Z)}}finally{a(!1),x(!1),b.current=null}})(),{close:()=>$.abort()}},[t,n,r,e.autoAppendAssistant]);return y.useEffect(()=>()=>{var _;S.current=!1,(_=b.current)==null||_.abort()},[]),{isStreaming:i,error:c,assistantText:d,lastCheckpointId:h,lastSeq:w,connected:g,stream:N,stop:T,clear:I,setToken:C}}function gg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function xg(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 Bl=y.createContext(null);function vg({children:e,enableFileAgentRouting:t=!1,fileAgentId:n="invoice_reader",onRegisterThreadCallbacks:r}){const{api:o,baseUrl:s}=so(),i=y.useMemo(()=>kl(s),[s]),{currentThreadId:a,setCurrentThreadId:c,isLoadingThread:u,refreshThreads:d}=mr(),f=Jm(),{state:h,dispatch:m,seed:w,prepend:v,pushUser:g,onEvent:x,reset:b}=$l(),[S,k]=y.useState(!1),[C,T]=y.useState(!1),[I,N]=y.useState(null),[_,R]=y.useState(void 0),[j,$]=y.useState(void 0),z=20,O=y.useRef(a);y.useEffect(()=>{O.current=a},[a]);const V=y.useRef(null),B=y.useRef(!1),K=y.useCallback(async()=>{if(B.current){B.current=!1;try{await d()}catch(Q){console.error("[MessagesProvider] Failed to refresh threads:",Q)}}},[d]),{isStreaming:L,error:A,stream:D,stop:H,setToken:Y}=zl({baseUrl:i,token:null}),Z=y.useRef(L);y.useEffect(()=>{Z.current=L,L||K()},[L,K]);const le=y.useCallback(()=>{B.current=!0,Z.current||K()},[K]);y.useEffect(()=>{var Ne;const Q=o.getAuthToken();Y(Q);const X=(Ne=o.onTokenChange)==null?void 0:Ne.call(o,He=>{Y(He)});return()=>{X==null||X()}},[o,Y]),y.useEffect(()=>{f(L?{type:"STREAM_START",assistantId:h.assemblingId??void 0}:{type:"STREAM_END"})},[L,h.assemblingId,f]),y.useEffect(()=>{f(A?{type:"STREAM_ERROR",error:A}:{type:"CLEAR_ERROR"})},[A,f]),y.useEffect(()=>{h.lastCheckpointId&&f({type:"UPDATE_CHECKPOINT",checkpointId:h.lastCheckpointId,checkpointNs:h.lastCheckpointNs??void 0})},[h.lastCheckpointId,h.lastCheckpointNs,f]),y.useEffect(()=>{f({type:"UPDATE_ASSEMBLING_ID",assistantId:h.assemblingId})},[h.assemblingId,f]);const xe=y.useCallback((Q,X)=>{const Ne=Array.isArray(Q==null?void 0:Q.messages)?Q.messages:[];X==="replace"?(console.log("[MessagesProvider] Replacing messages, count:",Ne.length),w(Ne,{checkpointId:(Q==null?void 0:Q.checkpointId)??null,checkpointNs:(Q==null?void 0:Q.checkpointNs)??null})):X==="prepend"&&Ne.length&&(console.log("[MessagesProvider] Prepending messages, count:",Ne.length),v(Ne)),N((Q==null?void 0:Q.nextCursor)??null),k(!!(Q!=null&&Q.hasMore)),R(He=>(Q==null?void 0:Q.checkpointId)??He??void 0),$(He=>(Q==null?void 0:Q.checkpointNs)??He??void 0)},[w,v]),Ee=y.useCallback(Q=>{const X=Q.threadId,Ne=!!Q.created,He=!!Q.ready;if(a!==X){const ee=!a&&h.messages.length<=1;ee&&(V.current=X),c(X),(He||Ne||ee)&&le();return}(He||Ne)&&le()},[a,h.messages.length,c,le]),W=y.useCallback(({from:Q,to:X})=>{const Ne=O.current;Ne&&console.warn(`[MessagesProvider] Stream sequence gap detected (${Q} -> ${X}) for thread ${Ne}`)},[]),{handleEvent:M,reset:G}=mg({onThreadInfo:Ee,onMessageEvent:x,onUnhandledEvent:Q=>{console.warn(`[MessagesProvider] Unhandled stream event type: ${Q.type}`,Q)},onSequenceGap:W}),te=y.useCallback(async Q=>{if(!a)throw new Error("No active thread");if(C||!S)return;const X=I;if(X){T(!0);try{const Ne=await o.getMessages({threadId:a,checkpointId:_,checkpointNs:j,limit:(Q==null?void 0:Q.limit)??z,beforeId:X});xe(Ne,"prepend")}finally{T(!1)}}},[o,a,_,j,I,S,C,xe,z]),de=y.useCallback(()=>{console.log("[MessagesProvider] Clearing messages"),b([]),k(!1),T(!1),N(null),R(void 0),$(void 0)},[b]),ce=y.useCallback((Q,X)=>{console.log("[MessagesProvider] Handling thread load for",Q),B.current=!1,xe(X,"replace")},[xe]),$e=y.useCallback(()=>{console.log("[MessagesProvider] Handling thread clear"),B.current=!1,de()},[de]),Ge=y.useMemo(()=>({onThreadLoaded:ce,onThreadCleared:$e}),[ce,$e]);y.useEffect(()=>{if(r)return r(Ge),()=>{r({onThreadLoaded:()=>{},onThreadCleared:()=>{}})}},[r,Ge]);const _e=y.useCallback(async(Q,X)=>{var Xe;!a&&!(X!=null&&X.payloadExtras)&&console.warn("[MessagesProvider] No thread ID - message will create new thread");const Ne=(X==null?void 0:X.attachments)||[],{contentParts:He,filesInfo:ee}=await eg(o,Ne),se=[...He];Q&&Q.trim()&&se.push({type:"text",text:Q.trim()});const he={id:((Xe=crypto.randomUUID)==null?void 0:Xe.call(crypto))||`user-${Date.now()}`,role:"user",content:se,createdAt:new Date().toISOString(),checkpointId:(X==null?void 0:X.checkpointId)??h.lastCheckpointId??void 0,checkpointNs:(X==null?void 0:X.checkpointNs)??h.lastCheckpointNs??void 0};g(he);const ge={...he,content:se},ke={...(X==null?void 0:X.payloadExtras)??{}},De=Ne&&Ne.length>0,Ye={...a?{threadId:a}:{},payload:{messages:[ge],files_info:ee,...t&&De&&n?{active_agent:n}:{},...ke},checkpointId:(X==null?void 0:X.checkpointId)??h.lastCheckpointId??void 0,checkpointNs:(X==null?void 0:X.checkpointNs)??h.lastCheckpointNs??void 0,nodeFilter:X==null?void 0:X.nodeFilter,config:X==null?void 0:X.config};G(),le(),D(Ye,Je=>{M(Je)},{onError:Je=>console.warn("[MessagesProvider] Stream error:",Je),onOpen:({threadId:Je,created:yt})=>{if(!a&&Je){const ln=h.messages.length<=1;ln&&(V.current=Je),c(Je),(yt||ln)&&le()}},onGap:W})},[a,g,D,M,G,W,h.lastCheckpointId,h.lastCheckpointNs,h.messages.length,o,le,c,t,n]),Re=y.useCallback(async(Q,X,Ne)=>{const He=O.current;if(!He)throw new Error("No active thread to handle interrupt");try{console.log(`[MessagesProvider] Handling interrupt ${Q}: ${X?"approved":"rejected"}`);const ee=X?Ne??!0:!1;await o.resume({threadId:He,value:ee}),console.log(`[MessagesProvider] Interrupt ${Q} handled successfully`)}catch(ee){throw console.error(`[MessagesProvider] Failed to handle interrupt ${Q}:`,ee),ee}},[o]),We={messages:h.messages,assemblingId:h.assemblingId,lastUserMessage:null,hasMoreHistory:S,isLoadingHistory:C,send:_e,stop:H,loadOlderMessages:te,clearMessages:de,handleInterrupt:Re};return l.jsx(Bl.Provider,{value:We,children:e})}function wg(e){return l.jsx(vg,{...e})}function qs(){const e=y.useContext(Bl);if(!e)throw new Error("useMessages must be used within MessagesProvider");return e}function io({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:c}){const u=y.useRef({onThreadLoaded:()=>{},onThreadCleared:()=>{}}),d=y.useCallback(m=>{u.current=m},[]),f=y.useCallback((m,w)=>{u.current.onThreadLoaded(m,w)},[]),h=y.useCallback(()=>{u.current.onThreadCleared()},[]);return l.jsx(qm,{apiConfig:t,children:l.jsx(Xm,{children:l.jsx(ng,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,onError:a,onThreadChange:c,onThreadLoaded:f,onThreadCleared:h,children:l.jsx(wg,{enableFileAgentRouting:s,fileAgentId:i,onRegisterThreadCallbacks:d,children:e})})})})}function J(...e){return Sp.twMerge(yp.clsx(e))}const bg=Kr.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),ze=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Tn.Slot:"button";return l.jsx(i,{className:J(bg({variant:t,size:n,className:e})),ref:s,...o})});ze.displayName="Button";const Hl=p.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:J("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}));Hl.displayName="Textarea";function yg({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:c,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,m]=y.useState(e),[w,v]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{m(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=y.useCallback(()=>{const N=g.current;N&&(N.style.height="auto",N.style.height=`${N.scrollHeight}px`)},[]);y.useEffect(()=>{x()},[x]);const b=y.useCallback(async N=>{N&&N.preventDefault();const _=(h??"").trim();!_&&!f||v(()=>{try{const R=i(_);R&&typeof R.then=="function"?R.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(N=>{m(N.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),k=y.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),b()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[b,t,a]),I=`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))]":""} ${d}`;return l.jsx("form",{onSubmit:N=>void b(N),className:`w-full ${u}`,children:l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(Hl,{ref:g,value:h,onChange:S,onKeyDown:k,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(ze,{type:"button",onClick:()=>{c==null||c()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!c,children:l.jsx(ne.Square,{size:16})}):l.jsx(ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:l.jsx(ne.Send,{size:16})})})]})})}const Sg=y.memo(yg),ao=0,dn=1,qn=2,Ul=4;function Wl(e){return()=>e}function Cg(e){e()}function Vl(e,t){return n=>e(t(n))}function Kl(e,t){return()=>e(t)}function Tg(e,t){return n=>e(t,n)}function Gs(e){return e!==void 0}function Eg(...e){return()=>{e.map(Cg)}}function Gn(){}function lo(e,t){return t(e),e}function kg(e,t){return t(e)}function Qe(...e){return e}function Ue(e,t){return e(dn,t)}function Ae(e,t){e(ao,t)}function Ys(e){e(qn)}function ot(e){return e(Ul)}function fe(e,t){return Ue(e,Tg(t,ao))}function Ft(e,t){const n=e(dn,r=>{n(),t(r)});return n}function ql(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Gl(e,t){return e===t}function et(e=Gl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function be(e){return t=>n=>{e(n)&&t(n)}}function oe(e){return t=>Vl(t,e)}function Kt(e){return t=>()=>{t(e)}}function F(e,...t){const n=Ig(...t);return(r,o)=>{switch(r){case qn:Ys(e);return;case dn:return Ue(e,n(o))}}}function qt(e,t){return n=>r=>{n(t=e(t,r))}}function Nn(e){return t=>n=>{e>0?e--:t(n)}}function on(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function je(...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);Ue(s,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Ig(...e){return t=>e.reduceRight(kg,t)}function Ng(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case dn:return s?n===s?void 0:(r(),n=s,t=Ue(e,s),t):(r(),Gn);case qn:r(),n=null;return}}}function q(e){let t=e;const n=Me();return(r,o)=>{switch(r){case ao:t=o;break;case dn:{o(t);break}case Ul:return t}return n(r,o)}}function ft(e,t){return lo(q(t),n=>fe(e,n))}function Me(){const e=[];return(t,n)=>{switch(t){case ao:e.slice().forEach(r=>{r(n)});return;case qn:e.splice(0,e.length);return;case dn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Et(e){return lo(Me(),t=>fe(e,t))}function Be(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Ag(),singleton:n}}const Ag=()=>Symbol();function _g(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(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function it(...e){const t=Me(),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);Ue(s,c=>{n[i]=c,r=r|a,r===o&&Ae(t,n)})}),function(s,i){switch(s){case qn:{Ys(t);return}case dn:return r===o&&i(n),Ue(t,i)}}}function we(e,t=Gl){return F(e,et(t))}function Xs(...e){return function(t,n){switch(t){case qn:return;case dn:return Eg(...e.map(r=>Ue(r,n)))}}}var bt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(bt||{});const jg={0:"debug",3:"error",1:"log",2:"warn"},Rg=()=>typeof globalThis>"u"?window:globalThis,fn=Be(()=>{const e=q(3);return{log:q((t,n,r=1)=>{var o;const s=(o=Rg().VIRTUOSO_LOG_LEVEL)!=null?o:ot(e);r>=s&&console[jg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function An(e,t,n){return Js(e,t,n).callbackRef}function Js(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};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 Pg(e,t,n,r,o,s,i,a,c){const u=y.useCallback(d=>{const f=Og(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const m=h.lastElementChild.dataset.viewportType==="window";let w;m&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:m?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:m?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:m?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?Yl("column-gap",getComputedStyle(d).columnGap,o):Yl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Js(u,n,c)}function Og(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 c=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},bt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==c-1?s.push({endIndex:c,size:d,startIndex:c}):s[s.length-1].endIndex++}return s}function Yl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,bt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Xl(e,t,n){const r=y.useRef(null),o=y.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),d=u.width;let f,h;if(t){const m=t.getBoundingClientRect(),w=u.top-m.top;h=m.height-Math.max(0,w),f=w+t.scrollTop}else{const m=i.current.ownerDocument.defaultView;h=m.innerHeight-Math.max(0,u.top),f=u.top+m.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Js(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var c;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const mt=Be(()=>{const e=Me(),t=Me(),n=q(0),r=Me(),o=q(0),s=Me(),i=Me(),a=q(0),c=q(0),u=q(0),d=q(0),f=Me(),h=Me(),m=q(!1),w=q(!1),v=q(!1);return fe(F(e,oe(({scrollTop:g})=>g)),t),fe(F(e,oe(({scrollHeight:g})=>g)),i),fe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:m,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),gr={lvl:0};function Jl(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:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Ke(e){return e===gr}function xr(e,t){if(!Ke(e))return t===e.k?e.v:t<e.k?xr(e.l,t):xr(e.r,t)}function zt(e,t,n="k"){if(Ke(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=zt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return zt(e.l,t,n)}function kt(e,t,n){return Ke(e)?ec(t,n,1):t===e.k?lt(e,{k:t,v:n}):t<e.k?tc(lt(e,{l:kt(e.l,t,n)})):tc(lt(e,{r:kt(e.r,t,n)}))}function Yn(){return gr}function co(e,t,n){if(Ke(e))return[];const r=zt(e,t)[0];return Mg(Qs(e,r,n))}function Zs(e,t){if(Ke(e))return gr;const{k:n,l:r,r:o}=e;if(t===n){if(Ke(r))return o;if(Ke(o))return r;{const[s,i]=Ql(r);return uo(lt(e,{k:s,l:Zl(r),v:i}))}}else return t<n?uo(lt(e,{l:Zs(r,t)})):uo(lt(e,{r:Zs(o,t)}))}function _n(e){return Ke(e)?[]:[..._n(e.l),{k:e.k,v:e.v},..._n(e.r)]}function Qs(e,t,n){if(Ke(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Qs(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Qs(s,t,n))),a}function uo(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(ei(t))return nc(lt(e,{lvl:n-1}));if(!Ke(t)&&!Ke(t.r))return lt(t.r,{l:lt(t,{r:t.r.l}),lvl:n,r:lt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ei(e))return ti(lt(e,{lvl:n-1}));if(!Ke(r)&&!Ke(r.l)){const o=r.l,s=ei(o)?r.lvl-1:r.lvl;return lt(o,{l:lt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ti(lt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function lt(e,t){return ec(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 Zl(e){return Ke(e.r)?e.l:uo(lt(e,{r:Zl(e.r)}))}function ei(e){return Ke(e)||e.lvl>e.r.lvl}function Ql(e){return Ke(e.r)?[e.k,e.v]:Ql(e.r)}function ec(e,t,n,r=gr,o=gr){return{k:e,l:r,lvl:n,r:o,v:t}}function tc(e){return ti(nc(e))}function nc(e){const{l:t}=e;return!Ke(t)&&t.lvl===e.lvl?lt(t,{r:lt(e,{l:t.r})}):e}function ti(e){const{lvl:t,r:n}=e;return!Ke(n)&&!Ke(n.r)&&n.lvl===t&&n.r.lvl===t?lt(n,{l:lt(e,{r:n.l}),lvl:t+1}):e}function Mg(e){return Jl(e,({k:t,v:n})=>({index:t,value:n}))}function rc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function vr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ni=Be(()=>({recalcInProgress:q(!1)}),[],{singleton:!0});function oc(e,t,n){return e[fo(e,t,n)]}function fo(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 Dg(e,t,n,r){const o=fo(e,t,r),s=fo(e,n,r,o);return e.slice(o,s+1)}function hn(e,t){return Math.round(e.getBoundingClientRect()[t])}function ho(e){return!Ke(e.groupOffsetTree)}function ri({index:e},t){return t===e?0:t<e?-1:1}function Lg(){return{groupIndices:[],groupOffsetTree:Yn(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Yn()}}function $g(e,t){let n=Ke(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ke(e)){e=kt(e,0,s);continue}const a=co(e,i-1,o+1);if(a.some(Vg(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:h}of a)c?(o>=f||s===h)&&(e=Zs(e,f)):(u=h!==s,c=!0),d>o&&o>=f&&h!==s&&(e=kt(e,o+1,h));u&&(e=kt(e,i,s))}return[e,n]}function Fg(e){return typeof e.groupIndex<"u"}function zg({offset:e},t){return t===e?0:t<e?-1:1}function wr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=oc(t,e,ri),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function sc(e,t){if(!ho(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function ic(e,t,n){if(Fg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=sc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Bg(e,t,n,r=0){return r>0&&(t=Math.max(t,oc(e,r,ri).offset)),Jl(Dg(e,t,n,zg),Wg)}function Hg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,bt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ke(s)&&t.length===2){const h=t[0].size,m=t[1].size;i=n.reduce((w,v)=>kt(kt(w,v,h),v+1,m),i)}else[i,a]=$g(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=oi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,m)=>kt(h,m,wr(m,f,o)),Yn()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Ug(e){return _n(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 ac(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 oi(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=fo(o,t-1,ri),a=o[c].offset;const u=zt(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===zt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of co(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Wg(e){return{index:e.index,value:e}}function Vg(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 Kg={offsetHeight:"height",offsetWidth:"width"},Gt=Be(([{log:e},{recalcInProgress:t}])=>{const n=Me(),r=Me(),o=ft(r,0),s=Me(),i=Me(),a=q(0),c=q([]),u=q(void 0),d=q(void 0),f=q((C,T)=>hn(C,Kg[T])),h=q(void 0),m=q(0),w=Lg(),v=ft(F(n,je(c,e,m),qt(Hg,w),et()),w),g=ft(F(c,et(),qt((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),oe(({prev:C})=>C)),[]);fe(F(c,be(C=>C.length>0),je(v,m),oe(([C,T,I])=>{const N=C.reduce((_,R,j)=>kt(_,R,wr(R,T.offsetTree,I)||j),Yn());return{...T,groupIndices:C,groupOffsetTree:N}})),v),fe(F(r,je(v),be(([C,{lastIndex:T}])=>C<T),oe(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),fe(u,d);const x=ft(F(u,oe(C=>C===void 0)),!0);fe(F(d,be(C=>C!==void 0&&Ke(ot(v).sizeTree)),oe(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Et(F(n,je(v),qt(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),oe(C=>C.changed)));Ue(F(a,qt((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),oe(C=>C.diff)),C=>{const{groupIndices:T}=ot(v);if(C>0)Ae(t,!0),Ae(s,C+ac(C,T));else if(C<0){const I=ot(g);I.length>0&&(C-=ac(-C,I)),Ae(i,C)}}),Ue(F(a,je(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},bt.ERROR)});const S=Et(s);fe(F(s,je(v),oe(([C,T])=>{const I=T.groupIndices.length>0,N=[],_=T.lastSize;if(I){const R=xr(T.sizeTree,0);let j=0,$=0;for(;j<C;){const O=T.groupIndices[$],V=T.groupIndices.length===$+1?1/0:T.groupIndices[$+1]-O-1;N.push({endIndex:O,size:R,startIndex:O}),N.push({endIndex:O+1+V-1,size:_,startIndex:O+1}),$++,j+=V+1}const z=_n(T.sizeTree);return j!==C&&z.shift(),z.reduce((O,{k:V,v:B})=>{let K=O.ranges;return O.prevSize!==0&&(K=[...O.ranges,{endIndex:V+C-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:V+C,prevSize:B,ranges:K}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return _n(T.sizeTree).reduce((R,{k:j,v:$})=>({prevIndex:j+C,prevSize:$,ranges:[...R.ranges,{endIndex:j+C-1,size:R.prevSize,startIndex:R.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Et(F(i,je(v,m),oe(([C,{offsetTree:T},I])=>{const N=-C;return wr(N,T,I)})));return fe(F(i,je(v,m),oe(([C,T,I])=>{if(T.groupIndices.length>0){if(Ke(T.sizeTree))return T;let N=Yn();const _=ot(g);let R=0,j=0,$=0;for(;R<-C;){$=_[j];const z=_[j+1]-$-1;j++,R+=z+1}if(N=_n(T.sizeTree).reduce((z,{k:O,v:V})=>kt(z,Math.max(0,O+C),V),N),R!==-C){const z=xr(T.sizeTree,$);N=kt(N,0,z);const O=zt(T.sizeTree,-C+1)[1];N=kt(N,1,O)}return{...T,sizeTree:N,...oi(T.offsetTree,0,N,I)}}else{const N=_n(T.sizeTree).reduce((_,{k:R,v:j})=>kt(_,Math.max(0,R+C),j),Yn());return{...T,sizeTree:N,...oi(T.offsetTree,0,N,I)}}})),v),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:m,groupIndices:c,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Qe(fn,ni),{singleton:!0});function qg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const lc=Be(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Me(),i=Me(),a=Et(F(s,oe(qg)));return fe(F(a,oe(c=>c.totalCount)),n),fe(F(a,oe(c=>c.groupIndices)),e),fe(F(it(o,t,r),be(([c,u])=>ho(u)),oe(([c,u,d])=>zt(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),et(),oe(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Qe(Gt,mt)),pn=Be(([{log:e}])=>{const t=q(!1),n=Et(F(t,be(r=>r),et()));return Ue(t,r=>{r&&ot(e)("props updated",{},bt.DEBUG)}),{didMount:n,propsReady:t}},Qe(fn),{singleton:!0}),Gg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function cc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Gg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const br=Be(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const m=Me(),w=Me(),v=q(0);let g=null,x=null,b=null;function S(){g&&(g(),g=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Ae(c,!1)}return fe(F(m,je(n,f,r,v,a,i,h),je(e,s,o),oe(([[k,C,T,I,N,_,R,j],$,z,O])=>{const V=cc(k),{align:B,behavior:K,offset:L}=V,A=I-1,D=ic(V,C,A);let H=wr(D,C.offsetTree,$)+_;B==="end"?(H+=z+zt(C.sizeTree,D)[1]-T+O,D===A&&(H+=R)):B==="center"?H+=(z+zt(C.sizeTree,D)[1]-T+O)/2:H-=N,L&&(H+=L);const Y=Z=>{S(),Z?(j("retrying to scroll to",{location:k},bt.DEBUG),Ae(m,k)):(Ae(w,!0),j("list did not change, scroll successful",{},bt.DEBUG))};if(S(),K==="smooth"){let Z=!1;b=Ue(t,le=>{Z=Z||le}),g=Ft(d,()=>{Y(Z)})}else g=Ft(F(t,Yg(150)),Y);return x=setTimeout(()=>{S()},1200),Ae(c,!0),j("scrolling from index to",{behavior:K,index:D,top:H},bt.DEBUG),{behavior:K,top:H}})),u),{scrollTargetReached:w,scrollToIndex:m,topListHeight:v}},Qe(Gt,mt,fn),{singleton:!0});function Yg(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function si(e,t){e==0?t():requestAnimationFrame(()=>{si(e-1,t)})}function ii(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const yr=Be(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=q(!0),c=q(0),u=q(!0);return fe(F(i,je(c),be(([d,f])=>!!f),Kt(!1)),a),fe(F(i,je(c),be(([d,f])=>!!f),Kt(!1)),u),Ue(F(it(t,i),je(a,n,e,u),be(([[,d],f,{sizeTree:h},m,w])=>d&&(!Ke(h)||Gs(m))&&!f&&!w),je(c)),([,d])=>{Ft(o,()=>{Ae(u,!0)}),si(4,()=>{Ft(r,()=>{Ae(a,!0)}),Ae(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Qe(Gt,mt,br,pn),{singleton:!0});function uc(e,t){return Math.abs(e-t)<1.01}const Sr="up",Cr="down",Xg="none",Jg={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Zg=0,Tr=Be(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=q(!1),a=q(!0),c=Me(),u=Me(),d=q(4),f=q(Zg),h=ft(F(Xs(F(we(o),Nn(1),Kt(!0)),F(we(o),Nn(1),Kt(!1),ql(100))),et()),!1),m=ft(F(Xs(F(n,Kt(!0)),F(n,Kt(!1),ql(200))),et()),!1);fe(F(it(we(o),we(f)),oe(([b,S])=>b<=S),et()),a),fe(F(a,on(50)),u);const w=Et(F(it(r,we(s),we(t),we(e),we(d)),qt((b,[{scrollHeight:S,scrollTop:k},C,T,I,N])=>{const _=k+C-S>-N,R={scrollHeight:S,scrollTop:k,viewportHeight:C};if(_){let $,z;return k>b.state.scrollTop?($="SCROLLED_DOWN",z=b.state.scrollTop-k):($="SIZE_DECREASED",z=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:$,scrollTopDelta:z,state:R}}let j;return R.scrollHeight>b.state.scrollHeight?j="SIZE_INCREASED":C<b.state.viewportHeight?j="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?j="SCROLLING_UPWARDS":j="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:j,state:R}},Jg),et((b,S)=>b&&b.atBottom===S.atBottom))),v=ft(F(r,qt((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(uc(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),be(b=>b.changed),oe(b=>b.jump)),0);fe(F(w,oe(b=>b.atBottom)),i),fe(F(i,on(50)),c);const g=q(Cr);fe(F(r,oe(({scrollTop:b})=>b),et(),qt((b,S)=>ot(m)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Sr:Cr,prevScrollTop:S},{direction:Cr,prevScrollTop:0}),oe(b=>b.direction)),g),fe(F(r,on(50),Kt(Xg)),g);const x=q(0);return fe(F(h,be(b=>!b),Kt(0)),x),fe(F(o,on(100),je(h),be(([b,S])=>!!S),qt(([b,S],[k])=>[S,k],[0,0]),oe(([b,S])=>S-b)),x),{atBottomState:w,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},Qe(mt)),po="top",mo="bottom",dc="none";function fc(e,t,n){return typeof e=="number"?n===Sr&&t===po||n===Cr&&t===mo?e:0:n===Sr?t===po?e.main:e.reverse:t===mo?e.main:e.reverse}function hc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ai=Be(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Me(),i=q(0),a=q(0),c=q(0),u=ft(F(it(we(r),we(o),we(n),we(s,vr),we(c),we(i),we(t),we(e),we(a)),oe(([d,f,h,[m,w],v,g,x,b,S])=>{const k=d-b,C=g+x,T=Math.max(h-k,0);let I=dc;const N=hc(S,po),_=hc(S,mo);return m-=b,m+=h+x,w+=h+x,w-=b,m>d+C-N&&(I=Sr),w<d-T+f+_&&(I=Cr),I!==dc?[Math.max(k-h-fc(v,po,I)-N,0),k-T-x+f+fc(v,mo,I)+_]:null}),be(d=>d!=null),et(vr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},Qe(mt),{singleton:!0});function Qg(e,t,n){if(ho(t)){const r=sc(e,t);return[{index:zt(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 li={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function go(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const v=e[e.length-1];d=v.offset+v.size}const f=n-i,h=a+f*c+(f-1)*r,m=u,w=h-d;return{bottom:d,firstItemIndex:s,items:mc(e,o,s),offsetBottom:w,offsetTop:u,top:m,topItems:mc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function pc(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,c=ii(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return go(u,[],a,o,n,r)}function mc(e,t,n){if(e.length===0)return[];if(!ho(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=co(t.groupOffsetTree,r,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const jn=Be(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:m},{recalcInProgress:w}])=>{const v=q([]),g=q(0),x=Me();fe(s.topItemsIndexes,v);const b=ft(F(it(m,w,we(c,vr),we(o),we(r),we(u),d,we(v),we(t),we(n),e),be(([T,I,,N,,,,,,,_])=>{const R=_&&_.length!==N;return T&&!I&&!R}),oe(([,,[T,I],N,_,R,j,$,z,O,V])=>{const B=_,{offsetTree:K,sizeTree:L}=B,A=ot(g);if(N===0)return{...li,totalCount:N};if(T===0&&I===0)return A===0?{...li,totalCount:N}:pc(A,R,_,z,O,V||[]);if(Ke(L))return A>0?null:go(Qg(ii(R,N),B,V),[],N,O,B,z);const D=[];if($.length>0){const xe=$[0],Ee=$[$.length-1];let W=0;for(const M of co(L,xe,Ee)){const G=M.value,te=Math.max(M.start,xe),de=Math.min(M.end,Ee);for(let ce=te;ce<=de;ce++)D.push({data:V==null?void 0:V[ce],index:ce,offset:W,size:G}),W+=G}}if(!j)return go([],D,N,O,B,z);const H=$.length>0?$[$.length-1]+1:0,Y=Bg(K,T,I,H);if(Y.length===0)return null;const Z=N-1,le=lo([],xe=>{for(const Ee of Y){const W=Ee.value;let M=W.offset,G=Ee.start;const te=W.size;if(W.offset<T){G+=Math.floor((T-W.offset+O)/(te+O));const ce=G-Ee.start;M+=ce*te+ce*O}G<H&&(M+=(H-G)*te,G=H);const de=Math.min(Ee.end,Z);for(let ce=G;ce<=de&&!(M>=I);ce++)xe.push({data:V==null?void 0:V[ce],index:ce,offset:M,size:te}),M+=te+O}});return go(le,D,N,O,B,z)}),be(T=>T!==null),et()),li);fe(F(e,be(Gs),oe(T=>T==null?void 0:T.length)),o),fe(F(b,oe(T=>T.topListHeight)),f),fe(f,a),fe(F(b,oe(T=>[T.top,T.bottom])),i),fe(F(b,oe(T=>T.items)),x);const S=Et(F(b,be(({items:T})=>T.length>0),je(o,e),be(([{items:T},I])=>T[T.length-1].originalIndex===I-1),oe(([,T,I])=>[T-1,I]),et(vr),oe(([T])=>T))),k=Et(F(b,on(200),be(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),oe(({items:T})=>T[0].index),et())),C=Et(F(b,be(({items:T})=>T.length>0),oe(({items:T})=>{let I=0,N=T.length-1;for(;T[I].type==="group"&&I<N;)I++;for(;T[N].type==="group"&&N>I;)N--;return{endIndex:T[N].index,startIndex:T[I].index}}),et(rc)));return{endReached:S,initialItemCount:g,itemsRendered:x,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:v,...h}},Qe(Gt,lc,ai,yr,br,Tr,pn,ni),{singleton:!0}),gc=Be(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Me(),i=ft(F(it(n,e,r,t,o),oe(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return fe(we(i),s),{totalListHeight:i,totalListHeightChanged:s}},Qe(mt,jn),{singleton:!0}),ex=Be(([{viewportHeight:e},{totalListHeight:t}])=>{const n=q(!1),r=ft(F(it(n,e,t),be(([o])=>o),oe(([,o,s])=>Math.max(0,o-s)),on(0),et()),0);return{alignToBottom:n,paddingTopAddition:r}},Qe(mt,gc),{singleton:!0}),xc=Be(()=>({context:q(null)})),tx=({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,vc=Be(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=Me();return fe(F(d,je(t,c,n,s,o,r,a),je(e),oe(([[f,h,m,w,v,g,x,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=tx,done:I,...N}=f,_=ic(f,h,w-1),R=wr(_,h.offsetTree,S)+v+g,j=R+zt(h.sizeTree,_)[1],$=b+g,z=b+m-x,O=T({itemBottom:j,itemTop:R,locationParams:{align:k,behavior:C,...N},viewportBottom:z,viewportTop:$});return O?I&&Ft(F(i,be(V=>!V),Nn(ot(i)?1:2)),I):I&&I(),O}),be(f=>f!==null)),u),{scrollIntoView:d}},Qe(Gt,mt,br,jn,fn),{singleton:!0});function wc(e){return e?e==="smooth"?"smooth":"auto":!1}const nx=(e,t)=>typeof e=="function"?wc(e(t)):t&&wc(e),rx=Be(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:m}])=>{const w=q(!1),v=Me();let g=null;function x(C){Ae(i,{align:"end",behavior:C,index:"LAST"})}Ue(F(it(F(we(t),Nn(1)),c),je(we(w),s,a,f),oe(([[C,T],I,N,_,R])=>{let j=T&&_,$="auto";return j&&($=nx(I,N||R),j=j&&!!$),{followOutputBehavior:$,shouldFollow:j,totalCount:C}}),be(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{g&&(g(),g=null),ot(n)?requestAnimationFrame(()=>{ot(d)("following output to ",{totalCount:T},bt.DEBUG),x(C)}):g=Ft(e,()=>{ot(d)("following output to ",{totalCount:T},bt.DEBUG),x(C),g=null})});function b(C){const T=Ft(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(ot(d)("scrolling to bottom due to increased size",{},bt.DEBUG),x("auto"))});setTimeout(T,100)}Ue(F(it(we(w),t,u),be(([C,,T])=>C&&T),qt(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),be(({refreshed:C})=>C),je(w,t)),([,C])=>{ot(a)&&b(C!==!1)}),Ue(v,()=>{b(ot(w)!==!1)}),Ue(it(we(w),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=q(null),k=Me();return fe(Xs(F(we(r),oe(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),F(we(t))),k),Ue(F(it(F(k,Nn(1)),c),je(we(S),a,f,h),oe(([[C,T],I,N,_,R])=>T&&N&&(I==null?void 0:I({context:R,totalCount:C,scrollingInProgress:_}))),be(C=>!!C),on(0)),C=>{g&&(g(),g=null),ot(n)?requestAnimationFrame(()=>{ot(d)("scrolling into view",{}),Ae(m,C)}):g=Ft(e,()=>{ot(d)("scrolling into view",{}),Ae(m,C),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:S}},Qe(Gt,Tr,br,yr,pn,fn,mt,xc,vc)),ox=Be(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(F(a,je(s),be(([,c])=>c!==0),je(o,r,t,n,e),oe(([[,c],u,d,f,h,m=[]])=>pc(c,u,d,f,h,m))),i),{}),Qe(Gt,yr,jn,pn),{singleton:!0}),sx=Be(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=q(0);return Ue(F(e,je(r),be(([,o])=>o!==0),oe(([,o])=>({top:o}))),o=>{Ft(F(n,Nn(1),be(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Ae(t,o)})})}),{initialScrollTop:r}},Qe(pn,mt,jn),{singleton:!0}),bc=Be(([{scrollVelocity:e}])=>{const t=q(!1),n=Me(),r=q(!1);return fe(F(e,je(r,t,n),be(([o,s])=>!!s),oe(([o,s,i,a])=>{const{enter:c,exit:u}=s;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),et()),t),Ue(F(it(t,e,n),je(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Qe(Tr),{singleton:!0}),ci=Be(([{scrollContainerState:e,scrollTo:t}])=>{const n=Me(),r=Me(),o=Me(),s=q(!1),i=q(void 0);return fe(F(it(n,r),oe(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),fe(F(t,je(r),oe(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Qe(mt)),ix=Be(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=Me(),d=q(void 0),f=q(null),h=q(null);return fe(a,f),fe(c,h),Ue(F(u,je(t,r,i,f,h,n)),([m,w,v,g,x,b,S])=>{const k=Ug(w.sizeTree);g&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=S,m({ranges:k,scrollTop:v})}),fe(F(d,be(Gs),oe(ax)),o),fe(F(s,je(d),be(([,m])=>m!==void 0),et(),oe(([,m])=>m.ranges)),e),{getState:u,restoreStateFrom:d}},Qe(Gt,mt,yr,pn,ci));function ax(e){return{align:"start",index:0,offset:e.scrollTop}}const lx=Be(([{topItemsIndexes:e}])=>{const t=q(0);return fe(F(t,be(n=>n>=0),oe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Qe(jn));function yc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const cx=yc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),ux=Be(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:m},{recalcInProgress:w}])=>{const v=Et(F(c,je(i),qt(([,x,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},N])=>{const _=k+T;let R=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(R=_-S,R!==0&&(R+=N))),[R,C,I,_]},[0,[],0,0]),be(([x])=>x!==0),je(r,a,n,o,m,w),be(([,x,b,S,,,k])=>!k&&!S&&x!==0&&b===Sr),oe(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},bt.DEBUG),x))));function g(x){x>0?(Ae(t,{behavior:"auto",top:-x}),Ae(e,0)):(Ae(e,0),Ae(t,{behavior:"auto",top:-x}))}return Ue(F(v,je(e,s)),([x,b,S])=>{S&&cx()?Ae(e,b-x):g(-x)}),Ue(F(it(ft(s,!1),e,w),be(([x,b,S])=>!x&&!S&&b!==0),oe(([x,b])=>b),on(1)),g),fe(F(f,oe(x=>({top:-x}))),t),Ue(F(u,je(h,d),oe(([x,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(x);{let I=0;const N=xr(k,0);let _=0,R=0;for(;_<x;){_++,I+=N;let j=b.length===R+1?1/0:b[R+1]-b[R]-1;_+j>x&&(I-=N,j=x-_+1),_+=j,I+=T(j),R++}return I}})),x=>{Ae(e,x),requestAnimationFrame(()=>{Ae(t,{top:x}),requestAnimationFrame(()=>{Ae(e,0),Ae(w,!1)})})}),{deviation:e}},Qe(mt,Tr,jn,Gt,fn,ni)),dx=Be(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),Qe(ai,ox,pn,bc,gc,sx,ex,ci,vc,fn,xc)),Sc=Be(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:m,scrolledToInitialItem:w},v,g,x,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:N},_])=>(fe(k.rangeChanged,_.scrollSeekRangeChanged),fe(F(_.windowViewportRect,oe(R=>R.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:m,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...k,..._,...v,sizes:c,...g}),Qe(Gt,yr,mt,ix,rx,jn,br,ux,lx,lc,dx));function fx(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 xo=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Cc(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=y.createContext({});function c(g,x){g.propsReady&&Ae(g.propsReady,!1);for(const b of r){const S=g[t.required[b]];Ae(S,x[b])}for(const b of o)if(b in x){const S=g[t.optional[b]];Ae(S,x[b])}g.propsReady&&Ae(g.propsReady,!0)}function u(g){return s.reduce((x,b)=>(x[b]=S=>{const k=g[t.methods[b]];Ae(k,S)},x),{})}function d(g){return i.reduce((x,b)=>(x[b]=Ng(g[t.events[b]]),x),{})}const f=y.forwardRef((g,x)=>{const{children:b,...S}=g,[k]=y.useState(()=>lo(_g(e),I=>{c(I,S)})),[C]=y.useState(Kl(d,k));xo(()=>{for(const I of i)I in S&&Ue(C[I],S[I]);return()=>{Object.values(C).map(Ys)}},[S,C,k]),xo(()=>{c(k,S)}),y.useImperativeHandle(x,Wl(u(k)));const T=n;return l.jsx(a.Provider,{value:k,children:n?l.jsx(T,{...fx([...r,...o,...i],S),children:b}):b})}),h=g=>{const x=y.useContext(a);return y.useCallback(b=>{Ae(x[g],b)},[x,g])},m=g=>{const x=y.useContext(a)[g],b=y.useCallback(S=>Ue(x,S),[x]);return y.useSyncExternalStore(b,()=>ot(x),()=>ot(x))},w=g=>{const x=y.useContext(a)[g],[b,S]=y.useState(Kl(ot,x));return xo(()=>Ue(x,k=>{k!==b&&S(Wl(k))}),[x,b]),b},v=y.version.startsWith("18")?m:w;return{Component:f,useEmitter:(g,x)=>{const b=y.useContext(a)[g];xo(()=>Ue(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const Tc=y.createContext(void 0),Ec=y.createContext(void 0),kc=typeof document<"u"?y.useLayoutEffect:y.useEffect;function ui(e){return"self"in e}function hx(e){return"body"in e}function Ic(e,t,n,r=Gn,o,s){const i=y.useRef(null),a=y.useRef(null),c=y.useRef(null),u=y.useCallback(h=>{let m,w,v;const g=h.target;if(hx(g)||ui(g)){const b=ui(g)?g:g.defaultView;v=s?b.scrollX:b.scrollY,m=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?g.scrollLeft:g.scrollTop,m=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:m,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Is.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===m-w)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const m=i.current;if(!m||(s?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;ui(m)?(g=Math.max(hn(m.document.documentElement,s?"width":"height"),s?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),v=s?m.innerWidth:m.innerHeight,x=s?window.scrollX:window.scrollY):(g=m[s?"scrollWidth":"scrollHeight"],v=hn(m,s?"width":"height"),x=m[s?"scrollLeft":"scrollTop"]);const b=g-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),uc(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),m.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 di="-webkit-sticky",Nc="sticky",fi=yc(()=>{if(typeof document>"u")return Nc;const e=document.createElement("div");return e.style.position=di,e.style.position===di?di:Nc});function hi(e){return e}const px=Be(()=>{const e=q(a=>`Item ${a}`),t=q(a=>`Group ${a}`),n=q({}),r=q(hi),o=q("div"),s=q(Gn),i=(a,c=null)=>ft(F(n,oe(u=>u[a]),et()),c);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")}}),mx=Be(([e,t])=>({...e,...t}),Qe(Sc,px)),gx=({height:e})=>l.jsx("div",{style:{height:e}}),xx={overflowAnchor:"none",position:fi(),zIndex:1},Ac={overflowAnchor:"none"},vx={...Ac,display:"inline-block",height:"100%"},_c=y.memo(function({showTopList:e=!1}){const t=Te("listState"),n=Rt("sizeRanges"),r=Te("useWindowScroll"),o=Te("customScrollParent"),s=Rt("windowScrollContainerState"),i=Rt("scrollContainerState"),a=o||r?s:i,c=Te("itemContent"),u=Te("context"),d=Te("groupContent"),f=Te("trackItemSizes"),h=Te("itemSize"),m=Te("log"),w=Rt("gap"),v=Te("horizontalDirection"),{callbackRef:g}=Pg(n,h,f,e?Gn:a,m,w,o,v,Te("skipAnimationFrameInResizeObserver")),[x,b]=y.useState(0);pi("deviation",O=>{x!==O&&b(O)});const S=Te("EmptyPlaceholder"),k=Te("ScrollSeekPlaceholder")||gx,C=Te("ListComponent"),T=Te("ItemComponent"),I=Te("GroupComponent"),N=Te("computeItemKey"),_=Te("isSeeking"),R=Te("groupIndices").length>0,j=Te("alignToBottom"),$=Te("initialItemFinalLocationReached"),z=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:j?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:j?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...$?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?l.jsx(S,{...ht(S,u)}):l.jsx(C,{...ht(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:z,children:(e?t.topItems:t.items).map(O=>{const V=O.originalIndex,B=N(V+t.firstItemIndex,O.data,u);return _?y.createElement(k,{...ht(k,u),height:O.size,index:O.index,key:B,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?y.createElement(I,{...ht(I,u),"data-index":V,"data-item-index":O.index,"data-known-size":O.size,key:B,style:xx},d(O.index,u)):y.createElement(T,{...ht(T,u),...Sx(T,O.data),"data-index":V,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:B,style:v?vx:Ac},R?c(O.index,O.groupIndex,O.data,u):c(O.index,O.data,u))})})}),wx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},bx={outline:"none",overflowX:"auto",position:"relative"},vo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),yx={position:fi(),top:0,width:"100%",zIndex:1};function ht(e,t){if(typeof e!="string")return{context:t}}function Sx(e,t){return{item:typeof e=="string"?void 0:t}}const Cx=y.memo(function(){const e=Te("HeaderComponent"),t=Rt("headerHeight"),n=Te("HeaderFooterTag"),r=An(y.useMemo(()=>s=>{t(hn(s,"height"))},[t]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...ht(e,o)})}):null}),Tx=y.memo(function(){const e=Te("FooterComponent"),t=Rt("footerHeight"),n=Te("HeaderFooterTag"),r=An(y.useMemo(()=>s=>{t(hn(s,"height"))},[t]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...ht(e,o)})}):null});function jc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:m,scrollToCallback:w}=Ic(a,u,c,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),l.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{...f?bx:wx,...o},tabIndex:0,...i,...ht(c,s),children:r})})}function Rc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),m=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Ic(a,u,c,w,h);return kc(()=>{var b;return g.current=h||((b=m.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),l.jsx(c,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...ht(c,s),children:r})})}const Ex=({children:e})=>{const t=y.useContext(Tc),n=Rt("viewportHeight"),r=Rt("fixedItemHeight"),o=Te("alignToBottom"),s=Te("horizontalDirection"),i=y.useMemo(()=>Vl(n,c=>hn(c,s?"width":"height")),[n,s]),a=An(i,!0,Te("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:vo(o),children:e})},kx=({children:e})=>{const t=y.useContext(Tc),n=Rt("windowViewportRect"),r=Rt("fixedItemHeight"),o=Te("customScrollParent"),s=Xl(n,o,Te("skipAnimationFrameInResizeObserver")),i=Te("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),l.jsx("div",{"data-viewport-type":"window",ref:s,style:vo(i),children:e})},Ix=({children:e})=>{const t=Te("TopItemListComponent")||"div",n=Te("headerHeight"),r={...yx,marginTop:`${n}px`},o=Te("context");return l.jsx(t,{style:r,...ht(t,o),children:e})},Nx=y.memo(function(e){const t=Te("useWindowScroll"),n=Te("topItemsIndexes").length>0,r=Te("customScrollParent"),o=Te("context");return l.jsxs(r||t?jx:_x,{...e,context:o,children:[n&&l.jsx(Ix,{children:l.jsx(_c,{showTopList:!0})}),l.jsxs(r||t?kx:Ex,{children:[l.jsx(Cx,{}),l.jsx(_c,{}),l.jsx(Tx,{})]})]})}),{Component:Ax,useEmitter:pi,useEmitterValue:Te,usePublisher:Rt}=Cc(mx,{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"}},Nx),_x=jc({useEmitter:pi,useEmitterValue:Te,usePublisher:Rt}),jx=Rc({useEmitter:pi,useEmitterValue:Te,usePublisher:Rt}),Rx=Ax;Qe(Sc,Be(()=>{const e=q(u=>l.jsxs("td",{children:["Item $",u]})),t=q(null),n=q(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=q(null),o=q(null),s=q({}),i=q(hi),a=q(Gn),c=(u,d=null)=>ft(F(s,oe(f=>f[u]),et()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),fi();const Pc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Px={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Oc,floor:wo,max:Er,min:mi,round:Mc}=Math;function Dc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Ox(e){return{...Px,items:e}}function bo(e,t){return e&&e.width===t.width&&e.height===t.height}function Mx(e,t){return e&&e.column===t.column&&e.row===t.row}const Dx=Be(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,m,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=q(0),I=q(0),N=q(Pc),_=q({height:0,width:0}),R=q({height:0,width:0}),j=Me(),$=Me(),z=q(0),O=q(null),V=q({column:0,row:0}),B=Me(),K=Me(),L=q(!1),A=q(0),D=q(!0),H=q(!1),Y=q(!1);Ue(F(w,je(A),be(([M,G])=>!!G)),()=>{Ae(D,!1)}),Ue(F(it(w,D,R,_,A,H),be(([M,G,te,de,,ce])=>M&&!G&&te.height!==0&&de.height!==0&&!ce)),([,,,,M])=>{Ae(H,!0),si(1,()=>{Ae(j,M)}),Ft(F(u),()=>{Ae(t,[0,0]),Ae(D,!0)})}),fe(F(K,be(M=>M!=null&&M.scrollTop>0),Kt(0)),I),Ue(F(w,je(K),be(([,M])=>M!=null)),([,M])=>{M&&(Ae(_,M.viewport),Ae(R,M.item),Ae(V,M.gap),M.scrollTop>0&&(Ae(L,!0),Ft(F(u,Nn(1)),G=>{Ae(L,!1)}),Ae(c,{top:M.scrollTop})))}),fe(F(_,oe(({height:M})=>M)),f),fe(F(it(we(_,bo),we(R,bo),we(V,(M,G)=>M&&M.column===G.column&&M.row===G.row),we(u)),oe(([M,G,te,de])=>({gap:te,item:G,scrollTop:de,viewport:M}))),B),fe(F(it(we(T),r,we(V,Mx),we(R,bo),we(_,bo),we(O),we(I),we(L),we(D),we(A)),be(([,,,,,,,M])=>!M),oe(([M,[G,te],de,ce,$e,Ge,_e,,Re,We])=>{const{column:Q,row:X}=de,{height:Ne,width:He}=ce,{width:ee}=$e;if(_e===0&&(M===0||ee===0))return Pc;if(He===0){const yt=ii(We,M),ln=yt+Math.max(_e-1,0);return Ox(Dc(yt,ln,Ge))}const se=Lc(ee,He,Q);let he,ge;Re?G===0&&te===0&&_e>0?(he=0,ge=_e-1):(he=se*wo((G+X)/(Ne+X)),ge=se*Oc((te+X)/(Ne+X))-1,ge=mi(M-1,Er(ge,se-1)),he=mi(ge,Er(0,he))):(he=0,ge=-1);const ke=Dc(he,ge,Ge),{bottom:De,top:Ye}=$c($e,de,ce,ke),Xe=Oc(M/se),Je=Xe*Ne+(Xe-1)*X-De;return{bottom:De,itemHeight:Ne,items:ke,itemWidth:He,offsetBottom:Je,offsetTop:Ye,top:Ye}})),N),fe(F(O,be(M=>M!==null),oe(M=>M.length)),T),fe(F(it(_,R,N,V),be(([M,G,{items:te}])=>te.length>0&&G.height!==0&&M.height!==0),oe(([M,G,{items:te},de])=>{const{bottom:ce,top:$e}=$c(M,de,G,te);return[$e,ce]}),et(vr)),t);const Z=q(!1);fe(F(u,je(Z),oe(([M,G])=>G||M!==0)),Z);const le=Et(F(it(N,T),be(([{items:M}])=>M.length>0),je(Z),be(([[M,G],te])=>{const de=M.items[M.items.length-1].index===G-1;return(te||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===G)&&de}),oe(([[,M]])=>M-1),et())),xe=Et(F(we(N),be(({items:M})=>M.length>0&&M[0].index===0),Kt(0),et())),Ee=Et(F(we(N),je(L),be(([{items:M},G])=>M.length>0&&!G),oe(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),et(rc),on(0)));fe(Ee,m.scrollSeekRangeChanged),fe(F(j,je(_,R,T,V),oe(([M,G,te,de,ce])=>{const $e=cc(M),{align:Ge,behavior:_e,offset:Re}=$e;let We=$e.index;We==="LAST"&&(We=de-1),We=Er(0,We,mi(de-1,We));let Q=gi(G,ce,te,We);return Ge==="end"?Q=Mc(Q-G.height+te.height):Ge==="center"&&(Q=Mc(Q-G.height/2+te.height/2)),Re&&(Q+=Re),{behavior:_e,top:Q}})),c);const W=ft(F(N,oe(M=>M.offsetBottom+M.bottom)),0);return fe(F(k,oe(M=>({height:M.visibleHeight,width:M.visibleWidth}))),_),{customScrollParent:g,data:O,deviation:z,footerHeight:o,gap:V,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:R,overscan:n,restoreStateFrom:K,scrollBy:i,scrollContainerState:a,scrollHeight:$,scrollTo:c,scrollToIndex:j,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...m,gridState:N,horizontalDirection:Y,initialTopMostItemIndex:A,totalListHeight:W,...h,endReached:le,propsReady:v,rangeChanged:Ee,startReached:xe,stateChanged:B,stateRestoreInProgress:L,...C}},Qe(ai,mt,Tr,bc,pn,ci,fn));function Lc(e,t,n){return Er(1,wo((e+n)/(wo(t)+n)))}function $c(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=gi(e,t,n,r[0].index);return{bottom:gi(e,t,n,r[r.length-1].index)+o,top:s}}function gi(e,t,n,r){const o=Lc(e.width,n.width,t.column),s=wo(r/o),i=s*n.height+Er(0,s-1)*t.row;return i>0?i+t.row:i}const Lx=Be(()=>{const e=q(f=>`Item ${f}`),t=q({}),n=q(null),r=q("virtuoso-grid-item"),o=q("virtuoso-grid-list"),s=q(hi),i=q("div"),a=q(Gn),c=(f,h=null)=>ft(F(t,oe(m=>m[f]),et()),h),u=q(!1),d=q(!1);return fe(we(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),$x=Be(([e,t])=>({...e,...t}),Qe(Dx,Lx)),Fx=y.memo(function(){const e=tt("gridState"),t=tt("listClassName"),n=tt("itemClassName"),r=tt("itemContent"),o=tt("computeItemKey"),s=tt("isSeeking"),i=Pt("scrollHeight"),a=tt("ItemComponent"),c=tt("ListComponent"),u=tt("ScrollSeekPlaceholder"),d=tt("context"),f=Pt("itemDimensions"),h=Pt("gap"),m=tt("log"),w=tt("stateRestoreInProgress"),v=Pt("reportReadyState"),g=An(y.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const S=x.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}h({column:zc("column-gap",getComputedStyle(x).columnGap,m),row:zc("row-gap",getComputedStyle(x).rowGap,m)})},[i,f,h,m]),!0,!1);return kc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:l.jsx(c,{className:t,ref:g,...ht(c,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?l.jsx(u,{...ht(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):y.createElement(a,{...ht(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),zx=y.memo(function(){const e=tt("HeaderComponent"),t=Pt("headerHeight"),n=tt("headerFooterTag"),r=An(y.useMemo(()=>s=>{t(hn(s,"height"))},[t]),!0,!1),o=tt("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...ht(e,o)})}):null}),Bx=y.memo(function(){const e=tt("FooterComponent"),t=Pt("footerHeight"),n=tt("headerFooterTag"),r=An(y.useMemo(()=>s=>{t(hn(s,"height"))},[t]),!0,!1),o=tt("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...ht(e,o)})}):null}),Hx=({children:e})=>{const t=y.useContext(Ec),n=Pt("itemDimensions"),r=Pt("viewportDimensions"),o=An(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),l.jsx("div",{ref:o,style:vo(!1),children:e})},Ux=({children:e})=>{const t=y.useContext(Ec),n=Pt("windowViewportRect"),r=Pt("itemDimensions"),o=tt("customScrollParent"),s=Xl(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),l.jsx("div",{ref:s,style:vo(!1),children:e})},Wx=y.memo(function({...e}){const t=tt("useWindowScroll"),n=tt("customScrollParent"),r=n||t?Kx:Vx,o=n||t?Ux:Hx,s=tt("context");return l.jsx(r,{...e,...ht(r,s),children:l.jsxs(o,{children:[l.jsx(zx,{}),l.jsx(Fx,{}),l.jsx(Bx,{})]})})}),{useEmitter:Fc,useEmitterValue:tt,usePublisher:Pt}=Cc($x,{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"}},Wx),Vx=jc({useEmitter:Fc,useEmitterValue:tt,usePublisher:Pt}),Kx=Rc({useEmitter:Fc,useEmitterValue:tt,usePublisher:Pt});function zc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,bt.WARN),t==="normal"?0:parseInt(t??"0",10)}const qx=Kr.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 xi({className:e,variant:t,...n}){return l.jsx("div",{className:J(qx({variant:t}),e),...n})}function ae(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 Gx(e,t){const n=p.createContext(t),r=s=>{const{children:i,...a}=s,c=p.useMemo(()=>a,Object.values(a));return l.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=p.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 Yt(e,t=[]){let n=[];function r(s,i){const a=p.createContext(i),c=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:m,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[c])||a,g=p.useMemo(()=>w,Object.values(w));return l.jsx(v.Provider,{value:g,children:m})};u.displayName=s+"Provider";function d(f,h){var v;const m=((v=h==null?void 0:h[e])==null?void 0:v[c])||a,w=p.useContext(m);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>p.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return p.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,Yx(o,...t)]}function Yx(...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:c,scopeName:u})=>{const f=c(s)[`__scope${u}`];return{...a,...f}},{});return p.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var ct=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},Xx=p[" useInsertionEffect ".trim().toString()]||ct;function Rn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Jx({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const d=p.useRef(e!==void 0);p.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 u=p.useCallback(d=>{var f;if(a){const h=Zx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[c,u]}function Jx({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return Xx(()=>{s.current=t},[t]),p.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Zx(e){return typeof e=="function"}function Bc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function vi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Bc(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():Bc(e[o],null)}}}}function Pe(...e){return p.useCallback(vi(...e),e)}var Qx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ye=Qx.reduce((e,t)=>{const n=Tn.createSlot(`Primitive.${t}`),r=p.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),l.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Hc(e,t){e&&qr.flushSync(()=>e.dispatchEvent(t))}function ev(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var It=e=>{const{present:t,children:n}=e,r=tv(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Pe(r.ref,nv(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};It.displayName="Presence";function tv(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,c]=ev(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const u=yo(r.current);s.current=a==="mounted"?u:"none"},[a]),ct(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,m=yo(u);e?c("MOUNT"):m==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&h!==m?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),ct(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=m=>{const v=yo(r.current).includes(CSS.escape(m.animationName));if(m.target===t&&v&&(c("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=m=>{m.target===t&&(s.current=yo(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:p.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function yo(e){return(e==null?void 0:e.animationName)||"none"}function nv(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 rv=p[" useId ".trim().toString()]||(()=>{}),ov=0;function Xt(e){const[t,n]=p.useState(rv());return ct(()=>{n(r=>r??String(ov++))},[e]),e||(t?`radix-${t}`:"")}var So="Collapsible",[sv,WC]=Yt(So),[iv,wi]=sv(So),Uc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=Rn({prop:r,defaultProp:o??!1,onChange:i,caller:So});return l.jsx(iv,{scope:n,disabled:s,contentId:Xt(),open:c,onOpenToggle:p.useCallback(()=>u(d=>!d),[u]),children:l.jsx(ye.div,{"data-state":yi(c),"data-disabled":s?"":void 0,...a,ref:t})})});Uc.displayName=So;var Wc="CollapsibleTrigger",Vc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=wi(Wc,n);return l.jsx(ye.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":yi(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ae(e.onClick,o.onOpenToggle)})});Vc.displayName=Wc;var bi="CollapsibleContent",av=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=wi(bi,e.__scopeCollapsible);return l.jsx(It,{present:n||o.open,children:({present:s})=>l.jsx(lv,{...r,ref:t,present:s})})});av.displayName=bi;var lv=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=wi(bi,n),[a,c]=p.useState(r),u=p.useRef(null),d=Pe(t,u),f=p.useRef(0),h=f.current,m=p.useRef(0),w=m.current,v=i.open||a,g=p.useRef(v),x=p.useRef(void 0);return p.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),ct(()=>{const b=u.current;if(b){x.current=x.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const S=b.getBoundingClientRect();f.current=S.height,m.current=S.width,g.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(ye.div,{"data-state":yi(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!v,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:v&&o})});function yi(e){return e?"open":"closed"}var cv=Uc;const Kc=cv,qc=Vc,kr=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));kr.displayName="Card";const Ir=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("flex flex-col space-y-1.5 p-6",e),...t}));Ir.displayName="CardHeader";const Nr=p.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:J("text-2xl font-semibold leading-none tracking-tight",e),...t}));Nr.displayName="CardTitle";const Gc=p.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:J("text-sm text-muted-foreground",e),...t}));Gc.displayName="CardDescription";const Co=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("p-6 pt-0",e),...t}));Co.displayName="CardContent";const Yc=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("flex items-center p-6 pt-0",e),...t}));Yc.displayName="CardFooter";function Xc(){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 Pn=Xc();function uv(e){Pn=e}const Jc=/[&<>"']/,dv=new RegExp(Jc.source,"g"),Zc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,fv=new RegExp(Zc.source,"g"),hv={"&":"&","<":"<",">":">",'"':""","'":"'"},Qc=e=>hv[e];function pt(e,t){if(t){if(Jc.test(e))return e.replace(dv,Qc)}else if(Zc.test(e))return e.replace(fv,Qc);return e}const pv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function eu(e){return e.replace(pv,(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 mv=/(^|[^\[])\^/g;function qe(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(mv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const gv=/[^\w:]/g,xv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function tu(e,t,n){if(e){let r;try{r=decodeURIComponent(eu(n)).replace(gv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!xv.test(n)&&(n=yv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const To={},vv=/^[^:]+:\/*[^/]*$/,wv=/^([^:]+:)[\s\S]*$/,bv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function yv(e,t){To[" "+e]||(vv.test(e)?To[" "+e]=e+"/":To[" "+e]=ko(e,"/",!0)),e=To[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(wv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(bv,"$1")+t:e+t}const Eo={exec:function(){}};function nu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,u=i;for(;--u>=0&&a[u]==="\\";)c=!c;return c?"|":" |"}),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 ko(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 Sv(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 Cv(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 ru(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function ou(e,t,n,r){const o=t.href,s=t.title?pt(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:pt(i)}}function Tv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
39
39
|
`).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(`
|
|
40
40
|
`)}class Si{constructor(t){this.options=t||Pn}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:ko(r,`
|
|
41
41
|
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Tv(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=ko(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,c,u,d,f,h,m,w,v=n[1].trim();const g=v.length>1,x={type:"list",raw:"",ordered:g,start:g?+v.slice(0,-1):"",loose:!1,items:[]};v=g?`\\d{1,9}\\${v.slice(-1)}`:`\\${v}`,this.options.pedantic&&(v=g?v:"[*+-]");const b=new RegExp(`^( {0,3}${v})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(w=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
@@ -80,7 +80,7 @@ ${t}</tr>
|
|
|
80
80
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
81
81
|
`}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=tu(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=tu(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 iu{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 au{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 gn{constructor(t){this.options=t||Pn,this.options.renderer=this.options.renderer||new Ci,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new iu,this.slugger=new au}static parse(t,n){return new gn(n).parse(t)}static parseInline(t,n){return new gn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,c,u,d,f,h,m,w,v,g,x,b,S,k,C,T;const I=t.length;for(o=0;o<I;o++){if(m=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[m.type]&&(T=this.options.extensions.renderers[m.type].call({parser:this},m),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(m.type))){r+=T||"";continue}switch(m.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(m.tokens),m.depth,eu(this.parseInline(m.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(m.text,m.lang,m.escaped);continue}case"table":{for(f="",d="",a=m.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(m.header[s].tokens),{header:!0,align:m.align[s]});for(f+=this.renderer.tablerow(d),h="",a=m.rows.length,s=0;s<a;s++){for(u=m.rows[s],d="",c=u.length,i=0;i<c;i++)d+=this.renderer.tablecell(this.parseInline(u[i].tokens),{header:!1,align:m.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(m.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(w=m.ordered,v=m.start,g=m.loose,a=m.items.length,h="",s=0;s<a;s++)b=m.items[s],S=b.checked,k=b.task,x="",b.task&&(C=this.renderer.checkbox(S),g?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):x+=C),x+=this.parse(b.tokens,g),h+=this.renderer.listitem(x,k,S);r+=this.renderer.list(h,w,v);continue}case"html":{r+=this.renderer.html(m.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(m.tokens));continue}case"text":{for(h=m.tokens?this.parseInline(m.tokens):m.text;o+1<I&&t[o+1].type==="text";)m=t[++o],h+=`
|
|
82
82
|
`+(m.tokens?this.parseInline(m.tokens):m.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const N='Token with "'+m.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}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 c='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(c);return}else throw new Error(c)}}}return r}}class Io{constructor(t){this.options=t||Pn}preprocess(t){return t}postprocess(t){return t}}wp(Io,"passThroughHooks",new Set(["preprocess","postprocess"]));function kv(e,t,n){return r=>{if(r.message+=`
|
|
83
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+pt(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 lu(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=kv(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(Cv(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let c;try{r.hooks&&(n=r.hooks.preprocess(n)),c=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&me.walkTokens(c,r.walkTokens),h=t(c,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(m){f=m}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!c.length))return u();let d=0;me.walkTokens(c,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,m){if(h)return u(h);m!=null&&m!==f.text&&(f.text=m,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(me.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&me.walkTokens(a,r.walkTokens);let c=t(a,r);return r.hooks&&(c=r.hooks.postprocess(c)),c}catch(a){return i(a)}}}function me(e,t,n){return lu(mn.lex,gn.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},uv(me.defaults),me},me.getDefaults=Xc,me.defaults=Pn,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=me.defaults.renderer||new Ci;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let c=n.renderer[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.renderer=o}if(n.tokenizer){const o=me.defaults.tokenizer||new Si;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let c=n.tokenizer[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.tokenizer=o}if(n.hooks){const o=me.defaults.hooks||new Io;for(const s in n.hooks){const i=o[s];Io.passThroughHooks.has(s)?o[s]=a=>{if(me.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const c=n.hooks[s].call(o,a);return i.call(o,c)}:o[s]=(...a)=>{let c=n.hooks[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.hooks=o}if(n.walkTokens){const o=me.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=lu(mn.lexInline,gn.parseInline),me.Parser=gn,me.parser=gn.parse,me.Renderer=Ci,me.TextRenderer=iu,me.Lexer=mn,me.lexer=mn.lex,me.Tokenizer=Si,me.Slugger=au,me.Hooks=Io,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,gn.parse,mn.lex;function Ti({content:e,className:t="",allowHtml:n=!1}){const r=y.useMemo(()=>{try{if(!n){const o=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return me.parse(o)}return me.parse(e)}catch(o){return console.error("[MarkdownContent] parse error",o),`<pre>Error rendering markdown: ${String(o)}</pre>`}},[e,n]);return l.jsx("div",{className:Z("markdown prose max-w-none break-words dark:prose-invert",t),dangerouslySetInnerHTML:{__html:r}})}async function cu(e,t){return await Ct(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function uu(e,t){return await(await cu(`/chat/files/${e}/view`,t)).text()}async function Iv(e,t){const n=await cu(`/chat/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Ct(`/chat/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 Nv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Ct("/chat/files",{params:r})}const Av=1,_v=1e6;let Ei=0;function jv(){return Ei=(Ei+1)%Number.MAX_SAFE_INTEGER,Ei.toString()}const ki=new Map,du=e=>{if(ki.has(e))return;const t=setTimeout(()=>{ki.delete(e),Ar({type:"REMOVE_TOAST",toastId:e})},_v);ki.set(e,t)},Rv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Av)};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?du(n):e.toasts.forEach(r=>{du(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)}}},No=[];let Ao={toasts:[]};function Ar(e){Ao=Rv(Ao,e),No.forEach(t=>{t(Ao)})}function Pv({...e}){const t=jv(),n=o=>Ar({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Ar({type:"DISMISS_TOAST",toastId:t});return Ar({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ii(){const[e,t]=p.useState(Ao);return p.useEffect(()=>(No.push(t),()=>{const n=No.indexOf(t);n>-1&&No.splice(n,1)}),[e]),{...e,toast:Pv,dismiss:n=>Ar({type:"DISMISS_TOAST",toastId:n})}}function ut(e){const t=p.useRef(e);return p.useEffect(()=>{t.current=e}),p.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Ov(e,t=globalThis==null?void 0:globalThis.document){const n=ut(e);p.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 Mv="DismissableLayer",Ni="dismissableLayer.update",Dv="dismissableLayer.pointerDownOutside",Lv="dismissableLayer.focusOutside",fu,hu=p.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),_o=p.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...c}=e,u=p.useContext(hu),[d,f]=p.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=p.useState({}),w=Pe(t,I=>f(I)),v=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=v.indexOf(g),b=d?v.indexOf(d):-1,S=u.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,C=zv(I=>{const N=I.target,_=[...u.branches].some(j=>j.contains(N));!k||_||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),T=Bv(I=>{const N=I.target;[...u.branches].some(j=>j.contains(N))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return Ov(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),p.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(fu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),pu(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=fu)}},[d,h,n,u]),p.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),pu())},[d,u]),p.useEffect(()=>{const I=()=>m({});return document.addEventListener(Ni,I),()=>document.removeEventListener(Ni,I)},[]),l.jsx(ye.div,{...c,ref:w,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:ae(e.onFocusCapture,T.onFocusCapture),onBlurCapture:ae(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:ae(e.onPointerDownCapture,C.onPointerDownCapture)})});_o.displayName=Mv;var $v="DismissableLayerBranch",Fv=p.forwardRef((e,t)=>{const n=p.useContext(hu),r=p.useRef(null),o=Pe(t,r);return p.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),l.jsx(ye.div,{...e,ref:o})});Fv.displayName=$v;function zv(e,t=globalThis==null?void 0:globalThis.document){const n=ut(e),r=p.useRef(!1),o=p.useRef(()=>{});return p.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let c=function(){mu(Dv,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=c,t.addEventListener("click",o.current,{once:!0})):c()}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 Bv(e,t=globalThis==null?void 0:globalThis.document){const n=ut(e),r=p.useRef(!1);return p.useEffect(()=>{const o=s=>{s.target&&!r.current&&mu(Lv,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 pu(){const e=new CustomEvent(Ni);document.dispatchEvent(e)}function mu(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Hc(o,s):o.dispatchEvent(s)}var Ai="focusScope.autoFocusOnMount",_i="focusScope.autoFocusOnUnmount",gu={bubbles:!1,cancelable:!0},Hv="FocusScope",jo=p.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,c]=p.useState(null),u=ut(o),d=ut(s),f=p.useRef(null),h=Pe(t,v=>c(v)),m=p.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;p.useEffect(()=>{if(r){let v=function(S){if(m.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:xn(f.current,{select:!0})},g=function(S){if(m.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||xn(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&xn(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",g);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,m.paused]),p.useEffect(()=>{if(a){wu.add(m);const v=document.activeElement;if(!a.contains(v)){const x=new CustomEvent(Ai,gu);a.addEventListener(Ai,u),a.dispatchEvent(x),x.defaultPrevented||(Uv(Gv(xu(a)),{select:!0}),document.activeElement===v&&xn(a))}return()=>{a.removeEventListener(Ai,u),setTimeout(()=>{const x=new CustomEvent(_i,gu);a.addEventListener(_i,d),a.dispatchEvent(x),x.defaultPrevented||xn(v??document.body,{select:!0}),a.removeEventListener(_i,d),wu.remove(m)},0)}}},[a,u,d,m]);const w=p.useCallback(v=>{if(!n&&!r||m.paused)return;const g=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(g&&x){const b=v.currentTarget,[S,k]=Wv(b);S&&k?!v.shiftKey&&x===k?(v.preventDefault(),n&&xn(S,{select:!0})):v.shiftKey&&x===S&&(v.preventDefault(),n&&xn(k,{select:!0})):x===b&&v.preventDefault()}},[n,r,m.paused]);return l.jsx(ye.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});jo.displayName=Hv;function Uv(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(xn(r,{select:t}),document.activeElement!==n)return}function Wv(e){const t=xu(e),n=vu(t,e),r=vu(t.reverse(),e);return[n,r]}function xu(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 vu(e,t){for(const n of e)if(!Vv(n,{upTo:t}))return n}function Vv(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 Kv(e){return e instanceof HTMLInputElement&&"select"in e}function xn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Kv(e)&&t&&e.select()}}var wu=qv();function qv(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=bu(e,t),e.unshift(t)},remove(t){var n;e=bu(e,t),(n=e[0])==null||n.resume()}}}function bu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Gv(e){return e.filter(t=>t.tagName!=="A")}var Yv="Portal",Ro=p.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=p.useState(!1);ct(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Is.createPortal(l.jsx(ye.div,{...r,ref:t}),i):null});Ro.displayName=Yv;var ji=0;function Ri(){p.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??yu()),document.body.insertAdjacentElement("beforeend",e[1]??yu()),ji++,()=>{ji===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ji--}},[])}function yu(){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 Jt=function(){return Jt=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},Jt.apply(this,arguments)};function Su(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 Xv(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 Po="right-scroll-bar-position",Oo="width-before-scroll-bar",Jv="with-scroll-bars-hidden",Zv="--removed-body-scroll-bar-size";function Pi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Qv(e,t){var n=y.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 ew=typeof window<"u"?p.useLayoutEffect:p.useEffect,Cu=new WeakMap;function tw(e,t){var n=Qv(null,function(r){return e.forEach(function(o){return Pi(o,r)})});return ew(function(){var r=Cu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Pi(a,null)}),s.forEach(function(a){o.has(a)||Pi(a,i)})}Cu.set(n,e)},[e]),n}function nw(e){return e}function rw(e,t){t===void 0&&(t=nw);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 c=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(c)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function ow(e){e===void 0&&(e={});var t=rw(null);return t.options=Jt({async:!0,ssr:!1},e),t}var Tu=function(e){var t=e.sideCar,n=Su(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 p.createElement(r,Jt({},n))};Tu.isSideCarExport=!0;function sw(e,t){return e.useMedium(t),Tu}var Eu=ow(),Oi=function(){},Mo=p.forwardRef(function(e,t){var n=p.useRef(null),r=p.useState({onScrollCapture:Oi,onWheelCapture:Oi,onTouchMoveCapture:Oi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,c=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,m=e.noRelative,w=e.noIsolation,v=e.inert,g=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,S=e.gapMode,k=Su(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,T=tw([n,t]),I=Jt(Jt({},k),o);return p.createElement(p.Fragment,null,d&&p.createElement(C,{sideCar:Eu,removeScrollBar:u,shards:f,noRelative:m,noIsolation:w,inert:v,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:S}),i?p.cloneElement(p.Children.only(a),Jt(Jt({},I),{ref:T})):p.createElement(b,Jt({},I,{className:c,ref:T}),a))});Mo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Mo.classNames={fullWidth:Oo,zeroRight:Po};var iw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function aw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=iw();return t&&e.setAttribute("nonce",t),e}function lw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function cw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var uw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=aw())&&(lw(t,n),cw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},dw=function(){var e=uw();return function(t,n){p.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},ku=function(){var e=dw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},fw={left:0,top:0,right:0,gap:0},Mi=function(e){return parseInt(e||"",10)||0},hw=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[Mi(n),Mi(r),Mi(o)]},pw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return fw;var t=hw(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])}},mw=ku(),Xn="data-scroll-locked",gw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
83
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+pt(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 lu(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=kv(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(Cv(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let c;try{r.hooks&&(n=r.hooks.preprocess(n)),c=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&me.walkTokens(c,r.walkTokens),h=t(c,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(m){f=m}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!c.length))return u();let d=0;me.walkTokens(c,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,m){if(h)return u(h);m!=null&&m!==f.text&&(f.text=m,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(me.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&me.walkTokens(a,r.walkTokens);let c=t(a,r);return r.hooks&&(c=r.hooks.postprocess(c)),c}catch(a){return i(a)}}}function me(e,t,n){return lu(mn.lex,gn.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},uv(me.defaults),me},me.getDefaults=Xc,me.defaults=Pn,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=me.defaults.renderer||new Ci;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let c=n.renderer[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.renderer=o}if(n.tokenizer){const o=me.defaults.tokenizer||new Si;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let c=n.tokenizer[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.tokenizer=o}if(n.hooks){const o=me.defaults.hooks||new Io;for(const s in n.hooks){const i=o[s];Io.passThroughHooks.has(s)?o[s]=a=>{if(me.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const c=n.hooks[s].call(o,a);return i.call(o,c)}:o[s]=(...a)=>{let c=n.hooks[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.hooks=o}if(n.walkTokens){const o=me.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=lu(mn.lexInline,gn.parseInline),me.Parser=gn,me.parser=gn.parse,me.Renderer=Ci,me.TextRenderer=iu,me.Lexer=mn,me.lexer=mn.lex,me.Tokenizer=Si,me.Slugger=au,me.Hooks=Io,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,gn.parse,mn.lex;function Ti({content:e,className:t="",allowHtml:n=!1}){const r=y.useMemo(()=>{try{if(!n){const o=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return me.parse(o)}return me.parse(e)}catch(o){return console.error("[MarkdownContent] parse error",o),`<pre>Error rendering markdown: ${String(o)}</pre>`}},[e,n]);return l.jsx("div",{className:J("markdown prose max-w-none break-words dark:prose-invert",t),dangerouslySetInnerHTML:{__html:r}})}async function cu(e,t){return await Ct(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function uu(e,t){return await(await cu(`/chat/files/${e}/view`,t)).text()}async function Iv(e,t){const n=await cu(`/chat/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Ct(`/chat/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 Nv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Ct("/chat/files",{params:r})}const Av=1,_v=1e6;let Ei=0;function jv(){return Ei=(Ei+1)%Number.MAX_SAFE_INTEGER,Ei.toString()}const ki=new Map,du=e=>{if(ki.has(e))return;const t=setTimeout(()=>{ki.delete(e),Ar({type:"REMOVE_TOAST",toastId:e})},_v);ki.set(e,t)},Rv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Av)};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?du(n):e.toasts.forEach(r=>{du(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)}}},No=[];let Ao={toasts:[]};function Ar(e){Ao=Rv(Ao,e),No.forEach(t=>{t(Ao)})}function Pv({...e}){const t=jv(),n=o=>Ar({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Ar({type:"DISMISS_TOAST",toastId:t});return Ar({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ii(){const[e,t]=p.useState(Ao);return p.useEffect(()=>(No.push(t),()=>{const n=No.indexOf(t);n>-1&&No.splice(n,1)}),[e]),{...e,toast:Pv,dismiss:n=>Ar({type:"DISMISS_TOAST",toastId:n})}}function ut(e){const t=p.useRef(e);return p.useEffect(()=>{t.current=e}),p.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Ov(e,t=globalThis==null?void 0:globalThis.document){const n=ut(e);p.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 Mv="DismissableLayer",Ni="dismissableLayer.update",Dv="dismissableLayer.pointerDownOutside",Lv="dismissableLayer.focusOutside",fu,hu=p.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),_o=p.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...c}=e,u=p.useContext(hu),[d,f]=p.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=p.useState({}),w=Pe(t,I=>f(I)),v=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=v.indexOf(g),b=d?v.indexOf(d):-1,S=u.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,C=zv(I=>{const N=I.target,_=[...u.branches].some(R=>R.contains(N));!k||_||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),T=Bv(I=>{const N=I.target;[...u.branches].some(R=>R.contains(N))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return Ov(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),p.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(fu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),pu(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=fu)}},[d,h,n,u]),p.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),pu())},[d,u]),p.useEffect(()=>{const I=()=>m({});return document.addEventListener(Ni,I),()=>document.removeEventListener(Ni,I)},[]),l.jsx(ye.div,{...c,ref:w,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:ae(e.onFocusCapture,T.onFocusCapture),onBlurCapture:ae(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:ae(e.onPointerDownCapture,C.onPointerDownCapture)})});_o.displayName=Mv;var $v="DismissableLayerBranch",Fv=p.forwardRef((e,t)=>{const n=p.useContext(hu),r=p.useRef(null),o=Pe(t,r);return p.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),l.jsx(ye.div,{...e,ref:o})});Fv.displayName=$v;function zv(e,t=globalThis==null?void 0:globalThis.document){const n=ut(e),r=p.useRef(!1),o=p.useRef(()=>{});return p.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let c=function(){mu(Dv,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=c,t.addEventListener("click",o.current,{once:!0})):c()}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 Bv(e,t=globalThis==null?void 0:globalThis.document){const n=ut(e),r=p.useRef(!1);return p.useEffect(()=>{const o=s=>{s.target&&!r.current&&mu(Lv,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 pu(){const e=new CustomEvent(Ni);document.dispatchEvent(e)}function mu(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Hc(o,s):o.dispatchEvent(s)}var Ai="focusScope.autoFocusOnMount",_i="focusScope.autoFocusOnUnmount",gu={bubbles:!1,cancelable:!0},Hv="FocusScope",jo=p.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,c]=p.useState(null),u=ut(o),d=ut(s),f=p.useRef(null),h=Pe(t,v=>c(v)),m=p.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;p.useEffect(()=>{if(r){let v=function(S){if(m.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:xn(f.current,{select:!0})},g=function(S){if(m.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||xn(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&xn(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",g);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,m.paused]),p.useEffect(()=>{if(a){wu.add(m);const v=document.activeElement;if(!a.contains(v)){const x=new CustomEvent(Ai,gu);a.addEventListener(Ai,u),a.dispatchEvent(x),x.defaultPrevented||(Uv(Gv(xu(a)),{select:!0}),document.activeElement===v&&xn(a))}return()=>{a.removeEventListener(Ai,u),setTimeout(()=>{const x=new CustomEvent(_i,gu);a.addEventListener(_i,d),a.dispatchEvent(x),x.defaultPrevented||xn(v??document.body,{select:!0}),a.removeEventListener(_i,d),wu.remove(m)},0)}}},[a,u,d,m]);const w=p.useCallback(v=>{if(!n&&!r||m.paused)return;const g=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(g&&x){const b=v.currentTarget,[S,k]=Wv(b);S&&k?!v.shiftKey&&x===k?(v.preventDefault(),n&&xn(S,{select:!0})):v.shiftKey&&x===S&&(v.preventDefault(),n&&xn(k,{select:!0})):x===b&&v.preventDefault()}},[n,r,m.paused]);return l.jsx(ye.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});jo.displayName=Hv;function Uv(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(xn(r,{select:t}),document.activeElement!==n)return}function Wv(e){const t=xu(e),n=vu(t,e),r=vu(t.reverse(),e);return[n,r]}function xu(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 vu(e,t){for(const n of e)if(!Vv(n,{upTo:t}))return n}function Vv(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 Kv(e){return e instanceof HTMLInputElement&&"select"in e}function xn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Kv(e)&&t&&e.select()}}var wu=qv();function qv(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=bu(e,t),e.unshift(t)},remove(t){var n;e=bu(e,t),(n=e[0])==null||n.resume()}}}function bu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Gv(e){return e.filter(t=>t.tagName!=="A")}var Yv="Portal",Ro=p.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=p.useState(!1);ct(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Is.createPortal(l.jsx(ye.div,{...r,ref:t}),i):null});Ro.displayName=Yv;var ji=0;function Ri(){p.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??yu()),document.body.insertAdjacentElement("beforeend",e[1]??yu()),ji++,()=>{ji===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ji--}},[])}function yu(){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 Jt=function(){return Jt=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},Jt.apply(this,arguments)};function Su(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 Xv(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 Po="right-scroll-bar-position",Oo="width-before-scroll-bar",Jv="with-scroll-bars-hidden",Zv="--removed-body-scroll-bar-size";function Pi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Qv(e,t){var n=y.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 ew=typeof window<"u"?p.useLayoutEffect:p.useEffect,Cu=new WeakMap;function tw(e,t){var n=Qv(null,function(r){return e.forEach(function(o){return Pi(o,r)})});return ew(function(){var r=Cu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Pi(a,null)}),s.forEach(function(a){o.has(a)||Pi(a,i)})}Cu.set(n,e)},[e]),n}function nw(e){return e}function rw(e,t){t===void 0&&(t=nw);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 c=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(c)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function ow(e){e===void 0&&(e={});var t=rw(null);return t.options=Jt({async:!0,ssr:!1},e),t}var Tu=function(e){var t=e.sideCar,n=Su(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 p.createElement(r,Jt({},n))};Tu.isSideCarExport=!0;function sw(e,t){return e.useMedium(t),Tu}var Eu=ow(),Oi=function(){},Mo=p.forwardRef(function(e,t){var n=p.useRef(null),r=p.useState({onScrollCapture:Oi,onWheelCapture:Oi,onTouchMoveCapture:Oi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,c=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,m=e.noRelative,w=e.noIsolation,v=e.inert,g=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,S=e.gapMode,k=Su(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,T=tw([n,t]),I=Jt(Jt({},k),o);return p.createElement(p.Fragment,null,d&&p.createElement(C,{sideCar:Eu,removeScrollBar:u,shards:f,noRelative:m,noIsolation:w,inert:v,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:S}),i?p.cloneElement(p.Children.only(a),Jt(Jt({},I),{ref:T})):p.createElement(b,Jt({},I,{className:c,ref:T}),a))});Mo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Mo.classNames={fullWidth:Oo,zeroRight:Po};var iw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function aw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=iw();return t&&e.setAttribute("nonce",t),e}function lw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function cw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var uw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=aw())&&(lw(t,n),cw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},dw=function(){var e=uw();return function(t,n){p.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},ku=function(){var e=dw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},fw={left:0,top:0,right:0,gap:0},Mi=function(e){return parseInt(e||"",10)||0},hw=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[Mi(n),Mi(r),Mi(o)]},pw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return fw;var t=hw(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])}},mw=ku(),Xn="data-scroll-locked",gw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
84
84
|
.`.concat(Jv,` {
|
|
85
85
|
overflow: hidden `).concat(r,`;
|
|
86
86
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -124,11 +124,11 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
|
|
|
124
124
|
|
|
125
125
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
126
126
|
|
|
127
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return p.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Hw="DialogDescriptionWarning",Uw=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Xu(Hw).contentName}}.`;return p.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},Ju=Du,Ww=$u,Zu=zu,Uo=Bu,Wo=Hu,Mn=Wu,Vo=Ku,Qu=Gu;const Vw=Ju,Kw=Zu,ed=p.forwardRef(({className:e,...t},n)=>l.jsx(Uo,{ref:n,className:
|
|
128
|
-
… [truncated ${i.length-o} chars]`}catch{return""}},n=e.filter(r=>r.type==="tool_end");if(n.length)try{return n.length===1?t(n[0].output):t(n.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return t(e)}function Qw(e){const t=e.find(r=>r.type==="tool_end");if(!t)return null;const n=t.output;return typeof n=="string"?n:null}function eb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function ad(e){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"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function tb({className:e}){const[t,n]=y.useState(0);return y.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),l.jsxs("span",{"aria-live":"polite",className:
|
|
129
|
-
… [truncated ${W.length-Dn} chars]`,[W]),G=y.useCallback(async(ee="all")=>{const he=ee==="visible"&&A?M:A?W:Y;async function ge(ke){try{await navigator.clipboard.writeText(ke)}catch{try{const De=document.createElement("textarea");De.value=ke,De.setAttribute("readonly",""),De.style.position="absolute",De.style.left="-9999px",document.body.appendChild(De),De.select(),document.execCommand("copy"),document.body.removeChild(De)}catch(De){throw console.error("Failed to copy:",De),De}}}try{await ge(he),S(!0),setTimeout(()=>S(!1),2e3),x==null||x(he)}catch(ke){console.error("Failed to copy:",ke)}},[A,W,Y,M,x]),te=y.useCallback(()=>{if(!w)return;const ee=A?W:Y;w(t.id,ee)},[w,t.id,A,W,Y]),de=y.useCallback(()=>{v==null||v(n)},[v,n]),ce=y.useCallback(async(ee,se,he)=>{if(!D){ee.preventDefault();return}if(
|
|
130
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[
|
|
131
|
-
… [truncated ${ke.length-Dn} chars]`:ke,Ye=k==="expanded";return l.jsxs(Kc,{open:Ye,onOpenChange:Xe=>C(Xe?"expanded":"preview"),children:[l.jsx("div",{className:"flex items-center gap-2 text-xs",children:l.jsx(xi,{variant:"outline",children:(he.name??"tool")+(he.toolCallId?` • ${he.toolCallId.slice(0,8)}`:"")})}),l.jsx("div",{className:"font-mono text-sm mt-1",children:l.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Ye?De:De.slice(0,d)+(De.length>d?"...":"")})}),l.jsx(qc,{asChild:!0,children:l.jsx(ze,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Ye?l.jsxs(l.Fragment,{children:[" ",l.jsx(ne.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):l.jsxs(l.Fragment,{children:[l.jsx(ne.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},he.toolCallId??ge)})})}if(!A){const se=l.jsx("div",{className:"space-y-2",children:t.content.map((he,ge)=>l.jsx(J,{part:he,i:ge},ge))});return r?l.jsxs("div",{"aria-busy":"true",role:"status",children:[se,l.jsx(tb,{className:H})]}):se}},[Y,le.length,xe.length,Ee.length,r,t.model,A,Q.name,W,k,u,X,H]),He=y.useMemo(()=>eb(t),[t]);return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:Z(Ge(),m.container),children:l.jsxs("div",{className:Z(_e(),m.content),children:[(i||a||A)&&l.jsxs("div",{className:Z("flex items-center justify-between mb-2 pb-2 border-b border-current/10",K&&"mb-1 pb-1",H,m.header),children:[l.jsxs("div",{className:"flex items-center gap-2",children:[$e(),a&&He&&l.jsx("span",{className:Z("font-medium",K?"text-xs":"text-sm"),children:He}),A&&Q.name&&l.jsxs(xi,{variant:"outline",className:Z("text-xs flex items-center gap-1 cursor-pointer",H,"border border-current/40",K&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":k!=="collapsed",onKeyDown:ee=>{(ee.key==="Enter"||ee.key===" ")&&(ee.preventDefault(),C(se=>se==="collapsed"?"preview":"collapsed"))},onClick:()=>C(ee=>ee==="collapsed"?"preview":"collapsed"),children:[l.jsx("span",{children:Q.name}),l.jsx("span",{className:"inline-flex items-center",children:k!=="collapsed"?l.jsx(ne.ChevronUp,{className:"h-3 w-3"}):l.jsx(ne.ChevronDown,{className:"h-3 w-3"})})]}),A&&!Q.name&&l.jsx(ze,{variant:"ghost",size:"sm",className:Z("h-6 px-1",H,"hover:bg-foreground/10"),onClick:()=>C(ee=>ee==="collapsed"?"preview":"collapsed"),children:l.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",k!=="collapsed"?l.jsx(ne.ChevronUp,{className:"h-3 w-3"}):l.jsx(ne.ChevronDown,{className:"h-3 w-3"})]})})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&l.jsx("time",{className:Z("text-xs opacity-60",H,K&&"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&&l.jsxs("div",{className:Z("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",m.actions),children:[l.jsxs("div",{className:"relative",children:[l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>G(A?"visible":"all"),className:Z("h-6 w-6 p-0 hover:bg-foreground/10",H,K&&"h-5 w-5"),"aria-label":A?"Copy visible":"Copy message",title:A?"Copy visible portion":"Copy message",children:l.jsx(ne.Copy,{className:Z(b?"text-success":H,K?"h-3 w-3":"h-4 w-4")})}),A&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>G("all"),className:Z("h-6 px-1 text-xs hover:bg-foreground/10",H),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),L==="user"&&w&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:te,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",H,K&&"h-5 w-5"),"aria-label":"Edit message",children:l.jsx(ne.Edit,{className:Z(H,K?"h-3 w-3":"h-4 w-4")})}),L==="assistant"&&v&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:de,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",H,K&&"h-5 w-5"),"aria-label":"Regenerate response",children:l.jsx(ne.RotateCcw,{className:Z(H,K?"h-3 w-3":"h-4 w-4")})})]})]})]}),l.jsx("div",{className:"relative",children:Ne()}),A&&k==="expanded"&&(Q.toolCallId||Q.name)&&l.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",K&&"text-xs"),children:[Q.name&&l.jsxs("div",{children:["Function: ",Q.name]}),Q.toolCallId&&l.jsxs("div",{children:["Call ID: ",Q.toolCallId]})]}),!(i||a||A)&&s&&!o&&l.jsxs("div",{className:Z("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",m.actions),children:[l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>G(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",K&&"h-5 w-5"),children:l.jsx(ne.Copy,{className:Z(b?"text-success":"text-current",K?"h-3 w-3":"h-4 w-4")})}),L==="user"&&w&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:te,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",K&&"h-5 w-5"),children:l.jsx(ne.Edit,{className:Z("text-current",K?"h-3 w-3":"h-4 w-4")})}),L==="assistant"&&v&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:de,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",K&&"h-5 w-5"),children:l.jsx(ne.RotateCcw,{className:Z("text-current",K?"h-3 w-3":"h-4 w-4")})})]})]})}),V&&l.jsx(Gw,{isOpen:z,onClose:()=>{O(!1),B(null)},fileId:V.id,fileName:V.name,mimeType:V.mimeType})]})},(e,t)=>{var i,a,c,u,d,f,h,m;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&ad(e.message)===ad(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(w=>e[w]===t[w]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((c=e.customStyles)==null?void 0:c.content)===((u=t.customStyles)==null?void 0:u.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)===((m=t.customStyles)==null?void 0:m.header);return o&&s});function nb({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?l.jsx("div",{className:Ko,children:l.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>l.jsx("li",{children:String(n)},r))})}):l.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hi(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return l.jsxs("div",{className:Ko,children:[typeof r=="boolean"&&l.jsxs("p",{children:[l.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&l.jsxs("div",{children:[l.jsx("p",{children:l.jsx("strong",{children:"Follow-up queries:"})}),l.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>l.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&l.jsxs("div",{children:[l.jsx("p",{children:l.jsx("strong",{children:"Facts:"})}),l.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>l.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return l.jsx("div",{className:Ko,children:l.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>l.jsxs("div",{className:"mb-1",children:[l.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),l.jsx("dd",{className:"inline",children:rb(i)})]},s))})})}return l.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hi(e)})}function rb(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return l.jsx("code",{className:"text-xs",children:JSON.stringify(_r(e))})}catch{return String(e)}}function ob({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return l.jsxs(kr,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[l.jsxs(Ir,{className:"pb-3",children:[l.jsx(Nr,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),l.jsx(Gc,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),l.jsx(Yc,{className:"pt-0",children:l.jsxs("div",{className:"flex gap-2 ml-auto",children:[l.jsx(ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",children:"Reject"}),l.jsx(ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function sb({data:e}){return l.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>l.jsxs("div",{className:"flex",children:[l.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),l.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>l.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function ib({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return l.jsx("div",{className:Ko,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:l.jsxs("div",{className:"mb-4",children:[l.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),l.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>l.jsxs("li",{children:[l.jsx("div",{className:"font-medium",children:o.title}),l.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const cd=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ui=y.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:c,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:m,followNewMessages:w=!0,isNavigatingCheckpoint:v=!1,onScrollAway:g,onAtBottom:x},b)=>{const S=y.useRef(null),k=y.useRef(null),C=y.useRef(!1),[T,I]=y.useState(!0),N=y.useCallback(R=>{I(R),g&&g(!R),x&&x(R)},[g,x]),_=y.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),j=y.useMemo(()=>!w||v?!1:T?"auto":!1,[T,w,v]);return e.length===0?l.jsx("div",{className:f,style:h,children:l.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:m||"No messages yet. Start a conversation!"})}):l.jsx("div",{className:f,style:h,children:l.jsx(Rx,{ref:R=>{S.current=R},scrollerRef:R=>{k.current=R instanceof HTMLDivElement?R:null},data:e,followOutput:j,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_&&_()},atBottomStateChange:N,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(R,$)=>cd($,R),itemContent:(R,$)=>{const z=cd($,R);return l.jsx("div",{className:"mb-4 last:mb-0","data-message-id":z,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:l.jsx(ld,{message:$,messageIndex:R,isStreamingMessage:t&&n===$.id,streamingDebounceMs:r,isEditing:i===$.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:c,onRegenerate:()=>u(R),onCancelEdit:d})})}})})});Ui.displayName="MessageList";const qo=1e4;function ab(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,`
|
|
127
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return p.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Hw="DialogDescriptionWarning",Uw=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Xu(Hw).contentName}}.`;return p.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},Ju=Du,Ww=$u,Zu=zu,Uo=Bu,Wo=Hu,Mn=Wu,Vo=Ku,Qu=Gu;const Vw=Ju,Kw=Zu,ed=p.forwardRef(({className:e,...t},n)=>l.jsx(Uo,{ref:n,className:J("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}));ed.displayName=Uo.displayName;const td=p.forwardRef(({className:e,children:t,...n},r)=>{const o=p.useMemo(()=>{let s=!1;function i(a){p.Children.forEach(a,c=>{if(s||!p.isValidElement(c))return;const u=c.type;if(u===Mn||(u==null?void 0:u.displayName)===Mn.displayName||(u==null?void 0:u.name)==="DialogTitle"){s=!0;return}c.props&&c.props.children&&i(c.props.children)})}return i(t),s},[t]);return l.jsxs(Kw,{children:[l.jsx(ed,{}),l.jsxs(Wo,{ref:r,className:J("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&&l.jsx(Mn,{className:"sr-only",children:"Dialog"}),t,l.jsxs(Qu,{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:[l.jsx(ne.X,{className:"h-4 w-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});td.displayName=Wo.displayName;const nd=({className:e,...t})=>l.jsx("div",{className:J("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});nd.displayName="DialogHeader";const rd=p.forwardRef(({className:e,...t},n)=>l.jsx(Mn,{ref:n,className:J("text-lg font-semibold leading-none tracking-tight",e),...t}));rd.displayName=Mn.displayName;const qw=p.forwardRef(({className:e,...t},n)=>l.jsx(Vo,{ref:n,className:J("text-sm text-muted-foreground",e),...t}));qw.displayName=Vo.displayName;function Gw({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=y.useState(!1),[a,c]=y.useState(null),[u,d]=y.useState(null),{toast:f}=Ii(),h=y.useCallback(async()=>{if(n){i(!0),d(null),c(null);try{const x=await uu(n);c(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);y.useEffect(()=>{e&&n&&h()},[e,n,h]);const m=async()=>{if(n)try{await Iv(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"})}},w=async()=>{if(n)try{const x=await uu(n),b=new Blob([x],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},v=()=>s?l.jsxs("div",{className:"flex items-center justify-center py-12",children:[l.jsx(ne.Loader,{className:"h-8 w-8 animate-spin mr-3"}),l.jsx("span",{children:"Loading file..."})]}):u?l.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[l.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),l.jsx("p",{className:"text-red-600 mb-4",children:u}),l.jsx(ze,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?l.jsx("div",{className:"flex justify-center",children:l.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?l.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:l.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?l.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:l.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):l.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[l.jsx(ne.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),l.jsx("p",{className:"text-lg font-medium mb-2",children:r}),l.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):l.jsx("div",{className:"flex items-center justify-center py-12",children:l.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),g=()=>o.startsWith("image/")?l.jsx(ne.Image,{className:"h-5 w-5"}):l.jsx(ne.FileText,{className:"h-5 w-5"});return l.jsx(Vw,{open:e,onOpenChange:t,children:l.jsxs(td,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[l.jsx(nd,{children:l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[g(),l.jsxs("div",{children:[l.jsx(rd,{className:"text-left",children:r}),l.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(ze,{variant:"outline",size:"sm",onClick:w,className:"flex items-center gap-2",children:[l.jsx(ne.ExternalLink,{className:"h-4 w-4"}),"External"]}),l.jsxs(ze,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[l.jsx(ne.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),l.jsx("div",{className:"flex-1 overflow-hidden",children:v()})]})})}function od(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 sd(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function _r(e){if(typeof e=="string")return e.length>2e3?e.slice(0,2e3)+"... [truncated]":e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(_r).filter(r=>r!==void 0);return n.length?n:void 0}if(sd(e))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=_r(r);o!==void 0&&(t[n]=o)}}return Object.keys(t).length?t:void 0}return e}function Hi(e){if(typeof e=="string")return e;if(sd(e))return"";try{const t=_r(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function id(e){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){if(e.desirability||e.feasibility||e.viability||e.other)return{desirability:Array.isArray(e.desirability)?e.desirability:[],feasibility:Array.isArray(e.feasibility)?e.feasibility:[],viability:Array.isArray(e.viability)?e.viability:[],other:Array.isArray(e.other)?e.other:[]};if(e.output&&typeof e.output!="object")e=e.output;else if(e.output&&typeof e.output=="object")return id(e.output)}const t=String(e),n={desirability:[],feasibility:[],viability:[],other:[]};let r=t;const o=Math.min(...["desirability=","feasibility=","viability=","other="].map(i=>{const a=r.toLowerCase().indexOf(i);return a===-1?Number.MAX_SAFE_INTEGER:a}));o!==Number.MAX_SAFE_INTEGER&&(r=r.slice(o));for(const i of Object.keys(n)){const c=new RegExp(i+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!c)continue;const u=c[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let f=null;for(;(f=d.exec(u))!==null;){const h=f[1],m=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(h),w=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(h),v=m?m[2].trim():"",g=w?w[2].trim():"";n[i].push({title:v,description:g})}}return Object.values(n).some(i=>i.length>0)?n:null}const Ko="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",Dn=1e5;function Yw(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Xw(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function Jw(e){const t=e.filter(r=>r.type==="tool_call");return e.filter(r=>r.type==="tool_end").map(r=>{var o;return{name:(o=t.find(s=>s.id===r.toolCallId))==null?void 0:o.name,toolCallId:r.toolCallId,output:r.output}})}function Zw(e){const t=(r,o=Dn)=>{try{const s=_r(r),i=typeof s=="string"?s:JSON.stringify(s??"");return i.length<=o?i:i.slice(0,o)+`
|
|
128
|
+
… [truncated ${i.length-o} chars]`}catch{return""}},n=e.filter(r=>r.type==="tool_end");if(n.length)try{return n.length===1?t(n[0].output):t(n.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return t(e)}function Qw(e){const t=e.find(r=>r.type==="tool_end");if(!t)return null;const n=t.output;return typeof n=="string"?n:null}function eb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function ad(e){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"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function tb({className:e}){const[t,n]=y.useState(0);return y.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),l.jsxs("span",{"aria-live":"polite",className:J("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const ld=y.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:c="desktop",truncateToolMessages:u=!0,toolMessagePreviewLength:d=200,truncateUserMessages:f=!0,userMessagePreviewLength:h=200,customStyles:m={},onEdit:w,onRegenerate:v,onCancelEdit:g,onCopy:x}){const[b,S]=y.useState(!1),[k,C]=y.useState("collapsed"),[T,I]=y.useState(!1),{currentThreadId:N}=mr(),{handleInterrupt:_}=qs(),{toast:R}=Ii(),[j,$]=y.useState({}),[z,O]=y.useState(!1),[V,B]=y.useState(null),K=c==="phone"||c==="half-screen",L=t.role,A=L==="tool",D=!(r&&L!=="user"),H=y.useMemo(()=>{switch(L){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))]"}},[L]),Y=y.useMemo(()=>Yw(t.content),[t.content]),Z=y.useMemo(()=>Xw(t.content),[t.content]),le=y.useMemo(()=>t.content.filter(ee=>ee.type==="image_url"),[t.content]),xe=y.useMemo(()=>t.content.filter(ee=>ee.type==="file"),[t.content]),Ee=y.useMemo(()=>t.content.filter(ee=>ee.type==="interrupt"),[t.content]),W=y.useMemo(()=>Zw(t.content),[t.content]);y.useMemo(()=>Qw(t.content),[t.content]);const M=y.useMemo(()=>W.length<=Dn?W:`${W.slice(0,Dn)}
|
|
129
|
+
… [truncated ${W.length-Dn} chars]`,[W]),G=y.useCallback(async(ee="all")=>{const he=ee==="visible"&&A?M:A?W:Y;async function ge(ke){try{await navigator.clipboard.writeText(ke)}catch{try{const De=document.createElement("textarea");De.value=ke,De.setAttribute("readonly",""),De.style.position="absolute",De.style.left="-9999px",document.body.appendChild(De),De.select(),document.execCommand("copy"),document.body.removeChild(De)}catch(De){throw console.error("Failed to copy:",De),De}}}try{await ge(he),S(!0),setTimeout(()=>S(!1),2e3),x==null||x(he)}catch(ke){console.error("Failed to copy:",ke)}},[A,W,Y,M,x]),te=y.useCallback(()=>{if(!w)return;const ee=A?W:Y;w(t.id,ee)},[w,t.id,A,W,Y]),de=y.useCallback(()=>{v==null||v(n)},[v,n]),ce=y.useCallback(async(ee,se,he)=>{if(!D){ee.preventDefault();return}if(j[he]){ee.preventDefault();return}try{const ge=String(se.url??""),ke=ge.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(ke){ee.preventDefault();const De=ke[1],Ye=se.name||`file_${De}`,Xe=se.mimeType||"application/octet-stream";B({id:De,name:Ye,mimeType:Xe}),O(!0);return}if(ge.startsWith("data:")){ee.preventDefault(),$(Xe=>({...Xe,[he]:!0}));const De=`${se.name}_${se.size}_${Date.now()}`,Ye=R({title:"Fetching file...",description:"",open:!0});try{const Xe=await Nv(N??void 0);if(!Xe||!Array.isArray(Xe))throw new Error("Invalid file list response");const Je=Xe.find(yt=>!yt||typeof yt!="object"||!((yt.filename??"")===(se.name??""))?!1:typeof se.size=="number"&&typeof yt.size=="number"?yt.size===se.size:!0);if(!(Je!=null&&Je.id))throw new Error(`File "${se.name}" is not yet available on the server`);if(!Je.id||!Je.filename)throw new Error("Invalid file data received from server");B({id:Je.id,name:se.name||Je.filename||`file_${Je.id}`,mimeType:se.mimeType||Je.mime_type||"application/octet-stream"}),O(!0),Ye.update({id:Ye.id,title:"Success",description:`Opened ${se.name}`,open:!0})}catch(Xe){console.error("Failed to fetch server file:",Xe);const Je=Xe instanceof Error?Xe.message:"Unknown error occurred";Ye.update({id:Ye.id,title:"Failed",description:Je}),R({title:"Failed to fetch file",description:Je,open:!0})}finally{$(Xe=>({...Xe,[he]:!1}))}}}catch(ge){console.error("File click error:",ge),$(ke=>({...ke,[he]:!1}))}},[D,j,R,N]),$e=y.useCallback(()=>{const se=J(K?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",H);switch(L){case"user":return l.jsx(ne.User,{className:se});case"assistant":return l.jsx(ne.Bot,{className:se});case"tool":return l.jsx(ne.Wrench,{className:se});default:return l.jsx(ne.Bot,{className:se})}},[K,H,L]),Ge=y.useCallback(()=>{const ee="group relative mb-4 flex w-full";switch(L){case"user":return J(ee,"justify-end");case"assistant":case"tool":case"system":return J(ee,"justify-start");default:return ee}},[L]),_e=y.useCallback(()=>{const ee=J("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",K&&"px-3 py-2 text-sm");switch(L){case"user":return J(ee,"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 J(ee,"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 J(ee,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return J(ee,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return J(ee,"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")}},[K,L]),Re=y.useCallback(async ee=>{try{const se=ee.id||`interrupt-${Date.now()}`;await _(se,!0)}catch(se){console.error("Failed to approve interrupt:",se)}},[_]),We=y.useCallback(async ee=>{try{const se=ee.id||`interrupt-${Date.now()}`;await _(se,!1)}catch(se){console.error("Failed to reject interrupt:",se)}},[_]),Q=y.useCallback(({part:ee,i:se})=>{if(ee.type==="text"){const he=ee.text??"",ge=he.trim(),ke=od(ge);return ke&&L!=="tool"?l.jsx(nb,{data:ke},se):L==="user"&&f&&ge.length>h?l.jsxs(Kc,{open:T,onOpenChange:I,children:[l.jsx("div",{className:J("text-sm text-[hsl(var(--chat-bubble-user-text))]",K&&"text-xs"),children:T?l.jsx(Ti,{content:ge,allowHtml:!1}):l.jsxs("pre",{className:J("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",K&&"text-xs"),children:[ge.substring(0,h),"..."]})}),l.jsx(qc,{asChild:!0,children:l.jsx(ze,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:T?l.jsxs(l.Fragment,{children:[l.jsx(ne.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):l.jsxs(l.Fragment,{children:[l.jsx(ne.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",ge.length-h," chars)"]})})})]},se):l.jsx(Ti,{content:he,allowHtml:!1},se)}if(ee.type==="image_url"){const he=ee;return l.jsx("div",{className:"my-2",children:l.jsx("img",{src:he.url,alt:he.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},se)}if(ee.type==="file"){const he=ee,ge=he.name||"file";return l.jsxs("a",{href:he.url,onClick:ke=>ce(ke,he,se),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
130
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[j[se]?l.jsx(ne.Loader,{className:"h-4 w-4 animate-spin"}):null,l.jsxs("span",{className:"truncate max-w-[180px]",children:[ge,j[se]?" (processing)":""]})]},se)}return ee.type==="interrupt"?l.jsx(ob,{interruptPart:ee,onApprove:Re,onReject:We},se):null},[ce,j,Re,We,L,f,h,T,K]),X=y.useCallback(()=>l.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[l.jsx(ne.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),l.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Ne=y.useCallback(()=>{const ee=Y.trim().length>0||le.length>0||xe.length>0||Ee.length>0;if(!A&&!ee&&!r)return X();if(t.model==="reflection"){const se=Y.trim(),he=od(se);if(he&&typeof he=="object")return l.jsx(sb,{data:he})}if(A&&Z.name==="get_issues"){const se=t.content.find(ke=>ke.type==="tool_end"),he=(se==null?void 0:se.output)??W,ge=id(he);if(ge)return l.jsx(ib,{issues:ge})}if(A){const se=Jw(t.content);if(se.length>0)return l.jsx("div",{className:"space-y-2",children:se.map((he,ge)=>{const ke=typeof he.output=="string"?he.output:Hi(he.output),De=ke.length>Dn?`${ke.slice(0,Dn)}
|
|
131
|
+
… [truncated ${ke.length-Dn} chars]`:ke,Ye=k==="expanded";return l.jsxs(Kc,{open:Ye,onOpenChange:Xe=>C(Xe?"expanded":"preview"),children:[l.jsx("div",{className:"flex items-center gap-2 text-xs",children:l.jsx(xi,{variant:"outline",children:(he.name??"tool")+(he.toolCallId?` • ${he.toolCallId.slice(0,8)}`:"")})}),l.jsx("div",{className:"font-mono text-sm mt-1",children:l.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Ye?De:De.slice(0,d)+(De.length>d?"...":"")})}),l.jsx(qc,{asChild:!0,children:l.jsx(ze,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Ye?l.jsxs(l.Fragment,{children:[" ",l.jsx(ne.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):l.jsxs(l.Fragment,{children:[l.jsx(ne.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},he.toolCallId??ge)})})}if(!A){const se=l.jsx("div",{className:"space-y-2",children:t.content.map((he,ge)=>l.jsx(Q,{part:he,i:ge},ge))});return r?l.jsxs("div",{"aria-busy":"true",role:"status",children:[se,l.jsx(tb,{className:H})]}):se}},[Y,le.length,xe.length,Ee.length,r,t.model,A,Z.name,W,k,u,X,H]),He=y.useMemo(()=>eb(t),[t]);return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:J(Ge(),m.container),children:l.jsxs("div",{className:J(_e(),m.content),children:[(i||a||A)&&l.jsxs("div",{className:J("flex items-center justify-between mb-2 pb-2 border-b border-current/10",K&&"mb-1 pb-1",H,m.header),children:[l.jsxs("div",{className:"flex items-center gap-2",children:[$e(),a&&He&&l.jsx("span",{className:J("font-medium",K?"text-xs":"text-sm"),children:He}),A&&Z.name&&l.jsxs(xi,{variant:"outline",className:J("text-xs flex items-center gap-1 cursor-pointer",H,"border border-current/40",K&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":k!=="collapsed",onKeyDown:ee=>{(ee.key==="Enter"||ee.key===" ")&&(ee.preventDefault(),C(se=>se==="collapsed"?"preview":"collapsed"))},onClick:()=>C(ee=>ee==="collapsed"?"preview":"collapsed"),children:[l.jsx("span",{children:Z.name}),l.jsx("span",{className:"inline-flex items-center",children:k!=="collapsed"?l.jsx(ne.ChevronUp,{className:"h-3 w-3"}):l.jsx(ne.ChevronDown,{className:"h-3 w-3"})})]}),A&&!Z.name&&l.jsx(ze,{variant:"ghost",size:"sm",className:J("h-6 px-1",H,"hover:bg-foreground/10"),onClick:()=>C(ee=>ee==="collapsed"?"preview":"collapsed"),children:l.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",k!=="collapsed"?l.jsx(ne.ChevronUp,{className:"h-3 w-3"}):l.jsx(ne.ChevronDown,{className:"h-3 w-3"})]})})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&l.jsx("time",{className:J("text-xs opacity-60",H,K&&"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&&l.jsxs("div",{className:J("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",m.actions),children:[l.jsxs("div",{className:"relative",children:[l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>G(A?"visible":"all"),className:J("h-6 w-6 p-0 hover:bg-foreground/10",H,K&&"h-5 w-5"),"aria-label":A?"Copy visible":"Copy message",title:A?"Copy visible portion":"Copy message",children:l.jsx(ne.Copy,{className:J(b?"text-success":H,K?"h-3 w-3":"h-4 w-4")})}),A&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>G("all"),className:J("h-6 px-1 text-xs hover:bg-foreground/10",H),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),L==="user"&&w&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:te,className:J("h-6 w-6 p-0 hover:bg-foreground/10",H,K&&"h-5 w-5"),"aria-label":"Edit message",children:l.jsx(ne.Edit,{className:J(H,K?"h-3 w-3":"h-4 w-4")})}),L==="assistant"&&v&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:de,className:J("h-6 w-6 p-0 hover:bg-foreground/10",H,K&&"h-5 w-5"),"aria-label":"Regenerate response",children:l.jsx(ne.RotateCcw,{className:J(H,K?"h-3 w-3":"h-4 w-4")})})]})]})]}),l.jsx("div",{className:"relative",children:Ne()}),A&&k==="expanded"&&(Z.toolCallId||Z.name)&&l.jsxs("div",{className:J("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",K&&"text-xs"),children:[Z.name&&l.jsxs("div",{children:["Function: ",Z.name]}),Z.toolCallId&&l.jsxs("div",{children:["Call ID: ",Z.toolCallId]})]}),!(i||a||A)&&s&&!o&&l.jsxs("div",{className:J("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",m.actions),children:[l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>G(),className:J("h-6 w-6 p-0 hover:bg-background/50 text-current",K&&"h-5 w-5"),children:l.jsx(ne.Copy,{className:J(b?"text-success":"text-current",K?"h-3 w-3":"h-4 w-4")})}),L==="user"&&w&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:te,className:J("h-6 w-6 p-0 hover:bg-background/50 text-current",K&&"h-5 w-5"),children:l.jsx(ne.Edit,{className:J("text-current",K?"h-3 w-3":"h-4 w-4")})}),L==="assistant"&&v&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:de,className:J("h-6 w-6 p-0 hover:bg-background/50 text-current",K&&"h-5 w-5"),children:l.jsx(ne.RotateCcw,{className:J("text-current",K?"h-3 w-3":"h-4 w-4")})})]})]})}),V&&l.jsx(Gw,{isOpen:z,onClose:()=>{O(!1),B(null)},fileId:V.id,fileName:V.name,mimeType:V.mimeType})]})},(e,t)=>{var i,a,c,u,d,f,h,m;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&ad(e.message)===ad(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(w=>e[w]===t[w]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((c=e.customStyles)==null?void 0:c.content)===((u=t.customStyles)==null?void 0:u.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)===((m=t.customStyles)==null?void 0:m.header);return o&&s});function nb({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?l.jsx("div",{className:Ko,children:l.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>l.jsx("li",{children:String(n)},r))})}):l.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hi(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return l.jsxs("div",{className:Ko,children:[typeof r=="boolean"&&l.jsxs("p",{children:[l.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&l.jsxs("div",{children:[l.jsx("p",{children:l.jsx("strong",{children:"Follow-up queries:"})}),l.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>l.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&l.jsxs("div",{children:[l.jsx("p",{children:l.jsx("strong",{children:"Facts:"})}),l.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>l.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return l.jsx("div",{className:Ko,children:l.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>l.jsxs("div",{className:"mb-1",children:[l.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),l.jsx("dd",{className:"inline",children:rb(i)})]},s))})})}return l.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hi(e)})}function rb(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return l.jsx("code",{className:"text-xs",children:JSON.stringify(_r(e))})}catch{return String(e)}}function ob({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return l.jsxs(kr,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[l.jsxs(Ir,{className:"pb-3",children:[l.jsx(Nr,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),l.jsx(Gc,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),l.jsx(Yc,{className:"pt-0",children:l.jsxs("div",{className:"flex gap-2 ml-auto",children:[l.jsx(ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",children:"Reject"}),l.jsx(ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function sb({data:e}){return l.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>l.jsxs("div",{className:"flex",children:[l.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),l.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>l.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function ib({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return l.jsx("div",{className:Ko,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:l.jsxs("div",{className:"mb-4",children:[l.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),l.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>l.jsxs("li",{children:[l.jsx("div",{className:"font-medium",children:o.title}),l.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const cd=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ui=y.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:c,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:m,followNewMessages:w=!0,isNavigatingCheckpoint:v=!1,onScrollAway:g,onAtBottom:x},b)=>{const S=y.useRef(null),k=y.useRef(null),C=y.useRef(!1),[T,I]=y.useState(!0),N=y.useCallback(j=>{I(j),g&&g(!j),x&&x(j)},[g,x]),_=y.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),R=y.useMemo(()=>!w||v?!1:T?"auto":!1,[T,w,v]);return e.length===0?l.jsx("div",{className:f,style:h,children:l.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:m||"No messages yet. Start a conversation!"})}):l.jsx("div",{className:f,style:h,children:l.jsx(Rx,{ref:j=>{S.current=j},scrollerRef:j=>{k.current=j instanceof HTMLDivElement?j:null},data:e,followOutput:R,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_&&_()},atBottomStateChange:N,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(j,$)=>cd($,j),itemContent:(j,$)=>{const z=cd($,j);return l.jsx("div",{className:"mb-4 last:mb-0","data-message-id":z,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:l.jsx(ld,{message:$,messageIndex:j,isStreamingMessage:t&&n===$.id,streamingDebounceMs:r,isEditing:i===$.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:c,onRegenerate:()=>u(j),onCancelEdit:d})})}})})});Ui.displayName="MessageList";const qo=1e4;function ab(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,`
|
|
132
132
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
133
133
|
|
|
134
134
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -136,4 +136,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
136
136
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
137
137
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
138
138
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
139
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function lb(e,t=qo){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 cb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),lb(t),ab(t)}function Wi(e){const t=e+"CollectionProvider",[n,r]=Yt(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:g,children:x}=v,b=y.useRef(null),S=y.useRef(new Map).current;return l.jsx(o,{scope:g,itemMap:S,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",c=Tn.createSlot(a),u=y.forwardRef((v,g)=>{const{scope:x,children:b}=v,S=s(a,x),k=Pe(g,S.collectionRef);return l.jsx(c,{ref:k,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Tn.createSlot(d),m=y.forwardRef((v,g)=>{const{scope:x,children:b,...S}=v,k=y.useRef(null),C=Pe(g,k),T=s(d,x);return y.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),l.jsx(h,{[f]:"",ref:C,children:b})});m.displayName=d;function w(v){const g=s(e+"CollectionConsumer",v);return y.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:m},w,r]}var ub=p.createContext(void 0);function Go(e){const t=p.useContext(ub);return e||t||"ltr"}const db=["top","right","bottom","left"],vn=Math.min,Nt=Math.max,Yo=Math.round,Xo=Math.floor,Zt=e=>({x:e,y:e}),fb={left:"right",right:"left",bottom:"top",top:"bottom"},hb={start:"end",end:"start"};function Vi(e,t,n){return Nt(e,vn(t,n))}function sn(e,t){return typeof e=="function"?e(t):e}function an(e){return e.split("-")[0]}function er(e){return e.split("-")[1]}function Ki(e){return e==="x"?"y":"x"}function qi(e){return e==="y"?"height":"width"}const pb=new Set(["top","bottom"]);function Qt(e){return pb.has(an(e))?"y":"x"}function Gi(e){return Ki(Qt(e))}function mb(e,t,n){n===void 0&&(n=!1);const r=er(e),o=Gi(e),s=qi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Jo(i)),[i,Jo(i)]}function gb(e){const t=Jo(e);return[Yi(e),t,Yi(t)]}function Yi(e){return e.replace(/start|end/g,t=>hb[t])}const ud=["left","right"],dd=["right","left"],xb=["top","bottom"],vb=["bottom","top"];function wb(e,t,n){switch(e){case"top":case"bottom":return n?t?dd:ud:t?ud:dd;case"left":case"right":return t?xb:vb;default:return[]}}function bb(e,t,n,r){const o=er(e);let s=wb(an(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Yi)))),s}function Jo(e){return e.replace(/left|right|bottom|top/g,t=>fb[t])}function yb(e){return{top:0,right:0,bottom:0,left:0,...e}}function fd(e){return typeof e!="number"?yb(e):{top:e,right:e,bottom:e,left:e}}function Zo(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 hd(e,t,n){let{reference:r,floating:o}=e;const s=Qt(t),i=Gi(t),a=qi(i),c=an(t),u=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 m;switch(c){case"top":m={x:d,y:r.y-o.height};break;case"bottom":m={x:d,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:f};break;case"left":m={x:r.x-o.width,y:f};break;default:m={x:r.x,y:r.y}}switch(er(t)){case"start":m[i]-=h*(n&&u?-1:1);break;case"end":m[i]+=h*(n&&u?-1:1);break}return m}const Sb=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=hd(u,r,c),h=r,m={},w=0;for(let v=0;v<a.length;v++){const{name:g,fn:x}=a[v],{x:b,y:S,data:k,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:m,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,m={...m,[g]:{...m[g],...k}},C&&w<=50&&(w++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(u=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=hd(u,h,c)),v=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:m}};async function jr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:m=0}=sn(t,e),w=fd(m),g=a[h?f==="floating"?"reference":"floating":f],x=Zo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:c})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Zo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:c}):b);return{top:(x.top-C.top+w.top)/k.y,bottom:(C.bottom-x.bottom+w.bottom)/k.y,left:(x.left-C.left+w.left)/k.x,right:(C.right-x.right+w.right)/k.x}}const Cb=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:c}=t,{element:u,padding:d=0}=sn(e,t)||{};if(u==null)return{};const f=fd(d),h={x:n,y:r},m=Gi(o),w=qi(m),v=await i.getDimensions(u),g=m==="y",x=g?"top":"left",b=g?"bottom":"right",S=g?"clientHeight":"clientWidth",k=s.reference[w]+s.reference[m]-h[m]-s.floating[w],C=h[m]-s.reference[m],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[w]);const N=k/2-C/2,_=I/2-v[w]/2-1,j=vn(f[x],_),R=vn(f[b],_),$=j,z=I-v[w]-R,O=I/2-v[w]/2+N,V=Vi($,O,z),B=!c.arrow&&er(o)!=null&&O!==V&&s.reference[w]/2-(O<$?j:R)-v[w]/2<0,K=B?O<$?O-$:O-z:0;return{[m]:h[m]+K,data:{[m]:V,centerOffset:O-V-K,...B&&{alignmentOffset:K}},reset:B}}}),Tb=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:c,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...g}=sn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=an(o),b=Qt(a),S=an(a)===a,k=await(c.isRTL==null?void 0:c.isRTL(u.floating)),C=h||(S||!v?[Jo(a)]:gb(a)),T=w!=="none";!h&&T&&C.push(...bb(a,v,w,k));const I=[a,...C],N=await jr(t,g),_=[];let j=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[x]),f){const O=mb(o,i,k);_.push(N[O[0]],N[O[1]])}if(j=[...j,{placement:o,overflows:_}],!_.every(O=>O<=0)){var R,$;const O=(((R=s.flip)==null?void 0:R.index)||0)+1,V=I[O];if(V&&(!(f==="alignment"?b!==Qt(V):!1)||j.every(L=>Qt(L.placement)===b?L.overflows[0]>0:!0)))return{data:{index:O,overflows:j},reset:{placement:V}};let B=($=j.filter(K=>K.overflows[0]<=0).sort((K,L)=>K.overflows[1]-L.overflows[1])[0])==null?void 0:$.placement;if(!B)switch(m){case"bestFit":{var z;const K=(z=j.filter(L=>{if(T){const A=Qt(L.placement);return A===b||A==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(A=>A>0).reduce((A,D)=>A+D,0)]).sort((L,A)=>L[1]-A[1])[0])==null?void 0:z[0];K&&(B=K);break}case"initialPlacement":B=a;break}if(o!==B)return{reset:{placement:B}}}return{}}}};function pd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function md(e){return db.some(t=>e[t]>=0)}const Eb=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=sn(e,t);switch(r){case"referenceHidden":{const s=await jr(t,{...o,elementContext:"reference"}),i=pd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:md(i)}}}case"escaped":{const s=await jr(t,{...o,altBoundary:!0}),i=pd(s,n.floating);return{data:{escapedOffsets:i,escaped:md(i)}}}default:return{}}}}},gd=new Set(["left","top"]);async function kb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=an(n),a=er(n),c=Qt(n)==="y",u=gd.has(i)?-1:1,d=s&&c?-1:1,f=sn(t,e);let{mainAxis:h,crossAxis:m,alignmentAxis:w}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof w=="number"&&(m=a==="end"?w*-1:w),c?{x:m*d,y:h*u}:{x:h*u,y:m*d}}const Ib=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,c=await kb(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:i}}}}},Nb=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:g=>{let{x,y:b}=g;return{x,y:b}}},...c}=sn(e,t),u={x:n,y:r},d=await jr(t,c),f=Qt(an(o)),h=Ki(f);let m=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=m+d[g],S=m-d[x];m=Vi(b,m,S)}if(i){const g=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=w+d[g],S=w-d[x];w=Vi(b,w,S)}const v=a.fn({...t,[h]:m,[f]:w});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[h]:s,[f]:i}}}}}},Ab=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:c=!0,crossAxis:u=!0}=sn(e,t),d={x:n,y:r},f=Qt(o),h=Ki(f);let m=d[h],w=d[f];const v=sn(a,t),g=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(c){const S=h==="y"?"height":"width",k=s.reference[h]-s.floating[S]+g.mainAxis,C=s.reference[h]+s.reference[S]-g.mainAxis;m<k?m=k:m>C&&(m=C)}if(u){var x,b;const S=h==="y"?"width":"height",k=gd.has(an(o)),C=s.reference[f]-s.floating[S]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:g.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?g.crossAxis:0);w<C?w=C:w>T&&(w=T)}return{[h]:m,[f]:w}}}},_b=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:c=()=>{},...u}=sn(e,t),d=await jr(t,u),f=an(o),h=er(o),m=Qt(o)==="y",{width:w,height:v}=s.floating;let g,x;f==="top"||f==="bottom"?(g=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,g=h==="end"?"top":"bottom");const b=v-d.top-d.bottom,S=w-d.left-d.right,k=vn(v-d[g],b),C=vn(w-d[x],S),T=!t.middlewareData.shift;let I=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!h){const j=Nt(d.left,0),R=Nt(d.right,0),$=Nt(d.top,0),z=Nt(d.bottom,0);m?N=w-2*(j!==0||R!==0?j+R:Nt(d.left,d.right)):I=v-2*($!==0||z!==0?$+z:Nt(d.top,d.bottom))}await c({...t,availableWidth:N,availableHeight:I});const _=await i.getDimensions(a.floating);return w!==_.width||v!==_.height?{reset:{rects:!0}}:{}}}};function Qo(){return typeof window<"u"}function tr(e){return xd(e)?(e.nodeName||"").toLowerCase():"#document"}function At(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function en(e){var t;return(t=(xd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function xd(e){return Qo()?e instanceof Node||e instanceof At(e).Node:!1}function Ht(e){return Qo()?e instanceof Element||e instanceof At(e).Element:!1}function tn(e){return Qo()?e instanceof HTMLElement||e instanceof At(e).HTMLElement:!1}function vd(e){return!Qo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof At(e).ShadowRoot}const jb=new Set(["inline","contents"]);function Rr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Ut(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!jb.has(o)}const Rb=new Set(["table","td","th"]);function Pb(e){return Rb.has(tr(e))}const Ob=[":popover-open",":modal"];function es(e){return Ob.some(t=>{try{return e.matches(t)}catch{return!1}})}const Mb=["transform","translate","scale","rotate","perspective"],Db=["transform","translate","scale","rotate","perspective","filter"],Lb=["paint","layout","strict","content"];function Xi(e){const t=Ji(),n=Ht(e)?Ut(e):e;return Mb.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)||Db.some(r=>(n.willChange||"").includes(r))||Lb.some(r=>(n.contain||"").includes(r))}function $b(e){let t=wn(e);for(;tn(t)&&!nr(t);){if(Xi(t))return t;if(es(t))return null;t=wn(t)}return null}function Ji(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Fb=new Set(["html","body","#document"]);function nr(e){return Fb.has(tr(e))}function Ut(e){return At(e).getComputedStyle(e)}function ts(e){return Ht(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function wn(e){if(tr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||vd(e)&&e.host||en(e);return vd(t)?t.host:t}function wd(e){const t=wn(e);return nr(t)?e.ownerDocument?e.ownerDocument.body:e.body:tn(t)&&Rr(t)?t:wd(t)}function Pr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=wd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=At(o);if(s){const a=Zi(i);return t.concat(i,i.visualViewport||[],Rr(o)?o:[],a&&n?Pr(a):[])}return t.concat(o,Pr(o,[],n))}function Zi(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function bd(e){const t=Ut(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=tn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Yo(n)!==s||Yo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Qi(e){return Ht(e)?e:e.contextElement}function rr(e){const t=Qi(e);if(!tn(t))return Zt(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=bd(t);let i=(s?Yo(n.width):n.width)/r,a=(s?Yo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const zb=Zt(0);function yd(e){const t=At(e);return!Ji()||!t.visualViewport?zb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Bb(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==At(e)?!1:t}function Ln(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Qi(e);let i=Zt(1);t&&(r?Ht(r)&&(i=rr(r)):i=rr(e));const a=Bb(s,n,r)?yd(s):Zt(0);let c=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=At(s),m=r&&Ht(r)?At(r):r;let w=h,v=Zi(w);for(;v&&r&&m!==w;){const g=rr(v),x=v.getBoundingClientRect(),b=Ut(v),S=x.left+(v.clientLeft+parseFloat(b.paddingLeft))*g.x,k=x.top+(v.clientTop+parseFloat(b.paddingTop))*g.y;c*=g.x,u*=g.y,d*=g.x,f*=g.y,c+=S,u+=k,w=At(v),v=Zi(w)}}return Zo({width:d,height:f,x:c,y:u})}function ea(e,t){const n=ts(e).scrollLeft;return t?t.left+n:Ln(en(e)).left+n}function Sd(e,t,n){n===void 0&&(n=!1);const r=e.getBoundingClientRect(),o=r.left+t.scrollLeft-(n?0:ea(e,r)),s=r.top+t.scrollTop;return{x:o,y:s}}function Hb(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=en(r),a=t?es(t.floating):!1;if(r===i||a&&s)return n;let c={scrollLeft:0,scrollTop:0},u=Zt(1);const d=Zt(0),f=tn(r);if((f||!f&&!s)&&((tr(r)!=="body"||Rr(i))&&(c=ts(r)),tn(r))){const m=Ln(r);u=rr(r),d.x=m.x+r.clientLeft,d.y=m.y+r.clientTop}const h=i&&!f&&!s?Sd(i,c,!0):Zt(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-c.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-c.scrollTop*u.y+d.y+h.y}}function Ub(e){return Array.from(e.getClientRects())}function Wb(e){const t=en(e),n=ts(e),r=e.ownerDocument.body,o=Nt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Nt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ea(e);const a=-n.scrollTop;return Ut(r).direction==="rtl"&&(i+=Nt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function Vb(e,t){const n=At(e),r=en(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,c=0;if(o){s=o.width,i=o.height;const u=Ji();(!u||u&&t==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}return{width:s,height:i,x:a,y:c}}const Kb=new Set(["absolute","fixed"]);function qb(e,t){const n=Ln(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=tn(e)?rr(e):Zt(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,c=o*s.x,u=r*s.y;return{width:i,height:a,x:c,y:u}}function Cd(e,t,n){let r;if(t==="viewport")r=Vb(e,n);else if(t==="document")r=Wb(en(e));else if(Ht(t))r=qb(t,n);else{const o=yd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Zo(r)}function Td(e,t){const n=wn(e);return n===t||!Ht(n)||nr(n)?!1:Ut(n).position==="fixed"||Td(n,t)}function Gb(e,t){const n=t.get(e);if(n)return n;let r=Pr(e,[],!1).filter(a=>Ht(a)&&tr(a)!=="body"),o=null;const s=Ut(e).position==="fixed";let i=s?wn(e):e;for(;Ht(i)&&!nr(i);){const a=Ut(i),c=Xi(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&Kb.has(o.position)||Rr(i)&&!c&&Td(e,i))?r=r.filter(d=>d!==i):o=a,i=wn(i)}return t.set(e,r),r}function Yb(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?es(t)?[]:Gb(t,this._c):[].concat(n),r],a=i[0],c=i.reduce((u,d)=>{const f=Cd(t,d,o);return u.top=Nt(f.top,u.top),u.right=vn(f.right,u.right),u.bottom=vn(f.bottom,u.bottom),u.left=Nt(f.left,u.left),u},Cd(t,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Xb(e){const{width:t,height:n}=bd(e);return{width:t,height:n}}function Jb(e,t,n){const r=tn(t),o=en(t),s=n==="fixed",i=Ln(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const c=Zt(0);function u(){c.x=ea(o)}if(r||!r&&!s)if((tr(t)!=="body"||Rr(o))&&(a=ts(t)),r){const m=Ln(t,!0,s,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?Sd(o,a):Zt(0),f=i.left+a.scrollLeft-c.x-d.x,h=i.top+a.scrollTop-c.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function ta(e){return Ut(e).position==="static"}function Ed(e,t){if(!tn(e)||Ut(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return en(e)===n&&(n=n.ownerDocument.body),n}function kd(e,t){const n=At(e);if(es(e))return n;if(!tn(e)){let o=wn(e);for(;o&&!nr(o);){if(Ht(o)&&!ta(o))return o;o=wn(o)}return n}let r=Ed(e,t);for(;r&&Pb(r)&&ta(r);)r=Ed(r,t);return r&&nr(r)&&ta(r)&&!Xi(r)?n:r||$b(e)||n}const Zb=async function(e){const t=this.getOffsetParent||kd,n=this.getDimensions,r=await n(e.floating);return{reference:Jb(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Qb(e){return Ut(e).direction==="rtl"}const ey={convertOffsetParentRelativeRectToViewportRelativeRect:Hb,getDocumentElement:en,getClippingRect:Yb,getOffsetParent:kd,getElementRects:Zb,getClientRects:Ub,getDimensions:Xb,getScale:rr,isElement:Ht,isRTL:Qb};function Id(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ty(e,t){let n=null,r;const o=en(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:m}=u;if(a||t(),!h||!m)return;const w=Xo(f),v=Xo(o.clientWidth-(d+h)),g=Xo(o.clientHeight-(f+m)),x=Xo(d),S={rootMargin:-w+"px "+-v+"px "+-g+"px "+-x+"px",threshold:Nt(0,vn(1,c))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==c){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Id(u,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function ny(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:c=!1}=r,u=Qi(e),d=o||s?[...u?Pr(u):[],...Pr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?ty(u,n):null;let h=-1,m=null;i&&(m=new ResizeObserver(x=>{let[b]=x;b&&b.target===u&&m&&(m.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=m)==null||S.observe(t)})),n()}),u&&!c&&m.observe(u),m.observe(t));let w,v=c?Ln(e):null;c&&g();function g(){const x=Ln(e);v&&!Id(v,x)&&n(),v=x,w=requestAnimationFrame(g)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=m)==null||x.disconnect(),m=null,c&&cancelAnimationFrame(w)}}const ry=Ib,oy=Nb,sy=Tb,iy=_b,ay=Eb,Nd=Cb,ly=Ab,cy=(e,t,n)=>{const r=new Map,o={platform:ey,...n},s={...o.platform,_c:r};return Sb(e,t,{...o,platform:s})};var uy=typeof document<"u",dy=function(){},ns=uy?y.useLayoutEffect:dy;function rs(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(!rs(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)&&!rs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Ad(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function _d(e,t){const n=Ad(e);return Math.round(t*n)/n}function na(e){const t=p.useRef(e);return ns(()=>{t.current=e}),t}function fy(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:c,open:u}=e,[d,f]=p.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,m]=p.useState(r);rs(h,r)||m(r);const[w,v]=p.useState(null),[g,x]=p.useState(null),b=p.useCallback(L=>{L!==T.current&&(T.current=L,v(L))},[]),S=p.useCallback(L=>{L!==I.current&&(I.current=L,x(L))},[]),k=s||w,C=i||g,T=p.useRef(null),I=p.useRef(null),N=p.useRef(d),_=c!=null,j=na(c),R=na(o),$=na(u),z=p.useCallback(()=>{if(!T.current||!I.current)return;const L={placement:t,strategy:n,middleware:h};R.current&&(L.platform=R.current),cy(T.current,I.current,L).then(A=>{const D={...A,isPositioned:$.current!==!1};O.current&&!rs(N.current,D)&&(N.current=D,qr.flushSync(()=>{f(D)}))})},[h,t,n,R,$]);ns(()=>{u===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[u]);const O=p.useRef(!1);ns(()=>(O.current=!0,()=>{O.current=!1}),[]),ns(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(j.current)return j.current(k,C,z);z()}},[k,C,z,j,_]);const V=p.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),B=p.useMemo(()=>({reference:k,floating:C}),[k,C]),K=p.useMemo(()=>{const L={position:n,left:0,top:0};if(!B.floating)return L;const A=_d(B.floating,d.x),D=_d(B.floating,d.y);return a?{...L,transform:"translate("+A+"px, "+D+"px)",...Ad(B.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:A,top:D}},[n,a,B.floating,d.x,d.y]);return p.useMemo(()=>({...d,update:z,refs:V,elements:B,floatingStyles:K}),[d,z,V,B,K])}const hy=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?Nd({element:r.current,padding:o}).fn(n):{}:r?Nd({element:r,padding:o}).fn(n):{}}}},py=(e,t)=>({...ry(e),options:[e,t]}),my=(e,t)=>({...oy(e),options:[e,t]}),gy=(e,t)=>({...ly(e),options:[e,t]}),xy=(e,t)=>({...sy(e),options:[e,t]}),vy=(e,t)=>({...iy(e),options:[e,t]}),wy=(e,t)=>({...ay(e),options:[e,t]}),by=(e,t)=>({...hy(e),options:[e,t]});var yy="Arrow",jd=p.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return l.jsx(ye.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:l.jsx("polygon",{points:"0,0 30,0 15,10"})})});jd.displayName=yy;var Sy=jd;function Rd(e){const[t,n]=p.useState(void 0);return ct(()=>{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 c=s.borderBoxSize,u=Array.isArray(c)?c[0]:c;i=u.inlineSize,a=u.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 ra="Popper",[Pd,os]=Yt(ra),[Cy,Od]=Pd(ra),Md=e=>{const{__scopePopper:t,children:n}=e,[r,o]=p.useState(null);return l.jsx(Cy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Md.displayName=ra;var Dd="PopperAnchor",Ld=p.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Od(Dd,n),i=p.useRef(null),a=Pe(t,i),c=p.useRef(null);return p.useEffect(()=>{const u=c.current;c.current=(r==null?void 0:r.current)||i.current,u!==c.current&&s.onAnchorChange(c.current)}),r?null:l.jsx(ye.div,{...o,ref:a})});Ld.displayName=Dd;var oa="PopperContent",[Ty,Ey]=Pd(oa),$d=p.forwardRef((e,t)=>{var W,M,G,te,de,ce;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:c=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:m="optimized",onPlaced:w,...v}=e,g=Od(oa,n),[x,b]=p.useState(null),S=Pe(t,$e=>b($e)),[k,C]=p.useState(null),T=Rd(k),I=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),j=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},R=Array.isArray(u)?u:[u],$=R.length>0,z={padding:j,boundary:R.filter(Iy),altBoundary:$},{refs:O,floatingStyles:V,placement:B,isPositioned:K,middlewareData:L}=fy({strategy:"fixed",placement:_,whileElementsMounted:(...$e)=>ny(...$e,{animationFrame:m==="always"}),elements:{reference:g.anchor},middleware:[py({mainAxis:o+N,alignmentAxis:i}),c&&my({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?gy():void 0,...z}),c&&xy({...z}),vy({...z,apply:({elements:$e,rects:Ge,availableWidth:_e,availableHeight:Re})=>{const{width:We,height:J}=Ge.reference,X=$e.floating.style;X.setProperty("--radix-popper-available-width",`${_e}px`),X.setProperty("--radix-popper-available-height",`${Re}px`),X.setProperty("--radix-popper-anchor-width",`${We}px`),X.setProperty("--radix-popper-anchor-height",`${J}px`)}}),k&&by({element:k,padding:a}),Ny({arrowWidth:I,arrowHeight:N}),h&&wy({strategy:"referenceHidden",...z})]}),[A,D]=Bd(B),H=ut(w);ct(()=>{K&&(H==null||H())},[K,H]);const Y=(W=L.arrow)==null?void 0:W.x,Q=(M=L.arrow)==null?void 0:M.y,le=((G=L.arrow)==null?void 0:G.centerOffset)!==0,[xe,Ee]=p.useState();return ct(()=>{x&&Ee(window.getComputedStyle(x).zIndex)},[x]),l.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...V,transform:K?V.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:xe,"--radix-popper-transform-origin":[(te=L.transformOrigin)==null?void 0:te.x,(de=L.transformOrigin)==null?void 0:de.y].join(" "),...((ce=L.hide)==null?void 0:ce.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:l.jsx(Ty,{scope:n,placedSide:A,onArrowChange:C,arrowX:Y,arrowY:Q,shouldHideArrow:le,children:l.jsx(ye.div,{"data-side":A,"data-align":D,...v,ref:S,style:{...v.style,animation:K?void 0:"none"}})})})});$d.displayName=oa;var Fd="PopperArrow",ky={top:"bottom",right:"left",bottom:"top",left:"right"},zd=p.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Ey(Fd,r),i=ky[s.placedSide];return l.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:l.jsx(Sy,{...o,ref:n,style:{...o.style,display:"block"}})})});zd.displayName=Fd;function Iy(e){return e!==null}var Ny=e=>({name:"transformOrigin",options:e,fn(t){var g,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,c=i?0:e.arrowHeight,[u,d]=Bd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,m=(((b=o.arrow)==null?void 0:b.y)??0)+c/2;let w="",v="";return u==="bottom"?(w=i?f:`${h}px`,v=`${-c}px`):u==="top"?(w=i?f:`${h}px`,v=`${r.floating.height+c}px`):u==="right"?(w=`${-c}px`,v=i?f:`${m}px`):u==="left"&&(w=`${r.floating.width+c}px`,v=i?f:`${m}px`),{data:{x:w,y:v}}}});function Bd(e){const[t,n="center"]=e.split("-");return[t,n]}var Hd=Md,Ud=Ld,Wd=$d,Vd=zd,sa="rovingFocusGroup.onEntryFocus",Ay={bubbles:!1,cancelable:!0},Or="RovingFocusGroup",[ia,Kd,_y]=Wi(Or),[jy,qd]=Yt(Or,[_y]),[Ry,Py]=jy(Or),Gd=p.forwardRef((e,t)=>l.jsx(ia.Provider,{scope:e.__scopeRovingFocusGroup,children:l.jsx(ia.Slot,{scope:e.__scopeRovingFocusGroup,children:l.jsx(Oy,{...e,ref:t})})}));Gd.displayName=Or;var Oy=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=p.useRef(null),m=Pe(t,h),w=Go(s),[v,g]=Rn({prop:i,defaultProp:a??null,onChange:c,caller:Or}),[x,b]=p.useState(!1),S=ut(u),k=Kd(n),C=p.useRef(!1),[T,I]=p.useState(0);return p.useEffect(()=>{const N=h.current;if(N)return N.addEventListener(sa,S),()=>N.removeEventListener(sa,S)},[S]),l.jsx(Ry,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:v,onItemFocus:p.useCallback(N=>g(N),[g]),onItemShiftTab:p.useCallback(()=>b(!0),[]),onFocusableItemAdd:p.useCallback(()=>I(N=>N+1),[]),onFocusableItemRemove:p.useCallback(()=>I(N=>N-1),[]),children:l.jsx(ye.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:m,style:{outline:"none",...e.style},onMouseDown:ae(e.onMouseDown,()=>{C.current=!0}),onFocus:ae(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!x){const j=new CustomEvent(sa,Ay);if(N.currentTarget.dispatchEvent(j),!j.defaultPrevented){const R=k().filter(B=>B.focusable),$=R.find(B=>B.active),z=R.find(B=>B.id===v),V=[$,z,...R].filter(Boolean).map(B=>B.ref.current);Jd(V,d)}}C.current=!1}),onBlur:ae(e.onBlur,()=>b(!1))})})}),Yd="RovingFocusGroupItem",Xd=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,c=Xt(),u=s||c,d=Py(Yd,n),f=d.currentTabStopId===u,h=Kd(n),{onFocusableItemAdd:m,onFocusableItemRemove:w,currentTabStopId:v}=d;return p.useEffect(()=>{if(r)return m(),()=>w()},[r,m,w]),l.jsx(ia.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:l.jsx(ye.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ae(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ae(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ae(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const x=Ly(g,d.orientation,d.dir);if(x!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const k=S.indexOf(g.currentTarget);S=d.loop?$y(S,k+1):S.slice(k+1)}setTimeout(()=>Jd(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:v!=null}):i})})});Xd.displayName=Yd;var My={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Dy(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Ly(e,t,n){const r=Dy(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return My[r]}function Jd(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function $y(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Fy=Gd,zy=Xd,aa=["Enter"," "],By=["ArrowDown","PageUp","Home"],Zd=["ArrowUp","PageDown","End"],Hy=[...By,...Zd],Uy={ltr:[...aa,"ArrowRight"],rtl:[...aa,"ArrowLeft"]},Wy={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Mr="Menu",[Dr,Vy,Ky]=Wi(Mr),[$n,Qd]=Yt(Mr,[Ky,os,qd]),ss=os(),ef=qd(),[qy,Fn]=$n(Mr),[Gy,Lr]=$n(Mr),tf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ss(t),[c,u]=p.useState(null),d=p.useRef(!1),f=ut(s),h=Go(o);return p.useEffect(()=>{const m=()=>{d.current=!0,document.addEventListener("pointerdown",w,{capture:!0,once:!0}),document.addEventListener("pointermove",w,{capture:!0,once:!0})},w=()=>d.current=!1;return document.addEventListener("keydown",m,{capture:!0}),()=>{document.removeEventListener("keydown",m,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),l.jsx(Hd,{...a,children:l.jsx(qy,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:u,children:l.jsx(Gy,{scope:t,onClose:p.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};tf.displayName=Mr;var Yy="MenuAnchor",la=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ss(n);return l.jsx(Ud,{...o,...r,ref:t})});la.displayName=Yy;var ca="MenuPortal",[Xy,nf]=$n(ca,{forceMount:void 0}),rf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Fn(ca,t);return l.jsx(Xy,{scope:t,forceMount:n,children:l.jsx(It,{present:n||s.open,children:l.jsx(Ro,{asChild:!0,container:o,children:r})})})};rf.displayName=ca;var Ot="MenuContent",[Jy,ua]=$n(Ot),of=p.forwardRef((e,t)=>{const n=nf(Ot,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Fn(Ot,e.__scopeMenu),i=Lr(Ot,e.__scopeMenu);return l.jsx(Dr.Provider,{scope:e.__scopeMenu,children:l.jsx(It,{present:r||s.open,children:l.jsx(Dr.Slot,{scope:e.__scopeMenu,children:i.modal?l.jsx(Zy,{...o,ref:t}):l.jsx(Qy,{...o,ref:t})})})})}),Zy=p.forwardRef((e,t)=>{const n=Fn(Ot,e.__scopeMenu),r=p.useRef(null),o=Pe(t,r);return p.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),l.jsx(da,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ae(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Qy=p.forwardRef((e,t)=>{const n=Fn(Ot,e.__scopeMenu);return l.jsx(da,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),e0=Tn.createSlot("MenuContent.ScrollLock"),da=p.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:m,disableOutsideScroll:w,...v}=e,g=Fn(Ot,n),x=Lr(Ot,n),b=ss(n),S=ef(n),k=Vy(n),[C,T]=p.useState(null),I=p.useRef(null),N=Pe(t,I,g.onContentChange),_=p.useRef(0),j=p.useRef(""),R=p.useRef(0),$=p.useRef(null),z=p.useRef("right"),O=p.useRef(0),V=w?$o:p.Fragment,B=w?{as:e0,allowPinchZoom:!0}:void 0,K=A=>{var W,M;const D=j.current+A,H=k().filter(G=>!G.disabled),Y=document.activeElement,Q=(W=H.find(G=>G.ref.current===Y))==null?void 0:W.textValue,le=H.map(G=>G.textValue),xe=f0(le,D,Q),Ee=(M=H.find(G=>G.textValue===xe))==null?void 0:M.ref.current;(function G(te){j.current=te,window.clearTimeout(_.current),te!==""&&(_.current=window.setTimeout(()=>G(""),1e3))})(D),Ee&&setTimeout(()=>Ee.focus())};p.useEffect(()=>()=>window.clearTimeout(_.current),[]),Ri();const L=p.useCallback(A=>{var H,Y;return z.current===((H=$.current)==null?void 0:H.side)&&p0(A,(Y=$.current)==null?void 0:Y.area)},[]);return l.jsx(Jy,{scope:n,searchRef:j,onItemEnter:p.useCallback(A=>{L(A)&&A.preventDefault()},[L]),onItemLeave:p.useCallback(A=>{var D;L(A)||((D=I.current)==null||D.focus(),T(null))},[L]),onTriggerLeave:p.useCallback(A=>{L(A)&&A.preventDefault()},[L]),pointerGraceTimerRef:R,onPointerGraceIntentChange:p.useCallback(A=>{$.current=A},[]),children:l.jsx(V,{...B,children:l.jsx(jo,{asChild:!0,trapped:o,onMountAutoFocus:ae(s,A=>{var D;A.preventDefault(),(D=I.current)==null||D.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:l.jsx(_o,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:m,children:l.jsx(Fy,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:ae(c,A=>{x.isUsingKeyboardRef.current||A.preventDefault()}),preventScrollOnEntryFocus:!0,children:l.jsx(Wd,{role:"menu","aria-orientation":"vertical","data-state":Sf(g.open),"data-radix-menu-content":"",dir:x.dir,...b,...v,ref:N,style:{outline:"none",...v.style},onKeyDown:ae(v.onKeyDown,A=>{const H=A.target.closest("[data-radix-menu-content]")===A.currentTarget,Y=A.ctrlKey||A.altKey||A.metaKey,Q=A.key.length===1;H&&(A.key==="Tab"&&A.preventDefault(),!Y&&Q&&K(A.key));const le=I.current;if(A.target!==le||!Hy.includes(A.key))return;A.preventDefault();const Ee=k().filter(W=>!W.disabled).map(W=>W.ref.current);Zd.includes(A.key)&&Ee.reverse(),u0(Ee)}),onBlur:ae(e.onBlur,A=>{A.currentTarget.contains(A.target)||(window.clearTimeout(_.current),j.current="")}),onPointerMove:ae(e.onPointerMove,Fr(A=>{const D=A.target,H=O.current!==A.clientX;if(A.currentTarget.contains(D)&&H){const Y=A.clientX>O.current?"right":"left";z.current=Y,O.current=A.clientX}}))})})})})})})});of.displayName=Ot;var t0="MenuGroup",fa=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(ye.div,{role:"group",...r,ref:t})});fa.displayName=t0;var n0="MenuLabel",sf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(ye.div,{...r,ref:t})});sf.displayName=n0;var is="MenuItem",af="menu.itemSelect",as=p.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=p.useRef(null),i=Lr(is,e.__scopeMenu),a=ua(is,e.__scopeMenu),c=Pe(t,s),u=p.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(af,{bubbles:!0,cancelable:!0});f.addEventListener(af,m=>r==null?void 0:r(m),{once:!0}),Hc(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return l.jsx(lf,{...o,ref:c,disabled:n,onClick:ae(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ae(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ae(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||aa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});as.displayName=is;var lf=p.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ua(is,n),a=ef(n),c=p.useRef(null),u=Pe(t,c),[d,f]=p.useState(!1),[h,m]=p.useState("");return p.useEffect(()=>{const w=c.current;w&&m((w.textContent??"").trim())},[s.children]),l.jsx(Dr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:l.jsx(zy,{asChild:!0,...a,focusable:!r,children:l.jsx(ye.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ae(e.onPointerMove,Fr(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ae(e.onPointerLeave,Fr(w=>i.onItemLeave(w))),onFocus:ae(e.onFocus,()=>f(!0)),onBlur:ae(e.onBlur,()=>f(!1))})})})}),r0="MenuCheckboxItem",cf=p.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return l.jsx(pf,{scope:e.__scopeMenu,checked:n,children:l.jsx(as,{role:"menuitemcheckbox","aria-checked":ls(n)?"mixed":n,...o,ref:t,"data-state":pa(n),onSelect:ae(o.onSelect,()=>r==null?void 0:r(ls(n)?!0:!n),{checkForDefaultPrevented:!1})})})});cf.displayName=r0;var uf="MenuRadioGroup",[o0,s0]=$n(uf,{value:void 0,onValueChange:()=>{}}),df=p.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=ut(r);return l.jsx(o0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:l.jsx(fa,{...o,ref:t})})});df.displayName=uf;var ff="MenuRadioItem",hf=p.forwardRef((e,t)=>{const{value:n,...r}=e,o=s0(ff,e.__scopeMenu),s=n===o.value;return l.jsx(pf,{scope:e.__scopeMenu,checked:s,children:l.jsx(as,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":pa(s),onSelect:ae(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});hf.displayName=ff;var ha="MenuItemIndicator",[pf,i0]=$n(ha,{checked:!1}),mf=p.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=i0(ha,n);return l.jsx(It,{present:r||ls(s.checked)||s.checked===!0,children:l.jsx(ye.span,{...o,ref:t,"data-state":pa(s.checked)})})});mf.displayName=ha;var a0="MenuSeparator",gf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(ye.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});gf.displayName=a0;var l0="MenuArrow",xf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ss(n);return l.jsx(Vd,{...o,...r,ref:t})});xf.displayName=l0;var c0="MenuSub",[qC,vf]=$n(c0),$r="MenuSubTrigger",wf=p.forwardRef((e,t)=>{const n=Fn($r,e.__scopeMenu),r=Lr($r,e.__scopeMenu),o=vf($r,e.__scopeMenu),s=ua($r,e.__scopeMenu),i=p.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,u={__scopeMenu:e.__scopeMenu},d=p.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return p.useEffect(()=>d,[d]),p.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),c(null)}},[a,c]),l.jsx(la,{asChild:!0,...u,children:l.jsx(lf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Sf(n.open),...e,ref:vi(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:ae(e.onPointerMove,Fr(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:ae(e.onPointerLeave,Fr(f=>{var m,w;d();const h=(m=n.content)==null?void 0:m.getBoundingClientRect();if(h){const v=(w=n.content)==null?void 0:w.dataset.side,g=v==="right",x=g?-5:5,b=h[g?"left":"right"],S=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ae(e.onKeyDown,f=>{var m;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||Uy[r.dir].includes(f.key)&&(n.onOpenChange(!0),(m=n.content)==null||m.focus(),f.preventDefault())})})})});wf.displayName=$r;var bf="MenuSubContent",yf=p.forwardRef((e,t)=>{const n=nf(Ot,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Fn(Ot,e.__scopeMenu),i=Lr(Ot,e.__scopeMenu),a=vf(bf,e.__scopeMenu),c=p.useRef(null),u=Pe(t,c);return l.jsx(Dr.Provider,{scope:e.__scopeMenu,children:l.jsx(It,{present:r||s.open,children:l.jsx(Dr.Slot,{scope:e.__scopeMenu,children:l.jsx(da,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=c.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ae(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ae(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ae(e.onKeyDown,d=>{var m;const f=d.currentTarget.contains(d.target),h=Wy[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(m=a.trigger)==null||m.focus(),d.preventDefault())})})})})})});yf.displayName=bf;function Sf(e){return e?"open":"closed"}function ls(e){return e==="indeterminate"}function pa(e){return ls(e)?"indeterminate":e?"checked":"unchecked"}function u0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function d0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function f0(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=d0(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const c=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return c!==n?c:void 0}function h0(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],c=t[i],u=a.x,d=a.y,f=c.x,h=c.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function p0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return h0(n,t)}function Fr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var m0=tf,g0=la,x0=rf,v0=of,w0=fa,b0=sf,y0=as,S0=cf,C0=df,T0=hf,E0=mf,k0=gf,I0=xf,N0=wf,A0=yf,cs="DropdownMenu",[_0,GC]=Yt(cs,[Qd]),gt=Qd(),[j0,Cf]=_0(cs),Tf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=gt(t),u=p.useRef(null),[d,f]=Rn({prop:o,defaultProp:s??!1,onChange:i,caller:cs});return l.jsx(j0,{scope:t,triggerId:Xt(),triggerRef:u,contentId:Xt(),open:d,onOpenChange:f,onOpenToggle:p.useCallback(()=>f(h=>!h),[f]),modal:a,children:l.jsx(m0,{...c,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Tf.displayName=cs;var Ef="DropdownMenuTrigger",kf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Cf(Ef,n),i=gt(n);return l.jsx(g0,{asChild:!0,...i,children:l.jsx(ye.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:vi(t,s.triggerRef),onPointerDown:ae(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ae(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});kf.displayName=Ef;var R0="DropdownMenuPortal",If=e=>{const{__scopeDropdownMenu:t,...n}=e,r=gt(t);return l.jsx(x0,{...r,...n})};If.displayName=R0;var Nf="DropdownMenuContent",Af=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Cf(Nf,n),s=gt(n),i=p.useRef(!1);return l.jsx(v0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ae(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)==null||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ae(e.onInteractOutside,a=>{const c=a.detail.originalEvent,u=c.button===0&&c.ctrlKey===!0,d=c.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Af.displayName=Nf;var P0="DropdownMenuGroup",O0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(w0,{...o,...r,ref:t})});O0.displayName=P0;var M0="DropdownMenuLabel",_f=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(b0,{...o,...r,ref:t})});_f.displayName=M0;var D0="DropdownMenuItem",jf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(y0,{...o,...r,ref:t})});jf.displayName=D0;var L0="DropdownMenuCheckboxItem",Rf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(S0,{...o,...r,ref:t})});Rf.displayName=L0;var $0="DropdownMenuRadioGroup",F0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(C0,{...o,...r,ref:t})});F0.displayName=$0;var z0="DropdownMenuRadioItem",Pf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(T0,{...o,...r,ref:t})});Pf.displayName=z0;var B0="DropdownMenuItemIndicator",Of=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(E0,{...o,...r,ref:t})});Of.displayName=B0;var H0="DropdownMenuSeparator",Mf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(k0,{...o,...r,ref:t})});Mf.displayName=H0;var U0="DropdownMenuArrow",W0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(I0,{...o,...r,ref:t})});W0.displayName=U0;var V0="DropdownMenuSubTrigger",Df=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(N0,{...o,...r,ref:t})});Df.displayName=V0;var K0="DropdownMenuSubContent",Lf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(A0,{...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)"}})});Lf.displayName=K0;var q0=Tf,G0=kf,Y0=If,$f=Af,Ff=_f,zf=jf,Bf=Rf,Hf=Pf,Uf=Of,Wf=Mf,Vf=Df,Kf=Lf;const X0=q0,J0=G0,Z0=p.forwardRef(({className:e,inset:t,children:n,...r},o)=>l.jsxs(Vf,{ref:o,className:Z("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,l.jsx(ne.ChevronRight,{className:"ml-auto h-4 w-4"})]}));Z0.displayName=Vf.displayName;const Q0=p.forwardRef(({className:e,...t},n)=>l.jsx(Kf,{ref:n,className:Z("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}));Q0.displayName=Kf.displayName;const qf=p.forwardRef(({className:e,sideOffset:t=4,...n},r)=>l.jsx(Y0,{children:l.jsx($f,{ref:r,sideOffset:t,className:Z("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})}));qf.displayName=$f.displayName;const ma=p.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(zf,{ref:r,className:Z("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}));ma.displayName=zf.displayName;const eS=p.forwardRef(({className:e,children:t,checked:n,...r},o)=>l.jsxs(Bf,{ref:o,className:Z("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:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(Uf,{children:l.jsx(ne.Check,{className:"h-4 w-4"})})}),t]}));eS.displayName=Bf.displayName;const tS=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Hf,{ref:r,className:Z("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:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(Uf,{children:l.jsx(ne.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));tS.displayName=Hf.displayName;const nS=p.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Ff,{ref:r,className:Z("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));nS.displayName=Ff.displayName;const rS=p.forwardRef(({className:e,...t},n)=>l.jsx(Wf,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));rS.displayName=Wf.displayName;function us({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:c=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:m}){const{api:w}=so(),{currentThreadId:v,isLoadingThread:g,listCheckpoints:x,navigateToCheckpoint:b,returnToLatest:S}=mr(),{messages:k,hasMoreHistory:C,isLoadingHistory:T,send:I,stop:N,loadOlderMessages:_}=qs(),{isStreaming:j,error:R,streamingAssistantId:$,lastCheckpointId:z,lastCheckpointNs:O}=Ol(),[V,B]=y.useState(null),[K,L]=y.useState(""),[A,D]=y.useState(null),[H,Y]=y.useState([]),[Q,le]=y.useState(0),[xe,Ee]=y.useState(0),[W,M]=y.useState(!1),[G,te]=y.useState(null),[de,ce]=y.useState(null),[$e,Ge]=y.useState(!1),[_e,Re]=y.useState(null),[We,J]=y.useState([]),[X,Ne]=y.useState(null),[He,ee]=y.useState(null),[se,he]=y.useState(!1),ge=y.useRef(null),ke=y.useRef(null),De=y.useRef(null),Ye=y.useCallback(()=>{ge.current&&(ge.current.value=""),ke.current&&(ke.current.value=""),le(ue=>ue+1),Ee(ue=>ue+1)},[]),Xe=y.useRef(!1);y.useEffect(()=>{Xe.current&&!j&&(Y([]),Ye()),Xe.current=j},[j,Ye]);const[Je,yt]=y.useState("desktop");y.useEffect(()=>{const ue=()=>{const ve=window.innerWidth;yt(ve<640?"phone":ve<1024?"tablet":"desktop")};return ue(),window.addEventListener("resize",ue),()=>window.removeEventListener("resize",ue)},[]),y.useEffect(()=>{let ue=!1;if(!v){J([]),Ne(null),ee(null),De.current=null;return}const ve={threadId:v,checkpointId:z??null,checkpointNs:O??null},Le=De.current;if(!(Le&&Le.threadId===ve.threadId&&Le.checkpointId===ve.checkpointId&&Le.checkpointNs===ve.checkpointNs))return x(v).then(nt=>{var ks;if(ue)return;const _t=((nt==null?void 0:nt.checkpoints)??[]).slice().sort((cn,E)=>new Date(E.createdAt).getTime()-new Date(cn.createdAt).getTime());J(_t);const rn=X,Vr=rn&&_t.some(cn=>cn.checkpointId===rn)?rn:((ks=_t[0])==null?void 0:ks.checkpointId)??null;let Es=null;if(Vr){const cn=_t.find(E=>E.checkpointId===Vr);Es=(cn==null?void 0:cn.checkpointNs)??null}Ne(Vr),ee(Es),De.current=ve}).catch(nt=>{console.error("ChatInterface - listCheckpoints error:",nt),ue||(J([]),De.current=null)}),()=>{ue=!0}},[v,z,O,X,x]),y.useEffect(()=>{z&&(Ne(z),ee(O??null))},[z,O]);const ln=y.useCallback(async()=>{if(!(!C||T))try{await _()}catch(ue){console.warn("loadOlderMessages failed",ue)}},[C,T,_]);y.useEffect(()=>{(async()=>{if(!w.baseUrl){Re(null);return}try{const ve=await w.getAgent("default");Re(ve.uiDefaultMessage||null)}catch(ve){console.warn("Failed to fetch default message:",ve),Re(null)}})()},[w]),y.useEffect(()=>{R&&!$e&&(m==null||m(R))},[R,$e,m]);const _a=ue=>{if(ue.length>qo)return`Message too long (${ue.length}/${qo} characters)`;try{return cb(ue),null}catch(ve){return(ve==null?void 0:ve.message)||"Invalid message"}},ja=async ue=>{const ve=ue.trim();if(!(!ve&&H.length===0)){if(ve){const Le=_a(ve);if(Le){D(Le);return}}try{await I(ve||"",{checkpointId:X??z??void 0,checkpointNs:He??O??void 0,payloadExtras:V?{edit:!0,originalMessageId:V}:void 0,attachments:H}),f==null||f(ve),D(null),Y([]),Ye(),B(null),L("")}catch(Le){const nt=(Le==null?void 0:Le.message)||"Failed to send message";D(nt),m==null||m(nt)}}},ys=y.useCallback((ue,ve)=>{u&&(B(ue),L(ve),D(null))},[u]),Br=y.useCallback(()=>{B(null),L(""),D(null)},[]),Ra=y.useCallback((ue,ve)=>{ys(ue,ve)},[ys]),Hr=y.useCallback(ue=>{const ve=Le=>{const nt=Le.content||[],_t=nt.filter(rn=>rn.type==="text").map(rn=>rn.text).join("");if(_t)return _t;try{return JSON.stringify(nt,null,2)}catch{return String(nt)}};for(let Le=ue-1;Le>=0;Le--)if(k[Le].role==="user"){const nt=ve(k[Le]);nt&&I(nt,{checkpointId:X??z??void 0,checkpointNs:He??O??void 0});break}},[k,I,X,He,z,O]),Ss=ue=>{const ve=Array.from(ue.target.files||[]);Y(Le=>[...Le,...ve]),ue.target.value=""},Cn=ue=>{Y(ve=>{const Le=ve.filter((nt,_t)=>ue!==_t);return Le.length===0&&Ye(),Le})},Ur=async ue=>{const ve=(ue.target.files||[])[0];if(ve){te(null),ce(null),M(!0);try{await I("",{checkpointId:X??z??void 0,checkpointNs:He??O??void 0,attachments:[ve]});const Le=`Uploaded ${ve.name} - processing through chat stream`;ce(Le)}catch(Le){const nt=Le instanceof Error?Le.message:"Failed to upload Excel file";console.error("Excel upload failed",Le),te(nt),m==null||m(nt)}finally{M(!1),ue.target.value="",Ye()}}},Wr=ue=>{if(!ue)return"Unknown";const ve=Date.parse(ue);return Number.isNaN(ve)?ue:new Date(ve).toLocaleString()},Cs=async ue=>{if(v){he(!0);try{if(!ue){await S(),Ne(null),ee(null);return}const ve=We.find(nt=>nt.checkpointId===ue),Le=(ve==null?void 0:ve.checkpointNs)??null;await b(ue,Le),Ne(ue),ee(Le)}finally{he(!1)}}},Pa=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Ts=`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 ${d.messagesArea||""}`,Oa=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return l.jsxs("div",{className:Pa,children:[!!R&&!$e&&l.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:[l.jsx("span",{children:R}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Ge(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:l.jsx(ne.X,{size:16})})]}),v&&We.length>0&&l.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:[l.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),l.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:X??"",onChange:ue=>{const ve=ue.target.value||null;Cs(ve)},children:[l.jsx("option",{value:"",children:"Latest"}),We.map(ue=>l.jsxs("option",{value:ue.checkpointId,children:[Wr(ue.createdAt),ue.preview?` — ${ue.preview.slice(0,40)}`:""]},ue.checkpointId))]})]}),l.jsxs("div",{className:`relative ${Ts}`,style:r?{maxHeight:r}:void 0,children:[l.jsx(Ui,{className:"h-full",style:{height:"100%"},messages:k,isStreaming:j,streamingAssistantId:$,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Je,enableMessageEditing:u,editingMessageId:V,onStartReached:()=>{ln()},onEdit:Ra,onRegenerate:Hr,onCancelEdit:Br,emptyMessage:_e??void 0,isNavigatingCheckpoint:se}),g&&l.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:[l.jsx(ne.Loader2,{className:"h-6 w-6 animate-spin"}),l.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),l.jsxs("div",{className:Oa,children:[V&&l.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ne.Edit3,{size:16,className:"text-blue-600"}),l.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:Br,className:"text-blue-600 hover:bg-blue-100",children:l.jsx(ne.X,{size:16})})]})}),(a||c)&&l.jsxs("div",{className:"mb-3 space-y-3",children:[a&&l.jsxs(l.Fragment,{children:[l.jsx("input",{ref:ge,type:"file",multiple:!0,onChange:ue=>Ss(ue),className:"hidden"},Q),H.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2",children:H.map((ue,ve)=>l.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:[l.jsx(ne.Paperclip,{size:14}),l.jsx("span",{className:"truncate max-w-[150px]",children:ue.name}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Cn(ve),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 ${ue.name}`,children:l.jsx(ne.X,{size:12})})]},ve))})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("input",{ref:ke,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Ur,className:"hidden"},xe),W&&l.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[l.jsx(ne.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),de&&!W&&l.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:de}),G&&!W&&l.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:G})]})]}),A&&l.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:A}),l.jsxs("div",{className:"flex items-end gap-2",children:[(a||c)&&l.jsxs(X0,{children:[l.jsx(J0,{asChild:!0,children:l.jsx(ze,{type:"button",size:"icon",variant:"outline",disabled:j,title:"More input actions",className:d.moreButton||"",children:l.jsx(ne.Plus,{size:16})})}),l.jsxs(qf,{align:"start",sideOffset:6,className:"w-52",children:[a&&l.jsxs(ma,{onClick:()=>{var ue;return(ue=ge.current)==null?void 0:ue.click()},className:"cursor-pointer",children:[l.jsx(ne.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),c&&l.jsxs(ma,{onClick:()=>{var ue;W||(ue=ke.current)==null||ue.click()},className:`cursor-pointer ${W?"opacity-60 pointer-events-none":""}`,children:[l.jsx(ne.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),l.jsx("div",{className:"flex-1",children:l.jsx(Sg,{initialValue:K,editingMessageId:V,placeholder:V?"Edit your message...":t,isStreaming:j,disabled:!1,maxLength:qo,onSend:ja,onCancelEdit:Br,onStop:N,allowEmptySend:H.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${V?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${A?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const ds=p.forwardRef(({className:e,type:t,...n},r)=>l.jsx("input",{type:t,className:Z("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}));ds.displayName="Input";function ga(e,[t,n]){return Math.min(n,Math.max(t,e))}function oS(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var xa="ScrollArea",[Gf,YC]=Yt(xa),[sS,Mt]=Gf(xa),Yf=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,c]=p.useState(null),[u,d]=p.useState(null),[f,h]=p.useState(null),[m,w]=p.useState(null),[v,g]=p.useState(null),[x,b]=p.useState(0),[S,k]=p.useState(0),[C,T]=p.useState(!1),[I,N]=p.useState(!1),_=Pe(t,R=>c(R)),j=Go(o);return l.jsx(sS,{scope:n,type:r,dir:j,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:m,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:v,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:l.jsx(ye.div,{dir:j,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Yf.displayName=xa;var Xf="ScrollAreaViewport",Jf=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Mt(Xf,n),a=p.useRef(null),c=Pe(t,a,i.onViewportChange);return l.jsxs(l.Fragment,{children:[l.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}),l.jsx(ye.div,{"data-radix-scroll-area-viewport":"",...s,ref:c,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:l.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Jf.displayName=Xf;var nn="ScrollAreaScrollbar",va=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Mt(nn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return p.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?l.jsx(iS,{...r,ref:t,forceMount:n}):o.type==="scroll"?l.jsx(aS,{...r,ref:t,forceMount:n}):o.type==="auto"?l.jsx(Zf,{...r,ref:t,forceMount:n}):o.type==="always"?l.jsx(wa,{...r,ref:t}):null});va.displayName=nn;var iS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Mt(nn,e.__scopeScrollArea),[s,i]=p.useState(!1);return p.useEffect(()=>{const a=o.scrollArea;let c=0;if(a){const u=()=>{window.clearTimeout(c),i(!0)},d=()=>{c=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(c),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),l.jsx(It,{present:n||s,children:l.jsx(Zf,{"data-state":s?"visible":"hidden",...r,ref:t})})}),aS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Mt(nn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ms(()=>c("SCROLL_END"),100),[a,c]=oS("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 p.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>c("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,c]),p.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const m=u[d];f!==m&&(c("SCROLL"),i()),f=m};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,c,i]),l.jsx(It,{present:n||a!=="hidden",children:l.jsx(wa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ae(e.onPointerEnter,()=>c("POINTER_ENTER")),onPointerLeave:ae(e.onPointerLeave,()=>c("POINTER_LEAVE"))})})}),Zf=p.forwardRef((e,t)=>{const n=Mt(nn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=p.useState(!1),a=e.orientation==="horizontal",c=ms(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return or(n.viewport,c),or(n.content,c),l.jsx(It,{present:r||s,children:l.jsx(wa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),wa=p.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Mt(nn,e.__scopeScrollArea),s=p.useRef(null),i=p.useRef(0),[a,c]=p.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=rh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:c,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,m){return hS(h,i.current,a,m)}return n==="horizontal"?l.jsx(lS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,m=oh(h,a,o.dir);s.current.style.transform=`translate3d(${m}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?l.jsx(cS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,m=oh(h,a);s.current.style.transform=`translate3d(0, ${m}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),lS=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Mt(nn,e.__scopeScrollArea),[i,a]=p.useState(),c=p.useRef(null),u=Pe(t,c,s.onScrollbarXChange);return p.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),l.jsx(eh,{"data-orientation":"horizontal",...o,ref:u,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":ps(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),ih(h,f)&&d.preventDefault()}},onResize:()=>{c.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:c.current.clientWidth,paddingStart:hs(i.paddingLeft),paddingEnd:hs(i.paddingRight)}})}})}),cS=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Mt(nn,e.__scopeScrollArea),[i,a]=p.useState(),c=p.useRef(null),u=Pe(t,c,s.onScrollbarYChange);return p.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),l.jsx(eh,{"data-orientation":"vertical",...o,ref:u,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":ps(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),ih(h,f)&&d.preventDefault()}},onResize:()=>{c.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:c.current.clientHeight,paddingStart:hs(i.paddingTop),paddingEnd:hs(i.paddingBottom)}})}})}),[uS,Qf]=Gf(nn),eh=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:c,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,m=Mt(nn,n),[w,v]=p.useState(null),g=Pe(t,_=>v(_)),x=p.useRef(null),b=p.useRef(""),S=m.viewport,k=r.content-r.viewport,C=ut(d),T=ut(c),I=ms(f,10);function N(_){if(x.current){const j=_.clientX-x.current.left,R=_.clientY-x.current.top;u({x:j,y:R})}}return p.useEffect(()=>{const _=j=>{const R=j.target;(w==null?void 0:w.contains(R))&&C(j,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,w,k,C]),p.useEffect(T,[r,T]),or(w,I),or(m.content,I),l.jsx(uS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:ut(s),onThumbPointerUp:ut(i),onThumbPositionChange:T,onThumbPointerDown:ut(a),children:l.jsx(ye.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ae(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",m.viewport&&(m.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:ae(e.onPointerMove,N),onPointerUp:ae(e.onPointerUp,_=>{const j=_.target;j.hasPointerCapture(_.pointerId)&&j.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,m.viewport&&(m.viewport.style.scrollBehavior=""),x.current=null})})})}),fs="ScrollAreaThumb",th=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qf(fs,e.__scopeScrollArea);return l.jsx(It,{present:n||o.hasThumb,children:l.jsx(dS,{ref:t,...r})})}),dS=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Mt(fs,n),i=Qf(fs,n),{onThumbPositionChange:a}=i,c=Pe(t,f=>i.onThumbChange(f)),u=p.useRef(void 0),d=ms(()=>{u.current&&(u.current(),u.current=void 0)},100);return p.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const m=pS(f,a);u.current=m,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),l.jsx(ye.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:c,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ae(e.onPointerDownCapture,f=>{const m=f.target.getBoundingClientRect(),w=f.clientX-m.left,v=f.clientY-m.top;i.onThumbPointerDown({x:w,y:v})}),onPointerUp:ae(e.onPointerUp,i.onThumbPointerUp)})});th.displayName=fs;var ba="ScrollAreaCorner",nh=p.forwardRef((e,t)=>{const n=Mt(ba,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?l.jsx(fS,{...e,ref:t}):null});nh.displayName=ba;var fS=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Mt(ba,n),[s,i]=p.useState(0),[a,c]=p.useState(0),u=!!(s&&a);return or(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),c(d)}),or(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?l.jsx(ye.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 hs(e){return e?parseInt(e,10):0}function rh(e,t){const n=e/t;return isNaN(n)?0:n}function ps(e){const t=rh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function hS(e,t,n,r="ltr"){const o=ps(n),s=o/2,i=t||s,a=o-i,c=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return sh([c,u],f)(e)}function oh(e,t,n="ltr"){const r=ps(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,c=n==="ltr"?[0,i]:[i*-1,0],u=ga(e,c);return sh([0,i],[0,a])(u)}function sh(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 ih(e,t){return e>0&&e<t}var pS=(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 ms(e,t){const n=ut(e),r=p.useRef(0);return p.useEffect(()=>()=>window.clearTimeout(r.current),[]),p.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function or(e,t){const n=ut(t);ct(()=>{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 ah=Yf,mS=Jf,gS=nh;const lh=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(ah,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[l.jsx(mS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),l.jsx(ch,{}),l.jsx(gS,{})]}));lh.displayName=ah.displayName;const ch=p.forwardRef(({className:e,orientation:t="vertical",...n},r)=>l.jsx(va,{ref:r,orientation:t,className:Z("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:l.jsx(th,{className:"relative flex-1 rounded-full bg-border"})}));ch.displayName=va.displayName;function ya({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:c,onThreadCreate:u,onThreadDelete:d}){const{loadThread:f,threads:h,currentThreadId:m,createThread:w,deleteThread:v,renameThread:g,isLoadingThreads:x}=mr(),[b,S]=y.useState(h??[]),[k,C]=y.useState(null),[T,I]=y.useState(""),[N,_]=y.useState(!1);y.useEffect(()=>{S(h??[])},[h]);const j=async A=>{try{await f(A),a==null||a(A),c==null||c(A)}catch(D){console.error("Failed to select thread:",D)}},R=async()=>{try{_(!0);const A=await w();u==null||u(A),a==null||a(A)}catch(A){console.error("Failed to create thread:",A)}finally{_(!1)}},$=async(A,D)=>{if(D.stopPropagation(),!!confirm("Delete this thread?"))try{await v(A),d==null||d(A)}catch(H){console.error("Failed to delete thread:",H)}},z=(A,D)=>{D.stopPropagation(),C(A.threadId),I(A.title||`Thread ${A.threadId.slice(0,8)}`)},O=async A=>{if(T.trim())try{await g(A,T.trim()),C(null),I("")}catch(D){console.error("Failed to update title:",D)}},V=()=>{C(null),I("")},B=(A,D)=>{A.key==="Enter"?O(D):A.key==="Escape"&&V()},K=A=>{if(!A)return"";try{const D=new Date(A),Y=new Date().getTime()-D.getTime(),Q=Math.floor(Y/(1e3*60*60*24));return Q===0?D.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Q===1?"Yesterday":Q<7?`${Q} days ago`:D.toLocaleDateString()}catch{return""}},L=A=>A.title||`Thread ${A.threadId.slice(0,8)}`;return l.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&l.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:l.jsx(ze,{onClick:R,disabled:N||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:N?"Creating...":"New Chat",children:l.jsx(ne.MessageSquarePlus,{size:20})})}),l.jsx(lh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:l.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?l.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[l.jsx(ne.Loader2,{className:"h-5 w-5 animate-spin"}),l.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):b.length===0?l.jsxs("div",{className:"text-center py-8 text-slate-400",children:[l.jsx(ne.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),l.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):b.slice().sort((A,D)=>new Date(D.updatedAt||D.createdAt||"").getTime()-new Date(A.updatedAt||A.createdAt||"").getTime()).map(A=>l.jsxs("div",{onClick:()=>j(A.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??m)===A.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:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("div",{className:"flex-1 min-w-0",children:k===A.threadId?l.jsxs("div",{className:"flex items-center gap-2",onClick:D=>D.stopPropagation(),children:[l.jsx(ds,{value:T,onChange:D=>I(D.target.value),onKeyDown:D=>B(D,A.threadId),className:"h-6 text-sm",autoFocus:!0}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>O(A.threadId),className:"h-6 w-6 p-0",children:l.jsx(ne.Check,{size:12})}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:V,className:"h-6 w-6 p-0",children:l.jsx(ne.X,{size:12})})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:L(A)}),l.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[l.jsx(ne.Calendar,{size:10}),l.jsx("span",{children:K(A.updatedAt||A.createdAt)})]})]})}),l.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&k!==A.threadId&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:D=>z(A,D),className:"h-6 w-6 p-0",title:"Edit title",children:l.jsx(ne.Edit3,{size:12})}),n&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:D=>$(A.threadId,D),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:l.jsx(ne.Trash2,{size:12})})]})]}),i===A.threadId&&l.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},A.threadId))})})]})}function sr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function xS(e){if(typeof e!="string")return;const t=e.trim();if(t)return t.replace(/\/+$/g,"")}function uh(){const e=[sr("__API_BASE_URL__"),sr("__CHAT_API_BASE_URL__"),sr("__CHAT_API_URL__")];for(const t of e){const n=xS(t);if(n)return n}}function dh(){const e=[sr("__API_AUTH_TOKEN__"),sr("__CHAT_API_KEY__"),sr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function fh(){const e={},t=uh(),n=dh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function hh(){const e=fh(),t=un.getAuthToken(),n=uh();return{apiBaseUrl:e.baseUrl||un.baseUrl||n||"http://localhost:8000",apiKey:t||e.apiKey||dh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const ph="chat-settings";function vS(){try{const e=localStorage.getItem(ph);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function wS(e){try{localStorage.setItem(ph,JSON.stringify(e)),e.apiKey&&un.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function bS(){const e=hh(),t=vS(),n=un.getAuthToken();return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:un.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function yS(e){e.apiKey&&un.setAuthToken(e.apiKey),wS(e)}var SS="Label",mh=p.forwardRef((e,t)=>l.jsx(ye.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())}}));mh.displayName=SS;var gh=mh;const CS=Kr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Dt=p.forwardRef(({className:e,...t},n)=>l.jsx(gh,{ref:n,className:Z(CS(),e),...t}));Dt.displayName=gh.displayName;function xh(e){const t=p.useRef({value:e,previous:e});return p.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var gs="Switch",[TS,XC]=Yt(gs),[ES,kS]=TS(gs),vh=p.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:c="on",onCheckedChange:u,form:d,...f}=e,[h,m]=p.useState(null),w=Pe(t,S=>m(S)),v=p.useRef(!1),g=h?d||!!h.closest("form"):!0,[x,b]=Rn({prop:o,defaultProp:s??!1,onChange:u,caller:gs});return l.jsxs(ES,{scope:n,checked:x,disabled:a,children:[l.jsx(ye.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Sh(x),"data-disabled":a?"":void 0,disabled:a,value:c,...f,ref:w,onClick:ae(e.onClick,S=>{b(k=>!k),g&&(v.current=S.isPropagationStopped(),v.current||S.stopPropagation())})}),g&&l.jsx(yh,{control:h,bubbles:!v.current,name:r,value:c,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});vh.displayName=gs;var wh="SwitchThumb",bh=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=kS(wh,n);return l.jsx(ye.span,{"data-state":Sh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});bh.displayName=wh;var IS="SwitchBubbleInput",yh=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=p.useRef(null),a=Pe(i,s),c=xh(n),u=Rd(t);return p.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(f,"checked").set;if(c!==n&&m){const w=new Event("click",{bubbles:r});m.call(d,n),d.dispatchEvent(w)}},[c,n,r]),l.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});yh.displayName=IS;function Sh(e){return e?"checked":"unchecked"}var Ch=vh,NS=bh;const bn=p.forwardRef(({className:e,...t},n)=>l.jsx(Ch,{className:Z("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:l.jsx(NS,{className:Z("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")})}));bn.displayName=Ch.displayName;var Th=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"}),AS="VisuallyHidden",_S=p.forwardRef((e,t)=>l.jsx(ye.span,{...e,ref:t,style:{...Th,...e.style}}));_S.displayName=AS;var jS=[" ","Enter","ArrowUp","ArrowDown"],RS=[" ","Enter"],zn="Select",[xs,vs,PS]=Wi(zn),[ir,JC]=Yt(zn,[PS,os]),ws=os(),[OS,yn]=ir(zn),[MS,DS]=ir(zn),Eh=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:c,dir:u,name:d,autoComplete:f,disabled:h,required:m,form:w}=e,v=ws(t),[g,x]=p.useState(null),[b,S]=p.useState(null),[k,C]=p.useState(!1),T=Go(u),[I,N]=Rn({prop:r,defaultProp:o??!1,onChange:s,caller:zn}),[_,j]=Rn({prop:i,defaultProp:a,onChange:c,caller:zn}),R=p.useRef(null),$=g?w||!!g.closest("form"):!0,[z,O]=p.useState(new Set),V=Array.from(z).map(B=>B.props.value).join(";");return l.jsx(Hd,{...v,children:l.jsxs(OS,{required:m,scope:t,trigger:g,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Xt(),value:_,onValueChange:j,open:I,onOpenChange:N,dir:T,triggerPointerDownPosRef:R,disabled:h,children:[l.jsx(xs.Provider,{scope:t,children:l.jsx(MS,{scope:e.__scopeSelect,onNativeOptionAdd:p.useCallback(B=>{O(K=>new Set(K).add(B))},[]),onNativeOptionRemove:p.useCallback(B=>{O(K=>{const L=new Set(K);return L.delete(B),L})},[]),children:n})}),$?l.jsxs(Yh,{"aria-hidden":!0,required:m,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:B=>j(B.target.value),disabled:h,form:w,children:[_===void 0?l.jsx("option",{value:""}):null,Array.from(z)]},V):null]})})};Eh.displayName=zn;var kh="SelectTrigger",Ih=p.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ws(n),i=yn(kh,n),a=i.disabled||r,c=Pe(t,i.onTriggerChange),u=vs(n),d=p.useRef("touch"),[f,h,m]=Jh(v=>{const g=u().filter(S=>!S.disabled),x=g.find(S=>S.value===i.value),b=Zh(g,v,x);b!==void 0&&i.onValueChange(b.value)}),w=v=>{a||(i.onOpenChange(!0),m()),v&&(i.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return l.jsx(Ud,{asChild:!0,...s,children:l.jsx(ye.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":Xh(i.value)?"":void 0,...o,ref:c,onClick:ae(o.onClick,v=>{v.currentTarget.focus(),d.current!=="mouse"&&w(v)}),onPointerDown:ae(o.onPointerDown,v=>{d.current=v.pointerType;const g=v.target;g.hasPointerCapture(v.pointerId)&&g.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(w(v),v.preventDefault())}),onKeyDown:ae(o.onKeyDown,v=>{const g=f.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&h(v.key),!(g&&v.key===" ")&&jS.includes(v.key)&&(w(),v.preventDefault())})})})});Ih.displayName=kh;var Nh="SelectValue",Ah=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,c=yn(Nh,n),{onValueNodeHasChildrenChange:u}=c,d=s!==void 0,f=Pe(t,c.onValueNodeChange);return ct(()=>{u(d)},[u,d]),l.jsx(ye.span,{...a,ref:f,style:{pointerEvents:"none"},children:Xh(c.value)?l.jsx(l.Fragment,{children:i}):s})});Ah.displayName=Nh;var LS="SelectIcon",_h=p.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return l.jsx(ye.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});_h.displayName=LS;var $S="SelectPortal",jh=e=>l.jsx(Ro,{asChild:!0,...e});jh.displayName=$S;var Bn="SelectContent",Rh=p.forwardRef((e,t)=>{const n=yn(Bn,e.__scopeSelect),[r,o]=p.useState();if(ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?qr.createPortal(l.jsx(Ph,{scope:e.__scopeSelect,children:l.jsx(xs.Slot,{scope:e.__scopeSelect,children:l.jsx("div",{children:e.children})})}),s):null}return l.jsx(Oh,{...e,ref:t})});Rh.displayName=Bn;var Wt=10,[Ph,Sn]=ir(Bn),FS="SelectContentImpl",zS=Tn.createSlot("SelectContent.RemoveScroll"),Oh=p.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:c,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:m,sticky:w,hideWhenDetached:v,avoidCollisions:g,...x}=e,b=yn(Bn,n),[S,k]=p.useState(null),[C,T]=p.useState(null),I=Pe(t,W=>k(W)),[N,_]=p.useState(null),[j,R]=p.useState(null),$=vs(n),[z,O]=p.useState(!1),V=p.useRef(!1);p.useEffect(()=>{if(S)return $i(S)},[S]),Ri();const B=p.useCallback(W=>{const[M,...G]=$().map(ce=>ce.ref.current),[te]=G.slice(-1),de=document.activeElement;for(const ce of W)if(ce===de||(ce==null||ce.scrollIntoView({block:"nearest"}),ce===M&&C&&(C.scrollTop=0),ce===te&&C&&(C.scrollTop=C.scrollHeight),ce==null||ce.focus(),document.activeElement!==de))return},[$,C]),K=p.useCallback(()=>B([N,S]),[B,N,S]);p.useEffect(()=>{z&&K()},[z,K]);const{onOpenChange:L,triggerPointerDownPosRef:A}=b;p.useEffect(()=>{if(S){let W={x:0,y:0};const M=te=>{var de,ce;W={x:Math.abs(Math.round(te.pageX)-(((de=A.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(te.pageY)-(((ce=A.current)==null?void 0:ce.y)??0))}},G=te=>{W.x<=10&&W.y<=10?te.preventDefault():S.contains(te.target)||L(!1),document.removeEventListener("pointermove",M),A.current=null};return A.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",G,{capture:!0})}}},[S,L,A]),p.useEffect(()=>{const W=()=>L(!1);return window.addEventListener("blur",W),window.addEventListener("resize",W),()=>{window.removeEventListener("blur",W),window.removeEventListener("resize",W)}},[L]);const[D,H]=Jh(W=>{const M=$().filter(de=>!de.disabled),G=M.find(de=>de.ref.current===document.activeElement),te=Zh(M,W,G);te&&setTimeout(()=>te.ref.current.focus())}),Y=p.useCallback((W,M,G)=>{const te=!V.current&&!G;(b.value!==void 0&&b.value===M||te)&&(_(W),te&&(V.current=!0))},[b.value]),Q=p.useCallback(()=>S==null?void 0:S.focus(),[S]),le=p.useCallback((W,M,G)=>{const te=!V.current&&!G;(b.value!==void 0&&b.value===M||te)&&R(W)},[b.value]),xe=r==="popper"?Sa:Mh,Ee=xe===Sa?{side:a,sideOffset:c,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:m,sticky:w,hideWhenDetached:v,avoidCollisions:g}:{};return l.jsx(Ph,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:Y,selectedItem:N,onItemLeave:Q,itemTextRefCallback:le,focusSelectedItem:K,selectedItemText:j,position:r,isPositioned:z,searchRef:D,children:l.jsx($o,{as:zS,allowPinchZoom:!0,children:l.jsx(jo,{asChild:!0,trapped:b.open,onMountAutoFocus:W=>{W.preventDefault()},onUnmountAutoFocus:ae(o,W=>{var M;(M=b.trigger)==null||M.focus({preventScroll:!0}),W.preventDefault()}),children:l.jsx(_o,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:W=>W.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:l.jsx(xe,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:W=>W.preventDefault(),...x,...Ee,onPlaced:()=>O(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ae(x.onKeyDown,W=>{const M=W.ctrlKey||W.altKey||W.metaKey;if(W.key==="Tab"&&W.preventDefault(),!M&&W.key.length===1&&H(W.key),["ArrowUp","ArrowDown","Home","End"].includes(W.key)){let te=$().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(W.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(W.key)){const de=W.target,ce=te.indexOf(de);te=te.slice(ce+1)}setTimeout(()=>B(te)),W.preventDefault()}})})})})})})});Oh.displayName=FS;var BS="SelectItemAlignedPosition",Mh=p.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=yn(Bn,n),i=Sn(Bn,n),[a,c]=p.useState(null),[u,d]=p.useState(null),f=Pe(t,I=>d(I)),h=vs(n),m=p.useRef(!1),w=p.useRef(!0),{viewport:v,selectedItem:g,selectedItemText:x,focusSelectedItem:b}=i,S=p.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&v&&g&&x){const I=s.trigger.getBoundingClientRect(),N=u.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),j=x.getBoundingClientRect();if(s.dir!=="rtl"){const de=j.left-N.left,ce=_.left-de,$e=I.left-ce,Ge=I.width+$e,_e=Math.max(Ge,N.width),Re=window.innerWidth-Wt,We=ga(ce,[Wt,Math.max(Wt,Re-_e)]);a.style.minWidth=Ge+"px",a.style.left=We+"px"}else{const de=N.right-j.right,ce=window.innerWidth-_.right-de,$e=window.innerWidth-I.right-ce,Ge=I.width+$e,_e=Math.max(Ge,N.width),Re=window.innerWidth-Wt,We=ga(ce,[Wt,Math.max(Wt,Re-_e)]);a.style.minWidth=Ge+"px",a.style.right=We+"px"}const R=h(),$=window.innerHeight-Wt*2,z=v.scrollHeight,O=window.getComputedStyle(u),V=parseInt(O.borderTopWidth,10),B=parseInt(O.paddingTop,10),K=parseInt(O.borderBottomWidth,10),L=parseInt(O.paddingBottom,10),A=V+B+z+L+K,D=Math.min(g.offsetHeight*5,A),H=window.getComputedStyle(v),Y=parseInt(H.paddingTop,10),Q=parseInt(H.paddingBottom,10),le=I.top+I.height/2-Wt,xe=$-le,Ee=g.offsetHeight/2,W=g.offsetTop+Ee,M=V+B+W,G=A-M;if(M<=le){const de=R.length>0&&g===R[R.length-1].ref.current;a.style.bottom="0px";const ce=u.clientHeight-v.offsetTop-v.offsetHeight,$e=Math.max(xe,Ee+(de?Q:0)+ce+K),Ge=M+$e;a.style.height=Ge+"px"}else{const de=R.length>0&&g===R[0].ref.current;a.style.top="0px";const $e=Math.max(le,V+v.offsetTop+(de?Y:0)+Ee)+G;a.style.height=$e+"px",v.scrollTop=M-le+v.offsetTop}a.style.margin=`${Wt}px 0`,a.style.minHeight=D+"px",a.style.maxHeight=$+"px",r==null||r(),requestAnimationFrame(()=>m.current=!0)}},[h,s.trigger,s.valueNode,a,u,v,g,x,s.dir,r]);ct(()=>S(),[S]);const[k,C]=p.useState();ct(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const T=p.useCallback(I=>{I&&w.current===!0&&(S(),b==null||b(),w.current=!1)},[S,b]);return l.jsx(US,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:m,onScrollButtonChange:T,children:l.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:l.jsx(ye.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Mh.displayName=BS;var HS="SelectPopperPosition",Sa=p.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Wt,...s}=e,i=ws(n);return l.jsx(Wd,{...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)"}})});Sa.displayName=HS;var[US,Ca]=ir(Bn,{}),Ta="SelectViewport",Dh=p.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Sn(Ta,n),i=Ca(Ta,n),a=Pe(t,s.onViewportChange),c=p.useRef(0);return l.jsxs(l.Fragment,{children:[l.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}),l.jsx(xs.Slot,{scope:n,children:l.jsx(ye.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ae(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const m=Math.abs(c.current-d.scrollTop);if(m>0){const w=window.innerHeight-Wt*2,v=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),x=Math.max(v,g);if(x<w){const b=x+m,S=Math.min(w,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}c.current=d.scrollTop})})})]})});Dh.displayName=Ta;var Lh="SelectGroup",[WS,VS]=ir(Lh),KS=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Xt();return l.jsx(WS,{scope:n,id:o,children:l.jsx(ye.div,{role:"group","aria-labelledby":o,...r,ref:t})})});KS.displayName=Lh;var $h="SelectLabel",Fh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=VS($h,n);return l.jsx(ye.div,{id:o.id,...r,ref:t})});Fh.displayName=$h;var bs="SelectItem",[qS,zh]=ir(bs),Bh=p.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=yn(bs,n),c=Sn(bs,n),u=a.value===r,[d,f]=p.useState(s??""),[h,m]=p.useState(!1),w=Pe(t,b=>{var S;return(S=c.itemRefCallback)==null?void 0:S.call(c,b,r,o)}),v=Xt(),g=p.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 l.jsx(qS,{scope:n,value:r,disabled:o,textId:v,isSelected:u,onItemTextChange:p.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:l.jsx(xs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:l.jsx(ye.div,{role:"option","aria-labelledby":v,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:w,onFocus:ae(i.onFocus,()=>m(!0)),onBlur:ae(i.onBlur,()=>m(!1)),onClick:ae(i.onClick,()=>{g.current!=="mouse"&&x()}),onPointerUp:ae(i.onPointerUp,()=>{g.current==="mouse"&&x()}),onPointerDown:ae(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:ae(i.onPointerMove,b=>{var S;g.current=b.pointerType,o?(S=c.onItemLeave)==null||S.call(c):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ae(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=c.onItemLeave)==null||S.call(c))}),onKeyDown:ae(i.onKeyDown,b=>{var k;((k=c.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(RS.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});Bh.displayName=bs;var zr="SelectItemText",Hh=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=yn(zr,n),a=Sn(zr,n),c=zh(zr,n),u=DS(zr,n),[d,f]=p.useState(null),h=Pe(t,x=>f(x),c.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,c.value,c.disabled)}),m=d==null?void 0:d.textContent,w=p.useMemo(()=>l.jsx("option",{value:c.value,disabled:c.disabled,children:m},c.value),[c.disabled,c.value,m]),{onNativeOptionAdd:v,onNativeOptionRemove:g}=u;return ct(()=>(v(w),()=>g(w)),[v,g,w]),l.jsxs(l.Fragment,{children:[l.jsx(ye.span,{id:c.textId,...s,ref:h}),c.isSelected&&i.valueNode&&!i.valueNodeHasChildren?qr.createPortal(s.children,i.valueNode):null]})});Hh.displayName=zr;var Uh="SelectItemIndicator",Wh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return zh(Uh,n).isSelected?l.jsx(ye.span,{"aria-hidden":!0,...r,ref:t}):null});Wh.displayName=Uh;var Ea="SelectScrollUpButton",Vh=p.forwardRef((e,t)=>{const n=Sn(Ea,e.__scopeSelect),r=Ca(Ea,e.__scopeSelect),[o,s]=p.useState(!1),i=Pe(t,r.onScrollButtonChange);return ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=c.scrollTop>0;s(u)};const c=n.viewport;return a(),c.addEventListener("scroll",a),()=>c.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?l.jsx(qh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop-c.offsetHeight)}}):null});Vh.displayName=Ea;var ka="SelectScrollDownButton",Kh=p.forwardRef((e,t)=>{const n=Sn(ka,e.__scopeSelect),r=Ca(ka,e.__scopeSelect),[o,s]=p.useState(!1),i=Pe(t,r.onScrollButtonChange);return ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=c.scrollHeight-c.clientHeight,d=Math.ceil(c.scrollTop)<u;s(d)};const c=n.viewport;return a(),c.addEventListener("scroll",a),()=>c.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?l.jsx(qh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop+c.offsetHeight)}}):null});Kh.displayName=ka;var qh=p.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Sn("SelectScrollButton",n),i=p.useRef(null),a=vs(n),c=p.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return p.useEffect(()=>()=>c(),[c]),ct(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),l.jsx(ye.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ae(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ae(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ae(o.onPointerLeave,()=>{c()})})}),GS="SelectSeparator",Gh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return l.jsx(ye.div,{"aria-hidden":!0,...r,ref:t})});Gh.displayName=GS;var Ia="SelectArrow",YS=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ws(n),s=yn(Ia,n),i=Sn(Ia,n);return s.open&&i.position==="popper"?l.jsx(Vd,{...o,...r,ref:t}):null});YS.displayName=Ia;var XS="SelectBubbleInput",Yh=p.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=p.useRef(null),s=Pe(r,o),i=xh(t);return p.useEffect(()=>{const a=o.current;if(!a)return;const c=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(c,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),l.jsx(ye.select,{...n,style:{...Th,...n.style},ref:s,defaultValue:t})});Yh.displayName=XS;function Xh(e){return e===""||e===void 0}function Jh(e){const t=ut(e),n=p.useRef(""),r=p.useRef(0),o=p.useCallback(i=>{const a=n.current+i;t(a),function c(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>c(""),1e3))}(a)},[t]),s=p.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return p.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Zh(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=JS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const c=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return c!==n?c:void 0}function JS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ZS=Eh,Qh=Ih,QS=Ah,eC=_h,tC=jh,ep=Rh,nC=Dh,tp=Fh,np=Bh,rC=Hh,oC=Wh,rp=Vh,op=Kh,sp=Gh;const ip=ZS,ap=QS,Na=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Qh,{ref:r,className:Z("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,l.jsx(eC,{asChild:!0,children:l.jsx(ne.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Na.displayName=Qh.displayName;const lp=p.forwardRef(({className:e,...t},n)=>l.jsx(rp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(ne.ChevronUp,{className:"h-4 w-4"})}));lp.displayName=rp.displayName;const cp=p.forwardRef(({className:e,...t},n)=>l.jsx(op,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(ne.ChevronDown,{className:"h-4 w-4"})}));cp.displayName=op.displayName;const Aa=p.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>l.jsx(tC,{children:l.jsxs(ep,{ref:o,className:Z("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:[l.jsx(lp,{}),l.jsx(nC,{className:Z("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),l.jsx(cp,{})]})}));Aa.displayName=ep.displayName;const sC=p.forwardRef(({className:e,...t},n)=>l.jsx(tp,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));sC.displayName=tp.displayName;const Hn=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(np,{ref:r,className:Z("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:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(oC,{children:l.jsx(ne.Check,{className:"h-4 w-4"})})}),l.jsx(rC,{children:t})]}));Hn.displayName=np.displayName;const iC=p.forwardRef(({className:e,...t},n)=>l.jsx(sp,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));iC.displayName=sp.displayName;var aC="Separator",up="horizontal",lC=["horizontal","vertical"],dp=p.forwardRef((e,t)=>{const{decorative:n,orientation:r=up,...o}=e,s=cC(r)?r:up,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return l.jsx(ye.div,{"data-orientation":s,...a,...o,ref:t})});dp.displayName=aC;function cC(e){return lC.includes(e)}var fp=dp;const hp=p.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>l.jsx(fp,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));hp.displayName=fp.displayName;const uC=Ju,dC=Ww,fC=Zu,pp=p.forwardRef(({className:e,...t},n)=>l.jsx(Uo,{className:Z("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}));pp.displayName=Uo.displayName;const hC=Kr.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"}}),mp=p.forwardRef(({side:e="right",className:t,children:n,...r},o)=>l.jsxs(fC,{children:[l.jsx(pp,{}),l.jsxs(Wo,{ref:o,className:Z(hC({side:e}),t),...r,children:[n,l.jsxs(Qu,{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:[l.jsx(ne.X,{className:"h-4 w-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));mp.displayName=Wo.displayName;const gp=({className:e,...t})=>l.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});gp.displayName="SheetHeader";const xp=p.forwardRef(({className:e,...t},n)=>l.jsx(Mn,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));xp.displayName=Mn.displayName;const vp=p.forwardRef(({className:e,...t},n)=>l.jsx(Vo,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));vp.displayName=Vo.displayName;const pC={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 mC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=y.useState(!1),[s,i]=y.useState(!1),[a,c]=y.useState(e),[u,d]=y.useState(!1),{toast:f}=Ii();y.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),y.useEffect(()=>{c(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},m=()=>{c(pC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{c(e),d(!1),o(!1)},v=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 l.jsxs(uC,{open:r,onOpenChange:o,children:[l.jsx(dC,{asChild:!0,children:l.jsxs(ze,{variant:"outline",size:"sm",className:n,children:[l.jsx(ne.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&l.jsx(xi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),l.jsxs(mp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[l.jsxs(gp,{children:[l.jsx(xp,{children:"Chat Settings"}),l.jsx(vp,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),l.jsxs("div",{className:"space-y-6 py-6",children:[l.jsxs(kr,{children:[l.jsx(Ir,{className:"pb-3",children:l.jsxs(Nr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.Server,{className:"h-5 w-5"}),"API Configuration"]})}),l.jsxs(Co,{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx(Dt,{htmlFor:"api-url",children:"API Base URL"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ds,{id:"api-url",value:a.api.baseUrl,onChange:g=>c(x=>({...x,api:{...x.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),l.jsx(ze,{variant:"outline",onClick:v,children:"Test"})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(Dt,{htmlFor:"enable-auth",children:"Enable Authentication"}),l.jsx(bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>c(x=>({...x,api:{...x.api,enableAuth:g}}))})]}),a.api.enableAuth&&l.jsxs("div",{className:"space-y-2",children:[l.jsx(Dt,{htmlFor:"auth-token",children:"Authentication Token"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ds,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>c(x=>({...x,api:{...x.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),l.jsx(ze,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?l.jsx(ne.EyeOff,{className:"h-4 w-4"}):l.jsx(ne.Eye,{className:"h-4 w-4"})})]})]})]})]}),l.jsxs(kr,{children:[l.jsx(Ir,{className:"pb-3",children:l.jsxs(Nr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),l.jsxs(Co,{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx(Dt,{htmlFor:"layout",children:"Layout Style"}),l.jsxs(ip,{value:a.ui.layout,onValueChange:g=>c(x=>({...x,ui:{...x.ui,layout:g}})),children:[l.jsx(Na,{children:l.jsx(ap,{})}),l.jsxs(Aa,{children:[l.jsx(Hn,{value:"sidebar",children:"Sidebar Layout"}),l.jsx(Hn,{value:"fullscreen",children:"Fullscreen"}),l.jsx(Hn,{value:"tabs",children:"Tabbed Interface"})]})]})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(Dt,{htmlFor:"theme",children:"Theme"}),l.jsxs(ip,{value:a.ui.theme,onValueChange:g=>c(x=>({...x,ui:{...x.ui,theme:g}})),children:[l.jsx(Na,{children:l.jsx(ap,{})}),l.jsxs(Aa,{children:[l.jsx(Hn,{value:"light",children:"Light"}),l.jsx(Hn,{value:"dark",children:"Dark"}),l.jsx(Hn,{value:"system",children:"System"})]})]})]}),l.jsx(hp,{}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(Dt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),l.jsx(bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>c(x=>({...x,ui:{...x.ui,showTimestamps:g}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(Dt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),l.jsx(bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>c(x=>({...x,ui:{...x.ui,showAgentNames:g}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(Dt,{htmlFor:"compact-messages",children:"Compact Messages"}),l.jsx(bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>c(x=>({...x,ui:{...x.ui,compactMessages:g}}))})]})]})]})]}),l.jsxs(kr,{children:[l.jsx(Ir,{className:"pb-3",children:l.jsxs(Nr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),l.jsxs(Co,{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx(Dt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),l.jsx(bn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>c(x=>({...x,behavior:{...x.behavior,autoSave:g}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx(Dt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),l.jsx(bn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>c(x=>({...x,behavior:{...x.behavior,enableStreaming:g}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx(Dt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),l.jsx(bn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>c(x=>({...x,behavior:{...x.behavior,showTypingIndicator:g}}))})]})]})]})]}),l.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[l.jsxs(ze,{variant:"outline",onClick:m,children:[l.jsx(ne.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ze,{variant:"outline",onClick:w,children:"Cancel"}),l.jsxs(ze,{onClick:h,disabled:!u,children:[l.jsx(ne.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function gC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){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=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),c=y.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?l.jsx(io,{...s,onThreadChange:c,children:l.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:l.jsx(us,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?l.jsx(io,{...s,onThreadChange:c,children:l.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:l.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&l.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:l.jsx(ya,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),l.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:l.jsx(us,{onError:s.onError,enableFileUpload:!0})})]})})}):l.jsx(io,{...s,onThreadChange:c,children:l.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&l.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:l.jsx(ya,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),l.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:l.jsx(us,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=_l,Ce.ChatInterface=us,Ce.ChatProviders=io,Ce.ChatSettings=mC,Ce.MarkdownContent=Ti,Ce.MessageComponent=ld,Ce.MessageList=Ui,Ce.ThreadManager=ya,Ce.applySettings=yS,Ce.chatApiClient=un,Ce.default=gC,Ce.del=Al,Ce.get=Ct,Ce.getChatToken=kl,Ce.getCurrentSettings=bS,Ce.getDefaultApiConfig=fh,Ce.getDefaultChatSettings=hh,Ce.onChatTokenChanged=Il,Ce.post=Us,Ce.put=Nl,Ce.setChatToken=Hs,Ce.useApi=so,Ce.useChatStream=zl,Ce.useMessages=qs,Ce.useMessagesReducer=Ll,Ce.useStream=Ol,Ce.useThreads=mr,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
139
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function lb(e,t=qo){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 cb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),lb(t),ab(t)}function Wi(e){const t=e+"CollectionProvider",[n,r]=Yt(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:g,children:x}=v,b=y.useRef(null),S=y.useRef(new Map).current;return l.jsx(o,{scope:g,itemMap:S,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",c=Tn.createSlot(a),u=y.forwardRef((v,g)=>{const{scope:x,children:b}=v,S=s(a,x),k=Pe(g,S.collectionRef);return l.jsx(c,{ref:k,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Tn.createSlot(d),m=y.forwardRef((v,g)=>{const{scope:x,children:b,...S}=v,k=y.useRef(null),C=Pe(g,k),T=s(d,x);return y.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),l.jsx(h,{[f]:"",ref:C,children:b})});m.displayName=d;function w(v){const g=s(e+"CollectionConsumer",v);return y.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:m},w,r]}var ub=p.createContext(void 0);function Go(e){const t=p.useContext(ub);return e||t||"ltr"}const db=["top","right","bottom","left"],vn=Math.min,Nt=Math.max,Yo=Math.round,Xo=Math.floor,Zt=e=>({x:e,y:e}),fb={left:"right",right:"left",bottom:"top",top:"bottom"},hb={start:"end",end:"start"};function Vi(e,t,n){return Nt(e,vn(t,n))}function sn(e,t){return typeof e=="function"?e(t):e}function an(e){return e.split("-")[0]}function er(e){return e.split("-")[1]}function Ki(e){return e==="x"?"y":"x"}function qi(e){return e==="y"?"height":"width"}const pb=new Set(["top","bottom"]);function Qt(e){return pb.has(an(e))?"y":"x"}function Gi(e){return Ki(Qt(e))}function mb(e,t,n){n===void 0&&(n=!1);const r=er(e),o=Gi(e),s=qi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Jo(i)),[i,Jo(i)]}function gb(e){const t=Jo(e);return[Yi(e),t,Yi(t)]}function Yi(e){return e.replace(/start|end/g,t=>hb[t])}const ud=["left","right"],dd=["right","left"],xb=["top","bottom"],vb=["bottom","top"];function wb(e,t,n){switch(e){case"top":case"bottom":return n?t?dd:ud:t?ud:dd;case"left":case"right":return t?xb:vb;default:return[]}}function bb(e,t,n,r){const o=er(e);let s=wb(an(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Yi)))),s}function Jo(e){return e.replace(/left|right|bottom|top/g,t=>fb[t])}function yb(e){return{top:0,right:0,bottom:0,left:0,...e}}function fd(e){return typeof e!="number"?yb(e):{top:e,right:e,bottom:e,left:e}}function Zo(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 hd(e,t,n){let{reference:r,floating:o}=e;const s=Qt(t),i=Gi(t),a=qi(i),c=an(t),u=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 m;switch(c){case"top":m={x:d,y:r.y-o.height};break;case"bottom":m={x:d,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:f};break;case"left":m={x:r.x-o.width,y:f};break;default:m={x:r.x,y:r.y}}switch(er(t)){case"start":m[i]-=h*(n&&u?-1:1);break;case"end":m[i]+=h*(n&&u?-1:1);break}return m}const Sb=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=hd(u,r,c),h=r,m={},w=0;for(let v=0;v<a.length;v++){const{name:g,fn:x}=a[v],{x:b,y:S,data:k,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:m,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,m={...m,[g]:{...m[g],...k}},C&&w<=50&&(w++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(u=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=hd(u,h,c)),v=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:m}};async function jr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:m=0}=sn(t,e),w=fd(m),g=a[h?f==="floating"?"reference":"floating":f],x=Zo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:c})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Zo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:c}):b);return{top:(x.top-C.top+w.top)/k.y,bottom:(C.bottom-x.bottom+w.bottom)/k.y,left:(x.left-C.left+w.left)/k.x,right:(C.right-x.right+w.right)/k.x}}const Cb=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:c}=t,{element:u,padding:d=0}=sn(e,t)||{};if(u==null)return{};const f=fd(d),h={x:n,y:r},m=Gi(o),w=qi(m),v=await i.getDimensions(u),g=m==="y",x=g?"top":"left",b=g?"bottom":"right",S=g?"clientHeight":"clientWidth",k=s.reference[w]+s.reference[m]-h[m]-s.floating[w],C=h[m]-s.reference[m],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[w]);const N=k/2-C/2,_=I/2-v[w]/2-1,R=vn(f[x],_),j=vn(f[b],_),$=R,z=I-v[w]-j,O=I/2-v[w]/2+N,V=Vi($,O,z),B=!c.arrow&&er(o)!=null&&O!==V&&s.reference[w]/2-(O<$?R:j)-v[w]/2<0,K=B?O<$?O-$:O-z:0;return{[m]:h[m]+K,data:{[m]:V,centerOffset:O-V-K,...B&&{alignmentOffset:K}},reset:B}}}),Tb=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:c,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...g}=sn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=an(o),b=Qt(a),S=an(a)===a,k=await(c.isRTL==null?void 0:c.isRTL(u.floating)),C=h||(S||!v?[Jo(a)]:gb(a)),T=w!=="none";!h&&T&&C.push(...bb(a,v,w,k));const I=[a,...C],N=await jr(t,g),_=[];let R=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[x]),f){const O=mb(o,i,k);_.push(N[O[0]],N[O[1]])}if(R=[...R,{placement:o,overflows:_}],!_.every(O=>O<=0)){var j,$;const O=(((j=s.flip)==null?void 0:j.index)||0)+1,V=I[O];if(V&&(!(f==="alignment"?b!==Qt(V):!1)||R.every(L=>Qt(L.placement)===b?L.overflows[0]>0:!0)))return{data:{index:O,overflows:R},reset:{placement:V}};let B=($=R.filter(K=>K.overflows[0]<=0).sort((K,L)=>K.overflows[1]-L.overflows[1])[0])==null?void 0:$.placement;if(!B)switch(m){case"bestFit":{var z;const K=(z=R.filter(L=>{if(T){const A=Qt(L.placement);return A===b||A==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(A=>A>0).reduce((A,D)=>A+D,0)]).sort((L,A)=>L[1]-A[1])[0])==null?void 0:z[0];K&&(B=K);break}case"initialPlacement":B=a;break}if(o!==B)return{reset:{placement:B}}}return{}}}};function pd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function md(e){return db.some(t=>e[t]>=0)}const Eb=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=sn(e,t);switch(r){case"referenceHidden":{const s=await jr(t,{...o,elementContext:"reference"}),i=pd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:md(i)}}}case"escaped":{const s=await jr(t,{...o,altBoundary:!0}),i=pd(s,n.floating);return{data:{escapedOffsets:i,escaped:md(i)}}}default:return{}}}}},gd=new Set(["left","top"]);async function kb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=an(n),a=er(n),c=Qt(n)==="y",u=gd.has(i)?-1:1,d=s&&c?-1:1,f=sn(t,e);let{mainAxis:h,crossAxis:m,alignmentAxis:w}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof w=="number"&&(m=a==="end"?w*-1:w),c?{x:m*d,y:h*u}:{x:h*u,y:m*d}}const Ib=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,c=await kb(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:i}}}}},Nb=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:g=>{let{x,y:b}=g;return{x,y:b}}},...c}=sn(e,t),u={x:n,y:r},d=await jr(t,c),f=Qt(an(o)),h=Ki(f);let m=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=m+d[g],S=m-d[x];m=Vi(b,m,S)}if(i){const g=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=w+d[g],S=w-d[x];w=Vi(b,w,S)}const v=a.fn({...t,[h]:m,[f]:w});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[h]:s,[f]:i}}}}}},Ab=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:c=!0,crossAxis:u=!0}=sn(e,t),d={x:n,y:r},f=Qt(o),h=Ki(f);let m=d[h],w=d[f];const v=sn(a,t),g=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(c){const S=h==="y"?"height":"width",k=s.reference[h]-s.floating[S]+g.mainAxis,C=s.reference[h]+s.reference[S]-g.mainAxis;m<k?m=k:m>C&&(m=C)}if(u){var x,b;const S=h==="y"?"width":"height",k=gd.has(an(o)),C=s.reference[f]-s.floating[S]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:g.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?g.crossAxis:0);w<C?w=C:w>T&&(w=T)}return{[h]:m,[f]:w}}}},_b=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:c=()=>{},...u}=sn(e,t),d=await jr(t,u),f=an(o),h=er(o),m=Qt(o)==="y",{width:w,height:v}=s.floating;let g,x;f==="top"||f==="bottom"?(g=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,g=h==="end"?"top":"bottom");const b=v-d.top-d.bottom,S=w-d.left-d.right,k=vn(v-d[g],b),C=vn(w-d[x],S),T=!t.middlewareData.shift;let I=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!h){const R=Nt(d.left,0),j=Nt(d.right,0),$=Nt(d.top,0),z=Nt(d.bottom,0);m?N=w-2*(R!==0||j!==0?R+j:Nt(d.left,d.right)):I=v-2*($!==0||z!==0?$+z:Nt(d.top,d.bottom))}await c({...t,availableWidth:N,availableHeight:I});const _=await i.getDimensions(a.floating);return w!==_.width||v!==_.height?{reset:{rects:!0}}:{}}}};function Qo(){return typeof window<"u"}function tr(e){return xd(e)?(e.nodeName||"").toLowerCase():"#document"}function At(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function en(e){var t;return(t=(xd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function xd(e){return Qo()?e instanceof Node||e instanceof At(e).Node:!1}function Ht(e){return Qo()?e instanceof Element||e instanceof At(e).Element:!1}function tn(e){return Qo()?e instanceof HTMLElement||e instanceof At(e).HTMLElement:!1}function vd(e){return!Qo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof At(e).ShadowRoot}const jb=new Set(["inline","contents"]);function Rr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Ut(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!jb.has(o)}const Rb=new Set(["table","td","th"]);function Pb(e){return Rb.has(tr(e))}const Ob=[":popover-open",":modal"];function es(e){return Ob.some(t=>{try{return e.matches(t)}catch{return!1}})}const Mb=["transform","translate","scale","rotate","perspective"],Db=["transform","translate","scale","rotate","perspective","filter"],Lb=["paint","layout","strict","content"];function Xi(e){const t=Ji(),n=Ht(e)?Ut(e):e;return Mb.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)||Db.some(r=>(n.willChange||"").includes(r))||Lb.some(r=>(n.contain||"").includes(r))}function $b(e){let t=wn(e);for(;tn(t)&&!nr(t);){if(Xi(t))return t;if(es(t))return null;t=wn(t)}return null}function Ji(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Fb=new Set(["html","body","#document"]);function nr(e){return Fb.has(tr(e))}function Ut(e){return At(e).getComputedStyle(e)}function ts(e){return Ht(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function wn(e){if(tr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||vd(e)&&e.host||en(e);return vd(t)?t.host:t}function wd(e){const t=wn(e);return nr(t)?e.ownerDocument?e.ownerDocument.body:e.body:tn(t)&&Rr(t)?t:wd(t)}function Pr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=wd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=At(o);if(s){const a=Zi(i);return t.concat(i,i.visualViewport||[],Rr(o)?o:[],a&&n?Pr(a):[])}return t.concat(o,Pr(o,[],n))}function Zi(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function bd(e){const t=Ut(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=tn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Yo(n)!==s||Yo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Qi(e){return Ht(e)?e:e.contextElement}function rr(e){const t=Qi(e);if(!tn(t))return Zt(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=bd(t);let i=(s?Yo(n.width):n.width)/r,a=(s?Yo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const zb=Zt(0);function yd(e){const t=At(e);return!Ji()||!t.visualViewport?zb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Bb(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==At(e)?!1:t}function Ln(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Qi(e);let i=Zt(1);t&&(r?Ht(r)&&(i=rr(r)):i=rr(e));const a=Bb(s,n,r)?yd(s):Zt(0);let c=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=At(s),m=r&&Ht(r)?At(r):r;let w=h,v=Zi(w);for(;v&&r&&m!==w;){const g=rr(v),x=v.getBoundingClientRect(),b=Ut(v),S=x.left+(v.clientLeft+parseFloat(b.paddingLeft))*g.x,k=x.top+(v.clientTop+parseFloat(b.paddingTop))*g.y;c*=g.x,u*=g.y,d*=g.x,f*=g.y,c+=S,u+=k,w=At(v),v=Zi(w)}}return Zo({width:d,height:f,x:c,y:u})}function ea(e,t){const n=ts(e).scrollLeft;return t?t.left+n:Ln(en(e)).left+n}function Sd(e,t,n){n===void 0&&(n=!1);const r=e.getBoundingClientRect(),o=r.left+t.scrollLeft-(n?0:ea(e,r)),s=r.top+t.scrollTop;return{x:o,y:s}}function Hb(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=en(r),a=t?es(t.floating):!1;if(r===i||a&&s)return n;let c={scrollLeft:0,scrollTop:0},u=Zt(1);const d=Zt(0),f=tn(r);if((f||!f&&!s)&&((tr(r)!=="body"||Rr(i))&&(c=ts(r)),tn(r))){const m=Ln(r);u=rr(r),d.x=m.x+r.clientLeft,d.y=m.y+r.clientTop}const h=i&&!f&&!s?Sd(i,c,!0):Zt(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-c.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-c.scrollTop*u.y+d.y+h.y}}function Ub(e){return Array.from(e.getClientRects())}function Wb(e){const t=en(e),n=ts(e),r=e.ownerDocument.body,o=Nt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Nt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ea(e);const a=-n.scrollTop;return Ut(r).direction==="rtl"&&(i+=Nt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function Vb(e,t){const n=At(e),r=en(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,c=0;if(o){s=o.width,i=o.height;const u=Ji();(!u||u&&t==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}return{width:s,height:i,x:a,y:c}}const Kb=new Set(["absolute","fixed"]);function qb(e,t){const n=Ln(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=tn(e)?rr(e):Zt(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,c=o*s.x,u=r*s.y;return{width:i,height:a,x:c,y:u}}function Cd(e,t,n){let r;if(t==="viewport")r=Vb(e,n);else if(t==="document")r=Wb(en(e));else if(Ht(t))r=qb(t,n);else{const o=yd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Zo(r)}function Td(e,t){const n=wn(e);return n===t||!Ht(n)||nr(n)?!1:Ut(n).position==="fixed"||Td(n,t)}function Gb(e,t){const n=t.get(e);if(n)return n;let r=Pr(e,[],!1).filter(a=>Ht(a)&&tr(a)!=="body"),o=null;const s=Ut(e).position==="fixed";let i=s?wn(e):e;for(;Ht(i)&&!nr(i);){const a=Ut(i),c=Xi(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&Kb.has(o.position)||Rr(i)&&!c&&Td(e,i))?r=r.filter(d=>d!==i):o=a,i=wn(i)}return t.set(e,r),r}function Yb(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?es(t)?[]:Gb(t,this._c):[].concat(n),r],a=i[0],c=i.reduce((u,d)=>{const f=Cd(t,d,o);return u.top=Nt(f.top,u.top),u.right=vn(f.right,u.right),u.bottom=vn(f.bottom,u.bottom),u.left=Nt(f.left,u.left),u},Cd(t,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Xb(e){const{width:t,height:n}=bd(e);return{width:t,height:n}}function Jb(e,t,n){const r=tn(t),o=en(t),s=n==="fixed",i=Ln(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const c=Zt(0);function u(){c.x=ea(o)}if(r||!r&&!s)if((tr(t)!=="body"||Rr(o))&&(a=ts(t)),r){const m=Ln(t,!0,s,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?Sd(o,a):Zt(0),f=i.left+a.scrollLeft-c.x-d.x,h=i.top+a.scrollTop-c.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function ta(e){return Ut(e).position==="static"}function Ed(e,t){if(!tn(e)||Ut(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return en(e)===n&&(n=n.ownerDocument.body),n}function kd(e,t){const n=At(e);if(es(e))return n;if(!tn(e)){let o=wn(e);for(;o&&!nr(o);){if(Ht(o)&&!ta(o))return o;o=wn(o)}return n}let r=Ed(e,t);for(;r&&Pb(r)&&ta(r);)r=Ed(r,t);return r&&nr(r)&&ta(r)&&!Xi(r)?n:r||$b(e)||n}const Zb=async function(e){const t=this.getOffsetParent||kd,n=this.getDimensions,r=await n(e.floating);return{reference:Jb(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Qb(e){return Ut(e).direction==="rtl"}const ey={convertOffsetParentRelativeRectToViewportRelativeRect:Hb,getDocumentElement:en,getClippingRect:Yb,getOffsetParent:kd,getElementRects:Zb,getClientRects:Ub,getDimensions:Xb,getScale:rr,isElement:Ht,isRTL:Qb};function Id(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ty(e,t){let n=null,r;const o=en(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:m}=u;if(a||t(),!h||!m)return;const w=Xo(f),v=Xo(o.clientWidth-(d+h)),g=Xo(o.clientHeight-(f+m)),x=Xo(d),S={rootMargin:-w+"px "+-v+"px "+-g+"px "+-x+"px",threshold:Nt(0,vn(1,c))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==c){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Id(u,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function ny(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:c=!1}=r,u=Qi(e),d=o||s?[...u?Pr(u):[],...Pr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?ty(u,n):null;let h=-1,m=null;i&&(m=new ResizeObserver(x=>{let[b]=x;b&&b.target===u&&m&&(m.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=m)==null||S.observe(t)})),n()}),u&&!c&&m.observe(u),m.observe(t));let w,v=c?Ln(e):null;c&&g();function g(){const x=Ln(e);v&&!Id(v,x)&&n(),v=x,w=requestAnimationFrame(g)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=m)==null||x.disconnect(),m=null,c&&cancelAnimationFrame(w)}}const ry=Ib,oy=Nb,sy=Tb,iy=_b,ay=Eb,Nd=Cb,ly=Ab,cy=(e,t,n)=>{const r=new Map,o={platform:ey,...n},s={...o.platform,_c:r};return Sb(e,t,{...o,platform:s})};var uy=typeof document<"u",dy=function(){},ns=uy?y.useLayoutEffect:dy;function rs(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(!rs(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)&&!rs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Ad(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function _d(e,t){const n=Ad(e);return Math.round(t*n)/n}function na(e){const t=p.useRef(e);return ns(()=>{t.current=e}),t}function fy(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:c,open:u}=e,[d,f]=p.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,m]=p.useState(r);rs(h,r)||m(r);const[w,v]=p.useState(null),[g,x]=p.useState(null),b=p.useCallback(L=>{L!==T.current&&(T.current=L,v(L))},[]),S=p.useCallback(L=>{L!==I.current&&(I.current=L,x(L))},[]),k=s||w,C=i||g,T=p.useRef(null),I=p.useRef(null),N=p.useRef(d),_=c!=null,R=na(c),j=na(o),$=na(u),z=p.useCallback(()=>{if(!T.current||!I.current)return;const L={placement:t,strategy:n,middleware:h};j.current&&(L.platform=j.current),cy(T.current,I.current,L).then(A=>{const D={...A,isPositioned:$.current!==!1};O.current&&!rs(N.current,D)&&(N.current=D,qr.flushSync(()=>{f(D)}))})},[h,t,n,j,$]);ns(()=>{u===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[u]);const O=p.useRef(!1);ns(()=>(O.current=!0,()=>{O.current=!1}),[]),ns(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(R.current)return R.current(k,C,z);z()}},[k,C,z,R,_]);const V=p.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),B=p.useMemo(()=>({reference:k,floating:C}),[k,C]),K=p.useMemo(()=>{const L={position:n,left:0,top:0};if(!B.floating)return L;const A=_d(B.floating,d.x),D=_d(B.floating,d.y);return a?{...L,transform:"translate("+A+"px, "+D+"px)",...Ad(B.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:A,top:D}},[n,a,B.floating,d.x,d.y]);return p.useMemo(()=>({...d,update:z,refs:V,elements:B,floatingStyles:K}),[d,z,V,B,K])}const hy=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?Nd({element:r.current,padding:o}).fn(n):{}:r?Nd({element:r,padding:o}).fn(n):{}}}},py=(e,t)=>({...ry(e),options:[e,t]}),my=(e,t)=>({...oy(e),options:[e,t]}),gy=(e,t)=>({...ly(e),options:[e,t]}),xy=(e,t)=>({...sy(e),options:[e,t]}),vy=(e,t)=>({...iy(e),options:[e,t]}),wy=(e,t)=>({...ay(e),options:[e,t]}),by=(e,t)=>({...hy(e),options:[e,t]});var yy="Arrow",jd=p.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return l.jsx(ye.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:l.jsx("polygon",{points:"0,0 30,0 15,10"})})});jd.displayName=yy;var Sy=jd;function Rd(e){const[t,n]=p.useState(void 0);return ct(()=>{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 c=s.borderBoxSize,u=Array.isArray(c)?c[0]:c;i=u.inlineSize,a=u.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 ra="Popper",[Pd,os]=Yt(ra),[Cy,Od]=Pd(ra),Md=e=>{const{__scopePopper:t,children:n}=e,[r,o]=p.useState(null);return l.jsx(Cy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Md.displayName=ra;var Dd="PopperAnchor",Ld=p.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Od(Dd,n),i=p.useRef(null),a=Pe(t,i),c=p.useRef(null);return p.useEffect(()=>{const u=c.current;c.current=(r==null?void 0:r.current)||i.current,u!==c.current&&s.onAnchorChange(c.current)}),r?null:l.jsx(ye.div,{...o,ref:a})});Ld.displayName=Dd;var oa="PopperContent",[Ty,Ey]=Pd(oa),$d=p.forwardRef((e,t)=>{var W,M,G,te,de,ce;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:c=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:m="optimized",onPlaced:w,...v}=e,g=Od(oa,n),[x,b]=p.useState(null),S=Pe(t,$e=>b($e)),[k,C]=p.useState(null),T=Rd(k),I=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),R=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},j=Array.isArray(u)?u:[u],$=j.length>0,z={padding:R,boundary:j.filter(Iy),altBoundary:$},{refs:O,floatingStyles:V,placement:B,isPositioned:K,middlewareData:L}=fy({strategy:"fixed",placement:_,whileElementsMounted:(...$e)=>ny(...$e,{animationFrame:m==="always"}),elements:{reference:g.anchor},middleware:[py({mainAxis:o+N,alignmentAxis:i}),c&&my({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?gy():void 0,...z}),c&&xy({...z}),vy({...z,apply:({elements:$e,rects:Ge,availableWidth:_e,availableHeight:Re})=>{const{width:We,height:Q}=Ge.reference,X=$e.floating.style;X.setProperty("--radix-popper-available-width",`${_e}px`),X.setProperty("--radix-popper-available-height",`${Re}px`),X.setProperty("--radix-popper-anchor-width",`${We}px`),X.setProperty("--radix-popper-anchor-height",`${Q}px`)}}),k&&by({element:k,padding:a}),Ny({arrowWidth:I,arrowHeight:N}),h&&wy({strategy:"referenceHidden",...z})]}),[A,D]=Bd(B),H=ut(w);ct(()=>{K&&(H==null||H())},[K,H]);const Y=(W=L.arrow)==null?void 0:W.x,Z=(M=L.arrow)==null?void 0:M.y,le=((G=L.arrow)==null?void 0:G.centerOffset)!==0,[xe,Ee]=p.useState();return ct(()=>{x&&Ee(window.getComputedStyle(x).zIndex)},[x]),l.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...V,transform:K?V.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:xe,"--radix-popper-transform-origin":[(te=L.transformOrigin)==null?void 0:te.x,(de=L.transformOrigin)==null?void 0:de.y].join(" "),...((ce=L.hide)==null?void 0:ce.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:l.jsx(Ty,{scope:n,placedSide:A,onArrowChange:C,arrowX:Y,arrowY:Z,shouldHideArrow:le,children:l.jsx(ye.div,{"data-side":A,"data-align":D,...v,ref:S,style:{...v.style,animation:K?void 0:"none"}})})})});$d.displayName=oa;var Fd="PopperArrow",ky={top:"bottom",right:"left",bottom:"top",left:"right"},zd=p.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Ey(Fd,r),i=ky[s.placedSide];return l.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:l.jsx(Sy,{...o,ref:n,style:{...o.style,display:"block"}})})});zd.displayName=Fd;function Iy(e){return e!==null}var Ny=e=>({name:"transformOrigin",options:e,fn(t){var g,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,c=i?0:e.arrowHeight,[u,d]=Bd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,m=(((b=o.arrow)==null?void 0:b.y)??0)+c/2;let w="",v="";return u==="bottom"?(w=i?f:`${h}px`,v=`${-c}px`):u==="top"?(w=i?f:`${h}px`,v=`${r.floating.height+c}px`):u==="right"?(w=`${-c}px`,v=i?f:`${m}px`):u==="left"&&(w=`${r.floating.width+c}px`,v=i?f:`${m}px`),{data:{x:w,y:v}}}});function Bd(e){const[t,n="center"]=e.split("-");return[t,n]}var Hd=Md,Ud=Ld,Wd=$d,Vd=zd,sa="rovingFocusGroup.onEntryFocus",Ay={bubbles:!1,cancelable:!0},Or="RovingFocusGroup",[ia,Kd,_y]=Wi(Or),[jy,qd]=Yt(Or,[_y]),[Ry,Py]=jy(Or),Gd=p.forwardRef((e,t)=>l.jsx(ia.Provider,{scope:e.__scopeRovingFocusGroup,children:l.jsx(ia.Slot,{scope:e.__scopeRovingFocusGroup,children:l.jsx(Oy,{...e,ref:t})})}));Gd.displayName=Or;var Oy=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=p.useRef(null),m=Pe(t,h),w=Go(s),[v,g]=Rn({prop:i,defaultProp:a??null,onChange:c,caller:Or}),[x,b]=p.useState(!1),S=ut(u),k=Kd(n),C=p.useRef(!1),[T,I]=p.useState(0);return p.useEffect(()=>{const N=h.current;if(N)return N.addEventListener(sa,S),()=>N.removeEventListener(sa,S)},[S]),l.jsx(Ry,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:v,onItemFocus:p.useCallback(N=>g(N),[g]),onItemShiftTab:p.useCallback(()=>b(!0),[]),onFocusableItemAdd:p.useCallback(()=>I(N=>N+1),[]),onFocusableItemRemove:p.useCallback(()=>I(N=>N-1),[]),children:l.jsx(ye.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:m,style:{outline:"none",...e.style},onMouseDown:ae(e.onMouseDown,()=>{C.current=!0}),onFocus:ae(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!x){const R=new CustomEvent(sa,Ay);if(N.currentTarget.dispatchEvent(R),!R.defaultPrevented){const j=k().filter(B=>B.focusable),$=j.find(B=>B.active),z=j.find(B=>B.id===v),V=[$,z,...j].filter(Boolean).map(B=>B.ref.current);Jd(V,d)}}C.current=!1}),onBlur:ae(e.onBlur,()=>b(!1))})})}),Yd="RovingFocusGroupItem",Xd=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,c=Xt(),u=s||c,d=Py(Yd,n),f=d.currentTabStopId===u,h=Kd(n),{onFocusableItemAdd:m,onFocusableItemRemove:w,currentTabStopId:v}=d;return p.useEffect(()=>{if(r)return m(),()=>w()},[r,m,w]),l.jsx(ia.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:l.jsx(ye.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ae(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ae(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ae(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const x=Ly(g,d.orientation,d.dir);if(x!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const k=S.indexOf(g.currentTarget);S=d.loop?$y(S,k+1):S.slice(k+1)}setTimeout(()=>Jd(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:v!=null}):i})})});Xd.displayName=Yd;var My={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Dy(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Ly(e,t,n){const r=Dy(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return My[r]}function Jd(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function $y(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Fy=Gd,zy=Xd,aa=["Enter"," "],By=["ArrowDown","PageUp","Home"],Zd=["ArrowUp","PageDown","End"],Hy=[...By,...Zd],Uy={ltr:[...aa,"ArrowRight"],rtl:[...aa,"ArrowLeft"]},Wy={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Mr="Menu",[Dr,Vy,Ky]=Wi(Mr),[$n,Qd]=Yt(Mr,[Ky,os,qd]),ss=os(),ef=qd(),[qy,Fn]=$n(Mr),[Gy,Lr]=$n(Mr),tf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ss(t),[c,u]=p.useState(null),d=p.useRef(!1),f=ut(s),h=Go(o);return p.useEffect(()=>{const m=()=>{d.current=!0,document.addEventListener("pointerdown",w,{capture:!0,once:!0}),document.addEventListener("pointermove",w,{capture:!0,once:!0})},w=()=>d.current=!1;return document.addEventListener("keydown",m,{capture:!0}),()=>{document.removeEventListener("keydown",m,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),l.jsx(Hd,{...a,children:l.jsx(qy,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:u,children:l.jsx(Gy,{scope:t,onClose:p.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};tf.displayName=Mr;var Yy="MenuAnchor",la=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ss(n);return l.jsx(Ud,{...o,...r,ref:t})});la.displayName=Yy;var ca="MenuPortal",[Xy,nf]=$n(ca,{forceMount:void 0}),rf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Fn(ca,t);return l.jsx(Xy,{scope:t,forceMount:n,children:l.jsx(It,{present:n||s.open,children:l.jsx(Ro,{asChild:!0,container:o,children:r})})})};rf.displayName=ca;var Ot="MenuContent",[Jy,ua]=$n(Ot),of=p.forwardRef((e,t)=>{const n=nf(Ot,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Fn(Ot,e.__scopeMenu),i=Lr(Ot,e.__scopeMenu);return l.jsx(Dr.Provider,{scope:e.__scopeMenu,children:l.jsx(It,{present:r||s.open,children:l.jsx(Dr.Slot,{scope:e.__scopeMenu,children:i.modal?l.jsx(Zy,{...o,ref:t}):l.jsx(Qy,{...o,ref:t})})})})}),Zy=p.forwardRef((e,t)=>{const n=Fn(Ot,e.__scopeMenu),r=p.useRef(null),o=Pe(t,r);return p.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),l.jsx(da,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ae(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Qy=p.forwardRef((e,t)=>{const n=Fn(Ot,e.__scopeMenu);return l.jsx(da,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),e0=Tn.createSlot("MenuContent.ScrollLock"),da=p.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:m,disableOutsideScroll:w,...v}=e,g=Fn(Ot,n),x=Lr(Ot,n),b=ss(n),S=ef(n),k=Vy(n),[C,T]=p.useState(null),I=p.useRef(null),N=Pe(t,I,g.onContentChange),_=p.useRef(0),R=p.useRef(""),j=p.useRef(0),$=p.useRef(null),z=p.useRef("right"),O=p.useRef(0),V=w?$o:p.Fragment,B=w?{as:e0,allowPinchZoom:!0}:void 0,K=A=>{var W,M;const D=R.current+A,H=k().filter(G=>!G.disabled),Y=document.activeElement,Z=(W=H.find(G=>G.ref.current===Y))==null?void 0:W.textValue,le=H.map(G=>G.textValue),xe=f0(le,D,Z),Ee=(M=H.find(G=>G.textValue===xe))==null?void 0:M.ref.current;(function G(te){R.current=te,window.clearTimeout(_.current),te!==""&&(_.current=window.setTimeout(()=>G(""),1e3))})(D),Ee&&setTimeout(()=>Ee.focus())};p.useEffect(()=>()=>window.clearTimeout(_.current),[]),Ri();const L=p.useCallback(A=>{var H,Y;return z.current===((H=$.current)==null?void 0:H.side)&&p0(A,(Y=$.current)==null?void 0:Y.area)},[]);return l.jsx(Jy,{scope:n,searchRef:R,onItemEnter:p.useCallback(A=>{L(A)&&A.preventDefault()},[L]),onItemLeave:p.useCallback(A=>{var D;L(A)||((D=I.current)==null||D.focus(),T(null))},[L]),onTriggerLeave:p.useCallback(A=>{L(A)&&A.preventDefault()},[L]),pointerGraceTimerRef:j,onPointerGraceIntentChange:p.useCallback(A=>{$.current=A},[]),children:l.jsx(V,{...B,children:l.jsx(jo,{asChild:!0,trapped:o,onMountAutoFocus:ae(s,A=>{var D;A.preventDefault(),(D=I.current)==null||D.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:l.jsx(_o,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:m,children:l.jsx(Fy,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:ae(c,A=>{x.isUsingKeyboardRef.current||A.preventDefault()}),preventScrollOnEntryFocus:!0,children:l.jsx(Wd,{role:"menu","aria-orientation":"vertical","data-state":Sf(g.open),"data-radix-menu-content":"",dir:x.dir,...b,...v,ref:N,style:{outline:"none",...v.style},onKeyDown:ae(v.onKeyDown,A=>{const H=A.target.closest("[data-radix-menu-content]")===A.currentTarget,Y=A.ctrlKey||A.altKey||A.metaKey,Z=A.key.length===1;H&&(A.key==="Tab"&&A.preventDefault(),!Y&&Z&&K(A.key));const le=I.current;if(A.target!==le||!Hy.includes(A.key))return;A.preventDefault();const Ee=k().filter(W=>!W.disabled).map(W=>W.ref.current);Zd.includes(A.key)&&Ee.reverse(),u0(Ee)}),onBlur:ae(e.onBlur,A=>{A.currentTarget.contains(A.target)||(window.clearTimeout(_.current),R.current="")}),onPointerMove:ae(e.onPointerMove,Fr(A=>{const D=A.target,H=O.current!==A.clientX;if(A.currentTarget.contains(D)&&H){const Y=A.clientX>O.current?"right":"left";z.current=Y,O.current=A.clientX}}))})})})})})})});of.displayName=Ot;var t0="MenuGroup",fa=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(ye.div,{role:"group",...r,ref:t})});fa.displayName=t0;var n0="MenuLabel",sf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(ye.div,{...r,ref:t})});sf.displayName=n0;var is="MenuItem",af="menu.itemSelect",as=p.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=p.useRef(null),i=Lr(is,e.__scopeMenu),a=ua(is,e.__scopeMenu),c=Pe(t,s),u=p.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(af,{bubbles:!0,cancelable:!0});f.addEventListener(af,m=>r==null?void 0:r(m),{once:!0}),Hc(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return l.jsx(lf,{...o,ref:c,disabled:n,onClick:ae(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ae(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ae(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||aa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});as.displayName=is;var lf=p.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ua(is,n),a=ef(n),c=p.useRef(null),u=Pe(t,c),[d,f]=p.useState(!1),[h,m]=p.useState("");return p.useEffect(()=>{const w=c.current;w&&m((w.textContent??"").trim())},[s.children]),l.jsx(Dr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:l.jsx(zy,{asChild:!0,...a,focusable:!r,children:l.jsx(ye.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ae(e.onPointerMove,Fr(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ae(e.onPointerLeave,Fr(w=>i.onItemLeave(w))),onFocus:ae(e.onFocus,()=>f(!0)),onBlur:ae(e.onBlur,()=>f(!1))})})})}),r0="MenuCheckboxItem",cf=p.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return l.jsx(pf,{scope:e.__scopeMenu,checked:n,children:l.jsx(as,{role:"menuitemcheckbox","aria-checked":ls(n)?"mixed":n,...o,ref:t,"data-state":pa(n),onSelect:ae(o.onSelect,()=>r==null?void 0:r(ls(n)?!0:!n),{checkForDefaultPrevented:!1})})})});cf.displayName=r0;var uf="MenuRadioGroup",[o0,s0]=$n(uf,{value:void 0,onValueChange:()=>{}}),df=p.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=ut(r);return l.jsx(o0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:l.jsx(fa,{...o,ref:t})})});df.displayName=uf;var ff="MenuRadioItem",hf=p.forwardRef((e,t)=>{const{value:n,...r}=e,o=s0(ff,e.__scopeMenu),s=n===o.value;return l.jsx(pf,{scope:e.__scopeMenu,checked:s,children:l.jsx(as,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":pa(s),onSelect:ae(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});hf.displayName=ff;var ha="MenuItemIndicator",[pf,i0]=$n(ha,{checked:!1}),mf=p.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=i0(ha,n);return l.jsx(It,{present:r||ls(s.checked)||s.checked===!0,children:l.jsx(ye.span,{...o,ref:t,"data-state":pa(s.checked)})})});mf.displayName=ha;var a0="MenuSeparator",gf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(ye.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});gf.displayName=a0;var l0="MenuArrow",xf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ss(n);return l.jsx(Vd,{...o,...r,ref:t})});xf.displayName=l0;var c0="MenuSub",[qC,vf]=$n(c0),$r="MenuSubTrigger",wf=p.forwardRef((e,t)=>{const n=Fn($r,e.__scopeMenu),r=Lr($r,e.__scopeMenu),o=vf($r,e.__scopeMenu),s=ua($r,e.__scopeMenu),i=p.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,u={__scopeMenu:e.__scopeMenu},d=p.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return p.useEffect(()=>d,[d]),p.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),c(null)}},[a,c]),l.jsx(la,{asChild:!0,...u,children:l.jsx(lf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Sf(n.open),...e,ref:vi(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:ae(e.onPointerMove,Fr(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:ae(e.onPointerLeave,Fr(f=>{var m,w;d();const h=(m=n.content)==null?void 0:m.getBoundingClientRect();if(h){const v=(w=n.content)==null?void 0:w.dataset.side,g=v==="right",x=g?-5:5,b=h[g?"left":"right"],S=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ae(e.onKeyDown,f=>{var m;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||Uy[r.dir].includes(f.key)&&(n.onOpenChange(!0),(m=n.content)==null||m.focus(),f.preventDefault())})})})});wf.displayName=$r;var bf="MenuSubContent",yf=p.forwardRef((e,t)=>{const n=nf(Ot,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Fn(Ot,e.__scopeMenu),i=Lr(Ot,e.__scopeMenu),a=vf(bf,e.__scopeMenu),c=p.useRef(null),u=Pe(t,c);return l.jsx(Dr.Provider,{scope:e.__scopeMenu,children:l.jsx(It,{present:r||s.open,children:l.jsx(Dr.Slot,{scope:e.__scopeMenu,children:l.jsx(da,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=c.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ae(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ae(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ae(e.onKeyDown,d=>{var m;const f=d.currentTarget.contains(d.target),h=Wy[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(m=a.trigger)==null||m.focus(),d.preventDefault())})})})})})});yf.displayName=bf;function Sf(e){return e?"open":"closed"}function ls(e){return e==="indeterminate"}function pa(e){return ls(e)?"indeterminate":e?"checked":"unchecked"}function u0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function d0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function f0(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=d0(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const c=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return c!==n?c:void 0}function h0(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],c=t[i],u=a.x,d=a.y,f=c.x,h=c.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function p0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return h0(n,t)}function Fr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var m0=tf,g0=la,x0=rf,v0=of,w0=fa,b0=sf,y0=as,S0=cf,C0=df,T0=hf,E0=mf,k0=gf,I0=xf,N0=wf,A0=yf,cs="DropdownMenu",[_0,GC]=Yt(cs,[Qd]),gt=Qd(),[j0,Cf]=_0(cs),Tf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=gt(t),u=p.useRef(null),[d,f]=Rn({prop:o,defaultProp:s??!1,onChange:i,caller:cs});return l.jsx(j0,{scope:t,triggerId:Xt(),triggerRef:u,contentId:Xt(),open:d,onOpenChange:f,onOpenToggle:p.useCallback(()=>f(h=>!h),[f]),modal:a,children:l.jsx(m0,{...c,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Tf.displayName=cs;var Ef="DropdownMenuTrigger",kf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Cf(Ef,n),i=gt(n);return l.jsx(g0,{asChild:!0,...i,children:l.jsx(ye.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:vi(t,s.triggerRef),onPointerDown:ae(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ae(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});kf.displayName=Ef;var R0="DropdownMenuPortal",If=e=>{const{__scopeDropdownMenu:t,...n}=e,r=gt(t);return l.jsx(x0,{...r,...n})};If.displayName=R0;var Nf="DropdownMenuContent",Af=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Cf(Nf,n),s=gt(n),i=p.useRef(!1);return l.jsx(v0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ae(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)==null||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ae(e.onInteractOutside,a=>{const c=a.detail.originalEvent,u=c.button===0&&c.ctrlKey===!0,d=c.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Af.displayName=Nf;var P0="DropdownMenuGroup",O0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(w0,{...o,...r,ref:t})});O0.displayName=P0;var M0="DropdownMenuLabel",_f=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(b0,{...o,...r,ref:t})});_f.displayName=M0;var D0="DropdownMenuItem",jf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(y0,{...o,...r,ref:t})});jf.displayName=D0;var L0="DropdownMenuCheckboxItem",Rf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(S0,{...o,...r,ref:t})});Rf.displayName=L0;var $0="DropdownMenuRadioGroup",F0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(C0,{...o,...r,ref:t})});F0.displayName=$0;var z0="DropdownMenuRadioItem",Pf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(T0,{...o,...r,ref:t})});Pf.displayName=z0;var B0="DropdownMenuItemIndicator",Of=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(E0,{...o,...r,ref:t})});Of.displayName=B0;var H0="DropdownMenuSeparator",Mf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(k0,{...o,...r,ref:t})});Mf.displayName=H0;var U0="DropdownMenuArrow",W0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(I0,{...o,...r,ref:t})});W0.displayName=U0;var V0="DropdownMenuSubTrigger",Df=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(N0,{...o,...r,ref:t})});Df.displayName=V0;var K0="DropdownMenuSubContent",Lf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=gt(n);return l.jsx(A0,{...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)"}})});Lf.displayName=K0;var q0=Tf,G0=kf,Y0=If,$f=Af,Ff=_f,zf=jf,Bf=Rf,Hf=Pf,Uf=Of,Wf=Mf,Vf=Df,Kf=Lf;const X0=q0,J0=G0,Z0=p.forwardRef(({className:e,inset:t,children:n,...r},o)=>l.jsxs(Vf,{ref:o,className:J("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,l.jsx(ne.ChevronRight,{className:"ml-auto h-4 w-4"})]}));Z0.displayName=Vf.displayName;const Q0=p.forwardRef(({className:e,...t},n)=>l.jsx(Kf,{ref:n,className:J("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}));Q0.displayName=Kf.displayName;const qf=p.forwardRef(({className:e,sideOffset:t=4,...n},r)=>l.jsx(Y0,{children:l.jsx($f,{ref:r,sideOffset:t,className:J("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})}));qf.displayName=$f.displayName;const ma=p.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(zf,{ref:r,className:J("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}));ma.displayName=zf.displayName;const eS=p.forwardRef(({className:e,children:t,checked:n,...r},o)=>l.jsxs(Bf,{ref:o,className:J("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:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(Uf,{children:l.jsx(ne.Check,{className:"h-4 w-4"})})}),t]}));eS.displayName=Bf.displayName;const tS=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Hf,{ref:r,className:J("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:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(Uf,{children:l.jsx(ne.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));tS.displayName=Hf.displayName;const nS=p.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Ff,{ref:r,className:J("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));nS.displayName=Ff.displayName;const rS=p.forwardRef(({className:e,...t},n)=>l.jsx(Wf,{ref:n,className:J("-mx-1 my-1 h-px bg-muted",e),...t}));rS.displayName=Wf.displayName;function us({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:c=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:m}){const{api:w}=so(),{currentThreadId:v,isLoadingThread:g,listCheckpoints:x,navigateToCheckpoint:b,returnToLatest:S}=mr(),{messages:k,hasMoreHistory:C,isLoadingHistory:T,send:I,stop:N,loadOlderMessages:_}=qs(),{isStreaming:R,error:j,streamingAssistantId:$,lastCheckpointId:z,lastCheckpointNs:O}=Ml(),[V,B]=y.useState(null),[K,L]=y.useState(""),[A,D]=y.useState(null),[H,Y]=y.useState([]),[Z,le]=y.useState(0),[xe,Ee]=y.useState(0),[W,M]=y.useState(!1),[G,te]=y.useState(null),[de,ce]=y.useState(null),[$e,Ge]=y.useState(!1),[_e,Re]=y.useState(null),[We,Q]=y.useState([]),[X,Ne]=y.useState(null),[He,ee]=y.useState(null),[se,he]=y.useState(!1),ge=y.useRef(null),ke=y.useRef(null),De=y.useRef(null),Ye=y.useCallback(()=>{ge.current&&(ge.current.value=""),ke.current&&(ke.current.value=""),le(ue=>ue+1),Ee(ue=>ue+1)},[]),Xe=y.useRef(!1);y.useEffect(()=>{Xe.current&&!R&&(Y([]),Ye()),Xe.current=R},[R,Ye]);const[Je,yt]=y.useState("desktop");y.useEffect(()=>{const ue=()=>{const ve=window.innerWidth;yt(ve<640?"phone":ve<1024?"tablet":"desktop")};return ue(),window.addEventListener("resize",ue),()=>window.removeEventListener("resize",ue)},[]),y.useEffect(()=>{let ue=!1;if(!v){Q([]),Ne(null),ee(null),De.current=null;return}const ve={threadId:v,checkpointId:z??null,checkpointNs:O??null},Le=De.current;if(!(Le&&Le.threadId===ve.threadId&&Le.checkpointId===ve.checkpointId&&Le.checkpointNs===ve.checkpointNs))return x(v).then(nt=>{var ks;if(ue)return;const _t=((nt==null?void 0:nt.checkpoints)??[]).slice().sort((cn,E)=>new Date(E.createdAt).getTime()-new Date(cn.createdAt).getTime());Q(_t);const rn=X,Vr=rn&&_t.some(cn=>cn.checkpointId===rn)?rn:((ks=_t[0])==null?void 0:ks.checkpointId)??null;let Es=null;if(Vr){const cn=_t.find(E=>E.checkpointId===Vr);Es=(cn==null?void 0:cn.checkpointNs)??null}Ne(Vr),ee(Es),De.current=ve}).catch(nt=>{console.error("ChatInterface - listCheckpoints error:",nt),ue||(Q([]),De.current=null)}),()=>{ue=!0}},[v,z,O,X,x]),y.useEffect(()=>{z&&(Ne(z),ee(O??null))},[z,O]);const ln=y.useCallback(async()=>{if(!(!C||T))try{await _()}catch(ue){console.warn("loadOlderMessages failed",ue)}},[C,T,_]);y.useEffect(()=>{(async()=>{if(!w.baseUrl){Re(null);return}try{const ve=await w.getAgent("default");Re(ve.uiDefaultMessage||null)}catch(ve){console.warn("Failed to fetch default message:",ve),Re(null)}})()},[w]),y.useEffect(()=>{j&&!$e&&(m==null||m(j))},[j,$e,m]);const _a=ue=>{if(ue.length>qo)return`Message too long (${ue.length}/${qo} characters)`;try{return cb(ue),null}catch(ve){return(ve==null?void 0:ve.message)||"Invalid message"}},ja=async ue=>{const ve=ue.trim();if(!(!ve&&H.length===0)){if(ve){const Le=_a(ve);if(Le){D(Le);return}}try{await I(ve||"",{checkpointId:X??z??void 0,checkpointNs:He??O??void 0,payloadExtras:V?{edit:!0,originalMessageId:V}:void 0,attachments:H}),f==null||f(ve),D(null),Y([]),Ye(),B(null),L("")}catch(Le){const nt=(Le==null?void 0:Le.message)||"Failed to send message";D(nt),m==null||m(nt)}}},ys=y.useCallback((ue,ve)=>{u&&(B(ue),L(ve),D(null))},[u]),Br=y.useCallback(()=>{B(null),L(""),D(null)},[]),Ra=y.useCallback((ue,ve)=>{ys(ue,ve)},[ys]),Hr=y.useCallback(ue=>{const ve=Le=>{const nt=Le.content||[],_t=nt.filter(rn=>rn.type==="text").map(rn=>rn.text).join("");if(_t)return _t;try{return JSON.stringify(nt,null,2)}catch{return String(nt)}};for(let Le=ue-1;Le>=0;Le--)if(k[Le].role==="user"){const nt=ve(k[Le]);nt&&I(nt,{checkpointId:X??z??void 0,checkpointNs:He??O??void 0});break}},[k,I,X,He,z,O]),Ss=ue=>{const ve=Array.from(ue.target.files||[]);Y(Le=>[...Le,...ve]),ue.target.value=""},Cn=ue=>{Y(ve=>{const Le=ve.filter((nt,_t)=>ue!==_t);return Le.length===0&&Ye(),Le})},Ur=async ue=>{const ve=(ue.target.files||[])[0];if(ve){te(null),ce(null),M(!0);try{await I("",{checkpointId:X??z??void 0,checkpointNs:He??O??void 0,attachments:[ve]});const Le=`Uploaded ${ve.name} - processing through chat stream`;ce(Le)}catch(Le){const nt=Le instanceof Error?Le.message:"Failed to upload Excel file";console.error("Excel upload failed",Le),te(nt),m==null||m(nt)}finally{M(!1),ue.target.value="",Ye()}}},Wr=ue=>{if(!ue)return"Unknown";const ve=Date.parse(ue);return Number.isNaN(ve)?ue:new Date(ve).toLocaleString()},Cs=async ue=>{if(v){he(!0);try{if(!ue){await S(),Ne(null),ee(null);return}const ve=We.find(nt=>nt.checkpointId===ue),Le=(ve==null?void 0:ve.checkpointNs)??null;await b(ue,Le),Ne(ue),ee(Le)}finally{he(!1)}}},Pa=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Ts=`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 ${d.messagesArea||""}`,Oa=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return l.jsxs("div",{className:Pa,children:[!!j&&!$e&&l.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:[l.jsx("span",{children:j}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Ge(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:l.jsx(ne.X,{size:16})})]}),v&&We.length>0&&l.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:[l.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),l.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:X??"",onChange:ue=>{const ve=ue.target.value||null;Cs(ve)},children:[l.jsx("option",{value:"",children:"Latest"}),We.map(ue=>l.jsxs("option",{value:ue.checkpointId,children:[Wr(ue.createdAt),ue.preview?` — ${ue.preview.slice(0,40)}`:""]},ue.checkpointId))]})]}),l.jsxs("div",{className:`relative ${Ts}`,style:r?{maxHeight:r}:void 0,children:[l.jsx(Ui,{className:"h-full",style:{height:"100%"},messages:k,isStreaming:R,streamingAssistantId:$,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Je,enableMessageEditing:u,editingMessageId:V,onStartReached:()=>{ln()},onEdit:Ra,onRegenerate:Hr,onCancelEdit:Br,emptyMessage:_e??void 0,isNavigatingCheckpoint:se}),g&&l.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:[l.jsx(ne.Loader2,{className:"h-6 w-6 animate-spin"}),l.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),l.jsxs("div",{className:Oa,children:[V&&l.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ne.Edit3,{size:16,className:"text-blue-600"}),l.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:Br,className:"text-blue-600 hover:bg-blue-100",children:l.jsx(ne.X,{size:16})})]})}),(a||c)&&l.jsxs("div",{className:"mb-3 space-y-3",children:[a&&l.jsxs(l.Fragment,{children:[l.jsx("input",{ref:ge,type:"file",multiple:!0,onChange:ue=>Ss(ue),className:"hidden"},Z),H.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2",children:H.map((ue,ve)=>l.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:[l.jsx(ne.Paperclip,{size:14}),l.jsx("span",{className:"truncate max-w-[150px]",children:ue.name}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>Cn(ve),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 ${ue.name}`,children:l.jsx(ne.X,{size:12})})]},ve))})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("input",{ref:ke,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Ur,className:"hidden"},xe),W&&l.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[l.jsx(ne.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),de&&!W&&l.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:de}),G&&!W&&l.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:G})]})]}),A&&l.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:A}),l.jsxs("div",{className:"flex items-end gap-2",children:[(a||c)&&l.jsxs(X0,{children:[l.jsx(J0,{asChild:!0,children:l.jsx(ze,{type:"button",size:"icon",variant:"outline",disabled:R,title:"More input actions",className:d.moreButton||"",children:l.jsx(ne.Plus,{size:16})})}),l.jsxs(qf,{align:"start",sideOffset:6,className:"w-52",children:[a&&l.jsxs(ma,{onClick:()=>{var ue;return(ue=ge.current)==null?void 0:ue.click()},className:"cursor-pointer",children:[l.jsx(ne.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),c&&l.jsxs(ma,{onClick:()=>{var ue;W||(ue=ke.current)==null||ue.click()},className:`cursor-pointer ${W?"opacity-60 pointer-events-none":""}`,children:[l.jsx(ne.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),l.jsx("div",{className:"flex-1",children:l.jsx(Sg,{initialValue:K,editingMessageId:V,placeholder:V?"Edit your message...":t,isStreaming:R,disabled:!1,maxLength:qo,onSend:ja,onCancelEdit:Br,onStop:N,allowEmptySend:H.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${V?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${A?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const ds=p.forwardRef(({className:e,type:t,...n},r)=>l.jsx("input",{type:t,className:J("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}));ds.displayName="Input";function ga(e,[t,n]){return Math.min(n,Math.max(t,e))}function oS(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var xa="ScrollArea",[Gf,YC]=Yt(xa),[sS,Mt]=Gf(xa),Yf=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,c]=p.useState(null),[u,d]=p.useState(null),[f,h]=p.useState(null),[m,w]=p.useState(null),[v,g]=p.useState(null),[x,b]=p.useState(0),[S,k]=p.useState(0),[C,T]=p.useState(!1),[I,N]=p.useState(!1),_=Pe(t,j=>c(j)),R=Go(o);return l.jsx(sS,{scope:n,type:r,dir:R,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:m,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:v,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:l.jsx(ye.div,{dir:R,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Yf.displayName=xa;var Xf="ScrollAreaViewport",Jf=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Mt(Xf,n),a=p.useRef(null),c=Pe(t,a,i.onViewportChange);return l.jsxs(l.Fragment,{children:[l.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}),l.jsx(ye.div,{"data-radix-scroll-area-viewport":"",...s,ref:c,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:l.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Jf.displayName=Xf;var nn="ScrollAreaScrollbar",va=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Mt(nn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return p.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?l.jsx(iS,{...r,ref:t,forceMount:n}):o.type==="scroll"?l.jsx(aS,{...r,ref:t,forceMount:n}):o.type==="auto"?l.jsx(Zf,{...r,ref:t,forceMount:n}):o.type==="always"?l.jsx(wa,{...r,ref:t}):null});va.displayName=nn;var iS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Mt(nn,e.__scopeScrollArea),[s,i]=p.useState(!1);return p.useEffect(()=>{const a=o.scrollArea;let c=0;if(a){const u=()=>{window.clearTimeout(c),i(!0)},d=()=>{c=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(c),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),l.jsx(It,{present:n||s,children:l.jsx(Zf,{"data-state":s?"visible":"hidden",...r,ref:t})})}),aS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Mt(nn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ms(()=>c("SCROLL_END"),100),[a,c]=oS("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 p.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>c("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,c]),p.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const m=u[d];f!==m&&(c("SCROLL"),i()),f=m};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,c,i]),l.jsx(It,{present:n||a!=="hidden",children:l.jsx(wa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ae(e.onPointerEnter,()=>c("POINTER_ENTER")),onPointerLeave:ae(e.onPointerLeave,()=>c("POINTER_LEAVE"))})})}),Zf=p.forwardRef((e,t)=>{const n=Mt(nn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=p.useState(!1),a=e.orientation==="horizontal",c=ms(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return or(n.viewport,c),or(n.content,c),l.jsx(It,{present:r||s,children:l.jsx(wa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),wa=p.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Mt(nn,e.__scopeScrollArea),s=p.useRef(null),i=p.useRef(0),[a,c]=p.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=rh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:c,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,m){return hS(h,i.current,a,m)}return n==="horizontal"?l.jsx(lS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,m=oh(h,a,o.dir);s.current.style.transform=`translate3d(${m}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?l.jsx(cS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,m=oh(h,a);s.current.style.transform=`translate3d(0, ${m}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),lS=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Mt(nn,e.__scopeScrollArea),[i,a]=p.useState(),c=p.useRef(null),u=Pe(t,c,s.onScrollbarXChange);return p.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),l.jsx(eh,{"data-orientation":"horizontal",...o,ref:u,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":ps(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),ih(h,f)&&d.preventDefault()}},onResize:()=>{c.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:c.current.clientWidth,paddingStart:hs(i.paddingLeft),paddingEnd:hs(i.paddingRight)}})}})}),cS=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Mt(nn,e.__scopeScrollArea),[i,a]=p.useState(),c=p.useRef(null),u=Pe(t,c,s.onScrollbarYChange);return p.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),l.jsx(eh,{"data-orientation":"vertical",...o,ref:u,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":ps(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),ih(h,f)&&d.preventDefault()}},onResize:()=>{c.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:c.current.clientHeight,paddingStart:hs(i.paddingTop),paddingEnd:hs(i.paddingBottom)}})}})}),[uS,Qf]=Gf(nn),eh=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:c,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,m=Mt(nn,n),[w,v]=p.useState(null),g=Pe(t,_=>v(_)),x=p.useRef(null),b=p.useRef(""),S=m.viewport,k=r.content-r.viewport,C=ut(d),T=ut(c),I=ms(f,10);function N(_){if(x.current){const R=_.clientX-x.current.left,j=_.clientY-x.current.top;u({x:R,y:j})}}return p.useEffect(()=>{const _=R=>{const j=R.target;(w==null?void 0:w.contains(j))&&C(R,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,w,k,C]),p.useEffect(T,[r,T]),or(w,I),or(m.content,I),l.jsx(uS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:ut(s),onThumbPointerUp:ut(i),onThumbPositionChange:T,onThumbPointerDown:ut(a),children:l.jsx(ye.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ae(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",m.viewport&&(m.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:ae(e.onPointerMove,N),onPointerUp:ae(e.onPointerUp,_=>{const R=_.target;R.hasPointerCapture(_.pointerId)&&R.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,m.viewport&&(m.viewport.style.scrollBehavior=""),x.current=null})})})}),fs="ScrollAreaThumb",th=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qf(fs,e.__scopeScrollArea);return l.jsx(It,{present:n||o.hasThumb,children:l.jsx(dS,{ref:t,...r})})}),dS=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Mt(fs,n),i=Qf(fs,n),{onThumbPositionChange:a}=i,c=Pe(t,f=>i.onThumbChange(f)),u=p.useRef(void 0),d=ms(()=>{u.current&&(u.current(),u.current=void 0)},100);return p.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const m=pS(f,a);u.current=m,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),l.jsx(ye.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:c,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ae(e.onPointerDownCapture,f=>{const m=f.target.getBoundingClientRect(),w=f.clientX-m.left,v=f.clientY-m.top;i.onThumbPointerDown({x:w,y:v})}),onPointerUp:ae(e.onPointerUp,i.onThumbPointerUp)})});th.displayName=fs;var ba="ScrollAreaCorner",nh=p.forwardRef((e,t)=>{const n=Mt(ba,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?l.jsx(fS,{...e,ref:t}):null});nh.displayName=ba;var fS=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Mt(ba,n),[s,i]=p.useState(0),[a,c]=p.useState(0),u=!!(s&&a);return or(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),c(d)}),or(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?l.jsx(ye.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 hs(e){return e?parseInt(e,10):0}function rh(e,t){const n=e/t;return isNaN(n)?0:n}function ps(e){const t=rh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function hS(e,t,n,r="ltr"){const o=ps(n),s=o/2,i=t||s,a=o-i,c=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return sh([c,u],f)(e)}function oh(e,t,n="ltr"){const r=ps(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,c=n==="ltr"?[0,i]:[i*-1,0],u=ga(e,c);return sh([0,i],[0,a])(u)}function sh(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 ih(e,t){return e>0&&e<t}var pS=(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 ms(e,t){const n=ut(e),r=p.useRef(0);return p.useEffect(()=>()=>window.clearTimeout(r.current),[]),p.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function or(e,t){const n=ut(t);ct(()=>{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 ah=Yf,mS=Jf,gS=nh;const lh=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(ah,{ref:r,className:J("relative overflow-hidden",e),...n,children:[l.jsx(mS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),l.jsx(ch,{}),l.jsx(gS,{})]}));lh.displayName=ah.displayName;const ch=p.forwardRef(({className:e,orientation:t="vertical",...n},r)=>l.jsx(va,{ref:r,orientation:t,className:J("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:l.jsx(th,{className:"relative flex-1 rounded-full bg-border"})}));ch.displayName=va.displayName;function ya({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:c,onThreadCreate:u,onThreadDelete:d}){const{loadThread:f,threads:h,currentThreadId:m,createThread:w,deleteThread:v,renameThread:g,isLoadingThreads:x}=mr(),[b,S]=y.useState(h??[]),[k,C]=y.useState(null),[T,I]=y.useState(""),[N,_]=y.useState(!1);y.useEffect(()=>{S(h??[])},[h]);const R=async A=>{try{await f(A),a==null||a(A),c==null||c(A)}catch(D){console.error("Failed to select thread:",D)}},j=async()=>{try{_(!0);const A=await w();u==null||u(A),a==null||a(A)}catch(A){console.error("Failed to create thread:",A)}finally{_(!1)}},$=async(A,D)=>{if(D.stopPropagation(),!!confirm("Delete this thread?"))try{await v(A),d==null||d(A)}catch(H){console.error("Failed to delete thread:",H)}},z=(A,D)=>{D.stopPropagation(),C(A.threadId),I(A.title||`Thread ${A.threadId.slice(0,8)}`)},O=async A=>{if(T.trim())try{await g(A,T.trim()),C(null),I("")}catch(D){console.error("Failed to update title:",D)}},V=()=>{C(null),I("")},B=(A,D)=>{A.key==="Enter"?O(D):A.key==="Escape"&&V()},K=A=>{if(!A)return"";try{const D=new Date(A),Y=new Date().getTime()-D.getTime(),Z=Math.floor(Y/(1e3*60*60*24));return Z===0?D.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Z===1?"Yesterday":Z<7?`${Z} days ago`:D.toLocaleDateString()}catch{return""}},L=A=>A.title||`Thread ${A.threadId.slice(0,8)}`;return l.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&l.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:l.jsx(ze,{onClick:j,disabled:N||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:N?"Creating...":"New Chat",children:l.jsx(ne.MessageSquarePlus,{size:20})})}),l.jsx(lh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:l.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?l.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[l.jsx(ne.Loader2,{className:"h-5 w-5 animate-spin"}),l.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):b.length===0?l.jsxs("div",{className:"text-center py-8 text-slate-400",children:[l.jsx(ne.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),l.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):b.slice().sort((A,D)=>new Date(D.updatedAt||D.createdAt||"").getTime()-new Date(A.updatedAt||A.createdAt||"").getTime()).map(A=>l.jsxs("div",{onClick:()=>R(A.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??m)===A.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:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("div",{className:"flex-1 min-w-0",children:k===A.threadId?l.jsxs("div",{className:"flex items-center gap-2",onClick:D=>D.stopPropagation(),children:[l.jsx(ds,{value:T,onChange:D=>I(D.target.value),onKeyDown:D=>B(D,A.threadId),className:"h-6 text-sm",autoFocus:!0}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:()=>O(A.threadId),className:"h-6 w-6 p-0",children:l.jsx(ne.Check,{size:12})}),l.jsx(ze,{variant:"ghost",size:"sm",onClick:V,className:"h-6 w-6 p-0",children:l.jsx(ne.X,{size:12})})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:L(A)}),l.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[l.jsx(ne.Calendar,{size:10}),l.jsx("span",{children:K(A.updatedAt||A.createdAt)})]})]})}),l.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&k!==A.threadId&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:D=>z(A,D),className:"h-6 w-6 p-0",title:"Edit title",children:l.jsx(ne.Edit3,{size:12})}),n&&l.jsx(ze,{variant:"ghost",size:"sm",onClick:D=>$(A.threadId,D),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:l.jsx(ne.Trash2,{size:12})})]})]}),i===A.threadId&&l.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},A.threadId))})})]})}function sr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function xS(e){if(typeof e!="string")return;const t=e.trim();if(t)return t.replace(/\/+$/g,"")}function uh(){const e=[sr("__API_BASE_URL__"),sr("__CHAT_API_BASE_URL__"),sr("__CHAT_API_URL__")];for(const t of e){const n=xS(t);if(n)return n}}function dh(){const e=[sr("__API_AUTH_TOKEN__"),sr("__CHAT_API_KEY__"),sr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function fh(){const e={},t=uh(),n=dh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function hh(){const e=fh(),t=un.getAuthToken(),n=uh();return{apiBaseUrl:e.baseUrl||un.baseUrl||n||"http://localhost:8000",apiKey:t||e.apiKey||dh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const ph="chat-settings";function vS(){try{const e=localStorage.getItem(ph);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function wS(e){try{localStorage.setItem(ph,JSON.stringify(e)),e.apiKey&&un.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function bS(){const e=hh(),t=vS(),n=un.getAuthToken();return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:un.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function yS(e){e.apiKey&&un.setAuthToken(e.apiKey),wS(e)}var SS="Label",mh=p.forwardRef((e,t)=>l.jsx(ye.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())}}));mh.displayName=SS;var gh=mh;const CS=Kr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Dt=p.forwardRef(({className:e,...t},n)=>l.jsx(gh,{ref:n,className:J(CS(),e),...t}));Dt.displayName=gh.displayName;function xh(e){const t=p.useRef({value:e,previous:e});return p.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var gs="Switch",[TS,XC]=Yt(gs),[ES,kS]=TS(gs),vh=p.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:c="on",onCheckedChange:u,form:d,...f}=e,[h,m]=p.useState(null),w=Pe(t,S=>m(S)),v=p.useRef(!1),g=h?d||!!h.closest("form"):!0,[x,b]=Rn({prop:o,defaultProp:s??!1,onChange:u,caller:gs});return l.jsxs(ES,{scope:n,checked:x,disabled:a,children:[l.jsx(ye.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Sh(x),"data-disabled":a?"":void 0,disabled:a,value:c,...f,ref:w,onClick:ae(e.onClick,S=>{b(k=>!k),g&&(v.current=S.isPropagationStopped(),v.current||S.stopPropagation())})}),g&&l.jsx(yh,{control:h,bubbles:!v.current,name:r,value:c,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});vh.displayName=gs;var wh="SwitchThumb",bh=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=kS(wh,n);return l.jsx(ye.span,{"data-state":Sh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});bh.displayName=wh;var IS="SwitchBubbleInput",yh=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=p.useRef(null),a=Pe(i,s),c=xh(n),u=Rd(t);return p.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(f,"checked").set;if(c!==n&&m){const w=new Event("click",{bubbles:r});m.call(d,n),d.dispatchEvent(w)}},[c,n,r]),l.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});yh.displayName=IS;function Sh(e){return e?"checked":"unchecked"}var Ch=vh,NS=bh;const bn=p.forwardRef(({className:e,...t},n)=>l.jsx(Ch,{className:J("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:l.jsx(NS,{className:J("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")})}));bn.displayName=Ch.displayName;var Th=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"}),AS="VisuallyHidden",_S=p.forwardRef((e,t)=>l.jsx(ye.span,{...e,ref:t,style:{...Th,...e.style}}));_S.displayName=AS;var jS=[" ","Enter","ArrowUp","ArrowDown"],RS=[" ","Enter"],zn="Select",[xs,vs,PS]=Wi(zn),[ir,JC]=Yt(zn,[PS,os]),ws=os(),[OS,yn]=ir(zn),[MS,DS]=ir(zn),Eh=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:c,dir:u,name:d,autoComplete:f,disabled:h,required:m,form:w}=e,v=ws(t),[g,x]=p.useState(null),[b,S]=p.useState(null),[k,C]=p.useState(!1),T=Go(u),[I,N]=Rn({prop:r,defaultProp:o??!1,onChange:s,caller:zn}),[_,R]=Rn({prop:i,defaultProp:a,onChange:c,caller:zn}),j=p.useRef(null),$=g?w||!!g.closest("form"):!0,[z,O]=p.useState(new Set),V=Array.from(z).map(B=>B.props.value).join(";");return l.jsx(Hd,{...v,children:l.jsxs(OS,{required:m,scope:t,trigger:g,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Xt(),value:_,onValueChange:R,open:I,onOpenChange:N,dir:T,triggerPointerDownPosRef:j,disabled:h,children:[l.jsx(xs.Provider,{scope:t,children:l.jsx(MS,{scope:e.__scopeSelect,onNativeOptionAdd:p.useCallback(B=>{O(K=>new Set(K).add(B))},[]),onNativeOptionRemove:p.useCallback(B=>{O(K=>{const L=new Set(K);return L.delete(B),L})},[]),children:n})}),$?l.jsxs(Yh,{"aria-hidden":!0,required:m,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:B=>R(B.target.value),disabled:h,form:w,children:[_===void 0?l.jsx("option",{value:""}):null,Array.from(z)]},V):null]})})};Eh.displayName=zn;var kh="SelectTrigger",Ih=p.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ws(n),i=yn(kh,n),a=i.disabled||r,c=Pe(t,i.onTriggerChange),u=vs(n),d=p.useRef("touch"),[f,h,m]=Jh(v=>{const g=u().filter(S=>!S.disabled),x=g.find(S=>S.value===i.value),b=Zh(g,v,x);b!==void 0&&i.onValueChange(b.value)}),w=v=>{a||(i.onOpenChange(!0),m()),v&&(i.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return l.jsx(Ud,{asChild:!0,...s,children:l.jsx(ye.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":Xh(i.value)?"":void 0,...o,ref:c,onClick:ae(o.onClick,v=>{v.currentTarget.focus(),d.current!=="mouse"&&w(v)}),onPointerDown:ae(o.onPointerDown,v=>{d.current=v.pointerType;const g=v.target;g.hasPointerCapture(v.pointerId)&&g.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(w(v),v.preventDefault())}),onKeyDown:ae(o.onKeyDown,v=>{const g=f.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&h(v.key),!(g&&v.key===" ")&&jS.includes(v.key)&&(w(),v.preventDefault())})})})});Ih.displayName=kh;var Nh="SelectValue",Ah=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,c=yn(Nh,n),{onValueNodeHasChildrenChange:u}=c,d=s!==void 0,f=Pe(t,c.onValueNodeChange);return ct(()=>{u(d)},[u,d]),l.jsx(ye.span,{...a,ref:f,style:{pointerEvents:"none"},children:Xh(c.value)?l.jsx(l.Fragment,{children:i}):s})});Ah.displayName=Nh;var LS="SelectIcon",_h=p.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return l.jsx(ye.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});_h.displayName=LS;var $S="SelectPortal",jh=e=>l.jsx(Ro,{asChild:!0,...e});jh.displayName=$S;var Bn="SelectContent",Rh=p.forwardRef((e,t)=>{const n=yn(Bn,e.__scopeSelect),[r,o]=p.useState();if(ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?qr.createPortal(l.jsx(Ph,{scope:e.__scopeSelect,children:l.jsx(xs.Slot,{scope:e.__scopeSelect,children:l.jsx("div",{children:e.children})})}),s):null}return l.jsx(Oh,{...e,ref:t})});Rh.displayName=Bn;var Wt=10,[Ph,Sn]=ir(Bn),FS="SelectContentImpl",zS=Tn.createSlot("SelectContent.RemoveScroll"),Oh=p.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:c,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:m,sticky:w,hideWhenDetached:v,avoidCollisions:g,...x}=e,b=yn(Bn,n),[S,k]=p.useState(null),[C,T]=p.useState(null),I=Pe(t,W=>k(W)),[N,_]=p.useState(null),[R,j]=p.useState(null),$=vs(n),[z,O]=p.useState(!1),V=p.useRef(!1);p.useEffect(()=>{if(S)return $i(S)},[S]),Ri();const B=p.useCallback(W=>{const[M,...G]=$().map(ce=>ce.ref.current),[te]=G.slice(-1),de=document.activeElement;for(const ce of W)if(ce===de||(ce==null||ce.scrollIntoView({block:"nearest"}),ce===M&&C&&(C.scrollTop=0),ce===te&&C&&(C.scrollTop=C.scrollHeight),ce==null||ce.focus(),document.activeElement!==de))return},[$,C]),K=p.useCallback(()=>B([N,S]),[B,N,S]);p.useEffect(()=>{z&&K()},[z,K]);const{onOpenChange:L,triggerPointerDownPosRef:A}=b;p.useEffect(()=>{if(S){let W={x:0,y:0};const M=te=>{var de,ce;W={x:Math.abs(Math.round(te.pageX)-(((de=A.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(te.pageY)-(((ce=A.current)==null?void 0:ce.y)??0))}},G=te=>{W.x<=10&&W.y<=10?te.preventDefault():S.contains(te.target)||L(!1),document.removeEventListener("pointermove",M),A.current=null};return A.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",G,{capture:!0})}}},[S,L,A]),p.useEffect(()=>{const W=()=>L(!1);return window.addEventListener("blur",W),window.addEventListener("resize",W),()=>{window.removeEventListener("blur",W),window.removeEventListener("resize",W)}},[L]);const[D,H]=Jh(W=>{const M=$().filter(de=>!de.disabled),G=M.find(de=>de.ref.current===document.activeElement),te=Zh(M,W,G);te&&setTimeout(()=>te.ref.current.focus())}),Y=p.useCallback((W,M,G)=>{const te=!V.current&&!G;(b.value!==void 0&&b.value===M||te)&&(_(W),te&&(V.current=!0))},[b.value]),Z=p.useCallback(()=>S==null?void 0:S.focus(),[S]),le=p.useCallback((W,M,G)=>{const te=!V.current&&!G;(b.value!==void 0&&b.value===M||te)&&j(W)},[b.value]),xe=r==="popper"?Sa:Mh,Ee=xe===Sa?{side:a,sideOffset:c,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:m,sticky:w,hideWhenDetached:v,avoidCollisions:g}:{};return l.jsx(Ph,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:Y,selectedItem:N,onItemLeave:Z,itemTextRefCallback:le,focusSelectedItem:K,selectedItemText:R,position:r,isPositioned:z,searchRef:D,children:l.jsx($o,{as:zS,allowPinchZoom:!0,children:l.jsx(jo,{asChild:!0,trapped:b.open,onMountAutoFocus:W=>{W.preventDefault()},onUnmountAutoFocus:ae(o,W=>{var M;(M=b.trigger)==null||M.focus({preventScroll:!0}),W.preventDefault()}),children:l.jsx(_o,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:W=>W.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:l.jsx(xe,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:W=>W.preventDefault(),...x,...Ee,onPlaced:()=>O(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ae(x.onKeyDown,W=>{const M=W.ctrlKey||W.altKey||W.metaKey;if(W.key==="Tab"&&W.preventDefault(),!M&&W.key.length===1&&H(W.key),["ArrowUp","ArrowDown","Home","End"].includes(W.key)){let te=$().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(W.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(W.key)){const de=W.target,ce=te.indexOf(de);te=te.slice(ce+1)}setTimeout(()=>B(te)),W.preventDefault()}})})})})})})});Oh.displayName=FS;var BS="SelectItemAlignedPosition",Mh=p.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=yn(Bn,n),i=Sn(Bn,n),[a,c]=p.useState(null),[u,d]=p.useState(null),f=Pe(t,I=>d(I)),h=vs(n),m=p.useRef(!1),w=p.useRef(!0),{viewport:v,selectedItem:g,selectedItemText:x,focusSelectedItem:b}=i,S=p.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&v&&g&&x){const I=s.trigger.getBoundingClientRect(),N=u.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),R=x.getBoundingClientRect();if(s.dir!=="rtl"){const de=R.left-N.left,ce=_.left-de,$e=I.left-ce,Ge=I.width+$e,_e=Math.max(Ge,N.width),Re=window.innerWidth-Wt,We=ga(ce,[Wt,Math.max(Wt,Re-_e)]);a.style.minWidth=Ge+"px",a.style.left=We+"px"}else{const de=N.right-R.right,ce=window.innerWidth-_.right-de,$e=window.innerWidth-I.right-ce,Ge=I.width+$e,_e=Math.max(Ge,N.width),Re=window.innerWidth-Wt,We=ga(ce,[Wt,Math.max(Wt,Re-_e)]);a.style.minWidth=Ge+"px",a.style.right=We+"px"}const j=h(),$=window.innerHeight-Wt*2,z=v.scrollHeight,O=window.getComputedStyle(u),V=parseInt(O.borderTopWidth,10),B=parseInt(O.paddingTop,10),K=parseInt(O.borderBottomWidth,10),L=parseInt(O.paddingBottom,10),A=V+B+z+L+K,D=Math.min(g.offsetHeight*5,A),H=window.getComputedStyle(v),Y=parseInt(H.paddingTop,10),Z=parseInt(H.paddingBottom,10),le=I.top+I.height/2-Wt,xe=$-le,Ee=g.offsetHeight/2,W=g.offsetTop+Ee,M=V+B+W,G=A-M;if(M<=le){const de=j.length>0&&g===j[j.length-1].ref.current;a.style.bottom="0px";const ce=u.clientHeight-v.offsetTop-v.offsetHeight,$e=Math.max(xe,Ee+(de?Z:0)+ce+K),Ge=M+$e;a.style.height=Ge+"px"}else{const de=j.length>0&&g===j[0].ref.current;a.style.top="0px";const $e=Math.max(le,V+v.offsetTop+(de?Y:0)+Ee)+G;a.style.height=$e+"px",v.scrollTop=M-le+v.offsetTop}a.style.margin=`${Wt}px 0`,a.style.minHeight=D+"px",a.style.maxHeight=$+"px",r==null||r(),requestAnimationFrame(()=>m.current=!0)}},[h,s.trigger,s.valueNode,a,u,v,g,x,s.dir,r]);ct(()=>S(),[S]);const[k,C]=p.useState();ct(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const T=p.useCallback(I=>{I&&w.current===!0&&(S(),b==null||b(),w.current=!1)},[S,b]);return l.jsx(US,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:m,onScrollButtonChange:T,children:l.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:l.jsx(ye.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Mh.displayName=BS;var HS="SelectPopperPosition",Sa=p.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Wt,...s}=e,i=ws(n);return l.jsx(Wd,{...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)"}})});Sa.displayName=HS;var[US,Ca]=ir(Bn,{}),Ta="SelectViewport",Dh=p.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Sn(Ta,n),i=Ca(Ta,n),a=Pe(t,s.onViewportChange),c=p.useRef(0);return l.jsxs(l.Fragment,{children:[l.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}),l.jsx(xs.Slot,{scope:n,children:l.jsx(ye.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ae(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const m=Math.abs(c.current-d.scrollTop);if(m>0){const w=window.innerHeight-Wt*2,v=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),x=Math.max(v,g);if(x<w){const b=x+m,S=Math.min(w,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}c.current=d.scrollTop})})})]})});Dh.displayName=Ta;var Lh="SelectGroup",[WS,VS]=ir(Lh),KS=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Xt();return l.jsx(WS,{scope:n,id:o,children:l.jsx(ye.div,{role:"group","aria-labelledby":o,...r,ref:t})})});KS.displayName=Lh;var $h="SelectLabel",Fh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=VS($h,n);return l.jsx(ye.div,{id:o.id,...r,ref:t})});Fh.displayName=$h;var bs="SelectItem",[qS,zh]=ir(bs),Bh=p.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=yn(bs,n),c=Sn(bs,n),u=a.value===r,[d,f]=p.useState(s??""),[h,m]=p.useState(!1),w=Pe(t,b=>{var S;return(S=c.itemRefCallback)==null?void 0:S.call(c,b,r,o)}),v=Xt(),g=p.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 l.jsx(qS,{scope:n,value:r,disabled:o,textId:v,isSelected:u,onItemTextChange:p.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:l.jsx(xs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:l.jsx(ye.div,{role:"option","aria-labelledby":v,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:w,onFocus:ae(i.onFocus,()=>m(!0)),onBlur:ae(i.onBlur,()=>m(!1)),onClick:ae(i.onClick,()=>{g.current!=="mouse"&&x()}),onPointerUp:ae(i.onPointerUp,()=>{g.current==="mouse"&&x()}),onPointerDown:ae(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:ae(i.onPointerMove,b=>{var S;g.current=b.pointerType,o?(S=c.onItemLeave)==null||S.call(c):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ae(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=c.onItemLeave)==null||S.call(c))}),onKeyDown:ae(i.onKeyDown,b=>{var k;((k=c.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(RS.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});Bh.displayName=bs;var zr="SelectItemText",Hh=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=yn(zr,n),a=Sn(zr,n),c=zh(zr,n),u=DS(zr,n),[d,f]=p.useState(null),h=Pe(t,x=>f(x),c.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,c.value,c.disabled)}),m=d==null?void 0:d.textContent,w=p.useMemo(()=>l.jsx("option",{value:c.value,disabled:c.disabled,children:m},c.value),[c.disabled,c.value,m]),{onNativeOptionAdd:v,onNativeOptionRemove:g}=u;return ct(()=>(v(w),()=>g(w)),[v,g,w]),l.jsxs(l.Fragment,{children:[l.jsx(ye.span,{id:c.textId,...s,ref:h}),c.isSelected&&i.valueNode&&!i.valueNodeHasChildren?qr.createPortal(s.children,i.valueNode):null]})});Hh.displayName=zr;var Uh="SelectItemIndicator",Wh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return zh(Uh,n).isSelected?l.jsx(ye.span,{"aria-hidden":!0,...r,ref:t}):null});Wh.displayName=Uh;var Ea="SelectScrollUpButton",Vh=p.forwardRef((e,t)=>{const n=Sn(Ea,e.__scopeSelect),r=Ca(Ea,e.__scopeSelect),[o,s]=p.useState(!1),i=Pe(t,r.onScrollButtonChange);return ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=c.scrollTop>0;s(u)};const c=n.viewport;return a(),c.addEventListener("scroll",a),()=>c.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?l.jsx(qh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop-c.offsetHeight)}}):null});Vh.displayName=Ea;var ka="SelectScrollDownButton",Kh=p.forwardRef((e,t)=>{const n=Sn(ka,e.__scopeSelect),r=Ca(ka,e.__scopeSelect),[o,s]=p.useState(!1),i=Pe(t,r.onScrollButtonChange);return ct(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=c.scrollHeight-c.clientHeight,d=Math.ceil(c.scrollTop)<u;s(d)};const c=n.viewport;return a(),c.addEventListener("scroll",a),()=>c.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?l.jsx(qh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop+c.offsetHeight)}}):null});Kh.displayName=ka;var qh=p.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Sn("SelectScrollButton",n),i=p.useRef(null),a=vs(n),c=p.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return p.useEffect(()=>()=>c(),[c]),ct(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),l.jsx(ye.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ae(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ae(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ae(o.onPointerLeave,()=>{c()})})}),GS="SelectSeparator",Gh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return l.jsx(ye.div,{"aria-hidden":!0,...r,ref:t})});Gh.displayName=GS;var Ia="SelectArrow",YS=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ws(n),s=yn(Ia,n),i=Sn(Ia,n);return s.open&&i.position==="popper"?l.jsx(Vd,{...o,...r,ref:t}):null});YS.displayName=Ia;var XS="SelectBubbleInput",Yh=p.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=p.useRef(null),s=Pe(r,o),i=xh(t);return p.useEffect(()=>{const a=o.current;if(!a)return;const c=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(c,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),l.jsx(ye.select,{...n,style:{...Th,...n.style},ref:s,defaultValue:t})});Yh.displayName=XS;function Xh(e){return e===""||e===void 0}function Jh(e){const t=ut(e),n=p.useRef(""),r=p.useRef(0),o=p.useCallback(i=>{const a=n.current+i;t(a),function c(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>c(""),1e3))}(a)},[t]),s=p.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return p.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Zh(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=JS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const c=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return c!==n?c:void 0}function JS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ZS=Eh,Qh=Ih,QS=Ah,eC=_h,tC=jh,ep=Rh,nC=Dh,tp=Fh,np=Bh,rC=Hh,oC=Wh,rp=Vh,op=Kh,sp=Gh;const ip=ZS,ap=QS,Na=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Qh,{ref:r,className:J("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,l.jsx(eC,{asChild:!0,children:l.jsx(ne.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Na.displayName=Qh.displayName;const lp=p.forwardRef(({className:e,...t},n)=>l.jsx(rp,{ref:n,className:J("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(ne.ChevronUp,{className:"h-4 w-4"})}));lp.displayName=rp.displayName;const cp=p.forwardRef(({className:e,...t},n)=>l.jsx(op,{ref:n,className:J("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(ne.ChevronDown,{className:"h-4 w-4"})}));cp.displayName=op.displayName;const Aa=p.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>l.jsx(tC,{children:l.jsxs(ep,{ref:o,className:J("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:[l.jsx(lp,{}),l.jsx(nC,{className:J("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),l.jsx(cp,{})]})}));Aa.displayName=ep.displayName;const sC=p.forwardRef(({className:e,...t},n)=>l.jsx(tp,{ref:n,className:J("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));sC.displayName=tp.displayName;const Hn=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(np,{ref:r,className:J("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:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(oC,{children:l.jsx(ne.Check,{className:"h-4 w-4"})})}),l.jsx(rC,{children:t})]}));Hn.displayName=np.displayName;const iC=p.forwardRef(({className:e,...t},n)=>l.jsx(sp,{ref:n,className:J("-mx-1 my-1 h-px bg-muted",e),...t}));iC.displayName=sp.displayName;var aC="Separator",up="horizontal",lC=["horizontal","vertical"],dp=p.forwardRef((e,t)=>{const{decorative:n,orientation:r=up,...o}=e,s=cC(r)?r:up,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return l.jsx(ye.div,{"data-orientation":s,...a,...o,ref:t})});dp.displayName=aC;function cC(e){return lC.includes(e)}var fp=dp;const hp=p.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>l.jsx(fp,{ref:o,decorative:n,orientation:t,className:J("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));hp.displayName=fp.displayName;const uC=Ju,dC=Ww,fC=Zu,pp=p.forwardRef(({className:e,...t},n)=>l.jsx(Uo,{className:J("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}));pp.displayName=Uo.displayName;const hC=Kr.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"}}),mp=p.forwardRef(({side:e="right",className:t,children:n,...r},o)=>l.jsxs(fC,{children:[l.jsx(pp,{}),l.jsxs(Wo,{ref:o,className:J(hC({side:e}),t),...r,children:[n,l.jsxs(Qu,{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:[l.jsx(ne.X,{className:"h-4 w-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));mp.displayName=Wo.displayName;const gp=({className:e,...t})=>l.jsx("div",{className:J("flex flex-col space-y-2 text-center sm:text-left",e),...t});gp.displayName="SheetHeader";const xp=p.forwardRef(({className:e,...t},n)=>l.jsx(Mn,{ref:n,className:J("text-lg font-semibold text-foreground",e),...t}));xp.displayName=Mn.displayName;const vp=p.forwardRef(({className:e,...t},n)=>l.jsx(Vo,{ref:n,className:J("text-sm text-muted-foreground",e),...t}));vp.displayName=Vo.displayName;const pC={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 mC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=y.useState(!1),[s,i]=y.useState(!1),[a,c]=y.useState(e),[u,d]=y.useState(!1),{toast:f}=Ii();y.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),y.useEffect(()=>{c(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},m=()=>{c(pC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{c(e),d(!1),o(!1)},v=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 l.jsxs(uC,{open:r,onOpenChange:o,children:[l.jsx(dC,{asChild:!0,children:l.jsxs(ze,{variant:"outline",size:"sm",className:n,children:[l.jsx(ne.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&l.jsx(xi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),l.jsxs(mp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[l.jsxs(gp,{children:[l.jsx(xp,{children:"Chat Settings"}),l.jsx(vp,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),l.jsxs("div",{className:"space-y-6 py-6",children:[l.jsxs(kr,{children:[l.jsx(Ir,{className:"pb-3",children:l.jsxs(Nr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.Server,{className:"h-5 w-5"}),"API Configuration"]})}),l.jsxs(Co,{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx(Dt,{htmlFor:"api-url",children:"API Base URL"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ds,{id:"api-url",value:a.api.baseUrl,onChange:g=>c(x=>({...x,api:{...x.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),l.jsx(ze,{variant:"outline",onClick:v,children:"Test"})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(Dt,{htmlFor:"enable-auth",children:"Enable Authentication"}),l.jsx(bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>c(x=>({...x,api:{...x.api,enableAuth:g}}))})]}),a.api.enableAuth&&l.jsxs("div",{className:"space-y-2",children:[l.jsx(Dt,{htmlFor:"auth-token",children:"Authentication Token"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ds,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>c(x=>({...x,api:{...x.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),l.jsx(ze,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?l.jsx(ne.EyeOff,{className:"h-4 w-4"}):l.jsx(ne.Eye,{className:"h-4 w-4"})})]})]})]})]}),l.jsxs(kr,{children:[l.jsx(Ir,{className:"pb-3",children:l.jsxs(Nr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),l.jsxs(Co,{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx(Dt,{htmlFor:"layout",children:"Layout Style"}),l.jsxs(ip,{value:a.ui.layout,onValueChange:g=>c(x=>({...x,ui:{...x.ui,layout:g}})),children:[l.jsx(Na,{children:l.jsx(ap,{})}),l.jsxs(Aa,{children:[l.jsx(Hn,{value:"sidebar",children:"Sidebar Layout"}),l.jsx(Hn,{value:"fullscreen",children:"Fullscreen"}),l.jsx(Hn,{value:"tabs",children:"Tabbed Interface"})]})]})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(Dt,{htmlFor:"theme",children:"Theme"}),l.jsxs(ip,{value:a.ui.theme,onValueChange:g=>c(x=>({...x,ui:{...x.ui,theme:g}})),children:[l.jsx(Na,{children:l.jsx(ap,{})}),l.jsxs(Aa,{children:[l.jsx(Hn,{value:"light",children:"Light"}),l.jsx(Hn,{value:"dark",children:"Dark"}),l.jsx(Hn,{value:"system",children:"System"})]})]})]}),l.jsx(hp,{}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(Dt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),l.jsx(bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>c(x=>({...x,ui:{...x.ui,showTimestamps:g}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(Dt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),l.jsx(bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>c(x=>({...x,ui:{...x.ui,showAgentNames:g}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(Dt,{htmlFor:"compact-messages",children:"Compact Messages"}),l.jsx(bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>c(x=>({...x,ui:{...x.ui,compactMessages:g}}))})]})]})]})]}),l.jsxs(kr,{children:[l.jsx(Ir,{className:"pb-3",children:l.jsxs(Nr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),l.jsxs(Co,{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx(Dt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),l.jsx(bn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>c(x=>({...x,behavior:{...x.behavior,autoSave:g}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx(Dt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),l.jsx(bn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>c(x=>({...x,behavior:{...x.behavior,enableStreaming:g}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx(Dt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),l.jsx(bn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>c(x=>({...x,behavior:{...x.behavior,showTypingIndicator:g}}))})]})]})]})]}),l.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[l.jsxs(ze,{variant:"outline",onClick:m,children:[l.jsx(ne.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ze,{variant:"outline",onClick:w,children:"Cancel"}),l.jsxs(ze,{onClick:h,disabled:!u,children:[l.jsx(ne.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function gC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){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=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),c=y.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?l.jsx(io,{...s,onThreadChange:c,children:l.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:l.jsx(us,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?l.jsx(io,{...s,onThreadChange:c,children:l.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:l.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&l.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:l.jsx(ya,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),l.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:l.jsx(us,{onError:s.onError,enableFileUpload:!0})})]})})}):l.jsx(io,{...s,onThreadChange:c,children:l.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&l.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:l.jsx(ya,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),l.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:l.jsx(us,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=jl,Ce.ChatInterface=us,Ce.ChatProviders=io,Ce.ChatSettings=mC,Ce.MarkdownContent=Ti,Ce.MessageComponent=ld,Ce.MessageList=Ui,Ce.ThreadManager=ya,Ce.applySettings=yS,Ce.chatApiClient=un,Ce.default=gC,Ce.del=_l,Ce.get=Ct,Ce.getChatToken=Il,Ce.getCurrentSettings=bS,Ce.getDefaultApiConfig=fh,Ce.getDefaultChatSettings=hh,Ce.onChatTokenChanged=Nl,Ce.post=Us,Ce.put=Al,Ce.setChatToken=Hs,Ce.useApi=so,Ce.useChatStream=zl,Ce.useMessages=qs,Ce.useMessagesReducer=$l,Ce.useStream=Ml,Ce.useThreads=mr,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|