teodor-new-chat-ui 4.0.7 β†’ 4.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -14,15 +14,15 @@
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 Ip(){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"),g=Symbol.for("react.offscreen"),w=Symbol.iterator,v="@@iterator";function m(k){if(k===null||typeof k!="object")return null;var U=w&&k[w]||k[v];return typeof U=="function"?U:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(k){{for(var U=arguments.length,re=new Array(U>1?U-1:0),ye=1;ye<U;ye++)re[ye-1]=arguments[ye];S("error",k,re)}}function S(k,U,re){{var ye=x.ReactDebugCurrentFrame,$e=ye.getStackAddendum();$e!==""&&(U+="%s",re=re.concat([$e]));var Ke=re.map(function(Pe){return String(Pe)});Ke.unshift("Warning: "+U),Function.prototype.apply.call(console[k],console,Ke)}}var I=!1,C=!1,T=!1,E=!1,N=!1,_;_=Symbol.for("react.module.reference");function P(k){return!!(typeof k=="string"||typeof k=="function"||k===r||k===s||N||k===o||k===u||k===d||E||k===g||I||C||T||typeof k=="object"&&k!==null&&(k.$$typeof===h||k.$$typeof===f||k.$$typeof===i||k.$$typeof===a||k.$$typeof===c||k.$$typeof===_||k.getModuleId!==void 0))}function j(k,U,re){var ye=k.displayName;if(ye)return ye;var $e=U.displayName||U.name||"";return $e!==""?re+"("+$e+")":re}function z(k){return k.displayName||"Context"}function G(k){if(k==null)return null;if(typeof k.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof k=="function")return k.displayName||k.name||null;if(typeof k=="string")return k;switch(k){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 k=="object")switch(k.$$typeof){case a:var U=k;return z(U)+".Consumer";case i:var re=k;return z(re._context)+".Provider";case c:return j(k,k.render,"ForwardRef");case f:var ye=k.displayName||null;return ye!==null?ye:G(k.type)||"Memo";case h:{var $e=k,Ke=$e._payload,Pe=$e._init;try{return G(Pe(Ke))}catch{return null}}}return null}var O=Object.assign,W=0,H,V,$,A,K,L,J;function Y(){}Y.__reactDisabledLog=!0;function ce(){{if(W===0){H=console.log,V=console.info,$=console.warn,A=console.error,K=console.group,L=console.groupCollapsed,J=console.groupEnd;var k={configurable:!0,enumerable:!0,value:Y,writable:!0};Object.defineProperties(console,{info:k,log:k,warn:k,error:k,group:k,groupCollapsed:k,groupEnd:k})}W++}}function pe(){{if(W--,W===0){var k={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},k,{value:H}),info:O({},k,{value:V}),warn:O({},k,{value:$}),error:O({},k,{value:A}),group:O({},k,{value:K}),groupCollapsed:O({},k,{value:L}),groupEnd:O({},k,{value:J})})}W<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var me=x.ReactCurrentDispatcher,q;function M(k,U,re){{if(q===void 0)try{throw Error()}catch($e){var ye=$e.stack.trim().match(/\n( *(at )?)/);q=ye&&ye[1]||""}return`
18
- `+q+k}}var D=!1,F;{var Q=typeof WeakMap=="function"?WeakMap:Map;F=new Q}function te(k,U){if(!k||D)return"";{var re=F.get(k);if(re!==void 0)return re}var ye;D=!0;var $e=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Ke;Ke=me.current,me.current=null,ce();try{if(U){var Pe=function(){throw Error()};if(Object.defineProperty(Pe.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Pe,[])}catch(kt){ye=kt}Reflect.construct(k,[],Pe)}else{try{Pe.call()}catch(kt){ye=kt}k.call(Pe.prototype)}}else{try{throw Error()}catch(kt){ye=kt}k()}}catch(kt){if(kt&&ye&&typeof kt.stack=="string"){for(var _e=kt.stack.split(`
17
+ */var $a;function Ip(){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"),g=Symbol.for("react.offscreen"),w=Symbol.iterator,v="@@iterator";function m(k){if(k===null||typeof k!="object")return null;var U=w&&k[w]||k[v];return typeof U=="function"?U:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(k){{for(var U=arguments.length,re=new Array(U>1?U-1:0),ye=1;ye<U;ye++)re[ye-1]=arguments[ye];S("error",k,re)}}function S(k,U,re){{var ye=x.ReactDebugCurrentFrame,ze=ye.getStackAddendum();ze!==""&&(U+="%s",re=re.concat([ze]));var Ke=re.map(function(Pe){return String(Pe)});Ke.unshift("Warning: "+U),Function.prototype.apply.call(console[k],console,Ke)}}var I=!1,C=!1,T=!1,E=!1,N=!1,_;_=Symbol.for("react.module.reference");function P(k){return!!(typeof k=="string"||typeof k=="function"||k===r||k===s||N||k===o||k===u||k===d||E||k===g||I||C||T||typeof k=="object"&&k!==null&&(k.$$typeof===h||k.$$typeof===f||k.$$typeof===i||k.$$typeof===a||k.$$typeof===c||k.$$typeof===_||k.getModuleId!==void 0))}function j(k,U,re){var ye=k.displayName;if(ye)return ye;var ze=U.displayName||U.name||"";return ze!==""?re+"("+ze+")":re}function z(k){return k.displayName||"Context"}function G(k){if(k==null)return null;if(typeof k.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof k=="function")return k.displayName||k.name||null;if(typeof k=="string")return k;switch(k){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 k=="object")switch(k.$$typeof){case a:var U=k;return z(U)+".Consumer";case i:var re=k;return z(re._context)+".Provider";case c:return j(k,k.render,"ForwardRef");case f:var ye=k.displayName||null;return ye!==null?ye:G(k.type)||"Memo";case h:{var ze=k,Ke=ze._payload,Pe=ze._init;try{return G(Pe(Ke))}catch{return null}}}return null}var O=Object.assign,W=0,H,V,$,A,K,L,J;function Y(){}Y.__reactDisabledLog=!0;function ce(){{if(W===0){H=console.log,V=console.info,$=console.warn,A=console.error,K=console.group,L=console.groupCollapsed,J=console.groupEnd;var k={configurable:!0,enumerable:!0,value:Y,writable:!0};Object.defineProperties(console,{info:k,log:k,warn:k,error:k,group:k,groupCollapsed:k,groupEnd:k})}W++}}function pe(){{if(W--,W===0){var k={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},k,{value:H}),info:O({},k,{value:V}),warn:O({},k,{value:$}),error:O({},k,{value:A}),group:O({},k,{value:K}),groupCollapsed:O({},k,{value:L}),groupEnd:O({},k,{value:J})})}W<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var me=x.ReactCurrentDispatcher,q;function M(k,U,re){{if(q===void 0)try{throw Error()}catch(ze){var ye=ze.stack.trim().match(/\n( *(at )?)/);q=ye&&ye[1]||""}return`
18
+ `+q+k}}var D=!1,F;{var Q=typeof WeakMap=="function"?WeakMap:Map;F=new Q}function te(k,U){if(!k||D)return"";{var re=F.get(k);if(re!==void 0)return re}var ye;D=!0;var ze=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Ke;Ke=me.current,me.current=null,ce();try{if(U){var Pe=function(){throw Error()};if(Object.defineProperty(Pe.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Pe,[])}catch(kt){ye=kt}Reflect.construct(k,[],Pe)}else{try{Pe.call()}catch(kt){ye=kt}k.call(Pe.prototype)}}else{try{throw Error()}catch(kt){ye=kt}k()}}catch(kt){if(kt&&ye&&typeof kt.stack=="string"){for(var _e=kt.stack.split(`
19
19
  `),yt=ye.stack.split(`
20
20
  `),rt=_e.length-1,st=yt.length-1;rt>=1&&st>=0&&_e[rt]!==yt[st];)st--;for(;rt>=1&&st>=0;rt--,st--)if(_e[rt]!==yt[st]){if(rt!==1||st!==1)do if(rt--,st--,st<0||_e[rt]!==yt[st]){var zt=`
21
- `+_e[rt].replace(" at new "," at ");return k.displayName&&zt.includes("<anonymous>")&&(zt=zt.replace("<anonymous>",k.displayName)),typeof k=="function"&&F.set(k,zt),zt}while(rt>=1&&st>=0);break}}}finally{D=!1,me.current=Ke,pe(),Error.prepareStackTrace=$e}var dr=k?k.displayName||k.name:"",Kn=dr?M(dr):"";return typeof k=="function"&&F.set(k,Kn),Kn}function Ie(k,U,re){return te(k,!1)}function He(k){var U=k.prototype;return!!(U&&U.isReactComponent)}function Te(k,U,re){if(k==null)return"";if(typeof k=="function")return te(k,He(k));if(typeof k=="string")return M(k);switch(k){case u:return M("Suspense");case d:return M("SuspenseList")}if(typeof k=="object")switch(k.$$typeof){case c:return Ie(k.render);case f:return Te(k.type,U,re);case h:{var ye=k,$e=ye._payload,Ke=ye._init;try{return Te(Ke($e),U,re)}catch{}}}return""}var Ae=Object.prototype.hasOwnProperty,Le={},Ve=x.ReactDebugCurrentFrame;function Me(k){if(k){var U=k._owner,re=Te(k.type,k._source,U?U.type:null);Ve.setExtraStackFrame(re)}else Ve.setExtraStackFrame(null)}function et(k,U,re,ye,$e){{var Ke=Function.call.bind(Ae);for(var Pe in k)if(Ke(k,Pe)){var _e=void 0;try{if(typeof k[Pe]!="function"){var yt=Error((ye||"React class")+": "+re+" type `"+Pe+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof k[Pe]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw yt.name="Invariant Violation",yt}_e=k[Pe](U,Pe,ye,re,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(rt){_e=rt}_e&&!(_e instanceof Error)&&(Me($e),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).",ye||"React class",re,Pe,typeof _e),Me(null)),_e instanceof Error&&!(_e.message in Le)&&(Le[_e.message]=!0,Me($e),b("Failed %s type: %s",re,_e.message),Me(null))}}}var Xe=Array.isArray;function at(k){return Xe(k)}function ft(k){{var U=typeof Symbol=="function"&&Symbol.toStringTag,re=U&&k[Symbol.toStringTag]||k.constructor.name||"Object";return re}}function ut(k){try{return ze(k),!1}catch{return!0}}function ze(k){return""+k}function ee(k){if(ut(k))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ft(k)),ze(k)}var ae=x.ReactCurrentOwner,he={key:!0,ref:!0,__self:!0,__source:!0},Be,qe;function Je(k){if(Ae.call(k,"ref")){var U=Object.getOwnPropertyDescriptor(k,"ref").get;if(U&&U.isReactWarning)return!1}return k.ref!==void 0}function xt(k){if(Ae.call(k,"key")){var U=Object.getOwnPropertyDescriptor(k,"key").get;if(U&&U.isReactWarning)return!1}return k.key!==void 0}function lt(k,U){typeof k.ref=="string"&&ae.current}function vt(k,U){{var re=function(){Be||(Be=!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(k,"key",{get:re,configurable:!0})}}function an(k,U){{var re=function(){qe||(qe=!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(k,"ref",{get:re,configurable:!0})}}var ur=function(k,U,re,ye,$e,Ke,Pe){var _e={$$typeof:t,type:k,key:U,ref:re,props:Pe,_owner:Ke};return _e._store={},Object.defineProperty(_e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(_e,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ye}),Object.defineProperty(_e,"_source",{configurable:!1,enumerable:!1,writable:!1,value:$e}),Object.freeze&&(Object.freeze(_e.props),Object.freeze(_e)),_e};function Pa(k,U,re,ye,$e){{var Ke,Pe={},_e=null,yt=null;re!==void 0&&(ee(re),_e=""+re),xt(U)&&(ee(U.key),_e=""+U.key),Je(U)&&(yt=U.ref,lt(U,$e));for(Ke in U)Ae.call(U,Ke)&&!he.hasOwnProperty(Ke)&&(Pe[Ke]=U[Ke]);if(k&&k.defaultProps){var rt=k.defaultProps;for(Ke in rt)Pe[Ke]===void 0&&(Pe[Ke]=rt[Ke])}if(_e||yt){var st=typeof k=="function"?k.displayName||k.name||"Unknown":k;_e&&vt(Pe,st),yt&&an(Pe,st)}return ur(k,_e,yt,$e,ye,ae.current,Pe)}}var Vr=x.ReactCurrentOwner,ks=x.ReactDebugCurrentFrame;function En(k){if(k){var U=k._owner,re=Te(k.type,k._source,U?U.type:null);ks.setExtraStackFrame(re)}else ks.setExtraStackFrame(null)}var Kr;Kr=!1;function qr(k){return typeof k=="object"&&k!==null&&k.$$typeof===t}function Es(){{if(Vr.current){var k=G(Vr.current.type);if(k)return`
21
+ `+_e[rt].replace(" at new "," at ");return k.displayName&&zt.includes("<anonymous>")&&(zt=zt.replace("<anonymous>",k.displayName)),typeof k=="function"&&F.set(k,zt),zt}while(rt>=1&&st>=0);break}}}finally{D=!1,me.current=Ke,pe(),Error.prepareStackTrace=ze}var dr=k?k.displayName||k.name:"",Kn=dr?M(dr):"";return typeof k=="function"&&F.set(k,Kn),Kn}function Ie(k,U,re){return te(k,!1)}function He(k){var U=k.prototype;return!!(U&&U.isReactComponent)}function Te(k,U,re){if(k==null)return"";if(typeof k=="function")return te(k,He(k));if(typeof k=="string")return M(k);switch(k){case u:return M("Suspense");case d:return M("SuspenseList")}if(typeof k=="object")switch(k.$$typeof){case c:return Ie(k.render);case f:return Te(k.type,U,re);case h:{var ye=k,ze=ye._payload,Ke=ye._init;try{return Te(Ke(ze),U,re)}catch{}}}return""}var Ae=Object.prototype.hasOwnProperty,Le={},Ve=x.ReactDebugCurrentFrame;function Me(k){if(k){var U=k._owner,re=Te(k.type,k._source,U?U.type:null);Ve.setExtraStackFrame(re)}else Ve.setExtraStackFrame(null)}function et(k,U,re,ye,ze){{var Ke=Function.call.bind(Ae);for(var Pe in k)if(Ke(k,Pe)){var _e=void 0;try{if(typeof k[Pe]!="function"){var yt=Error((ye||"React class")+": "+re+" type `"+Pe+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof k[Pe]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw yt.name="Invariant Violation",yt}_e=k[Pe](U,Pe,ye,re,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(rt){_e=rt}_e&&!(_e instanceof Error)&&(Me(ze),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).",ye||"React class",re,Pe,typeof _e),Me(null)),_e instanceof Error&&!(_e.message in Le)&&(Le[_e.message]=!0,Me(ze),b("Failed %s type: %s",re,_e.message),Me(null))}}}var Xe=Array.isArray;function at(k){return Xe(k)}function ft(k){{var U=typeof Symbol=="function"&&Symbol.toStringTag,re=U&&k[Symbol.toStringTag]||k.constructor.name||"Object";return re}}function ut(k){try{return $e(k),!1}catch{return!0}}function $e(k){return""+k}function ee(k){if(ut(k))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ft(k)),$e(k)}var ae=x.ReactCurrentOwner,he={key:!0,ref:!0,__self:!0,__source:!0},Be,qe;function Je(k){if(Ae.call(k,"ref")){var U=Object.getOwnPropertyDescriptor(k,"ref").get;if(U&&U.isReactWarning)return!1}return k.ref!==void 0}function xt(k){if(Ae.call(k,"key")){var U=Object.getOwnPropertyDescriptor(k,"key").get;if(U&&U.isReactWarning)return!1}return k.key!==void 0}function lt(k,U){typeof k.ref=="string"&&ae.current}function vt(k,U){{var re=function(){Be||(Be=!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(k,"key",{get:re,configurable:!0})}}function an(k,U){{var re=function(){qe||(qe=!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(k,"ref",{get:re,configurable:!0})}}var ur=function(k,U,re,ye,ze,Ke,Pe){var _e={$$typeof:t,type:k,key:U,ref:re,props:Pe,_owner:Ke};return _e._store={},Object.defineProperty(_e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(_e,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ye}),Object.defineProperty(_e,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ze}),Object.freeze&&(Object.freeze(_e.props),Object.freeze(_e)),_e};function Pa(k,U,re,ye,ze){{var Ke,Pe={},_e=null,yt=null;re!==void 0&&(ee(re),_e=""+re),xt(U)&&(ee(U.key),_e=""+U.key),Je(U)&&(yt=U.ref,lt(U,ze));for(Ke in U)Ae.call(U,Ke)&&!he.hasOwnProperty(Ke)&&(Pe[Ke]=U[Ke]);if(k&&k.defaultProps){var rt=k.defaultProps;for(Ke in rt)Pe[Ke]===void 0&&(Pe[Ke]=rt[Ke])}if(_e||yt){var st=typeof k=="function"?k.displayName||k.name||"Unknown":k;_e&&vt(Pe,st),yt&&an(Pe,st)}return ur(k,_e,yt,ze,ye,ae.current,Pe)}}var Vr=x.ReactCurrentOwner,ks=x.ReactDebugCurrentFrame;function En(k){if(k){var U=k._owner,re=Te(k.type,k._source,U?U.type:null);ks.setExtraStackFrame(re)}else ks.setExtraStackFrame(null)}var Kr;Kr=!1;function qr(k){return typeof k=="object"&&k!==null&&k.$$typeof===t}function Es(){{if(Vr.current){var k=G(Vr.current.type);if(k)return`
22
22
 
23
23
  Check the render method of \``+k+"`."}return""}}function Oa(k){return""}var Is={};function Ma(k){{var U=Es();if(!U){var re=typeof k=="string"?k:k.displayName||k.name;re&&(U=`
24
24
 
25
- Check the top-level render call using <`+re+">.")}return U}}function le(k,U){{if(!k._store||k._store.validated||k.key!=null)return;k._store.validated=!0;var re=Ma(U);if(Is[re])return;Is[re]=!0;var ye="";k&&k._owner&&k._owner!==Vr.current&&(ye=" It was passed a child from "+G(k._owner.type)+"."),En(k),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,ye),En(null)}}function ge(k,U){{if(typeof k!="object")return;if(at(k))for(var re=0;re<k.length;re++){var ye=k[re];qr(ye)&&le(ye,U)}else if(qr(k))k._store&&(k._store.validated=!0);else if(k){var $e=m(k);if(typeof $e=="function"&&$e!==k.entries)for(var Ke=$e.call(k),Pe;!(Pe=Ke.next()).done;)qr(Pe.value)&&le(Pe.value,U)}}}function Re(k){{var U=k.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 ye=G(U);et(re,k.props,"prop",ye,k)}else if(U.PropTypes!==void 0&&!Kr){Kr=!0;var $e=G(U);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",$e||"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 Qe(k){{for(var U=Object.keys(k.props),re=0;re<U.length;re++){var ye=U[re];if(ye!=="children"&&ye!=="key"){En(k),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ye),En(null);break}}k.ref!==null&&(En(k),b("Invalid attribute `ref` supplied to `React.Fragment`."),En(null))}}var Pt={};function ln(k,U,re,ye,$e,Ke){{var Pe=P(k);if(!Pe){var _e="";(k===void 0||typeof k=="object"&&k!==null&&Object.keys(k).length===0)&&(_e+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var yt=Oa();yt?_e+=yt:_e+=Es();var rt;k===null?rt="null":at(k)?rt="array":k!==void 0&&k.$$typeof===t?(rt="<"+(G(k.type)||"Unknown")+" />",_e=" Did you accidentally export a JSX literal instead of a component?"):rt=typeof k,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",rt,_e)}var st=Pa(k,U,re,$e,Ke);if(st==null)return st;if(Pe){var zt=U.children;if(zt!==void 0)if(ye)if(at(zt)){for(var dr=0;dr<zt.length;dr++)ge(zt[dr],k);Object.freeze&&Object.freeze(zt)}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 ge(zt,k)}if(Ae.call(U,"key")){var Kn=G(k),kt=Object.keys(U).filter(function(CC){return CC!=="key"}),Da=kt.length>0?"{key: someKey, "+kt.join(": ..., ")+": ...}":"{key: someKey}";if(!Pt[Kn+Da]){var SC=kt.length>0?"{"+kt.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+re+">.")}return U}}function le(k,U){{if(!k._store||k._store.validated||k.key!=null)return;k._store.validated=!0;var re=Ma(U);if(Is[re])return;Is[re]=!0;var ye="";k&&k._owner&&k._owner!==Vr.current&&(ye=" It was passed a child from "+G(k._owner.type)+"."),En(k),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,ye),En(null)}}function ge(k,U){{if(typeof k!="object")return;if(at(k))for(var re=0;re<k.length;re++){var ye=k[re];qr(ye)&&le(ye,U)}else if(qr(k))k._store&&(k._store.validated=!0);else if(k){var ze=m(k);if(typeof ze=="function"&&ze!==k.entries)for(var Ke=ze.call(k),Pe;!(Pe=Ke.next()).done;)qr(Pe.value)&&le(Pe.value,U)}}}function Re(k){{var U=k.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 ye=G(U);et(re,k.props,"prop",ye,k)}else if(U.PropTypes!==void 0&&!Kr){Kr=!0;var ze=G(U);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ze||"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 Qe(k){{for(var U=Object.keys(k.props),re=0;re<U.length;re++){var ye=U[re];if(ye!=="children"&&ye!=="key"){En(k),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ye),En(null);break}}k.ref!==null&&(En(k),b("Invalid attribute `ref` supplied to `React.Fragment`."),En(null))}}var Pt={};function ln(k,U,re,ye,ze,Ke){{var Pe=P(k);if(!Pe){var _e="";(k===void 0||typeof k=="object"&&k!==null&&Object.keys(k).length===0)&&(_e+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var yt=Oa();yt?_e+=yt:_e+=Es();var rt;k===null?rt="null":at(k)?rt="array":k!==void 0&&k.$$typeof===t?(rt="<"+(G(k.type)||"Unknown")+" />",_e=" Did you accidentally export a JSX literal instead of a component?"):rt=typeof k,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",rt,_e)}var st=Pa(k,U,re,ze,Ke);if(st==null)return st;if(Pe){var zt=U.children;if(zt!==void 0)if(ye)if(at(zt)){for(var dr=0;dr<zt.length;dr++)ge(zt[dr],k);Object.freeze&&Object.freeze(zt)}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 ge(zt,k)}if(Ae.call(U,"key")){var Kn=G(k),kt=Object.keys(U).filter(function(CC){return CC!=="key"}),Da=kt.length>0?"{key: someKey, "+kt.join(": ..., ")+": ...}":"{key: someKey}";if(!Pt[Kn+Da]){var SC=kt.length>0?"{"+kt.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:
@@ -34,8 +34,8 @@ React keys must be passed directly to JSX without using spread:
34
34
  `):" "+wl(i[0]):"as no adapter specified";throw new Ce("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Bs};function Hs(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Yn(null,e)}function yl(e){return Hs(e),e.headers=Ct.from(e.headers),e.data=zs.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),bl.getAdapter(e.adapter||xr.adapter,e)(e).then(function(r){return Hs(e),r.data=zs.call(e,e.transformResponse,r),r.headers=Ct.from(r.headers),r},function(r){return il(r)||(Hs(e),r&&r.response&&(r.response.data=zs.call(e,e.transformResponse,r.response),r.response.headers=Ct.from(r.response.headers))),Promise.reject(r)})}const Sl="1.12.2",so={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{so[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Cl={};so.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Sl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Ce(o(i," has been removed"+(n?" in "+n:"")),Ce.ERR_DEPRECATED);return n&&!Cl[i]&&(Cl[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}},so.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Km(e,t,n){if(typeof e!="object")throw new Ce("options must be an object",Ce.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 Ce("option "+s+" must be "+c,Ce.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Ce("Unknown option "+s,Ce.ERR_BAD_OPTION)}}const io={assertOptions:Km,validators:so},Gt=io.validators;let _n=class{constructor(t){this.defaults=t||{},this.interceptors={request:new nl,response:new nl}}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
35
  `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=An(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&io.assertOptions(r,{silentJSONParsing:Gt.transitional(Gt.boolean),forcedJSONParsing:Gt.transitional(Gt.boolean),clarifyTimeoutError:Gt.transitional(Gt.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:io.assertOptions(o,{encode:Gt.function,serialize:Gt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),io.assertOptions(n,{baseUrl:Gt.spelling("baseURL"),withXsrfToken:Gt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=Ct.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=[yl.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 g=n;for(;f<h;){const w=a[f++],v=a[f++];try{g=w(g)}catch(m){v.call(this,m);break}}try{d=yl.call(this,g)}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=An(this.defaults,t);const n=ul(t.baseURL,t.url,t.allowAbsoluteUrls);return tl(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){_n.prototype[t]=function(n,r){return this.request(An(r||{},{method:t,url:n,data:(r||{}).data}))}}),R.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(An(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}_n.prototype[t]=n(),_n.prototype[t+"Form"]=n(!0)});let qm=class Cp{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 Yn(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 Cp(function(o){t=o}),cancel:t}}};function Gm(e){return function(n){return e.apply(null,n)}}function Ym(e){return R.isObject(e)&&e.isAxiosError===!0}const Us={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(Us).forEach(([e,t])=>{Us[t]=e});function Tl(e){const t=new _n(e),n=za(_n.prototype.request,t);return R.extend(n,_n.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Tl(An(e,o))},n}const tt=Tl(xr);tt.Axios=_n,tt.CanceledError=Yn,tt.CancelToken=qm,tt.isCancel=il,tt.VERSION=Sl,tt.toFormData=to,tt.AxiosError=Ce,tt.Cancel=tt.CanceledError,tt.all=function(t){return Promise.all(t)},tt.spread=Gm,tt.isAxiosError=Ym,tt.mergeConfig=An,tt.AxiosHeaders=Ct,tt.formToJSON=e=>ol(R.isHTMLForm(e)?new FormData(e):e),tt.getAdapter=bl.getAdapter,tt.HttpStatusCode=Us,tt.default=tt;const{Axios:RC,AxiosError:PC,CanceledError:OC,isCancel:MC,CancelToken:DC,VERSION:LC,all:FC,Cancel:$C,isAxiosError:zC,spread:BC,toFormData:HC,AxiosHeaders:UC,HttpStatusCode:WC,formToJSON:VC,getAdapter:KC,mergeConfig:qC}=tt,kl=typeof window<"u"?window.__API_BASE_URL__:void 0,El=kl?kl.replace(/\/+$/,""):void 0;let ao=null;const Ws=new Set;function Il(){return ao}function Vs(e){ao=e,Ws.forEach(t=>t(e))}function Nl(e){return Ws.add(e),()=>Ws.delete(e)}const Ot=tt.create({...El?{baseURL:El}:{},timeout:3e4,withCredentials:!0});Ot.interceptors.request.use(e=>(ao&&(e.headers.Authorization=`Bearer ${ao}`),e)),Ot.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Et(e,t){return Ot.defaults.baseURL?(await Ot.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ks(e,t,n){return Ot.defaults.baseURL?(await Ot.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Al(e,t,n){return Ot.defaults.baseURL?(await Ot.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function _l(e,t){return Ot.defaults.baseURL?(await Ot.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function It(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class jl{get baseUrl(){const t=Ot.defaults.baseURL||"";return String(t).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(t){t.baseUrl&&(Ot.defaults.baseURL=String(t.baseUrl).replace(/\/+$/g,"")),t.authToken!==void 0&&Vs(t.authToken)}getAuthToken(){return Il()}setAuthToken(t){Vs(t)}onTokenChange(t){return Nl(t)}async listThreads(){const t=await Et("/chat/threads"),n=It(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Ks("/chat/threads",t?{title:t}:void 0);return It(r)}async updateThread(t,n){const r=await Al(`/chat/threads/${t}`,{title:n});return It(r)}async deleteThread(t){const n=await _l(`/chat/threads/${t}`);return It(n)}async threadInfo(t){const n=await Et(`/chat/threads/${t}/info`);return It(n)}async listAgents(){const t=await Et("/chat/agents"),n=It(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Et(`/chat/agents/${t}`);return It(n)}async getAgentSchema(t){const n=await Et(`/chat/agents/${t}/schema`);return It(n)}async getMessages(t){const n=await Et(`/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 It(n)}async getState(t){const n=await Et(`/chat/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return It(n)}async getStateHistory(t){const n=await Et(`/chat/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return It(n)}async listCheckpoints(t){const n=await Et(`/chat/threads/${t}/checkpoints`,{params:{thread_id:t}});return It(n)}async resume(t){const n=await Ks("/chat/runs/resume",{thread_id:t.threadId,value:t.value});return It(n)}}const hn=new jl,Rl=y.createContext(null);function Xm({children:e,apiConfig:t}){const n=hn;y.useEffect(()=>{t&&n.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[n,t]);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 lo(){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 Jm(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 Zm={isStreaming:!1,error:null,streamingAssistantId:null,lastCheckpointId:null,lastCheckpointNs:null};function Qm({children:e}){const[t,n]=y.useReducer(Jm,Zm);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 eg(){const e=y.useContext(Ol);if(!e)throw new Error("useStreamDispatch must be used within StreamProvider");return e}function tg(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 ng(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 rg(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await ng(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),og=y.createContext(null);function sg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,onThreadChange:o,onError:s}){const{api:i}=lo(),[a,c]=y.useState([]),[u,d]=y.useState(t),[f,h]=y.useState(!1),[g,w]=y.useState(!1),[v,m]=y.useState(void 0),[x,b]=y.useState(void 0),S=y.useRef(!1),I=y.useRef([]),C=y.useRef(null),T=y.useRef(null);y.useRef(!1);const E=y.useRef(u);y.useEffect(()=>{E.current=u},[u]);const N=y.useContext(og),_=y.useCallback((L,J)=>new Promise((Y,ce)=>{const pe=async()=>{S.current=!0;try{console.log(`[ThreadProvider] Executing operation: ${J||"unnamed"}`),await L(),Y()}catch(me){console.error(`[ThreadProvider] Operation "${J}" failed:`,me),ce(me)}finally{S.current=!1;const me=I.current.shift();me&&me().catch(()=>{})}};S.current?(I.current.push(pe),console.log(`[ThreadProvider] Queued operation: ${J||"unnamed"}`)):pe().catch(me=>{ce(me)})}),[]),P=y.useCallback(async()=>{h(!0);try{const L=await i.listThreads();c(L)}catch(L){console.error("[ThreadProvider] Failed to refresh threads:",L),s==null||s(String(L))}finally{h(!1)}},[i,s]),j=y.useCallback(async L=>{const J=await i.createThread(L),Y=typeof J=="string"?J:J.threadId;return await P(),d(Y),Y},[i,P]),z=y.useCallback(async L=>{await i.deleteThread(L),u===L&&(d(null),N==null||N.onThreadCleared()),await P()},[i,u,P,N]),G=y.useCallback(async(L,J)=>{try{await i.updateThread(L,J),c(Y=>Y.map(ce=>ce.threadId===L?{...ce,title:J}:ce))}catch(Y){throw await P(),Y}},[i,P]),O=y.useCallback(async(L,J,Y,ce=!1)=>{await _(async()=>{if(T.current===L&&!ce){console.log("[ThreadProvider] Skipping load for thread:",L),T.current=null;return}if(C.current===L&&!ce){console.log("[ThreadProvider] Load already in progress for thread:",L);return}C.current=L,w(!0);try{const pe=await i.getMessages({threadId:L,checkpointId:J,checkpointNs:Y});N==null||N.onThreadLoaded(L,pe),m((pe==null?void 0:pe.checkpointId)??void 0),b((pe==null?void 0:pe.checkpointNs)??void 0)}finally{C.current=null,w(!1)}},`loadThread-${L}`)},[i,_,N]),W=y.useCallback(async()=>{console.log("[ThreadProvider] πŸ”„ clearCurrentThread called"),await _(async()=>{u&&(T.current=u),N==null||N.onThreadCleared(),d(null),m(void 0),b(void 0);try{localStorage.removeItem("lastThreadId")}catch(L){console.warn("[ThreadProvider] Failed to clear localStorage:",L)}},"clearCurrentThread")},[u,_,N]),H=y.useCallback(async L=>{const J=await i.listCheckpoints(L);return tg(J,L)},[i]),V=y.useCallback(async(L,J)=>{if(!u)throw new Error("No active thread");await O(u,L,J??void 0,!0)},[u,O]),$=y.useCallback(async()=>{if(!u)throw new Error("No active thread");await O(u,void 0,void 0,!0)},[u,O]),A=y.useCallback(async(L,J,Y)=>{if(!u)throw new Error("No active thread to handle interrupt");try{console.log(`[ThreadProvider] Handling interrupt ${L}: ${J?"approved":"rejected"}`);const ce=!!J;await i.resume({threadId:u,value:ce}),console.log(`[ThreadProvider] Interrupt ${L} handled successfully`)}catch(ce){throw console.error(`[ThreadProvider] Failed to handle interrupt ${L}:`,ce),ce}},[i,u]);y.useEffect(()=>{if(o==null||o(u),u)try{localStorage.setItem("lastThreadId",u)}catch(L){console.warn("[ThreadProvider] Failed to persist thread ID:",L)}},[u,o]),y.useEffect(()=>{let L=!0;return(async()=>{try{if(await P(),!L)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))}})(),()=>{L=!1}},[]);const K={threads:a,currentThreadId:u,isLoadingThreads:f,isLoadingThread:g,setCurrentThreadId:d,createThread:j,deleteThread:z,renameThread:G,refreshThreads:P,loadThread:O,clearCurrentThread:W,listCheckpoints:H,navigateToCheckpoint:V,returnToLatest:$,handleInterrupt:A};return l.jsx(Dl.Provider,{value:K,children:e})}function qs(){const e=y.useContext(Dl);if(!e)throw new Error("useThreads must be used within ThreadProvider");return e}function ig(e){return e.type!=="thread_info"&&e.type!=="token"}const ag={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function lg(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:Gs(((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=Gs(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=Gs(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 Ll(e=[]){const[t,n]=y.useReducer(lg,{...ag,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=hg(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??Ys(e.messages);return o?{...e,messages:Xs(e.messages,o,t.delta)}:e}if(t.type==="message_end"){const o=e.assemblingId??Ys(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?Xs(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=fg(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??Ys(e.messages),s={type:"interrupt",value:t.value};if(o)return{...e,assemblingId:null,messages:Xs(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 Gs(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 cg(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Ys(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function ug(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 Xs(e,t,n){return ug(e,t,r=>({...r,content:dg(r.content,n)}))}function dg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function fg(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 cg(e,r,s)}return e}function hg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const pg={MODE:"library"};function mg(){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:js&&js.tagName.toUpperCase()==="SCRIPT"&&js.src||new URL("index.umd.js",document.baseURI).href}<"u"?pg: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 gg(){return!mg()}function xg({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){gg()&&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(ig(a)){t(a);return}n==null||n(a)},[t,r,e,n]),i=y.useCallback(()=>{o.current=null},[]);return{handleEvent:s,reset:i}}function $l(e={}){const t=e.baseUrl??"/api/chat",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,g]=y.useState(null),[w,v]=y.useState(0),[m,x]=y.useState(!1),b=y.useRef(null),S=y.useRef(!0),I=y.useRef(0),C=y.useCallback(_=>{o(_)},[]),T=y.useCallback(()=>{var _;(_=b.current)==null||_.abort(),b.current=null,a(!1),x(!1)},[]),E=y.useCallback(()=>{f(""),g(null),u(null)},[]),N=y.useCallback((_,P,j)=>{b.current&&(b.current.abort(),b.current=null),a(!0),u(null),e.autoAppendAssistant!==!1&&f("");const z=new AbortController;return b.current=z,(async()=>{var O,W,H,V,$,A,K,L;const G=J=>{var Y;try{const ce=JSON.parse(JSON.stringify(J));return(Y=ce==null?void 0:ce.payload)!=null&&Y.files_info&&Array.isArray(ce.payload.files_info)&&(ce.payload.files_info=ce.payload.files_info.map(pe=>({...pe,data:pe!=null&&pe.data?`<base64 ${String(pe.data).length} chars>`:pe==null?void 0:pe.data}))),ce}catch{return J}};try{let J={};try{if(r)J={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ae=window.__AUTH_TOKEN__,Le=((O=window.localStorage)==null?void 0:O.getItem("authToken"))||null;let Ve=null;try{const et=(W=window.localStorage)==null?void 0:W.getItem("chat-settings");et&&(Ve=((H=JSON.parse(et))==null?void 0:H.apiKey)||null)}catch{}const Me=Ae||Le||Ve||null;Me&&(J={Authorization:`Bearer ${Me}`})}}catch{}console.debug("[use-chat] POST",t+n,G(_));const Y=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...J,...s.current},body:JSON.stringify(_),signal:z.signal});if(!Y.ok||!Y.body){const Te=await Y.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",Y.status,Te==null?void 0:Te.slice(0,500)),new Error(`stream ${Y.status}${Te?": "+Te:""}`)}x(!0);const ce=Y.body.getReader(),pe=new TextDecoder;let me="",q=[],M=I.current,D=null;const F=()=>{if(q.length){const Te=q.join("");q=[],S.current&&f(Ae=>Ae+Te)}D=null},Q=()=>{typeof window<"u"&&D==null&&(D=requestAnimationFrame(F))};let te=Date.now();const Ie=setInterval(()=>{var Te;if(Date.now()-te>2e4){const Ae="Stream idle timeout";u(Ae),z.abort(),(Te=j==null?void 0:j.onError)==null||Te.call(j,Ae)}},5e3),He=1024*1024;try{const Te=Y.headers.get("X-Thread-Id")||Y.headers.get("x-thread-id"),Ae=Y.headers.get("X-Thread-Created")||Y.headers.get("x-thread-created"),Le=Te??null,Ve=String(Ae??"").toLowerCase()==="true";for((V=j==null?void 0:j.onOpen)==null||V.call(j,{threadId:Le,created:Ve});;){const{value:Me,done:et}=await ce.read();if(et)break;me+=pe.decode(Me,{stream:!0}),me.length>He&&(me="",console.warn("Stream buffer reset: exceeded 1MB"));let Xe;for(;(Xe=me.indexOf(`
36
36
 
37
- `))>=0;){const at=me.slice(0,Xe);me=me.slice(Xe+2);const ft=wg(at);if(!ft)continue;let ut;try{ut=JSON.parse(ft)}catch{console.debug("[use-chat] malformed SSE:",ft.slice(0,200));continue}const ze=vg(ut)?ut.data:ut;te=Date.now(),P==null||P(ze);const ee=ze.seq;if(ee!==void 0){if(ee<=M)continue;M>0&&ee>M+1&&(($=j==null?void 0:j.onGap)==null||$.call(j,{from:M,to:ee})),M=ee,I.current=ee,v(ee)}if(ze.type==="token"&&e.autoAppendAssistant!==!1)q.push(ze.content),Q();else if(ze.type==="message_delta"){const ae=ze.delta.filter(he=>he.type==="text").map(he=>he.text).join("");ae&&e.autoAppendAssistant!==!1&&(q.push(ae),Q())}else D!==null&&cancelAnimationFrame(D),F(),ze.type==="checkpoint"?g(ze.checkpointId):ze.type==="error"&&u(ze.message)}}F()}catch(Te){if(Te.name!=="AbortError"){const Ae=Te.message||String(Te);u(Ae),(A=j==null?void 0:j.onError)==null||A.call(j,Ae)}}finally{try{await ce.cancel()}catch{}finally{(K=ce.releaseLock)==null||K.call(ce)}D!==null&&typeof window<"u"&&window.cancelAnimationFrame(D),clearInterval(Ie),a(!1),x(!1),b.current=null}}catch(J){if(J.name!=="AbortError"){const Y=J.message||String(J);u(Y),(L=j==null?void 0:j.onError)==null||L.call(j,Y)}}finally{a(!1),x(!1),b.current=null}})(),{close:()=>z.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:m,stream:N,stop:T,clear:E,setToken:C}}function vg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function wg(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 zl=y.createContext(null);function bg({children:e,enableFileAgentRouting:t=!1,fileAgentId:n="invoice_reader"}){const{api:r,baseUrl:o}=lo(),{currentThreadId:s,setCurrentThreadId:i,isLoadingThread:a}=qs(),c=eg(),{state:u,dispatch:d,seed:f,prepend:h,pushUser:g,onEvent:w,reset:v}=Ll(),[m,x]=y.useState(!1),[b,S]=y.useState(!1),[I,C]=y.useState(null),[T,E]=y.useState(void 0),[N,_]=y.useState(void 0),P=20,j=y.useRef(s);y.useEffect(()=>{j.current=s},[s]);const z=y.useRef(null),G=y.useRef(!1),O=y.useCallback(()=>{G.current=!0},[]),{isStreaming:W,error:H,stream:V,stop:$,setToken:A}=$l({baseUrl:o,token:null});y.useEffect(()=>{const D=r.getAuthToken();A(D)},[r,A]),y.useEffect(()=>{c(W?{type:"STREAM_START",assistantId:u.assemblingId??void 0}:{type:"STREAM_END"})},[W,u.assemblingId,c]),y.useEffect(()=>{c(H?{type:"STREAM_ERROR",error:H}:{type:"CLEAR_ERROR"})},[H,c]),y.useEffect(()=>{u.lastCheckpointId&&c({type:"UPDATE_CHECKPOINT",checkpointId:u.lastCheckpointId,checkpointNs:u.lastCheckpointNs??void 0})},[u.lastCheckpointId,u.lastCheckpointNs,c]),y.useEffect(()=>{c({type:"UPDATE_ASSEMBLING_ID",assistantId:u.assemblingId})},[u.assemblingId,c]);const K=y.useCallback((D,F)=>{const Q=Array.isArray(D==null?void 0:D.messages)?D.messages:[];F==="replace"?(console.log("[MessagesProvider] Replacing messages, count:",Q.length),f(Q,{checkpointId:(D==null?void 0:D.checkpointId)??null,checkpointNs:(D==null?void 0:D.checkpointNs)??null})):F==="prepend"&&Q.length&&(console.log("[MessagesProvider] Prepending messages, count:",Q.length),h(Q)),C((D==null?void 0:D.nextCursor)??null),x(!!(D!=null&&D.hasMore)),E(te=>(D==null?void 0:D.checkpointId)??te??void 0),_(te=>(D==null?void 0:D.checkpointNs)??te??void 0)},[f,h]),L=y.useCallback(D=>{const F=D.threadId,Q=!!D.created,te=!!D.ready;if(s!==F){const Ie=!s&&u.messages.length<=1;Ie&&(z.current=F),i(F),(te||Q||Ie)&&O();return}(te||Q)&&O()},[s,u.messages.length,i,O]),J=y.useCallback(({from:D,to:F})=>{const Q=j.current;Q&&console.warn(`[MessagesProvider] Stream sequence gap detected (${D} -> ${F}) for thread ${Q}`)},[]),{handleEvent:Y,reset:ce}=xg({onThreadInfo:L,onMessageEvent:w,onUnhandledEvent:D=>{console.warn(`[MessagesProvider] Unhandled stream event type: ${D.type}`,D)},onSequenceGap:J}),pe=y.useCallback(async D=>{if(!s)throw new Error("No active thread");if(b||!m)return;const F=I;if(F){S(!0);try{const Q=await r.getMessages({threadId:s,checkpointId:T,checkpointNs:N,limit:(D==null?void 0:D.limit)??P,beforeId:F});K(Q,"prepend")}finally{S(!1)}}},[r,s,T,N,I,m,b,K,P]),me=y.useCallback(()=>{console.log("[MessagesProvider] Clearing messages"),v([]),x(!1),S(!1),C(null),E(void 0),_(void 0)},[v]),q=y.useCallback(async(D,F)=>{var et;!s&&!(F!=null&&F.payloadExtras)&&console.warn("[MessagesProvider] No thread ID - message will create new thread");const Q=(F==null?void 0:F.attachments)||[],{contentParts:te,filesInfo:Ie}=await rg(r,Q),He=[...te];D&&D.trim()&&He.push({type:"text",text:D.trim()});const Te={id:((et=crypto.randomUUID)==null?void 0:et.call(crypto))||`user-${Date.now()}`,role:"user",content:He,createdAt:new Date().toISOString(),checkpointId:(F==null?void 0:F.checkpointId)??u.lastCheckpointId??void 0,checkpointNs:(F==null?void 0:F.checkpointNs)??u.lastCheckpointNs??void 0};g(Te);const Ae={...Te,content:He},Le={...(F==null?void 0:F.payloadExtras)??{}},Ve=Q&&Q.length>0,Me={...s?{threadId:s}:{},payload:{messages:[Ae],files_info:Ie,...t&&Ve&&n?{active_agent:n}:{},...Le},checkpointId:(F==null?void 0:F.checkpointId)??u.lastCheckpointId??void 0,checkpointNs:(F==null?void 0:F.checkpointNs)??u.lastCheckpointNs??void 0,nodeFilter:F==null?void 0:F.nodeFilter,config:F==null?void 0:F.config};ce(),O(),V(Me,Xe=>{Y(Xe)},{onError:Xe=>console.warn("[MessagesProvider] Stream error:",Xe),onOpen:({threadId:Xe,created:at})=>{if(!s&&Xe){const ft=u.messages.length<=1;ft&&(z.current=Xe),i(Xe),(at||ft)&&O()}},onGap:J})},[s,g,V,Y,ce,J,u.lastCheckpointId,u.lastCheckpointNs,u.messages.length,r,O,i,t,n]),M={messages:u.messages,assemblingId:u.assemblingId,lastUserMessage:null,hasMoreHistory:m,isLoadingHistory:b,send:q,stop:$,loadOlderMessages:pe,clearMessages:me};return l.jsx(zl.Provider,{value:M,children:e})}function yg(e){return l.jsx(bg,{...e})}function Bl(){const e=y.useContext(zl);if(!e)throw new Error("useMessages must be used within MessagesProvider");return e}function Hl({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:c}){return l.jsx(Xm,{apiConfig:t,children:l.jsx(Qm,{children:l.jsx(sg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,onError:a,onThreadChange:c,children:l.jsx(yg,{enableFileAgentRouting:s,fileAgentId:i,children:e})})})})}const Ul=y.createContext(null);function Sg({children:e}){const t=lo(),n=Ml(),r=qs(),o=Bl(),s=y.useMemo(()=>({baseUrl:t.baseUrl,token:t.token,setToken:t.setToken,api:t.api,threads:r.threads,currentThreadId:r.currentThreadId,setCurrentThreadId:r.setCurrentThreadId,isLoadingThreads:r.isLoadingThreads,isLoadingThread:r.isLoadingThread,refreshThreads:r.refreshThreads,createThread:r.createThread,deleteThread:r.deleteThread,renameThread:r.renameThread,loadThread:r.loadThread,clearCurrentThread:r.clearCurrentThread,listCheckpoints:r.listCheckpoints,navigateToCheckpoint:r.navigateToCheckpoint,returnToLatest:r.returnToLatest,handleInterrupt:r.handleInterrupt,isStreaming:n.isStreaming,error:n.error,streamingAssistantId:n.streamingAssistantId,lastCheckpointId:n.lastCheckpointId,lastCheckpointNs:n.lastCheckpointNs,messages:o.messages,hasMoreHistory:o.hasMoreHistory,isLoadingHistory:o.isLoadingHistory,loadOlderMessages:o.loadOlderMessages,historyPageSize:20,send:o.send,stop:o.stop}),[t,n,r,o]);return l.jsx(Ul.Provider,{value:s,children:e})}function co(e){const{children:t,...n}=e;return l.jsx(Hl,{...n,children:l.jsx(Sg,{children:t})})}function wr(){const e=y.useContext(Ul);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function Z(...e){return kp.twMerge(Tp.clsx(e))}const Cg=Yr.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"}}),Oe=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?In.Slot:"button";return l.jsx(i,{className:Z(Cg({variant:t,size:n,className:e})),ref:s,...o})});Oe.displayName="Button";const Wl=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}));Wl.displayName="Textarea";function Tg({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,g]=y.useState(e),[w,v]=y.useTransition(),m=y.useRef(null);y.useEffect(()=>{g(e??""),m.current&&(m.current.style.height="auto",m.current.style.height=`${m.current.scrollHeight}px`)},[e,t]);const x=y.useCallback(()=>{const N=m.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 P=i(_);P&&typeof P.then=="function"?P.then(()=>{g(""),m.current&&(m.current.style.height="auto")}).catch(()=>{}):(g(""),m.current&&(m.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(N=>{g(N.target.value),m.current&&(m.current.style.height="auto",m.current.style.height=`${m.current.scrollHeight}px`)},[]),I=y.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),b()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[b,t,a]),E=`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(Wl,{ref:m,value:h,onChange:S,onKeyDown:I,placeholder:t?"Edit your message...":n,className:E,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(Oe,{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(Oe,{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 kg=y.memo(Tg),uo=0,pn=1,Xn=2,Vl=4;function Kl(e){return()=>e}function Eg(e){e()}function ql(e,t){return n=>e(t(n))}function Gl(e,t){return()=>e(t)}function Ig(e,t){return n=>e(t,n)}function Js(e){return e!==void 0}function Ng(...e){return()=>{e.map(Eg)}}function Jn(){}function fo(e,t){return t(e),e}function Ag(e,t){return t(e)}function Ge(...e){return e}function Fe(e,t){return e(pn,t)}function ke(e,t){e(uo,t)}function Zs(e){e(Xn)}function nt(e){return e(Vl)}function ue(e,t){return Fe(e,Ig(t,uo))}function Ht(e,t){const n=e(pn,r=>{n(),t(r)});return n}function Yl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Xl(e,t){return e===t}function Ye(e=Xl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function we(e){return t=>n=>{e(n)&&t(n)}}function oe(e){return t=>ql(t,e)}function Yt(e){return t=>()=>{t(e)}}function B(e,...t){const n=_g(...t);return(r,o)=>{switch(r){case Xn:Zs(e);return;case pn:return Fe(e,n(o))}}}function Xt(e,t){return n=>r=>{n(t=e(t,r))}}function jn(e){return t=>n=>{e>0?e--:t(n)}}function cn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ee(...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);Fe(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 _g(...e){return t=>e.reduceRight(Ag,t)}function jg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case pn:return s?n===s?void 0:(r(),n=s,t=Fe(e,s),t):(r(),Jn);case Xn:r(),n=null;return}}}function X(e){let t=e;const n=je();return(r,o)=>{switch(r){case uo:t=o;break;case pn:{o(t);break}case Vl:return t}return n(r,o)}}function pt(e,t){return fo(X(t),n=>ue(e,n))}function je(){const e=[];return(t,n)=>{switch(t){case uo:e.slice().forEach(r=>{r(n)});return;case Xn:e.splice(0,e.length);return;case pn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Nt(e){return fo(je(),t=>ue(e,t))}function De(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Rg(),singleton:n}}const Rg=()=>Symbol();function Pg(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 ot(...e){const t=je(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Fe(s,c=>{n[i]=c,r=r|a,r===o&&ke(t,n)})}),function(s,i){switch(s){case Xn:{Zs(t);return}case pn:return r===o&&i(n),Fe(t,i)}}}function xe(e,t=Xl){return B(e,Ye(t))}function Qs(...e){return function(t,n){switch(t){case Xn:return;case pn:return Ng(...e.map(r=>Fe(r,n)))}}}var Tt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Tt||{});const Og={0:"debug",3:"error",1:"log",2:"warn"},Mg=()=>typeof globalThis>"u"?window:globalThis,mn=De(()=>{const e=X(3);return{log:X((t,n,r=1)=>{var o;const s=(o=Mg().VIRTUOSO_LOG_LEVEL)!=null?o:nt(e);r>=s&&console[Og[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Rn(e,t,n){return ei(e,t,n).callbackRef}function ei(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 Dg(e,t,n,r,o,s,i,a,c){const u=y.useCallback(d=>{const f=Lg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const g=h.lastElementChild.dataset.viewportType==="window";let w;g&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:g?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,m=i?a?i.scrollWidth:i.scrollHeight:g?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:g?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:m,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?Jl("column-gap",getComputedStyle(d).columnGap,o):Jl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ei(u,n,c)}function Lg(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},Tt.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 Jl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Tt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Zl(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 g=t.getBoundingClientRect(),w=u.top-g.top;h=g.height-Math.max(0,w),f=w+t.scrollTop}else{const g=i.current.ownerDocument.defaultView;h=g.innerHeight-Math.max(0,u.top),f=u.top+g.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ei(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 wt=De(()=>{const e=je(),t=je(),n=X(0),r=je(),o=X(0),s=je(),i=je(),a=X(0),c=X(0),u=X(0),d=X(0),f=je(),h=je(),g=X(!1),w=X(!1),v=X(!1);return ue(B(e,oe(({scrollTop:m})=>m)),t),ue(B(e,oe(({scrollHeight:m})=>m)),i),ue(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:g,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),br={lvl:0};function Ql(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 Ue(e){return e===br}function yr(e,t){if(!Ue(e))return t===e.k?e.v:t<e.k?yr(e.l,t):yr(e.r,t)}function Ut(e,t,n="k"){if(Ue(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Ut(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Ut(e.l,t,n)}function At(e,t,n){return Ue(e)?nc(t,n,1):t===e.k?it(e,{k:t,v:n}):t<e.k?rc(it(e,{l:At(e.l,t,n)})):rc(it(e,{r:At(e.r,t,n)}))}function Zn(){return br}function ho(e,t,n){if(Ue(e))return[];const r=Ut(e,t)[0];return Fg(ni(e,r,n))}function ti(e,t){if(Ue(e))return br;const{k:n,l:r,r:o}=e;if(t===n){if(Ue(r))return o;if(Ue(o))return r;{const[s,i]=tc(r);return po(it(e,{k:s,l:ec(r),v:i}))}}else return t<n?po(it(e,{l:ti(r,t)})):po(it(e,{r:ti(o,t)}))}function Pn(e){return Ue(e)?[]:[...Pn(e.l),{k:e.k,v:e.v},...Pn(e.r)]}function ni(e,t,n){if(Ue(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ni(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ni(s,t,n))),a}function po(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(ri(t))return oc(it(e,{lvl:n-1}));if(!Ue(t)&&!Ue(t.r))return it(t.r,{l:it(t,{r:t.r.l}),lvl:n,r:it(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ri(e))return oi(it(e,{lvl:n-1}));if(!Ue(r)&&!Ue(r.l)){const o=r.l,s=ri(o)?r.lvl-1:r.lvl;return it(o,{l:it(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:oi(it(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function it(e,t){return nc(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 ec(e){return Ue(e.r)?e.l:po(it(e,{r:ec(e.r)}))}function ri(e){return Ue(e)||e.lvl>e.r.lvl}function tc(e){return Ue(e.r)?[e.k,e.v]:tc(e.r)}function nc(e,t,n,r=br,o=br){return{k:e,l:r,lvl:n,r:o,v:t}}function rc(e){return oi(oc(e))}function oc(e){const{l:t}=e;return!Ue(t)&&t.lvl===e.lvl?it(t,{r:it(e,{l:t.r})}):e}function oi(e){const{lvl:t,r:n}=e;return!Ue(n)&&!Ue(n.r)&&n.lvl===t&&n.r.lvl===t?it(n,{l:it(e,{r:n.l}),lvl:t+1}):e}function Fg(e){return Ql(e,({k:t,v:n})=>({index:t,value:n}))}function sc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Sr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const si=De(()=>({recalcInProgress:X(!1)}),[],{singleton:!0});function ic(e,t,n){return e[mo(e,t,n)]}function mo(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 $g(e,t,n,r){const o=mo(e,t,r),s=mo(e,n,r,o);return e.slice(o,s+1)}function gn(e,t){return Math.round(e.getBoundingClientRect()[t])}function go(e){return!Ue(e.groupOffsetTree)}function ii({index:e},t){return t===e?0:t<e?-1:1}function zg(){return{groupIndices:[],groupOffsetTree:Zn(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Zn()}}function Bg(e,t){let n=Ue(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ue(e)){e=At(e,0,s);continue}const a=ho(e,i-1,o+1);if(a.some(Gg(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:h}of a)c?(o>=f||s===h)&&(e=ti(e,f)):(u=h!==s,c=!0),d>o&&o>=f&&h!==s&&(e=At(e,o+1,h));u&&(e=At(e,i,s))}return[e,n]}function Hg(e){return typeof e.groupIndex<"u"}function Ug({offset:e},t){return t===e?0:t<e?-1:1}function Cr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ic(t,e,ii),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function ac(e,t){if(!go(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function lc(e,t,n){if(Hg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=ac(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Wg(e,t,n,r=0){return r>0&&(t=Math.max(t,ic(e,r,ii).offset)),Ql($g(e,t,n,Ug),qg)}function Vg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Tt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ue(s)&&t.length===2){const h=t[0].size,g=t[1].size;i=n.reduce((w,v)=>At(At(w,v,h),v+1,g),i)}else[i,a]=Bg(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=ai(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,g)=>At(h,g,Cr(g,f,o)),Zn()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Kg(e){return Pn(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 cc(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 ai(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=mo(o,t-1,ii),a=o[c].offset;const u=Ut(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===Ut(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of ho(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 qg(e){return{index:e.index,value:e}}function Gg(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 Yg={offsetHeight:"height",offsetWidth:"width"},Jt=De(([{log:e},{recalcInProgress:t}])=>{const n=je(),r=je(),o=pt(r,0),s=je(),i=je(),a=X(0),c=X([]),u=X(void 0),d=X(void 0),f=X((C,T)=>gn(C,Yg[T])),h=X(void 0),g=X(0),w=zg(),v=pt(B(n,Ee(c,e,g),Xt(Vg,w),Ye()),w),m=pt(B(c,Ye(),Xt((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),oe(({prev:C})=>C)),[]);ue(B(c,we(C=>C.length>0),Ee(v,g),oe(([C,T,E])=>{const N=C.reduce((_,P,j)=>At(_,P,Cr(P,T.offsetTree,E)||j),Zn());return{...T,groupIndices:C,groupOffsetTree:N}})),v),ue(B(r,Ee(v),we(([C,{lastIndex:T}])=>C<T),oe(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),ue(u,d);const x=pt(B(u,oe(C=>C===void 0)),!0);ue(B(d,we(C=>C!==void 0&&Ue(nt(v).sizeTree)),oe(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Nt(B(n,Ee(v),Xt(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:w}),oe(C=>C.changed)));Fe(B(a,Xt((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),oe(C=>C.diff)),C=>{const{groupIndices:T}=nt(v);if(C>0)ke(t,!0),ke(s,C+cc(C,T));else if(C<0){const E=nt(m);E.length>0&&(C-=cc(-C,E)),ke(i,C)}}),Fe(B(a,Ee(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},Tt.ERROR)});const S=Nt(s);ue(B(s,Ee(v),oe(([C,T])=>{const E=T.groupIndices.length>0,N=[],_=T.lastSize;if(E){const P=yr(T.sizeTree,0);let j=0,z=0;for(;j<C;){const O=T.groupIndices[z],W=T.groupIndices.length===z+1?1/0:T.groupIndices[z+1]-O-1;N.push({endIndex:O,size:P,startIndex:O}),N.push({endIndex:O+1+W-1,size:_,startIndex:O+1}),z++,j+=W+1}const G=Pn(T.sizeTree);return j!==C&&G.shift(),G.reduce((O,{k:W,v:H})=>{let V=O.ranges;return O.prevSize!==0&&(V=[...O.ranges,{endIndex:W+C-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:W+C,prevSize:H,ranges:V}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return Pn(T.sizeTree).reduce((P,{k:j,v:z})=>({prevIndex:j+C,prevSize:z,ranges:[...P.ranges,{endIndex:j+C-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const I=Nt(B(i,Ee(v,g),oe(([C,{offsetTree:T},E])=>{const N=-C;return Cr(N,T,E)})));return ue(B(i,Ee(v,g),oe(([C,T,E])=>{if(T.groupIndices.length>0){if(Ue(T.sizeTree))return T;let N=Zn();const _=nt(m);let P=0,j=0,z=0;for(;P<-C;){z=_[j];const G=_[j+1]-z-1;j++,P+=G+1}if(N=Pn(T.sizeTree).reduce((G,{k:O,v:W})=>At(G,Math.max(0,O+C),W),N),P!==-C){const G=yr(T.sizeTree,z);N=At(N,0,G);const O=Ut(T.sizeTree,-C+1)[1];N=At(N,1,O)}return{...T,sizeTree:N,...ai(T.offsetTree,0,N,E)}}else{const N=Pn(T.sizeTree).reduce((_,{k:P,v:j})=>At(_,Math.max(0,P+C),j),Zn());return{...T,sizeTree:N,...ai(T.offsetTree,0,N,E)}}})),v),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:g,groupIndices:c,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:I,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Ge(mn,si),{singleton:!0});function Xg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const uc=De(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=je(),i=je(),a=Nt(B(s,oe(Xg)));return ue(B(a,oe(c=>c.totalCount)),n),ue(B(a,oe(c=>c.groupIndices)),e),ue(B(ot(o,t,r),we(([c,u])=>go(u)),oe(([c,u,d])=>Ut(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),Ye(),oe(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Ge(Jt,wt)),xn=De(([{log:e}])=>{const t=X(!1),n=Nt(B(t,we(r=>r),Ye()));return Fe(t,r=>{r&&nt(e)("props updated",{},Tt.DEBUG)}),{didMount:n,propsReady:t}},Ge(mn),{singleton:!0}),Jg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function dc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Jg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Tr=De(([{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 g=je(),w=je(),v=X(0);let m=null,x=null,b=null;function S(){m&&(m(),m=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),ke(c,!1)}return ue(B(g,Ee(n,f,r,v,a,i,h),Ee(e,s,o),oe(([[I,C,T,E,N,_,P,j],z,G,O])=>{const W=dc(I),{align:H,behavior:V,offset:$}=W,A=E-1,K=lc(W,C,A);let L=Cr(K,C.offsetTree,z)+_;H==="end"?(L+=G+Ut(C.sizeTree,K)[1]-T+O,K===A&&(L+=P)):H==="center"?L+=(G+Ut(C.sizeTree,K)[1]-T+O)/2:L-=N,$&&(L+=$);const J=Y=>{S(),Y?(j("retrying to scroll to",{location:I},Tt.DEBUG),ke(g,I)):(ke(w,!0),j("list did not change, scroll successful",{},Tt.DEBUG))};if(S(),V==="smooth"){let Y=!1;b=Fe(t,ce=>{Y=Y||ce}),m=Ht(d,()=>{J(Y)})}else m=Ht(B(t,Zg(150)),J);return x=setTimeout(()=>{S()},1200),ke(c,!0),j("scrolling from index to",{behavior:V,index:K,top:L},Tt.DEBUG),{behavior:V,top:L}})),u),{scrollTargetReached:w,scrollToIndex:g,topListHeight:v}},Ge(Jt,wt,mn),{singleton:!0});function Zg(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function li(e,t){e==0?t():requestAnimationFrame(()=>{li(e-1,t)})}function ci(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const kr=De(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=X(!0),c=X(0),u=X(!0);return ue(B(i,Ee(c),we(([d,f])=>!!f),Yt(!1)),a),ue(B(i,Ee(c),we(([d,f])=>!!f),Yt(!1)),u),Fe(B(ot(t,i),Ee(a,n,e,u),we(([[,d],f,{sizeTree:h},g,w])=>d&&(!Ue(h)||Js(g))&&!f&&!w),Ee(c)),([,d])=>{Ht(o,()=>{ke(u,!0)}),li(4,()=>{Ht(r,()=>{ke(a,!0)}),ke(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Ge(Jt,wt,Tr,xn),{singleton:!0});function fc(e,t){return Math.abs(e-t)<1.01}const Er="up",Ir="down",Qg="none",ex={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},tx=0,Nr=De(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=X(!1),a=X(!0),c=je(),u=je(),d=X(4),f=X(tx),h=pt(B(Qs(B(xe(o),jn(1),Yt(!0)),B(xe(o),jn(1),Yt(!1),Yl(100))),Ye()),!1),g=pt(B(Qs(B(n,Yt(!0)),B(n,Yt(!1),Yl(200))),Ye()),!1);ue(B(ot(xe(o),xe(f)),oe(([b,S])=>b<=S),Ye()),a),ue(B(a,cn(50)),u);const w=Nt(B(ot(r,xe(s),xe(t),xe(e),xe(d)),Xt((b,[{scrollHeight:S,scrollTop:I},C,T,E,N])=>{const _=I+C-S>-N,P={scrollHeight:S,scrollTop:I,viewportHeight:C};if(_){let z,G;return I>b.state.scrollTop?(z="SCROLLED_DOWN",G=b.state.scrollTop-I):(z="SIZE_DECREASED",G=b.state.scrollTop-I||b.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:G,state:P}}let j;return P.scrollHeight>b.state.scrollHeight?j="SIZE_INCREASED":C<b.state.viewportHeight?j="VIEWPORT_HEIGHT_DECREASING":I<b.state.scrollTop?j="SCROLLING_UPWARDS":j="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:j,state:P}},ex),Ye((b,S)=>b&&b.atBottom===S.atBottom))),v=pt(B(r,Xt((b,{scrollHeight:S,scrollTop:I,viewportHeight:C})=>{if(fc(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:I};{const T=S-(I+C)<1;return b.scrollTop!==I&&T?{changed:!0,jump:b.scrollTop-I,scrollHeight:S,scrollTop:I}:{changed:!0,jump:0,scrollHeight:S,scrollTop:I}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),we(b=>b.changed),oe(b=>b.jump)),0);ue(B(w,oe(b=>b.atBottom)),i),ue(B(i,cn(50)),c);const m=X(Ir);ue(B(r,oe(({scrollTop:b})=>b),Ye(),Xt((b,S)=>nt(g)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Er:Ir,prevScrollTop:S},{direction:Ir,prevScrollTop:0}),oe(b=>b.direction)),m),ue(B(r,cn(50),Yt(Qg)),m);const x=X(0);return ue(B(h,we(b=>!b),Yt(0)),x),ue(B(o,cn(100),Ee(h),we(([b,S])=>!!S),Xt(([b,S],[I])=>[S,I],[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:m,scrollVelocity:x}},Ge(wt)),xo="top",vo="bottom",hc="none";function pc(e,t,n){return typeof e=="number"?n===Er&&t===xo||n===Ir&&t===vo?e:0:n===Er?t===xo?e.main:e.reverse:t===vo?e.main:e.reverse}function mc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ui=De(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=je(),i=X(0),a=X(0),c=X(0),u=pt(B(ot(xe(r),xe(o),xe(n),xe(s,Sr),xe(c),xe(i),xe(t),xe(e),xe(a)),oe(([d,f,h,[g,w],v,m,x,b,S])=>{const I=d-b,C=m+x,T=Math.max(h-I,0);let E=hc;const N=mc(S,xo),_=mc(S,vo);return g-=b,g+=h+x,w+=h+x,w-=b,g>d+C-N&&(E=Er),w<d-T+f+_&&(E=Ir),E!==hc?[Math.max(I-h-pc(v,xo,E)-N,0),I-T-x+f+pc(v,vo,E)+_]:null}),we(d=>d!=null),Ye(Sr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},Ge(wt),{singleton:!0});function nx(e,t,n){if(go(t)){const r=ac(e,t);return[{index:Ut(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 di={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function wo(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,g=u,w=h-d;return{bottom:d,firstItemIndex:s,items:xc(e,o,s),offsetBottom:w,offsetTop:u,top:g,topItems:xc(t,o,s),topListHeight:t.reduce((v,m)=>m.size+v,0),totalCount:n}}function gc(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=ci(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return wo(u,[],a,o,n,r)}function xc(e,t,n){if(e.length===0)return[];if(!go(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=ho(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 On=De(([{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:g},{recalcInProgress:w}])=>{const v=X([]),m=X(0),x=je();ue(s.topItemsIndexes,v);const b=pt(B(ot(g,w,xe(c,Sr),xe(o),xe(r),xe(u),d,xe(v),xe(t),xe(n),e),we(([T,E,,N,,,,,,,_])=>{const P=_&&_.length!==N;return T&&!E&&!P}),oe(([,,[T,E],N,_,P,j,z,G,O,W])=>{const H=_,{offsetTree:V,sizeTree:$}=H,A=nt(m);if(N===0)return{...di,totalCount:N};if(T===0&&E===0)return A===0?{...di,totalCount:N}:gc(A,P,_,G,O,W||[]);if(Ue($))return A>0?null:wo(nx(ci(P,N),H,W),[],N,O,H,G);const K=[];if(z.length>0){const pe=z[0],me=z[z.length-1];let q=0;for(const M of ho($,pe,me)){const D=M.value,F=Math.max(M.start,pe),Q=Math.min(M.end,me);for(let te=F;te<=Q;te++)K.push({data:W==null?void 0:W[te],index:te,offset:q,size:D}),q+=D}}if(!j)return wo([],K,N,O,H,G);const L=z.length>0?z[z.length-1]+1:0,J=Wg(V,T,E,L);if(J.length===0)return null;const Y=N-1,ce=fo([],pe=>{for(const me of J){const q=me.value;let M=q.offset,D=me.start;const F=q.size;if(q.offset<T){D+=Math.floor((T-q.offset+O)/(F+O));const te=D-me.start;M+=te*F+te*O}D<L&&(M+=(L-D)*F,D=L);const Q=Math.min(me.end,Y);for(let te=D;te<=Q&&!(M>=E);te++)pe.push({data:W==null?void 0:W[te],index:te,offset:M,size:F}),M+=F+O}});return wo(ce,K,N,O,H,G)}),we(T=>T!==null),Ye()),di);ue(B(e,we(Js),oe(T=>T==null?void 0:T.length)),o),ue(B(b,oe(T=>T.topListHeight)),f),ue(f,a),ue(B(b,oe(T=>[T.top,T.bottom])),i),ue(B(b,oe(T=>T.items)),x);const S=Nt(B(b,we(({items:T})=>T.length>0),Ee(o,e),we(([{items:T},E])=>T[T.length-1].originalIndex===E-1),oe(([,T,E])=>[T-1,E]),Ye(Sr),oe(([T])=>T))),I=Nt(B(b,cn(200),we(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),oe(({items:T})=>T[0].index),Ye())),C=Nt(B(b,we(({items:T})=>T.length>0),oe(({items:T})=>{let E=0,N=T.length-1;for(;T[E].type==="group"&&E<N;)E++;for(;T[N].type==="group"&&N>E;)N--;return{endIndex:T[N].index,startIndex:T[E].index}}),Ye(sc)));return{endReached:S,initialItemCount:m,itemsRendered:x,listState:b,rangeChanged:C,startReached:I,topItemsIndexes:v,...h}},Ge(Jt,uc,ui,kr,Tr,Nr,xn,si),{singleton:!0}),vc=De(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=je(),i=pt(B(ot(n,e,r,t,o),oe(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return ue(xe(i),s),{totalListHeight:i,totalListHeightChanged:s}},Ge(wt,On),{singleton:!0}),rx=De(([{viewportHeight:e},{totalListHeight:t}])=>{const n=X(!1),r=pt(B(ot(n,e,t),we(([o])=>o),oe(([,o,s])=>Math.max(0,o-s)),cn(0),Ye()),0);return{alignToBottom:n,paddingTopAddition:r}},Ge(wt,vc),{singleton:!0}),wc=De(()=>({context:X(null)})),ox=({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,bc=De(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=je();return ue(B(d,Ee(t,c,n,s,o,r,a),Ee(e),oe(([[f,h,g,w,v,m,x,b],S])=>{const{align:I,behavior:C,calculateViewLocation:T=ox,done:E,...N}=f,_=lc(f,h,w-1),P=Cr(_,h.offsetTree,S)+v+m,j=P+Ut(h.sizeTree,_)[1],z=b+m,G=b+g-x,O=T({itemBottom:j,itemTop:P,locationParams:{align:I,behavior:C,...N},viewportBottom:G,viewportTop:z});return O?E&&Ht(B(i,we(W=>!W),jn(nt(i)?1:2)),E):E&&E(),O}),we(f=>f!==null)),u),{scrollIntoView:d}},Ge(Jt,wt,Tr,On,mn),{singleton:!0});function yc(e){return e?e==="smooth"?"smooth":"auto":!1}const sx=(e,t)=>typeof e=="function"?yc(e(t)):t&&yc(e),ix=De(([{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:g}])=>{const w=X(!1),v=je();let m=null;function x(C){ke(i,{align:"end",behavior:C,index:"LAST"})}Fe(B(ot(B(xe(t),jn(1)),c),Ee(xe(w),s,a,f),oe(([[C,T],E,N,_,P])=>{let j=T&&_,z="auto";return j&&(z=sx(E,N||P),j=j&&!!z),{followOutputBehavior:z,shouldFollow:j,totalCount:C}}),we(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{m&&(m(),m=null),nt(n)?requestAnimationFrame(()=>{nt(d)("following output to ",{totalCount:T},Tt.DEBUG),x(C)}):m=Ht(e,()=>{nt(d)("following output to ",{totalCount:T},Tt.DEBUG),x(C),m=null})});function b(C){const T=Ht(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!m&&(nt(d)("scrolling to bottom due to increased size",{},Tt.DEBUG),x("auto"))});setTimeout(T,100)}Fe(B(ot(xe(w),t,u),we(([C,,T])=>C&&T),Xt(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),we(({refreshed:C})=>C),Ee(w,t)),([,C])=>{nt(a)&&b(C!==!1)}),Fe(v,()=>{b(nt(w)!==!1)}),Fe(ot(xe(w),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=X(null),I=je();return ue(Qs(B(xe(r),oe(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),B(xe(t))),I),Fe(B(ot(B(I,jn(1)),c),Ee(xe(S),a,f,h),oe(([[C,T],E,N,_,P])=>T&&N&&(E==null?void 0:E({context:P,totalCount:C,scrollingInProgress:_}))),we(C=>!!C),cn(0)),C=>{m&&(m(),m=null),nt(n)?requestAnimationFrame(()=>{nt(d)("scrolling into view",{}),ke(g,C)}):m=Ht(e,()=>{nt(d)("scrolling into view",{}),ke(g,C),m=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:S}},Ge(Jt,Nr,Tr,kr,xn,mn,wt,wc,bc)),ax=De(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ue(B(a,Ee(s),we(([,c])=>c!==0),Ee(o,r,t,n,e),oe(([[,c],u,d,f,h,g=[]])=>gc(c,u,d,f,h,g))),i),{}),Ge(Jt,kr,On,xn),{singleton:!0}),lx=De(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=X(0);return Fe(B(e,Ee(r),we(([,o])=>o!==0),oe(([,o])=>({top:o}))),o=>{Ht(B(n,jn(1),we(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ke(t,o)})})}),{initialScrollTop:r}},Ge(xn,wt,On),{singleton:!0}),Sc=De(([{scrollVelocity:e}])=>{const t=X(!1),n=je(),r=X(!1);return ue(B(e,Ee(r,t,n),we(([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}),Ye()),t),Fe(B(ot(t,e,n),Ee(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Ge(Nr),{singleton:!0}),fi=De(([{scrollContainerState:e,scrollTo:t}])=>{const n=je(),r=je(),o=je(),s=X(!1),i=X(void 0);return ue(B(ot(n,r),oe(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),ue(B(t,Ee(r),oe(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Ge(wt)),cx=De(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=je(),d=X(void 0),f=X(null),h=X(null);return ue(a,f),ue(c,h),Fe(B(u,Ee(t,r,i,f,h,n)),([g,w,v,m,x,b,S])=>{const I=Kg(w.sizeTree);m&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=S,g({ranges:I,scrollTop:v})}),ue(B(d,we(Js),oe(ux)),o),ue(B(s,Ee(d),we(([,g])=>g!==void 0),Ye(),oe(([,g])=>g.ranges)),e),{getState:u,restoreStateFrom:d}},Ge(Jt,wt,kr,xn,fi));function ux(e){return{align:"start",index:0,offset:e.scrollTop}}const dx=De(([{topItemsIndexes:e}])=>{const t=X(0);return ue(B(t,we(n=>n>=0),oe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Ge(On));function Cc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const fx=Cc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),hx=De(([{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:g},{recalcInProgress:w}])=>{const v=Nt(B(c,Ee(i),Xt(([,x,b,S],[{bottom:I,items:C,offsetBottom:T,totalCount:E},N])=>{const _=I+T;let P=0;return b===E&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(P=_-S,P!==0&&(P+=N))),[P,C,E,_]},[0,[],0,0]),we(([x])=>x!==0),Ee(r,a,n,o,g,w),we(([,x,b,S,,,I])=>!I&&!S&&x!==0&&b===Er),oe(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Tt.DEBUG),x))));function m(x){x>0?(ke(t,{behavior:"auto",top:-x}),ke(e,0)):(ke(e,0),ke(t,{behavior:"auto",top:-x}))}return Fe(B(v,Ee(e,s)),([x,b,S])=>{S&&fx()?ke(e,b-x):m(-x)}),Fe(B(ot(pt(s,!1),e,w),we(([x,b,S])=>!x&&!S&&b!==0),oe(([x,b])=>b),cn(1)),m),ue(B(f,oe(x=>({top:-x}))),t),Fe(B(u,Ee(h,d),oe(([x,{groupIndices:b,lastSize:S,sizeTree:I},C])=>{function T(E){return E*(S+C)}if(b.length===0)return T(x);{let E=0;const N=yr(I,0);let _=0,P=0;for(;_<x;){_++,E+=N;let j=b.length===P+1?1/0:b[P+1]-b[P]-1;_+j>x&&(E-=N,j=x-_+1),_+=j,E+=T(j),P++}return E}})),x=>{ke(e,x),requestAnimationFrame(()=>{ke(t,{top:x}),requestAnimationFrame(()=>{ke(e,0),ke(w,!1)})})}),{deviation:e}},Ge(wt,Nr,On,Jt,mn,si)),px=De(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),Ge(ui,ax,xn,Sc,vc,lx,rx,fi,bc,mn,wc)),Tc=De(([{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:g,scrolledToInitialItem:w},v,m,x,{listState:b,topItemsIndexes:S,...I},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:N},_])=>(ue(I.rangeChanged,_.scrollSeekRangeChanged),ue(B(_.windowViewportRect,oe(P=>P.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:g,scrolledToInitialItem:w,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...I,..._,...v,sizes:c,...m}),Ge(Jt,kr,wt,cx,ix,On,Tr,hx,dx,uc,px));function mx(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 bo=typeof document<"u"?y.useLayoutEffect:y.useEffect;function kc(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(m,x){m.propsReady&&ke(m.propsReady,!1);for(const b of r){const S=m[t.required[b]];ke(S,x[b])}for(const b of o)if(b in x){const S=m[t.optional[b]];ke(S,x[b])}m.propsReady&&ke(m.propsReady,!0)}function u(m){return s.reduce((x,b)=>(x[b]=S=>{const I=m[t.methods[b]];ke(I,S)},x),{})}function d(m){return i.reduce((x,b)=>(x[b]=jg(m[t.events[b]]),x),{})}const f=y.forwardRef((m,x)=>{const{children:b,...S}=m,[I]=y.useState(()=>fo(Pg(e),E=>{c(E,S)})),[C]=y.useState(Gl(d,I));bo(()=>{for(const E of i)E in S&&Fe(C[E],S[E]);return()=>{Object.values(C).map(Zs)}},[S,C,I]),bo(()=>{c(I,S)}),y.useImperativeHandle(x,Kl(u(I)));const T=n;return l.jsx(a.Provider,{value:I,children:n?l.jsx(T,{...mx([...r,...o,...i],S),children:b}):b})}),h=m=>{const x=y.useContext(a);return y.useCallback(b=>{ke(x[m],b)},[x,m])},g=m=>{const x=y.useContext(a)[m],b=y.useCallback(S=>Fe(x,S),[x]);return y.useSyncExternalStore(b,()=>nt(x),()=>nt(x))},w=m=>{const x=y.useContext(a)[m],[b,S]=y.useState(Gl(nt,x));return bo(()=>Fe(x,I=>{I!==b&&S(Kl(I))}),[x,b]),b},v=y.version.startsWith("18")?g:w;return{Component:f,useEmitter:(m,x)=>{const b=y.useContext(a)[m];bo(()=>Fe(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const Ec=y.createContext(void 0),Ic=y.createContext(void 0),Nc=typeof document<"u"?y.useLayoutEffect:y.useEffect;function hi(e){return"self"in e}function gx(e){return"body"in e}function Ac(e,t,n,r=Jn,o,s){const i=y.useRef(null),a=y.useRef(null),c=y.useRef(null),u=y.useCallback(h=>{let g,w,v;const m=h.target;if(gx(m)||hi(m)){const b=hi(m)?m:m.defaultView;v=s?b.scrollX:b.scrollY,g=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?m.scrollLeft:m.scrollTop,g=s?m.scrollWidth:m.scrollHeight,w=s?m.offsetWidth:m.offsetHeight;const x=()=>{e({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():_s.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===g-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 g=i.current;if(!g||(s?"offsetWidth"in g&&g.offsetWidth===0:"offsetHeight"in g&&g.offsetHeight===0))return;const w=h.behavior==="smooth";let v,m,x;hi(g)?(m=Math.max(gn(g.document.documentElement,s?"width":"height"),s?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight),v=s?g.innerWidth:g.innerHeight,x=s?window.scrollX:window.scrollY):(m=g[s?"scrollWidth":"scrollHeight"],v=gn(g,s?"width":"height"),x=g[s?"scrollLeft":"scrollTop"]);const b=m-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),fc(v,m)||h.top===x){e({scrollHeight:m,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}),g.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 pi="-webkit-sticky",_c="sticky",mi=Cc(()=>{if(typeof document>"u")return _c;const e=document.createElement("div");return e.style.position=pi,e.style.position===pi?pi:_c});function gi(e){return e}const xx=De(()=>{const e=X(a=>`Item ${a}`),t=X(a=>`Group ${a}`),n=X({}),r=X(gi),o=X("div"),s=X(Jn),i=(a,c=null)=>pt(B(n,oe(u=>u[a]),Ye()),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")}}),vx=De(([e,t])=>({...e,...t}),Ge(Tc,xx)),wx=({height:e})=>l.jsx("div",{style:{height:e}}),bx={overflowAnchor:"none",position:mi(),zIndex:1},jc={overflowAnchor:"none"},yx={...jc,display:"inline-block",height:"100%"},Rc=y.memo(function({showTopList:e=!1}){const t=Se("listState"),n=Mt("sizeRanges"),r=Se("useWindowScroll"),o=Se("customScrollParent"),s=Mt("windowScrollContainerState"),i=Mt("scrollContainerState"),a=o||r?s:i,c=Se("itemContent"),u=Se("context"),d=Se("groupContent"),f=Se("trackItemSizes"),h=Se("itemSize"),g=Se("log"),w=Mt("gap"),v=Se("horizontalDirection"),{callbackRef:m}=Dg(n,h,f,e?Jn:a,g,w,o,v,Se("skipAnimationFrameInResizeObserver")),[x,b]=y.useState(0);xi("deviation",O=>{x!==O&&b(O)});const S=Se("EmptyPlaceholder"),I=Se("ScrollSeekPlaceholder")||wx,C=Se("ListComponent"),T=Se("ItemComponent"),E=Se("GroupComponent"),N=Se("computeItemKey"),_=Se("isSeeking"),P=Se("groupIndices").length>0,j=Se("alignToBottom"),z=Se("initialItemFinalLocationReached"),G=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},...z?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?l.jsx(S,{...mt(S,u)}):l.jsx(C,{...mt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:m,style:G,children:(e?t.topItems:t.items).map(O=>{const W=O.originalIndex,H=N(W+t.firstItemIndex,O.data,u);return _?y.createElement(I,{...mt(I,u),height:O.size,index:O.index,key:H,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?y.createElement(E,{...mt(E,u),"data-index":W,"data-item-index":O.index,"data-known-size":O.size,key:H,style:bx},d(O.index,u)):y.createElement(T,{...mt(T,u),...kx(T,O.data),"data-index":W,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:H,style:v?yx:jc},P?c(O.index,O.groupIndex,O.data,u):c(O.index,O.data,u))})})}),Sx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Cx={outline:"none",overflowX:"auto",position:"relative"},yo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Tx={position:mi(),top:0,width:"100%",zIndex:1};function mt(e,t){if(typeof e!="string")return{context:t}}function kx(e,t){return{item:typeof e=="string"?void 0:t}}const Ex=y.memo(function(){const e=Se("HeaderComponent"),t=Mt("headerHeight"),n=Se("HeaderFooterTag"),r=Rn(y.useMemo(()=>s=>{t(gn(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Ix=y.memo(function(){const e=Se("FooterComponent"),t=Mt("footerHeight"),n=Se("HeaderFooterTag"),r=Rn(y.useMemo(()=>s=>{t(gn(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null});function Pc({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:g,scrollToCallback:w}=Ac(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:g,style:{...f?Cx:Sx,...o},tabIndex:0,...i,...mt(c,s),children:r})})}function Oc({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"),g=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:m,scrollToCallback:x}=Ac(a,u,c,w,h);return Nc(()=>{var b;return m.current=h||((b=g.current)==null?void 0:b.ownerDocument.defaultView),()=>{m.current=null}},[m,h]),e("windowScrollTo",x),e("scrollBy",v),l.jsx(c,{ref:g,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...mt(c,s),children:r})})}const Nx=({children:e})=>{const t=y.useContext(Ec),n=Mt("viewportHeight"),r=Mt("fixedItemHeight"),o=Se("alignToBottom"),s=Se("horizontalDirection"),i=y.useMemo(()=>ql(n,c=>gn(c,s?"width":"height")),[n,s]),a=Rn(i,!0,Se("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:yo(o),children:e})},Ax=({children:e})=>{const t=y.useContext(Ec),n=Mt("windowViewportRect"),r=Mt("fixedItemHeight"),o=Se("customScrollParent"),s=Zl(n,o,Se("skipAnimationFrameInResizeObserver")),i=Se("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:yo(i),children:e})},_x=({children:e})=>{const t=Se("TopItemListComponent")||"div",n=Se("headerHeight"),r={...Tx,marginTop:`${n}px`},o=Se("context");return l.jsx(t,{style:r,...mt(t,o),children:e})},jx=y.memo(function(e){const t=Se("useWindowScroll"),n=Se("topItemsIndexes").length>0,r=Se("customScrollParent"),o=Se("context");return l.jsxs(r||t?Ox:Px,{...e,context:o,children:[n&&l.jsx(_x,{children:l.jsx(Rc,{showTopList:!0})}),l.jsxs(r||t?Ax:Nx,{children:[l.jsx(Ex,{}),l.jsx(Rc,{}),l.jsx(Ix,{})]})]})}),{Component:Rx,useEmitter:xi,useEmitterValue:Se,usePublisher:Mt}=kc(vx,{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"}},jx),Px=Pc({useEmitter:xi,useEmitterValue:Se,usePublisher:Mt}),Ox=Oc({useEmitter:xi,useEmitterValue:Se,usePublisher:Mt}),Mx=Rx;Ge(Tc,De(()=>{const e=X(u=>l.jsxs("td",{children:["Item $",u]})),t=X(null),n=X(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=X(null),o=X(null),s=X({}),i=X(gi),a=X(Jn),c=(u,d=null)=>pt(B(s,oe(f=>f[u]),Ye()),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")}})),mi();const Mc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Dx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Dc,floor:So,max:Ar,min:vi,round:Lc}=Math;function Fc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Lx(e){return{...Dx,items:e}}function Co(e,t){return e&&e.width===t.width&&e.height===t.height}function Fx(e,t){return e&&e.column===t.column&&e.row===t.row}const $x=De(([{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,g,{didMount:w,propsReady:v},{customScrollParent:m,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:I},C])=>{const T=X(0),E=X(0),N=X(Mc),_=X({height:0,width:0}),P=X({height:0,width:0}),j=je(),z=je(),G=X(0),O=X(null),W=X({column:0,row:0}),H=je(),V=je(),$=X(!1),A=X(0),K=X(!0),L=X(!1),J=X(!1);Fe(B(w,Ee(A),we(([M,D])=>!!D)),()=>{ke(K,!1)}),Fe(B(ot(w,K,P,_,A,L),we(([M,D,F,Q,,te])=>M&&!D&&F.height!==0&&Q.height!==0&&!te)),([,,,,M])=>{ke(L,!0),li(1,()=>{ke(j,M)}),Ht(B(u),()=>{ke(t,[0,0]),ke(K,!0)})}),ue(B(V,we(M=>M!=null&&M.scrollTop>0),Yt(0)),E),Fe(B(w,Ee(V),we(([,M])=>M!=null)),([,M])=>{M&&(ke(_,M.viewport),ke(P,M.item),ke(W,M.gap),M.scrollTop>0&&(ke($,!0),Ht(B(u,jn(1)),D=>{ke($,!1)}),ke(c,{top:M.scrollTop})))}),ue(B(_,oe(({height:M})=>M)),f),ue(B(ot(xe(_,Co),xe(P,Co),xe(W,(M,D)=>M&&M.column===D.column&&M.row===D.row),xe(u)),oe(([M,D,F,Q])=>({gap:F,item:D,scrollTop:Q,viewport:M}))),H),ue(B(ot(xe(T),r,xe(W,Fx),xe(P,Co),xe(_,Co),xe(O),xe(E),xe($),xe(K),xe(A)),we(([,,,,,,,M])=>!M),oe(([M,[D,F],Q,te,Ie,He,Te,,Ae,Le])=>{const{column:Ve,row:Me}=Q,{height:et,width:Xe}=te,{width:at}=Ie;if(Te===0&&(M===0||at===0))return Mc;if(Xe===0){const Je=ci(Le,M),xt=Je+Math.max(Te-1,0);return Lx(Fc(Je,xt,He))}const ft=$c(at,Xe,Ve);let ut,ze;Ae?D===0&&F===0&&Te>0?(ut=0,ze=Te-1):(ut=ft*So((D+Me)/(et+Me)),ze=ft*Dc((F+Me)/(et+Me))-1,ze=vi(M-1,Ar(ze,ft-1)),ut=vi(ze,Ar(0,ut))):(ut=0,ze=-1);const ee=Fc(ut,ze,He),{bottom:ae,top:he}=zc(Ie,Q,te,ee),Be=Dc(M/ft),qe=Be*et+(Be-1)*Me-ae;return{bottom:ae,itemHeight:et,items:ee,itemWidth:Xe,offsetBottom:qe,offsetTop:he,top:he}})),N),ue(B(O,we(M=>M!==null),oe(M=>M.length)),T),ue(B(ot(_,P,N,W),we(([M,D,{items:F}])=>F.length>0&&D.height!==0&&M.height!==0),oe(([M,D,{items:F},Q])=>{const{bottom:te,top:Ie}=zc(M,Q,D,F);return[Ie,te]}),Ye(Sr)),t);const Y=X(!1);ue(B(u,Ee(Y),oe(([M,D])=>D||M!==0)),Y);const ce=Nt(B(ot(N,T),we(([{items:M}])=>M.length>0),Ee(Y),we(([[M,D],F])=>{const Q=M.items[M.items.length-1].index===D-1;return(F||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===D)&&Q}),oe(([[,M]])=>M-1),Ye())),pe=Nt(B(xe(N),we(({items:M})=>M.length>0&&M[0].index===0),Yt(0),Ye())),me=Nt(B(xe(N),Ee($),we(([{items:M},D])=>M.length>0&&!D),oe(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),Ye(sc),cn(0)));ue(me,g.scrollSeekRangeChanged),ue(B(j,Ee(_,P,T,W),oe(([M,D,F,Q,te])=>{const Ie=dc(M),{align:He,behavior:Te,offset:Ae}=Ie;let Le=Ie.index;Le==="LAST"&&(Le=Q-1),Le=Ar(0,Le,vi(Q-1,Le));let Ve=wi(D,te,F,Le);return He==="end"?Ve=Lc(Ve-D.height+F.height):He==="center"&&(Ve=Lc(Ve-D.height/2+F.height/2)),Ae&&(Ve+=Ae),{behavior:Te,top:Ve}})),c);const q=pt(B(N,oe(M=>M.offsetBottom+M.bottom)),0);return ue(B(I,oe(M=>({height:M.visibleHeight,width:M.visibleWidth}))),_),{customScrollParent:m,data:O,deviation:G,footerHeight:o,gap:W,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:z,scrollTo:c,scrollToIndex:j,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:I,...g,gridState:N,horizontalDirection:J,initialTopMostItemIndex:A,totalListHeight:q,...h,endReached:ce,propsReady:v,rangeChanged:me,startReached:pe,stateChanged:H,stateRestoreInProgress:$,...C}},Ge(ui,wt,Nr,Sc,xn,fi,mn));function $c(e,t,n){return Ar(1,So((e+n)/(So(t)+n)))}function zc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=wi(e,t,n,r[0].index);return{bottom:wi(e,t,n,r[r.length-1].index)+o,top:s}}function wi(e,t,n,r){const o=$c(e.width,n.width,t.column),s=So(r/o),i=s*n.height+Ar(0,s-1)*t.row;return i>0?i+t.row:i}const zx=De(()=>{const e=X(f=>`Item ${f}`),t=X({}),n=X(null),r=X("virtuoso-grid-item"),o=X("virtuoso-grid-list"),s=X(gi),i=X("div"),a=X(Jn),c=(f,h=null)=>pt(B(t,oe(g=>g[f]),Ye()),h),u=X(!1),d=X(!1);return ue(xe(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")}}),Bx=De(([e,t])=>({...e,...t}),Ge($x,zx)),Hx=y.memo(function(){const e=Ze("gridState"),t=Ze("listClassName"),n=Ze("itemClassName"),r=Ze("itemContent"),o=Ze("computeItemKey"),s=Ze("isSeeking"),i=Dt("scrollHeight"),a=Ze("ItemComponent"),c=Ze("ListComponent"),u=Ze("ScrollSeekPlaceholder"),d=Ze("context"),f=Dt("itemDimensions"),h=Dt("gap"),g=Ze("log"),w=Ze("stateRestoreInProgress"),v=Dt("reportReadyState"),m=Rn(y.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const S=x.firstChild;if(S){const{height:I,width:C}=S.getBoundingClientRect();f({height:I,width:C})}h({column:Hc("column-gap",getComputedStyle(x).columnGap,g),row:Hc("row-gap",getComputedStyle(x).rowGap,g)})},[i,f,h,g]),!0,!1);return Nc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:l.jsx(c,{className:t,ref:m,...mt(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,{...mt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):y.createElement(a,{...mt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),Ux=y.memo(function(){const e=Ze("HeaderComponent"),t=Dt("headerHeight"),n=Ze("headerFooterTag"),r=Rn(y.useMemo(()=>s=>{t(gn(s,"height"))},[t]),!0,!1),o=Ze("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Wx=y.memo(function(){const e=Ze("FooterComponent"),t=Dt("footerHeight"),n=Ze("headerFooterTag"),r=Rn(y.useMemo(()=>s=>{t(gn(s,"height"))},[t]),!0,!1),o=Ze("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Vx=({children:e})=>{const t=y.useContext(Ic),n=Dt("itemDimensions"),r=Dt("viewportDimensions"),o=Rn(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:yo(!1),children:e})},Kx=({children:e})=>{const t=y.useContext(Ic),n=Dt("windowViewportRect"),r=Dt("itemDimensions"),o=Ze("customScrollParent"),s=Zl(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:yo(!1),children:e})},qx=y.memo(function({...e}){const t=Ze("useWindowScroll"),n=Ze("customScrollParent"),r=n||t?Yx:Gx,o=n||t?Kx:Vx,s=Ze("context");return l.jsx(r,{...e,...mt(r,s),children:l.jsxs(o,{children:[l.jsx(Ux,{}),l.jsx(Hx,{}),l.jsx(Wx,{})]})})}),{useEmitter:Bc,useEmitterValue:Ze,usePublisher:Dt}=kc(Bx,{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"}},qx),Gx=Pc({useEmitter:Bc,useEmitterValue:Ze,usePublisher:Dt}),Yx=Oc({useEmitter:Bc,useEmitterValue:Ze,usePublisher:Dt});function Hc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Tt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Xx=Yr.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 bi({className:e,variant:t,...n}){return l.jsx("div",{className:Z(Xx({variant:t}),e),...n})}function ie(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 Jx(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 Zt(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:g,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[c])||a,m=p.useMemo(()=>w,Object.values(w));return l.jsx(v.Provider,{value:m,children:g})};u.displayName=s+"Provider";function d(f,h){var v;const g=((v=h==null?void 0:h[e])==null?void 0:v[c])||a,w=p.useContext(g);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,Zx(o,...t)]}function Zx(...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:()=>{},Qx=p[" useInsertionEffect ".trim().toString()]||ct;function Mn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ev({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=tv(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 ev({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return Qx(()=>{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 tv(e){return typeof e=="function"}function Uc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Uc(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():Uc(e[o],null)}}}}function Ne(...e){return p.useCallback(yi(...e),e)}var nv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],be=nv.reduce((e,t)=>{const n=In.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 Wc(e,t){e&&Xr.flushSync(()=>e.dispatchEvent(t))}function rv(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var _t=e=>{const{present:t,children:n}=e,r=ov(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Ne(r.ref,sv(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};_t.displayName="Presence";function ov(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,c]=rv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const u=To(r.current);s.current=a==="mounted"?u:"none"},[a]),ct(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,g=To(u);e?c("MOUNT"):g==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&h!==g?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),ct(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=g=>{const v=To(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&v&&(c("ANIMATION_END"),!o.current)){const m=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=m)})}},h=g=>{g.target===t&&(s.current=To(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 To(e){return(e==null?void 0:e.animationName)||"none"}function sv(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 iv=p[" useId ".trim().toString()]||(()=>{}),av=0;function Qt(e){const[t,n]=p.useState(iv());return ct(()=>{n(r=>r??String(av++))},[e]),e||(t?`radix-${t}`:"")}var ko="Collapsible",[lv,YC]=Zt(ko),[cv,Si]=lv(ko),Vc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=Mn({prop:r,defaultProp:o??!1,onChange:i,caller:ko});return l.jsx(cv,{scope:n,disabled:s,contentId:Qt(),open:c,onOpenToggle:p.useCallback(()=>u(d=>!d),[u]),children:l.jsx(be.div,{"data-state":Ti(c),"data-disabled":s?"":void 0,...a,ref:t})})});Vc.displayName=ko;var Kc="CollapsibleTrigger",qc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Si(Kc,n);return l.jsx(be.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ti(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ie(e.onClick,o.onOpenToggle)})});qc.displayName=Kc;var Ci="CollapsibleContent",uv=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Si(Ci,e.__scopeCollapsible);return l.jsx(_t,{present:n||o.open,children:({present:s})=>l.jsx(dv,{...r,ref:t,present:s})})});uv.displayName=Ci;var dv=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Si(Ci,n),[a,c]=p.useState(r),u=p.useRef(null),d=Ne(t,u),f=p.useRef(0),h=f.current,g=p.useRef(0),w=g.current,v=i.open||a,m=p.useRef(v),x=p.useRef(void 0);return p.useEffect(()=>{const b=requestAnimationFrame(()=>m.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,g.current=S.width,m.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(be.div,{"data-state":Ti(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 Ti(e){return e?"open":"closed"}var fv=Vc;const Gc=fv,Yc=qc,_r=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}));_r.displayName="Card";const jr=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 p-6",e),...t}));jr.displayName="CardHeader";const Rr=p.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:Z("text-2xl font-semibold leading-none tracking-tight",e),...t}));Rr.displayName="CardTitle";const Xc=p.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));Xc.displayName="CardDescription";const Eo=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("p-6 pt-0",e),...t}));Eo.displayName="CardContent";const Jc=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("flex items-center p-6 pt-0",e),...t}));Jc.displayName="CardFooter";function Zc(){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 Dn=Zc();function hv(e){Dn=e}const Qc=/[&<>"']/,pv=new RegExp(Qc.source,"g"),eu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,mv=new RegExp(eu.source,"g"),gv={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},tu=e=>gv[e];function gt(e,t){if(t){if(Qc.test(e))return e.replace(pv,tu)}else if(eu.test(e))return e.replace(mv,tu);return e}const xv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function nu(e){return e.replace(xv,(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 vv=/(^|[^\[])\^/g;function We(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(vv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const wv=/[^\w:]/g,bv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function ru(e,t,n){if(e){let r;try{r=decodeURIComponent(nu(n)).replace(wv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!bv.test(n)&&(n=Tv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Io={},yv=/^[^:]+:\/*[^/]*$/,Sv=/^([^:]+:)[\s\S]*$/,Cv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Tv(e,t){Io[" "+e]||(yv.test(e)?Io[" "+e]=e+"/":Io[" "+e]=Ao(e,"/",!0)),e=Io[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Sv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Cv,"$1")+t:e+t}const No={exec:function(){}};function ou(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 Ao(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 kv(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 Ev(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 su(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function iu(e,t,n,r){const o=t.href,s=t.title?gt(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:gt(i)}}function Iv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
37
+ `))>=0;){const at=me.slice(0,Xe);me=me.slice(Xe+2);const ft=wg(at);if(!ft)continue;let ut;try{ut=JSON.parse(ft)}catch{console.debug("[use-chat] malformed SSE:",ft.slice(0,200));continue}const $e=vg(ut)?ut.data:ut;te=Date.now();const ee=$e.seq;if(ee!==void 0){if(ee<=M){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:ee,lastProcessedSeq:M,type:$e.type});continue}M>0&&ee>M+1&&(($=j==null?void 0:j.onGap)==null||$.call(j,{from:M,to:ee})),M=ee,I.current=ee,v(ee)}if(P==null||P($e),$e.type==="token"&&e.autoAppendAssistant!==!1)q.push($e.content),Q();else if($e.type==="message_delta"){const ae=$e.delta.filter(he=>he.type==="text").map(he=>he.text).join("");ae&&e.autoAppendAssistant!==!1&&(q.push(ae),Q())}else D!==null&&cancelAnimationFrame(D),F(),$e.type==="checkpoint"?g($e.checkpointId):$e.type==="error"&&u($e.message)}}F()}catch(Te){if(Te.name!=="AbortError"){const Ae=Te.message||String(Te);u(Ae),(A=j==null?void 0:j.onError)==null||A.call(j,Ae)}}finally{try{await ce.cancel()}catch{}finally{(K=ce.releaseLock)==null||K.call(ce)}D!==null&&typeof window<"u"&&window.cancelAnimationFrame(D),clearInterval(Ie),a(!1),x(!1),b.current=null}}catch(J){if(J.name!=="AbortError"){const Y=J.message||String(J);u(Y),(L=j==null?void 0:j.onError)==null||L.call(j,Y)}}finally{a(!1),x(!1),b.current=null}})(),{close:()=>z.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:m,stream:N,stop:T,clear:E,setToken:C}}function vg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function wg(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 zl=y.createContext(null);function bg({children:e,enableFileAgentRouting:t=!1,fileAgentId:n="invoice_reader"}){const{api:r,baseUrl:o}=lo(),{currentThreadId:s,setCurrentThreadId:i,isLoadingThread:a}=qs(),c=eg(),{state:u,dispatch:d,seed:f,prepend:h,pushUser:g,onEvent:w,reset:v}=Ll(),[m,x]=y.useState(!1),[b,S]=y.useState(!1),[I,C]=y.useState(null),[T,E]=y.useState(void 0),[N,_]=y.useState(void 0),P=20,j=y.useRef(s);y.useEffect(()=>{j.current=s},[s]);const z=y.useRef(null),G=y.useRef(!1),O=y.useCallback(()=>{G.current=!0},[]),{isStreaming:W,error:H,stream:V,stop:$,setToken:A}=$l({baseUrl:o,token:null});y.useEffect(()=>{const D=r.getAuthToken();A(D)},[r,A]),y.useEffect(()=>{c(W?{type:"STREAM_START",assistantId:u.assemblingId??void 0}:{type:"STREAM_END"})},[W,u.assemblingId,c]),y.useEffect(()=>{c(H?{type:"STREAM_ERROR",error:H}:{type:"CLEAR_ERROR"})},[H,c]),y.useEffect(()=>{u.lastCheckpointId&&c({type:"UPDATE_CHECKPOINT",checkpointId:u.lastCheckpointId,checkpointNs:u.lastCheckpointNs??void 0})},[u.lastCheckpointId,u.lastCheckpointNs,c]),y.useEffect(()=>{c({type:"UPDATE_ASSEMBLING_ID",assistantId:u.assemblingId})},[u.assemblingId,c]);const K=y.useCallback((D,F)=>{const Q=Array.isArray(D==null?void 0:D.messages)?D.messages:[];F==="replace"?(console.log("[MessagesProvider] Replacing messages, count:",Q.length),f(Q,{checkpointId:(D==null?void 0:D.checkpointId)??null,checkpointNs:(D==null?void 0:D.checkpointNs)??null})):F==="prepend"&&Q.length&&(console.log("[MessagesProvider] Prepending messages, count:",Q.length),h(Q)),C((D==null?void 0:D.nextCursor)??null),x(!!(D!=null&&D.hasMore)),E(te=>(D==null?void 0:D.checkpointId)??te??void 0),_(te=>(D==null?void 0:D.checkpointNs)??te??void 0)},[f,h]),L=y.useCallback(D=>{const F=D.threadId,Q=!!D.created,te=!!D.ready;if(s!==F){const Ie=!s&&u.messages.length<=1;Ie&&(z.current=F),i(F),(te||Q||Ie)&&O();return}(te||Q)&&O()},[s,u.messages.length,i,O]),J=y.useCallback(({from:D,to:F})=>{const Q=j.current;Q&&console.warn(`[MessagesProvider] Stream sequence gap detected (${D} -> ${F}) for thread ${Q}`)},[]),{handleEvent:Y,reset:ce}=xg({onThreadInfo:L,onMessageEvent:w,onUnhandledEvent:D=>{console.warn(`[MessagesProvider] Unhandled stream event type: ${D.type}`,D)},onSequenceGap:J}),pe=y.useCallback(async D=>{if(!s)throw new Error("No active thread");if(b||!m)return;const F=I;if(F){S(!0);try{const Q=await r.getMessages({threadId:s,checkpointId:T,checkpointNs:N,limit:(D==null?void 0:D.limit)??P,beforeId:F});K(Q,"prepend")}finally{S(!1)}}},[r,s,T,N,I,m,b,K,P]),me=y.useCallback(()=>{console.log("[MessagesProvider] Clearing messages"),v([]),x(!1),S(!1),C(null),E(void 0),_(void 0)},[v]),q=y.useCallback(async(D,F)=>{var et;!s&&!(F!=null&&F.payloadExtras)&&console.warn("[MessagesProvider] No thread ID - message will create new thread");const Q=(F==null?void 0:F.attachments)||[],{contentParts:te,filesInfo:Ie}=await rg(r,Q),He=[...te];D&&D.trim()&&He.push({type:"text",text:D.trim()});const Te={id:((et=crypto.randomUUID)==null?void 0:et.call(crypto))||`user-${Date.now()}`,role:"user",content:He,createdAt:new Date().toISOString(),checkpointId:(F==null?void 0:F.checkpointId)??u.lastCheckpointId??void 0,checkpointNs:(F==null?void 0:F.checkpointNs)??u.lastCheckpointNs??void 0};g(Te);const Ae={...Te,content:He},Le={...(F==null?void 0:F.payloadExtras)??{}},Ve=Q&&Q.length>0,Me={...s?{threadId:s}:{},payload:{messages:[Ae],files_info:Ie,...t&&Ve&&n?{active_agent:n}:{},...Le},checkpointId:(F==null?void 0:F.checkpointId)??u.lastCheckpointId??void 0,checkpointNs:(F==null?void 0:F.checkpointNs)??u.lastCheckpointNs??void 0,nodeFilter:F==null?void 0:F.nodeFilter,config:F==null?void 0:F.config};ce(),O(),V(Me,Xe=>{Y(Xe)},{onError:Xe=>console.warn("[MessagesProvider] Stream error:",Xe),onOpen:({threadId:Xe,created:at})=>{if(!s&&Xe){const ft=u.messages.length<=1;ft&&(z.current=Xe),i(Xe),(at||ft)&&O()}},onGap:J})},[s,g,V,Y,ce,J,u.lastCheckpointId,u.lastCheckpointNs,u.messages.length,r,O,i,t,n]),M={messages:u.messages,assemblingId:u.assemblingId,lastUserMessage:null,hasMoreHistory:m,isLoadingHistory:b,send:q,stop:$,loadOlderMessages:pe,clearMessages:me};return l.jsx(zl.Provider,{value:M,children:e})}function yg(e){return l.jsx(bg,{...e})}function Bl(){const e=y.useContext(zl);if(!e)throw new Error("useMessages must be used within MessagesProvider");return e}function Hl({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:c}){return l.jsx(Xm,{apiConfig:t,children:l.jsx(Qm,{children:l.jsx(sg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,onError:a,onThreadChange:c,children:l.jsx(yg,{enableFileAgentRouting:s,fileAgentId:i,children:e})})})})}const Ul=y.createContext(null);function Sg({children:e}){const t=lo(),n=Ml(),r=qs(),o=Bl(),s=y.useMemo(()=>({baseUrl:t.baseUrl,token:t.token,setToken:t.setToken,api:t.api,threads:r.threads,currentThreadId:r.currentThreadId,setCurrentThreadId:r.setCurrentThreadId,isLoadingThreads:r.isLoadingThreads,isLoadingThread:r.isLoadingThread,refreshThreads:r.refreshThreads,createThread:r.createThread,deleteThread:r.deleteThread,renameThread:r.renameThread,loadThread:r.loadThread,clearCurrentThread:r.clearCurrentThread,listCheckpoints:r.listCheckpoints,navigateToCheckpoint:r.navigateToCheckpoint,returnToLatest:r.returnToLatest,handleInterrupt:r.handleInterrupt,isStreaming:n.isStreaming,error:n.error,streamingAssistantId:n.streamingAssistantId,lastCheckpointId:n.lastCheckpointId,lastCheckpointNs:n.lastCheckpointNs,messages:o.messages,hasMoreHistory:o.hasMoreHistory,isLoadingHistory:o.isLoadingHistory,loadOlderMessages:o.loadOlderMessages,historyPageSize:20,send:o.send,stop:o.stop}),[t,n,r,o]);return l.jsx(Ul.Provider,{value:s,children:e})}function co(e){const{children:t,...n}=e;return l.jsx(Hl,{...n,children:l.jsx(Sg,{children:t})})}function wr(){const e=y.useContext(Ul);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function Z(...e){return kp.twMerge(Tp.clsx(e))}const Cg=Yr.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"}}),Oe=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?In.Slot:"button";return l.jsx(i,{className:Z(Cg({variant:t,size:n,className:e})),ref:s,...o})});Oe.displayName="Button";const Wl=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}));Wl.displayName="Textarea";function Tg({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,g]=y.useState(e),[w,v]=y.useTransition(),m=y.useRef(null);y.useEffect(()=>{g(e??""),m.current&&(m.current.style.height="auto",m.current.style.height=`${m.current.scrollHeight}px`)},[e,t]);const x=y.useCallback(()=>{const N=m.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 P=i(_);P&&typeof P.then=="function"?P.then(()=>{g(""),m.current&&(m.current.style.height="auto")}).catch(()=>{}):(g(""),m.current&&(m.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(N=>{g(N.target.value),m.current&&(m.current.style.height="auto",m.current.style.height=`${m.current.scrollHeight}px`)},[]),I=y.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),b()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[b,t,a]),E=`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(Wl,{ref:m,value:h,onChange:S,onKeyDown:I,placeholder:t?"Edit your message...":n,className:E,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(Oe,{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(Oe,{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 kg=y.memo(Tg),uo=0,pn=1,Xn=2,Vl=4;function Kl(e){return()=>e}function Eg(e){e()}function ql(e,t){return n=>e(t(n))}function Gl(e,t){return()=>e(t)}function Ig(e,t){return n=>e(t,n)}function Js(e){return e!==void 0}function Ng(...e){return()=>{e.map(Eg)}}function Jn(){}function fo(e,t){return t(e),e}function Ag(e,t){return t(e)}function Ge(...e){return e}function Fe(e,t){return e(pn,t)}function ke(e,t){e(uo,t)}function Zs(e){e(Xn)}function nt(e){return e(Vl)}function ue(e,t){return Fe(e,Ig(t,uo))}function Ht(e,t){const n=e(pn,r=>{n(),t(r)});return n}function Yl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Xl(e,t){return e===t}function Ye(e=Xl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function we(e){return t=>n=>{e(n)&&t(n)}}function oe(e){return t=>ql(t,e)}function Yt(e){return t=>()=>{t(e)}}function B(e,...t){const n=_g(...t);return(r,o)=>{switch(r){case Xn:Zs(e);return;case pn:return Fe(e,n(o))}}}function Xt(e,t){return n=>r=>{n(t=e(t,r))}}function jn(e){return t=>n=>{e>0?e--:t(n)}}function cn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ee(...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);Fe(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 _g(...e){return t=>e.reduceRight(Ag,t)}function jg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case pn:return s?n===s?void 0:(r(),n=s,t=Fe(e,s),t):(r(),Jn);case Xn:r(),n=null;return}}}function X(e){let t=e;const n=je();return(r,o)=>{switch(r){case uo:t=o;break;case pn:{o(t);break}case Vl:return t}return n(r,o)}}function pt(e,t){return fo(X(t),n=>ue(e,n))}function je(){const e=[];return(t,n)=>{switch(t){case uo:e.slice().forEach(r=>{r(n)});return;case Xn:e.splice(0,e.length);return;case pn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Nt(e){return fo(je(),t=>ue(e,t))}function De(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Rg(),singleton:n}}const Rg=()=>Symbol();function Pg(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 ot(...e){const t=je(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Fe(s,c=>{n[i]=c,r=r|a,r===o&&ke(t,n)})}),function(s,i){switch(s){case Xn:{Zs(t);return}case pn:return r===o&&i(n),Fe(t,i)}}}function xe(e,t=Xl){return B(e,Ye(t))}function Qs(...e){return function(t,n){switch(t){case Xn:return;case pn:return Ng(...e.map(r=>Fe(r,n)))}}}var Tt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Tt||{});const Og={0:"debug",3:"error",1:"log",2:"warn"},Mg=()=>typeof globalThis>"u"?window:globalThis,mn=De(()=>{const e=X(3);return{log:X((t,n,r=1)=>{var o;const s=(o=Mg().VIRTUOSO_LOG_LEVEL)!=null?o:nt(e);r>=s&&console[Og[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Rn(e,t,n){return ei(e,t,n).callbackRef}function ei(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 Dg(e,t,n,r,o,s,i,a,c){const u=y.useCallback(d=>{const f=Lg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const g=h.lastElementChild.dataset.viewportType==="window";let w;g&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:g?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,m=i?a?i.scrollWidth:i.scrollHeight:g?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:g?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:m,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?Jl("column-gap",getComputedStyle(d).columnGap,o):Jl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ei(u,n,c)}function Lg(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},Tt.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 Jl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Tt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Zl(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 g=t.getBoundingClientRect(),w=u.top-g.top;h=g.height-Math.max(0,w),f=w+t.scrollTop}else{const g=i.current.ownerDocument.defaultView;h=g.innerHeight-Math.max(0,u.top),f=u.top+g.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ei(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 wt=De(()=>{const e=je(),t=je(),n=X(0),r=je(),o=X(0),s=je(),i=je(),a=X(0),c=X(0),u=X(0),d=X(0),f=je(),h=je(),g=X(!1),w=X(!1),v=X(!1);return ue(B(e,oe(({scrollTop:m})=>m)),t),ue(B(e,oe(({scrollHeight:m})=>m)),i),ue(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:g,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),br={lvl:0};function Ql(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 Ue(e){return e===br}function yr(e,t){if(!Ue(e))return t===e.k?e.v:t<e.k?yr(e.l,t):yr(e.r,t)}function Ut(e,t,n="k"){if(Ue(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Ut(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Ut(e.l,t,n)}function At(e,t,n){return Ue(e)?nc(t,n,1):t===e.k?it(e,{k:t,v:n}):t<e.k?rc(it(e,{l:At(e.l,t,n)})):rc(it(e,{r:At(e.r,t,n)}))}function Zn(){return br}function ho(e,t,n){if(Ue(e))return[];const r=Ut(e,t)[0];return Fg(ni(e,r,n))}function ti(e,t){if(Ue(e))return br;const{k:n,l:r,r:o}=e;if(t===n){if(Ue(r))return o;if(Ue(o))return r;{const[s,i]=tc(r);return po(it(e,{k:s,l:ec(r),v:i}))}}else return t<n?po(it(e,{l:ti(r,t)})):po(it(e,{r:ti(o,t)}))}function Pn(e){return Ue(e)?[]:[...Pn(e.l),{k:e.k,v:e.v},...Pn(e.r)]}function ni(e,t,n){if(Ue(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ni(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ni(s,t,n))),a}function po(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(ri(t))return oc(it(e,{lvl:n-1}));if(!Ue(t)&&!Ue(t.r))return it(t.r,{l:it(t,{r:t.r.l}),lvl:n,r:it(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ri(e))return oi(it(e,{lvl:n-1}));if(!Ue(r)&&!Ue(r.l)){const o=r.l,s=ri(o)?r.lvl-1:r.lvl;return it(o,{l:it(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:oi(it(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function it(e,t){return nc(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 ec(e){return Ue(e.r)?e.l:po(it(e,{r:ec(e.r)}))}function ri(e){return Ue(e)||e.lvl>e.r.lvl}function tc(e){return Ue(e.r)?[e.k,e.v]:tc(e.r)}function nc(e,t,n,r=br,o=br){return{k:e,l:r,lvl:n,r:o,v:t}}function rc(e){return oi(oc(e))}function oc(e){const{l:t}=e;return!Ue(t)&&t.lvl===e.lvl?it(t,{r:it(e,{l:t.r})}):e}function oi(e){const{lvl:t,r:n}=e;return!Ue(n)&&!Ue(n.r)&&n.lvl===t&&n.r.lvl===t?it(n,{l:it(e,{r:n.l}),lvl:t+1}):e}function Fg(e){return Ql(e,({k:t,v:n})=>({index:t,value:n}))}function sc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Sr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const si=De(()=>({recalcInProgress:X(!1)}),[],{singleton:!0});function ic(e,t,n){return e[mo(e,t,n)]}function mo(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 $g(e,t,n,r){const o=mo(e,t,r),s=mo(e,n,r,o);return e.slice(o,s+1)}function gn(e,t){return Math.round(e.getBoundingClientRect()[t])}function go(e){return!Ue(e.groupOffsetTree)}function ii({index:e},t){return t===e?0:t<e?-1:1}function zg(){return{groupIndices:[],groupOffsetTree:Zn(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Zn()}}function Bg(e,t){let n=Ue(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ue(e)){e=At(e,0,s);continue}const a=ho(e,i-1,o+1);if(a.some(Gg(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:h}of a)c?(o>=f||s===h)&&(e=ti(e,f)):(u=h!==s,c=!0),d>o&&o>=f&&h!==s&&(e=At(e,o+1,h));u&&(e=At(e,i,s))}return[e,n]}function Hg(e){return typeof e.groupIndex<"u"}function Ug({offset:e},t){return t===e?0:t<e?-1:1}function Cr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ic(t,e,ii),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function ac(e,t){if(!go(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function lc(e,t,n){if(Hg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=ac(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Wg(e,t,n,r=0){return r>0&&(t=Math.max(t,ic(e,r,ii).offset)),Ql($g(e,t,n,Ug),qg)}function Vg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Tt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ue(s)&&t.length===2){const h=t[0].size,g=t[1].size;i=n.reduce((w,v)=>At(At(w,v,h),v+1,g),i)}else[i,a]=Bg(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=ai(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,g)=>At(h,g,Cr(g,f,o)),Zn()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Kg(e){return Pn(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 cc(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 ai(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=mo(o,t-1,ii),a=o[c].offset;const u=Ut(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===Ut(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of ho(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 qg(e){return{index:e.index,value:e}}function Gg(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 Yg={offsetHeight:"height",offsetWidth:"width"},Jt=De(([{log:e},{recalcInProgress:t}])=>{const n=je(),r=je(),o=pt(r,0),s=je(),i=je(),a=X(0),c=X([]),u=X(void 0),d=X(void 0),f=X((C,T)=>gn(C,Yg[T])),h=X(void 0),g=X(0),w=zg(),v=pt(B(n,Ee(c,e,g),Xt(Vg,w),Ye()),w),m=pt(B(c,Ye(),Xt((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),oe(({prev:C})=>C)),[]);ue(B(c,we(C=>C.length>0),Ee(v,g),oe(([C,T,E])=>{const N=C.reduce((_,P,j)=>At(_,P,Cr(P,T.offsetTree,E)||j),Zn());return{...T,groupIndices:C,groupOffsetTree:N}})),v),ue(B(r,Ee(v),we(([C,{lastIndex:T}])=>C<T),oe(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),ue(u,d);const x=pt(B(u,oe(C=>C===void 0)),!0);ue(B(d,we(C=>C!==void 0&&Ue(nt(v).sizeTree)),oe(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Nt(B(n,Ee(v),Xt(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:w}),oe(C=>C.changed)));Fe(B(a,Xt((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),oe(C=>C.diff)),C=>{const{groupIndices:T}=nt(v);if(C>0)ke(t,!0),ke(s,C+cc(C,T));else if(C<0){const E=nt(m);E.length>0&&(C-=cc(-C,E)),ke(i,C)}}),Fe(B(a,Ee(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},Tt.ERROR)});const S=Nt(s);ue(B(s,Ee(v),oe(([C,T])=>{const E=T.groupIndices.length>0,N=[],_=T.lastSize;if(E){const P=yr(T.sizeTree,0);let j=0,z=0;for(;j<C;){const O=T.groupIndices[z],W=T.groupIndices.length===z+1?1/0:T.groupIndices[z+1]-O-1;N.push({endIndex:O,size:P,startIndex:O}),N.push({endIndex:O+1+W-1,size:_,startIndex:O+1}),z++,j+=W+1}const G=Pn(T.sizeTree);return j!==C&&G.shift(),G.reduce((O,{k:W,v:H})=>{let V=O.ranges;return O.prevSize!==0&&(V=[...O.ranges,{endIndex:W+C-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:W+C,prevSize:H,ranges:V}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return Pn(T.sizeTree).reduce((P,{k:j,v:z})=>({prevIndex:j+C,prevSize:z,ranges:[...P.ranges,{endIndex:j+C-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const I=Nt(B(i,Ee(v,g),oe(([C,{offsetTree:T},E])=>{const N=-C;return Cr(N,T,E)})));return ue(B(i,Ee(v,g),oe(([C,T,E])=>{if(T.groupIndices.length>0){if(Ue(T.sizeTree))return T;let N=Zn();const _=nt(m);let P=0,j=0,z=0;for(;P<-C;){z=_[j];const G=_[j+1]-z-1;j++,P+=G+1}if(N=Pn(T.sizeTree).reduce((G,{k:O,v:W})=>At(G,Math.max(0,O+C),W),N),P!==-C){const G=yr(T.sizeTree,z);N=At(N,0,G);const O=Ut(T.sizeTree,-C+1)[1];N=At(N,1,O)}return{...T,sizeTree:N,...ai(T.offsetTree,0,N,E)}}else{const N=Pn(T.sizeTree).reduce((_,{k:P,v:j})=>At(_,Math.max(0,P+C),j),Zn());return{...T,sizeTree:N,...ai(T.offsetTree,0,N,E)}}})),v),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:g,groupIndices:c,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:I,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Ge(mn,si),{singleton:!0});function Xg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const uc=De(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=je(),i=je(),a=Nt(B(s,oe(Xg)));return ue(B(a,oe(c=>c.totalCount)),n),ue(B(a,oe(c=>c.groupIndices)),e),ue(B(ot(o,t,r),we(([c,u])=>go(u)),oe(([c,u,d])=>Ut(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),Ye(),oe(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Ge(Jt,wt)),xn=De(([{log:e}])=>{const t=X(!1),n=Nt(B(t,we(r=>r),Ye()));return Fe(t,r=>{r&&nt(e)("props updated",{},Tt.DEBUG)}),{didMount:n,propsReady:t}},Ge(mn),{singleton:!0}),Jg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function dc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Jg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Tr=De(([{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 g=je(),w=je(),v=X(0);let m=null,x=null,b=null;function S(){m&&(m(),m=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),ke(c,!1)}return ue(B(g,Ee(n,f,r,v,a,i,h),Ee(e,s,o),oe(([[I,C,T,E,N,_,P,j],z,G,O])=>{const W=dc(I),{align:H,behavior:V,offset:$}=W,A=E-1,K=lc(W,C,A);let L=Cr(K,C.offsetTree,z)+_;H==="end"?(L+=G+Ut(C.sizeTree,K)[1]-T+O,K===A&&(L+=P)):H==="center"?L+=(G+Ut(C.sizeTree,K)[1]-T+O)/2:L-=N,$&&(L+=$);const J=Y=>{S(),Y?(j("retrying to scroll to",{location:I},Tt.DEBUG),ke(g,I)):(ke(w,!0),j("list did not change, scroll successful",{},Tt.DEBUG))};if(S(),V==="smooth"){let Y=!1;b=Fe(t,ce=>{Y=Y||ce}),m=Ht(d,()=>{J(Y)})}else m=Ht(B(t,Zg(150)),J);return x=setTimeout(()=>{S()},1200),ke(c,!0),j("scrolling from index to",{behavior:V,index:K,top:L},Tt.DEBUG),{behavior:V,top:L}})),u),{scrollTargetReached:w,scrollToIndex:g,topListHeight:v}},Ge(Jt,wt,mn),{singleton:!0});function Zg(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function li(e,t){e==0?t():requestAnimationFrame(()=>{li(e-1,t)})}function ci(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const kr=De(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=X(!0),c=X(0),u=X(!0);return ue(B(i,Ee(c),we(([d,f])=>!!f),Yt(!1)),a),ue(B(i,Ee(c),we(([d,f])=>!!f),Yt(!1)),u),Fe(B(ot(t,i),Ee(a,n,e,u),we(([[,d],f,{sizeTree:h},g,w])=>d&&(!Ue(h)||Js(g))&&!f&&!w),Ee(c)),([,d])=>{Ht(o,()=>{ke(u,!0)}),li(4,()=>{Ht(r,()=>{ke(a,!0)}),ke(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Ge(Jt,wt,Tr,xn),{singleton:!0});function fc(e,t){return Math.abs(e-t)<1.01}const Er="up",Ir="down",Qg="none",ex={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},tx=0,Nr=De(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=X(!1),a=X(!0),c=je(),u=je(),d=X(4),f=X(tx),h=pt(B(Qs(B(xe(o),jn(1),Yt(!0)),B(xe(o),jn(1),Yt(!1),Yl(100))),Ye()),!1),g=pt(B(Qs(B(n,Yt(!0)),B(n,Yt(!1),Yl(200))),Ye()),!1);ue(B(ot(xe(o),xe(f)),oe(([b,S])=>b<=S),Ye()),a),ue(B(a,cn(50)),u);const w=Nt(B(ot(r,xe(s),xe(t),xe(e),xe(d)),Xt((b,[{scrollHeight:S,scrollTop:I},C,T,E,N])=>{const _=I+C-S>-N,P={scrollHeight:S,scrollTop:I,viewportHeight:C};if(_){let z,G;return I>b.state.scrollTop?(z="SCROLLED_DOWN",G=b.state.scrollTop-I):(z="SIZE_DECREASED",G=b.state.scrollTop-I||b.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:G,state:P}}let j;return P.scrollHeight>b.state.scrollHeight?j="SIZE_INCREASED":C<b.state.viewportHeight?j="VIEWPORT_HEIGHT_DECREASING":I<b.state.scrollTop?j="SCROLLING_UPWARDS":j="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:j,state:P}},ex),Ye((b,S)=>b&&b.atBottom===S.atBottom))),v=pt(B(r,Xt((b,{scrollHeight:S,scrollTop:I,viewportHeight:C})=>{if(fc(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:I};{const T=S-(I+C)<1;return b.scrollTop!==I&&T?{changed:!0,jump:b.scrollTop-I,scrollHeight:S,scrollTop:I}:{changed:!0,jump:0,scrollHeight:S,scrollTop:I}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),we(b=>b.changed),oe(b=>b.jump)),0);ue(B(w,oe(b=>b.atBottom)),i),ue(B(i,cn(50)),c);const m=X(Ir);ue(B(r,oe(({scrollTop:b})=>b),Ye(),Xt((b,S)=>nt(g)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Er:Ir,prevScrollTop:S},{direction:Ir,prevScrollTop:0}),oe(b=>b.direction)),m),ue(B(r,cn(50),Yt(Qg)),m);const x=X(0);return ue(B(h,we(b=>!b),Yt(0)),x),ue(B(o,cn(100),Ee(h),we(([b,S])=>!!S),Xt(([b,S],[I])=>[S,I],[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:m,scrollVelocity:x}},Ge(wt)),xo="top",vo="bottom",hc="none";function pc(e,t,n){return typeof e=="number"?n===Er&&t===xo||n===Ir&&t===vo?e:0:n===Er?t===xo?e.main:e.reverse:t===vo?e.main:e.reverse}function mc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ui=De(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=je(),i=X(0),a=X(0),c=X(0),u=pt(B(ot(xe(r),xe(o),xe(n),xe(s,Sr),xe(c),xe(i),xe(t),xe(e),xe(a)),oe(([d,f,h,[g,w],v,m,x,b,S])=>{const I=d-b,C=m+x,T=Math.max(h-I,0);let E=hc;const N=mc(S,xo),_=mc(S,vo);return g-=b,g+=h+x,w+=h+x,w-=b,g>d+C-N&&(E=Er),w<d-T+f+_&&(E=Ir),E!==hc?[Math.max(I-h-pc(v,xo,E)-N,0),I-T-x+f+pc(v,vo,E)+_]:null}),we(d=>d!=null),Ye(Sr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},Ge(wt),{singleton:!0});function nx(e,t,n){if(go(t)){const r=ac(e,t);return[{index:Ut(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 di={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function wo(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,g=u,w=h-d;return{bottom:d,firstItemIndex:s,items:xc(e,o,s),offsetBottom:w,offsetTop:u,top:g,topItems:xc(t,o,s),topListHeight:t.reduce((v,m)=>m.size+v,0),totalCount:n}}function gc(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=ci(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return wo(u,[],a,o,n,r)}function xc(e,t,n){if(e.length===0)return[];if(!go(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=ho(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 On=De(([{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:g},{recalcInProgress:w}])=>{const v=X([]),m=X(0),x=je();ue(s.topItemsIndexes,v);const b=pt(B(ot(g,w,xe(c,Sr),xe(o),xe(r),xe(u),d,xe(v),xe(t),xe(n),e),we(([T,E,,N,,,,,,,_])=>{const P=_&&_.length!==N;return T&&!E&&!P}),oe(([,,[T,E],N,_,P,j,z,G,O,W])=>{const H=_,{offsetTree:V,sizeTree:$}=H,A=nt(m);if(N===0)return{...di,totalCount:N};if(T===0&&E===0)return A===0?{...di,totalCount:N}:gc(A,P,_,G,O,W||[]);if(Ue($))return A>0?null:wo(nx(ci(P,N),H,W),[],N,O,H,G);const K=[];if(z.length>0){const pe=z[0],me=z[z.length-1];let q=0;for(const M of ho($,pe,me)){const D=M.value,F=Math.max(M.start,pe),Q=Math.min(M.end,me);for(let te=F;te<=Q;te++)K.push({data:W==null?void 0:W[te],index:te,offset:q,size:D}),q+=D}}if(!j)return wo([],K,N,O,H,G);const L=z.length>0?z[z.length-1]+1:0,J=Wg(V,T,E,L);if(J.length===0)return null;const Y=N-1,ce=fo([],pe=>{for(const me of J){const q=me.value;let M=q.offset,D=me.start;const F=q.size;if(q.offset<T){D+=Math.floor((T-q.offset+O)/(F+O));const te=D-me.start;M+=te*F+te*O}D<L&&(M+=(L-D)*F,D=L);const Q=Math.min(me.end,Y);for(let te=D;te<=Q&&!(M>=E);te++)pe.push({data:W==null?void 0:W[te],index:te,offset:M,size:F}),M+=F+O}});return wo(ce,K,N,O,H,G)}),we(T=>T!==null),Ye()),di);ue(B(e,we(Js),oe(T=>T==null?void 0:T.length)),o),ue(B(b,oe(T=>T.topListHeight)),f),ue(f,a),ue(B(b,oe(T=>[T.top,T.bottom])),i),ue(B(b,oe(T=>T.items)),x);const S=Nt(B(b,we(({items:T})=>T.length>0),Ee(o,e),we(([{items:T},E])=>T[T.length-1].originalIndex===E-1),oe(([,T,E])=>[T-1,E]),Ye(Sr),oe(([T])=>T))),I=Nt(B(b,cn(200),we(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),oe(({items:T})=>T[0].index),Ye())),C=Nt(B(b,we(({items:T})=>T.length>0),oe(({items:T})=>{let E=0,N=T.length-1;for(;T[E].type==="group"&&E<N;)E++;for(;T[N].type==="group"&&N>E;)N--;return{endIndex:T[N].index,startIndex:T[E].index}}),Ye(sc)));return{endReached:S,initialItemCount:m,itemsRendered:x,listState:b,rangeChanged:C,startReached:I,topItemsIndexes:v,...h}},Ge(Jt,uc,ui,kr,Tr,Nr,xn,si),{singleton:!0}),vc=De(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=je(),i=pt(B(ot(n,e,r,t,o),oe(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return ue(xe(i),s),{totalListHeight:i,totalListHeightChanged:s}},Ge(wt,On),{singleton:!0}),rx=De(([{viewportHeight:e},{totalListHeight:t}])=>{const n=X(!1),r=pt(B(ot(n,e,t),we(([o])=>o),oe(([,o,s])=>Math.max(0,o-s)),cn(0),Ye()),0);return{alignToBottom:n,paddingTopAddition:r}},Ge(wt,vc),{singleton:!0}),wc=De(()=>({context:X(null)})),ox=({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,bc=De(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=je();return ue(B(d,Ee(t,c,n,s,o,r,a),Ee(e),oe(([[f,h,g,w,v,m,x,b],S])=>{const{align:I,behavior:C,calculateViewLocation:T=ox,done:E,...N}=f,_=lc(f,h,w-1),P=Cr(_,h.offsetTree,S)+v+m,j=P+Ut(h.sizeTree,_)[1],z=b+m,G=b+g-x,O=T({itemBottom:j,itemTop:P,locationParams:{align:I,behavior:C,...N},viewportBottom:G,viewportTop:z});return O?E&&Ht(B(i,we(W=>!W),jn(nt(i)?1:2)),E):E&&E(),O}),we(f=>f!==null)),u),{scrollIntoView:d}},Ge(Jt,wt,Tr,On,mn),{singleton:!0});function yc(e){return e?e==="smooth"?"smooth":"auto":!1}const sx=(e,t)=>typeof e=="function"?yc(e(t)):t&&yc(e),ix=De(([{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:g}])=>{const w=X(!1),v=je();let m=null;function x(C){ke(i,{align:"end",behavior:C,index:"LAST"})}Fe(B(ot(B(xe(t),jn(1)),c),Ee(xe(w),s,a,f),oe(([[C,T],E,N,_,P])=>{let j=T&&_,z="auto";return j&&(z=sx(E,N||P),j=j&&!!z),{followOutputBehavior:z,shouldFollow:j,totalCount:C}}),we(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{m&&(m(),m=null),nt(n)?requestAnimationFrame(()=>{nt(d)("following output to ",{totalCount:T},Tt.DEBUG),x(C)}):m=Ht(e,()=>{nt(d)("following output to ",{totalCount:T},Tt.DEBUG),x(C),m=null})});function b(C){const T=Ht(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!m&&(nt(d)("scrolling to bottom due to increased size",{},Tt.DEBUG),x("auto"))});setTimeout(T,100)}Fe(B(ot(xe(w),t,u),we(([C,,T])=>C&&T),Xt(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),we(({refreshed:C})=>C),Ee(w,t)),([,C])=>{nt(a)&&b(C!==!1)}),Fe(v,()=>{b(nt(w)!==!1)}),Fe(ot(xe(w),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=X(null),I=je();return ue(Qs(B(xe(r),oe(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),B(xe(t))),I),Fe(B(ot(B(I,jn(1)),c),Ee(xe(S),a,f,h),oe(([[C,T],E,N,_,P])=>T&&N&&(E==null?void 0:E({context:P,totalCount:C,scrollingInProgress:_}))),we(C=>!!C),cn(0)),C=>{m&&(m(),m=null),nt(n)?requestAnimationFrame(()=>{nt(d)("scrolling into view",{}),ke(g,C)}):m=Ht(e,()=>{nt(d)("scrolling into view",{}),ke(g,C),m=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:S}},Ge(Jt,Nr,Tr,kr,xn,mn,wt,wc,bc)),ax=De(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ue(B(a,Ee(s),we(([,c])=>c!==0),Ee(o,r,t,n,e),oe(([[,c],u,d,f,h,g=[]])=>gc(c,u,d,f,h,g))),i),{}),Ge(Jt,kr,On,xn),{singleton:!0}),lx=De(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=X(0);return Fe(B(e,Ee(r),we(([,o])=>o!==0),oe(([,o])=>({top:o}))),o=>{Ht(B(n,jn(1),we(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ke(t,o)})})}),{initialScrollTop:r}},Ge(xn,wt,On),{singleton:!0}),Sc=De(([{scrollVelocity:e}])=>{const t=X(!1),n=je(),r=X(!1);return ue(B(e,Ee(r,t,n),we(([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}),Ye()),t),Fe(B(ot(t,e,n),Ee(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Ge(Nr),{singleton:!0}),fi=De(([{scrollContainerState:e,scrollTo:t}])=>{const n=je(),r=je(),o=je(),s=X(!1),i=X(void 0);return ue(B(ot(n,r),oe(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),ue(B(t,Ee(r),oe(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Ge(wt)),cx=De(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=je(),d=X(void 0),f=X(null),h=X(null);return ue(a,f),ue(c,h),Fe(B(u,Ee(t,r,i,f,h,n)),([g,w,v,m,x,b,S])=>{const I=Kg(w.sizeTree);m&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=S,g({ranges:I,scrollTop:v})}),ue(B(d,we(Js),oe(ux)),o),ue(B(s,Ee(d),we(([,g])=>g!==void 0),Ye(),oe(([,g])=>g.ranges)),e),{getState:u,restoreStateFrom:d}},Ge(Jt,wt,kr,xn,fi));function ux(e){return{align:"start",index:0,offset:e.scrollTop}}const dx=De(([{topItemsIndexes:e}])=>{const t=X(0);return ue(B(t,we(n=>n>=0),oe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Ge(On));function Cc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const fx=Cc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),hx=De(([{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:g},{recalcInProgress:w}])=>{const v=Nt(B(c,Ee(i),Xt(([,x,b,S],[{bottom:I,items:C,offsetBottom:T,totalCount:E},N])=>{const _=I+T;let P=0;return b===E&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(P=_-S,P!==0&&(P+=N))),[P,C,E,_]},[0,[],0,0]),we(([x])=>x!==0),Ee(r,a,n,o,g,w),we(([,x,b,S,,,I])=>!I&&!S&&x!==0&&b===Er),oe(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Tt.DEBUG),x))));function m(x){x>0?(ke(t,{behavior:"auto",top:-x}),ke(e,0)):(ke(e,0),ke(t,{behavior:"auto",top:-x}))}return Fe(B(v,Ee(e,s)),([x,b,S])=>{S&&fx()?ke(e,b-x):m(-x)}),Fe(B(ot(pt(s,!1),e,w),we(([x,b,S])=>!x&&!S&&b!==0),oe(([x,b])=>b),cn(1)),m),ue(B(f,oe(x=>({top:-x}))),t),Fe(B(u,Ee(h,d),oe(([x,{groupIndices:b,lastSize:S,sizeTree:I},C])=>{function T(E){return E*(S+C)}if(b.length===0)return T(x);{let E=0;const N=yr(I,0);let _=0,P=0;for(;_<x;){_++,E+=N;let j=b.length===P+1?1/0:b[P+1]-b[P]-1;_+j>x&&(E-=N,j=x-_+1),_+=j,E+=T(j),P++}return E}})),x=>{ke(e,x),requestAnimationFrame(()=>{ke(t,{top:x}),requestAnimationFrame(()=>{ke(e,0),ke(w,!1)})})}),{deviation:e}},Ge(wt,Nr,On,Jt,mn,si)),px=De(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),Ge(ui,ax,xn,Sc,vc,lx,rx,fi,bc,mn,wc)),Tc=De(([{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:g,scrolledToInitialItem:w},v,m,x,{listState:b,topItemsIndexes:S,...I},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:N},_])=>(ue(I.rangeChanged,_.scrollSeekRangeChanged),ue(B(_.windowViewportRect,oe(P=>P.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:g,scrolledToInitialItem:w,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...I,..._,...v,sizes:c,...m}),Ge(Jt,kr,wt,cx,ix,On,Tr,hx,dx,uc,px));function mx(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 bo=typeof document<"u"?y.useLayoutEffect:y.useEffect;function kc(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(m,x){m.propsReady&&ke(m.propsReady,!1);for(const b of r){const S=m[t.required[b]];ke(S,x[b])}for(const b of o)if(b in x){const S=m[t.optional[b]];ke(S,x[b])}m.propsReady&&ke(m.propsReady,!0)}function u(m){return s.reduce((x,b)=>(x[b]=S=>{const I=m[t.methods[b]];ke(I,S)},x),{})}function d(m){return i.reduce((x,b)=>(x[b]=jg(m[t.events[b]]),x),{})}const f=y.forwardRef((m,x)=>{const{children:b,...S}=m,[I]=y.useState(()=>fo(Pg(e),E=>{c(E,S)})),[C]=y.useState(Gl(d,I));bo(()=>{for(const E of i)E in S&&Fe(C[E],S[E]);return()=>{Object.values(C).map(Zs)}},[S,C,I]),bo(()=>{c(I,S)}),y.useImperativeHandle(x,Kl(u(I)));const T=n;return l.jsx(a.Provider,{value:I,children:n?l.jsx(T,{...mx([...r,...o,...i],S),children:b}):b})}),h=m=>{const x=y.useContext(a);return y.useCallback(b=>{ke(x[m],b)},[x,m])},g=m=>{const x=y.useContext(a)[m],b=y.useCallback(S=>Fe(x,S),[x]);return y.useSyncExternalStore(b,()=>nt(x),()=>nt(x))},w=m=>{const x=y.useContext(a)[m],[b,S]=y.useState(Gl(nt,x));return bo(()=>Fe(x,I=>{I!==b&&S(Kl(I))}),[x,b]),b},v=y.version.startsWith("18")?g:w;return{Component:f,useEmitter:(m,x)=>{const b=y.useContext(a)[m];bo(()=>Fe(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const Ec=y.createContext(void 0),Ic=y.createContext(void 0),Nc=typeof document<"u"?y.useLayoutEffect:y.useEffect;function hi(e){return"self"in e}function gx(e){return"body"in e}function Ac(e,t,n,r=Jn,o,s){const i=y.useRef(null),a=y.useRef(null),c=y.useRef(null),u=y.useCallback(h=>{let g,w,v;const m=h.target;if(gx(m)||hi(m)){const b=hi(m)?m:m.defaultView;v=s?b.scrollX:b.scrollY,g=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?m.scrollLeft:m.scrollTop,g=s?m.scrollWidth:m.scrollHeight,w=s?m.offsetWidth:m.offsetHeight;const x=()=>{e({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():_s.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===g-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 g=i.current;if(!g||(s?"offsetWidth"in g&&g.offsetWidth===0:"offsetHeight"in g&&g.offsetHeight===0))return;const w=h.behavior==="smooth";let v,m,x;hi(g)?(m=Math.max(gn(g.document.documentElement,s?"width":"height"),s?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight),v=s?g.innerWidth:g.innerHeight,x=s?window.scrollX:window.scrollY):(m=g[s?"scrollWidth":"scrollHeight"],v=gn(g,s?"width":"height"),x=g[s?"scrollLeft":"scrollTop"]);const b=m-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),fc(v,m)||h.top===x){e({scrollHeight:m,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}),g.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 pi="-webkit-sticky",_c="sticky",mi=Cc(()=>{if(typeof document>"u")return _c;const e=document.createElement("div");return e.style.position=pi,e.style.position===pi?pi:_c});function gi(e){return e}const xx=De(()=>{const e=X(a=>`Item ${a}`),t=X(a=>`Group ${a}`),n=X({}),r=X(gi),o=X("div"),s=X(Jn),i=(a,c=null)=>pt(B(n,oe(u=>u[a]),Ye()),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")}}),vx=De(([e,t])=>({...e,...t}),Ge(Tc,xx)),wx=({height:e})=>l.jsx("div",{style:{height:e}}),bx={overflowAnchor:"none",position:mi(),zIndex:1},jc={overflowAnchor:"none"},yx={...jc,display:"inline-block",height:"100%"},Rc=y.memo(function({showTopList:e=!1}){const t=Se("listState"),n=Mt("sizeRanges"),r=Se("useWindowScroll"),o=Se("customScrollParent"),s=Mt("windowScrollContainerState"),i=Mt("scrollContainerState"),a=o||r?s:i,c=Se("itemContent"),u=Se("context"),d=Se("groupContent"),f=Se("trackItemSizes"),h=Se("itemSize"),g=Se("log"),w=Mt("gap"),v=Se("horizontalDirection"),{callbackRef:m}=Dg(n,h,f,e?Jn:a,g,w,o,v,Se("skipAnimationFrameInResizeObserver")),[x,b]=y.useState(0);xi("deviation",O=>{x!==O&&b(O)});const S=Se("EmptyPlaceholder"),I=Se("ScrollSeekPlaceholder")||wx,C=Se("ListComponent"),T=Se("ItemComponent"),E=Se("GroupComponent"),N=Se("computeItemKey"),_=Se("isSeeking"),P=Se("groupIndices").length>0,j=Se("alignToBottom"),z=Se("initialItemFinalLocationReached"),G=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},...z?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?l.jsx(S,{...mt(S,u)}):l.jsx(C,{...mt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:m,style:G,children:(e?t.topItems:t.items).map(O=>{const W=O.originalIndex,H=N(W+t.firstItemIndex,O.data,u);return _?y.createElement(I,{...mt(I,u),height:O.size,index:O.index,key:H,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?y.createElement(E,{...mt(E,u),"data-index":W,"data-item-index":O.index,"data-known-size":O.size,key:H,style:bx},d(O.index,u)):y.createElement(T,{...mt(T,u),...kx(T,O.data),"data-index":W,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:H,style:v?yx:jc},P?c(O.index,O.groupIndex,O.data,u):c(O.index,O.data,u))})})}),Sx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Cx={outline:"none",overflowX:"auto",position:"relative"},yo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Tx={position:mi(),top:0,width:"100%",zIndex:1};function mt(e,t){if(typeof e!="string")return{context:t}}function kx(e,t){return{item:typeof e=="string"?void 0:t}}const Ex=y.memo(function(){const e=Se("HeaderComponent"),t=Mt("headerHeight"),n=Se("HeaderFooterTag"),r=Rn(y.useMemo(()=>s=>{t(gn(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Ix=y.memo(function(){const e=Se("FooterComponent"),t=Mt("footerHeight"),n=Se("HeaderFooterTag"),r=Rn(y.useMemo(()=>s=>{t(gn(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null});function Pc({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:g,scrollToCallback:w}=Ac(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:g,style:{...f?Cx:Sx,...o},tabIndex:0,...i,...mt(c,s),children:r})})}function Oc({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"),g=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:m,scrollToCallback:x}=Ac(a,u,c,w,h);return Nc(()=>{var b;return m.current=h||((b=g.current)==null?void 0:b.ownerDocument.defaultView),()=>{m.current=null}},[m,h]),e("windowScrollTo",x),e("scrollBy",v),l.jsx(c,{ref:g,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...mt(c,s),children:r})})}const Nx=({children:e})=>{const t=y.useContext(Ec),n=Mt("viewportHeight"),r=Mt("fixedItemHeight"),o=Se("alignToBottom"),s=Se("horizontalDirection"),i=y.useMemo(()=>ql(n,c=>gn(c,s?"width":"height")),[n,s]),a=Rn(i,!0,Se("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:yo(o),children:e})},Ax=({children:e})=>{const t=y.useContext(Ec),n=Mt("windowViewportRect"),r=Mt("fixedItemHeight"),o=Se("customScrollParent"),s=Zl(n,o,Se("skipAnimationFrameInResizeObserver")),i=Se("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:yo(i),children:e})},_x=({children:e})=>{const t=Se("TopItemListComponent")||"div",n=Se("headerHeight"),r={...Tx,marginTop:`${n}px`},o=Se("context");return l.jsx(t,{style:r,...mt(t,o),children:e})},jx=y.memo(function(e){const t=Se("useWindowScroll"),n=Se("topItemsIndexes").length>0,r=Se("customScrollParent"),o=Se("context");return l.jsxs(r||t?Ox:Px,{...e,context:o,children:[n&&l.jsx(_x,{children:l.jsx(Rc,{showTopList:!0})}),l.jsxs(r||t?Ax:Nx,{children:[l.jsx(Ex,{}),l.jsx(Rc,{}),l.jsx(Ix,{})]})]})}),{Component:Rx,useEmitter:xi,useEmitterValue:Se,usePublisher:Mt}=kc(vx,{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"}},jx),Px=Pc({useEmitter:xi,useEmitterValue:Se,usePublisher:Mt}),Ox=Oc({useEmitter:xi,useEmitterValue:Se,usePublisher:Mt}),Mx=Rx;Ge(Tc,De(()=>{const e=X(u=>l.jsxs("td",{children:["Item $",u]})),t=X(null),n=X(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=X(null),o=X(null),s=X({}),i=X(gi),a=X(Jn),c=(u,d=null)=>pt(B(s,oe(f=>f[u]),Ye()),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")}})),mi();const Mc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Dx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Dc,floor:So,max:Ar,min:vi,round:Lc}=Math;function Fc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Lx(e){return{...Dx,items:e}}function Co(e,t){return e&&e.width===t.width&&e.height===t.height}function Fx(e,t){return e&&e.column===t.column&&e.row===t.row}const $x=De(([{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,g,{didMount:w,propsReady:v},{customScrollParent:m,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:I},C])=>{const T=X(0),E=X(0),N=X(Mc),_=X({height:0,width:0}),P=X({height:0,width:0}),j=je(),z=je(),G=X(0),O=X(null),W=X({column:0,row:0}),H=je(),V=je(),$=X(!1),A=X(0),K=X(!0),L=X(!1),J=X(!1);Fe(B(w,Ee(A),we(([M,D])=>!!D)),()=>{ke(K,!1)}),Fe(B(ot(w,K,P,_,A,L),we(([M,D,F,Q,,te])=>M&&!D&&F.height!==0&&Q.height!==0&&!te)),([,,,,M])=>{ke(L,!0),li(1,()=>{ke(j,M)}),Ht(B(u),()=>{ke(t,[0,0]),ke(K,!0)})}),ue(B(V,we(M=>M!=null&&M.scrollTop>0),Yt(0)),E),Fe(B(w,Ee(V),we(([,M])=>M!=null)),([,M])=>{M&&(ke(_,M.viewport),ke(P,M.item),ke(W,M.gap),M.scrollTop>0&&(ke($,!0),Ht(B(u,jn(1)),D=>{ke($,!1)}),ke(c,{top:M.scrollTop})))}),ue(B(_,oe(({height:M})=>M)),f),ue(B(ot(xe(_,Co),xe(P,Co),xe(W,(M,D)=>M&&M.column===D.column&&M.row===D.row),xe(u)),oe(([M,D,F,Q])=>({gap:F,item:D,scrollTop:Q,viewport:M}))),H),ue(B(ot(xe(T),r,xe(W,Fx),xe(P,Co),xe(_,Co),xe(O),xe(E),xe($),xe(K),xe(A)),we(([,,,,,,,M])=>!M),oe(([M,[D,F],Q,te,Ie,He,Te,,Ae,Le])=>{const{column:Ve,row:Me}=Q,{height:et,width:Xe}=te,{width:at}=Ie;if(Te===0&&(M===0||at===0))return Mc;if(Xe===0){const Je=ci(Le,M),xt=Je+Math.max(Te-1,0);return Lx(Fc(Je,xt,He))}const ft=$c(at,Xe,Ve);let ut,$e;Ae?D===0&&F===0&&Te>0?(ut=0,$e=Te-1):(ut=ft*So((D+Me)/(et+Me)),$e=ft*Dc((F+Me)/(et+Me))-1,$e=vi(M-1,Ar($e,ft-1)),ut=vi($e,Ar(0,ut))):(ut=0,$e=-1);const ee=Fc(ut,$e,He),{bottom:ae,top:he}=zc(Ie,Q,te,ee),Be=Dc(M/ft),qe=Be*et+(Be-1)*Me-ae;return{bottom:ae,itemHeight:et,items:ee,itemWidth:Xe,offsetBottom:qe,offsetTop:he,top:he}})),N),ue(B(O,we(M=>M!==null),oe(M=>M.length)),T),ue(B(ot(_,P,N,W),we(([M,D,{items:F}])=>F.length>0&&D.height!==0&&M.height!==0),oe(([M,D,{items:F},Q])=>{const{bottom:te,top:Ie}=zc(M,Q,D,F);return[Ie,te]}),Ye(Sr)),t);const Y=X(!1);ue(B(u,Ee(Y),oe(([M,D])=>D||M!==0)),Y);const ce=Nt(B(ot(N,T),we(([{items:M}])=>M.length>0),Ee(Y),we(([[M,D],F])=>{const Q=M.items[M.items.length-1].index===D-1;return(F||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===D)&&Q}),oe(([[,M]])=>M-1),Ye())),pe=Nt(B(xe(N),we(({items:M})=>M.length>0&&M[0].index===0),Yt(0),Ye())),me=Nt(B(xe(N),Ee($),we(([{items:M},D])=>M.length>0&&!D),oe(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),Ye(sc),cn(0)));ue(me,g.scrollSeekRangeChanged),ue(B(j,Ee(_,P,T,W),oe(([M,D,F,Q,te])=>{const Ie=dc(M),{align:He,behavior:Te,offset:Ae}=Ie;let Le=Ie.index;Le==="LAST"&&(Le=Q-1),Le=Ar(0,Le,vi(Q-1,Le));let Ve=wi(D,te,F,Le);return He==="end"?Ve=Lc(Ve-D.height+F.height):He==="center"&&(Ve=Lc(Ve-D.height/2+F.height/2)),Ae&&(Ve+=Ae),{behavior:Te,top:Ve}})),c);const q=pt(B(N,oe(M=>M.offsetBottom+M.bottom)),0);return ue(B(I,oe(M=>({height:M.visibleHeight,width:M.visibleWidth}))),_),{customScrollParent:m,data:O,deviation:G,footerHeight:o,gap:W,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:z,scrollTo:c,scrollToIndex:j,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:I,...g,gridState:N,horizontalDirection:J,initialTopMostItemIndex:A,totalListHeight:q,...h,endReached:ce,propsReady:v,rangeChanged:me,startReached:pe,stateChanged:H,stateRestoreInProgress:$,...C}},Ge(ui,wt,Nr,Sc,xn,fi,mn));function $c(e,t,n){return Ar(1,So((e+n)/(So(t)+n)))}function zc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=wi(e,t,n,r[0].index);return{bottom:wi(e,t,n,r[r.length-1].index)+o,top:s}}function wi(e,t,n,r){const o=$c(e.width,n.width,t.column),s=So(r/o),i=s*n.height+Ar(0,s-1)*t.row;return i>0?i+t.row:i}const zx=De(()=>{const e=X(f=>`Item ${f}`),t=X({}),n=X(null),r=X("virtuoso-grid-item"),o=X("virtuoso-grid-list"),s=X(gi),i=X("div"),a=X(Jn),c=(f,h=null)=>pt(B(t,oe(g=>g[f]),Ye()),h),u=X(!1),d=X(!1);return ue(xe(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")}}),Bx=De(([e,t])=>({...e,...t}),Ge($x,zx)),Hx=y.memo(function(){const e=Ze("gridState"),t=Ze("listClassName"),n=Ze("itemClassName"),r=Ze("itemContent"),o=Ze("computeItemKey"),s=Ze("isSeeking"),i=Dt("scrollHeight"),a=Ze("ItemComponent"),c=Ze("ListComponent"),u=Ze("ScrollSeekPlaceholder"),d=Ze("context"),f=Dt("itemDimensions"),h=Dt("gap"),g=Ze("log"),w=Ze("stateRestoreInProgress"),v=Dt("reportReadyState"),m=Rn(y.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const S=x.firstChild;if(S){const{height:I,width:C}=S.getBoundingClientRect();f({height:I,width:C})}h({column:Hc("column-gap",getComputedStyle(x).columnGap,g),row:Hc("row-gap",getComputedStyle(x).rowGap,g)})},[i,f,h,g]),!0,!1);return Nc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:l.jsx(c,{className:t,ref:m,...mt(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,{...mt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):y.createElement(a,{...mt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),Ux=y.memo(function(){const e=Ze("HeaderComponent"),t=Dt("headerHeight"),n=Ze("headerFooterTag"),r=Rn(y.useMemo(()=>s=>{t(gn(s,"height"))},[t]),!0,!1),o=Ze("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Wx=y.memo(function(){const e=Ze("FooterComponent"),t=Dt("footerHeight"),n=Ze("headerFooterTag"),r=Rn(y.useMemo(()=>s=>{t(gn(s,"height"))},[t]),!0,!1),o=Ze("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Vx=({children:e})=>{const t=y.useContext(Ic),n=Dt("itemDimensions"),r=Dt("viewportDimensions"),o=Rn(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:yo(!1),children:e})},Kx=({children:e})=>{const t=y.useContext(Ic),n=Dt("windowViewportRect"),r=Dt("itemDimensions"),o=Ze("customScrollParent"),s=Zl(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:yo(!1),children:e})},qx=y.memo(function({...e}){const t=Ze("useWindowScroll"),n=Ze("customScrollParent"),r=n||t?Yx:Gx,o=n||t?Kx:Vx,s=Ze("context");return l.jsx(r,{...e,...mt(r,s),children:l.jsxs(o,{children:[l.jsx(Ux,{}),l.jsx(Hx,{}),l.jsx(Wx,{})]})})}),{useEmitter:Bc,useEmitterValue:Ze,usePublisher:Dt}=kc(Bx,{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"}},qx),Gx=Pc({useEmitter:Bc,useEmitterValue:Ze,usePublisher:Dt}),Yx=Oc({useEmitter:Bc,useEmitterValue:Ze,usePublisher:Dt});function Hc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Tt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Xx=Yr.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 bi({className:e,variant:t,...n}){return l.jsx("div",{className:Z(Xx({variant:t}),e),...n})}function ie(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 Jx(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 Zt(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:g,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[c])||a,m=p.useMemo(()=>w,Object.values(w));return l.jsx(v.Provider,{value:m,children:g})};u.displayName=s+"Provider";function d(f,h){var v;const g=((v=h==null?void 0:h[e])==null?void 0:v[c])||a,w=p.useContext(g);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,Zx(o,...t)]}function Zx(...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:()=>{},Qx=p[" useInsertionEffect ".trim().toString()]||ct;function Mn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ev({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=tv(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 ev({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return Qx(()=>{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 tv(e){return typeof e=="function"}function Uc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Uc(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():Uc(e[o],null)}}}}function Ne(...e){return p.useCallback(yi(...e),e)}var nv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],be=nv.reduce((e,t)=>{const n=In.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 Wc(e,t){e&&Xr.flushSync(()=>e.dispatchEvent(t))}function rv(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var _t=e=>{const{present:t,children:n}=e,r=ov(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Ne(r.ref,sv(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};_t.displayName="Presence";function ov(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,c]=rv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const u=To(r.current);s.current=a==="mounted"?u:"none"},[a]),ct(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,g=To(u);e?c("MOUNT"):g==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&h!==g?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),ct(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=g=>{const v=To(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&v&&(c("ANIMATION_END"),!o.current)){const m=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=m)})}},h=g=>{g.target===t&&(s.current=To(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 To(e){return(e==null?void 0:e.animationName)||"none"}function sv(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 iv=p[" useId ".trim().toString()]||(()=>{}),av=0;function Qt(e){const[t,n]=p.useState(iv());return ct(()=>{n(r=>r??String(av++))},[e]),e||(t?`radix-${t}`:"")}var ko="Collapsible",[lv,YC]=Zt(ko),[cv,Si]=lv(ko),Vc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=Mn({prop:r,defaultProp:o??!1,onChange:i,caller:ko});return l.jsx(cv,{scope:n,disabled:s,contentId:Qt(),open:c,onOpenToggle:p.useCallback(()=>u(d=>!d),[u]),children:l.jsx(be.div,{"data-state":Ti(c),"data-disabled":s?"":void 0,...a,ref:t})})});Vc.displayName=ko;var Kc="CollapsibleTrigger",qc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Si(Kc,n);return l.jsx(be.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ti(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ie(e.onClick,o.onOpenToggle)})});qc.displayName=Kc;var Ci="CollapsibleContent",uv=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Si(Ci,e.__scopeCollapsible);return l.jsx(_t,{present:n||o.open,children:({present:s})=>l.jsx(dv,{...r,ref:t,present:s})})});uv.displayName=Ci;var dv=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Si(Ci,n),[a,c]=p.useState(r),u=p.useRef(null),d=Ne(t,u),f=p.useRef(0),h=f.current,g=p.useRef(0),w=g.current,v=i.open||a,m=p.useRef(v),x=p.useRef(void 0);return p.useEffect(()=>{const b=requestAnimationFrame(()=>m.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,g.current=S.width,m.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(be.div,{"data-state":Ti(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 Ti(e){return e?"open":"closed"}var fv=Vc;const Gc=fv,Yc=qc,_r=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}));_r.displayName="Card";const jr=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 p-6",e),...t}));jr.displayName="CardHeader";const Rr=p.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:Z("text-2xl font-semibold leading-none tracking-tight",e),...t}));Rr.displayName="CardTitle";const Xc=p.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));Xc.displayName="CardDescription";const Eo=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("p-6 pt-0",e),...t}));Eo.displayName="CardContent";const Jc=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Z("flex items-center p-6 pt-0",e),...t}));Jc.displayName="CardFooter";function Zc(){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 Dn=Zc();function hv(e){Dn=e}const Qc=/[&<>"']/,pv=new RegExp(Qc.source,"g"),eu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,mv=new RegExp(eu.source,"g"),gv={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},tu=e=>gv[e];function gt(e,t){if(t){if(Qc.test(e))return e.replace(pv,tu)}else if(eu.test(e))return e.replace(mv,tu);return e}const xv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function nu(e){return e.replace(xv,(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 vv=/(^|[^\[])\^/g;function We(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(vv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const wv=/[^\w:]/g,bv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function ru(e,t,n){if(e){let r;try{r=decodeURIComponent(nu(n)).replace(wv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!bv.test(n)&&(n=Tv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Io={},yv=/^[^:]+:\/*[^/]*$/,Sv=/^([^:]+:)[\s\S]*$/,Cv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Tv(e,t){Io[" "+e]||(yv.test(e)?Io[" "+e]=e+"/":Io[" "+e]=Ao(e,"/",!0)),e=Io[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Sv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Cv,"$1")+t:e+t}const No={exec:function(){}};function ou(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 Ao(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 kv(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 Ev(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 su(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function iu(e,t,n,r){const o=t.href,s=t.title?gt(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:gt(i)}}function Iv(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 ki{constructor(t){this.options=t||Dn}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:Ao(r,`
41
41
  `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Iv(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=Ao(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,g,w,v=n[1].trim();const m=v.length>1,x={type:"list",raw:"",ordered:m,start:m?+v.slice(0,-1):"",loose:!1,items:[]};v=m?`\\d{1,9}\\${v.slice(-1)}`:`\\${v}`,this.options.pedantic&&(v=m?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(`
@@ -128,7 +128,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
128
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 ob(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 sb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function cd(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 ib(e,t,n=16){const[r,o]=y.useState(e),s=y.useRef(e),i=y.useRef(null),a=y.useRef(null);return y.useEffect(()=>{if(s.current=e,!t){i.current&&cancelAnimationFrame(i.current),a.current&&clearTimeout(a.current),o(e);return}return a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{i.current&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>o(s.current))},n),()=>{i.current&&cancelAnimationFrame(i.current),a.current&&clearTimeout(a.current)}},[e,t,n]),r}function ab({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:Z("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const ud=y.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:o=16,isEditing:s=!1,showActions:i=!0,showTimestamp:a=!0,showAgentName:c=!0,layoutSize:u="desktop",truncateToolMessages:d=!0,toolMessagePreviewLength:f=200,truncateUserMessages:h=!0,userMessagePreviewLength:g=200,customStyles:w={},onEdit:v,onRegenerate:m,onCancelEdit:x,onCopy:b}){const[S,I]=y.useState(!1),[C,T]=y.useState("collapsed"),[E,N]=y.useState(!1),{currentThreadId:_}=wr(),{toast:P}=Ai(),[j,z]=y.useState({}),[G,O]=y.useState(!1),[W,H]=y.useState(null),V=u==="phone"||u==="half-screen",$=t.role,A=$==="tool",K=!(r&&$!=="user"),L=y.useMemo(()=>{switch($){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[$]),J=y.useMemo(()=>eb(t.content),[t.content]),Y=y.useMemo(()=>tb(t.content),[t.content]),ce=y.useMemo(()=>t.content.filter(ee=>ee.type==="image_url"),[t.content]),pe=y.useMemo(()=>t.content.filter(ee=>ee.type==="file"),[t.content]),me=y.useMemo(()=>t.content.filter(ee=>ee.type==="interrupt"),[t.content]),q=y.useMemo(()=>rb(t.content),[t.content]);y.useMemo(()=>ob(t.content),[t.content]);const M=y.useMemo(()=>q.length<=$n?q:`${q.slice(0,$n)}
129
129
  … [truncated ${q.length-$n} chars]`,[q]),D=ib(J,r,o),F=y.useCallback(async(ee="all")=>{const he=ee==="visible"&&A?M:A?q:J;async function Be(qe){try{await navigator.clipboard.writeText(qe)}catch{try{const Je=document.createElement("textarea");Je.value=qe,Je.setAttribute("readonly",""),Je.style.position="absolute",Je.style.left="-9999px",document.body.appendChild(Je),Je.select(),document.execCommand("copy"),document.body.removeChild(Je)}catch(Je){throw console.error("Failed to copy:",Je),Je}}}try{await Be(he),I(!0),setTimeout(()=>I(!1),2e3),b==null||b(he)}catch(qe){console.error("Failed to copy:",qe)}},[A,q,J,M,b]),Q=y.useCallback(()=>{if(!v)return;const ee=A?q:J;v(t.id,ee)},[v,t.id,A,q,J]),te=y.useCallback(()=>{m==null||m(n)},[m,n]),Ie=y.useCallback(async(ee,ae,he)=>{if(!K){ee.preventDefault();return}if(j[he]){ee.preventDefault();return}try{const Be=String(ae.url??""),qe=Be.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(qe){ee.preventDefault();const Je=qe[1],xt=ae.name||`file_${Je}`,lt=ae.mimeType||"application/octet-stream";H({id:Je,name:xt,mimeType:lt}),O(!0);return}if(Be.startsWith("data:")){ee.preventDefault(),z(lt=>({...lt,[he]:!0}));const Je=`${ae.name}_${ae.size}_${Date.now()}`,xt=P({title:"Fetching file...",description:"",open:!0});try{const lt=await jv(_??void 0);if(!lt||!Array.isArray(lt))throw new Error("Invalid file list response");const vt=lt.find(an=>!an||typeof an!="object"||!((an.filename??"")===(ae.name??""))?!1:typeof ae.size=="number"&&typeof an.size=="number"?an.size===ae.size:!0);if(!(vt!=null&&vt.id))throw new Error(`File "${ae.name}" is not yet available on the server`);if(!vt.id||!vt.filename)throw new Error("Invalid file data received from server");H({id:vt.id,name:ae.name||vt.filename||`file_${vt.id}`,mimeType:ae.mimeType||vt.mime_type||"application/octet-stream"}),O(!0),xt.update({id:xt.id,title:"Success",description:`Opened ${ae.name}`,open:!0})}catch(lt){console.error("Failed to fetch server file:",lt);const vt=lt instanceof Error?lt.message:"Unknown error occurred";xt.update({id:xt.id,title:"Failed",description:vt}),P({title:"Failed to fetch file",description:vt,open:!0})}finally{z(lt=>({...lt,[he]:!1}))}}}catch(Be){console.error("File click error:",Be),z(qe=>({...qe,[he]:!1}))}},[K,j,P,_]),He=y.useCallback(()=>{const ae=Z(V?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",L);switch($){case"user":return l.jsx(ne.User,{className:ae});case"assistant":return l.jsx(ne.Bot,{className:ae});case"tool":return l.jsx(ne.Wrench,{className:ae});default:return l.jsx(ne.Bot,{className:ae})}},[V,L,$]),Te=y.useCallback(()=>{const ee="group relative mb-4 flex w-full";switch($){case"user":return Z(ee,"justify-end");case"assistant":case"tool":case"system":return Z(ee,"justify-start");default:return ee}},[$]),Ae=y.useCallback(()=>{const ee=Z("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",V&&"px-3 py-2 text-sm");switch($){case"user":return Z(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 Z(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 Z(ee,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return Z(ee,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return Z(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")}},[V,$]),{handleInterrupt:Le}=wr(),Ve=y.useCallback(async ee=>{try{const ae=ee.id||`interrupt-${Date.now()}`;await Le(ae,!0)}catch(ae){console.error("Failed to approve interrupt:",ae)}},[Le]),Me=y.useCallback(async ee=>{try{const ae=ee.id||`interrupt-${Date.now()}`;await Le(ae,!1)}catch(ae){console.error("Failed to reject interrupt:",ae)}},[Le]),et=y.useCallback(({part:ee,i:ae})=>{if(ee.type==="text")return l.jsx(jo,{content:ee.text,allowHtml:!1},ae);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"})},ae)}if(ee.type==="file"){const he=ee,Be=he.name||"file";return l.jsxs("a",{href:he.url,onClick:qe=>Ie(qe,he,ae),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
130
130
  dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[j[ae]?l.jsx(ne.Loader,{className:"h-4 w-4 animate-spin"}):null,l.jsxs("span",{className:"truncate max-w-[180px]",children:[Be,j[ae]?" (processing)":""]})]},ae)}return ee.type==="interrupt"?l.jsx(cb,{interruptPart:ee,onApprove:Ve,onReject:Me},ae):null},[Ie,j,Ve,Me]),Xe=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"})]}),[]),at=y.useCallback(()=>{const ae=id($,D)?Wi(D):null;if(ae!==null)return l.jsx(dd,{data:ae});const he=Qw(Zw(D)),Be=D.trim().length===0;return l.jsx(l.Fragment,{children:Be?l.jsx("div",{className:"w-full",children:l.jsxs("div",{className:"animate-pulse space-y-2",children:[l.jsx("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-3/4"}),l.jsx("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-5/6"}),l.jsx("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-2/3"})]})}):l.jsx("pre",{className:Z("whitespace-pre-wrap break-words font-sans leading-relaxed transition-opacity duration-200",V&&"text-xs"),children:he})})},[$,D,V]),ft=y.useCallback(()=>{const ee=J.trim(),he=id($,ee)?Wi(ee):null;if(he!==null)return l.jsx(dd,{data:he});if($==="user"&&h){const Be=ee;if(Be.length>g)return l.jsxs(Gc,{open:E,onOpenChange:N,children:[l.jsx("div",{className:Z("text-sm text-[hsl(var(--chat-bubble-user-text))]",V&&"text-xs"),children:E?l.jsx(jo,{content:Be,allowHtml:!1}):l.jsxs("pre",{className:Z("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",V&&"text-xs"),children:[Be.substring(0,g),"..."]})}),l.jsx(Yc,{asChild:!0,children:l.jsx(Oe,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:E?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 (",Be.length-g," chars)"]})})})]})}return l.jsx(jo,{content:J.trim(),allowHtml:!1})},[J,$,h,g,E,V]),ut=y.useCallback(()=>{if(!(J.trim().length>0||ce.length>0||pe.length>0||me.length>0)&&!r)return Xe();if(t.model==="reflection"){const ae=J.trim(),he=Wi(ae);if(he&&typeof he=="object")return l.jsx(ub,{data:he})}if(A&&Y.name==="get_issues"){const ae=t.content.find(qe=>qe.type==="tool_end"),he=(ae==null?void 0:ae.output)??q,Be=ld(he);if(Be)return l.jsx(db,{issues:Be})}if(A){const ae=nb(t.content);if(ae.length>0)return l.jsx("div",{className:"space-y-2",children:ae.map((he,Be)=>{const qe=typeof he.output=="string"?he.output:Vi(he.output),Je=qe.length>$n?`${qe.slice(0,$n)}
131
- … [truncated ${qe.length-$n} chars]`:qe,xt=C==="expanded";return l.jsxs(Gc,{open:xt,onOpenChange:lt=>T(lt?"expanded":"preview"),children:[l.jsx("div",{className:"flex items-center gap-2 text-xs",children:l.jsx(bi,{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:xt?Je:Je.slice(0,f)+(Je.length>f?"...":"")})}),l.jsx(Yc,{asChild:!0,children:l.jsx(Oe,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:xt?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??Be)})})}if(!A)return r?l.jsxs("div",{"aria-busy":"true",role:"status",children:[at(),r&&l.jsx(ab,{className:L})]}):l.jsx("div",{className:"space-y-2",children:t.content.map((ae,he)=>l.jsx(et,{part:ae,i:he},he))})},[J,ce.length,pe.length,r,t.model,A,Y.name,q,C,d,Xe,at,ft,L]),ze=y.useMemo(()=>sb(t),[t]);return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:Z(Te(),w.container),children:l.jsxs("div",{className:Z(Ae(),w.content),children:[(a||c||A)&&l.jsxs("div",{className:Z("flex items-center justify-between mb-2 pb-2 border-b border-current/10",V&&"mb-1 pb-1",L,w.header),children:[l.jsxs("div",{className:"flex items-center gap-2",children:[He(),c&&ze&&l.jsx("span",{className:Z("font-medium",V?"text-xs":"text-sm"),children:ze}),A&&Y.name&&l.jsxs(bi,{variant:"outline",className:Z("text-xs flex items-center gap-1 cursor-pointer",L,"border border-current/40",V&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":C!=="collapsed",onKeyDown:ee=>{(ee.key==="Enter"||ee.key===" ")&&(ee.preventDefault(),T(ae=>ae==="collapsed"?"preview":"collapsed"))},onClick:()=>T(ee=>ee==="collapsed"?"preview":"collapsed"),children:[l.jsx("span",{children:Y.name}),l.jsx("span",{className:"inline-flex items-center",children:C!=="collapsed"?l.jsx(ne.ChevronUp,{className:"h-3 w-3"}):l.jsx(ne.ChevronDown,{className:"h-3 w-3"})})]}),A&&!Y.name&&l.jsx(Oe,{variant:"ghost",size:"sm",className:Z("h-6 px-1",L,"hover:bg-foreground/10"),onClick:()=>T(ee=>ee==="collapsed"?"preview":"collapsed"),children:l.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",C!=="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:[a&&t.createdAt&&l.jsx("time",{className:Z("text-xs opacity-60",L,V&&"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))}),i&&!s&&l.jsxs("div",{className:Z("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",w.actions),children:[l.jsxs("div",{className:"relative",children:[l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>F(A?"visible":"all"),className:Z("h-6 w-6 p-0 hover:bg-foreground/10",L,V&&"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(S?"text-success":L,V?"h-3 w-3":"h-4 w-4")})}),A&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>F("all"),className:Z("h-6 px-1 text-xs hover:bg-foreground/10",L),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),$==="user"&&v&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:Q,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",L,V&&"h-5 w-5"),"aria-label":"Edit message",children:l.jsx(ne.Edit,{className:Z(L,V?"h-3 w-3":"h-4 w-4")})}),$==="assistant"&&m&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:te,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",L,V&&"h-5 w-5"),"aria-label":"Regenerate response",children:l.jsx(ne.RotateCcw,{className:Z(L,V?"h-3 w-3":"h-4 w-4")})})]})]})]}),l.jsx("div",{className:"relative",children:ut()}),A&&C==="expanded"&&(Y.toolCallId||Y.name)&&l.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",V&&"text-xs"),children:[Y.name&&l.jsxs("div",{children:["Function: ",Y.name]}),Y.toolCallId&&l.jsxs("div",{children:["Call ID: ",Y.toolCallId]})]}),!(a||c||A)&&i&&!s&&l.jsxs("div",{className:Z("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",w.actions),children:[l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>F(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",V&&"h-5 w-5"),children:l.jsx(ne.Copy,{className:Z(S?"text-success":"text-current",V?"h-3 w-3":"h-4 w-4")})}),$==="user"&&v&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:Q,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",V&&"h-5 w-5"),children:l.jsx(ne.Edit,{className:Z("text-current",V?"h-3 w-3":"h-4 w-4")})}),$==="assistant"&&m&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:te,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",V&&"h-5 w-5"),children:l.jsx(ne.RotateCcw,{className:Z("text-current",V?"h-3 w-3":"h-4 w-4")})})]})]})}),W&&l.jsx(Jw,{isOpen:G,onClose:()=>{O(!1),H(null)},fileId:W.id,fileName:W.name,mimeType:W.mimeType})]})},(e,t)=>{var i,a,c,u,d,f,h,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&cd(e.message)===cd(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)===((g=t.customStyles)==null?void 0:g.header);return o&&s});function dd({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?l.jsx("div",{className:Xo,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:Vi(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:Xo,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:Xo,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:lb(i)})]},s))})})}return l.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Vi(e)})}function lb(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(Or(e))})}catch{return String(e)}}function cb({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return l.jsxs(_r,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[l.jsxs(jr,{className:"pb-3",children:[l.jsx(Rr,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),l.jsx(Xc,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),l.jsx(Jc,{className:"pt-0",children:l.jsxs("div",{className:"flex gap-2 ml-auto",children:[l.jsx(Oe,{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(Oe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function ub({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 db({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:Xo,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 fd=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ki=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:g,followNewMessages:w=!0,isNavigatingCheckpoint:v=!1,onScrollAway:m,onAtBottom:x},b)=>{const S=y.useRef(null),I=y.useRef(null),C=y.useRef(!1),[T,E]=y.useState(!0),N=y.useCallback(j=>{E(j),m&&m(!j),x&&x(j)},[m,x]),_=y.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),P=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:g||"No messages yet. Start a conversation!"})}):l.jsx("div",{className:f,style:h,children:l.jsx(Mx,{ref:j=>{S.current=j},scrollerRef:j=>{I.current=j instanceof HTMLDivElement?j:null},data:e,followOutput:P,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_&&_()},atBottomStateChange:N,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(j,z)=>fd(z,j),itemContent:(j,z)=>{const G=fd(z,j);return l.jsx("div",{className:"mb-4 last:mb-0","data-message-id":G,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:l.jsx(ud,{message:z,messageIndex:j,isStreamingMessage:t&&n===z.id,streamingDebounceMs:r,isEditing:i===z.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:c,onRegenerate:()=>u(j),onCancelEdit:d})})}})})});Ki.displayName="MessageList";const Jo=1e4;function fb(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,`
131
+ … [truncated ${qe.length-$n} chars]`:qe,xt=C==="expanded";return l.jsxs(Gc,{open:xt,onOpenChange:lt=>T(lt?"expanded":"preview"),children:[l.jsx("div",{className:"flex items-center gap-2 text-xs",children:l.jsx(bi,{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:xt?Je:Je.slice(0,f)+(Je.length>f?"...":"")})}),l.jsx(Yc,{asChild:!0,children:l.jsx(Oe,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:xt?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??Be)})})}if(!A)return r?l.jsxs("div",{"aria-busy":"true",role:"status",children:[at(),r&&l.jsx(ab,{className:L})]}):l.jsx("div",{className:"space-y-2",children:t.content.map((ae,he)=>l.jsx(et,{part:ae,i:he},he))})},[J,ce.length,pe.length,r,t.model,A,Y.name,q,C,d,Xe,at,ft,L]),$e=y.useMemo(()=>sb(t),[t]);return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:Z(Te(),w.container),children:l.jsxs("div",{className:Z(Ae(),w.content),children:[(a||c||A)&&l.jsxs("div",{className:Z("flex items-center justify-between mb-2 pb-2 border-b border-current/10",V&&"mb-1 pb-1",L,w.header),children:[l.jsxs("div",{className:"flex items-center gap-2",children:[He(),c&&$e&&l.jsx("span",{className:Z("font-medium",V?"text-xs":"text-sm"),children:$e}),A&&Y.name&&l.jsxs(bi,{variant:"outline",className:Z("text-xs flex items-center gap-1 cursor-pointer",L,"border border-current/40",V&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":C!=="collapsed",onKeyDown:ee=>{(ee.key==="Enter"||ee.key===" ")&&(ee.preventDefault(),T(ae=>ae==="collapsed"?"preview":"collapsed"))},onClick:()=>T(ee=>ee==="collapsed"?"preview":"collapsed"),children:[l.jsx("span",{children:Y.name}),l.jsx("span",{className:"inline-flex items-center",children:C!=="collapsed"?l.jsx(ne.ChevronUp,{className:"h-3 w-3"}):l.jsx(ne.ChevronDown,{className:"h-3 w-3"})})]}),A&&!Y.name&&l.jsx(Oe,{variant:"ghost",size:"sm",className:Z("h-6 px-1",L,"hover:bg-foreground/10"),onClick:()=>T(ee=>ee==="collapsed"?"preview":"collapsed"),children:l.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",C!=="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:[a&&t.createdAt&&l.jsx("time",{className:Z("text-xs opacity-60",L,V&&"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))}),i&&!s&&l.jsxs("div",{className:Z("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",w.actions),children:[l.jsxs("div",{className:"relative",children:[l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>F(A?"visible":"all"),className:Z("h-6 w-6 p-0 hover:bg-foreground/10",L,V&&"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(S?"text-success":L,V?"h-3 w-3":"h-4 w-4")})}),A&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>F("all"),className:Z("h-6 px-1 text-xs hover:bg-foreground/10",L),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),$==="user"&&v&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:Q,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",L,V&&"h-5 w-5"),"aria-label":"Edit message",children:l.jsx(ne.Edit,{className:Z(L,V?"h-3 w-3":"h-4 w-4")})}),$==="assistant"&&m&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:te,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",L,V&&"h-5 w-5"),"aria-label":"Regenerate response",children:l.jsx(ne.RotateCcw,{className:Z(L,V?"h-3 w-3":"h-4 w-4")})})]})]})]}),l.jsx("div",{className:"relative",children:ut()}),A&&C==="expanded"&&(Y.toolCallId||Y.name)&&l.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",V&&"text-xs"),children:[Y.name&&l.jsxs("div",{children:["Function: ",Y.name]}),Y.toolCallId&&l.jsxs("div",{children:["Call ID: ",Y.toolCallId]})]}),!(a||c||A)&&i&&!s&&l.jsxs("div",{className:Z("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",w.actions),children:[l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>F(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",V&&"h-5 w-5"),children:l.jsx(ne.Copy,{className:Z(S?"text-success":"text-current",V?"h-3 w-3":"h-4 w-4")})}),$==="user"&&v&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:Q,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",V&&"h-5 w-5"),children:l.jsx(ne.Edit,{className:Z("text-current",V?"h-3 w-3":"h-4 w-4")})}),$==="assistant"&&m&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:te,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",V&&"h-5 w-5"),children:l.jsx(ne.RotateCcw,{className:Z("text-current",V?"h-3 w-3":"h-4 w-4")})})]})]})}),W&&l.jsx(Jw,{isOpen:G,onClose:()=>{O(!1),H(null)},fileId:W.id,fileName:W.name,mimeType:W.mimeType})]})},(e,t)=>{var i,a,c,u,d,f,h,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&cd(e.message)===cd(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)===((g=t.customStyles)==null?void 0:g.header);return o&&s});function dd({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?l.jsx("div",{className:Xo,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:Vi(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:Xo,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:Xo,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:lb(i)})]},s))})})}return l.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Vi(e)})}function lb(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(Or(e))})}catch{return String(e)}}function cb({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return l.jsxs(_r,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[l.jsxs(jr,{className:"pb-3",children:[l.jsx(Rr,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),l.jsx(Xc,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),l.jsx(Jc,{className:"pt-0",children:l.jsxs("div",{className:"flex gap-2 ml-auto",children:[l.jsx(Oe,{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(Oe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function ub({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 db({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:Xo,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 fd=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ki=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:g,followNewMessages:w=!0,isNavigatingCheckpoint:v=!1,onScrollAway:m,onAtBottom:x},b)=>{const S=y.useRef(null),I=y.useRef(null),C=y.useRef(!1),[T,E]=y.useState(!0),N=y.useCallback(j=>{E(j),m&&m(!j),x&&x(j)},[m,x]),_=y.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),P=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:g||"No messages yet. Start a conversation!"})}):l.jsx("div",{className:f,style:h,children:l.jsx(Mx,{ref:j=>{S.current=j},scrollerRef:j=>{I.current=j instanceof HTMLDivElement?j:null},data:e,followOutput:P,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_&&_()},atBottomStateChange:N,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(j,z)=>fd(z,j),itemContent:(j,z)=>{const G=fd(z,j);return l.jsx("div",{className:"mb-4 last:mb-0","data-message-id":G,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:l.jsx(ud,{message:z,messageIndex:j,isStreamingMessage:t&&n===z.id,streamingDebounceMs:r,isEditing:i===z.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:c,onRegenerate:()=>u(j),onCancelEdit:d})})}})})});Ki.displayName="MessageList";const Jo=1e4;function fb(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,"&lt;").replace(/>/g,"&gt;").trim()}function hb(e,t=Jo){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 pb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),hb(t),fb(t)}function qi(e){const t=e+"CollectionProvider",[n,r]=Zt(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:m,children:x}=v,b=y.useRef(null),S=y.useRef(new Map).current;return l.jsx(o,{scope:m,itemMap:S,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",c=In.createSlot(a),u=y.forwardRef((v,m)=>{const{scope:x,children:b}=v,S=s(a,x),I=Ne(m,S.collectionRef);return l.jsx(c,{ref:I,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=In.createSlot(d),g=y.forwardRef((v,m)=>{const{scope:x,children:b,...S}=v,I=y.useRef(null),C=Ne(m,I),T=s(d,x);return y.useEffect(()=>(T.itemMap.set(I,{ref:I,...S}),()=>void T.itemMap.delete(I))),l.jsx(h,{[f]:"",ref:C,children:b})});g.displayName=d;function w(v){const m=s(e+"CollectionConsumer",v);return y.useCallback(()=>{const b=m.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(m.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[m.collectionRef,m.itemMap])}return[{Provider:i,Slot:u,ItemSlot:g},w,r]}var mb=p.createContext(void 0);function Zo(e){const t=p.useContext(mb);return e||t||"ltr"}const gb=["top","right","bottom","left"],yn=Math.min,jt=Math.max,Qo=Math.round,es=Math.floor,tn=e=>({x:e,y:e}),xb={left:"right",right:"left",bottom:"top",top:"bottom"},vb={start:"end",end:"start"};function Gi(e,t,n){return jt(e,yn(t,n))}function un(e,t){return typeof e=="function"?e(t):e}function dn(e){return e.split("-")[0]}function rr(e){return e.split("-")[1]}function Yi(e){return e==="x"?"y":"x"}function Xi(e){return e==="y"?"height":"width"}const wb=new Set(["top","bottom"]);function nn(e){return wb.has(dn(e))?"y":"x"}function Ji(e){return Yi(nn(e))}function bb(e,t,n){n===void 0&&(n=!1);const r=rr(e),o=Ji(e),s=Xi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=ts(i)),[i,ts(i)]}function yb(e){const t=ts(e);return[Zi(e),t,Zi(t)]}function Zi(e){return e.replace(/start|end/g,t=>vb[t])}const hd=["left","right"],pd=["right","left"],Sb=["top","bottom"],Cb=["bottom","top"];function Tb(e,t,n){switch(e){case"top":case"bottom":return n?t?pd:hd:t?hd:pd;case"left":case"right":return t?Sb:Cb;default:return[]}}function kb(e,t,n,r){const o=rr(e);let s=Tb(dn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Zi)))),s}function ts(e){return e.replace(/left|right|bottom|top/g,t=>xb[t])}function Eb(e){return{top:0,right:0,bottom:0,left:0,...e}}function md(e){return typeof e!="number"?Eb(e):{top:e,right:e,bottom:e,left:e}}function ns(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 gd(e,t,n){let{reference:r,floating:o}=e;const s=nn(t),i=Ji(t),a=Xi(i),c=dn(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 g;switch(c){case"top":g={x:d,y:r.y-o.height};break;case"bottom":g={x:d,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:f};break;case"left":g={x:r.x-o.width,y:f};break;default:g={x:r.x,y:r.y}}switch(rr(t)){case"start":g[i]-=h*(n&&u?-1:1);break;case"end":g[i]+=h*(n&&u?-1:1);break}return g}const Ib=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}=gd(u,r,c),h=r,g={},w=0;for(let v=0;v<a.length;v++){const{name:m,fn:x}=a[v],{x:b,y:S,data:I,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:g,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,g={...g,[m]:{...g[m],...I}},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}=gd(u,h,c)),v=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:g}};async function Mr(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:g=0}=un(t,e),w=md(g),m=a[h?f==="floating"?"reference":"floating":f],x=ns(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(m)))==null||n?m:m.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)),I=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=ns(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:c}):b);return{top:(x.top-C.top+w.top)/I.y,bottom:(C.bottom-x.bottom+w.bottom)/I.y,left:(x.left-C.left+w.left)/I.x,right:(C.right-x.right+w.right)/I.x}}const Nb=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}=un(e,t)||{};if(u==null)return{};const f=md(d),h={x:n,y:r},g=Ji(o),w=Xi(g),v=await i.getDimensions(u),m=g==="y",x=m?"top":"left",b=m?"bottom":"right",S=m?"clientHeight":"clientWidth",I=s.reference[w]+s.reference[g]-h[g]-s.floating[w],C=h[g]-s.reference[g],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[w]);const N=I/2-C/2,_=E/2-v[w]/2-1,P=yn(f[x],_),j=yn(f[b],_),z=P,G=E-v[w]-j,O=E/2-v[w]/2+N,W=Gi(z,O,G),H=!c.arrow&&rr(o)!=null&&O!==W&&s.reference[w]/2-(O<z?P:j)-v[w]/2<0,V=H?O<z?O-z:O-G:0;return{[g]:h[g]+V,data:{[g]:W,centerOffset:O-W-V,...H&&{alignmentOffset:V}},reset:H}}}),Ab=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:g="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...m}=un(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=dn(o),b=nn(a),S=dn(a)===a,I=await(c.isRTL==null?void 0:c.isRTL(u.floating)),C=h||(S||!v?[ts(a)]:yb(a)),T=w!=="none";!h&&T&&C.push(...kb(a,v,w,I));const E=[a,...C],N=await Mr(t,m),_=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[x]),f){const O=bb(o,i,I);_.push(N[O[0]],N[O[1]])}if(P=[...P,{placement:o,overflows:_}],!_.every(O=>O<=0)){var j,z;const O=(((j=s.flip)==null?void 0:j.index)||0)+1,W=E[O];if(W&&(!(f==="alignment"?b!==nn(W):!1)||P.every($=>nn($.placement)===b?$.overflows[0]>0:!0)))return{data:{index:O,overflows:P},reset:{placement:W}};let H=(z=P.filter(V=>V.overflows[0]<=0).sort((V,$)=>V.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!H)switch(g){case"bestFit":{var G;const V=(G=P.filter($=>{if(T){const A=nn($.placement);return A===b||A==="y"}return!0}).map($=>[$.placement,$.overflows.filter(A=>A>0).reduce((A,K)=>A+K,0)]).sort(($,A)=>$[1]-A[1])[0])==null?void 0:G[0];V&&(H=V);break}case"initialPlacement":H=a;break}if(o!==H)return{reset:{placement:H}}}return{}}}};function xd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function vd(e){return gb.some(t=>e[t]>=0)}const _b=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=un(e,t);switch(r){case"referenceHidden":{const s=await Mr(t,{...o,elementContext:"reference"}),i=xd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:vd(i)}}}case"escaped":{const s=await Mr(t,{...o,altBoundary:!0}),i=xd(s,n.floating);return{data:{escapedOffsets:i,escaped:vd(i)}}}default:return{}}}}},wd=new Set(["left","top"]);async function jb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=dn(n),a=rr(n),c=nn(n)==="y",u=wd.has(i)?-1:1,d=s&&c?-1:1,f=un(t,e);let{mainAxis:h,crossAxis:g,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"&&(g=a==="end"?w*-1:w),c?{x:g*d,y:h*u}:{x:h*u,y:g*d}}const Rb=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 jb(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}}}}},Pb=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:m=>{let{x,y:b}=m;return{x,y:b}}},...c}=un(e,t),u={x:n,y:r},d=await Mr(t,c),f=nn(dn(o)),h=Yi(f);let g=u[h],w=u[f];if(s){const m=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=g+d[m],S=g-d[x];g=Gi(b,g,S)}if(i){const m=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=w+d[m],S=w-d[x];w=Gi(b,w,S)}const v=a.fn({...t,[h]:g,[f]:w});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[h]:s,[f]:i}}}}}},Ob=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}=un(e,t),d={x:n,y:r},f=nn(o),h=Yi(f);let g=d[h],w=d[f];const v=un(a,t),m=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(c){const S=h==="y"?"height":"width",I=s.reference[h]-s.floating[S]+m.mainAxis,C=s.reference[h]+s.reference[S]-m.mainAxis;g<I?g=I:g>C&&(g=C)}if(u){var x,b;const S=h==="y"?"width":"height",I=wd.has(dn(o)),C=s.reference[f]-s.floating[S]+(I&&((x=i.offset)==null?void 0:x[f])||0)+(I?0:m.crossAxis),T=s.reference[f]+s.reference[S]+(I?0:((b=i.offset)==null?void 0:b[f])||0)-(I?m.crossAxis:0);w<C?w=C:w>T&&(w=T)}return{[h]:g,[f]:w}}}},Mb=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}=un(e,t),d=await Mr(t,u),f=dn(o),h=rr(o),g=nn(o)==="y",{width:w,height:v}=s.floating;let m,x;f==="top"||f==="bottom"?(m=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,m=h==="end"?"top":"bottom");const b=v-d.top-d.bottom,S=w-d.left-d.right,I=yn(v-d[m],b),C=yn(w-d[x],S),T=!t.middlewareData.shift;let E=I,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!h){const P=jt(d.left,0),j=jt(d.right,0),z=jt(d.top,0),G=jt(d.bottom,0);g?N=w-2*(P!==0||j!==0?P+j:jt(d.left,d.right)):E=v-2*(z!==0||G!==0?z+G:jt(d.top,d.bottom))}await c({...t,availableWidth:N,availableHeight:E});const _=await i.getDimensions(a.floating);return w!==_.width||v!==_.height?{reset:{rects:!0}}:{}}}};function rs(){return typeof window<"u"}function or(e){return bd(e)?(e.nodeName||"").toLowerCase():"#document"}function Rt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function rn(e){var t;return(t=(bd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function bd(e){return rs()?e instanceof Node||e instanceof Rt(e).Node:!1}function Vt(e){return rs()?e instanceof Element||e instanceof Rt(e).Element:!1}function on(e){return rs()?e instanceof HTMLElement||e instanceof Rt(e).HTMLElement:!1}function yd(e){return!rs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Rt(e).ShadowRoot}const Db=new Set(["inline","contents"]);function Dr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Kt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Db.has(o)}const Lb=new Set(["table","td","th"]);function Fb(e){return Lb.has(or(e))}const $b=[":popover-open",":modal"];function os(e){return $b.some(t=>{try{return e.matches(t)}catch{return!1}})}const zb=["transform","translate","scale","rotate","perspective"],Bb=["transform","translate","scale","rotate","perspective","filter"],Hb=["paint","layout","strict","content"];function Qi(e){const t=ea(),n=Vt(e)?Kt(e):e;return zb.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)||Bb.some(r=>(n.willChange||"").includes(r))||Hb.some(r=>(n.contain||"").includes(r))}function Ub(e){let t=Sn(e);for(;on(t)&&!sr(t);){if(Qi(t))return t;if(os(t))return null;t=Sn(t)}return null}function ea(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Wb=new Set(["html","body","#document"]);function sr(e){return Wb.has(or(e))}function Kt(e){return Rt(e).getComputedStyle(e)}function ss(e){return Vt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Sn(e){if(or(e)==="html")return e;const t=e.assignedSlot||e.parentNode||yd(e)&&e.host||rn(e);return yd(t)?t.host:t}function Sd(e){const t=Sn(e);return sr(t)?e.ownerDocument?e.ownerDocument.body:e.body:on(t)&&Dr(t)?t:Sd(t)}function Lr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Sd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Rt(o);if(s){const a=ta(i);return t.concat(i,i.visualViewport||[],Dr(o)?o:[],a&&n?Lr(a):[])}return t.concat(o,Lr(o,[],n))}function ta(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Cd(e){const t=Kt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=on(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Qo(n)!==s||Qo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function na(e){return Vt(e)?e:e.contextElement}function ir(e){const t=na(e);if(!on(t))return tn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Cd(t);let i=(s?Qo(n.width):n.width)/r,a=(s?Qo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Vb=tn(0);function Td(e){const t=Rt(e);return!ea()||!t.visualViewport?Vb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Kb(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Rt(e)?!1:t}function zn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=na(e);let i=tn(1);t&&(r?Vt(r)&&(i=ir(r)):i=ir(e));const a=Kb(s,n,r)?Td(s):tn(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=Rt(s),g=r&&Vt(r)?Rt(r):r;let w=h,v=ta(w);for(;v&&r&&g!==w;){const m=ir(v),x=v.getBoundingClientRect(),b=Kt(v),S=x.left+(v.clientLeft+parseFloat(b.paddingLeft))*m.x,I=x.top+(v.clientTop+parseFloat(b.paddingTop))*m.y;c*=m.x,u*=m.y,d*=m.x,f*=m.y,c+=S,u+=I,w=Rt(v),v=ta(w)}}return ns({width:d,height:f,x:c,y:u})}function ra(e,t){const n=ss(e).scrollLeft;return t?t.left+n:zn(rn(e)).left+n}function kd(e,t,n){n===void 0&&(n=!1);const r=e.getBoundingClientRect(),o=r.left+t.scrollLeft-(n?0:ra(e,r)),s=r.top+t.scrollTop;return{x:o,y:s}}function qb(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=rn(r),a=t?os(t.floating):!1;if(r===i||a&&s)return n;let c={scrollLeft:0,scrollTop:0},u=tn(1);const d=tn(0),f=on(r);if((f||!f&&!s)&&((or(r)!=="body"||Dr(i))&&(c=ss(r)),on(r))){const g=zn(r);u=ir(r),d.x=g.x+r.clientLeft,d.y=g.y+r.clientTop}const h=i&&!f&&!s?kd(i,c,!0):tn(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 Gb(e){return Array.from(e.getClientRects())}function Yb(e){const t=rn(e),n=ss(e),r=e.ownerDocument.body,o=jt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=jt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ra(e);const a=-n.scrollTop;return Kt(r).direction==="rtl"&&(i+=jt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function Xb(e,t){const n=Rt(e),r=rn(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=ea();(!u||u&&t==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}return{width:s,height:i,x:a,y:c}}const Jb=new Set(["absolute","fixed"]);function Zb(e,t){const n=zn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=on(e)?ir(e):tn(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 Ed(e,t,n){let r;if(t==="viewport")r=Xb(e,n);else if(t==="document")r=Yb(rn(e));else if(Vt(t))r=Zb(t,n);else{const o=Td(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ns(r)}function Id(e,t){const n=Sn(e);return n===t||!Vt(n)||sr(n)?!1:Kt(n).position==="fixed"||Id(n,t)}function Qb(e,t){const n=t.get(e);if(n)return n;let r=Lr(e,[],!1).filter(a=>Vt(a)&&or(a)!=="body"),o=null;const s=Kt(e).position==="fixed";let i=s?Sn(e):e;for(;Vt(i)&&!sr(i);){const a=Kt(i),c=Qi(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&Jb.has(o.position)||Dr(i)&&!c&&Id(e,i))?r=r.filter(d=>d!==i):o=a,i=Sn(i)}return t.set(e,r),r}function ey(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?os(t)?[]:Qb(t,this._c):[].concat(n),r],a=i[0],c=i.reduce((u,d)=>{const f=Ed(t,d,o);return u.top=jt(f.top,u.top),u.right=yn(f.right,u.right),u.bottom=yn(f.bottom,u.bottom),u.left=jt(f.left,u.left),u},Ed(t,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function ty(e){const{width:t,height:n}=Cd(e);return{width:t,height:n}}function ny(e,t,n){const r=on(t),o=rn(t),s=n==="fixed",i=zn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const c=tn(0);function u(){c.x=ra(o)}if(r||!r&&!s)if((or(t)!=="body"||Dr(o))&&(a=ss(t)),r){const g=zn(t,!0,s,t);c.x=g.x+t.clientLeft,c.y=g.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?kd(o,a):tn(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 oa(e){return Kt(e).position==="static"}function Nd(e,t){if(!on(e)||Kt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return rn(e)===n&&(n=n.ownerDocument.body),n}function Ad(e,t){const n=Rt(e);if(os(e))return n;if(!on(e)){let o=Sn(e);for(;o&&!sr(o);){if(Vt(o)&&!oa(o))return o;o=Sn(o)}return n}let r=Nd(e,t);for(;r&&Fb(r)&&oa(r);)r=Nd(r,t);return r&&sr(r)&&oa(r)&&!Qi(r)?n:r||Ub(e)||n}const ry=async function(e){const t=this.getOffsetParent||Ad,n=this.getDimensions,r=await n(e.floating);return{reference:ny(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function oy(e){return Kt(e).direction==="rtl"}const sy={convertOffsetParentRelativeRectToViewportRelativeRect:qb,getDocumentElement:rn,getClippingRect:ey,getOffsetParent:Ad,getElementRects:ry,getClientRects:Gb,getDimensions:ty,getScale:ir,isElement:Vt,isRTL:oy};function _d(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function iy(e,t){let n=null,r;const o=rn(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:g}=u;if(a||t(),!h||!g)return;const w=es(f),v=es(o.clientWidth-(d+h)),m=es(o.clientHeight-(f+g)),x=es(d),S={rootMargin:-w+"px "+-v+"px "+-m+"px "+-x+"px",threshold:jt(0,yn(1,c))||1};let I=!0;function C(T){const E=T[0].intersectionRatio;if(E!==c){if(!I)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!_d(u,e.getBoundingClientRect())&&i(),I=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function ay(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=na(e),d=o||s?[...u?Lr(u):[],...Lr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?iy(u,n):null;let h=-1,g=null;i&&(g=new ResizeObserver(x=>{let[b]=x;b&&b.target===u&&g&&(g.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=g)==null||S.observe(t)})),n()}),u&&!c&&g.observe(u),g.observe(t));let w,v=c?zn(e):null;c&&m();function m(){const x=zn(e);v&&!_d(v,x)&&n(),v=x,w=requestAnimationFrame(m)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=g)==null||x.disconnect(),g=null,c&&cancelAnimationFrame(w)}}const ly=Rb,cy=Pb,uy=Ab,dy=Mb,fy=_b,jd=Nb,hy=Ob,py=(e,t,n)=>{const r=new Map,o={platform:sy,...n},s={...o.platform,_c:r};return Ib(e,t,{...o,platform:s})};var my=typeof document<"u",gy=function(){},is=my?y.useLayoutEffect:gy;function as(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!as(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!as(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Rd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Pd(e,t){const n=Rd(e);return Math.round(t*n)/n}function sa(e){const t=p.useRef(e);return is(()=>{t.current=e}),t}function xy(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,g]=p.useState(r);as(h,r)||g(r);const[w,v]=p.useState(null),[m,x]=p.useState(null),b=p.useCallback($=>{$!==T.current&&(T.current=$,v($))},[]),S=p.useCallback($=>{$!==E.current&&(E.current=$,x($))},[]),I=s||w,C=i||m,T=p.useRef(null),E=p.useRef(null),N=p.useRef(d),_=c!=null,P=sa(c),j=sa(o),z=sa(u),G=p.useCallback(()=>{if(!T.current||!E.current)return;const $={placement:t,strategy:n,middleware:h};j.current&&($.platform=j.current),py(T.current,E.current,$).then(A=>{const K={...A,isPositioned:z.current!==!1};O.current&&!as(N.current,K)&&(N.current=K,Xr.flushSync(()=>{f(K)}))})},[h,t,n,j,z]);is(()=>{u===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[u]);const O=p.useRef(!1);is(()=>(O.current=!0,()=>{O.current=!1}),[]),is(()=>{if(I&&(T.current=I),C&&(E.current=C),I&&C){if(P.current)return P.current(I,C,G);G()}},[I,C,G,P,_]);const W=p.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:S}),[b,S]),H=p.useMemo(()=>({reference:I,floating:C}),[I,C]),V=p.useMemo(()=>{const $={position:n,left:0,top:0};if(!H.floating)return $;const A=Pd(H.floating,d.x),K=Pd(H.floating,d.y);return a?{...$,transform:"translate("+A+"px, "+K+"px)",...Rd(H.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:A,top:K}},[n,a,H.floating,d.x,d.y]);return p.useMemo(()=>({...d,update:G,refs:W,elements:H,floatingStyles:V}),[d,G,W,H,V])}const vy=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?jd({element:r.current,padding:o}).fn(n):{}:r?jd({element:r,padding:o}).fn(n):{}}}},wy=(e,t)=>({...ly(e),options:[e,t]}),by=(e,t)=>({...cy(e),options:[e,t]}),yy=(e,t)=>({...hy(e),options:[e,t]}),Sy=(e,t)=>({...uy(e),options:[e,t]}),Cy=(e,t)=>({...dy(e),options:[e,t]}),Ty=(e,t)=>({...fy(e),options:[e,t]}),ky=(e,t)=>({...vy(e),options:[e,t]});var Ey="Arrow",Od=p.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return l.jsx(be.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"})})});Od.displayName=Ey;var Iy=Od;function Md(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 ia="Popper",[Dd,ls]=Zt(ia),[Ny,Ld]=Dd(ia),Fd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=p.useState(null);return l.jsx(Ny,{scope:t,anchor:r,onAnchorChange:o,children:n})};Fd.displayName=ia;var $d="PopperAnchor",zd=p.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Ld($d,n),i=p.useRef(null),a=Ne(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(be.div,{...o,ref:a})});zd.displayName=$d;var aa="PopperContent",[Ay,_y]=Dd(aa),Bd=p.forwardRef((e,t)=>{var q,M,D,F,Q,te;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:g="optimized",onPlaced:w,...v}=e,m=Ld(aa,n),[x,b]=p.useState(null),S=Ne(t,Ie=>b(Ie)),[I,C]=p.useState(null),T=Md(I),E=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},j=Array.isArray(u)?u:[u],z=j.length>0,G={padding:P,boundary:j.filter(Ry),altBoundary:z},{refs:O,floatingStyles:W,placement:H,isPositioned:V,middlewareData:$}=xy({strategy:"fixed",placement:_,whileElementsMounted:(...Ie)=>ay(...Ie,{animationFrame:g==="always"}),elements:{reference:m.anchor},middleware:[wy({mainAxis:o+N,alignmentAxis:i}),c&&by({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?yy():void 0,...G}),c&&Sy({...G}),Cy({...G,apply:({elements:Ie,rects:He,availableWidth:Te,availableHeight:Ae})=>{const{width:Le,height:Ve}=He.reference,Me=Ie.floating.style;Me.setProperty("--radix-popper-available-width",`${Te}px`),Me.setProperty("--radix-popper-available-height",`${Ae}px`),Me.setProperty("--radix-popper-anchor-width",`${Le}px`),Me.setProperty("--radix-popper-anchor-height",`${Ve}px`)}}),I&&ky({element:I,padding:a}),Py({arrowWidth:E,arrowHeight:N}),h&&Ty({strategy:"referenceHidden",...G})]}),[A,K]=Wd(H),L=dt(w);ct(()=>{V&&(L==null||L())},[V,L]);const J=(q=$.arrow)==null?void 0:q.x,Y=(M=$.arrow)==null?void 0:M.y,ce=((D=$.arrow)==null?void 0:D.centerOffset)!==0,[pe,me]=p.useState();return ct(()=>{x&&me(window.getComputedStyle(x).zIndex)},[x]),l.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...W,transform:V?W.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:pe,"--radix-popper-transform-origin":[(F=$.transformOrigin)==null?void 0:F.x,(Q=$.transformOrigin)==null?void 0:Q.y].join(" "),...((te=$.hide)==null?void 0:te.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:l.jsx(Ay,{scope:n,placedSide:A,onArrowChange:C,arrowX:J,arrowY:Y,shouldHideArrow:ce,children:l.jsx(be.div,{"data-side":A,"data-align":K,...v,ref:S,style:{...v.style,animation:V?void 0:"none"}})})})});Bd.displayName=aa;var Hd="PopperArrow",jy={top:"bottom",right:"left",bottom:"top",left:"right"},Ud=p.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=_y(Hd,r),i=jy[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(Iy,{...o,ref:n,style:{...o.style,display:"block"}})})});Ud.displayName=Hd;function Ry(e){return e!==null}var Py=e=>({name:"transformOrigin",options:e,fn(t){var m,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((m=o.arrow)==null?void 0:m.centerOffset)!==0,a=i?0:e.arrowWidth,c=i?0:e.arrowHeight,[u,d]=Wd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,g=(((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:`${g}px`):u==="left"&&(w=`${r.floating.width+c}px`,v=i?f:`${g}px`),{data:{x:w,y:v}}}});function Wd(e){const[t,n="center"]=e.split("-");return[t,n]}var Vd=Fd,Kd=zd,qd=Bd,Gd=Ud,la="rovingFocusGroup.onEntryFocus",Oy={bubbles:!1,cancelable:!0},Fr="RovingFocusGroup",[ca,Yd,My]=qi(Fr),[Dy,Xd]=Zt(Fr,[My]),[Ly,Fy]=Dy(Fr),Jd=p.forwardRef((e,t)=>l.jsx(ca.Provider,{scope:e.__scopeRovingFocusGroup,children:l.jsx(ca.Slot,{scope:e.__scopeRovingFocusGroup,children:l.jsx($y,{...e,ref:t})})}));Jd.displayName=Fr;var $y=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),g=Ne(t,h),w=Zo(s),[v,m]=Mn({prop:i,defaultProp:a??null,onChange:c,caller:Fr}),[x,b]=p.useState(!1),S=dt(u),I=Yd(n),C=p.useRef(!1),[T,E]=p.useState(0);return p.useEffect(()=>{const N=h.current;if(N)return N.addEventListener(la,S),()=>N.removeEventListener(la,S)},[S]),l.jsx(Ly,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:v,onItemFocus:p.useCallback(N=>m(N),[m]),onItemShiftTab:p.useCallback(()=>b(!0),[]),onFocusableItemAdd:p.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:p.useCallback(()=>E(N=>N-1),[]),children:l.jsx(be.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:g,style:{outline:"none",...e.style},onMouseDown:ie(e.onMouseDown,()=>{C.current=!0}),onFocus:ie(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!x){const P=new CustomEvent(la,Oy);if(N.currentTarget.dispatchEvent(P),!P.defaultPrevented){const j=I().filter(H=>H.focusable),z=j.find(H=>H.active),G=j.find(H=>H.id===v),W=[z,G,...j].filter(Boolean).map(H=>H.ref.current);ef(W,d)}}C.current=!1}),onBlur:ie(e.onBlur,()=>b(!1))})})}),Zd="RovingFocusGroupItem",Qd=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,c=Qt(),u=s||c,d=Fy(Zd,n),f=d.currentTabStopId===u,h=Yd(n),{onFocusableItemAdd:g,onFocusableItemRemove:w,currentTabStopId:v}=d;return p.useEffect(()=>{if(r)return g(),()=>w()},[r,g,w]),l.jsx(ca.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:l.jsx(be.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ie(e.onMouseDown,m=>{r?d.onItemFocus(u):m.preventDefault()}),onFocus:ie(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ie(e.onKeyDown,m=>{if(m.key==="Tab"&&m.shiftKey){d.onItemShiftTab();return}if(m.target!==m.currentTarget)return;const x=Hy(m,d.orientation,d.dir);if(x!==void 0){if(m.metaKey||m.ctrlKey||m.altKey||m.shiftKey)return;m.preventDefault();let S=h().filter(I=>I.focusable).map(I=>I.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const I=S.indexOf(m.currentTarget);S=d.loop?Uy(S,I+1):S.slice(I+1)}setTimeout(()=>ef(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:v!=null}):i})})});Qd.displayName=Zd;var zy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function By(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Hy(e,t,n){const r=By(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return zy[r]}function ef(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Uy(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Wy=Jd,Vy=Qd,ua=["Enter"," "],Ky=["ArrowDown","PageUp","Home"],tf=["ArrowUp","PageDown","End"],qy=[...Ky,...tf],Gy={ltr:[...ua,"ArrowRight"],rtl:[...ua,"ArrowLeft"]},Yy={ltr:["ArrowLeft"],rtl:["ArrowRight"]},$r="Menu",[zr,Xy,Jy]=qi($r),[Bn,nf]=Zt($r,[Jy,ls,Xd]),cs=ls(),rf=Xd(),[Zy,Hn]=Bn($r),[Qy,Br]=Bn($r),of=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=cs(t),[c,u]=p.useState(null),d=p.useRef(!1),f=dt(s),h=Zo(o);return p.useEffect(()=>{const g=()=>{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",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),l.jsx(Vd,{...a,children:l.jsx(Zy,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:u,children:l.jsx(Qy,{scope:t,onClose:p.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};of.displayName=$r;var e0="MenuAnchor",da=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=cs(n);return l.jsx(Kd,{...o,...r,ref:t})});da.displayName=e0;var fa="MenuPortal",[t0,sf]=Bn(fa,{forceMount:void 0}),af=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Hn(fa,t);return l.jsx(t0,{scope:t,forceMount:n,children:l.jsx(_t,{present:n||s.open,children:l.jsx(Do,{asChild:!0,container:o,children:r})})})};af.displayName=fa;var Lt="MenuContent",[n0,ha]=Bn(Lt),lf=p.forwardRef((e,t)=>{const n=sf(Lt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Hn(Lt,e.__scopeMenu),i=Br(Lt,e.__scopeMenu);return l.jsx(zr.Provider,{scope:e.__scopeMenu,children:l.jsx(_t,{present:r||s.open,children:l.jsx(zr.Slot,{scope:e.__scopeMenu,children:i.modal?l.jsx(r0,{...o,ref:t}):l.jsx(o0,{...o,ref:t})})})})}),r0=p.forwardRef((e,t)=>{const n=Hn(Lt,e.__scopeMenu),r=p.useRef(null),o=Ne(t,r);return p.useEffect(()=>{const s=r.current;if(s)return zi(s)},[]),l.jsx(pa,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ie(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),o0=p.forwardRef((e,t)=>{const n=Hn(Lt,e.__scopeMenu);return l.jsx(pa,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),s0=In.createSlot("MenuContent.ScrollLock"),pa=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:g,disableOutsideScroll:w,...v}=e,m=Hn(Lt,n),x=Br(Lt,n),b=cs(n),S=rf(n),I=Xy(n),[C,T]=p.useState(null),E=p.useRef(null),N=Ne(t,E,m.onContentChange),_=p.useRef(0),P=p.useRef(""),j=p.useRef(0),z=p.useRef(null),G=p.useRef("right"),O=p.useRef(0),W=w?Ho:p.Fragment,H=w?{as:s0,allowPinchZoom:!0}:void 0,V=A=>{var q,M;const K=P.current+A,L=I().filter(D=>!D.disabled),J=document.activeElement,Y=(q=L.find(D=>D.ref.current===J))==null?void 0:q.textValue,ce=L.map(D=>D.textValue),pe=x0(ce,K,Y),me=(M=L.find(D=>D.textValue===pe))==null?void 0:M.ref.current;(function D(F){P.current=F,window.clearTimeout(_.current),F!==""&&(_.current=window.setTimeout(()=>D(""),1e3))})(K),me&&setTimeout(()=>me.focus())};p.useEffect(()=>()=>window.clearTimeout(_.current),[]),Oi();const $=p.useCallback(A=>{var L,J;return G.current===((L=z.current)==null?void 0:L.side)&&w0(A,(J=z.current)==null?void 0:J.area)},[]);return l.jsx(n0,{scope:n,searchRef:P,onItemEnter:p.useCallback(A=>{$(A)&&A.preventDefault()},[$]),onItemLeave:p.useCallback(A=>{var K;$(A)||((K=E.current)==null||K.focus(),T(null))},[$]),onTriggerLeave:p.useCallback(A=>{$(A)&&A.preventDefault()},[$]),pointerGraceTimerRef:j,onPointerGraceIntentChange:p.useCallback(A=>{z.current=A},[]),children:l.jsx(W,{...H,children:l.jsx(Mo,{asChild:!0,trapped:o,onMountAutoFocus:ie(s,A=>{var K;A.preventDefault(),(K=E.current)==null||K.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:l.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:g,children:l.jsx(Wy,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:ie(c,A=>{x.isUsingKeyboardRef.current||A.preventDefault()}),preventScrollOnEntryFocus:!0,children:l.jsx(qd,{role:"menu","aria-orientation":"vertical","data-state":kf(m.open),"data-radix-menu-content":"",dir:x.dir,...b,...v,ref:N,style:{outline:"none",...v.style},onKeyDown:ie(v.onKeyDown,A=>{const L=A.target.closest("[data-radix-menu-content]")===A.currentTarget,J=A.ctrlKey||A.altKey||A.metaKey,Y=A.key.length===1;L&&(A.key==="Tab"&&A.preventDefault(),!J&&Y&&V(A.key));const ce=E.current;if(A.target!==ce||!qy.includes(A.key))return;A.preventDefault();const me=I().filter(q=>!q.disabled).map(q=>q.ref.current);tf.includes(A.key)&&me.reverse(),m0(me)}),onBlur:ie(e.onBlur,A=>{A.currentTarget.contains(A.target)||(window.clearTimeout(_.current),P.current="")}),onPointerMove:ie(e.onPointerMove,Ur(A=>{const K=A.target,L=O.current!==A.clientX;if(A.currentTarget.contains(K)&&L){const J=A.clientX>O.current?"right":"left";G.current=J,O.current=A.clientX}}))})})})})})})});lf.displayName=Lt;var i0="MenuGroup",ma=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(be.div,{role:"group",...r,ref:t})});ma.displayName=i0;var a0="MenuLabel",cf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(be.div,{...r,ref:t})});cf.displayName=a0;var us="MenuItem",uf="menu.itemSelect",ds=p.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=p.useRef(null),i=Br(us,e.__scopeMenu),a=ha(us,e.__scopeMenu),c=Ne(t,s),u=p.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(uf,{bubbles:!0,cancelable:!0});f.addEventListener(uf,g=>r==null?void 0:r(g),{once:!0}),Wc(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return l.jsx(df,{...o,ref:c,disabled:n,onClick:ie(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ie(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ie(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||ua.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ds.displayName=us;var df=p.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ha(us,n),a=rf(n),c=p.useRef(null),u=Ne(t,c),[d,f]=p.useState(!1),[h,g]=p.useState("");return p.useEffect(()=>{const w=c.current;w&&g((w.textContent??"").trim())},[s.children]),l.jsx(zr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:l.jsx(Vy,{asChild:!0,...a,focusable:!r,children:l.jsx(be.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ie(e.onPointerMove,Ur(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ie(e.onPointerLeave,Ur(w=>i.onItemLeave(w))),onFocus:ie(e.onFocus,()=>f(!0)),onBlur:ie(e.onBlur,()=>f(!1))})})})}),l0="MenuCheckboxItem",ff=p.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return l.jsx(xf,{scope:e.__scopeMenu,checked:n,children:l.jsx(ds,{role:"menuitemcheckbox","aria-checked":fs(n)?"mixed":n,...o,ref:t,"data-state":xa(n),onSelect:ie(o.onSelect,()=>r==null?void 0:r(fs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});ff.displayName=l0;var hf="MenuRadioGroup",[c0,u0]=Bn(hf,{value:void 0,onValueChange:()=>{}}),pf=p.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=dt(r);return l.jsx(c0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:l.jsx(ma,{...o,ref:t})})});pf.displayName=hf;var mf="MenuRadioItem",gf=p.forwardRef((e,t)=>{const{value:n,...r}=e,o=u0(mf,e.__scopeMenu),s=n===o.value;return l.jsx(xf,{scope:e.__scopeMenu,checked:s,children:l.jsx(ds,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":xa(s),onSelect:ie(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});gf.displayName=mf;var ga="MenuItemIndicator",[xf,d0]=Bn(ga,{checked:!1}),vf=p.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=d0(ga,n);return l.jsx(_t,{present:r||fs(s.checked)||s.checked===!0,children:l.jsx(be.span,{...o,ref:t,"data-state":xa(s.checked)})})});vf.displayName=ga;var f0="MenuSeparator",wf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(be.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});wf.displayName=f0;var h0="MenuArrow",bf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=cs(n);return l.jsx(Gd,{...o,...r,ref:t})});bf.displayName=h0;var p0="MenuSub",[ZC,yf]=Bn(p0),Hr="MenuSubTrigger",Sf=p.forwardRef((e,t)=>{const n=Hn(Hr,e.__scopeMenu),r=Br(Hr,e.__scopeMenu),o=yf(Hr,e.__scopeMenu),s=ha(Hr,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(da,{asChild:!0,...u,children:l.jsx(df,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":kf(n.open),...e,ref:yi(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:ie(e.onPointerMove,Ur(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:ie(e.onPointerLeave,Ur(f=>{var g,w;d();const h=(g=n.content)==null?void 0:g.getBoundingClientRect();if(h){const v=(w=n.content)==null?void 0:w.dataset.side,m=v==="right",x=m?-5:5,b=h[m?"left":"right"],S=h[m?"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:ie(e.onKeyDown,f=>{var g;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||Gy[r.dir].includes(f.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),f.preventDefault())})})})});Sf.displayName=Hr;var Cf="MenuSubContent",Tf=p.forwardRef((e,t)=>{const n=sf(Lt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Hn(Lt,e.__scopeMenu),i=Br(Lt,e.__scopeMenu),a=yf(Cf,e.__scopeMenu),c=p.useRef(null),u=Ne(t,c);return l.jsx(zr.Provider,{scope:e.__scopeMenu,children:l.jsx(_t,{present:r||s.open,children:l.jsx(zr.Slot,{scope:e.__scopeMenu,children:l.jsx(pa,{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:ie(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ie(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ie(e.onKeyDown,d=>{var g;const f=d.currentTarget.contains(d.target),h=Yy[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(g=a.trigger)==null||g.focus(),d.preventDefault())})})})})})});Tf.displayName=Cf;function kf(e){return e?"open":"closed"}function fs(e){return e==="indeterminate"}function xa(e){return fs(e)?"indeterminate":e?"checked":"unchecked"}function m0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function g0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function x0(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=g0(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 v0(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 w0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return v0(n,t)}function Ur(e){return t=>t.pointerType==="mouse"?e(t):void 0}var b0=of,y0=da,S0=af,C0=lf,T0=ma,k0=cf,E0=ds,I0=ff,N0=pf,A0=gf,_0=vf,j0=wf,R0=bf,P0=Sf,O0=Tf,hs="DropdownMenu",[M0,QC]=Zt(hs,[nf]),bt=nf(),[D0,Ef]=M0(hs),If=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=bt(t),u=p.useRef(null),[d,f]=Mn({prop:o,defaultProp:s??!1,onChange:i,caller:hs});return l.jsx(D0,{scope:t,triggerId:Qt(),triggerRef:u,contentId:Qt(),open:d,onOpenChange:f,onOpenToggle:p.useCallback(()=>f(h=>!h),[f]),modal:a,children:l.jsx(b0,{...c,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};If.displayName=hs;var Nf="DropdownMenuTrigger",Af=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Ef(Nf,n),i=bt(n);return l.jsx(y0,{asChild:!0,...i,children:l.jsx(be.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:yi(t,s.triggerRef),onPointerDown:ie(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ie(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Af.displayName=Nf;var L0="DropdownMenuPortal",_f=e=>{const{__scopeDropdownMenu:t,...n}=e,r=bt(t);return l.jsx(S0,{...r,...n})};_f.displayName=L0;var jf="DropdownMenuContent",Rf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ef(jf,n),s=bt(n),i=p.useRef(!1);return l.jsx(C0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ie(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)==null||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ie(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)"}})});Rf.displayName=jf;var F0="DropdownMenuGroup",$0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(T0,{...o,...r,ref:t})});$0.displayName=F0;var z0="DropdownMenuLabel",Pf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(k0,{...o,...r,ref:t})});Pf.displayName=z0;var B0="DropdownMenuItem",Of=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(E0,{...o,...r,ref:t})});Of.displayName=B0;var H0="DropdownMenuCheckboxItem",Mf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(I0,{...o,...r,ref:t})});Mf.displayName=H0;var U0="DropdownMenuRadioGroup",W0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(N0,{...o,...r,ref:t})});W0.displayName=U0;var V0="DropdownMenuRadioItem",Df=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(A0,{...o,...r,ref:t})});Df.displayName=V0;var K0="DropdownMenuItemIndicator",Lf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(_0,{...o,...r,ref:t})});Lf.displayName=K0;var q0="DropdownMenuSeparator",Ff=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(j0,{...o,...r,ref:t})});Ff.displayName=q0;var G0="DropdownMenuArrow",Y0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(R0,{...o,...r,ref:t})});Y0.displayName=G0;var X0="DropdownMenuSubTrigger",$f=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(P0,{...o,...r,ref:t})});$f.displayName=X0;var J0="DropdownMenuSubContent",zf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(O0,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});zf.displayName=J0;var Z0=If,Q0=Af,eS=_f,Bf=Rf,Hf=Pf,Uf=Of,Wf=Mf,Vf=Df,Kf=Lf,qf=Ff,Gf=$f,Yf=zf;const tS=Z0,nS=Q0,rS=p.forwardRef(({className:e,inset:t,children:n,...r},o)=>l.jsxs(Gf,{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"})]}));rS.displayName=Gf.displayName;const oS=p.forwardRef(({className:e,...t},n)=>l.jsx(Yf,{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}));oS.displayName=Yf.displayName;const Xf=p.forwardRef(({className:e,sideOffset:t=4,...n},r)=>l.jsx(eS,{children:l.jsx(Bf,{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})}));Xf.displayName=Bf.displayName;const va=p.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Uf,{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}));va.displayName=Uf.displayName;const sS=p.forwardRef(({className:e,children:t,checked:n,...r},o)=>l.jsxs(Wf,{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(Kf,{children:l.jsx(ne.Check,{className:"h-4 w-4"})})}),t]}));sS.displayName=Wf.displayName;const iS=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Vf,{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(Kf,{children:l.jsx(ne.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));iS.displayName=Vf.displayName;const aS=p.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Hf,{ref:r,className:Z("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));aS.displayName=Hf.displayName;const lS=p.forwardRef(({className:e,...t},n)=>l.jsx(qf,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));lS.displayName=qf.displayName;function ps({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:g}){const{currentThreadId:w,messages:v,isStreaming:m,streamingAssistantId:x,isLoadingThread:b,error:S,send:I,stop:C,lastCheckpointId:T,lastCheckpointNs:E,listCheckpoints:N,navigateToCheckpoint:_,returnToLatest:P,hasMoreHistory:j,isLoadingHistory:z,loadOlderMessages:G,api:O}=wr(),[W,H]=y.useState(null),[V,$]=y.useState(""),[A,K]=y.useState(null),[L,J]=y.useState([]),[Y,ce]=y.useState(0),[pe,me]=y.useState(0),[q,M]=y.useState(!1),[D,F]=y.useState(null),[Q,te]=y.useState(null),[Ie,He]=y.useState(!1),[Te,Ae]=y.useState(null),[Le,Ve]=y.useState([]),[Me,et]=y.useState(null),[Xe,at]=y.useState(null),[ft,ut]=y.useState(!1),ze=y.useRef(null),ee=y.useRef(null),ae=y.useRef(null),he=y.useCallback(()=>{ze.current&&(ze.current.value=""),ee.current&&(ee.current.value=""),ce(le=>le+1),me(le=>le+1)},[]),Be=y.useRef(!1);y.useEffect(()=>{Be.current&&!m&&(J([]),he()),Be.current=m},[m,he]);const[qe,Je]=y.useState("desktop");y.useEffect(()=>{const le=()=>{const ge=window.innerWidth;Je(ge<640?"phone":ge<1024?"tablet":"desktop")};return le(),window.addEventListener("resize",le),()=>window.removeEventListener("resize",le)},[]),y.useEffect(()=>{let le=!1;if(!w){Ve([]),et(null),at(null),ae.current=null;return}const ge={threadId:w,checkpointId:T??null,checkpointNs:E??null},Re=ae.current;if(!(Re&&Re.threadId===ge.threadId&&Re.checkpointId===ge.checkpointId&&Re.checkpointNs===ge.checkpointNs))return N(w).then(Qe=>{var As;if(le)return;const Pt=((Qe==null?void 0:Qe.checkpoints)??[]).slice().sort((fn,k)=>new Date(k.createdAt).getTime()-new Date(fn.createdAt).getTime());Ve(Pt);const ln=Me,Gr=ln&&Pt.some(fn=>fn.checkpointId===ln)?ln:((As=Pt[0])==null?void 0:As.checkpointId)??null;let Ns=null;if(Gr){const fn=Pt.find(k=>k.checkpointId===Gr);Ns=(fn==null?void 0:fn.checkpointNs)??null}et(Gr),at(Ns),ae.current=ge}).catch(Qe=>{console.error("ChatInterface - listCheckpoints error:",Qe),le||(Ve([]),ae.current=null)}),()=>{le=!0}},[w,T,E,Me,N]),y.useEffect(()=>{T&&(et(T),at(E??null))},[T,E]);const xt=y.useCallback(async()=>{if(!(!j||z))try{await G()}catch(le){console.warn("loadOlderMessages failed",le)}},[j,z,G]);y.useEffect(()=>{(async()=>{if(!O.baseUrl){Ae(null);return}try{const ge=await O.getAgent("default");Ae(ge.uiDefaultMessage||null)}catch(ge){console.warn("Failed to fetch default message:",ge),Ae(null)}})()},[O]),y.useEffect(()=>{S&&!Ie&&(g==null||g(S))},[S,Ie,g]);const lt=le=>{if(le.length>Jo)return`Message too long (${le.length}/${Jo} characters)`;try{return pb(le),null}catch(ge){return(ge==null?void 0:ge.message)||"Invalid message"}},vt=async le=>{const ge=le.trim();if(!(!ge&&L.length===0)){if(ge){const Re=lt(ge);if(Re){K(Re);return}}try{await I(ge||"",{checkpointId:Me??T??void 0,checkpointNs:Xe??E??void 0,payloadExtras:W?{edit:!0,originalMessageId:W}:void 0,attachments:L}),f==null||f(ge),K(null),J([]),he(),H(null),$("")}catch(Re){const Qe=(Re==null?void 0:Re.message)||"Failed to send message";K(Qe),g==null||g(Qe)}}},an=y.useCallback((le,ge)=>{u&&(H(le),$(ge),K(null))},[u]),ur=y.useCallback(()=>{H(null),$(""),K(null)},[]),Pa=y.useCallback((le,ge)=>{an(le,ge)},[an]),Vr=y.useCallback(le=>{const ge=Re=>{const Qe=Re.content||[],Pt=Qe.filter(ln=>ln.type==="text").map(ln=>ln.text).join("");if(Pt)return Pt;try{return JSON.stringify(Qe,null,2)}catch{return String(Qe)}};for(let Re=le-1;Re>=0;Re--)if(v[Re].role==="user"){const Qe=ge(v[Re]);Qe&&I(Qe,{checkpointId:Me??T??void 0,checkpointNs:Xe??E??void 0});break}},[v,I,Me,Xe,T,E]),ks=le=>{const ge=Array.from(le.target.files||[]);J(Re=>[...Re,...ge]),le.target.value=""},En=le=>{J(ge=>{const Re=ge.filter((Qe,Pt)=>le!==Pt);return Re.length===0&&he(),Re})},Kr=async le=>{const ge=(le.target.files||[])[0];if(ge){F(null),te(null),M(!0);try{await I("",{checkpointId:Me??T??void 0,checkpointNs:Xe??E??void 0,attachments:[ge]});const Re=`Uploaded ${ge.name} - processing through chat stream`;te(Re)}catch(Re){const Qe=Re instanceof Error?Re.message:"Failed to upload Excel file";console.error("Excel upload failed",Re),F(Qe),g==null||g(Qe)}finally{M(!1),le.target.value="",he()}}},qr=le=>{if(!le)return"Unknown";const ge=Date.parse(le);return Number.isNaN(ge)?le:new Date(ge).toLocaleString()},Es=async le=>{if(w){ut(!0);try{if(!le){await P(),et(null),at(null);return}const ge=Le.find(Qe=>Qe.checkpointId===le),Re=(ge==null?void 0:ge.checkpointNs)??null;await _(le,Re),et(le),at(Re)}finally{ut(!1)}}},Oa=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Is=`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||""}`,Ma=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return l.jsxs("div",{className:Oa,children:[!!S&&!Ie&&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:S}),l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>He(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:l.jsx(ne.X,{size:16})})]}),w&&Le.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:Me??"",onChange:le=>{const ge=le.target.value||null;Es(ge)},children:[l.jsx("option",{value:"",children:"Latest"}),Le.map(le=>l.jsxs("option",{value:le.checkpointId,children:[qr(le.createdAt),le.preview?` β€” ${le.preview.slice(0,40)}`:""]},le.checkpointId))]})]}),l.jsxs("div",{className:`relative ${Is}`,style:r?{maxHeight:r}:void 0,children:[l.jsx(Ki,{className:"h-full",style:{height:"100%"},messages:v,isStreaming:m,streamingAssistantId:x,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:qe,enableMessageEditing:u,editingMessageId:W,onStartReached:()=>{xt()},onEdit:Pa,onRegenerate:Vr,onCancelEdit:ur,emptyMessage:Te??void 0,isNavigatingCheckpoint:ft}),b&&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:Ma,children:[W&&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(Oe,{variant:"ghost",size:"sm",onClick:ur,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:ze,type:"file",multiple:!0,onChange:le=>ks(le),className:"hidden"},Y),L.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2",children:L.map((le,ge)=>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:le.name}),l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>En(ge),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 ${le.name}`,children:l.jsx(ne.X,{size:12})})]},ge))})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("input",{ref:ee,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Kr,className:"hidden"},pe),q&&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..."]}),Q&&!q&&l.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Q}),D&&!q&&l.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:D})]})]}),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(tS,{children:[l.jsx(nS,{asChild:!0,children:l.jsx(Oe,{type:"button",size:"icon",variant:"outline",disabled:m,title:"More input actions",className:d.moreButton||"",children:l.jsx(ne.Plus,{size:16})})}),l.jsxs(Xf,{align:"start",sideOffset:6,className:"w-52",children:[a&&l.jsxs(va,{onClick:()=>{var le;return(le=ze.current)==null?void 0:le.click()},className:"cursor-pointer",children:[l.jsx(ne.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),c&&l.jsxs(va,{onClick:()=>{var le;q||(le=ee.current)==null||le.click()},className:`cursor-pointer ${q?"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(kg,{initialValue:V,editingMessageId:W,placeholder:W?"Edit your message...":t,isStreaming:m,disabled:!1,maxLength:Jo,onSend:vt,onCancelEdit:ur,onStop:C,allowEmptySend:L.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${W?"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 ms=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}));ms.displayName="Input";function wa(e,[t,n]){return Math.min(n,Math.max(t,e))}function cS(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var ba="ScrollArea",[Jf,eT]=Zt(ba),[uS,Ft]=Jf(ba),Zf=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),[g,w]=p.useState(null),[v,m]=p.useState(null),[x,b]=p.useState(0),[S,I]=p.useState(0),[C,T]=p.useState(!1),[E,N]=p.useState(!1),_=Ne(t,j=>c(j)),P=Zo(o);return l.jsx(uS,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:g,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:v,onScrollbarYChange:m,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:I,children:l.jsx(be.div,{dir:P,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Zf.displayName=ba;var Qf="ScrollAreaViewport",eh=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Ft(Qf,n),a=p.useRef(null),c=Ne(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(be.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})})]})});eh.displayName=Qf;var sn="ScrollAreaScrollbar",ya=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ft(sn,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(dS,{...r,ref:t,forceMount:n}):o.type==="scroll"?l.jsx(fS,{...r,ref:t,forceMount:n}):o.type==="auto"?l.jsx(th,{...r,ref:t,forceMount:n}):o.type==="always"?l.jsx(Sa,{...r,ref:t}):null});ya.displayName=sn;var dS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ft(sn,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(_t,{present:n||s,children:l.jsx(th,{"data-state":s?"visible":"hidden",...r,ref:t})})}),fS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ft(sn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ws(()=>c("SCROLL_END"),100),[a,c]=cS("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 g=u[d];f!==g&&(c("SCROLL"),i()),f=g};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,c,i]),l.jsx(_t,{present:n||a!=="hidden",children:l.jsx(Sa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ie(e.onPointerEnter,()=>c("POINTER_ENTER")),onPointerLeave:ie(e.onPointerLeave,()=>c("POINTER_LEAVE"))})})}),th=p.forwardRef((e,t)=>{const n=Ft(sn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=p.useState(!1),a=e.orientation==="horizontal",c=ws(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return ar(n.viewport,c),ar(n.content,c),l.jsx(_t,{present:r||s,children:l.jsx(Sa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Sa=p.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Ft(sn,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=ih(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,g){return vS(h,i.current,a,g)}return n==="horizontal"?l.jsx(hS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,g=ah(h,a,o.dir);s.current.style.transform=`translate3d(${g}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(pS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,g=ah(h,a);s.current.style.transform=`translate3d(0, ${g}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),hS=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Ft(sn,e.__scopeScrollArea),[i,a]=p.useState(),c=p.useRef(null),u=Ne(t,c,s.onScrollbarXChange);return p.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),l.jsx(rh,{"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":vs(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),ch(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:xs(i.paddingLeft),paddingEnd:xs(i.paddingRight)}})}})}),pS=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Ft(sn,e.__scopeScrollArea),[i,a]=p.useState(),c=p.useRef(null),u=Ne(t,c,s.onScrollbarYChange);return p.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),l.jsx(rh,{"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":vs(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),ch(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:xs(i.paddingTop),paddingEnd:xs(i.paddingBottom)}})}})}),[mS,nh]=Jf(sn),rh=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,g=Ft(sn,n),[w,v]=p.useState(null),m=Ne(t,_=>v(_)),x=p.useRef(null),b=p.useRef(""),S=g.viewport,I=r.content-r.viewport,C=dt(d),T=dt(c),E=ws(f,10);function N(_){if(x.current){const P=_.clientX-x.current.left,j=_.clientY-x.current.top;u({x:P,y:j})}}return p.useEffect(()=>{const _=P=>{const j=P.target;(w==null?void 0:w.contains(j))&&C(P,I)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,w,I,C]),p.useEffect(T,[r,T]),ar(w,E),ar(g.content,E),l.jsx(mS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:dt(s),onThumbPointerUp:dt(i),onThumbPositionChange:T,onThumbPointerDown:dt(a),children:l.jsx(be.div,{...h,ref:m,style:{position:"absolute",...h.style},onPointerDown:ie(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",g.viewport&&(g.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:ie(e.onPointerMove,N),onPointerUp:ie(e.onPointerUp,_=>{const P=_.target;P.hasPointerCapture(_.pointerId)&&P.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,g.viewport&&(g.viewport.style.scrollBehavior=""),x.current=null})})})}),gs="ScrollAreaThumb",oh=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nh(gs,e.__scopeScrollArea);return l.jsx(_t,{present:n||o.hasThumb,children:l.jsx(gS,{ref:t,...r})})}),gS=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Ft(gs,n),i=nh(gs,n),{onThumbPositionChange:a}=i,c=Ne(t,f=>i.onThumbChange(f)),u=p.useRef(void 0),d=ws(()=>{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 g=wS(f,a);u.current=g,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),l.jsx(be.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:ie(e.onPointerDownCapture,f=>{const g=f.target.getBoundingClientRect(),w=f.clientX-g.left,v=f.clientY-g.top;i.onThumbPointerDown({x:w,y:v})}),onPointerUp:ie(e.onPointerUp,i.onThumbPointerUp)})});oh.displayName=gs;var Ca="ScrollAreaCorner",sh=p.forwardRef((e,t)=>{const n=Ft(Ca,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?l.jsx(xS,{...e,ref:t}):null});sh.displayName=Ca;var xS=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Ft(Ca,n),[s,i]=p.useState(0),[a,c]=p.useState(0),u=!!(s&&a);return ar(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),c(d)}),ar(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?l.jsx(be.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 xs(e){return e?parseInt(e,10):0}function ih(e,t){const n=e/t;return isNaN(n)?0:n}function vs(e){const t=ih(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function vS(e,t,n,r="ltr"){const o=vs(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 lh([c,u],f)(e)}function ah(e,t,n="ltr"){const r=vs(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=wa(e,c);return lh([0,i],[0,a])(u)}function lh(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 ch(e,t){return e>0&&e<t}var wS=(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 ws(e,t){const n=dt(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 ar(e,t){const n=dt(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 uh=Zf,bS=eh,yS=sh;const dh=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(uh,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[l.jsx(bS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),l.jsx(fh,{}),l.jsx(yS,{})]}));dh.displayName=uh.displayName;const fh=p.forwardRef(({className:e,orientation:t="vertical",...n},r)=>l.jsx(ya,{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(oh,{className:"relative flex-1 rounded-full bg-border"})}));fh.displayName=ya.displayName;function Ta({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:g,createThread:w,deleteThread:v,renameThread:m,isLoadingThreads:x}=wr(),[b,S]=y.useState(h??[]),[I,C]=y.useState(null),[T,E]=y.useState(""),[N,_]=y.useState(!1);y.useEffect(()=>{S(h??[])},[h]);const P=async A=>{try{await f(A),a==null||a(A),c==null||c(A)}catch(K){console.error("Failed to select thread:",K)}},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)}},z=async(A,K)=>{if(K.stopPropagation(),!!confirm("Delete this thread?"))try{await v(A),d==null||d(A)}catch(L){console.error("Failed to delete thread:",L)}},G=(A,K)=>{K.stopPropagation(),C(A.threadId),E(A.title||`Thread ${A.threadId.slice(0,8)}`)},O=async A=>{if(T.trim())try{await m(A,T.trim()),C(null),E("")}catch(K){console.error("Failed to update title:",K)}},W=()=>{C(null),E("")},H=(A,K)=>{A.key==="Enter"?O(K):A.key==="Escape"&&W()},V=A=>{if(!A)return"";try{const K=new Date(A),J=new Date().getTime()-K.getTime(),Y=Math.floor(J/(1e3*60*60*24));return Y===0?K.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Y===1?"Yesterday":Y<7?`${Y} days ago`:K.toLocaleDateString()}catch{return""}},$=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(Oe,{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(dh,{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,K)=>new Date(K.updatedAt||K.createdAt||"").getTime()-new Date(A.updatedAt||A.createdAt||"").getTime()).map(A=>l.jsxs("div",{onClick:()=>P(A.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??g)===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:I===A.threadId?l.jsxs("div",{className:"flex items-center gap-2",onClick:K=>K.stopPropagation(),children:[l.jsx(ms,{value:T,onChange:K=>E(K.target.value),onKeyDown:K=>H(K,A.threadId),className:"h-6 text-sm",autoFocus:!0}),l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>O(A.threadId),className:"h-6 w-6 p-0",children:l.jsx(ne.Check,{size:12})}),l.jsx(Oe,{variant:"ghost",size:"sm",onClick:W,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:$(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:V(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&&I!==A.threadId&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:K=>G(A,K),className:"h-6 w-6 p-0",title:"Edit title",children:l.jsx(ne.Edit3,{size:12})}),n&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:K=>z(A.threadId,K),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 lr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function SS(e){if(typeof e!="string")return;const t=e.trim();if(t)return t.replace(/\/+$/g,"")}function hh(){const e=[lr("__API_BASE_URL__"),lr("__CHAT_API_BASE_URL__"),lr("__CHAT_API_URL__")];for(const t of e){const n=SS(t);if(n)return n}}function ph(){const e=[lr("__API_AUTH_TOKEN__"),lr("__CHAT_API_KEY__"),lr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function mh(){const e={},t=hh(),n=ph();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function gh(){const e=mh(),t=hn.getAuthToken(),n=hh();return{apiBaseUrl:e.baseUrl||hn.baseUrl||n||"http://localhost:8000",apiKey:t||e.apiKey||ph()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const xh="chat-settings";function CS(){try{const e=localStorage.getItem(xh);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function TS(e){try{localStorage.setItem(xh,JSON.stringify(e)),e.apiKey&&hn.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function kS(){const e=gh(),t=CS(),n=hn.getAuthToken();return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:hn.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function ES(e){e.apiKey&&hn.setAuthToken(e.apiKey),TS(e)}var IS="Label",vh=p.forwardRef((e,t)=>l.jsx(be.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())}}));vh.displayName=IS;var wh=vh;const NS=Yr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),$t=p.forwardRef(({className:e,...t},n)=>l.jsx(wh,{ref:n,className:Z(NS(),e),...t}));$t.displayName=wh.displayName;function bh(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 bs="Switch",[AS,tT]=Zt(bs),[_S,jS]=AS(bs),yh=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,g]=p.useState(null),w=Ne(t,S=>g(S)),v=p.useRef(!1),m=h?d||!!h.closest("form"):!0,[x,b]=Mn({prop:o,defaultProp:s??!1,onChange:u,caller:bs});return l.jsxs(_S,{scope:n,checked:x,disabled:a,children:[l.jsx(be.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":kh(x),"data-disabled":a?"":void 0,disabled:a,value:c,...f,ref:w,onClick:ie(e.onClick,S=>{b(I=>!I),m&&(v.current=S.isPropagationStopped(),v.current||S.stopPropagation())})}),m&&l.jsx(Th,{control:h,bubbles:!v.current,name:r,value:c,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});yh.displayName=bs;var Sh="SwitchThumb",Ch=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=jS(Sh,n);return l.jsx(be.span,{"data-state":kh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Ch.displayName=Sh;var RS="SwitchBubbleInput",Th=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=p.useRef(null),a=Ne(i,s),c=bh(n),u=Md(t);return p.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,g=Object.getOwnPropertyDescriptor(f,"checked").set;if(c!==n&&g){const w=new Event("click",{bubbles:r});g.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}})});Th.displayName=RS;function kh(e){return e?"checked":"unchecked"}var Eh=yh,PS=Ch;const Cn=p.forwardRef(({className:e,...t},n)=>l.jsx(Eh,{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(PS,{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")})}));Cn.displayName=Eh.displayName;var Ih=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"}),OS="VisuallyHidden",MS=p.forwardRef((e,t)=>l.jsx(be.span,{...e,ref:t,style:{...Ih,...e.style}}));MS.displayName=OS;var DS=[" ","Enter","ArrowUp","ArrowDown"],LS=[" ","Enter"],Un="Select",[ys,Ss,FS]=qi(Un),[cr,nT]=Zt(Un,[FS,ls]),Cs=ls(),[$S,Tn]=cr(Un),[zS,BS]=cr(Un),Nh=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:g,form:w}=e,v=Cs(t),[m,x]=p.useState(null),[b,S]=p.useState(null),[I,C]=p.useState(!1),T=Zo(u),[E,N]=Mn({prop:r,defaultProp:o??!1,onChange:s,caller:Un}),[_,P]=Mn({prop:i,defaultProp:a,onChange:c,caller:Un}),j=p.useRef(null),z=m?w||!!m.closest("form"):!0,[G,O]=p.useState(new Set),W=Array.from(G).map(H=>H.props.value).join(";");return l.jsx(Vd,{...v,children:l.jsxs($S,{required:g,scope:t,trigger:m,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:I,onValueNodeHasChildrenChange:C,contentId:Qt(),value:_,onValueChange:P,open:E,onOpenChange:N,dir:T,triggerPointerDownPosRef:j,disabled:h,children:[l.jsx(ys.Provider,{scope:t,children:l.jsx(zS,{scope:e.__scopeSelect,onNativeOptionAdd:p.useCallback(H=>{O(V=>new Set(V).add(H))},[]),onNativeOptionRemove:p.useCallback(H=>{O(V=>{const $=new Set(V);return $.delete(H),$})},[]),children:n})}),z?l.jsxs(Zh,{"aria-hidden":!0,required:g,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:H=>P(H.target.value),disabled:h,form:w,children:[_===void 0?l.jsx("option",{value:""}):null,Array.from(G)]},W):null]})})};Nh.displayName=Un;var Ah="SelectTrigger",_h=p.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Cs(n),i=Tn(Ah,n),a=i.disabled||r,c=Ne(t,i.onTriggerChange),u=Ss(n),d=p.useRef("touch"),[f,h,g]=ep(v=>{const m=u().filter(S=>!S.disabled),x=m.find(S=>S.value===i.value),b=tp(m,v,x);b!==void 0&&i.onValueChange(b.value)}),w=v=>{a||(i.onOpenChange(!0),g()),v&&(i.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return l.jsx(Kd,{asChild:!0,...s,children:l.jsx(be.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":Qh(i.value)?"":void 0,...o,ref:c,onClick:ie(o.onClick,v=>{v.currentTarget.focus(),d.current!=="mouse"&&w(v)}),onPointerDown:ie(o.onPointerDown,v=>{d.current=v.pointerType;const m=v.target;m.hasPointerCapture(v.pointerId)&&m.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(w(v),v.preventDefault())}),onKeyDown:ie(o.onKeyDown,v=>{const m=f.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&h(v.key),!(m&&v.key===" ")&&DS.includes(v.key)&&(w(),v.preventDefault())})})})});_h.displayName=Ah;var jh="SelectValue",Rh=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,c=Tn(jh,n),{onValueNodeHasChildrenChange:u}=c,d=s!==void 0,f=Ne(t,c.onValueNodeChange);return ct(()=>{u(d)},[u,d]),l.jsx(be.span,{...a,ref:f,style:{pointerEvents:"none"},children:Qh(c.value)?l.jsx(l.Fragment,{children:i}):s})});Rh.displayName=jh;var HS="SelectIcon",Ph=p.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return l.jsx(be.span,{"aria-hidden":!0,...o,ref:t,children:r||"β–Ό"})});Ph.displayName=HS;var US="SelectPortal",Oh=e=>l.jsx(Do,{asChild:!0,...e});Oh.displayName=US;var Wn="SelectContent",Mh=p.forwardRef((e,t)=>{const n=Tn(Wn,e.__scopeSelect),[r,o]=p.useState();if(ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Xr.createPortal(l.jsx(Dh,{scope:e.__scopeSelect,children:l.jsx(ys.Slot,{scope:e.__scopeSelect,children:l.jsx("div",{children:e.children})})}),s):null}return l.jsx(Lh,{...e,ref:t})});Mh.displayName=Wn;var qt=10,[Dh,kn]=cr(Wn),WS="SelectContentImpl",VS=In.createSlot("SelectContent.RemoveScroll"),Lh=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:g,sticky:w,hideWhenDetached:v,avoidCollisions:m,...x}=e,b=Tn(Wn,n),[S,I]=p.useState(null),[C,T]=p.useState(null),E=Ne(t,q=>I(q)),[N,_]=p.useState(null),[P,j]=p.useState(null),z=Ss(n),[G,O]=p.useState(!1),W=p.useRef(!1);p.useEffect(()=>{if(S)return zi(S)},[S]),Oi();const H=p.useCallback(q=>{const[M,...D]=z().map(te=>te.ref.current),[F]=D.slice(-1),Q=document.activeElement;for(const te of q)if(te===Q||(te==null||te.scrollIntoView({block:"nearest"}),te===M&&C&&(C.scrollTop=0),te===F&&C&&(C.scrollTop=C.scrollHeight),te==null||te.focus(),document.activeElement!==Q))return},[z,C]),V=p.useCallback(()=>H([N,S]),[H,N,S]);p.useEffect(()=>{G&&V()},[G,V]);const{onOpenChange:$,triggerPointerDownPosRef:A}=b;p.useEffect(()=>{if(S){let q={x:0,y:0};const M=F=>{var Q,te;q={x:Math.abs(Math.round(F.pageX)-(((Q=A.current)==null?void 0:Q.x)??0)),y:Math.abs(Math.round(F.pageY)-(((te=A.current)==null?void 0:te.y)??0))}},D=F=>{q.x<=10&&q.y<=10?F.preventDefault():S.contains(F.target)||$(!1),document.removeEventListener("pointermove",M),A.current=null};return A.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",D,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",D,{capture:!0})}}},[S,$,A]),p.useEffect(()=>{const q=()=>$(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[$]);const[K,L]=ep(q=>{const M=z().filter(Q=>!Q.disabled),D=M.find(Q=>Q.ref.current===document.activeElement),F=tp(M,q,D);F&&setTimeout(()=>F.ref.current.focus())}),J=p.useCallback((q,M,D)=>{const F=!W.current&&!D;(b.value!==void 0&&b.value===M||F)&&(_(q),F&&(W.current=!0))},[b.value]),Y=p.useCallback(()=>S==null?void 0:S.focus(),[S]),ce=p.useCallback((q,M,D)=>{const F=!W.current&&!D;(b.value!==void 0&&b.value===M||F)&&j(q)},[b.value]),pe=r==="popper"?ka:Fh,me=pe===ka?{side:a,sideOffset:c,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:g,sticky:w,hideWhenDetached:v,avoidCollisions:m}:{};return l.jsx(Dh,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:J,selectedItem:N,onItemLeave:Y,itemTextRefCallback:ce,focusSelectedItem:V,selectedItemText:P,position:r,isPositioned:G,searchRef:K,children:l.jsx(Ho,{as:VS,allowPinchZoom:!0,children:l.jsx(Mo,{asChild:!0,trapped:b.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ie(o,q=>{var M;(M=b.trigger)==null||M.focus({preventScroll:!0}),q.preventDefault()}),children:l.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:l.jsx(pe,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:q=>q.preventDefault(),...x,...me,onPlaced:()=>O(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ie(x.onKeyDown,q=>{const M=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!M&&q.key.length===1&&L(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let F=z().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);if(["ArrowUp","End"].includes(q.key)&&(F=F.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const Q=q.target,te=F.indexOf(Q);F=F.slice(te+1)}setTimeout(()=>H(F)),q.preventDefault()}})})})})})})});Lh.displayName=WS;var KS="SelectItemAlignedPosition",Fh=p.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Tn(Wn,n),i=kn(Wn,n),[a,c]=p.useState(null),[u,d]=p.useState(null),f=Ne(t,E=>d(E)),h=Ss(n),g=p.useRef(!1),w=p.useRef(!0),{viewport:v,selectedItem:m,selectedItemText:x,focusSelectedItem:b}=i,S=p.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&v&&m&&x){const E=s.trigger.getBoundingClientRect(),N=u.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),P=x.getBoundingClientRect();if(s.dir!=="rtl"){const Q=P.left-N.left,te=_.left-Q,Ie=E.left-te,He=E.width+Ie,Te=Math.max(He,N.width),Ae=window.innerWidth-qt,Le=wa(te,[qt,Math.max(qt,Ae-Te)]);a.style.minWidth=He+"px",a.style.left=Le+"px"}else{const Q=N.right-P.right,te=window.innerWidth-_.right-Q,Ie=window.innerWidth-E.right-te,He=E.width+Ie,Te=Math.max(He,N.width),Ae=window.innerWidth-qt,Le=wa(te,[qt,Math.max(qt,Ae-Te)]);a.style.minWidth=He+"px",a.style.right=Le+"px"}const j=h(),z=window.innerHeight-qt*2,G=v.scrollHeight,O=window.getComputedStyle(u),W=parseInt(O.borderTopWidth,10),H=parseInt(O.paddingTop,10),V=parseInt(O.borderBottomWidth,10),$=parseInt(O.paddingBottom,10),A=W+H+G+$+V,K=Math.min(m.offsetHeight*5,A),L=window.getComputedStyle(v),J=parseInt(L.paddingTop,10),Y=parseInt(L.paddingBottom,10),ce=E.top+E.height/2-qt,pe=z-ce,me=m.offsetHeight/2,q=m.offsetTop+me,M=W+H+q,D=A-M;if(M<=ce){const Q=j.length>0&&m===j[j.length-1].ref.current;a.style.bottom="0px";const te=u.clientHeight-v.offsetTop-v.offsetHeight,Ie=Math.max(pe,me+(Q?Y:0)+te+V),He=M+Ie;a.style.height=He+"px"}else{const Q=j.length>0&&m===j[0].ref.current;a.style.top="0px";const Ie=Math.max(ce,W+v.offsetTop+(Q?J:0)+me)+D;a.style.height=Ie+"px",v.scrollTop=M-ce+v.offsetTop}a.style.margin=`${qt}px 0`,a.style.minHeight=K+"px",a.style.maxHeight=z+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[h,s.trigger,s.valueNode,a,u,v,m,x,s.dir,r]);ct(()=>S(),[S]);const[I,C]=p.useState();ct(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const T=p.useCallback(E=>{E&&w.current===!0&&(S(),b==null||b(),w.current=!1)},[S,b]);return l.jsx(GS,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:l.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:I},children:l.jsx(be.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Fh.displayName=KS;var qS="SelectPopperPosition",ka=p.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=qt,...s}=e,i=Cs(n);return l.jsx(qd,{...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)"}})});ka.displayName=qS;var[GS,Ea]=cr(Wn,{}),Ia="SelectViewport",$h=p.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=kn(Ia,n),i=Ea(Ia,n),a=Ne(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(ys.Slot,{scope:n,children:l.jsx(be.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ie(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const g=Math.abs(c.current-d.scrollTop);if(g>0){const w=window.innerHeight-qt*2,v=parseFloat(f.style.minHeight),m=parseFloat(f.style.height),x=Math.max(v,m);if(x<w){const b=x+g,S=Math.min(w,b),I=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=I>0?I:0,f.style.justifyContent="flex-end")}}}c.current=d.scrollTop})})})]})});$h.displayName=Ia;var zh="SelectGroup",[YS,XS]=cr(zh),JS=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Qt();return l.jsx(YS,{scope:n,id:o,children:l.jsx(be.div,{role:"group","aria-labelledby":o,...r,ref:t})})});JS.displayName=zh;var Bh="SelectLabel",Hh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=XS(Bh,n);return l.jsx(be.div,{id:o.id,...r,ref:t})});Hh.displayName=Bh;var Ts="SelectItem",[ZS,Uh]=cr(Ts),Wh=p.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Tn(Ts,n),c=kn(Ts,n),u=a.value===r,[d,f]=p.useState(s??""),[h,g]=p.useState(!1),w=Ne(t,b=>{var S;return(S=c.itemRefCallback)==null?void 0:S.call(c,b,r,o)}),v=Qt(),m=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(ZS,{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(ys.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:l.jsx(be.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:ie(i.onFocus,()=>g(!0)),onBlur:ie(i.onBlur,()=>g(!1)),onClick:ie(i.onClick,()=>{m.current!=="mouse"&&x()}),onPointerUp:ie(i.onPointerUp,()=>{m.current==="mouse"&&x()}),onPointerDown:ie(i.onPointerDown,b=>{m.current=b.pointerType}),onPointerMove:ie(i.onPointerMove,b=>{var S;m.current=b.pointerType,o?(S=c.onItemLeave)==null||S.call(c):m.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ie(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=c.onItemLeave)==null||S.call(c))}),onKeyDown:ie(i.onKeyDown,b=>{var I;((I=c.searchRef)==null?void 0:I.current)!==""&&b.key===" "||(LS.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});Wh.displayName=Ts;var Wr="SelectItemText",Vh=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Tn(Wr,n),a=kn(Wr,n),c=Uh(Wr,n),u=BS(Wr,n),[d,f]=p.useState(null),h=Ne(t,x=>f(x),c.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,c.value,c.disabled)}),g=d==null?void 0:d.textContent,w=p.useMemo(()=>l.jsx("option",{value:c.value,disabled:c.disabled,children:g},c.value),[c.disabled,c.value,g]),{onNativeOptionAdd:v,onNativeOptionRemove:m}=u;return ct(()=>(v(w),()=>m(w)),[v,m,w]),l.jsxs(l.Fragment,{children:[l.jsx(be.span,{id:c.textId,...s,ref:h}),c.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Xr.createPortal(s.children,i.valueNode):null]})});Vh.displayName=Wr;var Kh="SelectItemIndicator",qh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Uh(Kh,n).isSelected?l.jsx(be.span,{"aria-hidden":!0,...r,ref:t}):null});qh.displayName=Kh;var Na="SelectScrollUpButton",Gh=p.forwardRef((e,t)=>{const n=kn(Na,e.__scopeSelect),r=Ea(Na,e.__scopeSelect),[o,s]=p.useState(!1),i=Ne(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(Xh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop-c.offsetHeight)}}):null});Gh.displayName=Na;var Aa="SelectScrollDownButton",Yh=p.forwardRef((e,t)=>{const n=kn(Aa,e.__scopeSelect),r=Ea(Aa,e.__scopeSelect),[o,s]=p.useState(!1),i=Ne(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(Xh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop+c.offsetHeight)}}):null});Yh.displayName=Aa;var Xh=p.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=kn("SelectScrollButton",n),i=p.useRef(null),a=Ss(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(be.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ie(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ie(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ie(o.onPointerLeave,()=>{c()})})}),QS="SelectSeparator",Jh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return l.jsx(be.div,{"aria-hidden":!0,...r,ref:t})});Jh.displayName=QS;var _a="SelectArrow",eC=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Cs(n),s=Tn(_a,n),i=kn(_a,n);return s.open&&i.position==="popper"?l.jsx(Gd,{...o,...r,ref:t}):null});eC.displayName=_a;var tC="SelectBubbleInput",Zh=p.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=p.useRef(null),s=Ne(r,o),i=bh(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(be.select,{...n,style:{...Ih,...n.style},ref:s,defaultValue:t})});Zh.displayName=tC;function Qh(e){return e===""||e===void 0}function ep(e){const t=dt(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 tp(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=nC(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 nC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rC=Nh,np=_h,oC=Rh,sC=Ph,iC=Oh,rp=Mh,aC=$h,op=Hh,sp=Wh,lC=Vh,cC=qh,ip=Gh,ap=Yh,lp=Jh;const cp=rC,up=oC,ja=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(np,{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(sC,{asChild:!0,children:l.jsx(ne.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));ja.displayName=np.displayName;const dp=p.forwardRef(({className:e,...t},n)=>l.jsx(ip,{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"})}));dp.displayName=ip.displayName;const fp=p.forwardRef(({className:e,...t},n)=>l.jsx(ap,{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"})}));fp.displayName=ap.displayName;const Ra=p.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>l.jsx(iC,{children:l.jsxs(rp,{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(dp,{}),l.jsx(aC,{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(fp,{})]})}));Ra.displayName=rp.displayName;const uC=p.forwardRef(({className:e,...t},n)=>l.jsx(op,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));uC.displayName=op.displayName;const Vn=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(sp,{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(cC,{children:l.jsx(ne.Check,{className:"h-4 w-4"})})}),l.jsx(lC,{children:t})]}));Vn.displayName=sp.displayName;const dC=p.forwardRef(({className:e,...t},n)=>l.jsx(lp,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));dC.displayName=lp.displayName;var fC="Separator",hp="horizontal",hC=["horizontal","vertical"],pp=p.forwardRef((e,t)=>{const{decorative:n,orientation:r=hp,...o}=e,s=pC(r)?r:hp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return l.jsx(be.div,{"data-orientation":s,...a,...o,ref:t})});pp.displayName=fC;function pC(e){return hC.includes(e)}var mp=pp;const gp=p.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>l.jsx(mp,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));gp.displayName=mp.displayName;const mC=Qu,gC=qw,xC=ed,xp=p.forwardRef(({className:e,...t},n)=>l.jsx(qo,{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}));xp.displayName=qo.displayName;const vC=Yr.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"}}),vp=p.forwardRef(({side:e="right",className:t,children:n,...r},o)=>l.jsxs(xC,{children:[l.jsx(xp,{}),l.jsxs(Go,{ref:o,className:Z(vC({side:e}),t),...r,children:[n,l.jsxs(td,{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"})]})]})]}));vp.displayName=Go.displayName;const wp=({className:e,...t})=>l.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});wp.displayName="SheetHeader";const bp=p.forwardRef(({className:e,...t},n)=>l.jsx(Fn,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));bp.displayName=Fn.displayName;const yp=p.forwardRef(({className:e,...t},n)=>l.jsx(Yo,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));yp.displayName=Yo.displayName;const wC={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 bC({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}=Ai();y.useEffect(()=>{const m=JSON.stringify(a)!==JSON.stringify(e);d(m)},[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."})},g=()=>{c(wC),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(mC,{open:r,onOpenChange:o,children:[l.jsx(gC,{asChild:!0,children:l.jsxs(Oe,{variant:"outline",size:"sm",className:n,children:[l.jsx(ne.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&l.jsx(bi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),l.jsxs(vp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[l.jsxs(wp,{children:[l.jsx(bp,{children:"Chat Settings"}),l.jsx(yp,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),l.jsxs("div",{className:"space-y-6 py-6",children:[l.jsxs(_r,{children:[l.jsx(jr,{className:"pb-3",children:l.jsxs(Rr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.Server,{className:"h-5 w-5"}),"API Configuration"]})}),l.jsxs(Eo,{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx($t,{htmlFor:"api-url",children:"API Base URL"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ms,{id:"api-url",value:a.api.baseUrl,onChange:m=>c(x=>({...x,api:{...x.api,baseUrl:m.target.value}})),placeholder:"http://localhost:8000/api"}),l.jsx(Oe,{variant:"outline",onClick:v,children:"Test"})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx($t,{htmlFor:"enable-auth",children:"Enable Authentication"}),l.jsx(Cn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:m=>c(x=>({...x,api:{...x.api,enableAuth:m}}))})]}),a.api.enableAuth&&l.jsxs("div",{className:"space-y-2",children:[l.jsx($t,{htmlFor:"auth-token",children:"Authentication Token"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ms,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:m=>c(x=>({...x,api:{...x.api,authToken:m.target.value}})),placeholder:"Enter your Bearer token"}),l.jsx(Oe,{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(_r,{children:[l.jsx(jr,{className:"pb-3",children:l.jsxs(Rr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),l.jsxs(Eo,{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx($t,{htmlFor:"layout",children:"Layout Style"}),l.jsxs(cp,{value:a.ui.layout,onValueChange:m=>c(x=>({...x,ui:{...x.ui,layout:m}})),children:[l.jsx(ja,{children:l.jsx(up,{})}),l.jsxs(Ra,{children:[l.jsx(Vn,{value:"sidebar",children:"Sidebar Layout"}),l.jsx(Vn,{value:"fullscreen",children:"Fullscreen"}),l.jsx(Vn,{value:"tabs",children:"Tabbed Interface"})]})]})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx($t,{htmlFor:"theme",children:"Theme"}),l.jsxs(cp,{value:a.ui.theme,onValueChange:m=>c(x=>({...x,ui:{...x.ui,theme:m}})),children:[l.jsx(ja,{children:l.jsx(up,{})}),l.jsxs(Ra,{children:[l.jsx(Vn,{value:"light",children:"Light"}),l.jsx(Vn,{value:"dark",children:"Dark"}),l.jsx(Vn,{value:"system",children:"System"})]})]})]}),l.jsx(gp,{}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx($t,{htmlFor:"show-timestamps",children:"Show Timestamps"}),l.jsx(Cn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:m=>c(x=>({...x,ui:{...x.ui,showTimestamps:m}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx($t,{htmlFor:"show-agent-names",children:"Show Agent Names"}),l.jsx(Cn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:m=>c(x=>({...x,ui:{...x.ui,showAgentNames:m}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx($t,{htmlFor:"compact-messages",children:"Compact Messages"}),l.jsx(Cn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:m=>c(x=>({...x,ui:{...x.ui,compactMessages:m}}))})]})]})]})]}),l.jsxs(_r,{children:[l.jsx(jr,{className:"pb-3",children:l.jsxs(Rr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),l.jsxs(Eo,{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx($t,{htmlFor:"auto-save",children:"Auto-save Conversations"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),l.jsx(Cn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:m=>c(x=>({...x,behavior:{...x.behavior,autoSave:m}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx($t,{htmlFor:"enable-streaming",children:"Enable Streaming"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),l.jsx(Cn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:m=>c(x=>({...x,behavior:{...x.behavior,enableStreaming:m}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx($t,{htmlFor:"typing-indicator",children:"Typing Indicator"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),l.jsx(Cn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:m=>c(x=>({...x,behavior:{...x.behavior,showTypingIndicator:m}}))})]})]})]})]}),l.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[l.jsxs(Oe,{variant:"outline",onClick:g,children:[l.jsx(ne.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(Oe,{variant:"outline",onClick:w,children:"Cancel"}),l.jsxs(Oe,{onClick:h,disabled:!u,children:[l.jsx(ne.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function yC({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(co,{...s,onThreadChange:c,children:l.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:l.jsx(ps,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?l.jsx(co,{...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(Ta,{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(ps,{onError:s.onError,enableFileUpload:!0})})]})})}):l.jsx(co,{...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(Ta,{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(ps,{onError:s.onError,enableFileUpload:!0})})]})})}ve.ChatApi=jl,ve.ChatInterface=ps,ve.ChatProvider=co,ve.ChatProviders=Hl,ve.ChatSettings=bC,ve.MarkdownContent=jo,ve.MessageComponent=ud,ve.MessageList=Ki,ve.ThreadManager=Ta,ve.applySettings=ES,ve.chatApiClient=hn,ve.default=yC,ve.del=_l,ve.get=Et,ve.getChatToken=Il,ve.getCurrentSettings=kS,ve.getDefaultApiConfig=mh,ve.getDefaultChatSettings=gh,ve.onChatTokenChanged=Nl,ve.post=Ks,ve.put=Al,ve.setChatToken=Vs,ve.useApi=lo,ve.useChat=wr,ve.useChatStream=$l,ve.useMessages=Bl,ve.useMessagesReducer=Ll,ve.useStream=Ml,ve.useThreads=qs,Object.defineProperties(ve,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
139
+ `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function hb(e,t=Jo){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 pb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),hb(t),fb(t)}function qi(e){const t=e+"CollectionProvider",[n,r]=Zt(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:m,children:x}=v,b=y.useRef(null),S=y.useRef(new Map).current;return l.jsx(o,{scope:m,itemMap:S,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",c=In.createSlot(a),u=y.forwardRef((v,m)=>{const{scope:x,children:b}=v,S=s(a,x),I=Ne(m,S.collectionRef);return l.jsx(c,{ref:I,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=In.createSlot(d),g=y.forwardRef((v,m)=>{const{scope:x,children:b,...S}=v,I=y.useRef(null),C=Ne(m,I),T=s(d,x);return y.useEffect(()=>(T.itemMap.set(I,{ref:I,...S}),()=>void T.itemMap.delete(I))),l.jsx(h,{[f]:"",ref:C,children:b})});g.displayName=d;function w(v){const m=s(e+"CollectionConsumer",v);return y.useCallback(()=>{const b=m.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(m.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[m.collectionRef,m.itemMap])}return[{Provider:i,Slot:u,ItemSlot:g},w,r]}var mb=p.createContext(void 0);function Zo(e){const t=p.useContext(mb);return e||t||"ltr"}const gb=["top","right","bottom","left"],yn=Math.min,jt=Math.max,Qo=Math.round,es=Math.floor,tn=e=>({x:e,y:e}),xb={left:"right",right:"left",bottom:"top",top:"bottom"},vb={start:"end",end:"start"};function Gi(e,t,n){return jt(e,yn(t,n))}function un(e,t){return typeof e=="function"?e(t):e}function dn(e){return e.split("-")[0]}function rr(e){return e.split("-")[1]}function Yi(e){return e==="x"?"y":"x"}function Xi(e){return e==="y"?"height":"width"}const wb=new Set(["top","bottom"]);function nn(e){return wb.has(dn(e))?"y":"x"}function Ji(e){return Yi(nn(e))}function bb(e,t,n){n===void 0&&(n=!1);const r=rr(e),o=Ji(e),s=Xi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=ts(i)),[i,ts(i)]}function yb(e){const t=ts(e);return[Zi(e),t,Zi(t)]}function Zi(e){return e.replace(/start|end/g,t=>vb[t])}const hd=["left","right"],pd=["right","left"],Sb=["top","bottom"],Cb=["bottom","top"];function Tb(e,t,n){switch(e){case"top":case"bottom":return n?t?pd:hd:t?hd:pd;case"left":case"right":return t?Sb:Cb;default:return[]}}function kb(e,t,n,r){const o=rr(e);let s=Tb(dn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Zi)))),s}function ts(e){return e.replace(/left|right|bottom|top/g,t=>xb[t])}function Eb(e){return{top:0,right:0,bottom:0,left:0,...e}}function md(e){return typeof e!="number"?Eb(e):{top:e,right:e,bottom:e,left:e}}function ns(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 gd(e,t,n){let{reference:r,floating:o}=e;const s=nn(t),i=Ji(t),a=Xi(i),c=dn(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 g;switch(c){case"top":g={x:d,y:r.y-o.height};break;case"bottom":g={x:d,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:f};break;case"left":g={x:r.x-o.width,y:f};break;default:g={x:r.x,y:r.y}}switch(rr(t)){case"start":g[i]-=h*(n&&u?-1:1);break;case"end":g[i]+=h*(n&&u?-1:1);break}return g}const Ib=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}=gd(u,r,c),h=r,g={},w=0;for(let v=0;v<a.length;v++){const{name:m,fn:x}=a[v],{x:b,y:S,data:I,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:g,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,g={...g,[m]:{...g[m],...I}},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}=gd(u,h,c)),v=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:g}};async function Mr(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:g=0}=un(t,e),w=md(g),m=a[h?f==="floating"?"reference":"floating":f],x=ns(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(m)))==null||n?m:m.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)),I=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=ns(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:c}):b);return{top:(x.top-C.top+w.top)/I.y,bottom:(C.bottom-x.bottom+w.bottom)/I.y,left:(x.left-C.left+w.left)/I.x,right:(C.right-x.right+w.right)/I.x}}const Nb=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}=un(e,t)||{};if(u==null)return{};const f=md(d),h={x:n,y:r},g=Ji(o),w=Xi(g),v=await i.getDimensions(u),m=g==="y",x=m?"top":"left",b=m?"bottom":"right",S=m?"clientHeight":"clientWidth",I=s.reference[w]+s.reference[g]-h[g]-s.floating[w],C=h[g]-s.reference[g],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[w]);const N=I/2-C/2,_=E/2-v[w]/2-1,P=yn(f[x],_),j=yn(f[b],_),z=P,G=E-v[w]-j,O=E/2-v[w]/2+N,W=Gi(z,O,G),H=!c.arrow&&rr(o)!=null&&O!==W&&s.reference[w]/2-(O<z?P:j)-v[w]/2<0,V=H?O<z?O-z:O-G:0;return{[g]:h[g]+V,data:{[g]:W,centerOffset:O-W-V,...H&&{alignmentOffset:V}},reset:H}}}),Ab=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:g="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...m}=un(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=dn(o),b=nn(a),S=dn(a)===a,I=await(c.isRTL==null?void 0:c.isRTL(u.floating)),C=h||(S||!v?[ts(a)]:yb(a)),T=w!=="none";!h&&T&&C.push(...kb(a,v,w,I));const E=[a,...C],N=await Mr(t,m),_=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[x]),f){const O=bb(o,i,I);_.push(N[O[0]],N[O[1]])}if(P=[...P,{placement:o,overflows:_}],!_.every(O=>O<=0)){var j,z;const O=(((j=s.flip)==null?void 0:j.index)||0)+1,W=E[O];if(W&&(!(f==="alignment"?b!==nn(W):!1)||P.every($=>nn($.placement)===b?$.overflows[0]>0:!0)))return{data:{index:O,overflows:P},reset:{placement:W}};let H=(z=P.filter(V=>V.overflows[0]<=0).sort((V,$)=>V.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!H)switch(g){case"bestFit":{var G;const V=(G=P.filter($=>{if(T){const A=nn($.placement);return A===b||A==="y"}return!0}).map($=>[$.placement,$.overflows.filter(A=>A>0).reduce((A,K)=>A+K,0)]).sort(($,A)=>$[1]-A[1])[0])==null?void 0:G[0];V&&(H=V);break}case"initialPlacement":H=a;break}if(o!==H)return{reset:{placement:H}}}return{}}}};function xd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function vd(e){return gb.some(t=>e[t]>=0)}const _b=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=un(e,t);switch(r){case"referenceHidden":{const s=await Mr(t,{...o,elementContext:"reference"}),i=xd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:vd(i)}}}case"escaped":{const s=await Mr(t,{...o,altBoundary:!0}),i=xd(s,n.floating);return{data:{escapedOffsets:i,escaped:vd(i)}}}default:return{}}}}},wd=new Set(["left","top"]);async function jb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=dn(n),a=rr(n),c=nn(n)==="y",u=wd.has(i)?-1:1,d=s&&c?-1:1,f=un(t,e);let{mainAxis:h,crossAxis:g,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"&&(g=a==="end"?w*-1:w),c?{x:g*d,y:h*u}:{x:h*u,y:g*d}}const Rb=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 jb(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}}}}},Pb=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:m=>{let{x,y:b}=m;return{x,y:b}}},...c}=un(e,t),u={x:n,y:r},d=await Mr(t,c),f=nn(dn(o)),h=Yi(f);let g=u[h],w=u[f];if(s){const m=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=g+d[m],S=g-d[x];g=Gi(b,g,S)}if(i){const m=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=w+d[m],S=w-d[x];w=Gi(b,w,S)}const v=a.fn({...t,[h]:g,[f]:w});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[h]:s,[f]:i}}}}}},Ob=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}=un(e,t),d={x:n,y:r},f=nn(o),h=Yi(f);let g=d[h],w=d[f];const v=un(a,t),m=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(c){const S=h==="y"?"height":"width",I=s.reference[h]-s.floating[S]+m.mainAxis,C=s.reference[h]+s.reference[S]-m.mainAxis;g<I?g=I:g>C&&(g=C)}if(u){var x,b;const S=h==="y"?"width":"height",I=wd.has(dn(o)),C=s.reference[f]-s.floating[S]+(I&&((x=i.offset)==null?void 0:x[f])||0)+(I?0:m.crossAxis),T=s.reference[f]+s.reference[S]+(I?0:((b=i.offset)==null?void 0:b[f])||0)-(I?m.crossAxis:0);w<C?w=C:w>T&&(w=T)}return{[h]:g,[f]:w}}}},Mb=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}=un(e,t),d=await Mr(t,u),f=dn(o),h=rr(o),g=nn(o)==="y",{width:w,height:v}=s.floating;let m,x;f==="top"||f==="bottom"?(m=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,m=h==="end"?"top":"bottom");const b=v-d.top-d.bottom,S=w-d.left-d.right,I=yn(v-d[m],b),C=yn(w-d[x],S),T=!t.middlewareData.shift;let E=I,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!h){const P=jt(d.left,0),j=jt(d.right,0),z=jt(d.top,0),G=jt(d.bottom,0);g?N=w-2*(P!==0||j!==0?P+j:jt(d.left,d.right)):E=v-2*(z!==0||G!==0?z+G:jt(d.top,d.bottom))}await c({...t,availableWidth:N,availableHeight:E});const _=await i.getDimensions(a.floating);return w!==_.width||v!==_.height?{reset:{rects:!0}}:{}}}};function rs(){return typeof window<"u"}function or(e){return bd(e)?(e.nodeName||"").toLowerCase():"#document"}function Rt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function rn(e){var t;return(t=(bd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function bd(e){return rs()?e instanceof Node||e instanceof Rt(e).Node:!1}function Vt(e){return rs()?e instanceof Element||e instanceof Rt(e).Element:!1}function on(e){return rs()?e instanceof HTMLElement||e instanceof Rt(e).HTMLElement:!1}function yd(e){return!rs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Rt(e).ShadowRoot}const Db=new Set(["inline","contents"]);function Dr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Kt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Db.has(o)}const Lb=new Set(["table","td","th"]);function Fb(e){return Lb.has(or(e))}const $b=[":popover-open",":modal"];function os(e){return $b.some(t=>{try{return e.matches(t)}catch{return!1}})}const zb=["transform","translate","scale","rotate","perspective"],Bb=["transform","translate","scale","rotate","perspective","filter"],Hb=["paint","layout","strict","content"];function Qi(e){const t=ea(),n=Vt(e)?Kt(e):e;return zb.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)||Bb.some(r=>(n.willChange||"").includes(r))||Hb.some(r=>(n.contain||"").includes(r))}function Ub(e){let t=Sn(e);for(;on(t)&&!sr(t);){if(Qi(t))return t;if(os(t))return null;t=Sn(t)}return null}function ea(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Wb=new Set(["html","body","#document"]);function sr(e){return Wb.has(or(e))}function Kt(e){return Rt(e).getComputedStyle(e)}function ss(e){return Vt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Sn(e){if(or(e)==="html")return e;const t=e.assignedSlot||e.parentNode||yd(e)&&e.host||rn(e);return yd(t)?t.host:t}function Sd(e){const t=Sn(e);return sr(t)?e.ownerDocument?e.ownerDocument.body:e.body:on(t)&&Dr(t)?t:Sd(t)}function Lr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Sd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Rt(o);if(s){const a=ta(i);return t.concat(i,i.visualViewport||[],Dr(o)?o:[],a&&n?Lr(a):[])}return t.concat(o,Lr(o,[],n))}function ta(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Cd(e){const t=Kt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=on(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Qo(n)!==s||Qo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function na(e){return Vt(e)?e:e.contextElement}function ir(e){const t=na(e);if(!on(t))return tn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Cd(t);let i=(s?Qo(n.width):n.width)/r,a=(s?Qo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Vb=tn(0);function Td(e){const t=Rt(e);return!ea()||!t.visualViewport?Vb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Kb(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Rt(e)?!1:t}function zn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=na(e);let i=tn(1);t&&(r?Vt(r)&&(i=ir(r)):i=ir(e));const a=Kb(s,n,r)?Td(s):tn(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=Rt(s),g=r&&Vt(r)?Rt(r):r;let w=h,v=ta(w);for(;v&&r&&g!==w;){const m=ir(v),x=v.getBoundingClientRect(),b=Kt(v),S=x.left+(v.clientLeft+parseFloat(b.paddingLeft))*m.x,I=x.top+(v.clientTop+parseFloat(b.paddingTop))*m.y;c*=m.x,u*=m.y,d*=m.x,f*=m.y,c+=S,u+=I,w=Rt(v),v=ta(w)}}return ns({width:d,height:f,x:c,y:u})}function ra(e,t){const n=ss(e).scrollLeft;return t?t.left+n:zn(rn(e)).left+n}function kd(e,t,n){n===void 0&&(n=!1);const r=e.getBoundingClientRect(),o=r.left+t.scrollLeft-(n?0:ra(e,r)),s=r.top+t.scrollTop;return{x:o,y:s}}function qb(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=rn(r),a=t?os(t.floating):!1;if(r===i||a&&s)return n;let c={scrollLeft:0,scrollTop:0},u=tn(1);const d=tn(0),f=on(r);if((f||!f&&!s)&&((or(r)!=="body"||Dr(i))&&(c=ss(r)),on(r))){const g=zn(r);u=ir(r),d.x=g.x+r.clientLeft,d.y=g.y+r.clientTop}const h=i&&!f&&!s?kd(i,c,!0):tn(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 Gb(e){return Array.from(e.getClientRects())}function Yb(e){const t=rn(e),n=ss(e),r=e.ownerDocument.body,o=jt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=jt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ra(e);const a=-n.scrollTop;return Kt(r).direction==="rtl"&&(i+=jt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function Xb(e,t){const n=Rt(e),r=rn(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=ea();(!u||u&&t==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}return{width:s,height:i,x:a,y:c}}const Jb=new Set(["absolute","fixed"]);function Zb(e,t){const n=zn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=on(e)?ir(e):tn(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 Ed(e,t,n){let r;if(t==="viewport")r=Xb(e,n);else if(t==="document")r=Yb(rn(e));else if(Vt(t))r=Zb(t,n);else{const o=Td(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ns(r)}function Id(e,t){const n=Sn(e);return n===t||!Vt(n)||sr(n)?!1:Kt(n).position==="fixed"||Id(n,t)}function Qb(e,t){const n=t.get(e);if(n)return n;let r=Lr(e,[],!1).filter(a=>Vt(a)&&or(a)!=="body"),o=null;const s=Kt(e).position==="fixed";let i=s?Sn(e):e;for(;Vt(i)&&!sr(i);){const a=Kt(i),c=Qi(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&Jb.has(o.position)||Dr(i)&&!c&&Id(e,i))?r=r.filter(d=>d!==i):o=a,i=Sn(i)}return t.set(e,r),r}function ey(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?os(t)?[]:Qb(t,this._c):[].concat(n),r],a=i[0],c=i.reduce((u,d)=>{const f=Ed(t,d,o);return u.top=jt(f.top,u.top),u.right=yn(f.right,u.right),u.bottom=yn(f.bottom,u.bottom),u.left=jt(f.left,u.left),u},Ed(t,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function ty(e){const{width:t,height:n}=Cd(e);return{width:t,height:n}}function ny(e,t,n){const r=on(t),o=rn(t),s=n==="fixed",i=zn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const c=tn(0);function u(){c.x=ra(o)}if(r||!r&&!s)if((or(t)!=="body"||Dr(o))&&(a=ss(t)),r){const g=zn(t,!0,s,t);c.x=g.x+t.clientLeft,c.y=g.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?kd(o,a):tn(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 oa(e){return Kt(e).position==="static"}function Nd(e,t){if(!on(e)||Kt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return rn(e)===n&&(n=n.ownerDocument.body),n}function Ad(e,t){const n=Rt(e);if(os(e))return n;if(!on(e)){let o=Sn(e);for(;o&&!sr(o);){if(Vt(o)&&!oa(o))return o;o=Sn(o)}return n}let r=Nd(e,t);for(;r&&Fb(r)&&oa(r);)r=Nd(r,t);return r&&sr(r)&&oa(r)&&!Qi(r)?n:r||Ub(e)||n}const ry=async function(e){const t=this.getOffsetParent||Ad,n=this.getDimensions,r=await n(e.floating);return{reference:ny(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function oy(e){return Kt(e).direction==="rtl"}const sy={convertOffsetParentRelativeRectToViewportRelativeRect:qb,getDocumentElement:rn,getClippingRect:ey,getOffsetParent:Ad,getElementRects:ry,getClientRects:Gb,getDimensions:ty,getScale:ir,isElement:Vt,isRTL:oy};function _d(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function iy(e,t){let n=null,r;const o=rn(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:g}=u;if(a||t(),!h||!g)return;const w=es(f),v=es(o.clientWidth-(d+h)),m=es(o.clientHeight-(f+g)),x=es(d),S={rootMargin:-w+"px "+-v+"px "+-m+"px "+-x+"px",threshold:jt(0,yn(1,c))||1};let I=!0;function C(T){const E=T[0].intersectionRatio;if(E!==c){if(!I)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!_d(u,e.getBoundingClientRect())&&i(),I=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function ay(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=na(e),d=o||s?[...u?Lr(u):[],...Lr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?iy(u,n):null;let h=-1,g=null;i&&(g=new ResizeObserver(x=>{let[b]=x;b&&b.target===u&&g&&(g.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=g)==null||S.observe(t)})),n()}),u&&!c&&g.observe(u),g.observe(t));let w,v=c?zn(e):null;c&&m();function m(){const x=zn(e);v&&!_d(v,x)&&n(),v=x,w=requestAnimationFrame(m)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=g)==null||x.disconnect(),g=null,c&&cancelAnimationFrame(w)}}const ly=Rb,cy=Pb,uy=Ab,dy=Mb,fy=_b,jd=Nb,hy=Ob,py=(e,t,n)=>{const r=new Map,o={platform:sy,...n},s={...o.platform,_c:r};return Ib(e,t,{...o,platform:s})};var my=typeof document<"u",gy=function(){},is=my?y.useLayoutEffect:gy;function as(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!as(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!as(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Rd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Pd(e,t){const n=Rd(e);return Math.round(t*n)/n}function sa(e){const t=p.useRef(e);return is(()=>{t.current=e}),t}function xy(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,g]=p.useState(r);as(h,r)||g(r);const[w,v]=p.useState(null),[m,x]=p.useState(null),b=p.useCallback($=>{$!==T.current&&(T.current=$,v($))},[]),S=p.useCallback($=>{$!==E.current&&(E.current=$,x($))},[]),I=s||w,C=i||m,T=p.useRef(null),E=p.useRef(null),N=p.useRef(d),_=c!=null,P=sa(c),j=sa(o),z=sa(u),G=p.useCallback(()=>{if(!T.current||!E.current)return;const $={placement:t,strategy:n,middleware:h};j.current&&($.platform=j.current),py(T.current,E.current,$).then(A=>{const K={...A,isPositioned:z.current!==!1};O.current&&!as(N.current,K)&&(N.current=K,Xr.flushSync(()=>{f(K)}))})},[h,t,n,j,z]);is(()=>{u===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[u]);const O=p.useRef(!1);is(()=>(O.current=!0,()=>{O.current=!1}),[]),is(()=>{if(I&&(T.current=I),C&&(E.current=C),I&&C){if(P.current)return P.current(I,C,G);G()}},[I,C,G,P,_]);const W=p.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:S}),[b,S]),H=p.useMemo(()=>({reference:I,floating:C}),[I,C]),V=p.useMemo(()=>{const $={position:n,left:0,top:0};if(!H.floating)return $;const A=Pd(H.floating,d.x),K=Pd(H.floating,d.y);return a?{...$,transform:"translate("+A+"px, "+K+"px)",...Rd(H.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:A,top:K}},[n,a,H.floating,d.x,d.y]);return p.useMemo(()=>({...d,update:G,refs:W,elements:H,floatingStyles:V}),[d,G,W,H,V])}const vy=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?jd({element:r.current,padding:o}).fn(n):{}:r?jd({element:r,padding:o}).fn(n):{}}}},wy=(e,t)=>({...ly(e),options:[e,t]}),by=(e,t)=>({...cy(e),options:[e,t]}),yy=(e,t)=>({...hy(e),options:[e,t]}),Sy=(e,t)=>({...uy(e),options:[e,t]}),Cy=(e,t)=>({...dy(e),options:[e,t]}),Ty=(e,t)=>({...fy(e),options:[e,t]}),ky=(e,t)=>({...vy(e),options:[e,t]});var Ey="Arrow",Od=p.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return l.jsx(be.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"})})});Od.displayName=Ey;var Iy=Od;function Md(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 ia="Popper",[Dd,ls]=Zt(ia),[Ny,Ld]=Dd(ia),Fd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=p.useState(null);return l.jsx(Ny,{scope:t,anchor:r,onAnchorChange:o,children:n})};Fd.displayName=ia;var $d="PopperAnchor",zd=p.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Ld($d,n),i=p.useRef(null),a=Ne(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(be.div,{...o,ref:a})});zd.displayName=$d;var aa="PopperContent",[Ay,_y]=Dd(aa),Bd=p.forwardRef((e,t)=>{var q,M,D,F,Q,te;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:g="optimized",onPlaced:w,...v}=e,m=Ld(aa,n),[x,b]=p.useState(null),S=Ne(t,Ie=>b(Ie)),[I,C]=p.useState(null),T=Md(I),E=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},j=Array.isArray(u)?u:[u],z=j.length>0,G={padding:P,boundary:j.filter(Ry),altBoundary:z},{refs:O,floatingStyles:W,placement:H,isPositioned:V,middlewareData:$}=xy({strategy:"fixed",placement:_,whileElementsMounted:(...Ie)=>ay(...Ie,{animationFrame:g==="always"}),elements:{reference:m.anchor},middleware:[wy({mainAxis:o+N,alignmentAxis:i}),c&&by({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?yy():void 0,...G}),c&&Sy({...G}),Cy({...G,apply:({elements:Ie,rects:He,availableWidth:Te,availableHeight:Ae})=>{const{width:Le,height:Ve}=He.reference,Me=Ie.floating.style;Me.setProperty("--radix-popper-available-width",`${Te}px`),Me.setProperty("--radix-popper-available-height",`${Ae}px`),Me.setProperty("--radix-popper-anchor-width",`${Le}px`),Me.setProperty("--radix-popper-anchor-height",`${Ve}px`)}}),I&&ky({element:I,padding:a}),Py({arrowWidth:E,arrowHeight:N}),h&&Ty({strategy:"referenceHidden",...G})]}),[A,K]=Wd(H),L=dt(w);ct(()=>{V&&(L==null||L())},[V,L]);const J=(q=$.arrow)==null?void 0:q.x,Y=(M=$.arrow)==null?void 0:M.y,ce=((D=$.arrow)==null?void 0:D.centerOffset)!==0,[pe,me]=p.useState();return ct(()=>{x&&me(window.getComputedStyle(x).zIndex)},[x]),l.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...W,transform:V?W.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:pe,"--radix-popper-transform-origin":[(F=$.transformOrigin)==null?void 0:F.x,(Q=$.transformOrigin)==null?void 0:Q.y].join(" "),...((te=$.hide)==null?void 0:te.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:l.jsx(Ay,{scope:n,placedSide:A,onArrowChange:C,arrowX:J,arrowY:Y,shouldHideArrow:ce,children:l.jsx(be.div,{"data-side":A,"data-align":K,...v,ref:S,style:{...v.style,animation:V?void 0:"none"}})})})});Bd.displayName=aa;var Hd="PopperArrow",jy={top:"bottom",right:"left",bottom:"top",left:"right"},Ud=p.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=_y(Hd,r),i=jy[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(Iy,{...o,ref:n,style:{...o.style,display:"block"}})})});Ud.displayName=Hd;function Ry(e){return e!==null}var Py=e=>({name:"transformOrigin",options:e,fn(t){var m,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((m=o.arrow)==null?void 0:m.centerOffset)!==0,a=i?0:e.arrowWidth,c=i?0:e.arrowHeight,[u,d]=Wd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,g=(((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:`${g}px`):u==="left"&&(w=`${r.floating.width+c}px`,v=i?f:`${g}px`),{data:{x:w,y:v}}}});function Wd(e){const[t,n="center"]=e.split("-");return[t,n]}var Vd=Fd,Kd=zd,qd=Bd,Gd=Ud,la="rovingFocusGroup.onEntryFocus",Oy={bubbles:!1,cancelable:!0},Fr="RovingFocusGroup",[ca,Yd,My]=qi(Fr),[Dy,Xd]=Zt(Fr,[My]),[Ly,Fy]=Dy(Fr),Jd=p.forwardRef((e,t)=>l.jsx(ca.Provider,{scope:e.__scopeRovingFocusGroup,children:l.jsx(ca.Slot,{scope:e.__scopeRovingFocusGroup,children:l.jsx($y,{...e,ref:t})})}));Jd.displayName=Fr;var $y=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),g=Ne(t,h),w=Zo(s),[v,m]=Mn({prop:i,defaultProp:a??null,onChange:c,caller:Fr}),[x,b]=p.useState(!1),S=dt(u),I=Yd(n),C=p.useRef(!1),[T,E]=p.useState(0);return p.useEffect(()=>{const N=h.current;if(N)return N.addEventListener(la,S),()=>N.removeEventListener(la,S)},[S]),l.jsx(Ly,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:v,onItemFocus:p.useCallback(N=>m(N),[m]),onItemShiftTab:p.useCallback(()=>b(!0),[]),onFocusableItemAdd:p.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:p.useCallback(()=>E(N=>N-1),[]),children:l.jsx(be.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:g,style:{outline:"none",...e.style},onMouseDown:ie(e.onMouseDown,()=>{C.current=!0}),onFocus:ie(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!x){const P=new CustomEvent(la,Oy);if(N.currentTarget.dispatchEvent(P),!P.defaultPrevented){const j=I().filter(H=>H.focusable),z=j.find(H=>H.active),G=j.find(H=>H.id===v),W=[z,G,...j].filter(Boolean).map(H=>H.ref.current);ef(W,d)}}C.current=!1}),onBlur:ie(e.onBlur,()=>b(!1))})})}),Zd="RovingFocusGroupItem",Qd=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,c=Qt(),u=s||c,d=Fy(Zd,n),f=d.currentTabStopId===u,h=Yd(n),{onFocusableItemAdd:g,onFocusableItemRemove:w,currentTabStopId:v}=d;return p.useEffect(()=>{if(r)return g(),()=>w()},[r,g,w]),l.jsx(ca.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:l.jsx(be.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ie(e.onMouseDown,m=>{r?d.onItemFocus(u):m.preventDefault()}),onFocus:ie(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ie(e.onKeyDown,m=>{if(m.key==="Tab"&&m.shiftKey){d.onItemShiftTab();return}if(m.target!==m.currentTarget)return;const x=Hy(m,d.orientation,d.dir);if(x!==void 0){if(m.metaKey||m.ctrlKey||m.altKey||m.shiftKey)return;m.preventDefault();let S=h().filter(I=>I.focusable).map(I=>I.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const I=S.indexOf(m.currentTarget);S=d.loop?Uy(S,I+1):S.slice(I+1)}setTimeout(()=>ef(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:v!=null}):i})})});Qd.displayName=Zd;var zy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function By(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Hy(e,t,n){const r=By(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return zy[r]}function ef(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Uy(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Wy=Jd,Vy=Qd,ua=["Enter"," "],Ky=["ArrowDown","PageUp","Home"],tf=["ArrowUp","PageDown","End"],qy=[...Ky,...tf],Gy={ltr:[...ua,"ArrowRight"],rtl:[...ua,"ArrowLeft"]},Yy={ltr:["ArrowLeft"],rtl:["ArrowRight"]},$r="Menu",[zr,Xy,Jy]=qi($r),[Bn,nf]=Zt($r,[Jy,ls,Xd]),cs=ls(),rf=Xd(),[Zy,Hn]=Bn($r),[Qy,Br]=Bn($r),of=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=cs(t),[c,u]=p.useState(null),d=p.useRef(!1),f=dt(s),h=Zo(o);return p.useEffect(()=>{const g=()=>{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",g,{capture:!0}),()=>{document.removeEventListener("keydown",g,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),l.jsx(Vd,{...a,children:l.jsx(Zy,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:u,children:l.jsx(Qy,{scope:t,onClose:p.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};of.displayName=$r;var e0="MenuAnchor",da=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=cs(n);return l.jsx(Kd,{...o,...r,ref:t})});da.displayName=e0;var fa="MenuPortal",[t0,sf]=Bn(fa,{forceMount:void 0}),af=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Hn(fa,t);return l.jsx(t0,{scope:t,forceMount:n,children:l.jsx(_t,{present:n||s.open,children:l.jsx(Do,{asChild:!0,container:o,children:r})})})};af.displayName=fa;var Lt="MenuContent",[n0,ha]=Bn(Lt),lf=p.forwardRef((e,t)=>{const n=sf(Lt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Hn(Lt,e.__scopeMenu),i=Br(Lt,e.__scopeMenu);return l.jsx(zr.Provider,{scope:e.__scopeMenu,children:l.jsx(_t,{present:r||s.open,children:l.jsx(zr.Slot,{scope:e.__scopeMenu,children:i.modal?l.jsx(r0,{...o,ref:t}):l.jsx(o0,{...o,ref:t})})})})}),r0=p.forwardRef((e,t)=>{const n=Hn(Lt,e.__scopeMenu),r=p.useRef(null),o=Ne(t,r);return p.useEffect(()=>{const s=r.current;if(s)return zi(s)},[]),l.jsx(pa,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ie(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),o0=p.forwardRef((e,t)=>{const n=Hn(Lt,e.__scopeMenu);return l.jsx(pa,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),s0=In.createSlot("MenuContent.ScrollLock"),pa=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:g,disableOutsideScroll:w,...v}=e,m=Hn(Lt,n),x=Br(Lt,n),b=cs(n),S=rf(n),I=Xy(n),[C,T]=p.useState(null),E=p.useRef(null),N=Ne(t,E,m.onContentChange),_=p.useRef(0),P=p.useRef(""),j=p.useRef(0),z=p.useRef(null),G=p.useRef("right"),O=p.useRef(0),W=w?Ho:p.Fragment,H=w?{as:s0,allowPinchZoom:!0}:void 0,V=A=>{var q,M;const K=P.current+A,L=I().filter(D=>!D.disabled),J=document.activeElement,Y=(q=L.find(D=>D.ref.current===J))==null?void 0:q.textValue,ce=L.map(D=>D.textValue),pe=x0(ce,K,Y),me=(M=L.find(D=>D.textValue===pe))==null?void 0:M.ref.current;(function D(F){P.current=F,window.clearTimeout(_.current),F!==""&&(_.current=window.setTimeout(()=>D(""),1e3))})(K),me&&setTimeout(()=>me.focus())};p.useEffect(()=>()=>window.clearTimeout(_.current),[]),Oi();const $=p.useCallback(A=>{var L,J;return G.current===((L=z.current)==null?void 0:L.side)&&w0(A,(J=z.current)==null?void 0:J.area)},[]);return l.jsx(n0,{scope:n,searchRef:P,onItemEnter:p.useCallback(A=>{$(A)&&A.preventDefault()},[$]),onItemLeave:p.useCallback(A=>{var K;$(A)||((K=E.current)==null||K.focus(),T(null))},[$]),onTriggerLeave:p.useCallback(A=>{$(A)&&A.preventDefault()},[$]),pointerGraceTimerRef:j,onPointerGraceIntentChange:p.useCallback(A=>{z.current=A},[]),children:l.jsx(W,{...H,children:l.jsx(Mo,{asChild:!0,trapped:o,onMountAutoFocus:ie(s,A=>{var K;A.preventDefault(),(K=E.current)==null||K.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:l.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:g,children:l.jsx(Wy,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:ie(c,A=>{x.isUsingKeyboardRef.current||A.preventDefault()}),preventScrollOnEntryFocus:!0,children:l.jsx(qd,{role:"menu","aria-orientation":"vertical","data-state":kf(m.open),"data-radix-menu-content":"",dir:x.dir,...b,...v,ref:N,style:{outline:"none",...v.style},onKeyDown:ie(v.onKeyDown,A=>{const L=A.target.closest("[data-radix-menu-content]")===A.currentTarget,J=A.ctrlKey||A.altKey||A.metaKey,Y=A.key.length===1;L&&(A.key==="Tab"&&A.preventDefault(),!J&&Y&&V(A.key));const ce=E.current;if(A.target!==ce||!qy.includes(A.key))return;A.preventDefault();const me=I().filter(q=>!q.disabled).map(q=>q.ref.current);tf.includes(A.key)&&me.reverse(),m0(me)}),onBlur:ie(e.onBlur,A=>{A.currentTarget.contains(A.target)||(window.clearTimeout(_.current),P.current="")}),onPointerMove:ie(e.onPointerMove,Ur(A=>{const K=A.target,L=O.current!==A.clientX;if(A.currentTarget.contains(K)&&L){const J=A.clientX>O.current?"right":"left";G.current=J,O.current=A.clientX}}))})})})})})})});lf.displayName=Lt;var i0="MenuGroup",ma=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(be.div,{role:"group",...r,ref:t})});ma.displayName=i0;var a0="MenuLabel",cf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(be.div,{...r,ref:t})});cf.displayName=a0;var us="MenuItem",uf="menu.itemSelect",ds=p.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=p.useRef(null),i=Br(us,e.__scopeMenu),a=ha(us,e.__scopeMenu),c=Ne(t,s),u=p.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(uf,{bubbles:!0,cancelable:!0});f.addEventListener(uf,g=>r==null?void 0:r(g),{once:!0}),Wc(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return l.jsx(df,{...o,ref:c,disabled:n,onClick:ie(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ie(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ie(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||ua.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ds.displayName=us;var df=p.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ha(us,n),a=rf(n),c=p.useRef(null),u=Ne(t,c),[d,f]=p.useState(!1),[h,g]=p.useState("");return p.useEffect(()=>{const w=c.current;w&&g((w.textContent??"").trim())},[s.children]),l.jsx(zr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:l.jsx(Vy,{asChild:!0,...a,focusable:!r,children:l.jsx(be.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ie(e.onPointerMove,Ur(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ie(e.onPointerLeave,Ur(w=>i.onItemLeave(w))),onFocus:ie(e.onFocus,()=>f(!0)),onBlur:ie(e.onBlur,()=>f(!1))})})})}),l0="MenuCheckboxItem",ff=p.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return l.jsx(xf,{scope:e.__scopeMenu,checked:n,children:l.jsx(ds,{role:"menuitemcheckbox","aria-checked":fs(n)?"mixed":n,...o,ref:t,"data-state":xa(n),onSelect:ie(o.onSelect,()=>r==null?void 0:r(fs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});ff.displayName=l0;var hf="MenuRadioGroup",[c0,u0]=Bn(hf,{value:void 0,onValueChange:()=>{}}),pf=p.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=dt(r);return l.jsx(c0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:l.jsx(ma,{...o,ref:t})})});pf.displayName=hf;var mf="MenuRadioItem",gf=p.forwardRef((e,t)=>{const{value:n,...r}=e,o=u0(mf,e.__scopeMenu),s=n===o.value;return l.jsx(xf,{scope:e.__scopeMenu,checked:s,children:l.jsx(ds,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":xa(s),onSelect:ie(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});gf.displayName=mf;var ga="MenuItemIndicator",[xf,d0]=Bn(ga,{checked:!1}),vf=p.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=d0(ga,n);return l.jsx(_t,{present:r||fs(s.checked)||s.checked===!0,children:l.jsx(be.span,{...o,ref:t,"data-state":xa(s.checked)})})});vf.displayName=ga;var f0="MenuSeparator",wf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return l.jsx(be.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});wf.displayName=f0;var h0="MenuArrow",bf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=cs(n);return l.jsx(Gd,{...o,...r,ref:t})});bf.displayName=h0;var p0="MenuSub",[ZC,yf]=Bn(p0),Hr="MenuSubTrigger",Sf=p.forwardRef((e,t)=>{const n=Hn(Hr,e.__scopeMenu),r=Br(Hr,e.__scopeMenu),o=yf(Hr,e.__scopeMenu),s=ha(Hr,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(da,{asChild:!0,...u,children:l.jsx(df,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":kf(n.open),...e,ref:yi(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:ie(e.onPointerMove,Ur(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:ie(e.onPointerLeave,Ur(f=>{var g,w;d();const h=(g=n.content)==null?void 0:g.getBoundingClientRect();if(h){const v=(w=n.content)==null?void 0:w.dataset.side,m=v==="right",x=m?-5:5,b=h[m?"left":"right"],S=h[m?"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:ie(e.onKeyDown,f=>{var g;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||Gy[r.dir].includes(f.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),f.preventDefault())})})})});Sf.displayName=Hr;var Cf="MenuSubContent",Tf=p.forwardRef((e,t)=>{const n=sf(Lt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Hn(Lt,e.__scopeMenu),i=Br(Lt,e.__scopeMenu),a=yf(Cf,e.__scopeMenu),c=p.useRef(null),u=Ne(t,c);return l.jsx(zr.Provider,{scope:e.__scopeMenu,children:l.jsx(_t,{present:r||s.open,children:l.jsx(zr.Slot,{scope:e.__scopeMenu,children:l.jsx(pa,{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:ie(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ie(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ie(e.onKeyDown,d=>{var g;const f=d.currentTarget.contains(d.target),h=Yy[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(g=a.trigger)==null||g.focus(),d.preventDefault())})})})})})});Tf.displayName=Cf;function kf(e){return e?"open":"closed"}function fs(e){return e==="indeterminate"}function xa(e){return fs(e)?"indeterminate":e?"checked":"unchecked"}function m0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function g0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function x0(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=g0(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 v0(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 w0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return v0(n,t)}function Ur(e){return t=>t.pointerType==="mouse"?e(t):void 0}var b0=of,y0=da,S0=af,C0=lf,T0=ma,k0=cf,E0=ds,I0=ff,N0=pf,A0=gf,_0=vf,j0=wf,R0=bf,P0=Sf,O0=Tf,hs="DropdownMenu",[M0,QC]=Zt(hs,[nf]),bt=nf(),[D0,Ef]=M0(hs),If=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=bt(t),u=p.useRef(null),[d,f]=Mn({prop:o,defaultProp:s??!1,onChange:i,caller:hs});return l.jsx(D0,{scope:t,triggerId:Qt(),triggerRef:u,contentId:Qt(),open:d,onOpenChange:f,onOpenToggle:p.useCallback(()=>f(h=>!h),[f]),modal:a,children:l.jsx(b0,{...c,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};If.displayName=hs;var Nf="DropdownMenuTrigger",Af=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Ef(Nf,n),i=bt(n);return l.jsx(y0,{asChild:!0,...i,children:l.jsx(be.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:yi(t,s.triggerRef),onPointerDown:ie(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ie(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Af.displayName=Nf;var L0="DropdownMenuPortal",_f=e=>{const{__scopeDropdownMenu:t,...n}=e,r=bt(t);return l.jsx(S0,{...r,...n})};_f.displayName=L0;var jf="DropdownMenuContent",Rf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ef(jf,n),s=bt(n),i=p.useRef(!1);return l.jsx(C0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ie(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)==null||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ie(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)"}})});Rf.displayName=jf;var F0="DropdownMenuGroup",$0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(T0,{...o,...r,ref:t})});$0.displayName=F0;var z0="DropdownMenuLabel",Pf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(k0,{...o,...r,ref:t})});Pf.displayName=z0;var B0="DropdownMenuItem",Of=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(E0,{...o,...r,ref:t})});Of.displayName=B0;var H0="DropdownMenuCheckboxItem",Mf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(I0,{...o,...r,ref:t})});Mf.displayName=H0;var U0="DropdownMenuRadioGroup",W0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(N0,{...o,...r,ref:t})});W0.displayName=U0;var V0="DropdownMenuRadioItem",Df=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(A0,{...o,...r,ref:t})});Df.displayName=V0;var K0="DropdownMenuItemIndicator",Lf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(_0,{...o,...r,ref:t})});Lf.displayName=K0;var q0="DropdownMenuSeparator",Ff=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(j0,{...o,...r,ref:t})});Ff.displayName=q0;var G0="DropdownMenuArrow",Y0=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(R0,{...o,...r,ref:t})});Y0.displayName=G0;var X0="DropdownMenuSubTrigger",$f=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(P0,{...o,...r,ref:t})});$f.displayName=X0;var J0="DropdownMenuSubContent",zf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return l.jsx(O0,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});zf.displayName=J0;var Z0=If,Q0=Af,eS=_f,Bf=Rf,Hf=Pf,Uf=Of,Wf=Mf,Vf=Df,Kf=Lf,qf=Ff,Gf=$f,Yf=zf;const tS=Z0,nS=Q0,rS=p.forwardRef(({className:e,inset:t,children:n,...r},o)=>l.jsxs(Gf,{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"})]}));rS.displayName=Gf.displayName;const oS=p.forwardRef(({className:e,...t},n)=>l.jsx(Yf,{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}));oS.displayName=Yf.displayName;const Xf=p.forwardRef(({className:e,sideOffset:t=4,...n},r)=>l.jsx(eS,{children:l.jsx(Bf,{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})}));Xf.displayName=Bf.displayName;const va=p.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Uf,{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}));va.displayName=Uf.displayName;const sS=p.forwardRef(({className:e,children:t,checked:n,...r},o)=>l.jsxs(Wf,{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(Kf,{children:l.jsx(ne.Check,{className:"h-4 w-4"})})}),t]}));sS.displayName=Wf.displayName;const iS=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Vf,{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(Kf,{children:l.jsx(ne.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));iS.displayName=Vf.displayName;const aS=p.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Hf,{ref:r,className:Z("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));aS.displayName=Hf.displayName;const lS=p.forwardRef(({className:e,...t},n)=>l.jsx(qf,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));lS.displayName=qf.displayName;function ps({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:g}){const{currentThreadId:w,messages:v,isStreaming:m,streamingAssistantId:x,isLoadingThread:b,error:S,send:I,stop:C,lastCheckpointId:T,lastCheckpointNs:E,listCheckpoints:N,navigateToCheckpoint:_,returnToLatest:P,hasMoreHistory:j,isLoadingHistory:z,loadOlderMessages:G,api:O}=wr(),[W,H]=y.useState(null),[V,$]=y.useState(""),[A,K]=y.useState(null),[L,J]=y.useState([]),[Y,ce]=y.useState(0),[pe,me]=y.useState(0),[q,M]=y.useState(!1),[D,F]=y.useState(null),[Q,te]=y.useState(null),[Ie,He]=y.useState(!1),[Te,Ae]=y.useState(null),[Le,Ve]=y.useState([]),[Me,et]=y.useState(null),[Xe,at]=y.useState(null),[ft,ut]=y.useState(!1),$e=y.useRef(null),ee=y.useRef(null),ae=y.useRef(null),he=y.useCallback(()=>{$e.current&&($e.current.value=""),ee.current&&(ee.current.value=""),ce(le=>le+1),me(le=>le+1)},[]),Be=y.useRef(!1);y.useEffect(()=>{Be.current&&!m&&(J([]),he()),Be.current=m},[m,he]);const[qe,Je]=y.useState("desktop");y.useEffect(()=>{const le=()=>{const ge=window.innerWidth;Je(ge<640?"phone":ge<1024?"tablet":"desktop")};return le(),window.addEventListener("resize",le),()=>window.removeEventListener("resize",le)},[]),y.useEffect(()=>{let le=!1;if(!w){Ve([]),et(null),at(null),ae.current=null;return}const ge={threadId:w,checkpointId:T??null,checkpointNs:E??null},Re=ae.current;if(!(Re&&Re.threadId===ge.threadId&&Re.checkpointId===ge.checkpointId&&Re.checkpointNs===ge.checkpointNs))return N(w).then(Qe=>{var As;if(le)return;const Pt=((Qe==null?void 0:Qe.checkpoints)??[]).slice().sort((fn,k)=>new Date(k.createdAt).getTime()-new Date(fn.createdAt).getTime());Ve(Pt);const ln=Me,Gr=ln&&Pt.some(fn=>fn.checkpointId===ln)?ln:((As=Pt[0])==null?void 0:As.checkpointId)??null;let Ns=null;if(Gr){const fn=Pt.find(k=>k.checkpointId===Gr);Ns=(fn==null?void 0:fn.checkpointNs)??null}et(Gr),at(Ns),ae.current=ge}).catch(Qe=>{console.error("ChatInterface - listCheckpoints error:",Qe),le||(Ve([]),ae.current=null)}),()=>{le=!0}},[w,T,E,Me,N]),y.useEffect(()=>{T&&(et(T),at(E??null))},[T,E]);const xt=y.useCallback(async()=>{if(!(!j||z))try{await G()}catch(le){console.warn("loadOlderMessages failed",le)}},[j,z,G]);y.useEffect(()=>{(async()=>{if(!O.baseUrl){Ae(null);return}try{const ge=await O.getAgent("default");Ae(ge.uiDefaultMessage||null)}catch(ge){console.warn("Failed to fetch default message:",ge),Ae(null)}})()},[O]),y.useEffect(()=>{S&&!Ie&&(g==null||g(S))},[S,Ie,g]);const lt=le=>{if(le.length>Jo)return`Message too long (${le.length}/${Jo} characters)`;try{return pb(le),null}catch(ge){return(ge==null?void 0:ge.message)||"Invalid message"}},vt=async le=>{const ge=le.trim();if(!(!ge&&L.length===0)){if(ge){const Re=lt(ge);if(Re){K(Re);return}}try{await I(ge||"",{checkpointId:Me??T??void 0,checkpointNs:Xe??E??void 0,payloadExtras:W?{edit:!0,originalMessageId:W}:void 0,attachments:L}),f==null||f(ge),K(null),J([]),he(),H(null),$("")}catch(Re){const Qe=(Re==null?void 0:Re.message)||"Failed to send message";K(Qe),g==null||g(Qe)}}},an=y.useCallback((le,ge)=>{u&&(H(le),$(ge),K(null))},[u]),ur=y.useCallback(()=>{H(null),$(""),K(null)},[]),Pa=y.useCallback((le,ge)=>{an(le,ge)},[an]),Vr=y.useCallback(le=>{const ge=Re=>{const Qe=Re.content||[],Pt=Qe.filter(ln=>ln.type==="text").map(ln=>ln.text).join("");if(Pt)return Pt;try{return JSON.stringify(Qe,null,2)}catch{return String(Qe)}};for(let Re=le-1;Re>=0;Re--)if(v[Re].role==="user"){const Qe=ge(v[Re]);Qe&&I(Qe,{checkpointId:Me??T??void 0,checkpointNs:Xe??E??void 0});break}},[v,I,Me,Xe,T,E]),ks=le=>{const ge=Array.from(le.target.files||[]);J(Re=>[...Re,...ge]),le.target.value=""},En=le=>{J(ge=>{const Re=ge.filter((Qe,Pt)=>le!==Pt);return Re.length===0&&he(),Re})},Kr=async le=>{const ge=(le.target.files||[])[0];if(ge){F(null),te(null),M(!0);try{await I("",{checkpointId:Me??T??void 0,checkpointNs:Xe??E??void 0,attachments:[ge]});const Re=`Uploaded ${ge.name} - processing through chat stream`;te(Re)}catch(Re){const Qe=Re instanceof Error?Re.message:"Failed to upload Excel file";console.error("Excel upload failed",Re),F(Qe),g==null||g(Qe)}finally{M(!1),le.target.value="",he()}}},qr=le=>{if(!le)return"Unknown";const ge=Date.parse(le);return Number.isNaN(ge)?le:new Date(ge).toLocaleString()},Es=async le=>{if(w){ut(!0);try{if(!le){await P(),et(null),at(null);return}const ge=Le.find(Qe=>Qe.checkpointId===le),Re=(ge==null?void 0:ge.checkpointNs)??null;await _(le,Re),et(le),at(Re)}finally{ut(!1)}}},Oa=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Is=`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||""}`,Ma=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return l.jsxs("div",{className:Oa,children:[!!S&&!Ie&&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:S}),l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>He(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:l.jsx(ne.X,{size:16})})]}),w&&Le.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:Me??"",onChange:le=>{const ge=le.target.value||null;Es(ge)},children:[l.jsx("option",{value:"",children:"Latest"}),Le.map(le=>l.jsxs("option",{value:le.checkpointId,children:[qr(le.createdAt),le.preview?` β€” ${le.preview.slice(0,40)}`:""]},le.checkpointId))]})]}),l.jsxs("div",{className:`relative ${Is}`,style:r?{maxHeight:r}:void 0,children:[l.jsx(Ki,{className:"h-full",style:{height:"100%"},messages:v,isStreaming:m,streamingAssistantId:x,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:qe,enableMessageEditing:u,editingMessageId:W,onStartReached:()=>{xt()},onEdit:Pa,onRegenerate:Vr,onCancelEdit:ur,emptyMessage:Te??void 0,isNavigatingCheckpoint:ft}),b&&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:Ma,children:[W&&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(Oe,{variant:"ghost",size:"sm",onClick:ur,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:$e,type:"file",multiple:!0,onChange:le=>ks(le),className:"hidden"},Y),L.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2",children:L.map((le,ge)=>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:le.name}),l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>En(ge),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 ${le.name}`,children:l.jsx(ne.X,{size:12})})]},ge))})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("input",{ref:ee,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Kr,className:"hidden"},pe),q&&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..."]}),Q&&!q&&l.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Q}),D&&!q&&l.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:D})]})]}),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(tS,{children:[l.jsx(nS,{asChild:!0,children:l.jsx(Oe,{type:"button",size:"icon",variant:"outline",disabled:m,title:"More input actions",className:d.moreButton||"",children:l.jsx(ne.Plus,{size:16})})}),l.jsxs(Xf,{align:"start",sideOffset:6,className:"w-52",children:[a&&l.jsxs(va,{onClick:()=>{var le;return(le=$e.current)==null?void 0:le.click()},className:"cursor-pointer",children:[l.jsx(ne.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),c&&l.jsxs(va,{onClick:()=>{var le;q||(le=ee.current)==null||le.click()},className:`cursor-pointer ${q?"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(kg,{initialValue:V,editingMessageId:W,placeholder:W?"Edit your message...":t,isStreaming:m,disabled:!1,maxLength:Jo,onSend:vt,onCancelEdit:ur,onStop:C,allowEmptySend:L.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${W?"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 ms=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}));ms.displayName="Input";function wa(e,[t,n]){return Math.min(n,Math.max(t,e))}function cS(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var ba="ScrollArea",[Jf,eT]=Zt(ba),[uS,Ft]=Jf(ba),Zf=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),[g,w]=p.useState(null),[v,m]=p.useState(null),[x,b]=p.useState(0),[S,I]=p.useState(0),[C,T]=p.useState(!1),[E,N]=p.useState(!1),_=Ne(t,j=>c(j)),P=Zo(o);return l.jsx(uS,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:g,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:v,onScrollbarYChange:m,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:I,children:l.jsx(be.div,{dir:P,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Zf.displayName=ba;var Qf="ScrollAreaViewport",eh=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Ft(Qf,n),a=p.useRef(null),c=Ne(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(be.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})})]})});eh.displayName=Qf;var sn="ScrollAreaScrollbar",ya=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ft(sn,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(dS,{...r,ref:t,forceMount:n}):o.type==="scroll"?l.jsx(fS,{...r,ref:t,forceMount:n}):o.type==="auto"?l.jsx(th,{...r,ref:t,forceMount:n}):o.type==="always"?l.jsx(Sa,{...r,ref:t}):null});ya.displayName=sn;var dS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ft(sn,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(_t,{present:n||s,children:l.jsx(th,{"data-state":s?"visible":"hidden",...r,ref:t})})}),fS=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ft(sn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ws(()=>c("SCROLL_END"),100),[a,c]=cS("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 g=u[d];f!==g&&(c("SCROLL"),i()),f=g};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,c,i]),l.jsx(_t,{present:n||a!=="hidden",children:l.jsx(Sa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ie(e.onPointerEnter,()=>c("POINTER_ENTER")),onPointerLeave:ie(e.onPointerLeave,()=>c("POINTER_LEAVE"))})})}),th=p.forwardRef((e,t)=>{const n=Ft(sn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=p.useState(!1),a=e.orientation==="horizontal",c=ws(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return ar(n.viewport,c),ar(n.content,c),l.jsx(_t,{present:r||s,children:l.jsx(Sa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Sa=p.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Ft(sn,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=ih(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,g){return vS(h,i.current,a,g)}return n==="horizontal"?l.jsx(hS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,g=ah(h,a,o.dir);s.current.style.transform=`translate3d(${g}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(pS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,g=ah(h,a);s.current.style.transform=`translate3d(0, ${g}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),hS=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Ft(sn,e.__scopeScrollArea),[i,a]=p.useState(),c=p.useRef(null),u=Ne(t,c,s.onScrollbarXChange);return p.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),l.jsx(rh,{"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":vs(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),ch(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:xs(i.paddingLeft),paddingEnd:xs(i.paddingRight)}})}})}),pS=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Ft(sn,e.__scopeScrollArea),[i,a]=p.useState(),c=p.useRef(null),u=Ne(t,c,s.onScrollbarYChange);return p.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),l.jsx(rh,{"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":vs(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),ch(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:xs(i.paddingTop),paddingEnd:xs(i.paddingBottom)}})}})}),[mS,nh]=Jf(sn),rh=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,g=Ft(sn,n),[w,v]=p.useState(null),m=Ne(t,_=>v(_)),x=p.useRef(null),b=p.useRef(""),S=g.viewport,I=r.content-r.viewport,C=dt(d),T=dt(c),E=ws(f,10);function N(_){if(x.current){const P=_.clientX-x.current.left,j=_.clientY-x.current.top;u({x:P,y:j})}}return p.useEffect(()=>{const _=P=>{const j=P.target;(w==null?void 0:w.contains(j))&&C(P,I)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,w,I,C]),p.useEffect(T,[r,T]),ar(w,E),ar(g.content,E),l.jsx(mS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:dt(s),onThumbPointerUp:dt(i),onThumbPositionChange:T,onThumbPointerDown:dt(a),children:l.jsx(be.div,{...h,ref:m,style:{position:"absolute",...h.style},onPointerDown:ie(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",g.viewport&&(g.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:ie(e.onPointerMove,N),onPointerUp:ie(e.onPointerUp,_=>{const P=_.target;P.hasPointerCapture(_.pointerId)&&P.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,g.viewport&&(g.viewport.style.scrollBehavior=""),x.current=null})})})}),gs="ScrollAreaThumb",oh=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nh(gs,e.__scopeScrollArea);return l.jsx(_t,{present:n||o.hasThumb,children:l.jsx(gS,{ref:t,...r})})}),gS=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Ft(gs,n),i=nh(gs,n),{onThumbPositionChange:a}=i,c=Ne(t,f=>i.onThumbChange(f)),u=p.useRef(void 0),d=ws(()=>{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 g=wS(f,a);u.current=g,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),l.jsx(be.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:ie(e.onPointerDownCapture,f=>{const g=f.target.getBoundingClientRect(),w=f.clientX-g.left,v=f.clientY-g.top;i.onThumbPointerDown({x:w,y:v})}),onPointerUp:ie(e.onPointerUp,i.onThumbPointerUp)})});oh.displayName=gs;var Ca="ScrollAreaCorner",sh=p.forwardRef((e,t)=>{const n=Ft(Ca,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?l.jsx(xS,{...e,ref:t}):null});sh.displayName=Ca;var xS=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Ft(Ca,n),[s,i]=p.useState(0),[a,c]=p.useState(0),u=!!(s&&a);return ar(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),c(d)}),ar(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?l.jsx(be.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 xs(e){return e?parseInt(e,10):0}function ih(e,t){const n=e/t;return isNaN(n)?0:n}function vs(e){const t=ih(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function vS(e,t,n,r="ltr"){const o=vs(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 lh([c,u],f)(e)}function ah(e,t,n="ltr"){const r=vs(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=wa(e,c);return lh([0,i],[0,a])(u)}function lh(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 ch(e,t){return e>0&&e<t}var wS=(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 ws(e,t){const n=dt(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 ar(e,t){const n=dt(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 uh=Zf,bS=eh,yS=sh;const dh=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(uh,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[l.jsx(bS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),l.jsx(fh,{}),l.jsx(yS,{})]}));dh.displayName=uh.displayName;const fh=p.forwardRef(({className:e,orientation:t="vertical",...n},r)=>l.jsx(ya,{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(oh,{className:"relative flex-1 rounded-full bg-border"})}));fh.displayName=ya.displayName;function Ta({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:g,createThread:w,deleteThread:v,renameThread:m,isLoadingThreads:x}=wr(),[b,S]=y.useState(h??[]),[I,C]=y.useState(null),[T,E]=y.useState(""),[N,_]=y.useState(!1);y.useEffect(()=>{S(h??[])},[h]);const P=async A=>{try{await f(A),a==null||a(A),c==null||c(A)}catch(K){console.error("Failed to select thread:",K)}},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)}},z=async(A,K)=>{if(K.stopPropagation(),!!confirm("Delete this thread?"))try{await v(A),d==null||d(A)}catch(L){console.error("Failed to delete thread:",L)}},G=(A,K)=>{K.stopPropagation(),C(A.threadId),E(A.title||`Thread ${A.threadId.slice(0,8)}`)},O=async A=>{if(T.trim())try{await m(A,T.trim()),C(null),E("")}catch(K){console.error("Failed to update title:",K)}},W=()=>{C(null),E("")},H=(A,K)=>{A.key==="Enter"?O(K):A.key==="Escape"&&W()},V=A=>{if(!A)return"";try{const K=new Date(A),J=new Date().getTime()-K.getTime(),Y=Math.floor(J/(1e3*60*60*24));return Y===0?K.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Y===1?"Yesterday":Y<7?`${Y} days ago`:K.toLocaleDateString()}catch{return""}},$=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(Oe,{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(dh,{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,K)=>new Date(K.updatedAt||K.createdAt||"").getTime()-new Date(A.updatedAt||A.createdAt||"").getTime()).map(A=>l.jsxs("div",{onClick:()=>P(A.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??g)===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:I===A.threadId?l.jsxs("div",{className:"flex items-center gap-2",onClick:K=>K.stopPropagation(),children:[l.jsx(ms,{value:T,onChange:K=>E(K.target.value),onKeyDown:K=>H(K,A.threadId),className:"h-6 text-sm",autoFocus:!0}),l.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>O(A.threadId),className:"h-6 w-6 p-0",children:l.jsx(ne.Check,{size:12})}),l.jsx(Oe,{variant:"ghost",size:"sm",onClick:W,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:$(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:V(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&&I!==A.threadId&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:K=>G(A,K),className:"h-6 w-6 p-0",title:"Edit title",children:l.jsx(ne.Edit3,{size:12})}),n&&l.jsx(Oe,{variant:"ghost",size:"sm",onClick:K=>z(A.threadId,K),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 lr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function SS(e){if(typeof e!="string")return;const t=e.trim();if(t)return t.replace(/\/+$/g,"")}function hh(){const e=[lr("__API_BASE_URL__"),lr("__CHAT_API_BASE_URL__"),lr("__CHAT_API_URL__")];for(const t of e){const n=SS(t);if(n)return n}}function ph(){const e=[lr("__API_AUTH_TOKEN__"),lr("__CHAT_API_KEY__"),lr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function mh(){const e={},t=hh(),n=ph();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function gh(){const e=mh(),t=hn.getAuthToken(),n=hh();return{apiBaseUrl:e.baseUrl||hn.baseUrl||n||"http://localhost:8000",apiKey:t||e.apiKey||ph()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const xh="chat-settings";function CS(){try{const e=localStorage.getItem(xh);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function TS(e){try{localStorage.setItem(xh,JSON.stringify(e)),e.apiKey&&hn.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function kS(){const e=gh(),t=CS(),n=hn.getAuthToken();return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:hn.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function ES(e){e.apiKey&&hn.setAuthToken(e.apiKey),TS(e)}var IS="Label",vh=p.forwardRef((e,t)=>l.jsx(be.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())}}));vh.displayName=IS;var wh=vh;const NS=Yr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),$t=p.forwardRef(({className:e,...t},n)=>l.jsx(wh,{ref:n,className:Z(NS(),e),...t}));$t.displayName=wh.displayName;function bh(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 bs="Switch",[AS,tT]=Zt(bs),[_S,jS]=AS(bs),yh=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,g]=p.useState(null),w=Ne(t,S=>g(S)),v=p.useRef(!1),m=h?d||!!h.closest("form"):!0,[x,b]=Mn({prop:o,defaultProp:s??!1,onChange:u,caller:bs});return l.jsxs(_S,{scope:n,checked:x,disabled:a,children:[l.jsx(be.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":kh(x),"data-disabled":a?"":void 0,disabled:a,value:c,...f,ref:w,onClick:ie(e.onClick,S=>{b(I=>!I),m&&(v.current=S.isPropagationStopped(),v.current||S.stopPropagation())})}),m&&l.jsx(Th,{control:h,bubbles:!v.current,name:r,value:c,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});yh.displayName=bs;var Sh="SwitchThumb",Ch=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=jS(Sh,n);return l.jsx(be.span,{"data-state":kh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Ch.displayName=Sh;var RS="SwitchBubbleInput",Th=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=p.useRef(null),a=Ne(i,s),c=bh(n),u=Md(t);return p.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,g=Object.getOwnPropertyDescriptor(f,"checked").set;if(c!==n&&g){const w=new Event("click",{bubbles:r});g.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}})});Th.displayName=RS;function kh(e){return e?"checked":"unchecked"}var Eh=yh,PS=Ch;const Cn=p.forwardRef(({className:e,...t},n)=>l.jsx(Eh,{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(PS,{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")})}));Cn.displayName=Eh.displayName;var Ih=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"}),OS="VisuallyHidden",MS=p.forwardRef((e,t)=>l.jsx(be.span,{...e,ref:t,style:{...Ih,...e.style}}));MS.displayName=OS;var DS=[" ","Enter","ArrowUp","ArrowDown"],LS=[" ","Enter"],Un="Select",[ys,Ss,FS]=qi(Un),[cr,nT]=Zt(Un,[FS,ls]),Cs=ls(),[$S,Tn]=cr(Un),[zS,BS]=cr(Un),Nh=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:g,form:w}=e,v=Cs(t),[m,x]=p.useState(null),[b,S]=p.useState(null),[I,C]=p.useState(!1),T=Zo(u),[E,N]=Mn({prop:r,defaultProp:o??!1,onChange:s,caller:Un}),[_,P]=Mn({prop:i,defaultProp:a,onChange:c,caller:Un}),j=p.useRef(null),z=m?w||!!m.closest("form"):!0,[G,O]=p.useState(new Set),W=Array.from(G).map(H=>H.props.value).join(";");return l.jsx(Vd,{...v,children:l.jsxs($S,{required:g,scope:t,trigger:m,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:I,onValueNodeHasChildrenChange:C,contentId:Qt(),value:_,onValueChange:P,open:E,onOpenChange:N,dir:T,triggerPointerDownPosRef:j,disabled:h,children:[l.jsx(ys.Provider,{scope:t,children:l.jsx(zS,{scope:e.__scopeSelect,onNativeOptionAdd:p.useCallback(H=>{O(V=>new Set(V).add(H))},[]),onNativeOptionRemove:p.useCallback(H=>{O(V=>{const $=new Set(V);return $.delete(H),$})},[]),children:n})}),z?l.jsxs(Zh,{"aria-hidden":!0,required:g,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:H=>P(H.target.value),disabled:h,form:w,children:[_===void 0?l.jsx("option",{value:""}):null,Array.from(G)]},W):null]})})};Nh.displayName=Un;var Ah="SelectTrigger",_h=p.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Cs(n),i=Tn(Ah,n),a=i.disabled||r,c=Ne(t,i.onTriggerChange),u=Ss(n),d=p.useRef("touch"),[f,h,g]=ep(v=>{const m=u().filter(S=>!S.disabled),x=m.find(S=>S.value===i.value),b=tp(m,v,x);b!==void 0&&i.onValueChange(b.value)}),w=v=>{a||(i.onOpenChange(!0),g()),v&&(i.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return l.jsx(Kd,{asChild:!0,...s,children:l.jsx(be.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":Qh(i.value)?"":void 0,...o,ref:c,onClick:ie(o.onClick,v=>{v.currentTarget.focus(),d.current!=="mouse"&&w(v)}),onPointerDown:ie(o.onPointerDown,v=>{d.current=v.pointerType;const m=v.target;m.hasPointerCapture(v.pointerId)&&m.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(w(v),v.preventDefault())}),onKeyDown:ie(o.onKeyDown,v=>{const m=f.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&h(v.key),!(m&&v.key===" ")&&DS.includes(v.key)&&(w(),v.preventDefault())})})})});_h.displayName=Ah;var jh="SelectValue",Rh=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,c=Tn(jh,n),{onValueNodeHasChildrenChange:u}=c,d=s!==void 0,f=Ne(t,c.onValueNodeChange);return ct(()=>{u(d)},[u,d]),l.jsx(be.span,{...a,ref:f,style:{pointerEvents:"none"},children:Qh(c.value)?l.jsx(l.Fragment,{children:i}):s})});Rh.displayName=jh;var HS="SelectIcon",Ph=p.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return l.jsx(be.span,{"aria-hidden":!0,...o,ref:t,children:r||"β–Ό"})});Ph.displayName=HS;var US="SelectPortal",Oh=e=>l.jsx(Do,{asChild:!0,...e});Oh.displayName=US;var Wn="SelectContent",Mh=p.forwardRef((e,t)=>{const n=Tn(Wn,e.__scopeSelect),[r,o]=p.useState();if(ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Xr.createPortal(l.jsx(Dh,{scope:e.__scopeSelect,children:l.jsx(ys.Slot,{scope:e.__scopeSelect,children:l.jsx("div",{children:e.children})})}),s):null}return l.jsx(Lh,{...e,ref:t})});Mh.displayName=Wn;var qt=10,[Dh,kn]=cr(Wn),WS="SelectContentImpl",VS=In.createSlot("SelectContent.RemoveScroll"),Lh=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:g,sticky:w,hideWhenDetached:v,avoidCollisions:m,...x}=e,b=Tn(Wn,n),[S,I]=p.useState(null),[C,T]=p.useState(null),E=Ne(t,q=>I(q)),[N,_]=p.useState(null),[P,j]=p.useState(null),z=Ss(n),[G,O]=p.useState(!1),W=p.useRef(!1);p.useEffect(()=>{if(S)return zi(S)},[S]),Oi();const H=p.useCallback(q=>{const[M,...D]=z().map(te=>te.ref.current),[F]=D.slice(-1),Q=document.activeElement;for(const te of q)if(te===Q||(te==null||te.scrollIntoView({block:"nearest"}),te===M&&C&&(C.scrollTop=0),te===F&&C&&(C.scrollTop=C.scrollHeight),te==null||te.focus(),document.activeElement!==Q))return},[z,C]),V=p.useCallback(()=>H([N,S]),[H,N,S]);p.useEffect(()=>{G&&V()},[G,V]);const{onOpenChange:$,triggerPointerDownPosRef:A}=b;p.useEffect(()=>{if(S){let q={x:0,y:0};const M=F=>{var Q,te;q={x:Math.abs(Math.round(F.pageX)-(((Q=A.current)==null?void 0:Q.x)??0)),y:Math.abs(Math.round(F.pageY)-(((te=A.current)==null?void 0:te.y)??0))}},D=F=>{q.x<=10&&q.y<=10?F.preventDefault():S.contains(F.target)||$(!1),document.removeEventListener("pointermove",M),A.current=null};return A.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",D,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",D,{capture:!0})}}},[S,$,A]),p.useEffect(()=>{const q=()=>$(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[$]);const[K,L]=ep(q=>{const M=z().filter(Q=>!Q.disabled),D=M.find(Q=>Q.ref.current===document.activeElement),F=tp(M,q,D);F&&setTimeout(()=>F.ref.current.focus())}),J=p.useCallback((q,M,D)=>{const F=!W.current&&!D;(b.value!==void 0&&b.value===M||F)&&(_(q),F&&(W.current=!0))},[b.value]),Y=p.useCallback(()=>S==null?void 0:S.focus(),[S]),ce=p.useCallback((q,M,D)=>{const F=!W.current&&!D;(b.value!==void 0&&b.value===M||F)&&j(q)},[b.value]),pe=r==="popper"?ka:Fh,me=pe===ka?{side:a,sideOffset:c,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:g,sticky:w,hideWhenDetached:v,avoidCollisions:m}:{};return l.jsx(Dh,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:J,selectedItem:N,onItemLeave:Y,itemTextRefCallback:ce,focusSelectedItem:V,selectedItemText:P,position:r,isPositioned:G,searchRef:K,children:l.jsx(Ho,{as:VS,allowPinchZoom:!0,children:l.jsx(Mo,{asChild:!0,trapped:b.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ie(o,q=>{var M;(M=b.trigger)==null||M.focus({preventScroll:!0}),q.preventDefault()}),children:l.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:l.jsx(pe,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:q=>q.preventDefault(),...x,...me,onPlaced:()=>O(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ie(x.onKeyDown,q=>{const M=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!M&&q.key.length===1&&L(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let F=z().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);if(["ArrowUp","End"].includes(q.key)&&(F=F.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const Q=q.target,te=F.indexOf(Q);F=F.slice(te+1)}setTimeout(()=>H(F)),q.preventDefault()}})})})})})})});Lh.displayName=WS;var KS="SelectItemAlignedPosition",Fh=p.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Tn(Wn,n),i=kn(Wn,n),[a,c]=p.useState(null),[u,d]=p.useState(null),f=Ne(t,E=>d(E)),h=Ss(n),g=p.useRef(!1),w=p.useRef(!0),{viewport:v,selectedItem:m,selectedItemText:x,focusSelectedItem:b}=i,S=p.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&v&&m&&x){const E=s.trigger.getBoundingClientRect(),N=u.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),P=x.getBoundingClientRect();if(s.dir!=="rtl"){const Q=P.left-N.left,te=_.left-Q,Ie=E.left-te,He=E.width+Ie,Te=Math.max(He,N.width),Ae=window.innerWidth-qt,Le=wa(te,[qt,Math.max(qt,Ae-Te)]);a.style.minWidth=He+"px",a.style.left=Le+"px"}else{const Q=N.right-P.right,te=window.innerWidth-_.right-Q,Ie=window.innerWidth-E.right-te,He=E.width+Ie,Te=Math.max(He,N.width),Ae=window.innerWidth-qt,Le=wa(te,[qt,Math.max(qt,Ae-Te)]);a.style.minWidth=He+"px",a.style.right=Le+"px"}const j=h(),z=window.innerHeight-qt*2,G=v.scrollHeight,O=window.getComputedStyle(u),W=parseInt(O.borderTopWidth,10),H=parseInt(O.paddingTop,10),V=parseInt(O.borderBottomWidth,10),$=parseInt(O.paddingBottom,10),A=W+H+G+$+V,K=Math.min(m.offsetHeight*5,A),L=window.getComputedStyle(v),J=parseInt(L.paddingTop,10),Y=parseInt(L.paddingBottom,10),ce=E.top+E.height/2-qt,pe=z-ce,me=m.offsetHeight/2,q=m.offsetTop+me,M=W+H+q,D=A-M;if(M<=ce){const Q=j.length>0&&m===j[j.length-1].ref.current;a.style.bottom="0px";const te=u.clientHeight-v.offsetTop-v.offsetHeight,Ie=Math.max(pe,me+(Q?Y:0)+te+V),He=M+Ie;a.style.height=He+"px"}else{const Q=j.length>0&&m===j[0].ref.current;a.style.top="0px";const Ie=Math.max(ce,W+v.offsetTop+(Q?J:0)+me)+D;a.style.height=Ie+"px",v.scrollTop=M-ce+v.offsetTop}a.style.margin=`${qt}px 0`,a.style.minHeight=K+"px",a.style.maxHeight=z+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[h,s.trigger,s.valueNode,a,u,v,m,x,s.dir,r]);ct(()=>S(),[S]);const[I,C]=p.useState();ct(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const T=p.useCallback(E=>{E&&w.current===!0&&(S(),b==null||b(),w.current=!1)},[S,b]);return l.jsx(GS,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:l.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:I},children:l.jsx(be.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Fh.displayName=KS;var qS="SelectPopperPosition",ka=p.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=qt,...s}=e,i=Cs(n);return l.jsx(qd,{...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)"}})});ka.displayName=qS;var[GS,Ea]=cr(Wn,{}),Ia="SelectViewport",$h=p.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=kn(Ia,n),i=Ea(Ia,n),a=Ne(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(ys.Slot,{scope:n,children:l.jsx(be.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ie(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const g=Math.abs(c.current-d.scrollTop);if(g>0){const w=window.innerHeight-qt*2,v=parseFloat(f.style.minHeight),m=parseFloat(f.style.height),x=Math.max(v,m);if(x<w){const b=x+g,S=Math.min(w,b),I=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=I>0?I:0,f.style.justifyContent="flex-end")}}}c.current=d.scrollTop})})})]})});$h.displayName=Ia;var zh="SelectGroup",[YS,XS]=cr(zh),JS=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Qt();return l.jsx(YS,{scope:n,id:o,children:l.jsx(be.div,{role:"group","aria-labelledby":o,...r,ref:t})})});JS.displayName=zh;var Bh="SelectLabel",Hh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=XS(Bh,n);return l.jsx(be.div,{id:o.id,...r,ref:t})});Hh.displayName=Bh;var Ts="SelectItem",[ZS,Uh]=cr(Ts),Wh=p.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Tn(Ts,n),c=kn(Ts,n),u=a.value===r,[d,f]=p.useState(s??""),[h,g]=p.useState(!1),w=Ne(t,b=>{var S;return(S=c.itemRefCallback)==null?void 0:S.call(c,b,r,o)}),v=Qt(),m=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(ZS,{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(ys.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:l.jsx(be.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:ie(i.onFocus,()=>g(!0)),onBlur:ie(i.onBlur,()=>g(!1)),onClick:ie(i.onClick,()=>{m.current!=="mouse"&&x()}),onPointerUp:ie(i.onPointerUp,()=>{m.current==="mouse"&&x()}),onPointerDown:ie(i.onPointerDown,b=>{m.current=b.pointerType}),onPointerMove:ie(i.onPointerMove,b=>{var S;m.current=b.pointerType,o?(S=c.onItemLeave)==null||S.call(c):m.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ie(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=c.onItemLeave)==null||S.call(c))}),onKeyDown:ie(i.onKeyDown,b=>{var I;((I=c.searchRef)==null?void 0:I.current)!==""&&b.key===" "||(LS.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});Wh.displayName=Ts;var Wr="SelectItemText",Vh=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Tn(Wr,n),a=kn(Wr,n),c=Uh(Wr,n),u=BS(Wr,n),[d,f]=p.useState(null),h=Ne(t,x=>f(x),c.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,c.value,c.disabled)}),g=d==null?void 0:d.textContent,w=p.useMemo(()=>l.jsx("option",{value:c.value,disabled:c.disabled,children:g},c.value),[c.disabled,c.value,g]),{onNativeOptionAdd:v,onNativeOptionRemove:m}=u;return ct(()=>(v(w),()=>m(w)),[v,m,w]),l.jsxs(l.Fragment,{children:[l.jsx(be.span,{id:c.textId,...s,ref:h}),c.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Xr.createPortal(s.children,i.valueNode):null]})});Vh.displayName=Wr;var Kh="SelectItemIndicator",qh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Uh(Kh,n).isSelected?l.jsx(be.span,{"aria-hidden":!0,...r,ref:t}):null});qh.displayName=Kh;var Na="SelectScrollUpButton",Gh=p.forwardRef((e,t)=>{const n=kn(Na,e.__scopeSelect),r=Ea(Na,e.__scopeSelect),[o,s]=p.useState(!1),i=Ne(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(Xh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop-c.offsetHeight)}}):null});Gh.displayName=Na;var Aa="SelectScrollDownButton",Yh=p.forwardRef((e,t)=>{const n=kn(Aa,e.__scopeSelect),r=Ea(Aa,e.__scopeSelect),[o,s]=p.useState(!1),i=Ne(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(Xh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop+c.offsetHeight)}}):null});Yh.displayName=Aa;var Xh=p.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=kn("SelectScrollButton",n),i=p.useRef(null),a=Ss(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(be.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ie(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ie(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ie(o.onPointerLeave,()=>{c()})})}),QS="SelectSeparator",Jh=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return l.jsx(be.div,{"aria-hidden":!0,...r,ref:t})});Jh.displayName=QS;var _a="SelectArrow",eC=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Cs(n),s=Tn(_a,n),i=kn(_a,n);return s.open&&i.position==="popper"?l.jsx(Gd,{...o,...r,ref:t}):null});eC.displayName=_a;var tC="SelectBubbleInput",Zh=p.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=p.useRef(null),s=Ne(r,o),i=bh(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(be.select,{...n,style:{...Ih,...n.style},ref:s,defaultValue:t})});Zh.displayName=tC;function Qh(e){return e===""||e===void 0}function ep(e){const t=dt(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 tp(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=nC(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 nC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rC=Nh,np=_h,oC=Rh,sC=Ph,iC=Oh,rp=Mh,aC=$h,op=Hh,sp=Wh,lC=Vh,cC=qh,ip=Gh,ap=Yh,lp=Jh;const cp=rC,up=oC,ja=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(np,{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(sC,{asChild:!0,children:l.jsx(ne.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));ja.displayName=np.displayName;const dp=p.forwardRef(({className:e,...t},n)=>l.jsx(ip,{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"})}));dp.displayName=ip.displayName;const fp=p.forwardRef(({className:e,...t},n)=>l.jsx(ap,{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"})}));fp.displayName=ap.displayName;const Ra=p.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>l.jsx(iC,{children:l.jsxs(rp,{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(dp,{}),l.jsx(aC,{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(fp,{})]})}));Ra.displayName=rp.displayName;const uC=p.forwardRef(({className:e,...t},n)=>l.jsx(op,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));uC.displayName=op.displayName;const Vn=p.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(sp,{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(cC,{children:l.jsx(ne.Check,{className:"h-4 w-4"})})}),l.jsx(lC,{children:t})]}));Vn.displayName=sp.displayName;const dC=p.forwardRef(({className:e,...t},n)=>l.jsx(lp,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));dC.displayName=lp.displayName;var fC="Separator",hp="horizontal",hC=["horizontal","vertical"],pp=p.forwardRef((e,t)=>{const{decorative:n,orientation:r=hp,...o}=e,s=pC(r)?r:hp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return l.jsx(be.div,{"data-orientation":s,...a,...o,ref:t})});pp.displayName=fC;function pC(e){return hC.includes(e)}var mp=pp;const gp=p.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>l.jsx(mp,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));gp.displayName=mp.displayName;const mC=Qu,gC=qw,xC=ed,xp=p.forwardRef(({className:e,...t},n)=>l.jsx(qo,{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}));xp.displayName=qo.displayName;const vC=Yr.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"}}),vp=p.forwardRef(({side:e="right",className:t,children:n,...r},o)=>l.jsxs(xC,{children:[l.jsx(xp,{}),l.jsxs(Go,{ref:o,className:Z(vC({side:e}),t),...r,children:[n,l.jsxs(td,{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"})]})]})]}));vp.displayName=Go.displayName;const wp=({className:e,...t})=>l.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});wp.displayName="SheetHeader";const bp=p.forwardRef(({className:e,...t},n)=>l.jsx(Fn,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));bp.displayName=Fn.displayName;const yp=p.forwardRef(({className:e,...t},n)=>l.jsx(Yo,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));yp.displayName=Yo.displayName;const wC={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 bC({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}=Ai();y.useEffect(()=>{const m=JSON.stringify(a)!==JSON.stringify(e);d(m)},[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."})},g=()=>{c(wC),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(mC,{open:r,onOpenChange:o,children:[l.jsx(gC,{asChild:!0,children:l.jsxs(Oe,{variant:"outline",size:"sm",className:n,children:[l.jsx(ne.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&l.jsx(bi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),l.jsxs(vp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[l.jsxs(wp,{children:[l.jsx(bp,{children:"Chat Settings"}),l.jsx(yp,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),l.jsxs("div",{className:"space-y-6 py-6",children:[l.jsxs(_r,{children:[l.jsx(jr,{className:"pb-3",children:l.jsxs(Rr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.Server,{className:"h-5 w-5"}),"API Configuration"]})}),l.jsxs(Eo,{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx($t,{htmlFor:"api-url",children:"API Base URL"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ms,{id:"api-url",value:a.api.baseUrl,onChange:m=>c(x=>({...x,api:{...x.api,baseUrl:m.target.value}})),placeholder:"http://localhost:8000/api"}),l.jsx(Oe,{variant:"outline",onClick:v,children:"Test"})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx($t,{htmlFor:"enable-auth",children:"Enable Authentication"}),l.jsx(Cn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:m=>c(x=>({...x,api:{...x.api,enableAuth:m}}))})]}),a.api.enableAuth&&l.jsxs("div",{className:"space-y-2",children:[l.jsx($t,{htmlFor:"auth-token",children:"Authentication Token"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ms,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:m=>c(x=>({...x,api:{...x.api,authToken:m.target.value}})),placeholder:"Enter your Bearer token"}),l.jsx(Oe,{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(_r,{children:[l.jsx(jr,{className:"pb-3",children:l.jsxs(Rr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),l.jsxs(Eo,{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx($t,{htmlFor:"layout",children:"Layout Style"}),l.jsxs(cp,{value:a.ui.layout,onValueChange:m=>c(x=>({...x,ui:{...x.ui,layout:m}})),children:[l.jsx(ja,{children:l.jsx(up,{})}),l.jsxs(Ra,{children:[l.jsx(Vn,{value:"sidebar",children:"Sidebar Layout"}),l.jsx(Vn,{value:"fullscreen",children:"Fullscreen"}),l.jsx(Vn,{value:"tabs",children:"Tabbed Interface"})]})]})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx($t,{htmlFor:"theme",children:"Theme"}),l.jsxs(cp,{value:a.ui.theme,onValueChange:m=>c(x=>({...x,ui:{...x.ui,theme:m}})),children:[l.jsx(ja,{children:l.jsx(up,{})}),l.jsxs(Ra,{children:[l.jsx(Vn,{value:"light",children:"Light"}),l.jsx(Vn,{value:"dark",children:"Dark"}),l.jsx(Vn,{value:"system",children:"System"})]})]})]}),l.jsx(gp,{}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx($t,{htmlFor:"show-timestamps",children:"Show Timestamps"}),l.jsx(Cn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:m=>c(x=>({...x,ui:{...x.ui,showTimestamps:m}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx($t,{htmlFor:"show-agent-names",children:"Show Agent Names"}),l.jsx(Cn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:m=>c(x=>({...x,ui:{...x.ui,showAgentNames:m}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx($t,{htmlFor:"compact-messages",children:"Compact Messages"}),l.jsx(Cn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:m=>c(x=>({...x,ui:{...x.ui,compactMessages:m}}))})]})]})]})]}),l.jsxs(_r,{children:[l.jsx(jr,{className:"pb-3",children:l.jsxs(Rr,{className:"text-lg flex items-center gap-2",children:[l.jsx(ne.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),l.jsxs(Eo,{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx($t,{htmlFor:"auto-save",children:"Auto-save Conversations"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),l.jsx(Cn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:m=>c(x=>({...x,behavior:{...x.behavior,autoSave:m}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx($t,{htmlFor:"enable-streaming",children:"Enable Streaming"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),l.jsx(Cn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:m=>c(x=>({...x,behavior:{...x.behavior,enableStreaming:m}}))})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx($t,{htmlFor:"typing-indicator",children:"Typing Indicator"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),l.jsx(Cn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:m=>c(x=>({...x,behavior:{...x.behavior,showTypingIndicator:m}}))})]})]})]})]}),l.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[l.jsxs(Oe,{variant:"outline",onClick:g,children:[l.jsx(ne.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(Oe,{variant:"outline",onClick:w,children:"Cancel"}),l.jsxs(Oe,{onClick:h,disabled:!u,children:[l.jsx(ne.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function yC({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(co,{...s,onThreadChange:c,children:l.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:l.jsx(ps,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?l.jsx(co,{...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(Ta,{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(ps,{onError:s.onError,enableFileUpload:!0})})]})})}):l.jsx(co,{...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(Ta,{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(ps,{onError:s.onError,enableFileUpload:!0})})]})})}ve.ChatApi=jl,ve.ChatInterface=ps,ve.ChatProvider=co,ve.ChatProviders=Hl,ve.ChatSettings=bC,ve.MarkdownContent=jo,ve.MessageComponent=ud,ve.MessageList=Ki,ve.ThreadManager=Ta,ve.applySettings=ES,ve.chatApiClient=hn,ve.default=yC,ve.del=_l,ve.get=Et,ve.getChatToken=Il,ve.getCurrentSettings=kS,ve.getDefaultApiConfig=mh,ve.getDefaultChatSettings=gh,ve.onChatTokenChanged=Nl,ve.post=Ks,ve.put=Al,ve.setChatToken=Vs,ve.useApi=lo,ve.useChat=wr,ve.useChatStream=$l,ve.useMessages=Bl,ve.useMessagesReducer=Ll,ve.useStream=Ml,ve.useThreads=qs,Object.defineProperties(ve,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});