teodor-new-chat-ui 4.1.2 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +317 -321
- package/dist/index.umd.js +13 -13
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -15,14 +15,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
17
|
*/var Fa;function Sp(){return Fa||(Fa=1,process.env.NODE_ENV!=="production"&&function(){var e=S,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),w=Symbol.iterator,v="@@iterator";function g(k){if(k===null||typeof k!="object")return null;var B=w&&k[w]||k[v];return typeof B=="function"?B:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(k){{for(var B=arguments.length,ee=new Array(B>1?B-1:0),Te=1;Te<B;Te++)ee[Te-1]=arguments[Te];y("error",k,ee)}}function y(k,B,ee){{var Te=x.ReactDebugCurrentFrame,Ke=Te.getStackAddendum();Ke!==""&&(B+="%s",ee=ee.concat([Ke]));var Qe=ee.map(function(ze){return String(ze)});Qe.unshift("Warning: "+B),Function.prototype.apply.call(console[k],console,Qe)}}var E=!1,C=!1,T=!1,I=!1,A=!1,R;R=Symbol.for("react.module.reference");function j(k){return!!(typeof k=="string"||typeof k=="function"||k===r||k===s||A||k===o||k===u||k===d||I||k===p||E||C||T||typeof k=="object"&&k!==null&&(k.$$typeof===h||k.$$typeof===f||k.$$typeof===i||k.$$typeof===a||k.$$typeof===l||k.$$typeof===R||k.getModuleId!==void 0))}function M(k,B,ee){var Te=k.displayName;if(Te)return Te;var Ke=B.displayName||B.name||"";return Ke!==""?ee+"("+Ke+")":ee}function D(k){return k.displayName||"Context"}function L(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 B=k;return D(B)+".Consumer";case i:var ee=k;return D(ee._context)+".Provider";case l:return M(k,k.render,"ForwardRef");case f:var Te=k.displayName||null;return Te!==null?Te:L(k.type)||"Memo";case h:{var Ke=k,Qe=Ke._payload,ze=Ke._init;try{return L(ze(Qe))}catch{return null}}}return null}var P=Object.assign,W=0,H,q,F,N,U,Y,fe;function ie(){}ie.__reactDisabledLog=!0;function he(){{if(W===0){H=console.log,q=console.info,F=console.warn,N=console.error,U=console.group,Y=console.groupCollapsed,fe=console.groupEnd;var k={configurable:!0,enumerable:!0,value:ie,writable:!0};Object.defineProperties(console,{info:k,log:k,warn:k,error:k,group:k,groupCollapsed:k,groupEnd:k})}W++}}function Ee(){{if(W--,W===0){var k={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},k,{value:H}),info:P({},k,{value:q}),warn:P({},k,{value:F}),error:P({},k,{value:N}),group:P({},k,{value:U}),groupCollapsed:P({},k,{value:Y}),groupEnd:P({},k,{value:fe})})}W<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var de=x.ReactCurrentDispatcher,z;function O(k,B,ee){{if(z===void 0)try{throw Error()}catch(Ke){var Te=Ke.stack.trim().match(/\n( *(at )?)/);z=Te&&Te[1]||""}return`
|
|
18
|
-
`+z+k}}var
|
|
18
|
+
`+z+k}}var K=!1,J;{var ae=typeof WeakMap=="function"?WeakMap:Map;J=new ae}function re(k,B){if(!k||K)return"";{var ee=J.get(k);if(ee!==void 0)return ee}var Te;K=!0;var Ke=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Qe;Qe=de.current,de.current=null,he();try{if(B){var ze=function(){throw Error()};if(Object.defineProperty(ze.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ze,[])}catch(Nt){Te=Nt}Reflect.construct(k,[],ze)}else{try{ze.call()}catch(Nt){Te=Nt}k.call(ze.prototype)}}else{try{throw Error()}catch(Nt){Te=Nt}k()}}catch(Nt){if(Nt&&Te&&typeof Nt.stack=="string"){for(var Me=Nt.stack.split(`
|
|
19
19
|
`),St=Te.stack.split(`
|
|
20
20
|
`),ut=Me.length-1,ft=St.length-1;ut>=1&&ft>=0&&Me[ut]!==St[ft];)ft--;for(;ut>=1&&ft>=0;ut--,ft--)if(Me[ut]!==St[ft]){if(ut!==1||ft!==1)do if(ut--,ft--,ft<0||Me[ut]!==St[ft]){var Ut=`
|
|
21
|
-
`+Me[ut].replace(" at new "," at ");return k.displayName&&Ut.includes("<anonymous>")&&(Ut=Ut.replace("<anonymous>",k.displayName)),typeof k=="function"&&J.set(k,Ut),Ut}while(ut>=1&&ft>=0);break}}}finally{
|
|
21
|
+
`+Me[ut].replace(" at new "," at ");return k.displayName&&Ut.includes("<anonymous>")&&(Ut=Ut.replace("<anonymous>",k.displayName)),typeof k=="function"&&J.set(k,Ut),Ut}while(ut>=1&&ft>=0);break}}}finally{K=!1,de.current=Qe,Ee(),Error.prepareStackTrace=Ke}var br=k?k.displayName||k.name:"",tr=br?O(br):"";return typeof k=="function"&&J.set(k,tr),tr}function Fe(k,B,ee){return re(k,!1)}function Xe(k){var B=k.prototype;return!!(B&&B.isReactComponent)}function et(k,B,ee){if(k==null)return"";if(typeof k=="function")return re(k,Xe(k));if(typeof k=="string")return O(k);switch(k){case u:return O("Suspense");case d:return O("SuspenseList")}if(typeof k=="object")switch(k.$$typeof){case l:return Fe(k.render);case f:return et(k.type,B,ee);case h:{var Te=k,Ke=Te._payload,Qe=Te._init;try{return et(Qe(Ke),B,ee)}catch{}}}return""}var ye=Object.prototype.hasOwnProperty,Pe={},Je=x.ReactDebugCurrentFrame;function $e(k){if(k){var B=k._owner,ee=et(k.type,k._source,B?B.type:null);Je.setExtraStackFrame(ee)}else Je.setExtraStackFrame(null)}function st(k,B,ee,Te,Ke){{var Qe=Function.call.bind(ye);for(var ze in k)if(Qe(k,ze)){var Me=void 0;try{if(typeof k[ze]!="function"){var St=Error((Te||"React class")+": "+ee+" type `"+ze+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof k[ze]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw St.name="Invariant Violation",St}Me=k[ze](B,ze,Te,ee,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ut){Me=ut}Me&&!(Me instanceof Error)&&($e(Ke),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).",Te||"React class",ee,ze,typeof Me),$e(null)),Me instanceof Error&&!(Me.message in Pe)&&(Pe[Me.message]=!0,$e(Ke),b("Failed %s type: %s",ee,Me.message),$e(null))}}}var lt=Array.isArray;function Z(k){return lt(k)}function le(k){{var B=typeof Symbol=="function"&&Symbol.toStringTag,ee=B&&k[Symbol.toStringTag]||k.constructor.name||"Object";return ee}}function ge(k){try{return Ce(k),!1}catch{return!0}}function Ce(k){return""+k}function we(k){if(ge(k))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",le(k)),Ce(k)}var je=x.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0},Ue,ct;function Et(k){if(ye.call(k,"ref")){var B=Object.getOwnPropertyDescriptor(k,"ref").get;if(B&&B.isReactWarning)return!1}return k.ref!==void 0}function _n(k){if(ye.call(k,"key")){var B=Object.getOwnPropertyDescriptor(k,"key").get;if(B&&B.isReactWarning)return!1}return k.key!==void 0}function G(k,B){typeof k.ref=="string"&&je.current}function ce(k,B){{var ee=function(){Ue||(Ue=!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)",B))};ee.isReactWarning=!0,Object.defineProperty(k,"key",{get:ee,configurable:!0})}}function Ie(k,B){{var ee=function(){ct||(ct=!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)",B))};ee.isReactWarning=!0,Object.defineProperty(k,"ref",{get:ee,configurable:!0})}}var Ve=function(k,B,ee,Te,Ke,Qe,ze){var Me={$$typeof:t,type:k,key:B,ref:ee,props:ze,_owner:Qe};return Me._store={},Object.defineProperty(Me._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Me,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Te}),Object.defineProperty(Me,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ke}),Object.freeze&&(Object.freeze(Me.props),Object.freeze(Me)),Me};function qe(k,B,ee,Te,Ke){{var Qe,ze={},Me=null,St=null;ee!==void 0&&(we(ee),Me=""+ee),_n(B)&&(we(B.key),Me=""+B.key),Et(B)&&(St=B.ref,G(B,Ke));for(Qe in B)ye.call(B,Qe)&&!Ze.hasOwnProperty(Qe)&&(ze[Qe]=B[Qe]);if(k&&k.defaultProps){var ut=k.defaultProps;for(Qe in ut)ze[Qe]===void 0&&(ze[Qe]=ut[Qe])}if(Me||St){var ft=typeof k=="function"?k.displayName||k.name||"Unknown":k;Me&&ce(ze,ft),St&&Ie(ze,ft)}return Ve(k,Me,St,Ke,Te,je.current,ze)}}var It=x.ReactCurrentOwner,Rn=x.ReactDebugCurrentFrame;function Jt(k){if(k){var B=k._owner,ee=et(k.type,k._source,B?B.type:null);Rn.setExtraStackFrame(ee)}else Rn.setExtraStackFrame(null)}var Zn;Zn=!1;function Qn(k){return typeof k=="object"&&k!==null&&k.$$typeof===t}function wr(){{if(It.current){var k=L(It.current.type);if(k)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+k+"`."}return""}}function Qr(k){return""}var er={};function gn(k){{var B=wr();if(!B){var ee=typeof k=="string"?k:k.displayName||k.name;ee&&(B=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+ee+">.")}return B}}function
|
|
25
|
+
Check the top-level render call using <`+ee+">.")}return B}}function oe(k,B){{if(!k._store||k._store.validated||k.key!=null)return;k._store.validated=!0;var ee=gn(B);if(er[ee])return;er[ee]=!0;var Te="";k&&k._owner&&k._owner!==It.current&&(Te=" It was passed a child from "+L(k._owner.type)+"."),Jt(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.',ee,Te),Jt(null)}}function xe(k,B){{if(typeof k!="object")return;if(Z(k))for(var ee=0;ee<k.length;ee++){var Te=k[ee];Qn(Te)&&oe(Te,B)}else if(Qn(k))k._store&&(k._store.validated=!0);else if(k){var Ke=g(k);if(typeof Ke=="function"&&Ke!==k.entries)for(var Qe=Ke.call(k),ze;!(ze=Qe.next()).done;)Qn(ze.value)&&oe(ze.value,B)}}}function Le(k){{var B=k.type;if(B==null||typeof B=="string")return;var ee;if(typeof B=="function")ee=B.propTypes;else if(typeof B=="object"&&(B.$$typeof===l||B.$$typeof===f))ee=B.propTypes;else return;if(ee){var Te=L(B);st(ee,k.props,"prop",Te,k)}else if(B.PropTypes!==void 0&&!Zn){Zn=!0;var Ke=L(B);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ke||"Unknown")}typeof B.getDefaultProps=="function"&&!B.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ot(k){{for(var B=Object.keys(k.props),ee=0;ee<B.length;ee++){var Te=B[ee];if(Te!=="children"&&Te!=="key"){Jt(k),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Te),Jt(null);break}}k.ref!==null&&(Jt(k),b("Invalid attribute `ref` supplied to `React.Fragment`."),Jt(null))}}var Dt={};function dn(k,B,ee,Te,Ke,Qe){{var ze=j(k);if(!ze){var Me="";(k===void 0||typeof k=="object"&&k!==null&&Object.keys(k).length===0)&&(Me+=" 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 St=Qr();St?Me+=St:Me+=wr();var ut;k===null?ut="null":Z(k)?ut="array":k!==void 0&&k.$$typeof===t?(ut="<"+(L(k.type)||"Unknown")+" />",Me=" Did you accidentally export a JSX literal instead of a component?"):ut=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",ut,Me)}var ft=qe(k,B,ee,Ke,Qe);if(ft==null)return ft;if(ze){var Ut=B.children;if(Ut!==void 0)if(Te)if(Z(Ut)){for(var br=0;br<Ut.length;br++)xe(Ut[br],k);Object.freeze&&Object.freeze(Ut)}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 xe(Ut,k)}if(ye.call(B,"key")){var tr=L(k),Nt=Object.keys(B).filter(function(lC){return lC!=="key"}),Ma=Nt.length>0?"{key: someKey, "+Nt.join(": ..., ")+": ...}":"{key: someKey}";if(!Dt[tr+Ma]){var aC=Nt.length>0?"{"+Nt.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:
|
|
@@ -32,10 +32,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
32
32
|
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[ol]=this[ol]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Ir(i);r[a]||(Tm(o,i),r[a]=!0)}return _.isArray(t)?t.forEach(s):s(t),this}};Tt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),_.reduceDescriptors(Tt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),_.freezeMethods(Tt);function Bs(e,t){const n=this||Er,r=t||n,o=Tt.from(r.headers);let s=r.data;return _.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function sl(e){return!!(e&&e.__CANCEL__)}function or(e,t,n){Ae.call(this,e??"canceled",Ae.ERR_CANCELED,t,n),this.name="CanceledError"}_.inherits(or,Ae,{__CANCEL__:!0});function il(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Ae("Request failed with status code "+n.status,[Ae.ERR_BAD_REQUEST,Ae.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function km(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Em(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function Im(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const co=(e,t,n=3)=>{let r=0;const o=Em(50,250);return Im(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},al=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},ll=e=>(...t)=>_.asap(()=>e(...t)),Nm=gt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,gt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(gt.origin),gt.navigator&&/(msie|trident)/i.test(gt.navigator.userAgent)):()=>!0,Am=gt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];_.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),_.isString(r)&&i.push("path="+r),_.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function jm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function _m(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function cl(e,t,n){let r=!jm(t);return e&&(r||n==!1)?_m(e,t):t}const ul=e=>e instanceof Tt?{...e}:e;function Mn(e,t){t=t||{};const n={};function r(u,d,f,h){return _.isPlainObject(u)&&_.isPlainObject(d)?_.merge.call({caseless:h},u,d):_.isPlainObject(d)?_.merge({},d):_.isArray(d)?d.slice():d}function o(u,d,f,h){if(_.isUndefined(d)){if(!_.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!_.isUndefined(d))return r(void 0,d)}function i(u,d){if(_.isUndefined(d)){if(!_.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(u,d,f)=>o(ul(u),ul(d),f,!0)};return _.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);_.isUndefined(h)&&f!==a||(n[d]=h)}),n}const dl=e=>{const t=Mn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Tt.from(i),t.url=el(cl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),_.isFormData(n)){if(gt.hasStandardBrowserEnv||gt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(_.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(gt.hasStandardBrowserEnv&&(r&&_.isFunction(r)&&(r=r(t)),r||r!==!1&&Nm(t.url))){const l=o&&s&&Am.read(s);l&&i.set(o,l)}return t},Rm=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=dl(e);let s=o.data;const i=Tt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,w;function v(){p&&p(),w&&w(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function x(){if(!g)return;const y=Tt.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:y,config:e,request:g};il(function(I){n(I),v()},function(I){r(I),v()},C),g=null}"onloadend"in g?g.onloadend=x:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(x)},g.onabort=function(){g&&(r(new Ae("Request aborted",Ae.ECONNABORTED,e,g)),g=null)},g.onerror=function(E){const C=E&&E.message?E.message:"Network Error",T=new Ae(C,Ae.ERR_NETWORK,e,g);T.event=E||null,r(T),g=null},g.ontimeout=function(){let E=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||nl;o.timeoutErrorMessage&&(E=o.timeoutErrorMessage),r(new Ae(E,C.clarifyTimeoutError?Ae.ETIMEDOUT:Ae.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&_.forEach(i.toJSON(),function(E,C){g.setRequestHeader(C,E)}),_.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,w]=co(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=co(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=y=>{g&&(r(!y||y.type?new or(null,e,g):y),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=km(o.url);if(b&>.protocols.indexOf(b)===-1){r(new Ae("Unsupported protocol "+b+":",Ae.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Pm=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof Ae?d:new or(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Ae(`timeout ${t} of ms exceeded`,Ae.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>_.asap(a),l}},Om=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},Mm=async function*(e,t){for await(const n of Dm(e))yield*Om(n,t)},Dm=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},fl=(e,t,n,r)=>{const o=Mm(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},hl=64*1024,{isFunction:uo}=_,Lm=(({Request:e,Response:t})=>({Request:e,Response:t}))(_.global),{ReadableStream:pl,TextEncoder:ml}=_.global,gl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Fm=e=>{e=_.merge.call({skipUndefined:!0},Lm,e);const{fetch:t,Request:n,Response:r}=e,o=t?uo(t):typeof fetch=="function",s=uo(n),i=uo(r);if(!o)return!1;const a=o&&uo(pl),l=o&&(typeof ml=="function"?(w=>v=>w.encode(v))(new ml):async w=>new Uint8Array(await new n(w).arrayBuffer())),u=s&&a&&gl(()=>{let w=!1;const v=new n(gt.origin,{body:new pl,method:"POST",get duplex(){return w=!0,"half"}}).headers.has("Content-Type");return w&&!v}),d=i&&a&&gl(()=>_.isReadableStream(new r("").body)),f={stream:d&&(w=>w.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(w=>{!f[w]&&(f[w]=(v,g)=>{let x=v&&v[w];if(x)return x.call(v);throw new Ae(`Response type '${w}' is not supported`,Ae.ERR_NOT_SUPPORT,g)})});const h=async w=>{if(w==null)return 0;if(_.isBlob(w))return w.size;if(_.isSpecCompliantForm(w))return(await new n(gt.origin,{method:"POST",body:w}).arrayBuffer()).byteLength;if(_.isArrayBufferView(w)||_.isArrayBuffer(w))return w.byteLength;if(_.isURLSearchParams(w)&&(w=w+""),_.isString(w))return(await l(w)).byteLength},p=async(w,v)=>{const g=_.toFiniteNumber(w.getContentLength());return g??h(v)};return async w=>{let{url:v,method:g,data:x,signal:b,cancelToken:y,timeout:E,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:A,withCredentials:R="same-origin",fetchOptions:j}=dl(w),M=t||fetch;I=I?(I+"").toLowerCase():"text";let D=Pm([b,y&&y.toAbortSignal()],E),L=null;const P=D&&D.unsubscribe&&(()=>{D.unsubscribe()});let W;try{if(T&&u&&g!=="get"&&g!=="head"&&(W=await p(A,x))!==0){let Y=new n(v,{method:"POST",body:x,duplex:"half"}),fe;if(_.isFormData(x)&&(fe=Y.headers.get("content-type"))&&A.setContentType(fe),Y.body){const[ie,he]=al(W,co(ll(T)));x=fl(Y.body,hl,ie,he)}}_.isString(R)||(R=R?"include":"omit");const H=s&&"credentials"in n.prototype,q={...j,signal:D,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:x,duplex:"half",credentials:H?R:void 0};L=s&&new n(v,q);let F=await(s?M(L,j):M(v,q));const N=d&&(I==="stream"||I==="response");if(d&&(C||N&&P)){const Y={};["status","statusText","headers"].forEach(Ee=>{Y[Ee]=F[Ee]});const fe=_.toFiniteNumber(F.headers.get("content-length")),[ie,he]=C&&al(fe,co(ll(C),!0))||[];F=new r(fl(F.body,hl,ie,()=>{he&&he(),P&&P()}),Y)}I=I||"text";let U=await f[_.findKey(f,I)||"text"](F,w);return!N&&P&&P(),await new Promise((Y,fe)=>{il(Y,fe,{data:U,headers:Tt.from(F.headers),status:F.status,statusText:F.statusText,config:w,request:L})})}catch(H){throw P&&P(),H&&H.name==="TypeError"&&/Load failed|fetch/i.test(H.message)?Object.assign(new Ae("Network Error",Ae.ERR_NETWORK,w,L),{cause:H.cause||H}):Ae.from(H,H&&H.code,w,L)}}},$m=new Map,xl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=$m;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Fm(t)),d=u;return u};xl();const Hs={http:am,xhr:Rm,fetch:{get:xl}};_.forEach(Hs,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const vl=e=>`- ${e}`,zm=e=>_.isFunction(e)||e===null||e===!1,wl={getAdapter:(e,t)=>{e=_.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!zm(r)&&(o=Hs[(a=String(r)).toLowerCase()],o===void 0))throw new Ae(`Unknown adapter '${a}'`);if(o&&(_.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
33
|
`+i.map(vl).join(`
|
|
34
34
|
`):" "+vl(i[0]):"as no adapter specified";throw new Ae("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Hs};function Us(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new or(null,e)}function bl(e){return Us(e),e.headers=Tt.from(e.headers),e.data=Bs.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),wl.getAdapter(e.adapter||Er.adapter,e)(e).then(function(r){return Us(e),r.data=Bs.call(e,e.transformResponse,r),r.headers=Tt.from(r.headers),r},function(r){return sl(r)||(Us(e),r&&r.response&&(r.response.data=Bs.call(e,e.transformResponse,r.response),r.response.headers=Tt.from(r.response.headers))),Promise.reject(r)})}const yl="1.12.2",fo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{fo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Sl={};fo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+yl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Ae(o(i," has been removed"+(n?" in "+n:"")),Ae.ERR_DEPRECATED);return n&&!Sl[i]&&(Sl[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},fo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Bm(e,t,n){if(typeof e!="object")throw new Ae("options must be an object",Ae.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new Ae("option "+s+" must be "+l,Ae.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Ae("Unknown option "+s,Ae.ERR_BAD_OPTION)}}const ho={assertOptions:Bm,validators:fo},Zt=ho.validators;let Dn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new tl,response:new tl}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Mn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ho.assertOptions(r,{silentJSONParsing:Zt.transitional(Zt.boolean),forcedJSONParsing:Zt.transitional(Zt.boolean),clarifyTimeoutError:Zt.transitional(Zt.boolean)},!1),o!=null&&(_.isFunction(o)?n.paramsSerializer={serialize:o}:ho.assertOptions(o,{encode:Zt.function,serialize:Zt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ho.assertOptions(n,{baseUrl:Zt.spelling("baseURL"),withXsrfToken:Zt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&_.merge(s.common,s[n.method]);s&&_.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=Tt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(n)===!1||(l=l&&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(!l){const w=[bl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],v=a[f++];try{p=w(p)}catch(g){v.call(this,g);break}}try{d=bl.call(this,p)}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=Mn(this.defaults,t);const n=cl(t.baseURL,t.url,t.allowAbsoluteUrls);return el(n,t.params,t.paramsSerializer)}};_.forEach(["delete","get","head","options"],function(t){Dn.prototype[t]=function(n,r){return this.request(Mn(r||{},{method:t,url:n,data:(r||{}).data}))}}),_.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Mn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Dn.prototype[t]=n(),Dn.prototype[t+"Form"]=n(!0)});let Hm=class vp{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 or(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 vp(function(o){t=o}),cancel:t}}};function Um(e){return function(n){return e.apply(null,n)}}function Wm(e){return _.isObject(e)&&e.isAxiosError===!0}const Ws={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(Ws).forEach(([e,t])=>{Ws[t]=e});function Cl(e){const t=new Dn(e),n=$a(Dn.prototype.request,t);return _.extend(n,Dn.prototype,t,{allOwnKeys:!0}),_.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Cl(Mn(e,o))},n}const it=Cl(Er);it.Axios=Dn,it.CanceledError=or,it.CancelToken=Hm,it.isCancel=sl,it.VERSION=yl,it.toFormData=ao,it.AxiosError=Ae,it.Cancel=it.CanceledError,it.all=function(t){return Promise.all(t)},it.spread=Um,it.isAxiosError=Wm,it.mergeConfig=Mn,it.AxiosHeaders=Tt,it.formToJSON=e=>rl(_.isHTMLForm(e)?new FormData(e):e),it.getAdapter=wl.getAdapter,it.HttpStatusCode=Ws,it.default=it;const{Axios:xC,AxiosError:vC,CanceledError:wC,isCancel:bC,CancelToken:yC,VERSION:SC,all:CC,Cancel:TC,isAxiosError:kC,spread:EC,toFormData:IC,AxiosHeaders:NC,HttpStatusCode:AC,formToJSON:jC,getAdapter:_C,mergeConfig:RC}=it,Tl=typeof window<"u"?window.__API_BASE_URL__:void 0,kl=Tl?fn(Tl):void 0;function fn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let po=null;const Vs=new Set;function El(){return po}function Ks(e){po=e,Vs.forEach(t=>t(e))}function Il(e){return Vs.add(e),()=>Vs.delete(e)}const Lt=it.create({...kl?{baseURL:kl}:{},timeout:3e4,withCredentials:!0});Lt.interceptors.request.use(e=>(po&&(e.headers.Authorization=`Bearer ${po}`),e)),Lt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function At(e,t){return Lt.defaults.baseURL?(await Lt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function qs(e,t,n){return Lt.defaults.baseURL?(await Lt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Nl(e,t,n){return Lt.defaults.baseURL?(await Lt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Al(e,t){return Lt.defaults.baseURL?(await Lt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function jt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class jl{get baseUrl(){const t=Lt.defaults.baseURL;return t?fn(String(t)):""}updateConfig(t){t.baseUrl&&(Lt.defaults.baseURL=fn(String(t.baseUrl))),t.authToken!==void 0&&Ks(t.authToken)}getAuthToken(){return El()}setAuthToken(t){Ks(t)}onTokenChange(t){return Il(t)}async listThreads(){const t=await At("/threads"),n=jt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await qs("/threads",t?{title:t}:void 0);return jt(r)}async updateThread(t,n){const r=await Nl(`/threads/${t}`,{title:n});return jt(r)}async deleteThread(t){const n=await Al(`/threads/${t}`);return jt(n)}async threadInfo(t){const n=await At(`/threads/${t}/info`);return jt(n)}async listAgents(){const t=await At("/agents"),n=jt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await At(`/agents/${t}`);return jt(n)}async getAgentSchema(t){const n=await At(`/agents/${t}/schema`);return jt(n)}async getMessages(t){const n=await At(`/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 jt(n)}async getState(t){const n=await At(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return jt(n)}async getStateHistory(t){const n=await At(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return jt(n)}async listCheckpoints(t){const n=await At(`/threads/${t}/checkpoints`,{params:{thread_id:t}});return jt(n)}async resume(t){const n=await qs("/runs/resume",{thread_id:t.threadId,value:t.value});return jt(n)}}const vn=new jl,_l=S.createContext(null);function Vm({children:e,apiConfig:t}){const n=vn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(_l.Provider,{value:r,children:e})}function Gs(){const e=S.useContext(_l);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function Km(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function qm(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Gm(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await qm(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}function Ym(e){return e.type!=="thread_info"&&e.type!=="token"}const Xm={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Jm(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:Ys(((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=Ys(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=Ys(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 Pl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Pl(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 Rl(e=[]){const[t,n]=S.useReducer(Jm,{...Xm,messages:e}),r=S.useRef([]),o=S.useRef(null),s=S.useRef(null),i=S.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=S.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=S.useCallback(d=>{r.current.push(d),a()},[a]);S.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=S.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function Pl(e,t){var n,r;if(t.type==="message_start"&&t.role==="assistant"){const o=t.id,s=rg(t.model);if(e.messages.some(l=>l.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??Xs(e.messages);return o?{...e,messages:Js(e.messages,o,t.delta)}:e}if(t.type==="message_end"){const o=e.assemblingId??Xs(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),l={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?Js(e.messages,s,[i]):[...e.messages,l];return{...e,messages:u,toolIndex:{...e.toolIndex,[o]:s}}}if(t.type==="checkpoint"){const o=t.checkpointNs??e.lastCheckpointNs??null,s=ng(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??Xs(e.messages),s={type:"interrupt",value:t.value};if(o)return{...e,assemblingId:null,messages:Js(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 Ys(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 Zm(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Xs(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Qm(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 Js(e,t,n){return Qm(e,t,r=>({...r,content:eg(r.content,n)}))}function eg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){const i=o,a=i.text??"";if(!a){i.text=s;continue}if(s.startsWith(a)){i.text=s;continue}if(a.startsWith(s)){i.text=s;continue}const l=tg(a,s);l?i.text=a+l:s.length!==a.length&&(i.text=s)}else n.push({type:"text",text:s})}else n.push(r);return n}function tg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let r=n;r>0;r--)if(e.slice(-r)===t.slice(0,r))return t.slice(r);return t}function ng(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 Zm(e,r,s)}return e}function rg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Ol(e={}){const t=S.useMemo(()=>fn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=S.useState(e.token??null),s=S.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=S.useState(!1),[u,d]=S.useState(null),[f,h]=S.useState(""),[p,w]=S.useState(null),[v,g]=S.useState(0),[x,b]=S.useState(!1),y=S.useRef(null),E=S.useRef(!0),C=S.useRef(0),T=S.useCallback(j=>{o(j)},[]),I=S.useCallback(()=>{var j;(j=y.current)==null||j.abort(),y.current=null,l(!1),b(!1),C.current=0,g(0)},[]),A=S.useCallback(()=>{h(""),w(null),d(null)},[]),R=S.useCallback((j,M,D)=>{y.current&&(y.current.abort(),y.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const L=new AbortController;return y.current=L,(async()=>{var W,H,q,F,N,U,Y,fe;const P=ie=>{var he;try{const Ee=JSON.parse(JSON.stringify(ie));return(he=Ee==null?void 0:Ee.payload)!=null&&he.files_info&&Array.isArray(Ee.payload.files_info)&&(Ee.payload.files_info=Ee.payload.files_info.map(de=>({...de,data:de!=null&&de.data?`<base64 ${String(de.data).length} chars>`:de==null?void 0:de.data}))),Ee}catch{return ie}};try{let ie={};try{if(r)ie={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Pe=window.__AUTH_TOKEN__,Je=((W=window.localStorage)==null?void 0:W.getItem("authToken"))||null;let $e=null;try{const lt=(H=window.localStorage)==null?void 0:H.getItem("chat-settings");lt&&($e=((q=JSON.parse(lt))==null?void 0:q.apiKey)||null)}catch{}const st=Pe||Je||$e||null;st&&(ie={Authorization:`Bearer ${st}`})}}catch{}console.debug("[use-chat] POST",t+n,P(j));const he=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...ie,...s.current},body:JSON.stringify(j),signal:L.signal,credentials:i});if(!he.ok||!he.body){const ye=await he.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",he.status,ye==null?void 0:ye.slice(0,500)),new Error(`stream ${he.status}${ye?": "+ye:""}`)}b(!0);const Ee=he.body.getReader(),de=new TextDecoder;let z="",O=[];C.current=0,g(0);let V=0,J=null;const ae=()=>{if(O.length){const ye=O.join("");O=[],E.current&&h(Pe=>Pe+ye)}J=null},oe=()=>{typeof window<"u"&&J==null&&(J=requestAnimationFrame(ae))};let Fe=Date.now();const Xe=setInterval(()=>{var ye;if(Date.now()-Fe>6e4){const Pe="Stream idle timeout";d(Pe),L.abort(),(ye=D==null?void 0:D.onError)==null||ye.call(D,Pe)}},5e3),et=1024*1024;try{const ye=he.headers.get("X-Thread-Id")||he.headers.get("x-thread-id"),Pe=he.headers.get("X-Thread-Created")||he.headers.get("x-thread-created"),Je=ye??null,$e=String(Pe??"").toLowerCase()==="true";for((F=D==null?void 0:D.onOpen)==null||F.call(D,{threadId:Je,created:$e});;){const{value:st,done:lt}=await Ee.read();if(lt)break;z+=de.decode(st,{stream:!0}),z.length>et&&(z="",console.warn("Stream buffer reset: exceeded 1MB"));let Z;for(;(Z=z.indexOf(`
|
|
35
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Mn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ho.assertOptions(r,{silentJSONParsing:Zt.transitional(Zt.boolean),forcedJSONParsing:Zt.transitional(Zt.boolean),clarifyTimeoutError:Zt.transitional(Zt.boolean)},!1),o!=null&&(_.isFunction(o)?n.paramsSerializer={serialize:o}:ho.assertOptions(o,{encode:Zt.function,serialize:Zt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ho.assertOptions(n,{baseUrl:Zt.spelling("baseURL"),withXsrfToken:Zt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&_.merge(s.common,s[n.method]);s&&_.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=Tt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(n)===!1||(l=l&&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(!l){const w=[bl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],v=a[f++];try{p=w(p)}catch(g){v.call(this,g);break}}try{d=bl.call(this,p)}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=Mn(this.defaults,t);const n=cl(t.baseURL,t.url,t.allowAbsoluteUrls);return el(n,t.params,t.paramsSerializer)}};_.forEach(["delete","get","head","options"],function(t){Dn.prototype[t]=function(n,r){return this.request(Mn(r||{},{method:t,url:n,data:(r||{}).data}))}}),_.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Mn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Dn.prototype[t]=n(),Dn.prototype[t+"Form"]=n(!0)});let Hm=class vp{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 or(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 vp(function(o){t=o}),cancel:t}}};function Um(e){return function(n){return e.apply(null,n)}}function Wm(e){return _.isObject(e)&&e.isAxiosError===!0}const Ws={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(Ws).forEach(([e,t])=>{Ws[t]=e});function Cl(e){const t=new Dn(e),n=$a(Dn.prototype.request,t);return _.extend(n,Dn.prototype,t,{allOwnKeys:!0}),_.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Cl(Mn(e,o))},n}const it=Cl(Er);it.Axios=Dn,it.CanceledError=or,it.CancelToken=Hm,it.isCancel=sl,it.VERSION=yl,it.toFormData=ao,it.AxiosError=Ae,it.Cancel=it.CanceledError,it.all=function(t){return Promise.all(t)},it.spread=Um,it.isAxiosError=Wm,it.mergeConfig=Mn,it.AxiosHeaders=Tt,it.formToJSON=e=>rl(_.isHTMLForm(e)?new FormData(e):e),it.getAdapter=wl.getAdapter,it.HttpStatusCode=Ws,it.default=it;const{Axios:xC,AxiosError:vC,CanceledError:wC,isCancel:bC,CancelToken:yC,VERSION:SC,all:CC,Cancel:TC,isAxiosError:kC,spread:EC,toFormData:IC,AxiosHeaders:NC,HttpStatusCode:AC,formToJSON:jC,getAdapter:_C,mergeConfig:RC}=it,Tl=typeof window<"u"?window.__API_BASE_URL__:void 0,kl=Tl?fn(Tl):void 0;function fn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let po=null;const Vs=new Set;function El(){return po}function Ks(e){po=e,Vs.forEach(t=>t(e))}function Il(e){return Vs.add(e),()=>Vs.delete(e)}const Lt=it.create({...kl?{baseURL:kl}:{},timeout:3e4,withCredentials:!0});Lt.interceptors.request.use(e=>(po&&(e.headers.Authorization=`Bearer ${po}`),e)),Lt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function At(e,t){return Lt.defaults.baseURL?(await Lt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function qs(e,t,n){return Lt.defaults.baseURL?(await Lt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Nl(e,t,n){return Lt.defaults.baseURL?(await Lt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Al(e,t){return Lt.defaults.baseURL?(await Lt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function jt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class jl{get baseUrl(){const t=Lt.defaults.baseURL;return t?fn(String(t)):""}updateConfig(t){t.baseUrl&&(Lt.defaults.baseURL=fn(String(t.baseUrl))),t.authToken!==void 0&&Ks(t.authToken)}getAuthToken(){return El()}setAuthToken(t){Ks(t)}onTokenChange(t){return Il(t)}async listThreads(){const t=await At("/threads"),n=jt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await qs("/threads",t?{title:t}:void 0);return jt(r)}async updateThread(t,n){const r=await Nl(`/threads/${t}`,{title:n});return jt(r)}async deleteThread(t){const n=await Al(`/threads/${t}`);return jt(n)}async threadInfo(t){const n=await At(`/threads/${t}/info`);return jt(n)}async listAgents(){const t=await At("/agents"),n=jt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await At(`/agents/${t}`);return jt(n)}async getAgentSchema(t){const n=await At(`/agents/${t}/schema`);return jt(n)}async getMessages(t){const n=await At(`/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 jt(n)}async getState(t){const n=await At(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return jt(n)}async getStateHistory(t){const n=await At(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return jt(n)}async listCheckpoints(t){const n=await At(`/threads/${t}/checkpoints`,{params:{thread_id:t}});return jt(n)}async resume(t){const n=await qs("/runs/resume",{thread_id:t.threadId,value:t.value});return jt(n)}}const vn=new jl,_l=S.createContext(null);function Vm({children:e,apiConfig:t}){const n=vn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(_l.Provider,{value:r,children:e})}function Gs(){const e=S.useContext(_l);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function Km(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function qm(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Gm(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await qm(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}function Ym(e){return e.type!=="thread_info"&&e.type!=="token"}const Xm={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Jm(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:Ys(((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=Ys(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=Ys(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 Pl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Pl(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 Rl(e=[]){const[t,n]=S.useReducer(Jm,{...Xm,messages:e}),r=S.useRef([]),o=S.useRef(null),s=S.useRef(null),i=S.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=S.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=S.useCallback(d=>{r.current.push(d),a()},[a]);S.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=S.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function Pl(e,t){var n,r;if(t.type==="message_start"&&t.role==="assistant"){const o=t.id,s=rg(t.model);if(e.messages.some(l=>l.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??Xs(e.messages);return o?{...e,messages:Js(e.messages,o,t.delta)}:e}if(t.type==="message_end"){const o=e.assemblingId??Xs(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),l={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?Js(e.messages,s,[i]):[...e.messages,l];return{...e,messages:u,toolIndex:{...e.toolIndex,[o]:s}}}if(t.type==="checkpoint"){const o=t.checkpointNs??e.lastCheckpointNs??null,s=ng(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??Xs(e.messages),s={type:"interrupt",value:t.value};if(o)return{...e,assemblingId:null,messages:Js(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 Ys(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 Zm(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Xs(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Qm(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 Js(e,t,n){return Qm(e,t,r=>({...r,content:eg(r.content,n)}))}function eg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){const i=o,a=i.text??"";if(!a){i.text=s;continue}if(s.startsWith(a)){i.text=s;continue}if(a.startsWith(s)){i.text=s;continue}const l=tg(a,s);l?i.text=a+l:s.length!==a.length&&(i.text=s)}else n.push({type:"text",text:s})}else n.push(r);return n}function tg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let r=n;r>0;r--)if(e.slice(-r)===t.slice(0,r))return t.slice(r);return t}function ng(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 Zm(e,r,s)}return e}function rg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Ol(e={}){const t=S.useMemo(()=>fn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=S.useState(e.token??null),s=S.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=S.useState(!1),[u,d]=S.useState(null),[f,h]=S.useState(""),[p,w]=S.useState(null),[v,g]=S.useState(0),[x,b]=S.useState(!1),y=S.useRef(null),E=S.useRef(!0),C=S.useRef(0),T=S.useCallback(j=>{o(j)},[]),I=S.useCallback(()=>{var j;(j=y.current)==null||j.abort(),y.current=null,l(!1),b(!1),C.current=0,g(0)},[]),A=S.useCallback(()=>{h(""),w(null),d(null)},[]),R=S.useCallback((j,M,D)=>{y.current&&(y.current.abort(),y.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const L=new AbortController;return y.current=L,(async()=>{var W,H,q,F,N,U,Y,fe;const P=ie=>{var he;try{const Ee=JSON.parse(JSON.stringify(ie));return(he=Ee==null?void 0:Ee.payload)!=null&&he.files_info&&Array.isArray(Ee.payload.files_info)&&(Ee.payload.files_info=Ee.payload.files_info.map(de=>({...de,data:de!=null&&de.data?`<base64 ${String(de.data).length} chars>`:de==null?void 0:de.data}))),Ee}catch{return ie}};try{let ie={};try{if(r)ie={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Pe=window.__AUTH_TOKEN__,Je=((W=window.localStorage)==null?void 0:W.getItem("authToken"))||null;let $e=null;try{const lt=(H=window.localStorage)==null?void 0:H.getItem("chat-settings");lt&&($e=((q=JSON.parse(lt))==null?void 0:q.apiKey)||null)}catch{}const st=Pe||Je||$e||null;st&&(ie={Authorization:`Bearer ${st}`})}}catch{}console.debug("[use-chat] POST",t+n,P(j));const he=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...ie,...s.current},body:JSON.stringify(j),signal:L.signal,credentials:i});if(!he.ok||!he.body){const ye=await he.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",he.status,ye==null?void 0:ye.slice(0,500)),new Error(`stream ${he.status}${ye?": "+ye:""}`)}b(!0);const Ee=he.body.getReader(),de=new TextDecoder;let z="",O=[];C.current=0,g(0);let K=0,J=null;const ae=()=>{if(O.length){const ye=O.join("");O=[],E.current&&h(Pe=>Pe+ye)}J=null},re=()=>{typeof window<"u"&&J==null&&(J=requestAnimationFrame(ae))};let Fe=Date.now();const Xe=setInterval(()=>{var ye;if(Date.now()-Fe>6e4){const Pe="Stream idle timeout";d(Pe),L.abort(),(ye=D==null?void 0:D.onError)==null||ye.call(D,Pe)}},5e3),et=1024*1024;try{const ye=he.headers.get("X-Thread-Id")||he.headers.get("x-thread-id"),Pe=he.headers.get("X-Thread-Created")||he.headers.get("x-thread-created"),Je=ye??null,$e=String(Pe??"").toLowerCase()==="true";for((F=D==null?void 0:D.onOpen)==null||F.call(D,{threadId:Je,created:$e});;){const{value:st,done:lt}=await Ee.read();if(lt)break;z+=de.decode(st,{stream:!0}),z.length>et&&(z="",console.warn("Stream buffer reset: exceeded 1MB"));let Z;for(;(Z=z.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const le=z.slice(0,Z);z=z.slice(Z+2);const
|
|
38
|
-
`)}function ig({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=S.useRef(null),i=S.useCallback(p=>{const w=p.seq??null;if(w!==null){const v=s.current;if(v!==null){if(w<=v)return;w>v+1&&(o==null||o({from:v,to:w}))}s.current=w}if(p.type==="thread_info"){t(p);return}if(Ym(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Ol({baseUrl:e,token:null}),h=S.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:v=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,v)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return S.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Ml=S.createContext(null),Dl=S.createContext(null),Ll=S.createContext(null),ag=S.createContext(!1),lg=20;function cg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=Gs(),d=S.useMemo(()=>fn(u),[u]),[f,h]=S.useState([]),[p,w]=S.useState(t),[v,g]=S.useState(!1),[x,b]=S.useState(!1),[y,E]=S.useState(!1),[C,T]=S.useState(!1),[I,A]=S.useState(null),[R,j]=S.useState(void 0),[M,D]=S.useState(void 0),{state:L,seed:P,prepend:W,pushUser:H,onEvent:q,reset:F}=Rl(),N=S.useRef(p);S.useEffect(()=>{N.current=p},[p]);const U=S.useRef(!1),Y=S.useRef([]),fe=S.useRef(null),ie=S.useRef(null),he=S.useRef(!1),Ee=S.useCallback((G,ce)=>new Promise((Ie,Ve)=>{const qe=async()=>{U.current=!0;try{await G(),Ie()}catch(It){Ve(It)}finally{U.current=!1;const It=Y.current.shift();It&&It().catch(()=>{})}};U.current?Y.current.push(qe):qe().catch(It=>{Ve(It)})}),[]),de=S.useCallback(async()=>{g(!0);try{const G=await l.listThreads();h(G)}catch(G){i==null||i(String(G)),console.error("[ChatSessionProvider] Failed to refresh threads:",G)}finally{g(!1)}},[l,i]),z=S.useCallback(async()=>{if(he.current){he.current=!1;try{await de()}catch(G){console.error("[ChatSessionProvider] Failed to refresh threads after stream:",G)}}},[de]),O=S.useRef(!1),V=S.useCallback(()=>{he.current=!0,O.current||z()},[z]),J=S.useCallback((G,ce)=>{const Ie=Array.isArray(G==null?void 0:G.messages)?G.messages:[];ce==="replace"?P(Ie,{checkpointId:(G==null?void 0:G.checkpointId)??null,checkpointNs:(G==null?void 0:G.checkpointNs)??null}):ce==="prepend"&&Ie.length&&W(Ie),A((G==null?void 0:G.nextCursor)??null),E(!!(G!=null&&G.hasMore)),j(Ve=>(G==null?void 0:G.checkpointId)??Ve??void 0),D(Ve=>(G==null?void 0:G.checkpointNs)??Ve??void 0)},[W,P]),ae=S.useCallback(()=>{F([]),E(!1),T(!1),A(null),j(void 0),D(void 0)},[F]),oe=S.useCallback(({from:G,to:ce})=>{const Ie=N.current;Ie&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${G} -> ${ce}) for thread ${Ie}`)},[]),Fe=S.useCallback(G=>{const ce=G.threadId,Ie=!!G.created,Ve=!!G.ready;if(N.current!==ce){!N.current&&L.messages.length<=1&&(ie.current=ce),w(ce),(Ve||Ie)&&V();return}(Ve||Ie)&&V()},[V,L.messages.length]),{startStream:Xe,stop:et,isStreaming:ye,error:Pe,setAuthToken:Je}=ig({baseUrl:d,onThreadInfo:Fe,onMessageEvent:q,onUnhandledEvent:G=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${G.type}`,G)},onSequenceGap:oe});S.useEffect(()=>{O.current=ye,ye||z()},[z,ye]),S.useEffect(()=>{var Ie;const G=l.getAuthToken();Je(G);const ce=(Ie=l.onTokenChange)==null?void 0:Ie.call(l,Ve=>{Je(Ve)});return()=>{ce==null||ce()}},[l,Je]);const $e=S.useCallback(async G=>{const ce=await l.createThread(G),Ie=typeof ce=="string"?ce:ce.threadId;return await de(),w(Ie),Ie},[l,de]),st=S.useCallback(async G=>{await l.deleteThread(G),N.current===G&&(ie.current=G,w(null),ae()),await de()},[l,ae,de]),lt=S.useCallback(async(G,ce)=>{try{await l.updateThread(G,ce),h(Ie=>Ie.map(Ve=>Ve.threadId===G?{...Ve,title:ce}:Ve))}catch(Ie){throw await de(),Ie}},[l,de]),Z=S.useCallback(async(G,ce,Ie,Ve=!1)=>{await Ee(async()=>{if(ie.current===G&&!Ve){ie.current=null;return}if(!(fe.current===G&&!Ve)){w(qe=>qe===G?qe:G),fe.current=G,b(!0);try{const qe=await l.getMessages({threadId:G,checkpointId:ce,checkpointNs:Ie});he.current=!1,J(qe,"replace"),j((qe==null?void 0:qe.checkpointId)??void 0),D((qe==null?void 0:qe.checkpointNs)??void 0)}catch(qe){throw i==null||i(String(qe)),qe}finally{fe.current=null,b(!1)}}},`loadThread-${G}`)},[l,J,Ee,i]),le=S.useCallback(async()=>{await Ee(async()=>{N.current&&(ie.current=N.current),he.current=!1,w(null),ae(),j(void 0),D(void 0);try{localStorage.removeItem("lastThreadId")}catch(G){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",G)}},"clearCurrentThread")},[ae,Ee]),xe=S.useCallback(async G=>{const ce=await l.listCheckpoints(G);return Km(ce,G)},[l]),Ce=S.useCallback(async(G,ce)=>{if(!N.current)throw new Error("No active thread");await Z(N.current,G,ce??void 0,!0)},[Z]),we=S.useCallback(async()=>{if(!N.current)throw new Error("No active thread");await Z(N.current,void 0,void 0,!0)},[Z]),je=S.useCallback(async G=>{if(!N.current)throw new Error("No active thread");if(C||!y)return;const ce=I;if(ce){T(!0);try{const Ie=await l.getMessages({threadId:N.current,checkpointId:R,checkpointNs:M,limit:(G==null?void 0:G.limit)??lg,beforeId:ce});J(Ie,"prepend")}finally{T(!1)}}},[l,J,y,R,M,I,C]),Ze=S.useCallback(async(G,ce)=>{var er;const Ie=N.current;!Ie&&!(ce!=null&&ce.payloadExtras)&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const Ve=(ce==null?void 0:ce.attachments)||[],{contentParts:qe,filesInfo:It}=await Gm(l,Ve),Rn=[...qe];G&&G.trim()&&Rn.push({type:"text",text:G.trim()});const Jt={id:((er=crypto.randomUUID)==null?void 0:er.call(crypto))||`user-${Date.now()}`,role:"user",content:Rn,createdAt:new Date().toISOString(),checkpointId:(ce==null?void 0:ce.checkpointId)??L.lastCheckpointId??void 0,checkpointNs:(ce==null?void 0:ce.checkpointNs)??L.lastCheckpointNs??void 0};H(Jt);const Zn={...Jt,content:Rn},Qn={...(ce==null?void 0:ce.payloadExtras)??{}},wr=Ve.length>0,Qr={...Ie?{threadId:Ie}:{},payload:{messages:[Zn],files_info:It,...o&&wr&&s?{active_agent:s}:{},...Qn},checkpointId:(ce==null?void 0:ce.checkpointId)??L.lastCheckpointId??void 0,checkpointNs:(ce==null?void 0:ce.checkpointNs)??L.lastCheckpointNs??void 0,nodeFilter:ce==null?void 0:ce.nodeFilter,config:ce==null?void 0:ce.config};V(),Xe(Qr,{onError:gn=>{console.warn("[ChatSessionProvider] Stream error:",gn)},onOpen:({threadId:gn,created:ne})=>{if(!N.current&&gn){const pe=L.messages.length<=1;pe&&(ie.current=gn),w(gn),(ne||pe)&&V()}},onGap:oe})},[l,o,s,oe,V,L.lastCheckpointId,L.lastCheckpointNs,L.messages.length,H,Xe]),Ue=S.useCallback(async(G,ce,Ie)=>{const Ve=N.current;if(!Ve)throw new Error("No active thread to handle interrupt");try{const qe=ce?Ie??!0:!1;await l.resume({threadId:Ve,value:qe})}catch(qe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${G}:`,qe),qe}},[l]);S.useEffect(()=>{if(a==null||a(p),p)try{localStorage.setItem("lastThreadId",p)}catch(G){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",G)}},[p,a]),S.useEffect(()=>{let G=!0;return(async()=>{try{if(await de(),!G)return;if(!r&&!t)try{const Ie=localStorage.getItem("lastThreadId");Ie&&(w(Ie),n&&await Z(Ie))}catch(Ie){console.warn("[ChatSessionProvider] Failed to restore last thread:",Ie)}else t&&n&&await Z(t)}catch(Ie){console.error("[ChatSessionProvider] Initialization failed:",Ie),i==null||i(String(Ie))}})(),()=>{G=!1}},[]);const ct=S.useMemo(()=>({threads:f,currentThreadId:p,isLoadingThreads:v,isLoadingThread:x,setCurrentThreadId:w,createThread:$e,deleteThread:st,renameThread:lt,refreshThreads:de,loadThread:Z,clearCurrentThread:le,listCheckpoints:xe,navigateToCheckpoint:Ce,returnToLatest:we}),[le,$e,p,st,x,v,xe,Z,Ce,de,lt,we,f]),Et=S.useMemo(()=>({messages:L.messages,assemblingId:L.assemblingId,lastUserMessage:null,hasMoreHistory:y,isLoadingHistory:C,send:Ze,stop:et,loadOlderMessages:je,clearMessages:ae,handleInterrupt:Ue}),[ae,Ue,y,C,je,L.assemblingId,L.messages,Ze,et]),_n=S.useMemo(()=>({isStreaming:ye,error:Pe,streamingAssistantId:L.assemblingId,lastCheckpointId:L.lastCheckpointId??null,lastCheckpointNs:L.lastCheckpointNs??null}),[ye,L.assemblingId,L.lastCheckpointId,L.lastCheckpointNs,Pe]);return c.jsx(ag.Provider,{value:!0,children:c.jsx(Ll.Provider,{value:_n,children:c.jsx(Ml.Provider,{value:ct,children:c.jsx(Dl.Provider,{value:Et,children:e})})})})}function mo(){const e=S.useContext(Ml);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Zs(){const e=S.useContext(Dl);if(!e)throw new Error("useMessages must be used within ChatSessionProvider");return e}function Fl(){const e=S.useContext(Ll);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function go({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Vm,{apiConfig:t,children:c.jsx(cg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function X(...e){return bp.twMerge(wp.clsx(e))}const ug=to.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"}}),Be=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Pn.Slot:"button";return c.jsx(i,{className:X(ug({variant:t,size:n,className:e})),ref:s,...o})});Be.displayName="Button";const $l=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:X("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}));$l.displayName="Textarea";function dg({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=S.useState(e),[w,v]=S.useTransition(),g=S.useRef(null);S.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=S.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);S.useEffect(()=>{x()},[x]);const b=S.useCallback(async A=>{A&&A.preventDefault();const R=(h??"").trim();!R&&!f||v(()=>{try{const j=i(R);j&&typeof j.then=="function"?j.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),y=S.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=S.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx($l,{ref:g,value:h,onChange:y,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Be,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(Q.Square,{size:16})}):c.jsx(Be,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(Q.Send,{size:16})})})]})})}const fg=S.memo(dg),xo=0,wn=1,sr=2,zl=4;function Bl(e){return()=>e}function hg(e){e()}function Hl(e,t){return n=>e(t(n))}function Ul(e,t){return()=>e(t)}function pg(e,t){return n=>e(t,n)}function Qs(e){return e!==void 0}function mg(...e){return()=>{e.map(hg)}}function ir(){}function vo(e,t){return t(e),e}function gg(e,t){return t(e)}function tt(...e){return e}function We(e,t){return e(wn,t)}function _e(e,t){e(xo,t)}function ei(e){e(sr)}function at(e){return e(zl)}function ue(e,t){return We(e,pg(t,xo))}function Vt(e,t){const n=e(wn,r=>{n(),t(r)});return n}function Wl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Vl(e,t){return e===t}function nt(e=Vl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function be(e){return t=>n=>{e(n)&&t(n)}}function te(e){return t=>Hl(t,e)}function Qt(e){return t=>()=>{t(e)}}function $(e,...t){const n=xg(...t);return(r,o)=>{switch(r){case sr:ei(e);return;case wn:return We(e,n(o))}}}function en(e,t){return n=>r=>{n(t=e(t,r))}}function Ln(e){return t=>n=>{e>0?e--:t(n)}}function hn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Re(...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);We(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function xg(...e){return t=>e.reduceRight(gg,t)}function vg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case wn:return s?n===s?void 0:(r(),n=s,t=We(e,s),t):(r(),ir);case sr:r(),n=null;return}}}function K(e){let t=e;const n=De();return(r,o)=>{switch(r){case xo:t=o;break;case wn:{o(t);break}case zl:return t}return n(r,o)}}function xt(e,t){return vo(K(t),n=>ue(e,n))}function De(){const e=[];return(t,n)=>{switch(t){case xo:e.slice().forEach(r=>{r(n)});return;case sr:e.splice(0,e.length);return;case wn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function _t(e){return vo(De(),t=>ue(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:wg(),singleton:n}}const wg=()=>Symbol();function bg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function dt(...e){const t=De(),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);We(s,l=>{n[i]=l,r=r|a,r===o&&_e(t,n)})}),function(s,i){switch(s){case sr:{ei(t);return}case wn:return r===o&&i(n),We(t,i)}}}function ve(e,t=Vl){return $(e,nt(t))}function ti(...e){return function(t,n){switch(t){case sr:return;case wn:return mg(...e.map(r=>We(r,n)))}}}var kt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(kt||{});const yg={0:"debug",3:"error",1:"log",2:"warn"},Sg=()=>typeof globalThis>"u"?window:globalThis,bn=He(()=>{const e=K(3);return{log:K((t,n,r=1)=>{var o;const s=(o=Sg().VIRTUOSO_LOG_LEVEL)!=null?o:at(e);r>=s&&console[yg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Fn(e,t,n){return ni(e,t,n).callbackRef}function ni(e,t,n){const r=S.useRef(null);let o=i=>{};const s=S.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Cg(e,t,n,r,o,s,i,a,l){const u=S.useCallback(d=>{const f=Tg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?Kl("column-gap",getComputedStyle(d).columnGap,o):Kl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ni(u,n,l)}function Tg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},kt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Kl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function ql(e,t,n){const r=S.useRef(null),o=S.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ni(o,!0,n),a=S.useCallback(()=>{o(i.current)},[o,i]);return S.useEffect(()=>{var l;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=(l=i.current)==null?void 0:l.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 bt=He(()=>{const e=De(),t=De(),n=K(0),r=De(),o=K(0),s=De(),i=De(),a=K(0),l=K(0),u=K(0),d=K(0),f=De(),h=De(),p=K(!1),w=K(!1),v=K(!1);return ue($(e,te(({scrollTop:g})=>g)),t),ue($(e,te(({scrollHeight:g})=>g)),i),ue(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Nr={lvl:0};function Gl(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function Ge(e){return e===Nr}function Ar(e,t){if(!Ge(e))return t===e.k?e.v:t<e.k?Ar(e.l,t):Ar(e.r,t)}function Kt(e,t,n="k"){if(Ge(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Kt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Kt(e.l,t,n)}function Rt(e,t,n){return Ge(e)?Jl(t,n,1):t===e.k?ht(e,{k:t,v:n}):t<e.k?Zl(ht(e,{l:Rt(e.l,t,n)})):Zl(ht(e,{r:Rt(e.r,t,n)}))}function ar(){return Nr}function wo(e,t,n){if(Ge(e))return[];const r=Kt(e,t)[0];return kg(oi(e,r,n))}function ri(e,t){if(Ge(e))return Nr;const{k:n,l:r,r:o}=e;if(t===n){if(Ge(r))return o;if(Ge(o))return r;{const[s,i]=Xl(r);return bo(ht(e,{k:s,l:Yl(r),v:i}))}}else return t<n?bo(ht(e,{l:ri(r,t)})):bo(ht(e,{r:ri(o,t)}))}function $n(e){return Ge(e)?[]:[...$n(e.l),{k:e.k,v:e.v},...$n(e.r)]}function oi(e,t,n){if(Ge(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oi(s,t,n))),a}function bo(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(si(t))return Ql(ht(e,{lvl:n-1}));if(!Ge(t)&&!Ge(t.r))return ht(t.r,{l:ht(t,{r:t.r.l}),lvl:n,r:ht(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(si(e))return ii(ht(e,{lvl:n-1}));if(!Ge(r)&&!Ge(r.l)){const o=r.l,s=si(o)?r.lvl-1:r.lvl;return ht(o,{l:ht(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ii(ht(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function ht(e,t){return Jl(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 Yl(e){return Ge(e.r)?e.l:bo(ht(e,{r:Yl(e.r)}))}function si(e){return Ge(e)||e.lvl>e.r.lvl}function Xl(e){return Ge(e.r)?[e.k,e.v]:Xl(e.r)}function Jl(e,t,n,r=Nr,o=Nr){return{k:e,l:r,lvl:n,r:o,v:t}}function Zl(e){return ii(Ql(e))}function Ql(e){const{l:t}=e;return!Ge(t)&&t.lvl===e.lvl?ht(t,{r:ht(e,{l:t.r})}):e}function ii(e){const{lvl:t,r:n}=e;return!Ge(n)&&!Ge(n.r)&&n.lvl===t&&n.r.lvl===t?ht(n,{l:ht(e,{r:n.l}),lvl:t+1}):e}function kg(e){return Gl(e,({k:t,v:n})=>({index:t,value:n}))}function ec(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function jr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ai=He(()=>({recalcInProgress:K(!1)}),[],{singleton:!0});function tc(e,t,n){return e[yo(e,t,n)]}function yo(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 Eg(e,t,n,r){const o=yo(e,t,r),s=yo(e,n,r,o);return e.slice(o,s+1)}function yn(e,t){return Math.round(e.getBoundingClientRect()[t])}function So(e){return!Ge(e.groupOffsetTree)}function li({index:e},t){return t===e?0:t<e?-1:1}function Ig(){return{groupIndices:[],groupOffsetTree:ar(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ar()}}function Ng(e,t){let n=Ge(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ge(e)){e=Rt(e,0,s);continue}const a=wo(e,i-1,o+1);if(a.some(Mg(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ri(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Rt(e,o+1,h));u&&(e=Rt(e,i,s))}return[e,n]}function Ag(e){return typeof e.groupIndex<"u"}function jg({offset:e},t){return t===e?0:t<e?-1:1}function _r(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=tc(t,e,li),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function nc(e,t){if(!So(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function rc(e,t,n){if(Ag(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=nc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function _g(e,t,n,r=0){return r>0&&(t=Math.max(t,tc(e,r,li).offset)),Gl(Eg(e,t,n,jg),Og)}function Rg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,kt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ge(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,v)=>Rt(Rt(w,v,h),v+1,p),i)}else[i,a]=Ng(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=ci(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Rt(h,p,_r(p,f,o)),ar()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Pg(e){return $n(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function oc(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 ci(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=yo(o,t-1,li),a=o[l].offset;const u=Kt(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===Kt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of wo(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 Og(e){return{index:e.index,value:e}}function Mg(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 Dg={offsetHeight:"height",offsetWidth:"width"},tn=He(([{log:e},{recalcInProgress:t}])=>{const n=De(),r=De(),o=xt(r,0),s=De(),i=De(),a=K(0),l=K([]),u=K(void 0),d=K(void 0),f=K((C,T)=>yn(C,Dg[T])),h=K(void 0),p=K(0),w=Ig(),v=xt($(n,Re(l,e,p),en(Rg,w),nt()),w),g=xt($(l,nt(),en((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),te(({prev:C})=>C)),[]);ue($(l,be(C=>C.length>0),Re(v,p),te(([C,T,I])=>{const A=C.reduce((R,j,M)=>Rt(R,j,_r(j,T.offsetTree,I)||M),ar());return{...T,groupIndices:C,groupOffsetTree:A}})),v),ue($(r,Re(v),be(([C,{lastIndex:T}])=>C<T),te(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),ue(u,d);const x=xt($(u,te(C=>C===void 0)),!0);ue($(d,be(C=>C!==void 0&&Ge(at(v).sizeTree)),te(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=_t($(n,Re(v),en(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),te(C=>C.changed)));We($(a,en((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),te(C=>C.diff)),C=>{const{groupIndices:T}=at(v);if(C>0)_e(t,!0),_e(s,C+oc(C,T));else if(C<0){const I=at(g);I.length>0&&(C-=oc(-C,I)),_e(i,C)}}),We($(a,Re(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},kt.ERROR)});const y=_t(s);ue($(s,Re(v),te(([C,T])=>{const I=T.groupIndices.length>0,A=[],R=T.lastSize;if(I){const j=Ar(T.sizeTree,0);let M=0,D=0;for(;M<C;){const P=T.groupIndices[D],W=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-P-1;A.push({endIndex:P,size:j,startIndex:P}),A.push({endIndex:P+1+W-1,size:R,startIndex:P+1}),D++,M+=W+1}const L=$n(T.sizeTree);return M!==C&&L.shift(),L.reduce((P,{k:W,v:H})=>{let q=P.ranges;return P.prevSize!==0&&(q=[...P.ranges,{endIndex:W+C-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:W+C,prevSize:H,ranges:q}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return $n(T.sizeTree).reduce((j,{k:M,v:D})=>({prevIndex:M+C,prevSize:D,ranges:[...j.ranges,{endIndex:M+C-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const E=_t($(i,Re(v,p),te(([C,{offsetTree:T},I])=>{const A=-C;return _r(A,T,I)})));return ue($(i,Re(v,p),te(([C,T,I])=>{if(T.groupIndices.length>0){if(Ge(T.sizeTree))return T;let A=ar();const R=at(g);let j=0,M=0,D=0;for(;j<-C;){D=R[M];const L=R[M+1]-D-1;M++,j+=L+1}if(A=$n(T.sizeTree).reduce((L,{k:P,v:W})=>Rt(L,Math.max(0,P+C),W),A),j!==-C){const L=Ar(T.sizeTree,D);A=Rt(A,0,L);const P=Kt(T.sizeTree,-C+1)[1];A=Rt(A,1,P)}return{...T,sizeTree:A,...ci(T.offsetTree,0,A,I)}}else{const A=$n(T.sizeTree).reduce((R,{k:j,v:M})=>Rt(R,Math.max(0,j+C),M),ar());return{...T,sizeTree:A,...ci(T.offsetTree,0,A,I)}}})),v),{beforeUnshiftWith:y,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},tt(bn,ai),{singleton:!0});function Lg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const sc=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=De(),i=De(),a=_t($(s,te(Lg)));return ue($(a,te(l=>l.totalCount)),n),ue($(a,te(l=>l.groupIndices)),e),ue($(dt(o,t,r),be(([l,u])=>So(u)),te(([l,u,d])=>Kt(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),nt(),te(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},tt(tn,bt)),Sn=He(([{log:e}])=>{const t=K(!1),n=_t($(t,be(r=>r),nt()));return We(t,r=>{r&&at(e)("props updated",{},kt.DEBUG)}),{didMount:n,propsReady:t}},tt(bn),{singleton:!0}),Fg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function ic(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Fg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Rr=He(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=De(),w=De(),v=K(0);let g=null,x=null,b=null;function y(){g&&(g(),g=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),_e(l,!1)}return ue($(p,Re(n,f,r,v,a,i,h),Re(e,s,o),te(([[E,C,T,I,A,R,j,M],D,L,P])=>{const W=ic(E),{align:H,behavior:q,offset:F}=W,N=I-1,U=rc(W,C,N);let Y=_r(U,C.offsetTree,D)+R;H==="end"?(Y+=L+Kt(C.sizeTree,U)[1]-T+P,U===N&&(Y+=j)):H==="center"?Y+=(L+Kt(C.sizeTree,U)[1]-T+P)/2:Y-=A,F&&(Y+=F);const fe=ie=>{y(),ie?(M("retrying to scroll to",{location:E},kt.DEBUG),_e(p,E)):(_e(w,!0),M("list did not change, scroll successful",{},kt.DEBUG))};if(y(),q==="smooth"){let ie=!1;b=We(t,he=>{ie=ie||he}),g=Vt(d,()=>{fe(ie)})}else g=Vt($(t,$g(150)),fe);return x=setTimeout(()=>{y()},1200),_e(l,!0),M("scrolling from index to",{behavior:q,index:U,top:Y},kt.DEBUG),{behavior:q,top:Y}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:v}},tt(tn,bt,bn),{singleton:!0});function $g(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ui(e,t){e==0?t():requestAnimationFrame(()=>{ui(e-1,t)})}function di(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Pr=He(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=K(!0),l=K(0),u=K(!0);return ue($(i,Re(l),be(([d,f])=>!!f),Qt(!1)),a),ue($(i,Re(l),be(([d,f])=>!!f),Qt(!1)),u),We($(dt(t,i),Re(a,n,e,u),be(([[,d],f,{sizeTree:h},p,w])=>d&&(!Ge(h)||Qs(p))&&!f&&!w),Re(l)),([,d])=>{Vt(o,()=>{_e(u,!0)}),ui(4,()=>{Vt(r,()=>{_e(a,!0)}),_e(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},tt(tn,bt,Rr,Sn),{singleton:!0});function ac(e,t){return Math.abs(e-t)<1.01}const Or="up",Mr="down",zg="none",Bg={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Hg=0,Dr=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=K(!1),a=K(!0),l=De(),u=De(),d=K(4),f=K(Hg),h=xt($(ti($(ve(o),Ln(1),Qt(!0)),$(ve(o),Ln(1),Qt(!1),Wl(100))),nt()),!1),p=xt($(ti($(n,Qt(!0)),$(n,Qt(!1),Wl(200))),nt()),!1);ue($(dt(ve(o),ve(f)),te(([b,y])=>b<=y),nt()),a),ue($(a,hn(50)),u);const w=_t($(dt(r,ve(s),ve(t),ve(e),ve(d)),en((b,[{scrollHeight:y,scrollTop:E},C,T,I,A])=>{const R=E+C-y>-A,j={scrollHeight:y,scrollTop:E,viewportHeight:C};if(R){let D,L;return E>b.state.scrollTop?(D="SCROLLED_DOWN",L=b.state.scrollTop-E):(D="SIZE_DECREASED",L=b.state.scrollTop-E||b.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:L,state:j}}let M;return j.scrollHeight>b.state.scrollHeight?M="SIZE_INCREASED":C<b.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":E<b.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:j}},Bg),nt((b,y)=>b&&b.atBottom===y.atBottom))),v=xt($(r,en((b,{scrollHeight:y,scrollTop:E,viewportHeight:C})=>{if(ac(b.scrollHeight,y))return{changed:!1,jump:0,scrollHeight:y,scrollTop:E};{const T=y-(E+C)<1;return b.scrollTop!==E&&T?{changed:!0,jump:b.scrollTop-E,scrollHeight:y,scrollTop:E}:{changed:!0,jump:0,scrollHeight:y,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),be(b=>b.changed),te(b=>b.jump)),0);ue($(w,te(b=>b.atBottom)),i),ue($(i,hn(50)),l);const g=K(Mr);ue($(r,te(({scrollTop:b})=>b),nt(),en((b,y)=>at(p)?{direction:b.direction,prevScrollTop:y}:{direction:y<b.prevScrollTop?Or:Mr,prevScrollTop:y},{direction:Mr,prevScrollTop:0}),te(b=>b.direction)),g),ue($(r,hn(50),Qt(zg)),g);const x=K(0);return ue($(h,be(b=>!b),Qt(0)),x),ue($(o,hn(100),Re(h),be(([b,y])=>!!y),en(([b,y],[E])=>[y,E],[0,0]),te(([b,y])=>y-b)),x),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},tt(bt)),Co="top",To="bottom",lc="none";function cc(e,t,n){return typeof e=="number"?n===Or&&t===Co||n===Mr&&t===To?e:0:n===Or?t===Co?e.main:e.reverse:t===To?e.main:e.reverse}function uc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fi=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=De(),i=K(0),a=K(0),l=K(0),u=xt($(dt(ve(r),ve(o),ve(n),ve(s,jr),ve(l),ve(i),ve(t),ve(e),ve(a)),te(([d,f,h,[p,w],v,g,x,b,y])=>{const E=d-b,C=g+x,T=Math.max(h-E,0);let I=lc;const A=uc(y,Co),R=uc(y,To);return p-=b,p+=h+x,w+=h+x,w-=b,p>d+C-A&&(I=Or),w<d-T+f+R&&(I=Mr),I!==lc?[Math.max(E-h-cc(v,Co,I)-A,0),E-T-x+f+cc(v,To,I)+R]:null}),be(d=>d!=null),nt(jr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},tt(bt),{singleton:!0});function Ug(e,t,n){if(So(t)){const r=nc(e,t);return[{index:Kt(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 hi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ko(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=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*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:fc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:fc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function dc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ko(u,[],a,o,n,r)}function fc(e,t,n){if(e.length===0)return[];if(!So(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=wo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const zn=He(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const v=K([]),g=K(0),x=De();ue(s.topItemsIndexes,v);const b=xt($(dt(p,w,ve(l,jr),ve(o),ve(r),ve(u),d,ve(v),ve(t),ve(n),e),be(([T,I,,A,,,,,,,R])=>{const j=R&&R.length!==A;return T&&!I&&!j}),te(([,,[T,I],A,R,j,M,D,L,P,W])=>{const H=R,{offsetTree:q,sizeTree:F}=H,N=at(g);if(A===0)return{...hi,totalCount:A};if(T===0&&I===0)return N===0?{...hi,totalCount:A}:dc(N,j,R,L,P,W||[]);if(Ge(F))return N>0?null:ko(Ug(di(j,A),H,W),[],A,P,H,L);const U=[];if(D.length>0){const Ee=D[0],de=D[D.length-1];let z=0;for(const O of wo(F,Ee,de)){const V=O.value,J=Math.max(O.start,Ee),ae=Math.min(O.end,de);for(let oe=J;oe<=ae;oe++)U.push({data:W==null?void 0:W[oe],index:oe,offset:z,size:V}),z+=V}}if(!M)return ko([],U,A,P,H,L);const Y=D.length>0?D[D.length-1]+1:0,fe=_g(q,T,I,Y);if(fe.length===0)return null;const ie=A-1,he=vo([],Ee=>{for(const de of fe){const z=de.value;let O=z.offset,V=de.start;const J=z.size;if(z.offset<T){V+=Math.floor((T-z.offset+P)/(J+P));const oe=V-de.start;O+=oe*J+oe*P}V<Y&&(O+=(Y-V)*J,V=Y);const ae=Math.min(de.end,ie);for(let oe=V;oe<=ae&&!(O>=I);oe++)Ee.push({data:W==null?void 0:W[oe],index:oe,offset:O,size:J}),O+=J+P}});return ko(he,U,A,P,H,L)}),be(T=>T!==null),nt()),hi);ue($(e,be(Qs),te(T=>T==null?void 0:T.length)),o),ue($(b,te(T=>T.topListHeight)),f),ue(f,a),ue($(b,te(T=>[T.top,T.bottom])),i),ue($(b,te(T=>T.items)),x);const y=_t($(b,be(({items:T})=>T.length>0),Re(o,e),be(([{items:T},I])=>T[T.length-1].originalIndex===I-1),te(([,T,I])=>[T-1,I]),nt(jr),te(([T])=>T))),E=_t($(b,hn(200),be(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),te(({items:T})=>T[0].index),nt())),C=_t($(b,be(({items:T})=>T.length>0),te(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),nt(ec)));return{endReached:y,initialItemCount:g,itemsRendered:x,listState:b,rangeChanged:C,startReached:E,topItemsIndexes:v,...h}},tt(tn,sc,fi,Pr,Rr,Dr,Sn,ai),{singleton:!0}),hc=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=De(),i=xt($(dt(n,e,r,t,o),te(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ue(ve(i),s),{totalListHeight:i,totalListHeightChanged:s}},tt(bt,zn),{singleton:!0}),Wg=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=K(!1),r=xt($(dt(n,e,t),be(([o])=>o),te(([,o,s])=>Math.max(0,o-s)),hn(0),nt()),0);return{alignToBottom:n,paddingTopAddition:r}},tt(bt,hc),{singleton:!0}),pc=He(()=>({context:K(null)})),Vg=({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,mc=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=De();return ue($(d,Re(t,l,n,s,o,r,a),Re(e),te(([[f,h,p,w,v,g,x,b],y])=>{const{align:E,behavior:C,calculateViewLocation:T=Vg,done:I,...A}=f,R=rc(f,h,w-1),j=_r(R,h.offsetTree,y)+v+g,M=j+Kt(h.sizeTree,R)[1],D=b+g,L=b+p-x,P=T({itemBottom:M,itemTop:j,locationParams:{align:E,behavior:C,...A},viewportBottom:L,viewportTop:D});return P?I&&Vt($(i,be(W=>!W),Ln(at(i)?1:2)),I):I&&I(),P}),be(f=>f!==null)),u),{scrollIntoView:d}},tt(tn,bt,Rr,zn,bn),{singleton:!0});function gc(e){return e?e==="smooth"?"smooth":"auto":!1}const Kg=(e,t)=>typeof e=="function"?gc(e(t)):t&&gc(e),qg=He(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=K(!1),v=De();let g=null;function x(C){_e(i,{align:"end",behavior:C,index:"LAST"})}We($(dt($(ve(t),Ln(1)),l),Re(ve(w),s,a,f),te(([[C,T],I,A,R,j])=>{let M=T&&R,D="auto";return M&&(D=Kg(I,A||j),M=M&&!!D),{followOutputBehavior:D,shouldFollow:M,totalCount:C}}),be(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("following output to ",{totalCount:T},kt.DEBUG),x(C)}):g=Vt(e,()=>{at(d)("following output to ",{totalCount:T},kt.DEBUG),x(C),g=null})});function b(C){const T=Vt(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(at(d)("scrolling to bottom due to increased size",{},kt.DEBUG),x("auto"))});setTimeout(T,100)}We($(dt(ve(w),t,u),be(([C,,T])=>C&&T),en(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),be(({refreshed:C})=>C),Re(w,t)),([,C])=>{at(a)&&b(C!==!1)}),We(v,()=>{b(at(w)!==!1)}),We(dt(ve(w),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const y=K(null),E=De();return ue(ti($(ve(r),te(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),$(ve(t))),E),We($(dt($(E,Ln(1)),l),Re(ve(y),a,f,h),te(([[C,T],I,A,R,j])=>T&&A&&(I==null?void 0:I({context:j,totalCount:C,scrollingInProgress:R}))),be(C=>!!C),hn(0)),C=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("scrolling into view",{}),_e(p,C)}):g=Vt(e,()=>{at(d)("scrolling into view",{}),_e(p,C),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:y}},tt(tn,Dr,Rr,Pr,Sn,bn,bt,pc,mc)),Gg=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ue($(a,Re(s),be(([,l])=>l!==0),Re(o,r,t,n,e),te(([[,l],u,d,f,h,p=[]])=>dc(l,u,d,f,h,p))),i),{}),tt(tn,Pr,zn,Sn),{singleton:!0}),Yg=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=K(0);return We($(e,Re(r),be(([,o])=>o!==0),te(([,o])=>({top:o}))),o=>{Vt($(n,Ln(1),be(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{_e(t,o)})})}),{initialScrollTop:r}},tt(Sn,bt,zn),{singleton:!0}),xc=He(([{scrollVelocity:e}])=>{const t=K(!1),n=De(),r=K(!1);return ue($(e,Re(r,t,n),be(([o,s])=>!!s),te(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),nt()),t),We($(dt(t,e,n),Re(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},tt(Dr),{singleton:!0}),pi=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=De(),r=De(),o=De(),s=K(!1),i=K(void 0);return ue($(dt(n,r),te(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ue($(t,Re(r),te(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},tt(bt)),Xg=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=De(),d=K(void 0),f=K(null),h=K(null);return ue(a,f),ue(l,h),We($(u,Re(t,r,i,f,h,n)),([p,w,v,g,x,b,y])=>{const E=Pg(w.sizeTree);g&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=y,p({ranges:E,scrollTop:v})}),ue($(d,be(Qs),te(Jg)),o),ue($(s,Re(d),be(([,p])=>p!==void 0),nt(),te(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},tt(tn,bt,Pr,Sn,pi));function Jg(e){return{align:"start",index:0,offset:e.scrollTop}}const Zg=He(([{topItemsIndexes:e}])=>{const t=K(0);return ue($(t,be(n=>n>=0),te(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},tt(zn));function vc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Qg=vc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),ex=He(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const v=_t($(l,Re(i),en(([,x,b,y],[{bottom:E,items:C,offsetBottom:T,totalCount:I},A])=>{const R=E+T;let j=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(j=R-y,j!==0&&(j+=A))),[j,C,I,R]},[0,[],0,0]),be(([x])=>x!==0),Re(r,a,n,o,p,w),be(([,x,b,y,,,E])=>!E&&!y&&x!==0&&b===Or),te(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},kt.DEBUG),x))));function g(x){x>0?(_e(t,{behavior:"auto",top:-x}),_e(e,0)):(_e(e,0),_e(t,{behavior:"auto",top:-x}))}return We($(v,Re(e,s)),([x,b,y])=>{y&&Qg()?_e(e,b-x):g(-x)}),We($(dt(xt(s,!1),e,w),be(([x,b,y])=>!x&&!y&&b!==0),te(([x,b])=>b),hn(1)),g),ue($(f,te(x=>({top:-x}))),t),We($(u,Re(h,d),te(([x,{groupIndices:b,lastSize:y,sizeTree:E},C])=>{function T(I){return I*(y+C)}if(b.length===0)return T(x);{let I=0;const A=Ar(E,0);let R=0,j=0;for(;R<x;){R++,I+=A;let M=b.length===j+1?1/0:b[j+1]-b[j]-1;R+M>x&&(I-=A,M=x-R+1),R+=M,I+=T(M),j++}return I}})),x=>{_e(e,x),requestAnimationFrame(()=>{_e(t,{top:x}),requestAnimationFrame(()=>{_e(e,0),_e(w,!1)})})}),{deviation:e}},tt(bt,Dr,zn,tn,bn,ai)),tx=He(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),tt(fi,Gg,Sn,xc,hc,Yg,Wg,pi,mc,bn,pc)),wc=He(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},v,g,x,{listState:b,topItemsIndexes:y,...E},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},R])=>(ue(E.rangeChanged,R.scrollSeekRangeChanged),ue($(R.windowViewportRect,te(j=>j.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:y,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...E,...R,...v,sizes:l,...g}),tt(tn,Pr,bt,Xg,qg,zn,Rr,ex,Zg,sc,tx));function nx(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 Eo=typeof document<"u"?S.useLayoutEffect:S.useEffect;function bc(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=S.createContext({});function l(g,x){g.propsReady&&_e(g.propsReady,!1);for(const b of r){const y=g[t.required[b]];_e(y,x[b])}for(const b of o)if(b in x){const y=g[t.optional[b]];_e(y,x[b])}g.propsReady&&_e(g.propsReady,!0)}function u(g){return s.reduce((x,b)=>(x[b]=y=>{const E=g[t.methods[b]];_e(E,y)},x),{})}function d(g){return i.reduce((x,b)=>(x[b]=vg(g[t.events[b]]),x),{})}const f=S.forwardRef((g,x)=>{const{children:b,...y}=g,[E]=S.useState(()=>vo(bg(e),I=>{l(I,y)})),[C]=S.useState(Ul(d,E));Eo(()=>{for(const I of i)I in y&&We(C[I],y[I]);return()=>{Object.values(C).map(ei)}},[y,C,E]),Eo(()=>{l(E,y)}),S.useImperativeHandle(x,Bl(u(E)));const T=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(T,{...nx([...r,...o,...i],y),children:b}):b})}),h=g=>{const x=S.useContext(a);return S.useCallback(b=>{_e(x[g],b)},[x,g])},p=g=>{const x=S.useContext(a)[g],b=S.useCallback(y=>We(x,y),[x]);return S.useSyncExternalStore(b,()=>at(x),()=>at(x))},w=g=>{const x=S.useContext(a)[g],[b,y]=S.useState(Ul(at,x));return Eo(()=>We(x,E=>{E!==b&&y(Bl(E))}),[x,b]),b},v=S.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,x)=>{const b=S.useContext(a)[g];Eo(()=>We(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const yc=S.createContext(void 0),Sc=S.createContext(void 0),Cc=typeof document<"u"?S.useLayoutEffect:S.useEffect;function mi(e){return"self"in e}function rx(e){return"body"in e}function Tc(e,t,n,r=ir,o,s){const i=S.useRef(null),a=S.useRef(null),l=S.useRef(null),u=S.useCallback(h=>{let p,w,v;const g=h.target;if(rx(g)||mi(g)){const b=mi(g)?g:g.defaultView;v=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Rs.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);S.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 p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;mi(p)?(g=Math.max(yn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),v=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],v=yn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=g-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),ac(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const gi="-webkit-sticky",kc="sticky",xi=vc(()=>{if(typeof document>"u")return kc;const e=document.createElement("div");return e.style.position=gi,e.style.position===gi?gi:kc});function vi(e){return e}const ox=He(()=>{const e=K(a=>`Item ${a}`),t=K(a=>`Group ${a}`),n=K({}),r=K(vi),o=K("div"),s=K(ir),i=(a,l=null)=>xt($(n,te(u=>u[a]),nt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),sx=He(([e,t])=>({...e,...t}),tt(wc,ox)),ix=({height:e})=>c.jsx("div",{style:{height:e}}),ax={overflowAnchor:"none",position:xi(),zIndex:1},Ec={overflowAnchor:"none"},lx={...Ec,display:"inline-block",height:"100%"},Ic=S.memo(function({showTopList:e=!1}){const t=Ne("listState"),n=Ft("sizeRanges"),r=Ne("useWindowScroll"),o=Ne("customScrollParent"),s=Ft("windowScrollContainerState"),i=Ft("scrollContainerState"),a=o||r?s:i,l=Ne("itemContent"),u=Ne("context"),d=Ne("groupContent"),f=Ne("trackItemSizes"),h=Ne("itemSize"),p=Ne("log"),w=Ft("gap"),v=Ne("horizontalDirection"),{callbackRef:g}=Cg(n,h,f,e?ir:a,p,w,o,v,Ne("skipAnimationFrameInResizeObserver")),[x,b]=S.useState(0);wi("deviation",P=>{x!==P&&b(P)});const y=Ne("EmptyPlaceholder"),E=Ne("ScrollSeekPlaceholder")||ix,C=Ne("ListComponent"),T=Ne("ItemComponent"),I=Ne("GroupComponent"),A=Ne("computeItemKey"),R=Ne("isSeeking"),j=Ne("groupIndices").length>0,M=Ne("alignToBottom"),D=Ne("initialItemFinalLocationReached"),L=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:M?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:M?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&y?c.jsx(y,{...vt(y,u)}):c.jsx(C,{...vt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:L,children:(e?t.topItems:t.items).map(P=>{const W=P.originalIndex,H=A(W+t.firstItemIndex,P.data,u);return R?S.createElement(E,{...vt(E,u),height:P.size,index:P.index,key:H,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?S.createElement(I,{...vt(I,u),"data-index":W,"data-item-index":P.index,"data-known-size":P.size,key:H,style:ax},d(P.index,u)):S.createElement(T,{...vt(T,u),...fx(T,P.data),"data-index":W,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:H,style:v?lx:Ec},j?l(P.index,P.groupIndex,P.data,u):l(P.index,P.data,u))})})}),cx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},ux={outline:"none",overflowX:"auto",position:"relative"},Io=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),dx={position:xi(),top:0,width:"100%",zIndex:1};function vt(e,t){if(typeof e!="string")return{context:t}}function fx(e,t){return{item:typeof e=="string"?void 0:t}}const hx=S.memo(function(){const e=Ne("HeaderComponent"),t=Ft("headerHeight"),n=Ne("HeaderFooterTag"),r=Fn(S.useMemo(()=>s=>{t(yn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),px=S.memo(function(){const e=Ne("FooterComponent"),t=Ft("footerHeight"),n=Ne("HeaderFooterTag"),r=Fn(S.useMemo(()=>s=>{t(yn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null});function Nc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=Tc(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?ux:cx,...o},tabIndex:0,...i,...vt(l,s),children:r})})}function Ac({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=S.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Tc(a,u,l,w,h);return Cc(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...vt(l,s),children:r})})}const mx=({children:e})=>{const t=S.useContext(yc),n=Ft("viewportHeight"),r=Ft("fixedItemHeight"),o=Ne("alignToBottom"),s=Ne("horizontalDirection"),i=S.useMemo(()=>Hl(n,l=>yn(l,s?"width":"height")),[n,s]),a=Fn(i,!0,Ne("skipAnimationFrameInResizeObserver"));return S.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Io(o),children:e})},gx=({children:e})=>{const t=S.useContext(yc),n=Ft("windowViewportRect"),r=Ft("fixedItemHeight"),o=Ne("customScrollParent"),s=ql(n,o,Ne("skipAnimationFrameInResizeObserver")),i=Ne("alignToBottom");return S.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Io(i),children:e})},xx=({children:e})=>{const t=Ne("TopItemListComponent")||"div",n=Ne("headerHeight"),r={...dx,marginTop:`${n}px`},o=Ne("context");return c.jsx(t,{style:r,...vt(t,o),children:e})},vx=S.memo(function(e){const t=Ne("useWindowScroll"),n=Ne("topItemsIndexes").length>0,r=Ne("customScrollParent"),o=Ne("context");return c.jsxs(r||t?yx:bx,{...e,context:o,children:[n&&c.jsx(xx,{children:c.jsx(Ic,{showTopList:!0})}),c.jsxs(r||t?gx:mx,{children:[c.jsx(hx,{}),c.jsx(Ic,{}),c.jsx(px,{})]})]})}),{Component:wx,useEmitter:wi,useEmitterValue:Ne,usePublisher:Ft}=bc(sx,{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"}},vx),bx=Nc({useEmitter:wi,useEmitterValue:Ne,usePublisher:Ft}),yx=Ac({useEmitter:wi,useEmitterValue:Ne,usePublisher:Ft}),Sx=wx;tt(wc,He(()=>{const e=K(u=>c.jsxs("td",{children:["Item $",u]})),t=K(null),n=K(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=K(null),o=K(null),s=K({}),i=K(vi),a=K(ir),l=(u,d=null)=>xt($(s,te(f=>f[u]),nt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),xi();const jc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Cx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:_c,floor:No,max:Lr,min:bi,round:Rc}=Math;function Pc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Tx(e){return{...Cx,items:e}}function Ao(e,t){return e&&e.width===t.width&&e.height===t.height}function kx(e,t){return e&&e.column===t.column&&e.row===t.row}const Ex=He(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:y,windowViewportRect:E},C])=>{const T=K(0),I=K(0),A=K(jc),R=K({height:0,width:0}),j=K({height:0,width:0}),M=De(),D=De(),L=K(0),P=K(null),W=K({column:0,row:0}),H=De(),q=De(),F=K(!1),N=K(0),U=K(!0),Y=K(!1),fe=K(!1);We($(w,Re(N),be(([O,V])=>!!V)),()=>{_e(U,!1)}),We($(dt(w,U,j,R,N,Y),be(([O,V,J,ae,,oe])=>O&&!V&&J.height!==0&&ae.height!==0&&!oe)),([,,,,O])=>{_e(Y,!0),ui(1,()=>{_e(M,O)}),Vt($(u),()=>{_e(t,[0,0]),_e(U,!0)})}),ue($(q,be(O=>O!=null&&O.scrollTop>0),Qt(0)),I),We($(w,Re(q),be(([,O])=>O!=null)),([,O])=>{O&&(_e(R,O.viewport),_e(j,O.item),_e(W,O.gap),O.scrollTop>0&&(_e(F,!0),Vt($(u,Ln(1)),V=>{_e(F,!1)}),_e(l,{top:O.scrollTop})))}),ue($(R,te(({height:O})=>O)),f),ue($(dt(ve(R,Ao),ve(j,Ao),ve(W,(O,V)=>O&&O.column===V.column&&O.row===V.row),ve(u)),te(([O,V,J,ae])=>({gap:J,item:V,scrollTop:ae,viewport:O}))),H),ue($(dt(ve(T),r,ve(W,kx),ve(j,Ao),ve(R,Ao),ve(P),ve(I),ve(F),ve(U),ve(N)),be(([,,,,,,,O])=>!O),te(([O,[V,J],ae,oe,Fe,Xe,et,,ye,Pe])=>{const{column:Je,row:$e}=ae,{height:st,width:lt}=oe,{width:Z}=Fe;if(et===0&&(O===0||Z===0))return jc;if(lt===0){const Et=di(Pe,O),_n=Et+Math.max(et-1,0);return Tx(Pc(Et,_n,Xe))}const le=Oc(Z,lt,Je);let xe,Ce;ye?V===0&&J===0&&et>0?(xe=0,Ce=et-1):(xe=le*No((V+$e)/(st+$e)),Ce=le*_c((J+$e)/(st+$e))-1,Ce=bi(O-1,Lr(Ce,le-1)),xe=bi(Ce,Lr(0,xe))):(xe=0,Ce=-1);const we=Pc(xe,Ce,Xe),{bottom:je,top:Ze}=Mc(Fe,ae,oe,we),Ue=_c(O/le),ct=Ue*st+(Ue-1)*$e-je;return{bottom:je,itemHeight:st,items:we,itemWidth:lt,offsetBottom:ct,offsetTop:Ze,top:Ze}})),A),ue($(P,be(O=>O!==null),te(O=>O.length)),T),ue($(dt(R,j,A,W),be(([O,V,{items:J}])=>J.length>0&&V.height!==0&&O.height!==0),te(([O,V,{items:J},ae])=>{const{bottom:oe,top:Fe}=Mc(O,ae,V,J);return[Fe,oe]}),nt(jr)),t);const ie=K(!1);ue($(u,Re(ie),te(([O,V])=>V||O!==0)),ie);const he=_t($(dt(A,T),be(([{items:O}])=>O.length>0),Re(ie),be(([[O,V],J])=>{const ae=O.items[O.items.length-1].index===V-1;return(J||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===V)&&ae}),te(([[,O]])=>O-1),nt())),Ee=_t($(ve(A),be(({items:O})=>O.length>0&&O[0].index===0),Qt(0),nt())),de=_t($(ve(A),Re(F),be(([{items:O},V])=>O.length>0&&!V),te(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),nt(ec),hn(0)));ue(de,p.scrollSeekRangeChanged),ue($(M,Re(R,j,T,W),te(([O,V,J,ae,oe])=>{const Fe=ic(O),{align:Xe,behavior:et,offset:ye}=Fe;let Pe=Fe.index;Pe==="LAST"&&(Pe=ae-1),Pe=Lr(0,Pe,bi(ae-1,Pe));let Je=yi(V,oe,J,Pe);return Xe==="end"?Je=Rc(Je-V.height+J.height):Xe==="center"&&(Je=Rc(Je-V.height/2+J.height/2)),ye&&(Je+=ye),{behavior:et,top:Je}})),l);const z=xt($(A,te(O=>O.offsetBottom+O.bottom)),0);return ue($(E,te(O=>({height:O.visibleHeight,width:O.visibleWidth}))),R),{customScrollParent:g,data:P,deviation:L,footerHeight:o,gap:W,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:j,overscan:n,restoreStateFrom:q,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:M,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:y,windowViewportRect:E,...p,gridState:A,horizontalDirection:fe,initialTopMostItemIndex:N,totalListHeight:z,...h,endReached:he,propsReady:v,rangeChanged:de,startReached:Ee,stateChanged:H,stateRestoreInProgress:F,...C}},tt(fi,bt,Dr,xc,Sn,pi,bn));function Oc(e,t,n){return Lr(1,No((e+n)/(No(t)+n)))}function Mc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=yi(e,t,n,r[0].index);return{bottom:yi(e,t,n,r[r.length-1].index)+o,top:s}}function yi(e,t,n,r){const o=Oc(e.width,n.width,t.column),s=No(r/o),i=s*n.height+Lr(0,s-1)*t.row;return i>0?i+t.row:i}const Ix=He(()=>{const e=K(f=>`Item ${f}`),t=K({}),n=K(null),r=K("virtuoso-grid-item"),o=K("virtuoso-grid-list"),s=K(vi),i=K("div"),a=K(ir),l=(f,h=null)=>xt($(t,te(p=>p[f]),nt()),h),u=K(!1),d=K(!1);return ue(ve(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Nx=He(([e,t])=>({...e,...t}),tt(Ex,Ix)),Ax=S.memo(function(){const e=rt("gridState"),t=rt("listClassName"),n=rt("itemClassName"),r=rt("itemContent"),o=rt("computeItemKey"),s=rt("isSeeking"),i=$t("scrollHeight"),a=rt("ItemComponent"),l=rt("ListComponent"),u=rt("ScrollSeekPlaceholder"),d=rt("context"),f=$t("itemDimensions"),h=$t("gap"),p=rt("log"),w=rt("stateRestoreInProgress"),v=$t("reportReadyState"),g=Fn(S.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const y=x.firstChild;if(y){const{height:E,width:C}=y.getBoundingClientRect();f({height:E,width:C})}h({column:Lc("column-gap",getComputedStyle(x).columnGap,p),row:Lc("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Cc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...vt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?c.jsx(u,{...vt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):S.createElement(a,{...vt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),jx=S.memo(function(){const e=rt("HeaderComponent"),t=$t("headerHeight"),n=rt("headerFooterTag"),r=Fn(S.useMemo(()=>s=>{t(yn(s,"height"))},[t]),!0,!1),o=rt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),_x=S.memo(function(){const e=rt("FooterComponent"),t=$t("footerHeight"),n=rt("headerFooterTag"),r=Fn(S.useMemo(()=>s=>{t(yn(s,"height"))},[t]),!0,!1),o=rt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),Rx=({children:e})=>{const t=S.useContext(Sc),n=$t("itemDimensions"),r=$t("viewportDimensions"),o=Fn(S.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return S.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Io(!1),children:e})},Px=({children:e})=>{const t=S.useContext(Sc),n=$t("windowViewportRect"),r=$t("itemDimensions"),o=rt("customScrollParent"),s=ql(n,o,!1);return S.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Io(!1),children:e})},Ox=S.memo(function({...e}){const t=rt("useWindowScroll"),n=rt("customScrollParent"),r=n||t?Dx:Mx,o=n||t?Px:Rx,s=rt("context");return c.jsx(r,{...e,...vt(r,s),children:c.jsxs(o,{children:[c.jsx(jx,{}),c.jsx(Ax,{}),c.jsx(_x,{})]})})}),{useEmitter:Dc,useEmitterValue:rt,usePublisher:$t}=bc(Nx,{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"}},Ox),Mx=Nc({useEmitter:Dc,useEmitterValue:rt,usePublisher:$t}),Dx=Ac({useEmitter:Dc,useEmitterValue:rt,usePublisher:$t});function Lc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Lx=to.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 Si({className:e,variant:t,...n}){return c.jsx("div",{className:X(Lx({variant:t}),e),...n})}function se(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 Fx(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.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 nn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(v.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var v;const p=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,w=m.useContext(p);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=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,$x(o,...t)]}function $x(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var pt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},zx=m[" useInsertionEffect ".trim().toString()]||pt;function Bn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Bx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.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=m.useCallback(d=>{var f;if(a){const h=Hx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function Bx({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return zx(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Hx(e){return typeof e=="function"}function Fc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ci(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Fc(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():Fc(e[o],null)}}}}function Oe(...e){return m.useCallback(Ci(...e),e)}var Ux=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=Ux.reduce((e,t)=>{const n=Pn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function $c(e,t){e&&no.flushSync(()=>e.dispatchEvent(t))}function Wx(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Pt=e=>{const{present:t,children:n}=e,r=Vx(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Oe(r.ref,Kx(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Pt.displayName="Presence";function Vx(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wx(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=jo(r.current);s.current=a==="mounted"?u:"none"},[a]),pt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=jo(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),pt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const v=jo(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&v&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=jo(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 l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function jo(e){return(e==null?void 0:e.animationName)||"none"}function Kx(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 qx=m[" useId ".trim().toString()]||(()=>{}),Gx=0;function rn(e){const[t,n]=m.useState(qx());return pt(()=>{n(r=>r??String(Gx++))},[e]),e||(t?`radix-${t}`:"")}var _o="Collapsible",[Yx,OC]=nn(_o),[Xx,Ti]=Yx(_o),zc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=Bn({prop:r,defaultProp:o??!1,onChange:i,caller:_o});return c.jsx(Xx,{scope:n,disabled:s,contentId:rn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Se.div,{"data-state":Ei(l),"data-disabled":s?"":void 0,...a,ref:t})})});zc.displayName=_o;var Bc="CollapsibleTrigger",Hc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Ti(Bc,n);return c.jsx(Se.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ei(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:se(e.onClick,o.onOpenToggle)})});Hc.displayName=Bc;var ki="CollapsibleContent",Jx=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ti(ki,e.__scopeCollapsible);return c.jsx(Pt,{present:n||o.open,children:({present:s})=>c.jsx(Zx,{...r,ref:t,present:s})})});Jx.displayName=ki;var Zx=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Ti(ki,n),[a,l]=m.useState(r),u=m.useRef(null),d=Oe(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,v=i.open||a,g=m.useRef(v),x=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),pt(()=>{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 y=b.getBoundingClientRect();f.current=y.height,p.current=y.width,g.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),l(r)}},[i.open,r]),c.jsx(Se.div,{"data-state":Ei(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 Ei(e){return e?"open":"closed"}var Qx=zc;const Uc=Qx,Wc=Hc,Fr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Fr.displayName="Card";const $r=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("flex flex-col space-y-1.5 p-6",e),...t}));$r.displayName="CardHeader";const zr=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:X("text-2xl font-semibold leading-none tracking-tight",e),...t}));zr.displayName="CardTitle";const Vc=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:X("text-sm text-muted-foreground",e),...t}));Vc.displayName="CardDescription";const Ro=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("p-6 pt-0",e),...t}));Ro.displayName="CardContent";const Kc=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("flex items-center p-6 pt-0",e),...t}));Kc.displayName="CardFooter";function qc(){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 Hn=qc();function ev(e){Hn=e}const Gc=/[&<>"']/,tv=new RegExp(Gc.source,"g"),Yc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,nv=new RegExp(Yc.source,"g"),rv={"&":"&","<":"<",">":">",'"':""","'":"'"},Xc=e=>rv[e];function wt(e,t){if(t){if(Gc.test(e))return e.replace(tv,Xc)}else if(Yc.test(e))return e.replace(nv,Xc);return e}const ov=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Jc(e){return e.replace(ov,(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 sv=/(^|[^\[])\^/g;function Ye(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(sv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const iv=/[^\w:]/g,av=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Zc(e,t,n){if(e){let r;try{r=decodeURIComponent(Jc(n)).replace(iv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!av.test(n)&&(n=dv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Po={},lv=/^[^:]+:\/*[^/]*$/,cv=/^([^:]+:)[\s\S]*$/,uv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function dv(e,t){Po[" "+e]||(lv.test(e)?Po[" "+e]=e+"/":Po[" "+e]=Mo(e,"/",!0)),e=Po[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(cv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(uv,"$1")+t:e+t}const Oo={exec:function(){}};function Qc(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Mo(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 fv(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 hv(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 eu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function tu(e,t,n,r){const o=t.href,s=t.title?wt(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:wt(i)}}function pv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
37
|
+
`))>=0;){const le=z.slice(0,Z);z=z.slice(Z+2);const ge=sg(le);if(!ge)continue;let Ce;try{Ce=JSON.parse(ge)}catch{console.debug("[use-chat] malformed SSE:",ge.slice(0,200));continue}const we=og(Ce)?Ce.data:Ce;Fe=Date.now();const je=we.seq;if(je!==void 0){if(je<=K){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:je,lastProcessedSeq:K,type:we.type});continue}K>0&&je>K+1&&((N=D==null?void 0:D.onGap)==null||N.call(D,{from:K,to:je})),K=je,C.current=je,g(je)}if(M==null||M(we),we.type==="token"&&e.autoAppendAssistant!==!1)O.push(we.content),re();else if(we.type==="message_delta"){const Ze=we.delta.filter(Ue=>Ue.type==="text").map(Ue=>Ue.text).join("");Ze&&e.autoAppendAssistant!==!1&&(O.push(Ze),re())}else we.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(J!==null&&cancelAnimationFrame(J),ae(),we.type==="checkpoint"?w(we.checkpointId):we.type==="error"&&d(we.message))}}ae()}catch(ye){if(ye.name!=="AbortError"){const Pe=ye.message||String(ye);d(Pe),(U=D==null?void 0:D.onError)==null||U.call(D,Pe)}}finally{try{await Ee.cancel()}catch{}finally{(Y=Ee.releaseLock)==null||Y.call(Ee)}J!==null&&typeof window<"u"&&window.cancelAnimationFrame(J),clearInterval(Xe),l(!1),b(!1),y.current=null,C.current=0,g(0)}}catch(ie){if(ie.name!=="AbortError"){const he=ie.message||String(ie);d(he),(fe=D==null?void 0:D.onError)==null||fe.call(D,he)}}finally{l(!1),b(!1),y.current=null,C.current=0,g(0)}})(),{close:()=>L.abort()}},[t,n,r,e.autoAppendAssistant]);return S.useEffect(()=>()=>{var j;E.current=!1,(j=y.current)==null||j.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:v,connected:x,stream:R,stop:I,clear:A,setToken:T}}function og(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function sg(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
|
+
`)}function ig({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=S.useRef(null),i=S.useCallback(p=>{const w=p.seq??null;if(w!==null){const v=s.current;if(v!==null){if(w<=v)return;w>v+1&&(o==null||o({from:v,to:w}))}s.current=w}if(p.type==="thread_info"){t(p);return}if(Ym(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Ol({baseUrl:e,token:null}),h=S.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:v=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,v)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return S.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Ml=S.createContext(null),Dl=S.createContext(null),Ll=S.createContext(null),ag=S.createContext(!1),lg=20;function cg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=Gs(),d=S.useMemo(()=>fn(u),[u]),[f,h]=S.useState([]),[p,w]=S.useState(t),[v,g]=S.useState(!1),[x,b]=S.useState(!1),[y,E]=S.useState(!1),[C,T]=S.useState(!1),[I,A]=S.useState(null),[R,j]=S.useState(void 0),[M,D]=S.useState(void 0),{state:L,seed:P,prepend:W,pushUser:H,onEvent:q,reset:F}=Rl(),N=S.useRef(p);S.useEffect(()=>{N.current=p},[p]);const U=S.useRef(!1),Y=S.useRef([]),fe=S.useRef(null),ie=S.useRef(null),he=S.useRef(!1),Ee=S.useCallback((G,ce)=>new Promise((Ie,Ve)=>{const qe=async()=>{U.current=!0;try{await G(),Ie()}catch(It){Ve(It)}finally{U.current=!1;const It=Y.current.shift();It&&It().catch(()=>{})}};U.current?Y.current.push(qe):qe().catch(It=>{Ve(It)})}),[]),de=S.useCallback(async()=>{g(!0);try{const G=await l.listThreads();h(G)}catch(G){i==null||i(String(G)),console.error("[ChatSessionProvider] Failed to refresh threads:",G)}finally{g(!1)}},[l,i]),z=S.useCallback(async()=>{he.current&&(he.current=!1,setTimeout(async()=>{try{await de()}catch(G){console.error("[ChatSessionProvider] Failed to refresh threads after stream:",G)}},100))},[de]),O=S.useRef(!1),K=S.useCallback(()=>{he.current=!0,O.current||z()},[z]),J=S.useCallback((G,ce)=>{const Ie=Array.isArray(G==null?void 0:G.messages)?G.messages:[];ce==="replace"?P(Ie,{checkpointId:(G==null?void 0:G.checkpointId)??null,checkpointNs:(G==null?void 0:G.checkpointNs)??null}):ce==="prepend"&&Ie.length&&W(Ie),A((G==null?void 0:G.nextCursor)??null),E(!!(G!=null&&G.hasMore)),j(Ve=>(G==null?void 0:G.checkpointId)??Ve??void 0),D(Ve=>(G==null?void 0:G.checkpointNs)??Ve??void 0)},[W,P]),ae=S.useCallback(()=>{F([]),E(!1),T(!1),A(null),j(void 0),D(void 0)},[F]),re=S.useCallback(({from:G,to:ce})=>{const Ie=N.current;Ie&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${G} -> ${ce}) for thread ${Ie}`)},[]),Fe=S.useCallback(G=>{const ce=G.threadId,Ie=!!G.created,Ve=!!G.ready;if(N.current!==ce){!N.current&&L.messages.length<=1&&(ie.current=ce),w(ce),(Ve||Ie)&&K();return}(Ve||Ie)&&K()},[K,L.messages.length]),{startStream:Xe,stop:et,isStreaming:ye,error:Pe,setAuthToken:Je}=ig({baseUrl:d,onThreadInfo:Fe,onMessageEvent:q,onUnhandledEvent:G=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${G.type}`,G)},onSequenceGap:re});S.useEffect(()=>{O.current=ye,ye||z()},[z,ye]),S.useEffect(()=>{var Ie;const G=l.getAuthToken();Je(G);const ce=(Ie=l.onTokenChange)==null?void 0:Ie.call(l,Ve=>{Je(Ve)});return()=>{ce==null||ce()}},[l,Je]);const $e=S.useCallback(async G=>{const ce=await l.createThread(G),Ie=typeof ce=="string"?ce:ce.threadId;return await de(),w(Ie),Ie},[l,de]),st=S.useCallback(async G=>{await l.deleteThread(G),N.current===G&&(ie.current=G,w(null),ae()),await de()},[l,ae,de]),lt=S.useCallback(async(G,ce)=>{try{await l.updateThread(G,ce),h(Ie=>Ie.map(Ve=>Ve.threadId===G?{...Ve,title:ce}:Ve))}catch(Ie){throw await de(),Ie}},[l,de]),Z=S.useCallback(async(G,ce,Ie,Ve=!1)=>{await Ee(async()=>{if(ie.current===G&&!Ve){ie.current=null;return}if(!(fe.current===G&&!Ve)){w(qe=>qe===G?qe:G),fe.current=G,b(!0);try{const qe=await l.getMessages({threadId:G,checkpointId:ce,checkpointNs:Ie});he.current=!1,J(qe,"replace"),j((qe==null?void 0:qe.checkpointId)??void 0),D((qe==null?void 0:qe.checkpointNs)??void 0)}catch(qe){throw i==null||i(String(qe)),qe}finally{fe.current=null,b(!1)}}},`loadThread-${G}`)},[l,J,Ee,i]),le=S.useCallback(async()=>{await Ee(async()=>{N.current&&(ie.current=N.current),he.current=!1,w(null),ae(),j(void 0),D(void 0);try{localStorage.removeItem("lastThreadId")}catch(G){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",G)}},"clearCurrentThread")},[ae,Ee]),ge=S.useCallback(async G=>{const ce=await l.listCheckpoints(G);return Km(ce,G)},[l]),Ce=S.useCallback(async(G,ce)=>{if(!N.current)throw new Error("No active thread");await Z(N.current,G,ce??void 0,!0)},[Z]),we=S.useCallback(async()=>{if(!N.current)throw new Error("No active thread");await Z(N.current,void 0,void 0,!0)},[Z]),je=S.useCallback(async G=>{if(!N.current)throw new Error("No active thread");if(C||!y)return;const ce=I;if(ce){T(!0);try{const Ie=await l.getMessages({threadId:N.current,checkpointId:R,checkpointNs:M,limit:(G==null?void 0:G.limit)??lg,beforeId:ce});J(Ie,"prepend")}finally{T(!1)}}},[l,J,y,R,M,I,C]),Ze=S.useCallback(async(G,ce)=>{var er;const Ie=N.current;!Ie&&!(ce!=null&&ce.payloadExtras)&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const Ve=(ce==null?void 0:ce.attachments)||[],{contentParts:qe,filesInfo:It}=await Gm(l,Ve),Rn=[...qe];G&&G.trim()&&Rn.push({type:"text",text:G.trim()});const Jt={id:((er=crypto.randomUUID)==null?void 0:er.call(crypto))||`user-${Date.now()}`,role:"user",content:Rn,createdAt:new Date().toISOString(),checkpointId:(ce==null?void 0:ce.checkpointId)??L.lastCheckpointId??void 0,checkpointNs:(ce==null?void 0:ce.checkpointNs)??L.lastCheckpointNs??void 0};H(Jt);const Zn={...Jt,content:Rn},Qn={...(ce==null?void 0:ce.payloadExtras)??{}},wr=Ve.length>0,Qr={...Ie?{threadId:Ie}:{},payload:{messages:[Zn],files_info:It,...o&&wr&&s?{active_agent:s}:{},...Qn},checkpointId:(ce==null?void 0:ce.checkpointId)??L.lastCheckpointId??void 0,checkpointNs:(ce==null?void 0:ce.checkpointNs)??L.lastCheckpointNs??void 0,nodeFilter:ce==null?void 0:ce.nodeFilter,config:ce==null?void 0:ce.config};Xe(Qr,{onError:gn=>{console.warn("[ChatSessionProvider] Stream error:",gn)},onOpen:({threadId:gn,created:oe})=>{!N.current&&gn&&(L.messages.length<=1&&(ie.current=gn),w(gn))},onGap:re})},[l,o,s,re,K,L.lastCheckpointId,L.lastCheckpointNs,L.messages.length,H,Xe]),Ue=S.useCallback(async(G,ce,Ie)=>{const Ve=N.current;if(!Ve)throw new Error("No active thread to handle interrupt");try{const qe=ce?Ie??!0:!1;await l.resume({threadId:Ve,value:qe})}catch(qe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${G}:`,qe),qe}},[l]);S.useEffect(()=>{if(a==null||a(p),p)try{localStorage.setItem("lastThreadId",p)}catch(G){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",G)}},[p,a]),S.useEffect(()=>{let G=!0;return(async()=>{try{if(await de(),!G)return;if(!r&&!t)try{const Ie=localStorage.getItem("lastThreadId");Ie&&(w(Ie),n&&await Z(Ie))}catch(Ie){console.warn("[ChatSessionProvider] Failed to restore last thread:",Ie)}else t&&n&&await Z(t)}catch(Ie){console.error("[ChatSessionProvider] Initialization failed:",Ie),i==null||i(String(Ie))}})(),()=>{G=!1}},[]);const ct=S.useMemo(()=>({threads:f,currentThreadId:p,isLoadingThreads:v,isLoadingThread:x,setCurrentThreadId:w,createThread:$e,deleteThread:st,renameThread:lt,refreshThreads:de,loadThread:Z,clearCurrentThread:le,listCheckpoints:ge,navigateToCheckpoint:Ce,returnToLatest:we}),[le,$e,p,st,x,v,ge,Z,Ce,de,lt,we,f]),Et=S.useMemo(()=>({messages:L.messages,assemblingId:L.assemblingId,lastUserMessage:null,hasMoreHistory:y,isLoadingHistory:C,send:Ze,stop:et,loadOlderMessages:je,clearMessages:ae,handleInterrupt:Ue}),[ae,Ue,y,C,je,L.assemblingId,L.messages,Ze,et]),_n=S.useMemo(()=>({isStreaming:ye,error:Pe,streamingAssistantId:L.assemblingId,lastCheckpointId:L.lastCheckpointId??null,lastCheckpointNs:L.lastCheckpointNs??null}),[ye,L.assemblingId,L.lastCheckpointId,L.lastCheckpointNs,Pe]);return c.jsx(ag.Provider,{value:!0,children:c.jsx(Ll.Provider,{value:_n,children:c.jsx(Ml.Provider,{value:ct,children:c.jsx(Dl.Provider,{value:Et,children:e})})})})}function mo(){const e=S.useContext(Ml);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Zs(){const e=S.useContext(Dl);if(!e)throw new Error("useMessages must be used within ChatSessionProvider");return e}function Fl(){const e=S.useContext(Ll);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function go({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Vm,{apiConfig:t,children:c.jsx(cg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function X(...e){return bp.twMerge(wp.clsx(e))}const ug=to.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"}}),Be=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Pn.Slot:"button";return c.jsx(i,{className:X(ug({variant:t,size:n,className:e})),ref:s,...o})});Be.displayName="Button";const $l=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:X("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}));$l.displayName="Textarea";function dg({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=S.useState(e),[w,v]=S.useTransition(),g=S.useRef(null);S.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=S.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);S.useEffect(()=>{x()},[x]);const b=S.useCallback(async A=>{A&&A.preventDefault();const R=(h??"").trim();!R&&!f||v(()=>{try{const j=i(R);j&&typeof j.then=="function"?j.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),y=S.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=S.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx($l,{ref:g,value:h,onChange:y,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Be,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(Q.Square,{size:16})}):c.jsx(Be,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(Q.Send,{size:16})})})]})})}const fg=S.memo(dg),xo=0,wn=1,sr=2,zl=4;function Bl(e){return()=>e}function hg(e){e()}function Hl(e,t){return n=>e(t(n))}function Ul(e,t){return()=>e(t)}function pg(e,t){return n=>e(t,n)}function Qs(e){return e!==void 0}function mg(...e){return()=>{e.map(hg)}}function ir(){}function vo(e,t){return t(e),e}function gg(e,t){return t(e)}function tt(...e){return e}function We(e,t){return e(wn,t)}function _e(e,t){e(xo,t)}function ei(e){e(sr)}function at(e){return e(zl)}function ue(e,t){return We(e,pg(t,xo))}function Vt(e,t){const n=e(wn,r=>{n(),t(r)});return n}function Wl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Vl(e,t){return e===t}function nt(e=Vl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function be(e){return t=>n=>{e(n)&&t(n)}}function te(e){return t=>Hl(t,e)}function Qt(e){return t=>()=>{t(e)}}function $(e,...t){const n=xg(...t);return(r,o)=>{switch(r){case sr:ei(e);return;case wn:return We(e,n(o))}}}function en(e,t){return n=>r=>{n(t=e(t,r))}}function Ln(e){return t=>n=>{e>0?e--:t(n)}}function hn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Re(...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);We(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function xg(...e){return t=>e.reduceRight(gg,t)}function vg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case wn:return s?n===s?void 0:(r(),n=s,t=We(e,s),t):(r(),ir);case sr:r(),n=null;return}}}function V(e){let t=e;const n=De();return(r,o)=>{switch(r){case xo:t=o;break;case wn:{o(t);break}case zl:return t}return n(r,o)}}function xt(e,t){return vo(V(t),n=>ue(e,n))}function De(){const e=[];return(t,n)=>{switch(t){case xo:e.slice().forEach(r=>{r(n)});return;case sr:e.splice(0,e.length);return;case wn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function _t(e){return vo(De(),t=>ue(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:wg(),singleton:n}}const wg=()=>Symbol();function bg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function dt(...e){const t=De(),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);We(s,l=>{n[i]=l,r=r|a,r===o&&_e(t,n)})}),function(s,i){switch(s){case sr:{ei(t);return}case wn:return r===o&&i(n),We(t,i)}}}function ve(e,t=Vl){return $(e,nt(t))}function ti(...e){return function(t,n){switch(t){case sr:return;case wn:return mg(...e.map(r=>We(r,n)))}}}var kt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(kt||{});const yg={0:"debug",3:"error",1:"log",2:"warn"},Sg=()=>typeof globalThis>"u"?window:globalThis,bn=He(()=>{const e=V(3);return{log:V((t,n,r=1)=>{var o;const s=(o=Sg().VIRTUOSO_LOG_LEVEL)!=null?o:at(e);r>=s&&console[yg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Fn(e,t,n){return ni(e,t,n).callbackRef}function ni(e,t,n){const r=S.useRef(null);let o=i=>{};const s=S.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Cg(e,t,n,r,o,s,i,a,l){const u=S.useCallback(d=>{const f=Tg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?Kl("column-gap",getComputedStyle(d).columnGap,o):Kl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ni(u,n,l)}function Tg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},kt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Kl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function ql(e,t,n){const r=S.useRef(null),o=S.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ni(o,!0,n),a=S.useCallback(()=>{o(i.current)},[o,i]);return S.useEffect(()=>{var l;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=(l=i.current)==null?void 0:l.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 bt=He(()=>{const e=De(),t=De(),n=V(0),r=De(),o=V(0),s=De(),i=De(),a=V(0),l=V(0),u=V(0),d=V(0),f=De(),h=De(),p=V(!1),w=V(!1),v=V(!1);return ue($(e,te(({scrollTop:g})=>g)),t),ue($(e,te(({scrollHeight:g})=>g)),i),ue(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Nr={lvl:0};function Gl(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function Ge(e){return e===Nr}function Ar(e,t){if(!Ge(e))return t===e.k?e.v:t<e.k?Ar(e.l,t):Ar(e.r,t)}function Kt(e,t,n="k"){if(Ge(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Kt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Kt(e.l,t,n)}function Rt(e,t,n){return Ge(e)?Jl(t,n,1):t===e.k?ht(e,{k:t,v:n}):t<e.k?Zl(ht(e,{l:Rt(e.l,t,n)})):Zl(ht(e,{r:Rt(e.r,t,n)}))}function ar(){return Nr}function wo(e,t,n){if(Ge(e))return[];const r=Kt(e,t)[0];return kg(oi(e,r,n))}function ri(e,t){if(Ge(e))return Nr;const{k:n,l:r,r:o}=e;if(t===n){if(Ge(r))return o;if(Ge(o))return r;{const[s,i]=Xl(r);return bo(ht(e,{k:s,l:Yl(r),v:i}))}}else return t<n?bo(ht(e,{l:ri(r,t)})):bo(ht(e,{r:ri(o,t)}))}function $n(e){return Ge(e)?[]:[...$n(e.l),{k:e.k,v:e.v},...$n(e.r)]}function oi(e,t,n){if(Ge(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oi(s,t,n))),a}function bo(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(si(t))return Ql(ht(e,{lvl:n-1}));if(!Ge(t)&&!Ge(t.r))return ht(t.r,{l:ht(t,{r:t.r.l}),lvl:n,r:ht(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(si(e))return ii(ht(e,{lvl:n-1}));if(!Ge(r)&&!Ge(r.l)){const o=r.l,s=si(o)?r.lvl-1:r.lvl;return ht(o,{l:ht(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ii(ht(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function ht(e,t){return Jl(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 Yl(e){return Ge(e.r)?e.l:bo(ht(e,{r:Yl(e.r)}))}function si(e){return Ge(e)||e.lvl>e.r.lvl}function Xl(e){return Ge(e.r)?[e.k,e.v]:Xl(e.r)}function Jl(e,t,n,r=Nr,o=Nr){return{k:e,l:r,lvl:n,r:o,v:t}}function Zl(e){return ii(Ql(e))}function Ql(e){const{l:t}=e;return!Ge(t)&&t.lvl===e.lvl?ht(t,{r:ht(e,{l:t.r})}):e}function ii(e){const{lvl:t,r:n}=e;return!Ge(n)&&!Ge(n.r)&&n.lvl===t&&n.r.lvl===t?ht(n,{l:ht(e,{r:n.l}),lvl:t+1}):e}function kg(e){return Gl(e,({k:t,v:n})=>({index:t,value:n}))}function ec(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function jr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ai=He(()=>({recalcInProgress:V(!1)}),[],{singleton:!0});function tc(e,t,n){return e[yo(e,t,n)]}function yo(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 Eg(e,t,n,r){const o=yo(e,t,r),s=yo(e,n,r,o);return e.slice(o,s+1)}function yn(e,t){return Math.round(e.getBoundingClientRect()[t])}function So(e){return!Ge(e.groupOffsetTree)}function li({index:e},t){return t===e?0:t<e?-1:1}function Ig(){return{groupIndices:[],groupOffsetTree:ar(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ar()}}function Ng(e,t){let n=Ge(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ge(e)){e=Rt(e,0,s);continue}const a=wo(e,i-1,o+1);if(a.some(Mg(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ri(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Rt(e,o+1,h));u&&(e=Rt(e,i,s))}return[e,n]}function Ag(e){return typeof e.groupIndex<"u"}function jg({offset:e},t){return t===e?0:t<e?-1:1}function _r(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=tc(t,e,li),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function nc(e,t){if(!So(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function rc(e,t,n){if(Ag(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=nc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function _g(e,t,n,r=0){return r>0&&(t=Math.max(t,tc(e,r,li).offset)),Gl(Eg(e,t,n,jg),Og)}function Rg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,kt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ge(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,v)=>Rt(Rt(w,v,h),v+1,p),i)}else[i,a]=Ng(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=ci(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Rt(h,p,_r(p,f,o)),ar()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Pg(e){return $n(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function oc(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 ci(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=yo(o,t-1,li),a=o[l].offset;const u=Kt(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===Kt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of wo(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 Og(e){return{index:e.index,value:e}}function Mg(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 Dg={offsetHeight:"height",offsetWidth:"width"},tn=He(([{log:e},{recalcInProgress:t}])=>{const n=De(),r=De(),o=xt(r,0),s=De(),i=De(),a=V(0),l=V([]),u=V(void 0),d=V(void 0),f=V((C,T)=>yn(C,Dg[T])),h=V(void 0),p=V(0),w=Ig(),v=xt($(n,Re(l,e,p),en(Rg,w),nt()),w),g=xt($(l,nt(),en((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),te(({prev:C})=>C)),[]);ue($(l,be(C=>C.length>0),Re(v,p),te(([C,T,I])=>{const A=C.reduce((R,j,M)=>Rt(R,j,_r(j,T.offsetTree,I)||M),ar());return{...T,groupIndices:C,groupOffsetTree:A}})),v),ue($(r,Re(v),be(([C,{lastIndex:T}])=>C<T),te(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),ue(u,d);const x=xt($(u,te(C=>C===void 0)),!0);ue($(d,be(C=>C!==void 0&&Ge(at(v).sizeTree)),te(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=_t($(n,Re(v),en(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),te(C=>C.changed)));We($(a,en((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),te(C=>C.diff)),C=>{const{groupIndices:T}=at(v);if(C>0)_e(t,!0),_e(s,C+oc(C,T));else if(C<0){const I=at(g);I.length>0&&(C-=oc(-C,I)),_e(i,C)}}),We($(a,Re(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},kt.ERROR)});const y=_t(s);ue($(s,Re(v),te(([C,T])=>{const I=T.groupIndices.length>0,A=[],R=T.lastSize;if(I){const j=Ar(T.sizeTree,0);let M=0,D=0;for(;M<C;){const P=T.groupIndices[D],W=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-P-1;A.push({endIndex:P,size:j,startIndex:P}),A.push({endIndex:P+1+W-1,size:R,startIndex:P+1}),D++,M+=W+1}const L=$n(T.sizeTree);return M!==C&&L.shift(),L.reduce((P,{k:W,v:H})=>{let q=P.ranges;return P.prevSize!==0&&(q=[...P.ranges,{endIndex:W+C-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:W+C,prevSize:H,ranges:q}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return $n(T.sizeTree).reduce((j,{k:M,v:D})=>({prevIndex:M+C,prevSize:D,ranges:[...j.ranges,{endIndex:M+C-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const E=_t($(i,Re(v,p),te(([C,{offsetTree:T},I])=>{const A=-C;return _r(A,T,I)})));return ue($(i,Re(v,p),te(([C,T,I])=>{if(T.groupIndices.length>0){if(Ge(T.sizeTree))return T;let A=ar();const R=at(g);let j=0,M=0,D=0;for(;j<-C;){D=R[M];const L=R[M+1]-D-1;M++,j+=L+1}if(A=$n(T.sizeTree).reduce((L,{k:P,v:W})=>Rt(L,Math.max(0,P+C),W),A),j!==-C){const L=Ar(T.sizeTree,D);A=Rt(A,0,L);const P=Kt(T.sizeTree,-C+1)[1];A=Rt(A,1,P)}return{...T,sizeTree:A,...ci(T.offsetTree,0,A,I)}}else{const A=$n(T.sizeTree).reduce((R,{k:j,v:M})=>Rt(R,Math.max(0,j+C),M),ar());return{...T,sizeTree:A,...ci(T.offsetTree,0,A,I)}}})),v),{beforeUnshiftWith:y,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},tt(bn,ai),{singleton:!0});function Lg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const sc=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=De(),i=De(),a=_t($(s,te(Lg)));return ue($(a,te(l=>l.totalCount)),n),ue($(a,te(l=>l.groupIndices)),e),ue($(dt(o,t,r),be(([l,u])=>So(u)),te(([l,u,d])=>Kt(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),nt(),te(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},tt(tn,bt)),Sn=He(([{log:e}])=>{const t=V(!1),n=_t($(t,be(r=>r),nt()));return We(t,r=>{r&&at(e)("props updated",{},kt.DEBUG)}),{didMount:n,propsReady:t}},tt(bn),{singleton:!0}),Fg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function ic(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Fg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Rr=He(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=De(),w=De(),v=V(0);let g=null,x=null,b=null;function y(){g&&(g(),g=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),_e(l,!1)}return ue($(p,Re(n,f,r,v,a,i,h),Re(e,s,o),te(([[E,C,T,I,A,R,j,M],D,L,P])=>{const W=ic(E),{align:H,behavior:q,offset:F}=W,N=I-1,U=rc(W,C,N);let Y=_r(U,C.offsetTree,D)+R;H==="end"?(Y+=L+Kt(C.sizeTree,U)[1]-T+P,U===N&&(Y+=j)):H==="center"?Y+=(L+Kt(C.sizeTree,U)[1]-T+P)/2:Y-=A,F&&(Y+=F);const fe=ie=>{y(),ie?(M("retrying to scroll to",{location:E},kt.DEBUG),_e(p,E)):(_e(w,!0),M("list did not change, scroll successful",{},kt.DEBUG))};if(y(),q==="smooth"){let ie=!1;b=We(t,he=>{ie=ie||he}),g=Vt(d,()=>{fe(ie)})}else g=Vt($(t,$g(150)),fe);return x=setTimeout(()=>{y()},1200),_e(l,!0),M("scrolling from index to",{behavior:q,index:U,top:Y},kt.DEBUG),{behavior:q,top:Y}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:v}},tt(tn,bt,bn),{singleton:!0});function $g(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ui(e,t){e==0?t():requestAnimationFrame(()=>{ui(e-1,t)})}function di(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Pr=He(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=V(!0),l=V(0),u=V(!0);return ue($(i,Re(l),be(([d,f])=>!!f),Qt(!1)),a),ue($(i,Re(l),be(([d,f])=>!!f),Qt(!1)),u),We($(dt(t,i),Re(a,n,e,u),be(([[,d],f,{sizeTree:h},p,w])=>d&&(!Ge(h)||Qs(p))&&!f&&!w),Re(l)),([,d])=>{Vt(o,()=>{_e(u,!0)}),ui(4,()=>{Vt(r,()=>{_e(a,!0)}),_e(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},tt(tn,bt,Rr,Sn),{singleton:!0});function ac(e,t){return Math.abs(e-t)<1.01}const Or="up",Mr="down",zg="none",Bg={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Hg=0,Dr=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=V(!1),a=V(!0),l=De(),u=De(),d=V(4),f=V(Hg),h=xt($(ti($(ve(o),Ln(1),Qt(!0)),$(ve(o),Ln(1),Qt(!1),Wl(100))),nt()),!1),p=xt($(ti($(n,Qt(!0)),$(n,Qt(!1),Wl(200))),nt()),!1);ue($(dt(ve(o),ve(f)),te(([b,y])=>b<=y),nt()),a),ue($(a,hn(50)),u);const w=_t($(dt(r,ve(s),ve(t),ve(e),ve(d)),en((b,[{scrollHeight:y,scrollTop:E},C,T,I,A])=>{const R=E+C-y>-A,j={scrollHeight:y,scrollTop:E,viewportHeight:C};if(R){let D,L;return E>b.state.scrollTop?(D="SCROLLED_DOWN",L=b.state.scrollTop-E):(D="SIZE_DECREASED",L=b.state.scrollTop-E||b.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:L,state:j}}let M;return j.scrollHeight>b.state.scrollHeight?M="SIZE_INCREASED":C<b.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":E<b.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:j}},Bg),nt((b,y)=>b&&b.atBottom===y.atBottom))),v=xt($(r,en((b,{scrollHeight:y,scrollTop:E,viewportHeight:C})=>{if(ac(b.scrollHeight,y))return{changed:!1,jump:0,scrollHeight:y,scrollTop:E};{const T=y-(E+C)<1;return b.scrollTop!==E&&T?{changed:!0,jump:b.scrollTop-E,scrollHeight:y,scrollTop:E}:{changed:!0,jump:0,scrollHeight:y,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),be(b=>b.changed),te(b=>b.jump)),0);ue($(w,te(b=>b.atBottom)),i),ue($(i,hn(50)),l);const g=V(Mr);ue($(r,te(({scrollTop:b})=>b),nt(),en((b,y)=>at(p)?{direction:b.direction,prevScrollTop:y}:{direction:y<b.prevScrollTop?Or:Mr,prevScrollTop:y},{direction:Mr,prevScrollTop:0}),te(b=>b.direction)),g),ue($(r,hn(50),Qt(zg)),g);const x=V(0);return ue($(h,be(b=>!b),Qt(0)),x),ue($(o,hn(100),Re(h),be(([b,y])=>!!y),en(([b,y],[E])=>[y,E],[0,0]),te(([b,y])=>y-b)),x),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},tt(bt)),Co="top",To="bottom",lc="none";function cc(e,t,n){return typeof e=="number"?n===Or&&t===Co||n===Mr&&t===To?e:0:n===Or?t===Co?e.main:e.reverse:t===To?e.main:e.reverse}function uc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fi=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=De(),i=V(0),a=V(0),l=V(0),u=xt($(dt(ve(r),ve(o),ve(n),ve(s,jr),ve(l),ve(i),ve(t),ve(e),ve(a)),te(([d,f,h,[p,w],v,g,x,b,y])=>{const E=d-b,C=g+x,T=Math.max(h-E,0);let I=lc;const A=uc(y,Co),R=uc(y,To);return p-=b,p+=h+x,w+=h+x,w-=b,p>d+C-A&&(I=Or),w<d-T+f+R&&(I=Mr),I!==lc?[Math.max(E-h-cc(v,Co,I)-A,0),E-T-x+f+cc(v,To,I)+R]:null}),be(d=>d!=null),nt(jr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},tt(bt),{singleton:!0});function Ug(e,t,n){if(So(t)){const r=nc(e,t);return[{index:Kt(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 hi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ko(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=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*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:fc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:fc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function dc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ko(u,[],a,o,n,r)}function fc(e,t,n){if(e.length===0)return[];if(!So(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=wo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const zn=He(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const v=V([]),g=V(0),x=De();ue(s.topItemsIndexes,v);const b=xt($(dt(p,w,ve(l,jr),ve(o),ve(r),ve(u),d,ve(v),ve(t),ve(n),e),be(([T,I,,A,,,,,,,R])=>{const j=R&&R.length!==A;return T&&!I&&!j}),te(([,,[T,I],A,R,j,M,D,L,P,W])=>{const H=R,{offsetTree:q,sizeTree:F}=H,N=at(g);if(A===0)return{...hi,totalCount:A};if(T===0&&I===0)return N===0?{...hi,totalCount:A}:dc(N,j,R,L,P,W||[]);if(Ge(F))return N>0?null:ko(Ug(di(j,A),H,W),[],A,P,H,L);const U=[];if(D.length>0){const Ee=D[0],de=D[D.length-1];let z=0;for(const O of wo(F,Ee,de)){const K=O.value,J=Math.max(O.start,Ee),ae=Math.min(O.end,de);for(let re=J;re<=ae;re++)U.push({data:W==null?void 0:W[re],index:re,offset:z,size:K}),z+=K}}if(!M)return ko([],U,A,P,H,L);const Y=D.length>0?D[D.length-1]+1:0,fe=_g(q,T,I,Y);if(fe.length===0)return null;const ie=A-1,he=vo([],Ee=>{for(const de of fe){const z=de.value;let O=z.offset,K=de.start;const J=z.size;if(z.offset<T){K+=Math.floor((T-z.offset+P)/(J+P));const re=K-de.start;O+=re*J+re*P}K<Y&&(O+=(Y-K)*J,K=Y);const ae=Math.min(de.end,ie);for(let re=K;re<=ae&&!(O>=I);re++)Ee.push({data:W==null?void 0:W[re],index:re,offset:O,size:J}),O+=J+P}});return ko(he,U,A,P,H,L)}),be(T=>T!==null),nt()),hi);ue($(e,be(Qs),te(T=>T==null?void 0:T.length)),o),ue($(b,te(T=>T.topListHeight)),f),ue(f,a),ue($(b,te(T=>[T.top,T.bottom])),i),ue($(b,te(T=>T.items)),x);const y=_t($(b,be(({items:T})=>T.length>0),Re(o,e),be(([{items:T},I])=>T[T.length-1].originalIndex===I-1),te(([,T,I])=>[T-1,I]),nt(jr),te(([T])=>T))),E=_t($(b,hn(200),be(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),te(({items:T})=>T[0].index),nt())),C=_t($(b,be(({items:T})=>T.length>0),te(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),nt(ec)));return{endReached:y,initialItemCount:g,itemsRendered:x,listState:b,rangeChanged:C,startReached:E,topItemsIndexes:v,...h}},tt(tn,sc,fi,Pr,Rr,Dr,Sn,ai),{singleton:!0}),hc=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=De(),i=xt($(dt(n,e,r,t,o),te(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ue(ve(i),s),{totalListHeight:i,totalListHeightChanged:s}},tt(bt,zn),{singleton:!0}),Wg=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=V(!1),r=xt($(dt(n,e,t),be(([o])=>o),te(([,o,s])=>Math.max(0,o-s)),hn(0),nt()),0);return{alignToBottom:n,paddingTopAddition:r}},tt(bt,hc),{singleton:!0}),pc=He(()=>({context:V(null)})),Vg=({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,mc=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=De();return ue($(d,Re(t,l,n,s,o,r,a),Re(e),te(([[f,h,p,w,v,g,x,b],y])=>{const{align:E,behavior:C,calculateViewLocation:T=Vg,done:I,...A}=f,R=rc(f,h,w-1),j=_r(R,h.offsetTree,y)+v+g,M=j+Kt(h.sizeTree,R)[1],D=b+g,L=b+p-x,P=T({itemBottom:M,itemTop:j,locationParams:{align:E,behavior:C,...A},viewportBottom:L,viewportTop:D});return P?I&&Vt($(i,be(W=>!W),Ln(at(i)?1:2)),I):I&&I(),P}),be(f=>f!==null)),u),{scrollIntoView:d}},tt(tn,bt,Rr,zn,bn),{singleton:!0});function gc(e){return e?e==="smooth"?"smooth":"auto":!1}const Kg=(e,t)=>typeof e=="function"?gc(e(t)):t&&gc(e),qg=He(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=V(!1),v=De();let g=null;function x(C){_e(i,{align:"end",behavior:C,index:"LAST"})}We($(dt($(ve(t),Ln(1)),l),Re(ve(w),s,a,f),te(([[C,T],I,A,R,j])=>{let M=T&&R,D="auto";return M&&(D=Kg(I,A||j),M=M&&!!D),{followOutputBehavior:D,shouldFollow:M,totalCount:C}}),be(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("following output to ",{totalCount:T},kt.DEBUG),x(C)}):g=Vt(e,()=>{at(d)("following output to ",{totalCount:T},kt.DEBUG),x(C),g=null})});function b(C){const T=Vt(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(at(d)("scrolling to bottom due to increased size",{},kt.DEBUG),x("auto"))});setTimeout(T,100)}We($(dt(ve(w),t,u),be(([C,,T])=>C&&T),en(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),be(({refreshed:C})=>C),Re(w,t)),([,C])=>{at(a)&&b(C!==!1)}),We(v,()=>{b(at(w)!==!1)}),We(dt(ve(w),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const y=V(null),E=De();return ue(ti($(ve(r),te(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),$(ve(t))),E),We($(dt($(E,Ln(1)),l),Re(ve(y),a,f,h),te(([[C,T],I,A,R,j])=>T&&A&&(I==null?void 0:I({context:j,totalCount:C,scrollingInProgress:R}))),be(C=>!!C),hn(0)),C=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("scrolling into view",{}),_e(p,C)}):g=Vt(e,()=>{at(d)("scrolling into view",{}),_e(p,C),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:y}},tt(tn,Dr,Rr,Pr,Sn,bn,bt,pc,mc)),Gg=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ue($(a,Re(s),be(([,l])=>l!==0),Re(o,r,t,n,e),te(([[,l],u,d,f,h,p=[]])=>dc(l,u,d,f,h,p))),i),{}),tt(tn,Pr,zn,Sn),{singleton:!0}),Yg=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=V(0);return We($(e,Re(r),be(([,o])=>o!==0),te(([,o])=>({top:o}))),o=>{Vt($(n,Ln(1),be(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{_e(t,o)})})}),{initialScrollTop:r}},tt(Sn,bt,zn),{singleton:!0}),xc=He(([{scrollVelocity:e}])=>{const t=V(!1),n=De(),r=V(!1);return ue($(e,Re(r,t,n),be(([o,s])=>!!s),te(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),nt()),t),We($(dt(t,e,n),Re(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},tt(Dr),{singleton:!0}),pi=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=De(),r=De(),o=De(),s=V(!1),i=V(void 0);return ue($(dt(n,r),te(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ue($(t,Re(r),te(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},tt(bt)),Xg=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=De(),d=V(void 0),f=V(null),h=V(null);return ue(a,f),ue(l,h),We($(u,Re(t,r,i,f,h,n)),([p,w,v,g,x,b,y])=>{const E=Pg(w.sizeTree);g&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=y,p({ranges:E,scrollTop:v})}),ue($(d,be(Qs),te(Jg)),o),ue($(s,Re(d),be(([,p])=>p!==void 0),nt(),te(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},tt(tn,bt,Pr,Sn,pi));function Jg(e){return{align:"start",index:0,offset:e.scrollTop}}const Zg=He(([{topItemsIndexes:e}])=>{const t=V(0);return ue($(t,be(n=>n>=0),te(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},tt(zn));function vc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Qg=vc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),ex=He(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const v=_t($(l,Re(i),en(([,x,b,y],[{bottom:E,items:C,offsetBottom:T,totalCount:I},A])=>{const R=E+T;let j=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(j=R-y,j!==0&&(j+=A))),[j,C,I,R]},[0,[],0,0]),be(([x])=>x!==0),Re(r,a,n,o,p,w),be(([,x,b,y,,,E])=>!E&&!y&&x!==0&&b===Or),te(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},kt.DEBUG),x))));function g(x){x>0?(_e(t,{behavior:"auto",top:-x}),_e(e,0)):(_e(e,0),_e(t,{behavior:"auto",top:-x}))}return We($(v,Re(e,s)),([x,b,y])=>{y&&Qg()?_e(e,b-x):g(-x)}),We($(dt(xt(s,!1),e,w),be(([x,b,y])=>!x&&!y&&b!==0),te(([x,b])=>b),hn(1)),g),ue($(f,te(x=>({top:-x}))),t),We($(u,Re(h,d),te(([x,{groupIndices:b,lastSize:y,sizeTree:E},C])=>{function T(I){return I*(y+C)}if(b.length===0)return T(x);{let I=0;const A=Ar(E,0);let R=0,j=0;for(;R<x;){R++,I+=A;let M=b.length===j+1?1/0:b[j+1]-b[j]-1;R+M>x&&(I-=A,M=x-R+1),R+=M,I+=T(M),j++}return I}})),x=>{_e(e,x),requestAnimationFrame(()=>{_e(t,{top:x}),requestAnimationFrame(()=>{_e(e,0),_e(w,!1)})})}),{deviation:e}},tt(bt,Dr,zn,tn,bn,ai)),tx=He(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),tt(fi,Gg,Sn,xc,hc,Yg,Wg,pi,mc,bn,pc)),wc=He(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},v,g,x,{listState:b,topItemsIndexes:y,...E},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},R])=>(ue(E.rangeChanged,R.scrollSeekRangeChanged),ue($(R.windowViewportRect,te(j=>j.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:y,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...E,...R,...v,sizes:l,...g}),tt(tn,Pr,bt,Xg,qg,zn,Rr,ex,Zg,sc,tx));function nx(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 Eo=typeof document<"u"?S.useLayoutEffect:S.useEffect;function bc(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=S.createContext({});function l(g,x){g.propsReady&&_e(g.propsReady,!1);for(const b of r){const y=g[t.required[b]];_e(y,x[b])}for(const b of o)if(b in x){const y=g[t.optional[b]];_e(y,x[b])}g.propsReady&&_e(g.propsReady,!0)}function u(g){return s.reduce((x,b)=>(x[b]=y=>{const E=g[t.methods[b]];_e(E,y)},x),{})}function d(g){return i.reduce((x,b)=>(x[b]=vg(g[t.events[b]]),x),{})}const f=S.forwardRef((g,x)=>{const{children:b,...y}=g,[E]=S.useState(()=>vo(bg(e),I=>{l(I,y)})),[C]=S.useState(Ul(d,E));Eo(()=>{for(const I of i)I in y&&We(C[I],y[I]);return()=>{Object.values(C).map(ei)}},[y,C,E]),Eo(()=>{l(E,y)}),S.useImperativeHandle(x,Bl(u(E)));const T=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(T,{...nx([...r,...o,...i],y),children:b}):b})}),h=g=>{const x=S.useContext(a);return S.useCallback(b=>{_e(x[g],b)},[x,g])},p=g=>{const x=S.useContext(a)[g],b=S.useCallback(y=>We(x,y),[x]);return S.useSyncExternalStore(b,()=>at(x),()=>at(x))},w=g=>{const x=S.useContext(a)[g],[b,y]=S.useState(Ul(at,x));return Eo(()=>We(x,E=>{E!==b&&y(Bl(E))}),[x,b]),b},v=S.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,x)=>{const b=S.useContext(a)[g];Eo(()=>We(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const yc=S.createContext(void 0),Sc=S.createContext(void 0),Cc=typeof document<"u"?S.useLayoutEffect:S.useEffect;function mi(e){return"self"in e}function rx(e){return"body"in e}function Tc(e,t,n,r=ir,o,s){const i=S.useRef(null),a=S.useRef(null),l=S.useRef(null),u=S.useCallback(h=>{let p,w,v;const g=h.target;if(rx(g)||mi(g)){const b=mi(g)?g:g.defaultView;v=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Rs.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);S.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 p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;mi(p)?(g=Math.max(yn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),v=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],v=yn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=g-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),ac(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const gi="-webkit-sticky",kc="sticky",xi=vc(()=>{if(typeof document>"u")return kc;const e=document.createElement("div");return e.style.position=gi,e.style.position===gi?gi:kc});function vi(e){return e}const ox=He(()=>{const e=V(a=>`Item ${a}`),t=V(a=>`Group ${a}`),n=V({}),r=V(vi),o=V("div"),s=V(ir),i=(a,l=null)=>xt($(n,te(u=>u[a]),nt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),sx=He(([e,t])=>({...e,...t}),tt(wc,ox)),ix=({height:e})=>c.jsx("div",{style:{height:e}}),ax={overflowAnchor:"none",position:xi(),zIndex:1},Ec={overflowAnchor:"none"},lx={...Ec,display:"inline-block",height:"100%"},Ic=S.memo(function({showTopList:e=!1}){const t=Ne("listState"),n=Ft("sizeRanges"),r=Ne("useWindowScroll"),o=Ne("customScrollParent"),s=Ft("windowScrollContainerState"),i=Ft("scrollContainerState"),a=o||r?s:i,l=Ne("itemContent"),u=Ne("context"),d=Ne("groupContent"),f=Ne("trackItemSizes"),h=Ne("itemSize"),p=Ne("log"),w=Ft("gap"),v=Ne("horizontalDirection"),{callbackRef:g}=Cg(n,h,f,e?ir:a,p,w,o,v,Ne("skipAnimationFrameInResizeObserver")),[x,b]=S.useState(0);wi("deviation",P=>{x!==P&&b(P)});const y=Ne("EmptyPlaceholder"),E=Ne("ScrollSeekPlaceholder")||ix,C=Ne("ListComponent"),T=Ne("ItemComponent"),I=Ne("GroupComponent"),A=Ne("computeItemKey"),R=Ne("isSeeking"),j=Ne("groupIndices").length>0,M=Ne("alignToBottom"),D=Ne("initialItemFinalLocationReached"),L=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:M?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:M?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&y?c.jsx(y,{...vt(y,u)}):c.jsx(C,{...vt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:L,children:(e?t.topItems:t.items).map(P=>{const W=P.originalIndex,H=A(W+t.firstItemIndex,P.data,u);return R?S.createElement(E,{...vt(E,u),height:P.size,index:P.index,key:H,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?S.createElement(I,{...vt(I,u),"data-index":W,"data-item-index":P.index,"data-known-size":P.size,key:H,style:ax},d(P.index,u)):S.createElement(T,{...vt(T,u),...fx(T,P.data),"data-index":W,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:H,style:v?lx:Ec},j?l(P.index,P.groupIndex,P.data,u):l(P.index,P.data,u))})})}),cx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},ux={outline:"none",overflowX:"auto",position:"relative"},Io=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),dx={position:xi(),top:0,width:"100%",zIndex:1};function vt(e,t){if(typeof e!="string")return{context:t}}function fx(e,t){return{item:typeof e=="string"?void 0:t}}const hx=S.memo(function(){const e=Ne("HeaderComponent"),t=Ft("headerHeight"),n=Ne("HeaderFooterTag"),r=Fn(S.useMemo(()=>s=>{t(yn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),px=S.memo(function(){const e=Ne("FooterComponent"),t=Ft("footerHeight"),n=Ne("HeaderFooterTag"),r=Fn(S.useMemo(()=>s=>{t(yn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null});function Nc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=Tc(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?ux:cx,...o},tabIndex:0,...i,...vt(l,s),children:r})})}function Ac({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=S.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Tc(a,u,l,w,h);return Cc(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...vt(l,s),children:r})})}const mx=({children:e})=>{const t=S.useContext(yc),n=Ft("viewportHeight"),r=Ft("fixedItemHeight"),o=Ne("alignToBottom"),s=Ne("horizontalDirection"),i=S.useMemo(()=>Hl(n,l=>yn(l,s?"width":"height")),[n,s]),a=Fn(i,!0,Ne("skipAnimationFrameInResizeObserver"));return S.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Io(o),children:e})},gx=({children:e})=>{const t=S.useContext(yc),n=Ft("windowViewportRect"),r=Ft("fixedItemHeight"),o=Ne("customScrollParent"),s=ql(n,o,Ne("skipAnimationFrameInResizeObserver")),i=Ne("alignToBottom");return S.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Io(i),children:e})},xx=({children:e})=>{const t=Ne("TopItemListComponent")||"div",n=Ne("headerHeight"),r={...dx,marginTop:`${n}px`},o=Ne("context");return c.jsx(t,{style:r,...vt(t,o),children:e})},vx=S.memo(function(e){const t=Ne("useWindowScroll"),n=Ne("topItemsIndexes").length>0,r=Ne("customScrollParent"),o=Ne("context");return c.jsxs(r||t?yx:bx,{...e,context:o,children:[n&&c.jsx(xx,{children:c.jsx(Ic,{showTopList:!0})}),c.jsxs(r||t?gx:mx,{children:[c.jsx(hx,{}),c.jsx(Ic,{}),c.jsx(px,{})]})]})}),{Component:wx,useEmitter:wi,useEmitterValue:Ne,usePublisher:Ft}=bc(sx,{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"}},vx),bx=Nc({useEmitter:wi,useEmitterValue:Ne,usePublisher:Ft}),yx=Ac({useEmitter:wi,useEmitterValue:Ne,usePublisher:Ft}),Sx=wx;tt(wc,He(()=>{const e=V(u=>c.jsxs("td",{children:["Item $",u]})),t=V(null),n=V(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=V(null),o=V(null),s=V({}),i=V(vi),a=V(ir),l=(u,d=null)=>xt($(s,te(f=>f[u]),nt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),xi();const jc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Cx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:_c,floor:No,max:Lr,min:bi,round:Rc}=Math;function Pc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Tx(e){return{...Cx,items:e}}function Ao(e,t){return e&&e.width===t.width&&e.height===t.height}function kx(e,t){return e&&e.column===t.column&&e.row===t.row}const Ex=He(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:y,windowViewportRect:E},C])=>{const T=V(0),I=V(0),A=V(jc),R=V({height:0,width:0}),j=V({height:0,width:0}),M=De(),D=De(),L=V(0),P=V(null),W=V({column:0,row:0}),H=De(),q=De(),F=V(!1),N=V(0),U=V(!0),Y=V(!1),fe=V(!1);We($(w,Re(N),be(([O,K])=>!!K)),()=>{_e(U,!1)}),We($(dt(w,U,j,R,N,Y),be(([O,K,J,ae,,re])=>O&&!K&&J.height!==0&&ae.height!==0&&!re)),([,,,,O])=>{_e(Y,!0),ui(1,()=>{_e(M,O)}),Vt($(u),()=>{_e(t,[0,0]),_e(U,!0)})}),ue($(q,be(O=>O!=null&&O.scrollTop>0),Qt(0)),I),We($(w,Re(q),be(([,O])=>O!=null)),([,O])=>{O&&(_e(R,O.viewport),_e(j,O.item),_e(W,O.gap),O.scrollTop>0&&(_e(F,!0),Vt($(u,Ln(1)),K=>{_e(F,!1)}),_e(l,{top:O.scrollTop})))}),ue($(R,te(({height:O})=>O)),f),ue($(dt(ve(R,Ao),ve(j,Ao),ve(W,(O,K)=>O&&O.column===K.column&&O.row===K.row),ve(u)),te(([O,K,J,ae])=>({gap:J,item:K,scrollTop:ae,viewport:O}))),H),ue($(dt(ve(T),r,ve(W,kx),ve(j,Ao),ve(R,Ao),ve(P),ve(I),ve(F),ve(U),ve(N)),be(([,,,,,,,O])=>!O),te(([O,[K,J],ae,re,Fe,Xe,et,,ye,Pe])=>{const{column:Je,row:$e}=ae,{height:st,width:lt}=re,{width:Z}=Fe;if(et===0&&(O===0||Z===0))return jc;if(lt===0){const Et=di(Pe,O),_n=Et+Math.max(et-1,0);return Tx(Pc(Et,_n,Xe))}const le=Oc(Z,lt,Je);let ge,Ce;ye?K===0&&J===0&&et>0?(ge=0,Ce=et-1):(ge=le*No((K+$e)/(st+$e)),Ce=le*_c((J+$e)/(st+$e))-1,Ce=bi(O-1,Lr(Ce,le-1)),ge=bi(Ce,Lr(0,ge))):(ge=0,Ce=-1);const we=Pc(ge,Ce,Xe),{bottom:je,top:Ze}=Mc(Fe,ae,re,we),Ue=_c(O/le),ct=Ue*st+(Ue-1)*$e-je;return{bottom:je,itemHeight:st,items:we,itemWidth:lt,offsetBottom:ct,offsetTop:Ze,top:Ze}})),A),ue($(P,be(O=>O!==null),te(O=>O.length)),T),ue($(dt(R,j,A,W),be(([O,K,{items:J}])=>J.length>0&&K.height!==0&&O.height!==0),te(([O,K,{items:J},ae])=>{const{bottom:re,top:Fe}=Mc(O,ae,K,J);return[Fe,re]}),nt(jr)),t);const ie=V(!1);ue($(u,Re(ie),te(([O,K])=>K||O!==0)),ie);const he=_t($(dt(A,T),be(([{items:O}])=>O.length>0),Re(ie),be(([[O,K],J])=>{const ae=O.items[O.items.length-1].index===K-1;return(J||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===K)&&ae}),te(([[,O]])=>O-1),nt())),Ee=_t($(ve(A),be(({items:O})=>O.length>0&&O[0].index===0),Qt(0),nt())),de=_t($(ve(A),Re(F),be(([{items:O},K])=>O.length>0&&!K),te(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),nt(ec),hn(0)));ue(de,p.scrollSeekRangeChanged),ue($(M,Re(R,j,T,W),te(([O,K,J,ae,re])=>{const Fe=ic(O),{align:Xe,behavior:et,offset:ye}=Fe;let Pe=Fe.index;Pe==="LAST"&&(Pe=ae-1),Pe=Lr(0,Pe,bi(ae-1,Pe));let Je=yi(K,re,J,Pe);return Xe==="end"?Je=Rc(Je-K.height+J.height):Xe==="center"&&(Je=Rc(Je-K.height/2+J.height/2)),ye&&(Je+=ye),{behavior:et,top:Je}})),l);const z=xt($(A,te(O=>O.offsetBottom+O.bottom)),0);return ue($(E,te(O=>({height:O.visibleHeight,width:O.visibleWidth}))),R),{customScrollParent:g,data:P,deviation:L,footerHeight:o,gap:W,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:j,overscan:n,restoreStateFrom:q,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:M,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:y,windowViewportRect:E,...p,gridState:A,horizontalDirection:fe,initialTopMostItemIndex:N,totalListHeight:z,...h,endReached:he,propsReady:v,rangeChanged:de,startReached:Ee,stateChanged:H,stateRestoreInProgress:F,...C}},tt(fi,bt,Dr,xc,Sn,pi,bn));function Oc(e,t,n){return Lr(1,No((e+n)/(No(t)+n)))}function Mc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=yi(e,t,n,r[0].index);return{bottom:yi(e,t,n,r[r.length-1].index)+o,top:s}}function yi(e,t,n,r){const o=Oc(e.width,n.width,t.column),s=No(r/o),i=s*n.height+Lr(0,s-1)*t.row;return i>0?i+t.row:i}const Ix=He(()=>{const e=V(f=>`Item ${f}`),t=V({}),n=V(null),r=V("virtuoso-grid-item"),o=V("virtuoso-grid-list"),s=V(vi),i=V("div"),a=V(ir),l=(f,h=null)=>xt($(t,te(p=>p[f]),nt()),h),u=V(!1),d=V(!1);return ue(ve(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Nx=He(([e,t])=>({...e,...t}),tt(Ex,Ix)),Ax=S.memo(function(){const e=rt("gridState"),t=rt("listClassName"),n=rt("itemClassName"),r=rt("itemContent"),o=rt("computeItemKey"),s=rt("isSeeking"),i=$t("scrollHeight"),a=rt("ItemComponent"),l=rt("ListComponent"),u=rt("ScrollSeekPlaceholder"),d=rt("context"),f=$t("itemDimensions"),h=$t("gap"),p=rt("log"),w=rt("stateRestoreInProgress"),v=$t("reportReadyState"),g=Fn(S.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const y=x.firstChild;if(y){const{height:E,width:C}=y.getBoundingClientRect();f({height:E,width:C})}h({column:Lc("column-gap",getComputedStyle(x).columnGap,p),row:Lc("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Cc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...vt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?c.jsx(u,{...vt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):S.createElement(a,{...vt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),jx=S.memo(function(){const e=rt("HeaderComponent"),t=$t("headerHeight"),n=rt("headerFooterTag"),r=Fn(S.useMemo(()=>s=>{t(yn(s,"height"))},[t]),!0,!1),o=rt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),_x=S.memo(function(){const e=rt("FooterComponent"),t=$t("footerHeight"),n=rt("headerFooterTag"),r=Fn(S.useMemo(()=>s=>{t(yn(s,"height"))},[t]),!0,!1),o=rt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),Rx=({children:e})=>{const t=S.useContext(Sc),n=$t("itemDimensions"),r=$t("viewportDimensions"),o=Fn(S.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return S.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Io(!1),children:e})},Px=({children:e})=>{const t=S.useContext(Sc),n=$t("windowViewportRect"),r=$t("itemDimensions"),o=rt("customScrollParent"),s=ql(n,o,!1);return S.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Io(!1),children:e})},Ox=S.memo(function({...e}){const t=rt("useWindowScroll"),n=rt("customScrollParent"),r=n||t?Dx:Mx,o=n||t?Px:Rx,s=rt("context");return c.jsx(r,{...e,...vt(r,s),children:c.jsxs(o,{children:[c.jsx(jx,{}),c.jsx(Ax,{}),c.jsx(_x,{})]})})}),{useEmitter:Dc,useEmitterValue:rt,usePublisher:$t}=bc(Nx,{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"}},Ox),Mx=Nc({useEmitter:Dc,useEmitterValue:rt,usePublisher:$t}),Dx=Ac({useEmitter:Dc,useEmitterValue:rt,usePublisher:$t});function Lc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Lx=to.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 Si({className:e,variant:t,...n}){return c.jsx("div",{className:X(Lx({variant:t}),e),...n})}function se(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 Fx(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.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 nn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(v.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var v;const p=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,w=m.useContext(p);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=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,$x(o,...t)]}function $x(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var pt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},zx=m[" useInsertionEffect ".trim().toString()]||pt;function Bn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Bx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.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=m.useCallback(d=>{var f;if(a){const h=Hx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function Bx({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return zx(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Hx(e){return typeof e=="function"}function Fc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ci(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Fc(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():Fc(e[o],null)}}}}function Oe(...e){return m.useCallback(Ci(...e),e)}var Ux=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=Ux.reduce((e,t)=>{const n=Pn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function $c(e,t){e&&no.flushSync(()=>e.dispatchEvent(t))}function Wx(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Pt=e=>{const{present:t,children:n}=e,r=Vx(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Oe(r.ref,Kx(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Pt.displayName="Presence";function Vx(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wx(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=jo(r.current);s.current=a==="mounted"?u:"none"},[a]),pt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=jo(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),pt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const v=jo(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&v&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=jo(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 l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function jo(e){return(e==null?void 0:e.animationName)||"none"}function Kx(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 qx=m[" useId ".trim().toString()]||(()=>{}),Gx=0;function rn(e){const[t,n]=m.useState(qx());return pt(()=>{n(r=>r??String(Gx++))},[e]),e||(t?`radix-${t}`:"")}var _o="Collapsible",[Yx,OC]=nn(_o),[Xx,Ti]=Yx(_o),zc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=Bn({prop:r,defaultProp:o??!1,onChange:i,caller:_o});return c.jsx(Xx,{scope:n,disabled:s,contentId:rn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Se.div,{"data-state":Ei(l),"data-disabled":s?"":void 0,...a,ref:t})})});zc.displayName=_o;var Bc="CollapsibleTrigger",Hc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Ti(Bc,n);return c.jsx(Se.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ei(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:se(e.onClick,o.onOpenToggle)})});Hc.displayName=Bc;var ki="CollapsibleContent",Jx=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ti(ki,e.__scopeCollapsible);return c.jsx(Pt,{present:n||o.open,children:({present:s})=>c.jsx(Zx,{...r,ref:t,present:s})})});Jx.displayName=ki;var Zx=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Ti(ki,n),[a,l]=m.useState(r),u=m.useRef(null),d=Oe(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,v=i.open||a,g=m.useRef(v),x=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),pt(()=>{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 y=b.getBoundingClientRect();f.current=y.height,p.current=y.width,g.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),l(r)}},[i.open,r]),c.jsx(Se.div,{"data-state":Ei(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 Ei(e){return e?"open":"closed"}var Qx=zc;const Uc=Qx,Wc=Hc,Fr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Fr.displayName="Card";const $r=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("flex flex-col space-y-1.5 p-6",e),...t}));$r.displayName="CardHeader";const zr=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:X("text-2xl font-semibold leading-none tracking-tight",e),...t}));zr.displayName="CardTitle";const Vc=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:X("text-sm text-muted-foreground",e),...t}));Vc.displayName="CardDescription";const Ro=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("p-6 pt-0",e),...t}));Ro.displayName="CardContent";const Kc=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("flex items-center p-6 pt-0",e),...t}));Kc.displayName="CardFooter";function qc(){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 Hn=qc();function ev(e){Hn=e}const Gc=/[&<>"']/,tv=new RegExp(Gc.source,"g"),Yc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,nv=new RegExp(Yc.source,"g"),rv={"&":"&","<":"<",">":">",'"':""","'":"'"},Xc=e=>rv[e];function wt(e,t){if(t){if(Gc.test(e))return e.replace(tv,Xc)}else if(Yc.test(e))return e.replace(nv,Xc);return e}const ov=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Jc(e){return e.replace(ov,(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 sv=/(^|[^\[])\^/g;function Ye(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(sv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const iv=/[^\w:]/g,av=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Zc(e,t,n){if(e){let r;try{r=decodeURIComponent(Jc(n)).replace(iv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!av.test(n)&&(n=dv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Po={},lv=/^[^:]+:\/*[^/]*$/,cv=/^([^:]+:)[\s\S]*$/,uv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function dv(e,t){Po[" "+e]||(lv.test(e)?Po[" "+e]=e+"/":Po[" "+e]=Mo(e,"/",!0)),e=Po[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(cv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(uv,"$1")+t:e+t}const Oo={exec:function(){}};function Qc(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Mo(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 fv(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 hv(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 eu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function tu(e,t,n,r){const o=t.href,s=t.title?wt(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:wt(i)}}function pv(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 Ii{constructor(t){this.options=t||Hn}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:Mo(r,`
|
|
41
41
|
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=pv(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=Mo(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,u,d,f,h,p,w,v=n[1].trim();const g=v.length>1,x={type:"list",raw:"",ordered:g,start:g?+v.slice(0,-1):"",loose:!1,items:[]};v=g?`\\d{1,9}\\${v.slice(-1)}`:`\\${v}`,this.options.pedantic&&(v=g?v:"[*+-]");const b=new RegExp(`^( {0,3}${v})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(w=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
@@ -47,8 +47,8 @@ React keys must be passed directly to JSX without using spread:
|
|
|
47
47
|
`+f}!l&&!f.trim()&&(l=!0),r+=h+`
|
|
48
48
|
`,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(u?x.loose=!0:/\n *\n *$/.test(r)&&(u=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const y=x.items.length;for(a=0;a<y;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const E=x.items[a].tokens.filter(T=>T.type==="space"),C=E.length>0&&E.some(T=>/\n.*\n/.test(T.raw));x.loose=C}if(x.loose)for(a=0;a<y;a++)x.items[a].loose=!0;return x}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):wt(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:Qc(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
|
|
49
49
|
`):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=Qc(r.rows[s],r.header.length).map(u=>({text:u}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
|
|
50
|
-
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:wt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):wt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Mo(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=fv(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),tu(n,{href:o&&o.replace(this.rules.inline._escapes,"$1"),title:s&&s.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(t,n){let r;if((r=this.rules.inline.reflink.exec(t))||(r=this.rules.inline.nolink.exec(t))){let o=(r[2]||r[1]).replace(/\s+/g," ");if(o=n[o.toLowerCase()],!o){const s=r[0].charAt(0);return{type:"text",raw:s,text:s}}return tu(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,u=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){u+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(u-=l,u>0)continue;l=Math.min(l,l+u+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const w=h.slice(1,-1);return{type:"em",raw:h,text:w,tokens:this.lexer.inlineTokens(w)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=wt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=wt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=wt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=wt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=wt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):wt(r[0]):r[0]:o=wt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const
|
|
51
|
-
]`).replace("lheading",
|
|
50
|
+
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:wt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):wt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Mo(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=fv(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),tu(n,{href:o&&o.replace(this.rules.inline._escapes,"$1"),title:s&&s.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(t,n){let r;if((r=this.rules.inline.reflink.exec(t))||(r=this.rules.inline.nolink.exec(t))){let o=(r[2]||r[1]).replace(/\s+/g," ");if(o=n[o.toLowerCase()],!o){const s=r[0].charAt(0);return{type:"text",raw:s,text:s}}return tu(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,u=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){u+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(u-=l,u>0)continue;l=Math.min(l,l+u+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const w=h.slice(1,-1);return{type:"em",raw:h,text:w,tokens:this.lexer.inlineTokens(w)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=wt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=wt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=wt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=wt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=wt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):wt(r[0]):r[0]:o=wt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const pe={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:Oo,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};pe._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,pe._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,pe.def=Ye(pe.def).replace("label",pe._label).replace("title",pe._title).getRegex(),pe.bullet=/(?:[*+-]|\d{1,9}[.)])/,pe.listItemStart=Ye(/^( *)(bull) */).replace("bull",pe.bullet).getRegex(),pe.list=Ye(pe.list).replace(/bull/g,pe.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+pe.def.source+")").getRegex(),pe._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",pe._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,pe.html=Ye(pe.html,"i").replace("comment",pe._comment).replace("tag",pe._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),pe.paragraph=Ye(pe._paragraph).replace("hr",pe.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",pe._tag).getRegex(),pe.blockquote=Ye(pe.blockquote).replace("paragraph",pe.paragraph).getRegex(),pe.normal={...pe},pe.gfm={...pe.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},pe.gfm.table=Ye(pe.gfm.table).replace("hr",pe.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",pe._tag).getRegex(),pe.gfm.paragraph=Ye(pe._paragraph).replace("hr",pe.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",pe.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",pe._tag).getRegex(),pe.pedantic={...pe.normal,html:Ye(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",pe._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Oo,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Ye(pe.normal._paragraph).replace("hr",pe.hr).replace("heading",` *#{1,6} *[^
|
|
51
|
+
]`).replace("lheading",pe.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ne={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Oo,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:Oo,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ne._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ne.punctuation=Ye(ne.punctuation).replace(/punctuation/g,ne._punctuation).getRegex(),ne.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ne.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ne._comment=Ye(pe._comment).replace("(?:-->|$)","-->").getRegex(),ne.emStrong.lDelim=Ye(ne.emStrong.lDelim).replace(/punct/g,ne._punctuation).getRegex(),ne.emStrong.rDelimAst=Ye(ne.emStrong.rDelimAst,"g").replace(/punct/g,ne._punctuation).getRegex(),ne.emStrong.rDelimUnd=Ye(ne.emStrong.rDelimUnd,"g").replace(/punct/g,ne._punctuation).getRegex(),ne._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,ne._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,ne._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,ne.autolink=Ye(ne.autolink).replace("scheme",ne._scheme).replace("email",ne._email).getRegex(),ne._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,ne.tag=Ye(ne.tag).replace("comment",ne._comment).replace("attribute",ne._attribute).getRegex(),ne._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ne._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ne._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ne.link=Ye(ne.link).replace("label",ne._label).replace("href",ne._href).replace("title",ne._title).getRegex(),ne.reflink=Ye(ne.reflink).replace("label",ne._label).replace("ref",pe._label).getRegex(),ne.nolink=Ye(ne.nolink).replace("ref",pe._label).getRegex(),ne.reflinkSearch=Ye(ne.reflinkSearch,"g").replace("reflink",ne.reflink).replace("nolink",ne.nolink).getRegex(),ne.normal={...ne},ne.pedantic={...ne.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:Ye(/^!?\[(label)\]\((.*?)\)/).replace("label",ne._label).getRegex(),reflink:Ye(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ne._label).getRegex()},ne.gfm={...ne.normal,escape:Ye(ne.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},ne.gfm.url=Ye(ne.gfm.url,"i").replace("email",ne.gfm._extended_email).getRegex(),ne.breaks={...ne.gfm,br:Ye(ne.br).replace("{2,}","*").getRegex(),text:Ye(ne.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function mv(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")}function nu(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class Cn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Hn,this.options.tokenizer=this.options.tokenizer||new Ii,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:pe.normal,inline:ne.normal};this.options.pedantic?(n.block=pe.pedantic,n.inline=ne.pedantic):this.options.gfm&&(n.block=pe.gfm,this.options.breaks?n.inline=ne.breaks:n.inline=ne.gfm),this.tokenizer.rules=n}static get rules(){return{block:pe,inline:ne}}static lex(t,n){return new Cn(n).lex(t)}static lexInline(t,n){return new Cn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
|
|
52
52
|
`),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,u)=>l+" ".repeat(u.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
|
|
53
53
|
`:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
|
|
54
54
|
`+r.raw,o.text+=`
|
|
@@ -80,7 +80,7 @@ ${t}</tr>
|
|
|
80
80
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
81
81
|
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=Zc(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o='<a href="'+t+'"';return n&&(o+=' title="'+n+'"'),o+=">"+r+"</a>",o}image(t,n,r){if(t=Zc(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o=`<img src="${t}" alt="${r}"`;return n&&(o+=` title="${n}"`),o+=this.options.xhtml?"/>":">",o}text(t){return t}}class ru{strong(t){return t}em(t){return t}codespan(t){return t}del(t){return t}html(t){return t}text(t){return t}link(t,n,r){return""+r}image(t,n,r){return""+r}br(){return""}}class ou{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class Tn{constructor(t){this.options=t||Hn,this.options.renderer=this.options.renderer||new Ni,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ru,this.slugger=new ou}static parse(t,n){return new Tn(n).parse(t)}static parseInline(t,n){return new Tn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,u,d,f,h,p,w,v,g,x,b,y,E,C,T;const I=t.length;for(o=0;o<I;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(T=this.options.extensions.renderers[p.type].call({parser:this},p),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=T||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,Jc(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(u=p.rows[s],d="",l=u.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(u[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(w=p.ordered,v=p.start,g=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],y=b.checked,E=b.task,x="",b.task&&(C=this.renderer.checkbox(y),g?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):x+=C),x+=this.parse(b.tokens,g),h+=this.renderer.listitem(x,E,y);r+=this.renderer.list(h,w,v);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<I&&t[o+1].type==="text";)p=t[++o],h+=`
|
|
82
82
|
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Do{constructor(t){this.options=t||Hn}preprocess(t){return t}postprocess(t){return t}}xp(Do,"passThroughHooks",new Set(["preprocess","postprocess"]));function gv(e,t,n){return r=>{if(r.message+=`
|
|
83
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+wt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function su(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ge.defaults,...s};const i=gv(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(hv(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&ge.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;ge.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ge.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&ge.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ge(e,t,n){return su(Cn.lex,Tn.parse)(e,t,n)}ge.options=ge.setOptions=function(e){return ge.defaults={...ge.defaults,...e},ev(ge.defaults),ge},ge.getDefaults=qc,ge.defaults=Hn,ge.use=function(...e){const t=ge.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ge.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=ge.defaults.renderer||new Ni;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=ge.defaults.tokenizer||new Ii;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=ge.defaults.hooks||new Do;for(const s in n.hooks){const i=o[s];Do.passThroughHooks.has(s)?o[s]=a=>{if(ge.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=ge.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}ge.setOptions(r)})},ge.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ge,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ge.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ge.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ge.walkTokens(r.items,t));break}default:ge.defaults.extensions&&ge.defaults.extensions.childTokens&&ge.defaults.extensions.childTokens[r.type]?ge.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ge.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ge.walkTokens(r.tokens,t)))}return n},ge.parseInline=su(Cn.lexInline,Tn.parseInline),ge.Parser=Tn,ge.parser=Tn.parse,ge.Renderer=Ni,ge.TextRenderer=ru,ge.Lexer=Cn,ge.lexer=Cn.lex,ge.Tokenizer=Ii,ge.Slugger=ou,ge.Hooks=Do,ge.parse=ge,ge.options,ge.setOptions,ge.use,ge.walkTokens,ge.parseInline,Tn.parse,Cn.lex;function Ai({content:e,className:t="",allowHtml:n=!1}){const r=S.useMemo(()=>{try{if(!n){const o=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return ge.parse(o)}return ge.parse(e)}catch(o){return console.error("[MarkdownContent] parse error",o),`<pre>Error rendering markdown: ${String(o)}</pre>`}},[e,n]);return c.jsx("div",{className:X("markdown prose max-w-none break-words dark:prose-invert",t),dangerouslySetInnerHTML:{__html:r}})}async function iu(e,t){return await At(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function au(e,t){return await(await iu(`/files/${e}/view`,t)).text()}async function xv(e,t){const n=await iu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await At(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function vv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await At("/files",{params:r})}const wv=1,bv=1e6;let ji=0;function yv(){return ji=(ji+1)%Number.MAX_SAFE_INTEGER,ji.toString()}const _i=new Map,lu=e=>{if(_i.has(e))return;const t=setTimeout(()=>{_i.delete(e),Br({type:"REMOVE_TOAST",toastId:e})},bv);_i.set(e,t)},Sv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,wv)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?lu(n):e.toasts.forEach(r=>{lu(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},Lo=[];let Fo={toasts:[]};function Br(e){Fo=Sv(Fo,e),Lo.forEach(t=>{t(Fo)})}function Cv({...e}){const t=yv(),n=o=>Br({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Br({type:"DISMISS_TOAST",toastId:t});return Br({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ri(){const[e,t]=m.useState(Fo);return m.useEffect(()=>(Lo.push(t),()=>{const n=Lo.indexOf(t);n>-1&&Lo.splice(n,1)}),[e]),{...e,toast:Cv,dismiss:n=>Br({type:"DISMISS_TOAST",toastId:n})}}function mt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Tv(e,t=globalThis==null?void 0:globalThis.document){const n=mt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var kv="DismissableLayer",Pi="dismissableLayer.update",Ev="dismissableLayer.pointerDownOutside",Iv="dismissableLayer.focusOutside",cu,uu=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),$o=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(uu),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),w=Oe(t,I=>f(I)),v=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=v.indexOf(g),b=d?v.indexOf(d):-1,y=u.layersWithOutsidePointerEventsDisabled.size>0,E=b>=x,C=jv(I=>{const A=I.target,R=[...u.branches].some(j=>j.contains(A));!E||R||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),T=_v(I=>{const A=I.target;[...u.branches].some(j=>j.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return Tv(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(cu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),du(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=cu)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),du())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(Pi,I),()=>document.removeEventListener(Pi,I)},[]),c.jsx(Se.div,{...l,ref:w,style:{pointerEvents:y?E?"auto":"none":void 0,...e.style},onFocusCapture:se(e.onFocusCapture,T.onFocusCapture),onBlurCapture:se(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:se(e.onPointerDownCapture,C.onPointerDownCapture)})});$o.displayName=kv;var Nv="DismissableLayerBranch",Av=m.forwardRef((e,t)=>{const n=m.useContext(uu),r=m.useRef(null),o=Oe(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Se.div,{...e,ref:o})});Av.displayName=Nv;function jv(e,t=globalThis==null?void 0:globalThis.document){const n=mt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){fu(Ev,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function _v(e,t=globalThis==null?void 0:globalThis.document){const n=mt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&fu(Iv,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function du(){const e=new CustomEvent(Pi);document.dispatchEvent(e)}function fu(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?$c(o,s):o.dispatchEvent(s)}var Oi="focusScope.autoFocusOnMount",Mi="focusScope.autoFocusOnUnmount",hu={bubbles:!1,cancelable:!0},Rv="FocusScope",zo=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=mt(o),d=mt(s),f=m.useRef(null),h=Oe(t,v=>l(v)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let v=function(y){if(p.paused||!a)return;const E=y.target;a.contains(E)?f.current=E:kn(f.current,{select:!0})},g=function(y){if(p.paused||!a)return;const E=y.relatedTarget;E!==null&&(a.contains(E)||kn(f.current,{select:!0}))},x=function(y){if(document.activeElement===document.body)for(const C of y)C.removedNodes.length>0&&kn(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",g);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){gu.add(p);const v=document.activeElement;if(!a.contains(v)){const x=new CustomEvent(Oi,hu);a.addEventListener(Oi,u),a.dispatchEvent(x),x.defaultPrevented||(Pv(Fv(pu(a)),{select:!0}),document.activeElement===v&&kn(a))}return()=>{a.removeEventListener(Oi,u),setTimeout(()=>{const x=new CustomEvent(Mi,hu);a.addEventListener(Mi,d),a.dispatchEvent(x),x.defaultPrevented||kn(v??document.body,{select:!0}),a.removeEventListener(Mi,d),gu.remove(p)},0)}}},[a,u,d,p]);const w=m.useCallback(v=>{if(!n&&!r||p.paused)return;const g=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(g&&x){const b=v.currentTarget,[y,E]=Ov(b);y&&E?!v.shiftKey&&x===E?(v.preventDefault(),n&&kn(y,{select:!0})):v.shiftKey&&x===y&&(v.preventDefault(),n&&kn(E,{select:!0})):x===b&&v.preventDefault()}},[n,r,p.paused]);return c.jsx(Se.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});zo.displayName=Rv;function Pv(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(kn(r,{select:t}),document.activeElement!==n)return}function Ov(e){const t=pu(e),n=mu(t,e),r=mu(t.reverse(),e);return[n,r]}function pu(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function mu(e,t){for(const n of e)if(!Mv(n,{upTo:t}))return n}function Mv(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Dv(e){return e instanceof HTMLInputElement&&"select"in e}function kn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Dv(e)&&t&&e.select()}}var gu=Lv();function Lv(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=xu(e,t),e.unshift(t)},remove(t){var n;e=xu(e,t),(n=e[0])==null||n.resume()}}}function xu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Fv(e){return e.filter(t=>t.tagName!=="A")}var $v="Portal",Bo=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);pt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Rs.createPortal(c.jsx(Se.div,{...r,ref:t}),i):null});Bo.displayName=$v;var Di=0;function Li(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??vu()),document.body.insertAdjacentElement("beforeend",e[1]??vu()),Di++,()=>{Di===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Di--}},[])}function vu(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var on=function(){return on=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},on.apply(this,arguments)};function wu(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function zv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var Ho="right-scroll-bar-position",Uo="width-before-scroll-bar",Bv="with-scroll-bars-hidden",Hv="--removed-body-scroll-bar-size";function Fi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Uv(e,t){var n=S.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var Wv=typeof window<"u"?m.useLayoutEffect:m.useEffect,bu=new WeakMap;function Vv(e,t){var n=Uv(null,function(r){return e.forEach(function(o){return Fi(o,r)})});return Wv(function(){var r=bu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Fi(a,null)}),s.forEach(function(a){o.has(a)||Fi(a,i)})}bu.set(n,e)},[e]),n}function Kv(e){return e}function qv(e,t){t===void 0&&(t=Kv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function Gv(e){e===void 0&&(e={});var t=qv(null);return t.options=on({async:!0,ssr:!1},e),t}var yu=function(e){var t=e.sideCar,n=wu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,on({},n))};yu.isSideCarExport=!0;function Yv(e,t){return e.useMedium(t),yu}var Su=Gv(),$i=function(){},Wo=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:$i,onWheelCapture:$i,onTouchMoveCapture:$i}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,w=e.noIsolation,v=e.inert,g=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,y=e.gapMode,E=wu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,T=Vv([n,t]),I=on(on({},E),o);return m.createElement(m.Fragment,null,d&&m.createElement(C,{sideCar:Su,removeScrollBar:u,shards:f,noRelative:p,noIsolation:w,inert:v,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:y}),i?m.cloneElement(m.Children.only(a),on(on({},I),{ref:T})):m.createElement(b,on({},I,{className:l,ref:T}),a))});Wo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Wo.classNames={fullWidth:Uo,zeroRight:Ho};var Xv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Jv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Xv();return t&&e.setAttribute("nonce",t),e}function Zv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Qv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var ew=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Jv())&&(Zv(t,n),Qv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},tw=function(){var e=ew();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Cu=function(){var e=tw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},nw={left:0,top:0,right:0,gap:0},zi=function(e){return parseInt(e||"",10)||0},rw=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[zi(n),zi(r),zi(o)]},ow=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return nw;var t=rw(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},sw=Cu(),lr="data-scroll-locked",iw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
83
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+wt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function su(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=gv(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(hv(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&me.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;me.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(me.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&me.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function me(e,t,n){return su(Cn.lex,Tn.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},ev(me.defaults),me},me.getDefaults=qc,me.defaults=Hn,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=me.defaults.renderer||new Ni;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=me.defaults.tokenizer||new Ii;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=me.defaults.hooks||new Do;for(const s in n.hooks){const i=o[s];Do.passThroughHooks.has(s)?o[s]=a=>{if(me.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=me.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=su(Cn.lexInline,Tn.parseInline),me.Parser=Tn,me.parser=Tn.parse,me.Renderer=Ni,me.TextRenderer=ru,me.Lexer=Cn,me.lexer=Cn.lex,me.Tokenizer=Ii,me.Slugger=ou,me.Hooks=Do,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,Tn.parse,Cn.lex;function Ai({content:e,className:t="",allowHtml:n=!1}){const r=S.useMemo(()=>{try{if(!n){const o=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return me.parse(o)}return me.parse(e)}catch(o){return console.error("[MarkdownContent] parse error",o),`<pre>Error rendering markdown: ${String(o)}</pre>`}},[e,n]);return c.jsx("div",{className:X("markdown prose max-w-none break-words dark:prose-invert",t),dangerouslySetInnerHTML:{__html:r}})}async function iu(e,t){return await At(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function au(e,t){return await(await iu(`/files/${e}/view`,t)).text()}async function xv(e,t){const n=await iu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await At(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function vv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await At("/files",{params:r})}const wv=1,bv=1e6;let ji=0;function yv(){return ji=(ji+1)%Number.MAX_SAFE_INTEGER,ji.toString()}const _i=new Map,lu=e=>{if(_i.has(e))return;const t=setTimeout(()=>{_i.delete(e),Br({type:"REMOVE_TOAST",toastId:e})},bv);_i.set(e,t)},Sv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,wv)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?lu(n):e.toasts.forEach(r=>{lu(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},Lo=[];let Fo={toasts:[]};function Br(e){Fo=Sv(Fo,e),Lo.forEach(t=>{t(Fo)})}function Cv({...e}){const t=yv(),n=o=>Br({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Br({type:"DISMISS_TOAST",toastId:t});return Br({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ri(){const[e,t]=m.useState(Fo);return m.useEffect(()=>(Lo.push(t),()=>{const n=Lo.indexOf(t);n>-1&&Lo.splice(n,1)}),[e]),{...e,toast:Cv,dismiss:n=>Br({type:"DISMISS_TOAST",toastId:n})}}function mt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Tv(e,t=globalThis==null?void 0:globalThis.document){const n=mt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var kv="DismissableLayer",Pi="dismissableLayer.update",Ev="dismissableLayer.pointerDownOutside",Iv="dismissableLayer.focusOutside",cu,uu=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),$o=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(uu),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),w=Oe(t,I=>f(I)),v=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=v.indexOf(g),b=d?v.indexOf(d):-1,y=u.layersWithOutsidePointerEventsDisabled.size>0,E=b>=x,C=jv(I=>{const A=I.target,R=[...u.branches].some(j=>j.contains(A));!E||R||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),T=_v(I=>{const A=I.target;[...u.branches].some(j=>j.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return Tv(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(cu=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),du(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=cu)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),du())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(Pi,I),()=>document.removeEventListener(Pi,I)},[]),c.jsx(Se.div,{...l,ref:w,style:{pointerEvents:y?E?"auto":"none":void 0,...e.style},onFocusCapture:se(e.onFocusCapture,T.onFocusCapture),onBlurCapture:se(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:se(e.onPointerDownCapture,C.onPointerDownCapture)})});$o.displayName=kv;var Nv="DismissableLayerBranch",Av=m.forwardRef((e,t)=>{const n=m.useContext(uu),r=m.useRef(null),o=Oe(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Se.div,{...e,ref:o})});Av.displayName=Nv;function jv(e,t=globalThis==null?void 0:globalThis.document){const n=mt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){fu(Ev,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function _v(e,t=globalThis==null?void 0:globalThis.document){const n=mt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&fu(Iv,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function du(){const e=new CustomEvent(Pi);document.dispatchEvent(e)}function fu(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?$c(o,s):o.dispatchEvent(s)}var Oi="focusScope.autoFocusOnMount",Mi="focusScope.autoFocusOnUnmount",hu={bubbles:!1,cancelable:!0},Rv="FocusScope",zo=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=mt(o),d=mt(s),f=m.useRef(null),h=Oe(t,v=>l(v)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let v=function(y){if(p.paused||!a)return;const E=y.target;a.contains(E)?f.current=E:kn(f.current,{select:!0})},g=function(y){if(p.paused||!a)return;const E=y.relatedTarget;E!==null&&(a.contains(E)||kn(f.current,{select:!0}))},x=function(y){if(document.activeElement===document.body)for(const C of y)C.removedNodes.length>0&&kn(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",g);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){gu.add(p);const v=document.activeElement;if(!a.contains(v)){const x=new CustomEvent(Oi,hu);a.addEventListener(Oi,u),a.dispatchEvent(x),x.defaultPrevented||(Pv(Fv(pu(a)),{select:!0}),document.activeElement===v&&kn(a))}return()=>{a.removeEventListener(Oi,u),setTimeout(()=>{const x=new CustomEvent(Mi,hu);a.addEventListener(Mi,d),a.dispatchEvent(x),x.defaultPrevented||kn(v??document.body,{select:!0}),a.removeEventListener(Mi,d),gu.remove(p)},0)}}},[a,u,d,p]);const w=m.useCallback(v=>{if(!n&&!r||p.paused)return;const g=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(g&&x){const b=v.currentTarget,[y,E]=Ov(b);y&&E?!v.shiftKey&&x===E?(v.preventDefault(),n&&kn(y,{select:!0})):v.shiftKey&&x===y&&(v.preventDefault(),n&&kn(E,{select:!0})):x===b&&v.preventDefault()}},[n,r,p.paused]);return c.jsx(Se.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});zo.displayName=Rv;function Pv(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(kn(r,{select:t}),document.activeElement!==n)return}function Ov(e){const t=pu(e),n=mu(t,e),r=mu(t.reverse(),e);return[n,r]}function pu(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function mu(e,t){for(const n of e)if(!Mv(n,{upTo:t}))return n}function Mv(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Dv(e){return e instanceof HTMLInputElement&&"select"in e}function kn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Dv(e)&&t&&e.select()}}var gu=Lv();function Lv(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=xu(e,t),e.unshift(t)},remove(t){var n;e=xu(e,t),(n=e[0])==null||n.resume()}}}function xu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Fv(e){return e.filter(t=>t.tagName!=="A")}var $v="Portal",Bo=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);pt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Rs.createPortal(c.jsx(Se.div,{...r,ref:t}),i):null});Bo.displayName=$v;var Di=0;function Li(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??vu()),document.body.insertAdjacentElement("beforeend",e[1]??vu()),Di++,()=>{Di===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Di--}},[])}function vu(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var on=function(){return on=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},on.apply(this,arguments)};function wu(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function zv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var Ho="right-scroll-bar-position",Uo="width-before-scroll-bar",Bv="with-scroll-bars-hidden",Hv="--removed-body-scroll-bar-size";function Fi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Uv(e,t){var n=S.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var Wv=typeof window<"u"?m.useLayoutEffect:m.useEffect,bu=new WeakMap;function Vv(e,t){var n=Uv(null,function(r){return e.forEach(function(o){return Fi(o,r)})});return Wv(function(){var r=bu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Fi(a,null)}),s.forEach(function(a){o.has(a)||Fi(a,i)})}bu.set(n,e)},[e]),n}function Kv(e){return e}function qv(e,t){t===void 0&&(t=Kv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function Gv(e){e===void 0&&(e={});var t=qv(null);return t.options=on({async:!0,ssr:!1},e),t}var yu=function(e){var t=e.sideCar,n=wu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,on({},n))};yu.isSideCarExport=!0;function Yv(e,t){return e.useMedium(t),yu}var Su=Gv(),$i=function(){},Wo=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:$i,onWheelCapture:$i,onTouchMoveCapture:$i}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,w=e.noIsolation,v=e.inert,g=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,y=e.gapMode,E=wu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,T=Vv([n,t]),I=on(on({},E),o);return m.createElement(m.Fragment,null,d&&m.createElement(C,{sideCar:Su,removeScrollBar:u,shards:f,noRelative:p,noIsolation:w,inert:v,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:y}),i?m.cloneElement(m.Children.only(a),on(on({},I),{ref:T})):m.createElement(b,on({},I,{className:l,ref:T}),a))});Wo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Wo.classNames={fullWidth:Uo,zeroRight:Ho};var Xv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Jv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Xv();return t&&e.setAttribute("nonce",t),e}function Zv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Qv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var ew=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Jv())&&(Zv(t,n),Qv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},tw=function(){var e=ew();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Cu=function(){var e=tw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},nw={left:0,top:0,right:0,gap:0},zi=function(e){return parseInt(e||"",10)||0},rw=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[zi(n),zi(r),zi(o)]},ow=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return nw;var t=rw(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},sw=Cu(),lr="data-scroll-locked",iw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
84
84
|
.`.concat(Bv,` {
|
|
85
85
|
overflow: hidden `).concat(r,`;
|
|
86
86
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -126,9 +126,9 @@ If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHid
|
|
|
126
126
|
|
|
127
127
|
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Rw="DialogDescriptionWarning",Pw=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${qu(Rw).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Gu=Pu,Ow=Mu,Yu=Lu,Zo=Fu,Qo=$u,Wn=Bu,es=Uu,Xu=Vu;const Mw=Gu,Dw=Yu,Ju=m.forwardRef(({className:e,...t},n)=>c.jsx(Zo,{ref:n,className:X("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}));Ju.displayName=Zo.displayName;const Zu=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const u=l.type;if(u===Wn||(u==null?void 0:u.displayName)===Wn.displayName||(u==null?void 0:u.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return c.jsxs(Dw,{children:[c.jsx(Ju,{}),c.jsxs(Qo,{ref:r,className:X("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&c.jsx(Wn,{className:"sr-only",children:"Dialog"}),t,c.jsxs(Xu,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[c.jsx(Q.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Zu.displayName=Qo.displayName;const Qu=({className:e,...t})=>c.jsx("div",{className:X("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Qu.displayName="DialogHeader";const ed=m.forwardRef(({className:e,...t},n)=>c.jsx(Wn,{ref:n,className:X("text-lg font-semibold leading-none tracking-tight",e),...t}));ed.displayName=Wn.displayName;const Lw=m.forwardRef(({className:e,...t},n)=>c.jsx(es,{ref:n,className:X("text-sm text-muted-foreground",e),...t}));Lw.displayName=es.displayName;function Fw({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=S.useState(!1),[a,l]=S.useState(null),[u,d]=S.useState(null),{toast:f}=Ri(),h=S.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await au(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);S.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await xv(n),f({title:"Download started",description:`Downloading ${r}`})}catch(x){console.error("Failed to download file:",x),f({title:"Download failed",description:String(x),variant:"destructive"})}},w=async()=>{if(n)try{const x=await au(n),b=new Blob([x],{type:o}),y=URL.createObjectURL(b);window.open(y,"_blank"),URL.revokeObjectURL(y)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},v=()=>s?c.jsxs("div",{className:"flex items-center justify-center py-12",children:[c.jsx(Q.Loader,{className:"h-8 w-8 animate-spin mr-3"}),c.jsx("span",{children:"Loading file..."})]}):u?c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),c.jsx("p",{className:"text-red-600 mb-4",children:u}),c.jsx(Be,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?c.jsx("div",{className:"flex justify-center",children:c.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?c.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:c.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?c.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:c.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx(Q.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),c.jsx("p",{className:"text-lg font-medium mb-2",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),g=()=>o.startsWith("image/")?c.jsx(Q.Image,{className:"h-5 w-5"}):c.jsx(Q.FileText,{className:"h-5 w-5"});return c.jsx(Mw,{open:e,onOpenChange:t,children:c.jsxs(Zu,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(Qu,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[g(),c.jsxs("div",{children:[c.jsx(ed,{className:"text-left",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Be,{variant:"outline",size:"sm",onClick:w,className:"flex items-center gap-2",children:[c.jsx(Q.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(Be,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(Q.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:v()})]})})}function td(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function nd(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Hr(e){if(typeof e=="string")return e.length>2e3?e.slice(0,2e3)+"... [truncated]":e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Hr).filter(r=>r!==void 0);return n.length?n:void 0}if(nd(e))return;const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=Hr(r);o!==void 0&&(t[n]=o)}}return Object.keys(t).length?t:void 0}return e}function qi(e){if(typeof e=="string")return e;if(nd(e))return"";try{const t=Hr(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function rd(e){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){if(e.desirability||e.feasibility||e.viability||e.other)return{desirability:Array.isArray(e.desirability)?e.desirability:[],feasibility:Array.isArray(e.feasibility)?e.feasibility:[],viability:Array.isArray(e.viability)?e.viability:[],other:Array.isArray(e.other)?e.other:[]};if(e.output&&typeof e.output!="object")e=e.output;else if(e.output&&typeof e.output=="object")return rd(e.output)}const t=String(e),n={desirability:[],feasibility:[],viability:[],other:[]};let r=t;const o=Math.min(...["desirability=","feasibility=","viability=","other="].map(i=>{const a=r.toLowerCase().indexOf(i);return a===-1?Number.MAX_SAFE_INTEGER:a}));o!==Number.MAX_SAFE_INTEGER&&(r=r.slice(o));for(const i of Object.keys(n)){const l=new RegExp(i+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const u=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let f=null;for(;(f=d.exec(u))!==null;){const h=f[1],p=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(h),w=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(h),v=p?p[2].trim():"",g=w?w[2].trim():"";n[i].push({title:v,description:g})}}return Object.values(n).some(i=>i.length>0)?n:null}const ts="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words",Vn=1e5;function $w(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function zw(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function Bw(e){const t=e.filter(r=>r.type==="tool_call");return e.filter(r=>r.type==="tool_end").map(r=>{var o;return{name:(o=t.find(s=>s.id===r.toolCallId))==null?void 0:o.name,toolCallId:r.toolCallId,output:r.output}})}function Hw(e){const t=(r,o=Vn)=>{try{const s=Hr(r),i=typeof s=="string"?s:JSON.stringify(s??"");return i.length<=o?i:i.slice(0,o)+`
|
|
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 Uw(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 Ww(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function od(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 Vw({className:e}){const[t,n]=S.useState(0);return S.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),c.jsxs("span",{"aria-live":"polite",className:X("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const sd=S.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateToolMessages:u=!0,toolMessagePreviewLength:d=200,truncateUserMessages:f=!0,userMessagePreviewLength:h=200,customStyles:p={},onEdit:w,onRegenerate:v,onCancelEdit:g,onCopy:x}){const[b,y]=S.useState(!1),[E,C]=S.useState("collapsed"),[T,I]=S.useState(!1),{currentThreadId:A}=mo(),{handleInterrupt:R}=Zs(),{toast:j}=Ri(),[M,D]=S.useState({}),[L,P]=S.useState(!1),[W,H]=S.useState(null),q=l==="phone"||l==="half-screen",F=t.role,N=F==="tool",U=!(r&&F!=="user"),Y=S.useMemo(()=>{switch(F){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[F]),fe=S.useMemo(()=>$w(t.content),[t.content]),ie=S.useMemo(()=>zw(t.content),[t.content]),he=S.useMemo(()=>t.content.filter(Z=>Z.type==="image_url"),[t.content]),Ee=S.useMemo(()=>t.content.filter(Z=>Z.type==="file"),[t.content]),de=S.useMemo(()=>t.content.filter(Z=>Z.type==="interrupt"),[t.content]),z=S.useMemo(()=>Hw(t.content),[t.content]);S.useMemo(()=>Uw(t.content),[t.content]);const O=S.useMemo(()=>z.length<=Vn?z:`${z.slice(0,Vn)}
|
|
129
|
-
… [truncated ${z.length-Vn} chars]`,[z]),
|
|
130
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[M[le]?c.jsx(Q.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[Ce,M[le]?" (processing)":""]})]},le)}return Z.type==="interrupt"?c.jsx(Gw,{interruptPart:Z,onApprove:ye,onReject:Pe},le):null},[
|
|
131
|
-
… [truncated ${we.length-Vn} chars]`:we,Ze=E==="expanded";return c.jsxs(Uc,{open:Ze,onOpenChange:Ue=>C(Ue?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(Si,{variant:"outline",children:(xe.name??"tool")+(xe.toolCallId?` • ${xe.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Ze?je:je.slice(0,d)+(je.length>d?"...":"")})}),c.jsx(Wc,{asChild:!0,children:c.jsx(Be,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Ze?c.jsxs(c.Fragment,{children:[" ",c.jsx(Q.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(Q.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},xe.toolCallId??Ce)})})}if(!N){const le=c.jsx("div",{className:"space-y-2",children:t.content.map((xe,Ce)=>c.jsx(Je,{part:xe,i:Ce},Ce))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[le,c.jsx(Vw,{className:Y})]}):le}},[fe,he.length,Ee.length,de.length,r,t.model,N,ie.name,z,E,u,$e,Y]),lt=S.useMemo(()=>Ww(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:X(Xe(),p.container),children:c.jsxs("div",{className:X(et(),p.content),children:[(i||a||N)&&c.jsxs("div",{className:X("flex items-center justify-between mb-2 pb-2 border-b border-current/10",q&&"mb-1 pb-1",Y,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[Fe(),a&<&&c.jsx("span",{className:X("font-medium",q?"text-xs":"text-sm"),children:lt}),N&&ie.name&&c.jsxs(Si,{variant:"outline",className:X("text-xs flex items-center gap-1 cursor-pointer",Y,"border border-current/40",q&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E!=="collapsed",onKeyDown:Z=>{(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),C(le=>le==="collapsed"?"preview":"collapsed"))},onClick:()=>C(Z=>Z==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:ie.name}),c.jsx("span",{className:"inline-flex items-center",children:E!=="collapsed"?c.jsx(Q.ChevronUp,{className:"h-3 w-3"}):c.jsx(Q.ChevronDown,{className:"h-3 w-3"})})]}),N&&!ie.name&&c.jsx(Be,{variant:"ghost",size:"sm",className:X("h-6 px-1",Y,"hover:bg-foreground/10"),onClick:()=>C(Z=>Z==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",E!=="collapsed"?c.jsx(Q.ChevronUp,{className:"h-3 w-3"}):c.jsx(Q.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:X("text-xs opacity-60",Y,q&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:X("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>V(N?"visible":"all"),className:X("h-6 w-6 p-0 hover:bg-foreground/10",Y,q&&"h-5 w-5"),"aria-label":N?"Copy visible":"Copy message",title:N?"Copy visible portion":"Copy message",children:c.jsx(Q.Copy,{className:X(b?"text-success":Y,q?"h-3 w-3":"h-4 w-4")})}),N&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>V("all"),className:X("h-6 px-1 text-xs hover:bg-foreground/10",Y),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),F==="user"&&w&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:J,className:X("h-6 w-6 p-0 hover:bg-foreground/10",Y,q&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(Q.Edit,{className:X(Y,q?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&v&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:ae,className:X("h-6 w-6 p-0 hover:bg-foreground/10",Y,q&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(Q.RotateCcw,{className:X(Y,q?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:st()}),N&&E==="expanded"&&(ie.toolCallId||ie.name)&&c.jsxs("div",{className:X("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",q&&"text-xs"),children:[ie.name&&c.jsxs("div",{children:["Function: ",ie.name]}),ie.toolCallId&&c.jsxs("div",{children:["Call ID: ",ie.toolCallId]})]}),!(i||a||N)&&s&&!o&&c.jsxs("div",{className:X("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>V(),className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(Q.Copy,{className:X(b?"text-success":"text-current",q?"h-3 w-3":"h-4 w-4")})}),F==="user"&&w&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:J,className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(Q.Edit,{className:X("text-current",q?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&v&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:ae,className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(Q.RotateCcw,{className:X("text-current",q?"h-3 w-3":"h-4 w-4")})})]})]})}),W&&c.jsx(Fw,{isOpen:L,onClose:()=>{P(!1),H(null)},fileId:W.id,fileName:W.name,mimeType:W.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&od(e.message)===od(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)&&((l=e.customStyles)==null?void 0:l.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)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function Kw({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:ts,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:qi(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 c.jsxs("div",{className:ts,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:ts,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:qw(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:qi(e)})}function qw(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 c.jsx("code",{className:"text-xs",children:JSON.stringify(Hr(e))})}catch{return String(e)}}function Gw({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(Fr,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs($r,{className:"pb-3",children:[c.jsx(zr,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(Vc,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Kc,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Be,{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"}),c.jsx(Be,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function Yw({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function Xw({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:ts,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const id=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Gi=S.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:w=!0,isNavigatingCheckpoint:v=!1,onScrollAway:g,onAtBottom:x},b)=>{const y=S.useRef(null),E=S.useRef(null),C=S.useRef(!1),[T,I]=S.useState(!0),A=S.useCallback(M=>{I(M),g&&g(!M),x&&x(M)},[g,x]),R=S.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),j=S.useMemo(()=>!w||v?!1:T?"auto":!1,[T,w,v]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Sx,{ref:M=>{y.current=M},scrollerRef:M=>{E.current=M instanceof HTMLDivElement?M:null},data:e,followOutput:j,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{R&&R()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(M,D)=>id(D,M),itemContent:(M,D)=>{const L=id(D,M);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":L,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(sd,{message:D,messageIndex:M,isStreamingMessage:t&&n===D.id,streamingDebounceMs:r,isEditing:i===D.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(M),onCancelEdit:d})})}})})});Gi.displayName="MessageList";const ns=1e4;function Jw(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,`
|
|
129
|
+
… [truncated ${z.length-Vn} chars]`,[z]),K=S.useCallback(async(Z="all")=>{const ge=Z==="visible"&&N?O:N?z:fe;async function Ce(we){try{await navigator.clipboard.writeText(we)}catch{try{const je=document.createElement("textarea");je.value=we,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 Ce(ge),y(!0),setTimeout(()=>y(!1),2e3),x==null||x(ge)}catch(we){console.error("Failed to copy:",we)}},[N,z,fe,O,x]),J=S.useCallback(()=>{if(!w)return;const Z=N?z:fe;w(t.id,Z)},[w,t.id,N,z,fe]),ae=S.useCallback(()=>{v==null||v(n)},[v,n]),re=S.useCallback(async(Z,le,ge)=>{if(!U){Z.preventDefault();return}if(M[ge]){Z.preventDefault();return}try{const Ce=String(le.url??""),we=Ce.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(we){Z.preventDefault();const je=we[1],Ze=le.name||`file_${je}`,Ue=le.mimeType||"application/octet-stream";H({id:je,name:Ze,mimeType:Ue}),P(!0);return}if(Ce.startsWith("data:")){Z.preventDefault(),D(Ue=>({...Ue,[ge]:!0}));const je=`${le.name}_${le.size}_${Date.now()}`,Ze=j({title:"Fetching file...",description:"",open:!0});try{const Ue=await vv(A??void 0);if(!Ue||!Array.isArray(Ue))throw new Error("Invalid file list response");const ct=Ue.find(Et=>!Et||typeof Et!="object"||!((Et.filename??"")===(le.name??""))?!1:typeof le.size=="number"&&typeof Et.size=="number"?Et.size===le.size:!0);if(!(ct!=null&&ct.id))throw new Error(`File "${le.name}" is not yet available on the server`);if(!ct.id||!ct.filename)throw new Error("Invalid file data received from server");H({id:ct.id,name:le.name||ct.filename||`file_${ct.id}`,mimeType:le.mimeType||ct.mime_type||"application/octet-stream"}),P(!0),Ze.update({id:Ze.id,title:"Success",description:`Opened ${le.name}`,open:!0})}catch(Ue){console.error("Failed to fetch server file:",Ue);const ct=Ue instanceof Error?Ue.message:"Unknown error occurred";Ze.update({id:Ze.id,title:"Failed",description:ct}),j({title:"Failed to fetch file",description:ct,open:!0})}finally{D(Ue=>({...Ue,[ge]:!1}))}}}catch(Ce){console.error("File click error:",Ce),D(we=>({...we,[ge]:!1}))}},[U,M,j,A]),Fe=S.useCallback(()=>{const le=X(q?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Y);switch(F){case"user":return c.jsx(Q.User,{className:le});case"assistant":return c.jsx(Q.Bot,{className:le});case"tool":return c.jsx(Q.Wrench,{className:le});default:return c.jsx(Q.Bot,{className:le})}},[q,Y,F]),Xe=S.useCallback(()=>{const Z="group relative mb-4 flex w-full";switch(F){case"user":return X(Z,"justify-end");case"assistant":case"tool":case"system":return X(Z,"justify-start");default:return Z}},[F]),et=S.useCallback(()=>{const Z=X("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",q&&"px-3 py-2 text-sm");switch(F){case"user":return X(Z,"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 X(Z,"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 X(Z,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return X(Z,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return X(Z,"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")}},[q,F]),ye=S.useCallback(async Z=>{try{const le=Z.id||`interrupt-${Date.now()}`;await R(le,!0)}catch(le){console.error("Failed to approve interrupt:",le)}},[R]),Pe=S.useCallback(async Z=>{try{const le=Z.id||`interrupt-${Date.now()}`;await R(le,!1)}catch(le){console.error("Failed to reject interrupt:",le)}},[R]),Je=S.useCallback(({part:Z,i:le})=>{if(Z.type==="text"){const ge=Z.text??"",Ce=ge.trim(),we=td(Ce);return we&&F!=="tool"?c.jsx(Kw,{data:we},le):F==="user"&&f&&Ce.length>h?c.jsxs(Uc,{open:T,onOpenChange:I,children:[c.jsx("div",{className:X("text-sm text-[hsl(var(--chat-bubble-user-text))]",q&&"text-xs"),children:T?c.jsx(Ai,{content:Ce,allowHtml:!1}):c.jsxs("pre",{className:X("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",q&&"text-xs"),children:[Ce.substring(0,h),"..."]})}),c.jsx(Wc,{asChild:!0,children:c.jsx(Be,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:T?c.jsxs(c.Fragment,{children:[c.jsx(Q.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(Q.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",Ce.length-h," chars)"]})})})]},le):c.jsx(Ai,{content:ge,allowHtml:!1},le)}if(Z.type==="image_url"){const ge=Z;return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:ge.url,alt:ge.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},le)}if(Z.type==="file"){const ge=Z,Ce=ge.name||"file";return c.jsxs("a",{href:ge.url,onClick:we=>re(we,ge,le),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
130
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[M[le]?c.jsx(Q.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[Ce,M[le]?" (processing)":""]})]},le)}return Z.type==="interrupt"?c.jsx(Gw,{interruptPart:Z,onApprove:ye,onReject:Pe},le):null},[re,M,ye,Pe,F,f,h,T,q]),$e=S.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(Q.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),st=S.useCallback(()=>{const Z=fe.trim().length>0||he.length>0||Ee.length>0||de.length>0;if(!N&&!Z&&!r)return $e();if(t.model==="reflection"){const le=fe.trim(),ge=td(le);if(ge&&typeof ge=="object")return c.jsx(Yw,{data:ge})}if(N&&ie.name==="get_issues"){const le=t.content.find(we=>we.type==="tool_end"),ge=(le==null?void 0:le.output)??z,Ce=rd(ge);if(Ce)return c.jsx(Xw,{issues:Ce})}if(N){const le=Bw(t.content);if(le.length>0)return c.jsx("div",{className:"space-y-2",children:le.map((ge,Ce)=>{const we=typeof ge.output=="string"?ge.output:qi(ge.output),je=we.length>Vn?`${we.slice(0,Vn)}
|
|
131
|
+
… [truncated ${we.length-Vn} chars]`:we,Ze=E==="expanded";return c.jsxs(Uc,{open:Ze,onOpenChange:Ue=>C(Ue?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(Si,{variant:"outline",children:(ge.name??"tool")+(ge.toolCallId?` • ${ge.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Ze?je:je.slice(0,d)+(je.length>d?"...":"")})}),c.jsx(Wc,{asChild:!0,children:c.jsx(Be,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Ze?c.jsxs(c.Fragment,{children:[" ",c.jsx(Q.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(Q.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},ge.toolCallId??Ce)})})}if(!N){const le=c.jsx("div",{className:"space-y-2",children:t.content.map((ge,Ce)=>c.jsx(Je,{part:ge,i:Ce},Ce))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[le,c.jsx(Vw,{className:Y})]}):le}},[fe,he.length,Ee.length,de.length,r,t.model,N,ie.name,z,E,u,$e,Y]),lt=S.useMemo(()=>Ww(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:X(Xe(),p.container),children:c.jsxs("div",{className:X(et(),p.content),children:[(i||a||N)&&c.jsxs("div",{className:X("flex items-center justify-between mb-2 pb-2 border-b border-current/10",q&&"mb-1 pb-1",Y,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[Fe(),a&<&&c.jsx("span",{className:X("font-medium",q?"text-xs":"text-sm"),children:lt}),N&&ie.name&&c.jsxs(Si,{variant:"outline",className:X("text-xs flex items-center gap-1 cursor-pointer",Y,"border border-current/40",q&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E!=="collapsed",onKeyDown:Z=>{(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),C(le=>le==="collapsed"?"preview":"collapsed"))},onClick:()=>C(Z=>Z==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:ie.name}),c.jsx("span",{className:"inline-flex items-center",children:E!=="collapsed"?c.jsx(Q.ChevronUp,{className:"h-3 w-3"}):c.jsx(Q.ChevronDown,{className:"h-3 w-3"})})]}),N&&!ie.name&&c.jsx(Be,{variant:"ghost",size:"sm",className:X("h-6 px-1",Y,"hover:bg-foreground/10"),onClick:()=>C(Z=>Z==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",E!=="collapsed"?c.jsx(Q.ChevronUp,{className:"h-3 w-3"}):c.jsx(Q.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:X("text-xs opacity-60",Y,q&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:X("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>K(N?"visible":"all"),className:X("h-6 w-6 p-0 hover:bg-foreground/10",Y,q&&"h-5 w-5"),"aria-label":N?"Copy visible":"Copy message",title:N?"Copy visible portion":"Copy message",children:c.jsx(Q.Copy,{className:X(b?"text-success":Y,q?"h-3 w-3":"h-4 w-4")})}),N&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>K("all"),className:X("h-6 px-1 text-xs hover:bg-foreground/10",Y),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),F==="user"&&w&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:J,className:X("h-6 w-6 p-0 hover:bg-foreground/10",Y,q&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(Q.Edit,{className:X(Y,q?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&v&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:ae,className:X("h-6 w-6 p-0 hover:bg-foreground/10",Y,q&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(Q.RotateCcw,{className:X(Y,q?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:st()}),N&&E==="expanded"&&(ie.toolCallId||ie.name)&&c.jsxs("div",{className:X("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",q&&"text-xs"),children:[ie.name&&c.jsxs("div",{children:["Function: ",ie.name]}),ie.toolCallId&&c.jsxs("div",{children:["Call ID: ",ie.toolCallId]})]}),!(i||a||N)&&s&&!o&&c.jsxs("div",{className:X("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>K(),className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(Q.Copy,{className:X(b?"text-success":"text-current",q?"h-3 w-3":"h-4 w-4")})}),F==="user"&&w&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:J,className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(Q.Edit,{className:X("text-current",q?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&v&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:ae,className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(Q.RotateCcw,{className:X("text-current",q?"h-3 w-3":"h-4 w-4")})})]})]})}),W&&c.jsx(Fw,{isOpen:L,onClose:()=>{P(!1),H(null)},fileId:W.id,fileName:W.name,mimeType:W.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&od(e.message)===od(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)&&((l=e.customStyles)==null?void 0:l.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)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function Kw({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:ts,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:qi(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 c.jsxs("div",{className:ts,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:ts,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:qw(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:qi(e)})}function qw(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 c.jsx("code",{className:"text-xs",children:JSON.stringify(Hr(e))})}catch{return String(e)}}function Gw({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(Fr,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs($r,{className:"pb-3",children:[c.jsx(zr,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(Vc,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Kc,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Be,{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"}),c.jsx(Be,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function Yw({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function Xw({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:ts,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const id=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Gi=S.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:w=!0,isNavigatingCheckpoint:v=!1,onScrollAway:g,onAtBottom:x},b)=>{const y=S.useRef(null),E=S.useRef(null),C=S.useRef(!1),[T,I]=S.useState(!0),A=S.useCallback(M=>{I(M),g&&g(!M),x&&x(M)},[g,x]),R=S.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),j=S.useMemo(()=>!w||v?!1:T?"auto":!1,[T,w,v]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Sx,{ref:M=>{y.current=M},scrollerRef:M=>{E.current=M instanceof HTMLDivElement?M:null},data:e,followOutput:j,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{R&&R()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(M,D)=>id(D,M),itemContent:(M,D)=>{const L=id(D,M);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":L,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(sd,{message:D,messageIndex:M,isStreamingMessage:t&&n===D.id,streamingDebounceMs:r,isEditing:i===D.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(M),onCancelEdit:d})})}})})});Gi.displayName="MessageList";const ns=1e4;function Jw(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
132
132
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
133
133
|
|
|
134
134
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -136,4 +136,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
136
136
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
137
137
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
138
138
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
139
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function Zw(e,t=ns){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 Qw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Zw(t),Jw(t)}function Yi(e){const t=e+"CollectionProvider",[n,r]=nn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:g,children:x}=v,b=S.useRef(null),y=S.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:y,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Pn.createSlot(a),u=S.forwardRef((v,g)=>{const{scope:x,children:b}=v,y=s(a,x),E=Oe(g,y.collectionRef);return c.jsx(l,{ref:E,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Pn.createSlot(d),p=S.forwardRef((v,g)=>{const{scope:x,children:b,...y}=v,E=S.useRef(null),C=Oe(g,E),T=s(d,x);return S.useEffect(()=>(T.itemMap.set(E,{ref:E,...y}),()=>void T.itemMap.delete(E))),c.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function w(v){const g=s(e+"CollectionConsumer",v);return S.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const y=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((T,I)=>y.indexOf(T.ref.current)-y.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},w,r]}var eb=m.createContext(void 0);function rs(e){const t=m.useContext(eb);return e||t||"ltr"}const tb=["top","right","bottom","left"],En=Math.min,Ot=Math.max,os=Math.round,ss=Math.floor,sn=e=>({x:e,y:e}),nb={left:"right",right:"left",bottom:"top",top:"bottom"},rb={start:"end",end:"start"};function Xi(e,t,n){return Ot(e,En(t,n))}function pn(e,t){return typeof e=="function"?e(t):e}function mn(e){return e.split("-")[0]}function fr(e){return e.split("-")[1]}function Ji(e){return e==="x"?"y":"x"}function Zi(e){return e==="y"?"height":"width"}const ob=new Set(["top","bottom"]);function an(e){return ob.has(mn(e))?"y":"x"}function Qi(e){return Ji(an(e))}function sb(e,t,n){n===void 0&&(n=!1);const r=fr(e),o=Qi(e),s=Zi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=is(i)),[i,is(i)]}function ib(e){const t=is(e);return[ea(e),t,ea(t)]}function ea(e){return e.replace(/start|end/g,t=>rb[t])}const ad=["left","right"],ld=["right","left"],ab=["top","bottom"],lb=["bottom","top"];function cb(e,t,n){switch(e){case"top":case"bottom":return n?t?ld:ad:t?ad:ld;case"left":case"right":return t?ab:lb;default:return[]}}function ub(e,t,n,r){const o=fr(e);let s=cb(mn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ea)))),s}function is(e){return e.replace(/left|right|bottom|top/g,t=>nb[t])}function db(e){return{top:0,right:0,bottom:0,left:0,...e}}function cd(e){return typeof e!="number"?db(e):{top:e,right:e,bottom:e,left:e}}function as(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 ud(e,t,n){let{reference:r,floating:o}=e;const s=an(t),i=Qi(t),a=Zi(i),l=mn(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 p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(fr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const fb=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=ud(u,r,l),h=r,p={},w=0;for(let v=0;v<a.length;v++){const{name:g,fn:x}=a[v],{x:b,y,data:E,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=y??f,p={...p,[g]:{...p[g],...E}},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}=ud(u,h,l)),v=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Ur(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=pn(t,e),w=cd(p),g=a[h?f==="floating"?"reference":"floating":f],x=as(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,y=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(y))?await(s.getScale==null?void 0:s.getScale(y))||{x:1,y:1}:{x:1,y:1},C=as(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:y,strategy:l}):b);return{top:(x.top-C.top+w.top)/E.y,bottom:(C.bottom-x.bottom+w.bottom)/E.y,left:(x.left-C.left+w.left)/E.x,right:(C.right-x.right+w.right)/E.x}}const hb=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=pn(e,t)||{};if(u==null)return{};const f=cd(d),h={x:n,y:r},p=Qi(o),w=Zi(p),v=await i.getDimensions(u),g=p==="y",x=g?"top":"left",b=g?"bottom":"right",y=g?"clientHeight":"clientWidth",E=s.reference[w]+s.reference[p]-h[p]-s.floating[w],C=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=T?T[y]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[y]||s.floating[w]);const A=E/2-C/2,R=I/2-v[w]/2-1,j=En(f[x],R),M=En(f[b],R),D=j,L=I-v[w]-M,P=I/2-v[w]/2+A,W=Xi(D,P,L),H=!l.arrow&&fr(o)!=null&&P!==W&&s.reference[w]/2-(P<D?j:M)-v[w]/2<0,q=H?P<D?P-D:P-L:0;return{[p]:h[p]+q,data:{[p]:W,centerOffset:P-W-q,...H&&{alignmentOffset:q}},reset:H}}}),pb=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...g}=pn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=mn(o),b=an(a),y=mn(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(u.floating)),C=h||(y||!v?[is(a)]:ib(a)),T=w!=="none";!h&&T&&C.push(...ub(a,v,w,E));const I=[a,...C],A=await Ur(t,g),R=[];let j=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(A[x]),f){const P=sb(o,i,E);R.push(A[P[0]],A[P[1]])}if(j=[...j,{placement:o,overflows:R}],!R.every(P=>P<=0)){var M,D;const P=(((M=s.flip)==null?void 0:M.index)||0)+1,W=I[P];if(W&&(!(f==="alignment"?b!==an(W):!1)||j.every(F=>an(F.placement)===b?F.overflows[0]>0:!0)))return{data:{index:P,overflows:j},reset:{placement:W}};let H=(D=j.filter(q=>q.overflows[0]<=0).sort((q,F)=>q.overflows[1]-F.overflows[1])[0])==null?void 0:D.placement;if(!H)switch(p){case"bestFit":{var L;const q=(L=j.filter(F=>{if(T){const N=an(F.placement);return N===b||N==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(N=>N>0).reduce((N,U)=>N+U,0)]).sort((F,N)=>F[1]-N[1])[0])==null?void 0:L[0];q&&(H=q);break}case"initialPlacement":H=a;break}if(o!==H)return{reset:{placement:H}}}return{}}}};function dd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function fd(e){return tb.some(t=>e[t]>=0)}const mb=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=pn(e,t);switch(r){case"referenceHidden":{const s=await Ur(t,{...o,elementContext:"reference"}),i=dd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:fd(i)}}}case"escaped":{const s=await Ur(t,{...o,altBoundary:!0}),i=dd(s,n.floating);return{data:{escapedOffsets:i,escaped:fd(i)}}}default:return{}}}}},hd=new Set(["left","top"]);async function gb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=mn(n),a=fr(n),l=an(n)==="y",u=hd.has(i)?-1:1,d=s&&l?-1:1,f=pn(t,e);let{mainAxis:h,crossAxis:p,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"&&(p=a==="end"?w*-1:w),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const xb=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await gb(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},vb=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x,y:b}=g;return{x,y:b}}},...l}=pn(e,t),u={x:n,y:r},d=await Ur(t,l),f=an(mn(o)),h=Ji(f);let p=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=p+d[g],y=p-d[x];p=Xi(b,p,y)}if(i){const g=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=w+d[g],y=w-d[x];w=Xi(b,w,y)}const v=a.fn({...t,[h]:p,[f]:w});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[h]:s,[f]:i}}}}}},wb=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=pn(e,t),d={x:n,y:r},f=an(o),h=Ji(f);let p=d[h],w=d[f];const v=pn(a,t),g=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(l){const y=h==="y"?"height":"width",E=s.reference[h]-s.floating[y]+g.mainAxis,C=s.reference[h]+s.reference[y]-g.mainAxis;p<E?p=E:p>C&&(p=C)}if(u){var x,b;const y=h==="y"?"width":"height",E=hd.has(mn(o)),C=s.reference[f]-s.floating[y]+(E&&((x=i.offset)==null?void 0:x[f])||0)+(E?0:g.crossAxis),T=s.reference[f]+s.reference[y]+(E?0:((b=i.offset)==null?void 0:b[f])||0)-(E?g.crossAxis:0);w<C?w=C:w>T&&(w=T)}return{[h]:p,[f]:w}}}},bb=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=pn(e,t),d=await Ur(t,u),f=mn(o),h=fr(o),p=an(o)==="y",{width:w,height:v}=s.floating;let g,x;f==="top"||f==="bottom"?(g=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,g=h==="end"?"top":"bottom");const b=v-d.top-d.bottom,y=w-d.left-d.right,E=En(v-d[g],b),C=En(w-d[x],y),T=!t.middlewareData.shift;let I=E,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!h){const j=Ot(d.left,0),M=Ot(d.right,0),D=Ot(d.top,0),L=Ot(d.bottom,0);p?A=w-2*(j!==0||M!==0?j+M:Ot(d.left,d.right)):I=v-2*(D!==0||L!==0?D+L:Ot(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const R=await i.getDimensions(a.floating);return w!==R.width||v!==R.height?{reset:{rects:!0}}:{}}}};function ls(){return typeof window<"u"}function hr(e){return pd(e)?(e.nodeName||"").toLowerCase():"#document"}function Mt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ln(e){var t;return(t=(pd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function pd(e){return ls()?e instanceof Node||e instanceof Mt(e).Node:!1}function Gt(e){return ls()?e instanceof Element||e instanceof Mt(e).Element:!1}function cn(e){return ls()?e instanceof HTMLElement||e instanceof Mt(e).HTMLElement:!1}function md(e){return!ls()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Mt(e).ShadowRoot}const yb=new Set(["inline","contents"]);function Wr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Yt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!yb.has(o)}const Sb=new Set(["table","td","th"]);function Cb(e){return Sb.has(hr(e))}const Tb=[":popover-open",":modal"];function cs(e){return Tb.some(t=>{try{return e.matches(t)}catch{return!1}})}const kb=["transform","translate","scale","rotate","perspective"],Eb=["transform","translate","scale","rotate","perspective","filter"],Ib=["paint","layout","strict","content"];function ta(e){const t=na(),n=Gt(e)?Yt(e):e;return kb.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)||Eb.some(r=>(n.willChange||"").includes(r))||Ib.some(r=>(n.contain||"").includes(r))}function Nb(e){let t=In(e);for(;cn(t)&&!pr(t);){if(ta(t))return t;if(cs(t))return null;t=In(t)}return null}function na(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Ab=new Set(["html","body","#document"]);function pr(e){return Ab.has(hr(e))}function Yt(e){return Mt(e).getComputedStyle(e)}function us(e){return Gt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function In(e){if(hr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||md(e)&&e.host||ln(e);return md(t)?t.host:t}function gd(e){const t=In(e);return pr(t)?e.ownerDocument?e.ownerDocument.body:e.body:cn(t)&&Wr(t)?t:gd(t)}function Vr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=gd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Mt(o);if(s){const a=ra(i);return t.concat(i,i.visualViewport||[],Wr(o)?o:[],a&&n?Vr(a):[])}return t.concat(o,Vr(o,[],n))}function ra(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function xd(e){const t=Yt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=cn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=os(n)!==s||os(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function oa(e){return Gt(e)?e:e.contextElement}function mr(e){const t=oa(e);if(!cn(t))return sn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=xd(t);let i=(s?os(n.width):n.width)/r,a=(s?os(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const jb=sn(0);function vd(e){const t=Mt(e);return!na()||!t.visualViewport?jb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function _b(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Mt(e)?!1:t}function Kn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=oa(e);let i=sn(1);t&&(r?Gt(r)&&(i=mr(r)):i=mr(e));const a=_b(s,n,r)?vd(s):sn(0);let l=(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=Mt(s),p=r&&Gt(r)?Mt(r):r;let w=h,v=ra(w);for(;v&&r&&p!==w;){const g=mr(v),x=v.getBoundingClientRect(),b=Yt(v),y=x.left+(v.clientLeft+parseFloat(b.paddingLeft))*g.x,E=x.top+(v.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=y,u+=E,w=Mt(v),v=ra(w)}}return as({width:d,height:f,x:l,y:u})}function sa(e,t){const n=us(e).scrollLeft;return t?t.left+n:Kn(ln(e)).left+n}function wd(e,t,n){n===void 0&&(n=!1);const r=e.getBoundingClientRect(),o=r.left+t.scrollLeft-(n?0:sa(e,r)),s=r.top+t.scrollTop;return{x:o,y:s}}function Rb(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=ln(r),a=t?cs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=sn(1);const d=sn(0),f=cn(r);if((f||!f&&!s)&&((hr(r)!=="body"||Wr(i))&&(l=us(r)),cn(r))){const p=Kn(r);u=mr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?wd(i,l,!0):sn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function Pb(e){return Array.from(e.getClientRects())}function Ob(e){const t=ln(e),n=us(e),r=e.ownerDocument.body,o=Ot(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ot(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+sa(e);const a=-n.scrollTop;return Yt(r).direction==="rtl"&&(i+=Ot(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function Mb(e,t){const n=Mt(e),r=ln(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const u=na();(!u||u&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}const Db=new Set(["absolute","fixed"]);function Lb(e,t){const n=Kn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=cn(e)?mr(e):sn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function bd(e,t,n){let r;if(t==="viewport")r=Mb(e,n);else if(t==="document")r=Ob(ln(e));else if(Gt(t))r=Lb(t,n);else{const o=vd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return as(r)}function yd(e,t){const n=In(e);return n===t||!Gt(n)||pr(n)?!1:Yt(n).position==="fixed"||yd(n,t)}function Fb(e,t){const n=t.get(e);if(n)return n;let r=Vr(e,[],!1).filter(a=>Gt(a)&&hr(a)!=="body"),o=null;const s=Yt(e).position==="fixed";let i=s?In(e):e;for(;Gt(i)&&!pr(i);){const a=Yt(i),l=ta(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Db.has(o.position)||Wr(i)&&!l&&yd(e,i))?r=r.filter(d=>d!==i):o=a,i=In(i)}return t.set(e,r),r}function $b(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?cs(t)?[]:Fb(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=bd(t,d,o);return u.top=Ot(f.top,u.top),u.right=En(f.right,u.right),u.bottom=En(f.bottom,u.bottom),u.left=Ot(f.left,u.left),u},bd(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function zb(e){const{width:t,height:n}=xd(e);return{width:t,height:n}}function Bb(e,t,n){const r=cn(t),o=ln(t),s=n==="fixed",i=Kn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=sn(0);function u(){l.x=sa(o)}if(r||!r&&!s)if((hr(t)!=="body"||Wr(o))&&(a=us(t)),r){const p=Kn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?wd(o,a):sn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function ia(e){return Yt(e).position==="static"}function Sd(e,t){if(!cn(e)||Yt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ln(e)===n&&(n=n.ownerDocument.body),n}function Cd(e,t){const n=Mt(e);if(cs(e))return n;if(!cn(e)){let o=In(e);for(;o&&!pr(o);){if(Gt(o)&&!ia(o))return o;o=In(o)}return n}let r=Sd(e,t);for(;r&&Cb(r)&&ia(r);)r=Sd(r,t);return r&&pr(r)&&ia(r)&&!ta(r)?n:r||Nb(e)||n}const Hb=async function(e){const t=this.getOffsetParent||Cd,n=this.getDimensions,r=await n(e.floating);return{reference:Bb(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Ub(e){return Yt(e).direction==="rtl"}const Wb={convertOffsetParentRelativeRectToViewportRelativeRect:Rb,getDocumentElement:ln,getClippingRect:$b,getOffsetParent:Cd,getElementRects:Hb,getClientRects:Pb,getDimensions:zb,getScale:mr,isElement:Gt,isRTL:Ub};function Td(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Vb(e,t){let n=null,r;const o=ln(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const w=ss(f),v=ss(o.clientWidth-(d+h)),g=ss(o.clientHeight-(f+p)),x=ss(d),y={rootMargin:-w+"px "+-v+"px "+-g+"px "+-x+"px",threshold:Ot(0,En(1,l))||1};let E=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!E)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Td(u,e.getBoundingClientRect())&&i(),E=!1}try{n=new IntersectionObserver(C,{...y,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,y)}n.observe(e)}return i(!0),s}function Kb(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=oa(e),d=o||s?[...u?Vr(u):[],...Vr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?Vb(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[b]=x;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var y;(y=p)==null||y.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let w,v=l?Kn(e):null;l&&g();function g(){const x=Kn(e);v&&!Td(v,x)&&n(),v=x,w=requestAnimationFrame(g)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(w)}}const qb=xb,Gb=vb,Yb=pb,Xb=bb,Jb=mb,kd=hb,Zb=wb,Qb=(e,t,n)=>{const r=new Map,o={platform:Wb,...n},s={...o.platform,_c:r};return fb(e,t,{...o,platform:s})};var ey=typeof document<"u",ty=function(){},ds=ey?S.useLayoutEffect:ty;function fs(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(!fs(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)&&!fs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Ed(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Id(e,t){const n=Ed(e);return Math.round(t*n)/n}function aa(e){const t=m.useRef(e);return ds(()=>{t.current=e}),t}function ny(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);fs(h,r)||p(r);const[w,v]=m.useState(null),[g,x]=m.useState(null),b=m.useCallback(F=>{F!==T.current&&(T.current=F,v(F))},[]),y=m.useCallback(F=>{F!==I.current&&(I.current=F,x(F))},[]),E=s||w,C=i||g,T=m.useRef(null),I=m.useRef(null),A=m.useRef(d),R=l!=null,j=aa(l),M=aa(o),D=aa(u),L=m.useCallback(()=>{if(!T.current||!I.current)return;const F={placement:t,strategy:n,middleware:h};M.current&&(F.platform=M.current),Qb(T.current,I.current,F).then(N=>{const U={...N,isPositioned:D.current!==!1};P.current&&!fs(A.current,U)&&(A.current=U,no.flushSync(()=>{f(U)}))})},[h,t,n,M,D]);ds(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(F=>({...F,isPositioned:!1})))},[u]);const P=m.useRef(!1);ds(()=>(P.current=!0,()=>{P.current=!1}),[]),ds(()=>{if(E&&(T.current=E),C&&(I.current=C),E&&C){if(j.current)return j.current(E,C,L);L()}},[E,C,L,j,R]);const W=m.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:y}),[b,y]),H=m.useMemo(()=>({reference:E,floating:C}),[E,C]),q=m.useMemo(()=>{const F={position:n,left:0,top:0};if(!H.floating)return F;const N=Id(H.floating,d.x),U=Id(H.floating,d.y);return a?{...F,transform:"translate("+N+"px, "+U+"px)",...Ed(H.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:N,top:U}},[n,a,H.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:L,refs:W,elements:H,floatingStyles:q}),[d,L,W,H,q])}const ry=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?kd({element:r.current,padding:o}).fn(n):{}:r?kd({element:r,padding:o}).fn(n):{}}}},oy=(e,t)=>({...qb(e),options:[e,t]}),sy=(e,t)=>({...Gb(e),options:[e,t]}),iy=(e,t)=>({...Zb(e),options:[e,t]}),ay=(e,t)=>({...Yb(e),options:[e,t]}),ly=(e,t)=>({...Xb(e),options:[e,t]}),cy=(e,t)=>({...Jb(e),options:[e,t]}),uy=(e,t)=>({...ry(e),options:[e,t]});var dy="Arrow",Nd=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Se.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});Nd.displayName=dy;var fy=Nd;function Ad(e){const[t,n]=m.useState(void 0);return pt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;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 la="Popper",[jd,hs]=nn(la),[hy,_d]=jd(la),Rd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(hy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Rd.displayName=la;var Pd="PopperAnchor",Od=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=_d(Pd,n),i=m.useRef(null),a=Oe(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(Se.div,{...o,ref:a})});Od.displayName=Pd;var ca="PopperContent",[py,my]=jd(ca),Md=m.forwardRef((e,t)=>{var z,O,V,J,ae,oe;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:w,...v}=e,g=_d(ca,n),[x,b]=m.useState(null),y=Oe(t,Fe=>b(Fe)),[E,C]=m.useState(null),T=Ad(E),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,R=r+(s!=="center"?"-"+s:""),j=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},M=Array.isArray(u)?u:[u],D=M.length>0,L={padding:j,boundary:M.filter(xy),altBoundary:D},{refs:P,floatingStyles:W,placement:H,isPositioned:q,middlewareData:F}=ny({strategy:"fixed",placement:R,whileElementsMounted:(...Fe)=>Kb(...Fe,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[oy({mainAxis:o+A,alignmentAxis:i}),l&&sy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?iy():void 0,...L}),l&&ay({...L}),ly({...L,apply:({elements:Fe,rects:Xe,availableWidth:et,availableHeight:ye})=>{const{width:Pe,height:Je}=Xe.reference,$e=Fe.floating.style;$e.setProperty("--radix-popper-available-width",`${et}px`),$e.setProperty("--radix-popper-available-height",`${ye}px`),$e.setProperty("--radix-popper-anchor-width",`${Pe}px`),$e.setProperty("--radix-popper-anchor-height",`${Je}px`)}}),E&&uy({element:E,padding:a}),vy({arrowWidth:I,arrowHeight:A}),h&&cy({strategy:"referenceHidden",...L})]}),[N,U]=Fd(H),Y=mt(w);pt(()=>{q&&(Y==null||Y())},[q,Y]);const fe=(z=F.arrow)==null?void 0:z.x,ie=(O=F.arrow)==null?void 0:O.y,he=((V=F.arrow)==null?void 0:V.centerOffset)!==0,[Ee,de]=m.useState();return pt(()=>{x&&de(window.getComputedStyle(x).zIndex)},[x]),c.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...W,transform:q?W.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ee,"--radix-popper-transform-origin":[(J=F.transformOrigin)==null?void 0:J.x,(ae=F.transformOrigin)==null?void 0:ae.y].join(" "),...((oe=F.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(py,{scope:n,placedSide:N,onArrowChange:C,arrowX:fe,arrowY:ie,shouldHideArrow:he,children:c.jsx(Se.div,{"data-side":N,"data-align":U,...v,ref:y,style:{...v.style,animation:q?void 0:"none"}})})})});Md.displayName=ca;var Dd="PopperArrow",gy={top:"bottom",right:"left",bottom:"top",left:"right"},Ld=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=my(Dd,r),i=gy[s.placedSide];return c.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:c.jsx(fy,{...o,ref:n,style:{...o.style,display:"block"}})})});Ld.displayName=Dd;function xy(e){return e!==null}var vy=e=>({name:"transformOrigin",options:e,fn(t){var g,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Fd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let w="",v="";return u==="bottom"?(w=i?f:`${h}px`,v=`${-l}px`):u==="top"?(w=i?f:`${h}px`,v=`${r.floating.height+l}px`):u==="right"?(w=`${-l}px`,v=i?f:`${p}px`):u==="left"&&(w=`${r.floating.width+l}px`,v=i?f:`${p}px`),{data:{x:w,y:v}}}});function Fd(e){const[t,n="center"]=e.split("-");return[t,n]}var $d=Rd,zd=Od,Bd=Md,Hd=Ld,ua="rovingFocusGroup.onEntryFocus",wy={bubbles:!1,cancelable:!0},Kr="RovingFocusGroup",[da,Ud,by]=Yi(Kr),[yy,Wd]=nn(Kr,[by]),[Sy,Cy]=yy(Kr),Vd=m.forwardRef((e,t)=>c.jsx(da.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(da.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ty,{...e,ref:t})})}));Vd.displayName=Kr;var Ty=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=Oe(t,h),w=rs(s),[v,g]=Bn({prop:i,defaultProp:a??null,onChange:l,caller:Kr}),[x,b]=m.useState(!1),y=mt(u),E=Ud(n),C=m.useRef(!1),[T,I]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(ua,y),()=>A.removeEventListener(ua,y)},[y]),c.jsx(Sy,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:v,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>I(A=>A-1),[]),children:c.jsx(Se.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:se(e.onMouseDown,()=>{C.current=!0}),onFocus:se(e.onFocus,A=>{const R=!C.current;if(A.target===A.currentTarget&&R&&!x){const j=new CustomEvent(ua,wy);if(A.currentTarget.dispatchEvent(j),!j.defaultPrevented){const M=E().filter(H=>H.focusable),D=M.find(H=>H.active),L=M.find(H=>H.id===v),W=[D,L,...M].filter(Boolean).map(H=>H.ref.current);Gd(W,d)}}C.current=!1}),onBlur:se(e.onBlur,()=>b(!1))})})}),Kd="RovingFocusGroupItem",qd=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=rn(),u=s||l,d=Cy(Kd,n),f=d.currentTabStopId===u,h=Ud(n),{onFocusableItemAdd:p,onFocusableItemRemove:w,currentTabStopId:v}=d;return m.useEffect(()=>{if(r)return p(),()=>w()},[r,p,w]),c.jsx(da.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Se.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:se(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:se(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:se(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const x=Iy(g,d.orientation,d.dir);if(x!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let y=h().filter(E=>E.focusable).map(E=>E.ref.current);if(x==="last")y.reverse();else if(x==="prev"||x==="next"){x==="prev"&&y.reverse();const E=y.indexOf(g.currentTarget);y=d.loop?Ny(y,E+1):y.slice(E+1)}setTimeout(()=>Gd(y))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:v!=null}):i})})});qd.displayName=Kd;var ky={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ey(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Iy(e,t,n){const r=Ey(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ky[r]}function Gd(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ny(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ay=Vd,jy=qd,fa=["Enter"," "],_y=["ArrowDown","PageUp","Home"],Yd=["ArrowUp","PageDown","End"],Ry=[..._y,...Yd],Py={ltr:[...fa,"ArrowRight"],rtl:[...fa,"ArrowLeft"]},Oy={ltr:["ArrowLeft"],rtl:["ArrowRight"]},qr="Menu",[Gr,My,Dy]=Yi(qr),[qn,Xd]=nn(qr,[Dy,hs,Wd]),ps=hs(),Jd=Wd(),[Ly,Gn]=qn(qr),[Fy,Yr]=qn(qr),Zd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ps(t),[l,u]=m.useState(null),d=m.useRef(!1),f=mt(s),h=rs(o);return m.useEffect(()=>{const p=()=>{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",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),c.jsx($d,{...a,children:c.jsx(Ly,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(Fy,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Zd.displayName=qr;var $y="MenuAnchor",ha=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ps(n);return c.jsx(zd,{...o,...r,ref:t})});ha.displayName=$y;var pa="MenuPortal",[zy,Qd]=qn(pa,{forceMount:void 0}),ef=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Gn(pa,t);return c.jsx(zy,{scope:t,forceMount:n,children:c.jsx(Pt,{present:n||s.open,children:c.jsx(Bo,{asChild:!0,container:o,children:r})})})};ef.displayName=pa;var zt="MenuContent",[By,ma]=qn(zt),tf=m.forwardRef((e,t)=>{const n=Qd(zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Gn(zt,e.__scopeMenu),i=Yr(zt,e.__scopeMenu);return c.jsx(Gr.Provider,{scope:e.__scopeMenu,children:c.jsx(Pt,{present:r||s.open,children:c.jsx(Gr.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(Hy,{...o,ref:t}):c.jsx(Uy,{...o,ref:t})})})})}),Hy=m.forwardRef((e,t)=>{const n=Gn(zt,e.__scopeMenu),r=m.useRef(null),o=Oe(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Ui(s)},[]),c.jsx(ga,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Uy=m.forwardRef((e,t)=>{const n=Gn(zt,e.__scopeMenu);return c.jsx(ga,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Wy=Pn.createSlot("MenuContent.ScrollLock"),ga=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:w,...v}=e,g=Gn(zt,n),x=Yr(zt,n),b=ps(n),y=Jd(n),E=My(n),[C,T]=m.useState(null),I=m.useRef(null),A=Oe(t,I,g.onContentChange),R=m.useRef(0),j=m.useRef(""),M=m.useRef(0),D=m.useRef(null),L=m.useRef("right"),P=m.useRef(0),W=w?qo:m.Fragment,H=w?{as:Wy,allowPinchZoom:!0}:void 0,q=N=>{var z,O;const U=j.current+N,Y=E().filter(V=>!V.disabled),fe=document.activeElement,ie=(z=Y.find(V=>V.ref.current===fe))==null?void 0:z.textValue,he=Y.map(V=>V.textValue),Ee=n0(he,U,ie),de=(O=Y.find(V=>V.textValue===Ee))==null?void 0:O.ref.current;(function V(J){j.current=J,window.clearTimeout(R.current),J!==""&&(R.current=window.setTimeout(()=>V(""),1e3))})(U),de&&setTimeout(()=>de.focus())};m.useEffect(()=>()=>window.clearTimeout(R.current),[]),Li();const F=m.useCallback(N=>{var Y,fe;return L.current===((Y=D.current)==null?void 0:Y.side)&&o0(N,(fe=D.current)==null?void 0:fe.area)},[]);return c.jsx(By,{scope:n,searchRef:j,onItemEnter:m.useCallback(N=>{F(N)&&N.preventDefault()},[F]),onItemLeave:m.useCallback(N=>{var U;F(N)||((U=I.current)==null||U.focus(),T(null))},[F]),onTriggerLeave:m.useCallback(N=>{F(N)&&N.preventDefault()},[F]),pointerGraceTimerRef:M,onPointerGraceIntentChange:m.useCallback(N=>{D.current=N},[]),children:c.jsx(W,{...H,children:c.jsx(zo,{asChild:!0,trapped:o,onMountAutoFocus:se(s,N=>{var U;N.preventDefault(),(U=I.current)==null||U.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx($o,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(Ay,{asChild:!0,...y,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:se(l,N=>{x.isUsingKeyboardRef.current||N.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(Bd,{role:"menu","aria-orientation":"vertical","data-state":wf(g.open),"data-radix-menu-content":"",dir:x.dir,...b,...v,ref:A,style:{outline:"none",...v.style},onKeyDown:se(v.onKeyDown,N=>{const Y=N.target.closest("[data-radix-menu-content]")===N.currentTarget,fe=N.ctrlKey||N.altKey||N.metaKey,ie=N.key.length===1;Y&&(N.key==="Tab"&&N.preventDefault(),!fe&&ie&&q(N.key));const he=I.current;if(N.target!==he||!Ry.includes(N.key))return;N.preventDefault();const de=E().filter(z=>!z.disabled).map(z=>z.ref.current);Yd.includes(N.key)&&de.reverse(),e0(de)}),onBlur:se(e.onBlur,N=>{N.currentTarget.contains(N.target)||(window.clearTimeout(R.current),j.current="")}),onPointerMove:se(e.onPointerMove,Jr(N=>{const U=N.target,Y=P.current!==N.clientX;if(N.currentTarget.contains(U)&&Y){const fe=N.clientX>P.current?"right":"left";L.current=fe,P.current=N.clientX}}))})})})})})})});tf.displayName=zt;var Vy="MenuGroup",xa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{role:"group",...r,ref:t})});xa.displayName=Vy;var Ky="MenuLabel",nf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{...r,ref:t})});nf.displayName=Ky;var ms="MenuItem",rf="menu.itemSelect",gs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=Yr(ms,e.__scopeMenu),a=ma(ms,e.__scopeMenu),l=Oe(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(rf,{bubbles:!0,cancelable:!0});f.addEventListener(rf,p=>r==null?void 0:r(p),{once:!0}),$c(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(of,{...o,ref:l,disabled:n,onClick:se(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:se(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:se(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||fa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});gs.displayName=ms;var of=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ma(ms,n),a=Jd(n),l=m.useRef(null),u=Oe(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const w=l.current;w&&p((w.textContent??"").trim())},[s.children]),c.jsx(Gr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(jy,{asChild:!0,...a,focusable:!r,children:c.jsx(Se.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:se(e.onPointerMove,Jr(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:se(e.onPointerLeave,Jr(w=>i.onItemLeave(w))),onFocus:se(e.onFocus,()=>f(!0)),onBlur:se(e.onBlur,()=>f(!1))})})})}),qy="MenuCheckboxItem",sf=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(df,{scope:e.__scopeMenu,checked:n,children:c.jsx(gs,{role:"menuitemcheckbox","aria-checked":xs(n)?"mixed":n,...o,ref:t,"data-state":wa(n),onSelect:se(o.onSelect,()=>r==null?void 0:r(xs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});sf.displayName=qy;var af="MenuRadioGroup",[Gy,Yy]=qn(af,{value:void 0,onValueChange:()=>{}}),lf=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=mt(r);return c.jsx(Gy,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(xa,{...o,ref:t})})});lf.displayName=af;var cf="MenuRadioItem",uf=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=Yy(cf,e.__scopeMenu),s=n===o.value;return c.jsx(df,{scope:e.__scopeMenu,checked:s,children:c.jsx(gs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":wa(s),onSelect:se(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});uf.displayName=cf;var va="MenuItemIndicator",[df,Xy]=qn(va,{checked:!1}),ff=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Xy(va,n);return c.jsx(Pt,{present:r||xs(s.checked)||s.checked===!0,children:c.jsx(Se.span,{...o,ref:t,"data-state":wa(s.checked)})})});ff.displayName=va;var Jy="MenuSeparator",hf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});hf.displayName=Jy;var Zy="MenuArrow",pf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ps(n);return c.jsx(Hd,{...o,...r,ref:t})});pf.displayName=Zy;var Qy="MenuSub",[LC,mf]=qn(Qy),Xr="MenuSubTrigger",gf=m.forwardRef((e,t)=>{const n=Gn(Xr,e.__scopeMenu),r=Yr(Xr,e.__scopeMenu),o=mf(Xr,e.__scopeMenu),s=ma(Xr,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(ha,{asChild:!0,...u,children:c.jsx(of,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":wf(n.open),...e,ref:Ci(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:se(e.onPointerMove,Jr(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:se(e.onPointerLeave,Jr(f=>{var p,w;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const v=(w=n.content)==null?void 0:w.dataset.side,g=v==="right",x=g?-5:5,b=h[g?"left":"right"],y=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:y,y:h.top},{x:y,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:se(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||Py[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});gf.displayName=Xr;var xf="MenuSubContent",vf=m.forwardRef((e,t)=>{const n=Qd(zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Gn(zt,e.__scopeMenu),i=Yr(zt,e.__scopeMenu),a=mf(xf,e.__scopeMenu),l=m.useRef(null),u=Oe(t,l);return c.jsx(Gr.Provider,{scope:e.__scopeMenu,children:c.jsx(Pt,{present:r||s.open,children:c.jsx(Gr.Slot,{scope:e.__scopeMenu,children:c.jsx(ga,{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=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:se(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:se(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:se(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=Oy[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});vf.displayName=xf;function wf(e){return e?"open":"closed"}function xs(e){return e==="indeterminate"}function wa(e){return xs(e)?"indeterminate":e?"checked":"unchecked"}function e0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function t0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function n0(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=t0(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function r0(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function o0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return r0(n,t)}function Jr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var s0=Zd,i0=ha,a0=ef,l0=tf,c0=xa,u0=nf,d0=gs,f0=sf,h0=lf,p0=uf,m0=ff,g0=hf,x0=pf,v0=gf,w0=vf,vs="DropdownMenu",[b0,FC]=nn(vs,[Xd]),yt=Xd(),[y0,bf]=b0(vs),yf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=yt(t),u=m.useRef(null),[d,f]=Bn({prop:o,defaultProp:s??!1,onChange:i,caller:vs});return c.jsx(y0,{scope:t,triggerId:rn(),triggerRef:u,contentId:rn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(s0,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};yf.displayName=vs;var Sf="DropdownMenuTrigger",Cf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=bf(Sf,n),i=yt(n);return c.jsx(i0,{asChild:!0,...i,children:c.jsx(Se.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:Ci(t,s.triggerRef),onPointerDown:se(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:se(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Cf.displayName=Sf;var S0="DropdownMenuPortal",Tf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=yt(t);return c.jsx(a0,{...r,...n})};Tf.displayName=S0;var kf="DropdownMenuContent",Ef=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bf(kf,n),s=yt(n),i=m.useRef(!1);return c.jsx(l0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:se(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:se(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.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)"}})});Ef.displayName=kf;var C0="DropdownMenuGroup",T0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(c0,{...o,...r,ref:t})});T0.displayName=C0;var k0="DropdownMenuLabel",If=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(u0,{...o,...r,ref:t})});If.displayName=k0;var E0="DropdownMenuItem",Nf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(d0,{...o,...r,ref:t})});Nf.displayName=E0;var I0="DropdownMenuCheckboxItem",Af=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(f0,{...o,...r,ref:t})});Af.displayName=I0;var N0="DropdownMenuRadioGroup",A0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(h0,{...o,...r,ref:t})});A0.displayName=N0;var j0="DropdownMenuRadioItem",jf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(p0,{...o,...r,ref:t})});jf.displayName=j0;var _0="DropdownMenuItemIndicator",_f=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(m0,{...o,...r,ref:t})});_f.displayName=_0;var R0="DropdownMenuSeparator",Rf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(g0,{...o,...r,ref:t})});Rf.displayName=R0;var P0="DropdownMenuArrow",O0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(x0,{...o,...r,ref:t})});O0.displayName=P0;var M0="DropdownMenuSubTrigger",Pf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(v0,{...o,...r,ref:t})});Pf.displayName=M0;var D0="DropdownMenuSubContent",Of=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(w0,{...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)"}})});Of.displayName=D0;var L0=yf,F0=Cf,$0=Tf,Mf=Ef,Df=If,Lf=Nf,Ff=Af,$f=jf,zf=_f,Bf=Rf,Hf=Pf,Uf=Of;const z0=L0,B0=F0,H0=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Hf,{ref:o,className:X("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,c.jsx(Q.ChevronRight,{className:"ml-auto h-4 w-4"})]}));H0.displayName=Hf.displayName;const U0=m.forwardRef(({className:e,...t},n)=>c.jsx(Uf,{ref:n,className:X("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}));U0.displayName=Uf.displayName;const Wf=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx($0,{children:c.jsx(Mf,{ref:r,sideOffset:t,className:X("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})}));Wf.displayName=Mf.displayName;const ba=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Lf,{ref:r,className:X("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}));ba.displayName=Lf.displayName;const W0=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Ff,{ref:o,className:X("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(zf,{children:c.jsx(Q.Check,{className:"h-4 w-4"})})}),t]}));W0.displayName=Ff.displayName;const V0=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs($f,{ref:r,className:X("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(zf,{children:c.jsx(Q.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));V0.displayName=$f.displayName;const K0=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Df,{ref:r,className:X("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));K0.displayName=Df.displayName;const q0=m.forwardRef(({className:e,...t},n)=>c.jsx(Bf,{ref:n,className:X("-mx-1 my-1 h-px bg-muted",e),...t}));q0.displayName=Bf.displayName;function ws({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:w}=Gs(),{currentThreadId:v,isLoadingThread:g,listCheckpoints:x,navigateToCheckpoint:b,returnToLatest:y}=mo(),{messages:E,hasMoreHistory:C,isLoadingHistory:T,send:I,stop:A,loadOlderMessages:R}=Zs(),{isStreaming:j,error:M,streamingAssistantId:D,lastCheckpointId:L,lastCheckpointNs:P}=Fl(),[W,H]=S.useState(null),[q,F]=S.useState(""),[N,U]=S.useState(null),[Y,fe]=S.useState([]),[ie,he]=S.useState(0),[Ee,de]=S.useState(0),[z,O]=S.useState(!1),[V,J]=S.useState(null),[ae,oe]=S.useState(null),[Fe,Xe]=S.useState(!1),[et,ye]=S.useState(null),[Pe,Je]=S.useState([]),[$e,st]=S.useState(null),[lt,Z]=S.useState(null),[le,xe]=S.useState(!1),Ce=S.useRef(null),we=S.useRef(null),je=S.useRef(null),Ze=S.useCallback(()=>{Ce.current&&(Ce.current.value=""),we.current&&(we.current.value=""),he(ne=>ne+1),de(ne=>ne+1)},[]),Ue=S.useRef(!1);S.useEffect(()=>{Ue.current&&!j&&(fe([]),Ze()),Ue.current=j},[j,Ze]);const[ct,Et]=S.useState("desktop");S.useEffect(()=>{const ne=()=>{const pe=window.innerWidth;Et(pe<640?"phone":pe<1024?"tablet":"desktop")};return ne(),window.addEventListener("resize",ne),()=>window.removeEventListener("resize",ne)},[]),S.useEffect(()=>{let ne=!1;if(!v){Je([]),st(null),Z(null),je.current=null;return}const pe={threadId:v,checkpointId:L??null,checkpointNs:P??null},Le=je.current;if(!(Le&&Le.threadId===pe.threadId&&Le.checkpointId===pe.checkpointId&&Le.checkpointNs===pe.checkpointNs))return x(v).then(ot=>{var _s;if(ne)return;const Dt=((ot==null?void 0:ot.checkpoints)??[]).slice().sort((xn,k)=>new Date(k.createdAt).getTime()-new Date(xn.createdAt).getTime());Je(Dt);const dn=$e,eo=dn&&Dt.some(xn=>xn.checkpointId===dn)?dn:((_s=Dt[0])==null?void 0:_s.checkpointId)??null;let js=null;if(eo){const xn=Dt.find(k=>k.checkpointId===eo);js=(xn==null?void 0:xn.checkpointNs)??null}st(eo),Z(js),je.current=pe}).catch(ot=>{console.error("ChatInterface - listCheckpoints error:",ot),ne||(Je([]),je.current=null)}),()=>{ne=!0}},[v,L,P,$e,x]),S.useEffect(()=>{L&&(st(L),Z(P??null))},[L,P]);const _n=S.useCallback(async()=>{if(!(!C||T))try{await R()}catch(ne){console.warn("loadOlderMessages failed",ne)}},[C,T,R]);S.useEffect(()=>{(async()=>{if(!w.baseUrl){ye(null);return}try{const pe=await w.getAgent("default");ye(pe.uiDefaultMessage||null)}catch(pe){console.warn("Failed to fetch default message:",pe),ye(null)}})()},[w]),S.useEffect(()=>{M&&!Fe&&(p==null||p(M))},[M,Fe,p]);const G=ne=>{if(ne.length>ns)return`Message too long (${ne.length}/${ns} characters)`;try{return Qw(ne),null}catch(pe){return(pe==null?void 0:pe.message)||"Invalid message"}},ce=async ne=>{const pe=ne.trim();if(!(!pe&&Y.length===0)){if(pe){const Le=G(pe);if(Le){U(Le);return}}try{await I(pe||"",{checkpointId:$e??L??void 0,checkpointNs:lt??P??void 0,payloadExtras:W?{edit:!0,originalMessageId:W}:void 0,attachments:Y}),f==null||f(pe),U(null),fe([]),Ze(),H(null),F("")}catch(Le){const ot=(Le==null?void 0:Le.message)||"Failed to send message";U(ot),p==null||p(ot)}}},Ie=S.useCallback((ne,pe)=>{u&&(H(ne),F(pe),U(null))},[u]),Ve=S.useCallback(()=>{H(null),F(""),U(null)},[]),qe=S.useCallback((ne,pe)=>{Ie(ne,pe)},[Ie]),It=S.useCallback(ne=>{const pe=Le=>{const ot=Le.content||[],Dt=ot.filter(dn=>dn.type==="text").map(dn=>dn.text).join("");if(Dt)return Dt;try{return JSON.stringify(ot,null,2)}catch{return String(ot)}};for(let Le=ne-1;Le>=0;Le--)if(E[Le].role==="user"){const ot=pe(E[Le]);ot&&I(ot,{checkpointId:$e??L??void 0,checkpointNs:lt??P??void 0});break}},[E,I,$e,lt,L,P]),Rn=ne=>{const pe=Array.from(ne.target.files||[]);fe(Le=>[...Le,...pe]),ne.target.value=""},Jt=ne=>{fe(pe=>{const Le=pe.filter((ot,Dt)=>ne!==Dt);return Le.length===0&&Ze(),Le})},Zn=async ne=>{const pe=(ne.target.files||[])[0];if(pe){J(null),oe(null),O(!0);try{await I("",{checkpointId:$e??L??void 0,checkpointNs:lt??P??void 0,attachments:[pe]});const Le=`Uploaded ${pe.name} - processing through chat stream`;oe(Le)}catch(Le){const ot=Le instanceof Error?Le.message:"Failed to upload Excel file";console.error("Excel upload failed",Le),J(ot),p==null||p(ot)}finally{O(!1),ne.target.value="",Ze()}}},Qn=ne=>{if(!ne)return"Unknown";const pe=Date.parse(ne);return Number.isNaN(pe)?ne:new Date(pe).toLocaleString()},wr=async ne=>{if(v){xe(!0);try{if(!ne){await y(),st(null),Z(null);return}const pe=Pe.find(ot=>ot.checkpointId===ne),Le=(pe==null?void 0:pe.checkpointNs)??null;await b(ne,Le),st(ne),Z(Le)}finally{xe(!1)}}},Qr=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,er=`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||""}`,gn=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Qr,children:[!!M&&!Fe&&c.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:[c.jsx("span",{children:M}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>Xe(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(Q.X,{size:16})})]}),v&&Pe.length>0&&c.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:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.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:$e??"",onChange:ne=>{const pe=ne.target.value||null;wr(pe)},children:[c.jsx("option",{value:"",children:"Latest"}),Pe.map(ne=>c.jsxs("option",{value:ne.checkpointId,children:[Qn(ne.createdAt),ne.preview?` — ${ne.preview.slice(0,40)}`:""]},ne.checkpointId))]})]}),c.jsxs("div",{className:`relative ${er}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Gi,{className:"h-full",style:{height:"100%"},messages:E,isStreaming:j,streamingAssistantId:D,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ct,enableMessageEditing:u,editingMessageId:W,onStartReached:()=>{_n()},onEdit:qe,onRegenerate:It,onCancelEdit:Ve,emptyMessage:et??void 0,isNavigatingCheckpoint:le}),g&&c.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:[c.jsx(Q.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:gn,children:[W&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Q.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:Ve,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(Q.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:Ce,type:"file",multiple:!0,onChange:ne=>Rn(ne),className:"hidden"},ie),Y.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:Y.map((ne,pe)=>c.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:[c.jsx(Q.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:ne.name}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>Jt(pe),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 ${ne.name}`,children:c.jsx(Q.X,{size:12})})]},pe))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:we,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Zn,className:"hidden"},Ee),z&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(Q.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),ae&&!z&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:ae}),V&&!z&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:V})]})]}),N&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:N}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(z0,{children:[c.jsx(B0,{asChild:!0,children:c.jsx(Be,{type:"button",size:"icon",variant:"outline",disabled:j,title:"More input actions",className:d.moreButton||"",children:c.jsx(Q.Plus,{size:16})})}),c.jsxs(Wf,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(ba,{onClick:()=>{var ne;return(ne=Ce.current)==null?void 0:ne.click()},className:"cursor-pointer",children:[c.jsx(Q.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(ba,{onClick:()=>{var ne;z||(ne=we.current)==null||ne.click()},className:`cursor-pointer ${z?"opacity-60 pointer-events-none":""}`,children:[c.jsx(Q.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(fg,{initialValue:q,editingMessageId:W,placeholder:W?"Edit your message...":t,isStreaming:j,disabled:!1,maxLength:ns,onSend:ce,onCancelEdit:Ve,onStop:A,allowEmptySend:Y.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":""} ${N?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const bs=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:X("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}));bs.displayName="Input";function ya(e,[t,n]){return Math.min(n,Math.max(t,e))}function G0(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Sa="ScrollArea",[Vf,$C]=nn(Sa),[Y0,Bt]=Vf(Sa),Kf=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,w]=m.useState(null),[v,g]=m.useState(null),[x,b]=m.useState(0),[y,E]=m.useState(0),[C,T]=m.useState(!1),[I,A]=m.useState(!1),R=Oe(t,M=>l(M)),j=rs(o);return c.jsx(Y0,{scope:n,type:r,dir:j,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:v,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:E,children:c.jsx(Se.div,{dir:j,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":y+"px",...e.style}})})});Kf.displayName=Sa;var qf="ScrollAreaViewport",Gf=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Bt(qf,n),a=m.useRef(null),l=Oe(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.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}),c.jsx(Se.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Gf.displayName=qf;var un="ScrollAreaScrollbar",Ca=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(un,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(X0,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(J0,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Yf,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(Ta,{...r,ref:t}):null});Ca.displayName=un;var X0=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(un,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Pt,{present:n||s,children:c.jsx(Yf,{"data-state":s?"visible":"hidden",...r,ref:t})})}),J0=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(un,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ts(()=>l("SCROLL_END"),100),[a,l]=G0("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 m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Pt,{present:n||a!=="hidden",children:c.jsx(Ta,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:se(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:se(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Yf=m.forwardRef((e,t)=>{const n=Bt(un,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=Ts(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return gr(n.viewport,l),gr(n.content,l),c.jsx(Pt,{present:r||s,children:c.jsx(Ta,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ta=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Bt(un,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=eh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return rS(h,i.current,a,p)}return n==="horizontal"?c.jsx(Z0,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=th(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?c.jsx(Q0,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=th(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),Z0=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Bt(un,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Oe(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Jf,{"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":Cs(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),rh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ss(i.paddingLeft),paddingEnd:Ss(i.paddingRight)}})}})}),Q0=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Bt(un,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Oe(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Jf,{"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":Cs(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),rh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ss(i.paddingTop),paddingEnd:Ss(i.paddingBottom)}})}})}),[eS,Xf]=Vf(un),Jf=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=Bt(un,n),[w,v]=m.useState(null),g=Oe(t,R=>v(R)),x=m.useRef(null),b=m.useRef(""),y=p.viewport,E=r.content-r.viewport,C=mt(d),T=mt(l),I=Ts(f,10);function A(R){if(x.current){const j=R.clientX-x.current.left,M=R.clientY-x.current.top;u({x:j,y:M})}}return m.useEffect(()=>{const R=j=>{const M=j.target;(w==null?void 0:w.contains(M))&&C(j,E)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[y,w,E,C]),m.useEffect(T,[r,T]),gr(w,I),gr(p.content,I),c.jsx(eS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:mt(s),onThumbPointerUp:mt(i),onThumbPositionChange:T,onThumbPointerDown:mt(a),children:c.jsx(Se.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:se(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),x.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:se(e.onPointerMove,A),onPointerUp:se(e.onPointerUp,R=>{const j=R.target;j.hasPointerCapture(R.pointerId)&&j.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),ys="ScrollAreaThumb",Zf=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xf(ys,e.__scopeScrollArea);return c.jsx(Pt,{present:n||o.hasThumb,children:c.jsx(tS,{ref:t,...r})})}),tS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Bt(ys,n),i=Xf(ys,n),{onThumbPositionChange:a}=i,l=Oe(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=Ts(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=oS(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(Se.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:se(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),w=f.clientX-p.left,v=f.clientY-p.top;i.onThumbPointerDown({x:w,y:v})}),onPointerUp:se(e.onPointerUp,i.onThumbPointerUp)})});Zf.displayName=ys;var ka="ScrollAreaCorner",Qf=m.forwardRef((e,t)=>{const n=Bt(ka,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(nS,{...e,ref:t}):null});Qf.displayName=ka;var nS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Bt(ka,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return gr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),gr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(Se.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 Ss(e){return e?parseInt(e,10):0}function eh(e,t){const n=e/t;return isNaN(n)?0:n}function Cs(e){const t=eh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function rS(e,t,n,r="ltr"){const o=Cs(n),s=o/2,i=t||s,a=o-i,l=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 nh([l,u],f)(e)}function th(e,t,n="ltr"){const r=Cs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=ya(e,l);return nh([0,i],[0,a])(u)}function nh(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 rh(e,t){return e>0&&e<t}var oS=(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 Ts(e,t){const n=mt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function gr(e,t){const n=mt(t);pt(()=>{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 oh=Kf,sS=Gf,iS=Qf;const sh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(oh,{ref:r,className:X("relative overflow-hidden",e),...n,children:[c.jsx(sS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(ih,{}),c.jsx(iS,{})]}));sh.displayName=oh.displayName;const ih=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(Ca,{ref:r,orientation:t,className:X("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:c.jsx(Zf,{className:"relative flex-1 rounded-full bg-border"})}));ih.displayName=Ca.displayName;function Ea({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{loadThread:f,threads:h,currentThreadId:p,createThread:w,deleteThread:v,renameThread:g,isLoadingThreads:x}=mo(),[b,y]=S.useState(h??[]),[E,C]=S.useState(null),[T,I]=S.useState(""),[A,R]=S.useState(!1);S.useEffect(()=>{y(h??[])},[h]);const j=async N=>{try{await f(N),a==null||a(N),l==null||l(N)}catch(U){console.error("Failed to select thread:",U)}},M=async()=>{try{R(!0);const N=await w();u==null||u(N),a==null||a(N)}catch(N){console.error("Failed to create thread:",N)}finally{R(!1)}},D=async(N,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?"))try{await v(N),d==null||d(N)}catch(Y){console.error("Failed to delete thread:",Y)}},L=(N,U)=>{U.stopPropagation(),C(N.threadId),I(N.title||`Thread ${N.threadId.slice(0,8)}`)},P=async N=>{if(T.trim())try{await g(N,T.trim()),C(null),I("")}catch(U){console.error("Failed to update title:",U)}},W=()=>{C(null),I("")},H=(N,U)=>{N.key==="Enter"?P(U):N.key==="Escape"&&W()},q=N=>{if(!N)return"";try{const U=new Date(N),fe=new Date().getTime()-U.getTime(),ie=Math.floor(fe/(1e3*60*60*24));return ie===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):ie===1?"Yesterday":ie<7?`${ie} days ago`:U.toLocaleDateString()}catch{return""}},F=N=>N.title||`Thread ${N.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.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:c.jsx(Be,{onClick:M,disabled:A||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:A?"Creating...":"New Chat",children:c.jsx(Q.MessageSquarePlus,{size:20})})}),c.jsx(sh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(Q.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):b.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(Q.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):b.slice().sort((N,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(N.updatedAt||N.createdAt||"").getTime()).map(N=>c.jsxs("div",{onClick:()=>j(N.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===N.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:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:E===N.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[c.jsx(bs,{value:T,onChange:U=>I(U.target.value),onKeyDown:U=>H(U,N.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>P(N.threadId),className:"h-6 w-6 p-0",children:c.jsx(Q.Check,{size:12})}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:W,className:"h-6 w-6 p-0",children:c.jsx(Q.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:F(N)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(Q.Calendar,{size:10}),c.jsx("span",{children:q(N.updatedAt||N.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&E!==N.threadId&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:U=>L(N,U),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(Q.Edit3,{size:12})}),n&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:U=>D(N.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(Q.Trash2,{size:12})})]})]}),i===N.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},N.threadId))})})]})}function xr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function aS(e){if(typeof e!="string")return;const t=e.trim();if(t)return fn(t)}function ah(){const e=[xr("__API_BASE_URL__"),xr("__CHAT_API_BASE_URL__"),xr("__CHAT_API_URL__")];for(const t of e){const n=aS(t);if(n)return n}}function lh(){const e=[xr("__API_AUTH_TOKEN__"),xr("__CHAT_API_KEY__"),xr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function ch(...e){for(const t of e)if(typeof t=="string"&&t.trim())return fn(t);return fn()}function uh(){const e={},t=ah(),n=lh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function dh(){const e=uh(),t=vn.getAuthToken(),n=ah();return{apiBaseUrl:ch(e.baseUrl,vn.baseUrl,n),apiKey:t||e.apiKey||lh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const fh="chat-settings";function lS(){try{const e=localStorage.getItem(fh);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function cS(e){try{const t={...e,apiBaseUrl:fn(e.apiBaseUrl)};localStorage.setItem(fh,JSON.stringify(t)),t.apiKey&&vn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function uS(){const e=dh(),t=lS(),n=vn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:ch(vn.baseUrl,r,e.apiBaseUrl)}}function dS(e){vn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),cS(e)}var fS="Label",hh=m.forwardRef((e,t)=>c.jsx(Se.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())}}));hh.displayName=fS;var ph=hh;const hS=to.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ht=m.forwardRef(({className:e,...t},n)=>c.jsx(ph,{ref:n,className:X(hS(),e),...t}));Ht.displayName=ph.displayName;function mh(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var ks="Switch",[pS,zC]=nn(ks),[mS,gS]=pS(ks),gh=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),w=Oe(t,y=>p(y)),v=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[x,b]=Bn({prop:o,defaultProp:s??!1,onChange:u,caller:ks});return c.jsxs(mS,{scope:n,checked:x,disabled:a,children:[c.jsx(Se.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":bh(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:w,onClick:se(e.onClick,y=>{b(E=>!E),g&&(v.current=y.isPropagationStopped(),v.current||y.stopPropagation())})}),g&&c.jsx(wh,{control:h,bubbles:!v.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});gh.displayName=ks;var xh="SwitchThumb",vh=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=gS(xh,n);return c.jsx(Se.span,{"data-state":bh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});vh.displayName=xh;var xS="SwitchBubbleInput",wh=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Oe(i,s),l=mh(n),u=Ad(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const w=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(w)}},[l,n,r]),c.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}})});wh.displayName=xS;function bh(e){return e?"checked":"unchecked"}var yh=gh,vS=vh;const Nn=m.forwardRef(({className:e,...t},n)=>c.jsx(yh,{className:X("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:c.jsx(vS,{className:X("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")})}));Nn.displayName=yh.displayName;var Sh=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"}),wS="VisuallyHidden",bS=m.forwardRef((e,t)=>c.jsx(Se.span,{...e,ref:t,style:{...Sh,...e.style}}));bS.displayName=wS;var yS=[" ","Enter","ArrowUp","ArrowDown"],SS=[" ","Enter"],Yn="Select",[Es,Is,CS]=Yi(Yn),[vr,BC]=nn(Yn,[CS,hs]),Ns=hs(),[TS,An]=vr(Yn),[kS,ES]=vr(Yn),Ch=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:w}=e,v=Ns(t),[g,x]=m.useState(null),[b,y]=m.useState(null),[E,C]=m.useState(!1),T=rs(u),[I,A]=Bn({prop:r,defaultProp:o??!1,onChange:s,caller:Yn}),[R,j]=Bn({prop:i,defaultProp:a,onChange:l,caller:Yn}),M=m.useRef(null),D=g?w||!!g.closest("form"):!0,[L,P]=m.useState(new Set),W=Array.from(L).map(H=>H.props.value).join(";");return c.jsx($d,{...v,children:c.jsxs(TS,{required:p,scope:t,trigger:g,onTriggerChange:x,valueNode:b,onValueNodeChange:y,valueNodeHasChildren:E,onValueNodeHasChildrenChange:C,contentId:rn(),value:R,onValueChange:j,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:M,disabled:h,children:[c.jsx(Es.Provider,{scope:t,children:c.jsx(kS,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(H=>{P(q=>new Set(q).add(H))},[]),onNativeOptionRemove:m.useCallback(H=>{P(q=>{const F=new Set(q);return F.delete(H),F})},[]),children:n})}),D?c.jsxs(qh,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:H=>j(H.target.value),disabled:h,form:w,children:[R===void 0?c.jsx("option",{value:""}):null,Array.from(L)]},W):null]})})};Ch.displayName=Yn;var Th="SelectTrigger",kh=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ns(n),i=An(Th,n),a=i.disabled||r,l=Oe(t,i.onTriggerChange),u=Is(n),d=m.useRef("touch"),[f,h,p]=Yh(v=>{const g=u().filter(y=>!y.disabled),x=g.find(y=>y.value===i.value),b=Xh(g,v,x);b!==void 0&&i.onValueChange(b.value)}),w=v=>{a||(i.onOpenChange(!0),p()),v&&(i.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return c.jsx(zd,{asChild:!0,...s,children:c.jsx(Se.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":Gh(i.value)?"":void 0,...o,ref:l,onClick:se(o.onClick,v=>{v.currentTarget.focus(),d.current!=="mouse"&&w(v)}),onPointerDown:se(o.onPointerDown,v=>{d.current=v.pointerType;const g=v.target;g.hasPointerCapture(v.pointerId)&&g.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(w(v),v.preventDefault())}),onKeyDown:se(o.onKeyDown,v=>{const g=f.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&h(v.key),!(g&&v.key===" ")&&yS.includes(v.key)&&(w(),v.preventDefault())})})})});kh.displayName=Th;var Eh="SelectValue",Ih=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=An(Eh,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=Oe(t,l.onValueNodeChange);return pt(()=>{u(d)},[u,d]),c.jsx(Se.span,{...a,ref:f,style:{pointerEvents:"none"},children:Gh(l.value)?c.jsx(c.Fragment,{children:i}):s})});Ih.displayName=Eh;var IS="SelectIcon",Nh=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Se.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Nh.displayName=IS;var NS="SelectPortal",Ah=e=>c.jsx(Bo,{asChild:!0,...e});Ah.displayName=NS;var Xn="SelectContent",jh=m.forwardRef((e,t)=>{const n=An(Xn,e.__scopeSelect),[r,o]=m.useState();if(pt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?no.createPortal(c.jsx(_h,{scope:e.__scopeSelect,children:c.jsx(Es.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Rh,{...e,ref:t})});jh.displayName=Xn;var Xt=10,[_h,jn]=vr(Xn),AS="SelectContentImpl",jS=Pn.createSlot("SelectContent.RemoveScroll"),Rh=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:v,avoidCollisions:g,...x}=e,b=An(Xn,n),[y,E]=m.useState(null),[C,T]=m.useState(null),I=Oe(t,z=>E(z)),[A,R]=m.useState(null),[j,M]=m.useState(null),D=Is(n),[L,P]=m.useState(!1),W=m.useRef(!1);m.useEffect(()=>{if(y)return Ui(y)},[y]),Li();const H=m.useCallback(z=>{const[O,...V]=D().map(oe=>oe.ref.current),[J]=V.slice(-1),ae=document.activeElement;for(const oe of z)if(oe===ae||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===O&&C&&(C.scrollTop=0),oe===J&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==ae))return},[D,C]),q=m.useCallback(()=>H([A,y]),[H,A,y]);m.useEffect(()=>{L&&q()},[L,q]);const{onOpenChange:F,triggerPointerDownPosRef:N}=b;m.useEffect(()=>{if(y){let z={x:0,y:0};const O=J=>{var ae,oe;z={x:Math.abs(Math.round(J.pageX)-(((ae=N.current)==null?void 0:ae.x)??0)),y:Math.abs(Math.round(J.pageY)-(((oe=N.current)==null?void 0:oe.y)??0))}},V=J=>{z.x<=10&&z.y<=10?J.preventDefault():y.contains(J.target)||F(!1),document.removeEventListener("pointermove",O),N.current=null};return N.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",V,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",V,{capture:!0})}}},[y,F,N]),m.useEffect(()=>{const z=()=>F(!1);return window.addEventListener("blur",z),window.addEventListener("resize",z),()=>{window.removeEventListener("blur",z),window.removeEventListener("resize",z)}},[F]);const[U,Y]=Yh(z=>{const O=D().filter(ae=>!ae.disabled),V=O.find(ae=>ae.ref.current===document.activeElement),J=Xh(O,z,V);J&&setTimeout(()=>J.ref.current.focus())}),fe=m.useCallback((z,O,V)=>{const J=!W.current&&!V;(b.value!==void 0&&b.value===O||J)&&(R(z),J&&(W.current=!0))},[b.value]),ie=m.useCallback(()=>y==null?void 0:y.focus(),[y]),he=m.useCallback((z,O,V)=>{const J=!W.current&&!V;(b.value!==void 0&&b.value===O||J)&&M(z)},[b.value]),Ee=r==="popper"?Ia:Ph,de=Ee===Ia?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:v,avoidCollisions:g}:{};return c.jsx(_h,{scope:n,content:y,viewport:C,onViewportChange:T,itemRefCallback:fe,selectedItem:A,onItemLeave:ie,itemTextRefCallback:he,focusSelectedItem:q,selectedItemText:j,position:r,isPositioned:L,searchRef:U,children:c.jsx(qo,{as:jS,allowPinchZoom:!0,children:c.jsx(zo,{asChild:!0,trapped:b.open,onMountAutoFocus:z=>{z.preventDefault()},onUnmountAutoFocus:se(o,z=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),z.preventDefault()}),children:c.jsx($o,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:z=>z.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(Ee,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:z=>z.preventDefault(),...x,...de,onPlaced:()=>P(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:se(x.onKeyDown,z=>{const O=z.ctrlKey||z.altKey||z.metaKey;if(z.key==="Tab"&&z.preventDefault(),!O&&z.key.length===1&&Y(z.key),["ArrowUp","ArrowDown","Home","End"].includes(z.key)){let J=D().filter(ae=>!ae.disabled).map(ae=>ae.ref.current);if(["ArrowUp","End"].includes(z.key)&&(J=J.slice().reverse()),["ArrowUp","ArrowDown"].includes(z.key)){const ae=z.target,oe=J.indexOf(ae);J=J.slice(oe+1)}setTimeout(()=>H(J)),z.preventDefault()}})})})})})})});Rh.displayName=AS;var _S="SelectItemAlignedPosition",Ph=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=An(Xn,n),i=jn(Xn,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=Oe(t,I=>d(I)),h=Is(n),p=m.useRef(!1),w=m.useRef(!0),{viewport:v,selectedItem:g,selectedItemText:x,focusSelectedItem:b}=i,y=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&v&&g&&x){const I=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),j=x.getBoundingClientRect();if(s.dir!=="rtl"){const ae=j.left-A.left,oe=R.left-ae,Fe=I.left-oe,Xe=I.width+Fe,et=Math.max(Xe,A.width),ye=window.innerWidth-Xt,Pe=ya(oe,[Xt,Math.max(Xt,ye-et)]);a.style.minWidth=Xe+"px",a.style.left=Pe+"px"}else{const ae=A.right-j.right,oe=window.innerWidth-R.right-ae,Fe=window.innerWidth-I.right-oe,Xe=I.width+Fe,et=Math.max(Xe,A.width),ye=window.innerWidth-Xt,Pe=ya(oe,[Xt,Math.max(Xt,ye-et)]);a.style.minWidth=Xe+"px",a.style.right=Pe+"px"}const M=h(),D=window.innerHeight-Xt*2,L=v.scrollHeight,P=window.getComputedStyle(u),W=parseInt(P.borderTopWidth,10),H=parseInt(P.paddingTop,10),q=parseInt(P.borderBottomWidth,10),F=parseInt(P.paddingBottom,10),N=W+H+L+F+q,U=Math.min(g.offsetHeight*5,N),Y=window.getComputedStyle(v),fe=parseInt(Y.paddingTop,10),ie=parseInt(Y.paddingBottom,10),he=I.top+I.height/2-Xt,Ee=D-he,de=g.offsetHeight/2,z=g.offsetTop+de,O=W+H+z,V=N-O;if(O<=he){const ae=M.length>0&&g===M[M.length-1].ref.current;a.style.bottom="0px";const oe=u.clientHeight-v.offsetTop-v.offsetHeight,Fe=Math.max(Ee,de+(ae?ie:0)+oe+q),Xe=O+Fe;a.style.height=Xe+"px"}else{const ae=M.length>0&&g===M[0].ref.current;a.style.top="0px";const Fe=Math.max(he,W+v.offsetTop+(ae?fe:0)+de)+V;a.style.height=Fe+"px",v.scrollTop=O-he+v.offsetTop}a.style.margin=`${Xt}px 0`,a.style.minHeight=U+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,v,g,x,s.dir,r]);pt(()=>y(),[y]);const[E,C]=m.useState();pt(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const T=m.useCallback(I=>{I&&w.current===!0&&(y(),b==null||b(),w.current=!1)},[y,b]);return c.jsx(PS,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:E},children:c.jsx(Se.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Ph.displayName=_S;var RS="SelectPopperPosition",Ia=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Xt,...s}=e,i=Ns(n);return c.jsx(Bd,{...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)"}})});Ia.displayName=RS;var[PS,Na]=vr(Xn,{}),Aa="SelectViewport",Oh=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=jn(Aa,n),i=Na(Aa,n),a=Oe(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.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}),c.jsx(Es.Slot,{scope:n,children:c.jsx(Se.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:se(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const w=window.innerHeight-Xt*2,v=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),x=Math.max(v,g);if(x<w){const b=x+p,y=Math.min(w,b),E=b-y;f.style.height=y+"px",f.style.bottom==="0px"&&(d.scrollTop=E>0?E:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Oh.displayName=Aa;var Mh="SelectGroup",[OS,MS]=vr(Mh),DS=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=rn();return c.jsx(OS,{scope:n,id:o,children:c.jsx(Se.div,{role:"group","aria-labelledby":o,...r,ref:t})})});DS.displayName=Mh;var Dh="SelectLabel",Lh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=MS(Dh,n);return c.jsx(Se.div,{id:o.id,...r,ref:t})});Lh.displayName=Dh;var As="SelectItem",[LS,Fh]=vr(As),$h=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=An(As,n),l=jn(As,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),w=Oe(t,b=>{var y;return(y=l.itemRefCallback)==null?void 0:y.call(l,b,r,o)}),v=rn(),g=m.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 c.jsx(LS,{scope:n,value:r,disabled:o,textId:v,isSelected:u,onItemTextChange:m.useCallback(b=>{f(y=>y||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(Es.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Se.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:se(i.onFocus,()=>p(!0)),onBlur:se(i.onBlur,()=>p(!1)),onClick:se(i.onClick,()=>{g.current!=="mouse"&&x()}),onPointerUp:se(i.onPointerUp,()=>{g.current==="mouse"&&x()}),onPointerDown:se(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:se(i.onPointerMove,b=>{var y;g.current=b.pointerType,o?(y=l.onItemLeave)==null||y.call(l):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:se(i.onPointerLeave,b=>{var y;b.currentTarget===document.activeElement&&((y=l.onItemLeave)==null||y.call(l))}),onKeyDown:se(i.onKeyDown,b=>{var E;((E=l.searchRef)==null?void 0:E.current)!==""&&b.key===" "||(SS.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});$h.displayName=As;var Zr="SelectItemText",zh=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=An(Zr,n),a=jn(Zr,n),l=Fh(Zr,n),u=ES(Zr,n),[d,f]=m.useState(null),h=Oe(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,w=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:v,onNativeOptionRemove:g}=u;return pt(()=>(v(w),()=>g(w)),[v,g,w]),c.jsxs(c.Fragment,{children:[c.jsx(Se.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?no.createPortal(s.children,i.valueNode):null]})});zh.displayName=Zr;var Bh="SelectItemIndicator",Hh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Fh(Bh,n).isSelected?c.jsx(Se.span,{"aria-hidden":!0,...r,ref:t}):null});Hh.displayName=Bh;var ja="SelectScrollUpButton",Uh=m.forwardRef((e,t)=>{const n=jn(ja,e.__scopeSelect),r=Na(ja,e.__scopeSelect),[o,s]=m.useState(!1),i=Oe(t,r.onScrollButtonChange);return pt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Uh.displayName=ja;var _a="SelectScrollDownButton",Wh=m.forwardRef((e,t)=>{const n=jn(_a,e.__scopeSelect),r=Na(_a,e.__scopeSelect),[o,s]=m.useState(!1),i=Oe(t,r.onScrollButtonChange);return pt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Wh.displayName=_a;var Vh=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=jn("SelectScrollButton",n),i=m.useRef(null),a=Is(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),pt(()=>{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]),c.jsx(Se.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:se(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:se(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:se(o.onPointerLeave,()=>{l()})})}),FS="SelectSeparator",Kh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Se.div,{"aria-hidden":!0,...r,ref:t})});Kh.displayName=FS;var Ra="SelectArrow",$S=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ns(n),s=An(Ra,n),i=jn(Ra,n);return s.open&&i.position==="popper"?c.jsx(Hd,{...o,...r,ref:t}):null});$S.displayName=Ra;var zS="SelectBubbleInput",qh=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Oe(r,o),i=mh(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(Se.select,{...n,style:{...Sh,...n.style},ref:s,defaultValue:t})});qh.displayName=zS;function Gh(e){return e===""||e===void 0}function Yh(e){const t=mt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Xh(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=BS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function BS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var HS=Ch,Jh=kh,US=Ih,WS=Nh,VS=Ah,Zh=jh,KS=Oh,Qh=Lh,ep=$h,qS=zh,GS=Hh,tp=Uh,np=Wh,rp=Kh;const op=HS,sp=US,Pa=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Jh,{ref:r,className:X("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,c.jsx(WS,{asChild:!0,children:c.jsx(Q.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Pa.displayName=Jh.displayName;const ip=m.forwardRef(({className:e,...t},n)=>c.jsx(tp,{ref:n,className:X("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(Q.ChevronUp,{className:"h-4 w-4"})}));ip.displayName=tp.displayName;const ap=m.forwardRef(({className:e,...t},n)=>c.jsx(np,{ref:n,className:X("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(Q.ChevronDown,{className:"h-4 w-4"})}));ap.displayName=np.displayName;const Oa=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(VS,{children:c.jsxs(Zh,{ref:o,className:X("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:[c.jsx(ip,{}),c.jsx(KS,{className:X("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(ap,{})]})}));Oa.displayName=Zh.displayName;const YS=m.forwardRef(({className:e,...t},n)=>c.jsx(Qh,{ref:n,className:X("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));YS.displayName=Qh.displayName;const Jn=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(ep,{ref:r,className:X("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(GS,{children:c.jsx(Q.Check,{className:"h-4 w-4"})})}),c.jsx(qS,{children:t})]}));Jn.displayName=ep.displayName;const XS=m.forwardRef(({className:e,...t},n)=>c.jsx(rp,{ref:n,className:X("-mx-1 my-1 h-px bg-muted",e),...t}));XS.displayName=rp.displayName;var JS="Separator",lp="horizontal",ZS=["horizontal","vertical"],cp=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=lp,...o}=e,s=QS(r)?r:lp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Se.div,{"data-orientation":s,...a,...o,ref:t})});cp.displayName=JS;function QS(e){return ZS.includes(e)}var up=cp;const dp=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(up,{ref:o,decorative:n,orientation:t,className:X("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));dp.displayName=up.displayName;const eC=Gu,tC=Ow,nC=Yu,fp=m.forwardRef(({className:e,...t},n)=>c.jsx(Zo,{className:X("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}));fp.displayName=Zo.displayName;const rC=to.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"}}),hp=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(nC,{children:[c.jsx(fp,{}),c.jsxs(Qo,{ref:o,className:X(rC({side:e}),t),...r,children:[n,c.jsxs(Xu,{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:[c.jsx(Q.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));hp.displayName=Qo.displayName;const pp=({className:e,...t})=>c.jsx("div",{className:X("flex flex-col space-y-2 text-center sm:text-left",e),...t});pp.displayName="SheetHeader";const mp=m.forwardRef(({className:e,...t},n)=>c.jsx(Wn,{ref:n,className:X("text-lg font-semibold text-foreground",e),...t}));mp.displayName=Wn.displayName;const gp=m.forwardRef(({className:e,...t},n)=>c.jsx(es,{ref:n,className:X("text-sm text-muted-foreground",e),...t}));gp.displayName=es.displayName;const oC={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 sC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=S.useState(!1),[s,i]=S.useState(!1),[a,l]=S.useState(e),[u,d]=S.useState(!1),{toast:f}=Ri();S.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),S.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(oC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{l(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 c.jsxs(eC,{open:r,onOpenChange:o,children:[c.jsx(tC,{asChild:!0,children:c.jsxs(Be,{variant:"outline",size:"sm",className:n,children:[c.jsx(Q.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Si,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(hp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(pp,{children:[c.jsx(mp,{children:"Chat Settings"}),c.jsx(gp,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(Fr,{children:[c.jsx($r,{className:"pb-3",children:c.jsxs(zr,{className:"text-lg flex items-center gap-2",children:[c.jsx(Q.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(Ro,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ht,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(bs,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(x=>({...x,api:{...x.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(Be,{variant:"outline",onClick:v,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Ht,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Nn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(x=>({...x,api:{...x.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ht,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(bs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(x=>({...x,api:{...x.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(Be,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(Q.EyeOff,{className:"h-4 w-4"}):c.jsx(Q.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(Fr,{children:[c.jsx($r,{className:"pb-3",children:c.jsxs(zr,{className:"text-lg flex items-center gap-2",children:[c.jsx(Q.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(Ro,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ht,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(op,{value:a.ui.layout,onValueChange:g=>l(x=>({...x,ui:{...x.ui,layout:g}})),children:[c.jsx(Pa,{children:c.jsx(sp,{})}),c.jsxs(Oa,{children:[c.jsx(Jn,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(Jn,{value:"fullscreen",children:"Fullscreen"}),c.jsx(Jn,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ht,{htmlFor:"theme",children:"Theme"}),c.jsxs(op,{value:a.ui.theme,onValueChange:g=>l(x=>({...x,ui:{...x.ui,theme:g}})),children:[c.jsx(Pa,{children:c.jsx(sp,{})}),c.jsxs(Oa,{children:[c.jsx(Jn,{value:"light",children:"Light"}),c.jsx(Jn,{value:"dark",children:"Dark"}),c.jsx(Jn,{value:"system",children:"System"})]})]})]}),c.jsx(dp,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Ht,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Nn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Ht,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Nn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Ht,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Nn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(Fr,{children:[c.jsx($r,{className:"pb-3",children:c.jsxs(zr,{className:"text-lg flex items-center gap-2",children:[c.jsx(Q.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(Ro,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Ht,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Nn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Ht,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Nn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Ht,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Nn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(Be,{variant:"outline",onClick:p,children:[c.jsx(Q.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Be,{variant:"outline",onClick:w,children:"Cancel"}),c.jsxs(Be,{onClick:h,disabled:!u,children:[c.jsx(Q.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function iC({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"}),l=S.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(go,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(ws,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(go,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(Ea,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(ws,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(go,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(Ea,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(ws,{onError:s.onError,enableFileUpload:!0})})]})})}ke.ChatApi=jl,ke.ChatInterface=ws,ke.ChatProviders=go,ke.ChatSettings=sC,ke.MarkdownContent=Ai,ke.MessageComponent=sd,ke.MessageList=Gi,ke.ThreadManager=Ea,ke.applySettings=dS,ke.chatApiClient=vn,ke.default=iC,ke.del=Al,ke.get=At,ke.getChatToken=El,ke.getCurrentSettings=uS,ke.getDefaultApiConfig=uh,ke.getDefaultChatSettings=dh,ke.onChatTokenChanged=Il,ke.post=qs,ke.put=Nl,ke.setChatToken=Ks,ke.useApi=Gs,ke.useChatStream=Ol,ke.useMessages=Zs,ke.useMessagesReducer=Rl,ke.useStream=Fl,ke.useThreads=mo,Object.defineProperties(ke,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
139
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function Zw(e,t=ns){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 Qw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Zw(t),Jw(t)}function Yi(e){const t=e+"CollectionProvider",[n,r]=nn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:g,children:x}=v,b=S.useRef(null),y=S.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:y,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Pn.createSlot(a),u=S.forwardRef((v,g)=>{const{scope:x,children:b}=v,y=s(a,x),E=Oe(g,y.collectionRef);return c.jsx(l,{ref:E,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Pn.createSlot(d),p=S.forwardRef((v,g)=>{const{scope:x,children:b,...y}=v,E=S.useRef(null),C=Oe(g,E),T=s(d,x);return S.useEffect(()=>(T.itemMap.set(E,{ref:E,...y}),()=>void T.itemMap.delete(E))),c.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function w(v){const g=s(e+"CollectionConsumer",v);return S.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const y=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((T,I)=>y.indexOf(T.ref.current)-y.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},w,r]}var eb=m.createContext(void 0);function rs(e){const t=m.useContext(eb);return e||t||"ltr"}const tb=["top","right","bottom","left"],En=Math.min,Ot=Math.max,os=Math.round,ss=Math.floor,sn=e=>({x:e,y:e}),nb={left:"right",right:"left",bottom:"top",top:"bottom"},rb={start:"end",end:"start"};function Xi(e,t,n){return Ot(e,En(t,n))}function pn(e,t){return typeof e=="function"?e(t):e}function mn(e){return e.split("-")[0]}function fr(e){return e.split("-")[1]}function Ji(e){return e==="x"?"y":"x"}function Zi(e){return e==="y"?"height":"width"}const ob=new Set(["top","bottom"]);function an(e){return ob.has(mn(e))?"y":"x"}function Qi(e){return Ji(an(e))}function sb(e,t,n){n===void 0&&(n=!1);const r=fr(e),o=Qi(e),s=Zi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=is(i)),[i,is(i)]}function ib(e){const t=is(e);return[ea(e),t,ea(t)]}function ea(e){return e.replace(/start|end/g,t=>rb[t])}const ad=["left","right"],ld=["right","left"],ab=["top","bottom"],lb=["bottom","top"];function cb(e,t,n){switch(e){case"top":case"bottom":return n?t?ld:ad:t?ad:ld;case"left":case"right":return t?ab:lb;default:return[]}}function ub(e,t,n,r){const o=fr(e);let s=cb(mn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ea)))),s}function is(e){return e.replace(/left|right|bottom|top/g,t=>nb[t])}function db(e){return{top:0,right:0,bottom:0,left:0,...e}}function cd(e){return typeof e!="number"?db(e):{top:e,right:e,bottom:e,left:e}}function as(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 ud(e,t,n){let{reference:r,floating:o}=e;const s=an(t),i=Qi(t),a=Zi(i),l=mn(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 p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(fr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const fb=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=ud(u,r,l),h=r,p={},w=0;for(let v=0;v<a.length;v++){const{name:g,fn:x}=a[v],{x:b,y,data:E,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=y??f,p={...p,[g]:{...p[g],...E}},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}=ud(u,h,l)),v=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Ur(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=pn(t,e),w=cd(p),g=a[h?f==="floating"?"reference":"floating":f],x=as(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,y=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(y))?await(s.getScale==null?void 0:s.getScale(y))||{x:1,y:1}:{x:1,y:1},C=as(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:y,strategy:l}):b);return{top:(x.top-C.top+w.top)/E.y,bottom:(C.bottom-x.bottom+w.bottom)/E.y,left:(x.left-C.left+w.left)/E.x,right:(C.right-x.right+w.right)/E.x}}const hb=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=pn(e,t)||{};if(u==null)return{};const f=cd(d),h={x:n,y:r},p=Qi(o),w=Zi(p),v=await i.getDimensions(u),g=p==="y",x=g?"top":"left",b=g?"bottom":"right",y=g?"clientHeight":"clientWidth",E=s.reference[w]+s.reference[p]-h[p]-s.floating[w],C=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=T?T[y]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[y]||s.floating[w]);const A=E/2-C/2,R=I/2-v[w]/2-1,j=En(f[x],R),M=En(f[b],R),D=j,L=I-v[w]-M,P=I/2-v[w]/2+A,W=Xi(D,P,L),H=!l.arrow&&fr(o)!=null&&P!==W&&s.reference[w]/2-(P<D?j:M)-v[w]/2<0,q=H?P<D?P-D:P-L:0;return{[p]:h[p]+q,data:{[p]:W,centerOffset:P-W-q,...H&&{alignmentOffset:q}},reset:H}}}),pb=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...g}=pn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=mn(o),b=an(a),y=mn(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(u.floating)),C=h||(y||!v?[is(a)]:ib(a)),T=w!=="none";!h&&T&&C.push(...ub(a,v,w,E));const I=[a,...C],A=await Ur(t,g),R=[];let j=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(A[x]),f){const P=sb(o,i,E);R.push(A[P[0]],A[P[1]])}if(j=[...j,{placement:o,overflows:R}],!R.every(P=>P<=0)){var M,D;const P=(((M=s.flip)==null?void 0:M.index)||0)+1,W=I[P];if(W&&(!(f==="alignment"?b!==an(W):!1)||j.every(F=>an(F.placement)===b?F.overflows[0]>0:!0)))return{data:{index:P,overflows:j},reset:{placement:W}};let H=(D=j.filter(q=>q.overflows[0]<=0).sort((q,F)=>q.overflows[1]-F.overflows[1])[0])==null?void 0:D.placement;if(!H)switch(p){case"bestFit":{var L;const q=(L=j.filter(F=>{if(T){const N=an(F.placement);return N===b||N==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(N=>N>0).reduce((N,U)=>N+U,0)]).sort((F,N)=>F[1]-N[1])[0])==null?void 0:L[0];q&&(H=q);break}case"initialPlacement":H=a;break}if(o!==H)return{reset:{placement:H}}}return{}}}};function dd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function fd(e){return tb.some(t=>e[t]>=0)}const mb=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=pn(e,t);switch(r){case"referenceHidden":{const s=await Ur(t,{...o,elementContext:"reference"}),i=dd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:fd(i)}}}case"escaped":{const s=await Ur(t,{...o,altBoundary:!0}),i=dd(s,n.floating);return{data:{escapedOffsets:i,escaped:fd(i)}}}default:return{}}}}},hd=new Set(["left","top"]);async function gb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=mn(n),a=fr(n),l=an(n)==="y",u=hd.has(i)?-1:1,d=s&&l?-1:1,f=pn(t,e);let{mainAxis:h,crossAxis:p,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"&&(p=a==="end"?w*-1:w),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const xb=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await gb(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},vb=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x,y:b}=g;return{x,y:b}}},...l}=pn(e,t),u={x:n,y:r},d=await Ur(t,l),f=an(mn(o)),h=Ji(f);let p=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=p+d[g],y=p-d[x];p=Xi(b,p,y)}if(i){const g=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=w+d[g],y=w-d[x];w=Xi(b,w,y)}const v=a.fn({...t,[h]:p,[f]:w});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[h]:s,[f]:i}}}}}},wb=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=pn(e,t),d={x:n,y:r},f=an(o),h=Ji(f);let p=d[h],w=d[f];const v=pn(a,t),g=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(l){const y=h==="y"?"height":"width",E=s.reference[h]-s.floating[y]+g.mainAxis,C=s.reference[h]+s.reference[y]-g.mainAxis;p<E?p=E:p>C&&(p=C)}if(u){var x,b;const y=h==="y"?"width":"height",E=hd.has(mn(o)),C=s.reference[f]-s.floating[y]+(E&&((x=i.offset)==null?void 0:x[f])||0)+(E?0:g.crossAxis),T=s.reference[f]+s.reference[y]+(E?0:((b=i.offset)==null?void 0:b[f])||0)-(E?g.crossAxis:0);w<C?w=C:w>T&&(w=T)}return{[h]:p,[f]:w}}}},bb=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=pn(e,t),d=await Ur(t,u),f=mn(o),h=fr(o),p=an(o)==="y",{width:w,height:v}=s.floating;let g,x;f==="top"||f==="bottom"?(g=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,g=h==="end"?"top":"bottom");const b=v-d.top-d.bottom,y=w-d.left-d.right,E=En(v-d[g],b),C=En(w-d[x],y),T=!t.middlewareData.shift;let I=E,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!h){const j=Ot(d.left,0),M=Ot(d.right,0),D=Ot(d.top,0),L=Ot(d.bottom,0);p?A=w-2*(j!==0||M!==0?j+M:Ot(d.left,d.right)):I=v-2*(D!==0||L!==0?D+L:Ot(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const R=await i.getDimensions(a.floating);return w!==R.width||v!==R.height?{reset:{rects:!0}}:{}}}};function ls(){return typeof window<"u"}function hr(e){return pd(e)?(e.nodeName||"").toLowerCase():"#document"}function Mt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ln(e){var t;return(t=(pd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function pd(e){return ls()?e instanceof Node||e instanceof Mt(e).Node:!1}function Gt(e){return ls()?e instanceof Element||e instanceof Mt(e).Element:!1}function cn(e){return ls()?e instanceof HTMLElement||e instanceof Mt(e).HTMLElement:!1}function md(e){return!ls()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Mt(e).ShadowRoot}const yb=new Set(["inline","contents"]);function Wr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Yt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!yb.has(o)}const Sb=new Set(["table","td","th"]);function Cb(e){return Sb.has(hr(e))}const Tb=[":popover-open",":modal"];function cs(e){return Tb.some(t=>{try{return e.matches(t)}catch{return!1}})}const kb=["transform","translate","scale","rotate","perspective"],Eb=["transform","translate","scale","rotate","perspective","filter"],Ib=["paint","layout","strict","content"];function ta(e){const t=na(),n=Gt(e)?Yt(e):e;return kb.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)||Eb.some(r=>(n.willChange||"").includes(r))||Ib.some(r=>(n.contain||"").includes(r))}function Nb(e){let t=In(e);for(;cn(t)&&!pr(t);){if(ta(t))return t;if(cs(t))return null;t=In(t)}return null}function na(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Ab=new Set(["html","body","#document"]);function pr(e){return Ab.has(hr(e))}function Yt(e){return Mt(e).getComputedStyle(e)}function us(e){return Gt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function In(e){if(hr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||md(e)&&e.host||ln(e);return md(t)?t.host:t}function gd(e){const t=In(e);return pr(t)?e.ownerDocument?e.ownerDocument.body:e.body:cn(t)&&Wr(t)?t:gd(t)}function Vr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=gd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Mt(o);if(s){const a=ra(i);return t.concat(i,i.visualViewport||[],Wr(o)?o:[],a&&n?Vr(a):[])}return t.concat(o,Vr(o,[],n))}function ra(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function xd(e){const t=Yt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=cn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=os(n)!==s||os(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function oa(e){return Gt(e)?e:e.contextElement}function mr(e){const t=oa(e);if(!cn(t))return sn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=xd(t);let i=(s?os(n.width):n.width)/r,a=(s?os(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const jb=sn(0);function vd(e){const t=Mt(e);return!na()||!t.visualViewport?jb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function _b(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Mt(e)?!1:t}function Kn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=oa(e);let i=sn(1);t&&(r?Gt(r)&&(i=mr(r)):i=mr(e));const a=_b(s,n,r)?vd(s):sn(0);let l=(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=Mt(s),p=r&&Gt(r)?Mt(r):r;let w=h,v=ra(w);for(;v&&r&&p!==w;){const g=mr(v),x=v.getBoundingClientRect(),b=Yt(v),y=x.left+(v.clientLeft+parseFloat(b.paddingLeft))*g.x,E=x.top+(v.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=y,u+=E,w=Mt(v),v=ra(w)}}return as({width:d,height:f,x:l,y:u})}function sa(e,t){const n=us(e).scrollLeft;return t?t.left+n:Kn(ln(e)).left+n}function wd(e,t,n){n===void 0&&(n=!1);const r=e.getBoundingClientRect(),o=r.left+t.scrollLeft-(n?0:sa(e,r)),s=r.top+t.scrollTop;return{x:o,y:s}}function Rb(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=ln(r),a=t?cs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=sn(1);const d=sn(0),f=cn(r);if((f||!f&&!s)&&((hr(r)!=="body"||Wr(i))&&(l=us(r)),cn(r))){const p=Kn(r);u=mr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?wd(i,l,!0):sn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function Pb(e){return Array.from(e.getClientRects())}function Ob(e){const t=ln(e),n=us(e),r=e.ownerDocument.body,o=Ot(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ot(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+sa(e);const a=-n.scrollTop;return Yt(r).direction==="rtl"&&(i+=Ot(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function Mb(e,t){const n=Mt(e),r=ln(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const u=na();(!u||u&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}const Db=new Set(["absolute","fixed"]);function Lb(e,t){const n=Kn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=cn(e)?mr(e):sn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function bd(e,t,n){let r;if(t==="viewport")r=Mb(e,n);else if(t==="document")r=Ob(ln(e));else if(Gt(t))r=Lb(t,n);else{const o=vd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return as(r)}function yd(e,t){const n=In(e);return n===t||!Gt(n)||pr(n)?!1:Yt(n).position==="fixed"||yd(n,t)}function Fb(e,t){const n=t.get(e);if(n)return n;let r=Vr(e,[],!1).filter(a=>Gt(a)&&hr(a)!=="body"),o=null;const s=Yt(e).position==="fixed";let i=s?In(e):e;for(;Gt(i)&&!pr(i);){const a=Yt(i),l=ta(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Db.has(o.position)||Wr(i)&&!l&&yd(e,i))?r=r.filter(d=>d!==i):o=a,i=In(i)}return t.set(e,r),r}function $b(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?cs(t)?[]:Fb(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=bd(t,d,o);return u.top=Ot(f.top,u.top),u.right=En(f.right,u.right),u.bottom=En(f.bottom,u.bottom),u.left=Ot(f.left,u.left),u},bd(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function zb(e){const{width:t,height:n}=xd(e);return{width:t,height:n}}function Bb(e,t,n){const r=cn(t),o=ln(t),s=n==="fixed",i=Kn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=sn(0);function u(){l.x=sa(o)}if(r||!r&&!s)if((hr(t)!=="body"||Wr(o))&&(a=us(t)),r){const p=Kn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?wd(o,a):sn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function ia(e){return Yt(e).position==="static"}function Sd(e,t){if(!cn(e)||Yt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ln(e)===n&&(n=n.ownerDocument.body),n}function Cd(e,t){const n=Mt(e);if(cs(e))return n;if(!cn(e)){let o=In(e);for(;o&&!pr(o);){if(Gt(o)&&!ia(o))return o;o=In(o)}return n}let r=Sd(e,t);for(;r&&Cb(r)&&ia(r);)r=Sd(r,t);return r&&pr(r)&&ia(r)&&!ta(r)?n:r||Nb(e)||n}const Hb=async function(e){const t=this.getOffsetParent||Cd,n=this.getDimensions,r=await n(e.floating);return{reference:Bb(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Ub(e){return Yt(e).direction==="rtl"}const Wb={convertOffsetParentRelativeRectToViewportRelativeRect:Rb,getDocumentElement:ln,getClippingRect:$b,getOffsetParent:Cd,getElementRects:Hb,getClientRects:Pb,getDimensions:zb,getScale:mr,isElement:Gt,isRTL:Ub};function Td(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Vb(e,t){let n=null,r;const o=ln(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const w=ss(f),v=ss(o.clientWidth-(d+h)),g=ss(o.clientHeight-(f+p)),x=ss(d),y={rootMargin:-w+"px "+-v+"px "+-g+"px "+-x+"px",threshold:Ot(0,En(1,l))||1};let E=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!E)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Td(u,e.getBoundingClientRect())&&i(),E=!1}try{n=new IntersectionObserver(C,{...y,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,y)}n.observe(e)}return i(!0),s}function Kb(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=oa(e),d=o||s?[...u?Vr(u):[],...Vr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?Vb(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[b]=x;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var y;(y=p)==null||y.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let w,v=l?Kn(e):null;l&&g();function g(){const x=Kn(e);v&&!Td(v,x)&&n(),v=x,w=requestAnimationFrame(g)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(w)}}const qb=xb,Gb=vb,Yb=pb,Xb=bb,Jb=mb,kd=hb,Zb=wb,Qb=(e,t,n)=>{const r=new Map,o={platform:Wb,...n},s={...o.platform,_c:r};return fb(e,t,{...o,platform:s})};var ey=typeof document<"u",ty=function(){},ds=ey?S.useLayoutEffect:ty;function fs(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(!fs(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)&&!fs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Ed(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Id(e,t){const n=Ed(e);return Math.round(t*n)/n}function aa(e){const t=m.useRef(e);return ds(()=>{t.current=e}),t}function ny(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);fs(h,r)||p(r);const[w,v]=m.useState(null),[g,x]=m.useState(null),b=m.useCallback(F=>{F!==T.current&&(T.current=F,v(F))},[]),y=m.useCallback(F=>{F!==I.current&&(I.current=F,x(F))},[]),E=s||w,C=i||g,T=m.useRef(null),I=m.useRef(null),A=m.useRef(d),R=l!=null,j=aa(l),M=aa(o),D=aa(u),L=m.useCallback(()=>{if(!T.current||!I.current)return;const F={placement:t,strategy:n,middleware:h};M.current&&(F.platform=M.current),Qb(T.current,I.current,F).then(N=>{const U={...N,isPositioned:D.current!==!1};P.current&&!fs(A.current,U)&&(A.current=U,no.flushSync(()=>{f(U)}))})},[h,t,n,M,D]);ds(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(F=>({...F,isPositioned:!1})))},[u]);const P=m.useRef(!1);ds(()=>(P.current=!0,()=>{P.current=!1}),[]),ds(()=>{if(E&&(T.current=E),C&&(I.current=C),E&&C){if(j.current)return j.current(E,C,L);L()}},[E,C,L,j,R]);const W=m.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:y}),[b,y]),H=m.useMemo(()=>({reference:E,floating:C}),[E,C]),q=m.useMemo(()=>{const F={position:n,left:0,top:0};if(!H.floating)return F;const N=Id(H.floating,d.x),U=Id(H.floating,d.y);return a?{...F,transform:"translate("+N+"px, "+U+"px)",...Ed(H.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:N,top:U}},[n,a,H.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:L,refs:W,elements:H,floatingStyles:q}),[d,L,W,H,q])}const ry=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?kd({element:r.current,padding:o}).fn(n):{}:r?kd({element:r,padding:o}).fn(n):{}}}},oy=(e,t)=>({...qb(e),options:[e,t]}),sy=(e,t)=>({...Gb(e),options:[e,t]}),iy=(e,t)=>({...Zb(e),options:[e,t]}),ay=(e,t)=>({...Yb(e),options:[e,t]}),ly=(e,t)=>({...Xb(e),options:[e,t]}),cy=(e,t)=>({...Jb(e),options:[e,t]}),uy=(e,t)=>({...ry(e),options:[e,t]});var dy="Arrow",Nd=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Se.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});Nd.displayName=dy;var fy=Nd;function Ad(e){const[t,n]=m.useState(void 0);return pt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;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 la="Popper",[jd,hs]=nn(la),[hy,_d]=jd(la),Rd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(hy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Rd.displayName=la;var Pd="PopperAnchor",Od=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=_d(Pd,n),i=m.useRef(null),a=Oe(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(Se.div,{...o,ref:a})});Od.displayName=Pd;var ca="PopperContent",[py,my]=jd(ca),Md=m.forwardRef((e,t)=>{var z,O,K,J,ae,re;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:w,...v}=e,g=_d(ca,n),[x,b]=m.useState(null),y=Oe(t,Fe=>b(Fe)),[E,C]=m.useState(null),T=Ad(E),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,R=r+(s!=="center"?"-"+s:""),j=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},M=Array.isArray(u)?u:[u],D=M.length>0,L={padding:j,boundary:M.filter(xy),altBoundary:D},{refs:P,floatingStyles:W,placement:H,isPositioned:q,middlewareData:F}=ny({strategy:"fixed",placement:R,whileElementsMounted:(...Fe)=>Kb(...Fe,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[oy({mainAxis:o+A,alignmentAxis:i}),l&&sy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?iy():void 0,...L}),l&&ay({...L}),ly({...L,apply:({elements:Fe,rects:Xe,availableWidth:et,availableHeight:ye})=>{const{width:Pe,height:Je}=Xe.reference,$e=Fe.floating.style;$e.setProperty("--radix-popper-available-width",`${et}px`),$e.setProperty("--radix-popper-available-height",`${ye}px`),$e.setProperty("--radix-popper-anchor-width",`${Pe}px`),$e.setProperty("--radix-popper-anchor-height",`${Je}px`)}}),E&&uy({element:E,padding:a}),vy({arrowWidth:I,arrowHeight:A}),h&&cy({strategy:"referenceHidden",...L})]}),[N,U]=Fd(H),Y=mt(w);pt(()=>{q&&(Y==null||Y())},[q,Y]);const fe=(z=F.arrow)==null?void 0:z.x,ie=(O=F.arrow)==null?void 0:O.y,he=((K=F.arrow)==null?void 0:K.centerOffset)!==0,[Ee,de]=m.useState();return pt(()=>{x&&de(window.getComputedStyle(x).zIndex)},[x]),c.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...W,transform:q?W.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ee,"--radix-popper-transform-origin":[(J=F.transformOrigin)==null?void 0:J.x,(ae=F.transformOrigin)==null?void 0:ae.y].join(" "),...((re=F.hide)==null?void 0:re.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(py,{scope:n,placedSide:N,onArrowChange:C,arrowX:fe,arrowY:ie,shouldHideArrow:he,children:c.jsx(Se.div,{"data-side":N,"data-align":U,...v,ref:y,style:{...v.style,animation:q?void 0:"none"}})})})});Md.displayName=ca;var Dd="PopperArrow",gy={top:"bottom",right:"left",bottom:"top",left:"right"},Ld=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=my(Dd,r),i=gy[s.placedSide];return c.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:c.jsx(fy,{...o,ref:n,style:{...o.style,display:"block"}})})});Ld.displayName=Dd;function xy(e){return e!==null}var vy=e=>({name:"transformOrigin",options:e,fn(t){var g,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Fd(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let w="",v="";return u==="bottom"?(w=i?f:`${h}px`,v=`${-l}px`):u==="top"?(w=i?f:`${h}px`,v=`${r.floating.height+l}px`):u==="right"?(w=`${-l}px`,v=i?f:`${p}px`):u==="left"&&(w=`${r.floating.width+l}px`,v=i?f:`${p}px`),{data:{x:w,y:v}}}});function Fd(e){const[t,n="center"]=e.split("-");return[t,n]}var $d=Rd,zd=Od,Bd=Md,Hd=Ld,ua="rovingFocusGroup.onEntryFocus",wy={bubbles:!1,cancelable:!0},Kr="RovingFocusGroup",[da,Ud,by]=Yi(Kr),[yy,Wd]=nn(Kr,[by]),[Sy,Cy]=yy(Kr),Vd=m.forwardRef((e,t)=>c.jsx(da.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(da.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ty,{...e,ref:t})})}));Vd.displayName=Kr;var Ty=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=Oe(t,h),w=rs(s),[v,g]=Bn({prop:i,defaultProp:a??null,onChange:l,caller:Kr}),[x,b]=m.useState(!1),y=mt(u),E=Ud(n),C=m.useRef(!1),[T,I]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(ua,y),()=>A.removeEventListener(ua,y)},[y]),c.jsx(Sy,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:v,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>I(A=>A-1),[]),children:c.jsx(Se.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:se(e.onMouseDown,()=>{C.current=!0}),onFocus:se(e.onFocus,A=>{const R=!C.current;if(A.target===A.currentTarget&&R&&!x){const j=new CustomEvent(ua,wy);if(A.currentTarget.dispatchEvent(j),!j.defaultPrevented){const M=E().filter(H=>H.focusable),D=M.find(H=>H.active),L=M.find(H=>H.id===v),W=[D,L,...M].filter(Boolean).map(H=>H.ref.current);Gd(W,d)}}C.current=!1}),onBlur:se(e.onBlur,()=>b(!1))})})}),Kd="RovingFocusGroupItem",qd=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=rn(),u=s||l,d=Cy(Kd,n),f=d.currentTabStopId===u,h=Ud(n),{onFocusableItemAdd:p,onFocusableItemRemove:w,currentTabStopId:v}=d;return m.useEffect(()=>{if(r)return p(),()=>w()},[r,p,w]),c.jsx(da.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Se.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:se(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:se(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:se(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const x=Iy(g,d.orientation,d.dir);if(x!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let y=h().filter(E=>E.focusable).map(E=>E.ref.current);if(x==="last")y.reverse();else if(x==="prev"||x==="next"){x==="prev"&&y.reverse();const E=y.indexOf(g.currentTarget);y=d.loop?Ny(y,E+1):y.slice(E+1)}setTimeout(()=>Gd(y))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:v!=null}):i})})});qd.displayName=Kd;var ky={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ey(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Iy(e,t,n){const r=Ey(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ky[r]}function Gd(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ny(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ay=Vd,jy=qd,fa=["Enter"," "],_y=["ArrowDown","PageUp","Home"],Yd=["ArrowUp","PageDown","End"],Ry=[..._y,...Yd],Py={ltr:[...fa,"ArrowRight"],rtl:[...fa,"ArrowLeft"]},Oy={ltr:["ArrowLeft"],rtl:["ArrowRight"]},qr="Menu",[Gr,My,Dy]=Yi(qr),[qn,Xd]=nn(qr,[Dy,hs,Wd]),ps=hs(),Jd=Wd(),[Ly,Gn]=qn(qr),[Fy,Yr]=qn(qr),Zd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ps(t),[l,u]=m.useState(null),d=m.useRef(!1),f=mt(s),h=rs(o);return m.useEffect(()=>{const p=()=>{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",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),c.jsx($d,{...a,children:c.jsx(Ly,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(Fy,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};Zd.displayName=qr;var $y="MenuAnchor",ha=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ps(n);return c.jsx(zd,{...o,...r,ref:t})});ha.displayName=$y;var pa="MenuPortal",[zy,Qd]=qn(pa,{forceMount:void 0}),ef=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Gn(pa,t);return c.jsx(zy,{scope:t,forceMount:n,children:c.jsx(Pt,{present:n||s.open,children:c.jsx(Bo,{asChild:!0,container:o,children:r})})})};ef.displayName=pa;var zt="MenuContent",[By,ma]=qn(zt),tf=m.forwardRef((e,t)=>{const n=Qd(zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Gn(zt,e.__scopeMenu),i=Yr(zt,e.__scopeMenu);return c.jsx(Gr.Provider,{scope:e.__scopeMenu,children:c.jsx(Pt,{present:r||s.open,children:c.jsx(Gr.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(Hy,{...o,ref:t}):c.jsx(Uy,{...o,ref:t})})})})}),Hy=m.forwardRef((e,t)=>{const n=Gn(zt,e.__scopeMenu),r=m.useRef(null),o=Oe(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Ui(s)},[]),c.jsx(ga,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Uy=m.forwardRef((e,t)=>{const n=Gn(zt,e.__scopeMenu);return c.jsx(ga,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Wy=Pn.createSlot("MenuContent.ScrollLock"),ga=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:w,...v}=e,g=Gn(zt,n),x=Yr(zt,n),b=ps(n),y=Jd(n),E=My(n),[C,T]=m.useState(null),I=m.useRef(null),A=Oe(t,I,g.onContentChange),R=m.useRef(0),j=m.useRef(""),M=m.useRef(0),D=m.useRef(null),L=m.useRef("right"),P=m.useRef(0),W=w?qo:m.Fragment,H=w?{as:Wy,allowPinchZoom:!0}:void 0,q=N=>{var z,O;const U=j.current+N,Y=E().filter(K=>!K.disabled),fe=document.activeElement,ie=(z=Y.find(K=>K.ref.current===fe))==null?void 0:z.textValue,he=Y.map(K=>K.textValue),Ee=n0(he,U,ie),de=(O=Y.find(K=>K.textValue===Ee))==null?void 0:O.ref.current;(function K(J){j.current=J,window.clearTimeout(R.current),J!==""&&(R.current=window.setTimeout(()=>K(""),1e3))})(U),de&&setTimeout(()=>de.focus())};m.useEffect(()=>()=>window.clearTimeout(R.current),[]),Li();const F=m.useCallback(N=>{var Y,fe;return L.current===((Y=D.current)==null?void 0:Y.side)&&o0(N,(fe=D.current)==null?void 0:fe.area)},[]);return c.jsx(By,{scope:n,searchRef:j,onItemEnter:m.useCallback(N=>{F(N)&&N.preventDefault()},[F]),onItemLeave:m.useCallback(N=>{var U;F(N)||((U=I.current)==null||U.focus(),T(null))},[F]),onTriggerLeave:m.useCallback(N=>{F(N)&&N.preventDefault()},[F]),pointerGraceTimerRef:M,onPointerGraceIntentChange:m.useCallback(N=>{D.current=N},[]),children:c.jsx(W,{...H,children:c.jsx(zo,{asChild:!0,trapped:o,onMountAutoFocus:se(s,N=>{var U;N.preventDefault(),(U=I.current)==null||U.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx($o,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(Ay,{asChild:!0,...y,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:se(l,N=>{x.isUsingKeyboardRef.current||N.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(Bd,{role:"menu","aria-orientation":"vertical","data-state":wf(g.open),"data-radix-menu-content":"",dir:x.dir,...b,...v,ref:A,style:{outline:"none",...v.style},onKeyDown:se(v.onKeyDown,N=>{const Y=N.target.closest("[data-radix-menu-content]")===N.currentTarget,fe=N.ctrlKey||N.altKey||N.metaKey,ie=N.key.length===1;Y&&(N.key==="Tab"&&N.preventDefault(),!fe&&ie&&q(N.key));const he=I.current;if(N.target!==he||!Ry.includes(N.key))return;N.preventDefault();const de=E().filter(z=>!z.disabled).map(z=>z.ref.current);Yd.includes(N.key)&&de.reverse(),e0(de)}),onBlur:se(e.onBlur,N=>{N.currentTarget.contains(N.target)||(window.clearTimeout(R.current),j.current="")}),onPointerMove:se(e.onPointerMove,Jr(N=>{const U=N.target,Y=P.current!==N.clientX;if(N.currentTarget.contains(U)&&Y){const fe=N.clientX>P.current?"right":"left";L.current=fe,P.current=N.clientX}}))})})})})})})});tf.displayName=zt;var Vy="MenuGroup",xa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{role:"group",...r,ref:t})});xa.displayName=Vy;var Ky="MenuLabel",nf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{...r,ref:t})});nf.displayName=Ky;var ms="MenuItem",rf="menu.itemSelect",gs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=Yr(ms,e.__scopeMenu),a=ma(ms,e.__scopeMenu),l=Oe(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(rf,{bubbles:!0,cancelable:!0});f.addEventListener(rf,p=>r==null?void 0:r(p),{once:!0}),$c(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(of,{...o,ref:l,disabled:n,onClick:se(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:se(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:se(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||fa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});gs.displayName=ms;var of=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ma(ms,n),a=Jd(n),l=m.useRef(null),u=Oe(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const w=l.current;w&&p((w.textContent??"").trim())},[s.children]),c.jsx(Gr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(jy,{asChild:!0,...a,focusable:!r,children:c.jsx(Se.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:se(e.onPointerMove,Jr(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:se(e.onPointerLeave,Jr(w=>i.onItemLeave(w))),onFocus:se(e.onFocus,()=>f(!0)),onBlur:se(e.onBlur,()=>f(!1))})})})}),qy="MenuCheckboxItem",sf=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(df,{scope:e.__scopeMenu,checked:n,children:c.jsx(gs,{role:"menuitemcheckbox","aria-checked":xs(n)?"mixed":n,...o,ref:t,"data-state":wa(n),onSelect:se(o.onSelect,()=>r==null?void 0:r(xs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});sf.displayName=qy;var af="MenuRadioGroup",[Gy,Yy]=qn(af,{value:void 0,onValueChange:()=>{}}),lf=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=mt(r);return c.jsx(Gy,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(xa,{...o,ref:t})})});lf.displayName=af;var cf="MenuRadioItem",uf=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=Yy(cf,e.__scopeMenu),s=n===o.value;return c.jsx(df,{scope:e.__scopeMenu,checked:s,children:c.jsx(gs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":wa(s),onSelect:se(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});uf.displayName=cf;var va="MenuItemIndicator",[df,Xy]=qn(va,{checked:!1}),ff=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Xy(va,n);return c.jsx(Pt,{present:r||xs(s.checked)||s.checked===!0,children:c.jsx(Se.span,{...o,ref:t,"data-state":wa(s.checked)})})});ff.displayName=va;var Jy="MenuSeparator",hf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});hf.displayName=Jy;var Zy="MenuArrow",pf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ps(n);return c.jsx(Hd,{...o,...r,ref:t})});pf.displayName=Zy;var Qy="MenuSub",[LC,mf]=qn(Qy),Xr="MenuSubTrigger",gf=m.forwardRef((e,t)=>{const n=Gn(Xr,e.__scopeMenu),r=Yr(Xr,e.__scopeMenu),o=mf(Xr,e.__scopeMenu),s=ma(Xr,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(ha,{asChild:!0,...u,children:c.jsx(of,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":wf(n.open),...e,ref:Ci(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:se(e.onPointerMove,Jr(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:se(e.onPointerLeave,Jr(f=>{var p,w;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const v=(w=n.content)==null?void 0:w.dataset.side,g=v==="right",x=g?-5:5,b=h[g?"left":"right"],y=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:y,y:h.top},{x:y,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:se(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||Py[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});gf.displayName=Xr;var xf="MenuSubContent",vf=m.forwardRef((e,t)=>{const n=Qd(zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Gn(zt,e.__scopeMenu),i=Yr(zt,e.__scopeMenu),a=mf(xf,e.__scopeMenu),l=m.useRef(null),u=Oe(t,l);return c.jsx(Gr.Provider,{scope:e.__scopeMenu,children:c.jsx(Pt,{present:r||s.open,children:c.jsx(Gr.Slot,{scope:e.__scopeMenu,children:c.jsx(ga,{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=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:se(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:se(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:se(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=Oy[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});vf.displayName=xf;function wf(e){return e?"open":"closed"}function xs(e){return e==="indeterminate"}function wa(e){return xs(e)?"indeterminate":e?"checked":"unchecked"}function e0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function t0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function n0(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=t0(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function r0(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function o0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return r0(n,t)}function Jr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var s0=Zd,i0=ha,a0=ef,l0=tf,c0=xa,u0=nf,d0=gs,f0=sf,h0=lf,p0=uf,m0=ff,g0=hf,x0=pf,v0=gf,w0=vf,vs="DropdownMenu",[b0,FC]=nn(vs,[Xd]),yt=Xd(),[y0,bf]=b0(vs),yf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=yt(t),u=m.useRef(null),[d,f]=Bn({prop:o,defaultProp:s??!1,onChange:i,caller:vs});return c.jsx(y0,{scope:t,triggerId:rn(),triggerRef:u,contentId:rn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(s0,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};yf.displayName=vs;var Sf="DropdownMenuTrigger",Cf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=bf(Sf,n),i=yt(n);return c.jsx(i0,{asChild:!0,...i,children:c.jsx(Se.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:Ci(t,s.triggerRef),onPointerDown:se(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:se(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Cf.displayName=Sf;var S0="DropdownMenuPortal",Tf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=yt(t);return c.jsx(a0,{...r,...n})};Tf.displayName=S0;var kf="DropdownMenuContent",Ef=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bf(kf,n),s=yt(n),i=m.useRef(!1);return c.jsx(l0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:se(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:se(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.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)"}})});Ef.displayName=kf;var C0="DropdownMenuGroup",T0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(c0,{...o,...r,ref:t})});T0.displayName=C0;var k0="DropdownMenuLabel",If=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(u0,{...o,...r,ref:t})});If.displayName=k0;var E0="DropdownMenuItem",Nf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(d0,{...o,...r,ref:t})});Nf.displayName=E0;var I0="DropdownMenuCheckboxItem",Af=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(f0,{...o,...r,ref:t})});Af.displayName=I0;var N0="DropdownMenuRadioGroup",A0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(h0,{...o,...r,ref:t})});A0.displayName=N0;var j0="DropdownMenuRadioItem",jf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(p0,{...o,...r,ref:t})});jf.displayName=j0;var _0="DropdownMenuItemIndicator",_f=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(m0,{...o,...r,ref:t})});_f.displayName=_0;var R0="DropdownMenuSeparator",Rf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(g0,{...o,...r,ref:t})});Rf.displayName=R0;var P0="DropdownMenuArrow",O0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(x0,{...o,...r,ref:t})});O0.displayName=P0;var M0="DropdownMenuSubTrigger",Pf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(v0,{...o,...r,ref:t})});Pf.displayName=M0;var D0="DropdownMenuSubContent",Of=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=yt(n);return c.jsx(w0,{...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)"}})});Of.displayName=D0;var L0=yf,F0=Cf,$0=Tf,Mf=Ef,Df=If,Lf=Nf,Ff=Af,$f=jf,zf=_f,Bf=Rf,Hf=Pf,Uf=Of;const z0=L0,B0=F0,H0=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Hf,{ref:o,className:X("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,c.jsx(Q.ChevronRight,{className:"ml-auto h-4 w-4"})]}));H0.displayName=Hf.displayName;const U0=m.forwardRef(({className:e,...t},n)=>c.jsx(Uf,{ref:n,className:X("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}));U0.displayName=Uf.displayName;const Wf=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx($0,{children:c.jsx(Mf,{ref:r,sideOffset:t,className:X("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})}));Wf.displayName=Mf.displayName;const ba=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Lf,{ref:r,className:X("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}));ba.displayName=Lf.displayName;const W0=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Ff,{ref:o,className:X("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(zf,{children:c.jsx(Q.Check,{className:"h-4 w-4"})})}),t]}));W0.displayName=Ff.displayName;const V0=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs($f,{ref:r,className:X("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(zf,{children:c.jsx(Q.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));V0.displayName=$f.displayName;const K0=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Df,{ref:r,className:X("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));K0.displayName=Df.displayName;const q0=m.forwardRef(({className:e,...t},n)=>c.jsx(Bf,{ref:n,className:X("-mx-1 my-1 h-px bg-muted",e),...t}));q0.displayName=Bf.displayName;function ws({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:w}=Gs(),{currentThreadId:v,isLoadingThread:g,listCheckpoints:x,navigateToCheckpoint:b,returnToLatest:y}=mo(),{messages:E,hasMoreHistory:C,isLoadingHistory:T,send:I,stop:A,loadOlderMessages:R}=Zs(),{isStreaming:j,error:M,streamingAssistantId:D,lastCheckpointId:L,lastCheckpointNs:P}=Fl(),[W,H]=S.useState(null),[q,F]=S.useState(""),[N,U]=S.useState(null),[Y,fe]=S.useState([]),[ie,he]=S.useState(0),[Ee,de]=S.useState(0),[z,O]=S.useState(!1),[K,J]=S.useState(null),[ae,re]=S.useState(null),[Fe,Xe]=S.useState(!1),[et,ye]=S.useState(null),[Pe,Je]=S.useState([]),[$e,st]=S.useState(null),[lt,Z]=S.useState(null),[le,ge]=S.useState(!1),Ce=S.useRef(null),we=S.useRef(null),je=S.useRef(null),Ze=S.useCallback(()=>{Ce.current&&(Ce.current.value=""),we.current&&(we.current.value=""),he(oe=>oe+1),de(oe=>oe+1)},[]),Ue=S.useRef(!1);S.useEffect(()=>{Ue.current&&!j&&(fe([]),Ze()),Ue.current=j},[j,Ze]);const[ct,Et]=S.useState("desktop");S.useEffect(()=>{const oe=()=>{const xe=window.innerWidth;Et(xe<640?"phone":xe<1024?"tablet":"desktop")};return oe(),window.addEventListener("resize",oe),()=>window.removeEventListener("resize",oe)},[]),S.useEffect(()=>{let oe=!1;if(!v){Je([]),st(null),Z(null),je.current=null;return}const xe={threadId:v,checkpointId:L??null,checkpointNs:P??null},Le=je.current;if(!(Le&&Le.threadId===xe.threadId&&Le.checkpointId===xe.checkpointId&&Le.checkpointNs===xe.checkpointNs))return x(v).then(ot=>{var _s;if(oe)return;const Dt=((ot==null?void 0:ot.checkpoints)??[]).slice().sort((xn,k)=>new Date(k.createdAt).getTime()-new Date(xn.createdAt).getTime());Je(Dt);const dn=$e,eo=dn&&Dt.some(xn=>xn.checkpointId===dn)?dn:((_s=Dt[0])==null?void 0:_s.checkpointId)??null;let js=null;if(eo){const xn=Dt.find(k=>k.checkpointId===eo);js=(xn==null?void 0:xn.checkpointNs)??null}st(eo),Z(js),je.current=xe}).catch(ot=>{console.error("ChatInterface - listCheckpoints error:",ot),oe||(Je([]),je.current=null)}),()=>{oe=!0}},[v,L,P,$e,x]),S.useEffect(()=>{L&&(st(L),Z(P??null))},[L,P]);const _n=S.useCallback(async()=>{if(!(!C||T))try{await R()}catch(oe){console.warn("loadOlderMessages failed",oe)}},[C,T,R]);S.useEffect(()=>{(async()=>{if(!w.baseUrl){ye(null);return}try{const xe=await w.getAgent("default");ye(xe.uiDefaultMessage||null)}catch(xe){console.warn("Failed to fetch default message:",xe),ye(null)}})()},[w]),S.useEffect(()=>{M&&!Fe&&(p==null||p(M))},[M,Fe,p]);const G=oe=>{if(oe.length>ns)return`Message too long (${oe.length}/${ns} characters)`;try{return Qw(oe),null}catch(xe){return(xe==null?void 0:xe.message)||"Invalid message"}},ce=async oe=>{const xe=oe.trim();if(!(!xe&&Y.length===0)){if(xe){const Le=G(xe);if(Le){U(Le);return}}try{await I(xe||"",{checkpointId:$e??L??void 0,checkpointNs:lt??P??void 0,payloadExtras:W?{edit:!0,originalMessageId:W}:void 0,attachments:Y}),f==null||f(xe),U(null),fe([]),Ze(),H(null),F("")}catch(Le){const ot=(Le==null?void 0:Le.message)||"Failed to send message";U(ot),p==null||p(ot)}}},Ie=S.useCallback((oe,xe)=>{u&&(H(oe),F(xe),U(null))},[u]),Ve=S.useCallback(()=>{H(null),F(""),U(null)},[]),qe=S.useCallback((oe,xe)=>{Ie(oe,xe)},[Ie]),It=S.useCallback(oe=>{const xe=Le=>{const ot=Le.content||[],Dt=ot.filter(dn=>dn.type==="text").map(dn=>dn.text).join("");if(Dt)return Dt;try{return JSON.stringify(ot,null,2)}catch{return String(ot)}};for(let Le=oe-1;Le>=0;Le--)if(E[Le].role==="user"){const ot=xe(E[Le]);ot&&I(ot,{checkpointId:$e??L??void 0,checkpointNs:lt??P??void 0});break}},[E,I,$e,lt,L,P]),Rn=oe=>{const xe=Array.from(oe.target.files||[]);fe(Le=>[...Le,...xe]),oe.target.value=""},Jt=oe=>{fe(xe=>{const Le=xe.filter((ot,Dt)=>oe!==Dt);return Le.length===0&&Ze(),Le})},Zn=async oe=>{const xe=(oe.target.files||[])[0];if(xe){J(null),re(null),O(!0);try{await I("",{checkpointId:$e??L??void 0,checkpointNs:lt??P??void 0,attachments:[xe]});const Le=`Uploaded ${xe.name} - processing through chat stream`;re(Le)}catch(Le){const ot=Le instanceof Error?Le.message:"Failed to upload Excel file";console.error("Excel upload failed",Le),J(ot),p==null||p(ot)}finally{O(!1),oe.target.value="",Ze()}}},Qn=oe=>{if(!oe)return"Unknown";const xe=Date.parse(oe);return Number.isNaN(xe)?oe:new Date(xe).toLocaleString()},wr=async oe=>{if(v){ge(!0);try{if(!oe){await y(),st(null),Z(null);return}const xe=Pe.find(ot=>ot.checkpointId===oe),Le=(xe==null?void 0:xe.checkpointNs)??null;await b(oe,Le),st(oe),Z(Le)}finally{ge(!1)}}},Qr=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,er=`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||""}`,gn=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Qr,children:[!!M&&!Fe&&c.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:[c.jsx("span",{children:M}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>Xe(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(Q.X,{size:16})})]}),v&&Pe.length>0&&c.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:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.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:$e??"",onChange:oe=>{const xe=oe.target.value||null;wr(xe)},children:[c.jsx("option",{value:"",children:"Latest"}),Pe.map(oe=>c.jsxs("option",{value:oe.checkpointId,children:[Qn(oe.createdAt),oe.preview?` — ${oe.preview.slice(0,40)}`:""]},oe.checkpointId))]})]}),c.jsxs("div",{className:`relative ${er}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Gi,{className:"h-full",style:{height:"100%"},messages:E,isStreaming:j,streamingAssistantId:D,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ct,enableMessageEditing:u,editingMessageId:W,onStartReached:()=>{_n()},onEdit:qe,onRegenerate:It,onCancelEdit:Ve,emptyMessage:et??void 0,isNavigatingCheckpoint:le}),g&&c.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:[c.jsx(Q.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:gn,children:[W&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Q.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:Ve,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(Q.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:Ce,type:"file",multiple:!0,onChange:oe=>Rn(oe),className:"hidden"},ie),Y.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:Y.map((oe,xe)=>c.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:[c.jsx(Q.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:oe.name}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>Jt(xe),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 ${oe.name}`,children:c.jsx(Q.X,{size:12})})]},xe))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:we,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Zn,className:"hidden"},Ee),z&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(Q.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),ae&&!z&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:ae}),K&&!z&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:K})]})]}),N&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:N}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(z0,{children:[c.jsx(B0,{asChild:!0,children:c.jsx(Be,{type:"button",size:"icon",variant:"outline",disabled:j,title:"More input actions",className:d.moreButton||"",children:c.jsx(Q.Plus,{size:16})})}),c.jsxs(Wf,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(ba,{onClick:()=>{var oe;return(oe=Ce.current)==null?void 0:oe.click()},className:"cursor-pointer",children:[c.jsx(Q.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(ba,{onClick:()=>{var oe;z||(oe=we.current)==null||oe.click()},className:`cursor-pointer ${z?"opacity-60 pointer-events-none":""}`,children:[c.jsx(Q.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(fg,{initialValue:q,editingMessageId:W,placeholder:W?"Edit your message...":t,isStreaming:j,disabled:!1,maxLength:ns,onSend:ce,onCancelEdit:Ve,onStop:A,allowEmptySend:Y.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":""} ${N?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const bs=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:X("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}));bs.displayName="Input";function ya(e,[t,n]){return Math.min(n,Math.max(t,e))}function G0(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Sa="ScrollArea",[Vf,$C]=nn(Sa),[Y0,Bt]=Vf(Sa),Kf=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,w]=m.useState(null),[v,g]=m.useState(null),[x,b]=m.useState(0),[y,E]=m.useState(0),[C,T]=m.useState(!1),[I,A]=m.useState(!1),R=Oe(t,M=>l(M)),j=rs(o);return c.jsx(Y0,{scope:n,type:r,dir:j,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:w,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:v,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:E,children:c.jsx(Se.div,{dir:j,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":y+"px",...e.style}})})});Kf.displayName=Sa;var qf="ScrollAreaViewport",Gf=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Bt(qf,n),a=m.useRef(null),l=Oe(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.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}),c.jsx(Se.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Gf.displayName=qf;var un="ScrollAreaScrollbar",Ca=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(un,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(X0,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(J0,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Yf,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(Ta,{...r,ref:t}):null});Ca.displayName=un;var X0=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(un,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Pt,{present:n||s,children:c.jsx(Yf,{"data-state":s?"visible":"hidden",...r,ref:t})})}),J0=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(un,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ts(()=>l("SCROLL_END"),100),[a,l]=G0("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 m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Pt,{present:n||a!=="hidden",children:c.jsx(Ta,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:se(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:se(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Yf=m.forwardRef((e,t)=>{const n=Bt(un,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=Ts(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return gr(n.viewport,l),gr(n.content,l),c.jsx(Pt,{present:r||s,children:c.jsx(Ta,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ta=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Bt(un,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=eh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return rS(h,i.current,a,p)}return n==="horizontal"?c.jsx(Z0,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=th(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?c.jsx(Q0,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=th(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),Z0=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Bt(un,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Oe(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Jf,{"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":Cs(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),rh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ss(i.paddingLeft),paddingEnd:Ss(i.paddingRight)}})}})}),Q0=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Bt(un,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Oe(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(Jf,{"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":Cs(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),rh(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ss(i.paddingTop),paddingEnd:Ss(i.paddingBottom)}})}})}),[eS,Xf]=Vf(un),Jf=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=Bt(un,n),[w,v]=m.useState(null),g=Oe(t,R=>v(R)),x=m.useRef(null),b=m.useRef(""),y=p.viewport,E=r.content-r.viewport,C=mt(d),T=mt(l),I=Ts(f,10);function A(R){if(x.current){const j=R.clientX-x.current.left,M=R.clientY-x.current.top;u({x:j,y:M})}}return m.useEffect(()=>{const R=j=>{const M=j.target;(w==null?void 0:w.contains(M))&&C(j,E)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[y,w,E,C]),m.useEffect(T,[r,T]),gr(w,I),gr(p.content,I),c.jsx(eS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:mt(s),onThumbPointerUp:mt(i),onThumbPositionChange:T,onThumbPointerDown:mt(a),children:c.jsx(Se.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:se(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),x.current=w.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:se(e.onPointerMove,A),onPointerUp:se(e.onPointerUp,R=>{const j=R.target;j.hasPointerCapture(R.pointerId)&&j.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),ys="ScrollAreaThumb",Zf=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Xf(ys,e.__scopeScrollArea);return c.jsx(Pt,{present:n||o.hasThumb,children:c.jsx(tS,{ref:t,...r})})}),tS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Bt(ys,n),i=Xf(ys,n),{onThumbPositionChange:a}=i,l=Oe(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=Ts(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=oS(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(Se.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:se(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),w=f.clientX-p.left,v=f.clientY-p.top;i.onThumbPointerDown({x:w,y:v})}),onPointerUp:se(e.onPointerUp,i.onThumbPointerUp)})});Zf.displayName=ys;var ka="ScrollAreaCorner",Qf=m.forwardRef((e,t)=>{const n=Bt(ka,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(nS,{...e,ref:t}):null});Qf.displayName=ka;var nS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Bt(ka,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return gr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),gr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(Se.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 Ss(e){return e?parseInt(e,10):0}function eh(e,t){const n=e/t;return isNaN(n)?0:n}function Cs(e){const t=eh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function rS(e,t,n,r="ltr"){const o=Cs(n),s=o/2,i=t||s,a=o-i,l=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 nh([l,u],f)(e)}function th(e,t,n="ltr"){const r=Cs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=ya(e,l);return nh([0,i],[0,a])(u)}function nh(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 rh(e,t){return e>0&&e<t}var oS=(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 Ts(e,t){const n=mt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function gr(e,t){const n=mt(t);pt(()=>{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 oh=Kf,sS=Gf,iS=Qf;const sh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(oh,{ref:r,className:X("relative overflow-hidden",e),...n,children:[c.jsx(sS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(ih,{}),c.jsx(iS,{})]}));sh.displayName=oh.displayName;const ih=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(Ca,{ref:r,orientation:t,className:X("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:c.jsx(Zf,{className:"relative flex-1 rounded-full bg-border"})}));ih.displayName=Ca.displayName;function Ea({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{loadThread:f,threads:h,currentThreadId:p,createThread:w,deleteThread:v,renameThread:g,isLoadingThreads:x}=mo(),[b,y]=S.useState(h??[]),[E,C]=S.useState(null),[T,I]=S.useState(""),[A,R]=S.useState(!1);S.useEffect(()=>{y(h??[])},[h]);const j=async N=>{try{await f(N),a==null||a(N),l==null||l(N)}catch(U){console.error("Failed to select thread:",U)}},M=async()=>{try{R(!0);const N=await w();u==null||u(N),a==null||a(N)}catch(N){console.error("Failed to create thread:",N)}finally{R(!1)}},D=async(N,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?"))try{await v(N),d==null||d(N)}catch(Y){console.error("Failed to delete thread:",Y)}},L=(N,U)=>{U.stopPropagation(),C(N.threadId),I(N.title||`Thread ${N.threadId.slice(0,8)}`)},P=async N=>{if(T.trim())try{await g(N,T.trim()),C(null),I("")}catch(U){console.error("Failed to update title:",U)}},W=()=>{C(null),I("")},H=(N,U)=>{N.key==="Enter"?P(U):N.key==="Escape"&&W()},q=N=>{if(!N)return"";try{const U=new Date(N),fe=new Date().getTime()-U.getTime(),ie=Math.floor(fe/(1e3*60*60*24));return ie===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):ie===1?"Yesterday":ie<7?`${ie} days ago`:U.toLocaleDateString()}catch{return""}},F=N=>N.title||`Thread ${N.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.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:c.jsx(Be,{onClick:M,disabled:A||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:A?"Creating...":"New Chat",children:c.jsx(Q.MessageSquarePlus,{size:20})})}),c.jsx(sh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(Q.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):b.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(Q.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):b.slice().sort((N,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(N.updatedAt||N.createdAt||"").getTime()).map(N=>c.jsxs("div",{onClick:()=>j(N.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===N.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:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:E===N.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[c.jsx(bs,{value:T,onChange:U=>I(U.target.value),onKeyDown:U=>H(U,N.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>P(N.threadId),className:"h-6 w-6 p-0",children:c.jsx(Q.Check,{size:12})}),c.jsx(Be,{variant:"ghost",size:"sm",onClick:W,className:"h-6 w-6 p-0",children:c.jsx(Q.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:F(N)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(Q.Calendar,{size:10}),c.jsx("span",{children:q(N.updatedAt||N.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&E!==N.threadId&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:U=>L(N,U),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(Q.Edit3,{size:12})}),n&&c.jsx(Be,{variant:"ghost",size:"sm",onClick:U=>D(N.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(Q.Trash2,{size:12})})]})]}),i===N.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},N.threadId))})})]})}function xr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function aS(e){if(typeof e!="string")return;const t=e.trim();if(t)return fn(t)}function ah(){const e=[xr("__API_BASE_URL__"),xr("__CHAT_API_BASE_URL__"),xr("__CHAT_API_URL__")];for(const t of e){const n=aS(t);if(n)return n}}function lh(){const e=[xr("__API_AUTH_TOKEN__"),xr("__CHAT_API_KEY__"),xr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function ch(...e){for(const t of e)if(typeof t=="string"&&t.trim())return fn(t);return fn()}function uh(){const e={},t=ah(),n=lh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function dh(){const e=uh(),t=vn.getAuthToken(),n=ah();return{apiBaseUrl:ch(e.baseUrl,vn.baseUrl,n),apiKey:t||e.apiKey||lh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const fh="chat-settings";function lS(){try{const e=localStorage.getItem(fh);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function cS(e){try{const t={...e,apiBaseUrl:fn(e.apiBaseUrl)};localStorage.setItem(fh,JSON.stringify(t)),t.apiKey&&vn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function uS(){const e=dh(),t=lS(),n=vn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:ch(vn.baseUrl,r,e.apiBaseUrl)}}function dS(e){vn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),cS(e)}var fS="Label",hh=m.forwardRef((e,t)=>c.jsx(Se.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())}}));hh.displayName=fS;var ph=hh;const hS=to.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ht=m.forwardRef(({className:e,...t},n)=>c.jsx(ph,{ref:n,className:X(hS(),e),...t}));Ht.displayName=ph.displayName;function mh(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var ks="Switch",[pS,zC]=nn(ks),[mS,gS]=pS(ks),gh=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),w=Oe(t,y=>p(y)),v=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[x,b]=Bn({prop:o,defaultProp:s??!1,onChange:u,caller:ks});return c.jsxs(mS,{scope:n,checked:x,disabled:a,children:[c.jsx(Se.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":bh(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:w,onClick:se(e.onClick,y=>{b(E=>!E),g&&(v.current=y.isPropagationStopped(),v.current||y.stopPropagation())})}),g&&c.jsx(wh,{control:h,bubbles:!v.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});gh.displayName=ks;var xh="SwitchThumb",vh=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=gS(xh,n);return c.jsx(Se.span,{"data-state":bh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});vh.displayName=xh;var xS="SwitchBubbleInput",wh=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Oe(i,s),l=mh(n),u=Ad(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const w=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(w)}},[l,n,r]),c.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}})});wh.displayName=xS;function bh(e){return e?"checked":"unchecked"}var yh=gh,vS=vh;const Nn=m.forwardRef(({className:e,...t},n)=>c.jsx(yh,{className:X("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:c.jsx(vS,{className:X("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")})}));Nn.displayName=yh.displayName;var Sh=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"}),wS="VisuallyHidden",bS=m.forwardRef((e,t)=>c.jsx(Se.span,{...e,ref:t,style:{...Sh,...e.style}}));bS.displayName=wS;var yS=[" ","Enter","ArrowUp","ArrowDown"],SS=[" ","Enter"],Yn="Select",[Es,Is,CS]=Yi(Yn),[vr,BC]=nn(Yn,[CS,hs]),Ns=hs(),[TS,An]=vr(Yn),[kS,ES]=vr(Yn),Ch=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:w}=e,v=Ns(t),[g,x]=m.useState(null),[b,y]=m.useState(null),[E,C]=m.useState(!1),T=rs(u),[I,A]=Bn({prop:r,defaultProp:o??!1,onChange:s,caller:Yn}),[R,j]=Bn({prop:i,defaultProp:a,onChange:l,caller:Yn}),M=m.useRef(null),D=g?w||!!g.closest("form"):!0,[L,P]=m.useState(new Set),W=Array.from(L).map(H=>H.props.value).join(";");return c.jsx($d,{...v,children:c.jsxs(TS,{required:p,scope:t,trigger:g,onTriggerChange:x,valueNode:b,onValueNodeChange:y,valueNodeHasChildren:E,onValueNodeHasChildrenChange:C,contentId:rn(),value:R,onValueChange:j,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:M,disabled:h,children:[c.jsx(Es.Provider,{scope:t,children:c.jsx(kS,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(H=>{P(q=>new Set(q).add(H))},[]),onNativeOptionRemove:m.useCallback(H=>{P(q=>{const F=new Set(q);return F.delete(H),F})},[]),children:n})}),D?c.jsxs(qh,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:H=>j(H.target.value),disabled:h,form:w,children:[R===void 0?c.jsx("option",{value:""}):null,Array.from(L)]},W):null]})})};Ch.displayName=Yn;var Th="SelectTrigger",kh=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ns(n),i=An(Th,n),a=i.disabled||r,l=Oe(t,i.onTriggerChange),u=Is(n),d=m.useRef("touch"),[f,h,p]=Yh(v=>{const g=u().filter(y=>!y.disabled),x=g.find(y=>y.value===i.value),b=Xh(g,v,x);b!==void 0&&i.onValueChange(b.value)}),w=v=>{a||(i.onOpenChange(!0),p()),v&&(i.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return c.jsx(zd,{asChild:!0,...s,children:c.jsx(Se.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":Gh(i.value)?"":void 0,...o,ref:l,onClick:se(o.onClick,v=>{v.currentTarget.focus(),d.current!=="mouse"&&w(v)}),onPointerDown:se(o.onPointerDown,v=>{d.current=v.pointerType;const g=v.target;g.hasPointerCapture(v.pointerId)&&g.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(w(v),v.preventDefault())}),onKeyDown:se(o.onKeyDown,v=>{const g=f.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&h(v.key),!(g&&v.key===" ")&&yS.includes(v.key)&&(w(),v.preventDefault())})})})});kh.displayName=Th;var Eh="SelectValue",Ih=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=An(Eh,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=Oe(t,l.onValueNodeChange);return pt(()=>{u(d)},[u,d]),c.jsx(Se.span,{...a,ref:f,style:{pointerEvents:"none"},children:Gh(l.value)?c.jsx(c.Fragment,{children:i}):s})});Ih.displayName=Eh;var IS="SelectIcon",Nh=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Se.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Nh.displayName=IS;var NS="SelectPortal",Ah=e=>c.jsx(Bo,{asChild:!0,...e});Ah.displayName=NS;var Xn="SelectContent",jh=m.forwardRef((e,t)=>{const n=An(Xn,e.__scopeSelect),[r,o]=m.useState();if(pt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?no.createPortal(c.jsx(_h,{scope:e.__scopeSelect,children:c.jsx(Es.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Rh,{...e,ref:t})});jh.displayName=Xn;var Xt=10,[_h,jn]=vr(Xn),AS="SelectContentImpl",jS=Pn.createSlot("SelectContent.RemoveScroll"),Rh=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:v,avoidCollisions:g,...x}=e,b=An(Xn,n),[y,E]=m.useState(null),[C,T]=m.useState(null),I=Oe(t,z=>E(z)),[A,R]=m.useState(null),[j,M]=m.useState(null),D=Is(n),[L,P]=m.useState(!1),W=m.useRef(!1);m.useEffect(()=>{if(y)return Ui(y)},[y]),Li();const H=m.useCallback(z=>{const[O,...K]=D().map(re=>re.ref.current),[J]=K.slice(-1),ae=document.activeElement;for(const re of z)if(re===ae||(re==null||re.scrollIntoView({block:"nearest"}),re===O&&C&&(C.scrollTop=0),re===J&&C&&(C.scrollTop=C.scrollHeight),re==null||re.focus(),document.activeElement!==ae))return},[D,C]),q=m.useCallback(()=>H([A,y]),[H,A,y]);m.useEffect(()=>{L&&q()},[L,q]);const{onOpenChange:F,triggerPointerDownPosRef:N}=b;m.useEffect(()=>{if(y){let z={x:0,y:0};const O=J=>{var ae,re;z={x:Math.abs(Math.round(J.pageX)-(((ae=N.current)==null?void 0:ae.x)??0)),y:Math.abs(Math.round(J.pageY)-(((re=N.current)==null?void 0:re.y)??0))}},K=J=>{z.x<=10&&z.y<=10?J.preventDefault():y.contains(J.target)||F(!1),document.removeEventListener("pointermove",O),N.current=null};return N.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",K,{capture:!0})}}},[y,F,N]),m.useEffect(()=>{const z=()=>F(!1);return window.addEventListener("blur",z),window.addEventListener("resize",z),()=>{window.removeEventListener("blur",z),window.removeEventListener("resize",z)}},[F]);const[U,Y]=Yh(z=>{const O=D().filter(ae=>!ae.disabled),K=O.find(ae=>ae.ref.current===document.activeElement),J=Xh(O,z,K);J&&setTimeout(()=>J.ref.current.focus())}),fe=m.useCallback((z,O,K)=>{const J=!W.current&&!K;(b.value!==void 0&&b.value===O||J)&&(R(z),J&&(W.current=!0))},[b.value]),ie=m.useCallback(()=>y==null?void 0:y.focus(),[y]),he=m.useCallback((z,O,K)=>{const J=!W.current&&!K;(b.value!==void 0&&b.value===O||J)&&M(z)},[b.value]),Ee=r==="popper"?Ia:Ph,de=Ee===Ia?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:v,avoidCollisions:g}:{};return c.jsx(_h,{scope:n,content:y,viewport:C,onViewportChange:T,itemRefCallback:fe,selectedItem:A,onItemLeave:ie,itemTextRefCallback:he,focusSelectedItem:q,selectedItemText:j,position:r,isPositioned:L,searchRef:U,children:c.jsx(qo,{as:jS,allowPinchZoom:!0,children:c.jsx(zo,{asChild:!0,trapped:b.open,onMountAutoFocus:z=>{z.preventDefault()},onUnmountAutoFocus:se(o,z=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),z.preventDefault()}),children:c.jsx($o,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:z=>z.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(Ee,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:z=>z.preventDefault(),...x,...de,onPlaced:()=>P(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:se(x.onKeyDown,z=>{const O=z.ctrlKey||z.altKey||z.metaKey;if(z.key==="Tab"&&z.preventDefault(),!O&&z.key.length===1&&Y(z.key),["ArrowUp","ArrowDown","Home","End"].includes(z.key)){let J=D().filter(ae=>!ae.disabled).map(ae=>ae.ref.current);if(["ArrowUp","End"].includes(z.key)&&(J=J.slice().reverse()),["ArrowUp","ArrowDown"].includes(z.key)){const ae=z.target,re=J.indexOf(ae);J=J.slice(re+1)}setTimeout(()=>H(J)),z.preventDefault()}})})})})})})});Rh.displayName=AS;var _S="SelectItemAlignedPosition",Ph=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=An(Xn,n),i=jn(Xn,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=Oe(t,I=>d(I)),h=Is(n),p=m.useRef(!1),w=m.useRef(!0),{viewport:v,selectedItem:g,selectedItemText:x,focusSelectedItem:b}=i,y=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&v&&g&&x){const I=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),j=x.getBoundingClientRect();if(s.dir!=="rtl"){const ae=j.left-A.left,re=R.left-ae,Fe=I.left-re,Xe=I.width+Fe,et=Math.max(Xe,A.width),ye=window.innerWidth-Xt,Pe=ya(re,[Xt,Math.max(Xt,ye-et)]);a.style.minWidth=Xe+"px",a.style.left=Pe+"px"}else{const ae=A.right-j.right,re=window.innerWidth-R.right-ae,Fe=window.innerWidth-I.right-re,Xe=I.width+Fe,et=Math.max(Xe,A.width),ye=window.innerWidth-Xt,Pe=ya(re,[Xt,Math.max(Xt,ye-et)]);a.style.minWidth=Xe+"px",a.style.right=Pe+"px"}const M=h(),D=window.innerHeight-Xt*2,L=v.scrollHeight,P=window.getComputedStyle(u),W=parseInt(P.borderTopWidth,10),H=parseInt(P.paddingTop,10),q=parseInt(P.borderBottomWidth,10),F=parseInt(P.paddingBottom,10),N=W+H+L+F+q,U=Math.min(g.offsetHeight*5,N),Y=window.getComputedStyle(v),fe=parseInt(Y.paddingTop,10),ie=parseInt(Y.paddingBottom,10),he=I.top+I.height/2-Xt,Ee=D-he,de=g.offsetHeight/2,z=g.offsetTop+de,O=W+H+z,K=N-O;if(O<=he){const ae=M.length>0&&g===M[M.length-1].ref.current;a.style.bottom="0px";const re=u.clientHeight-v.offsetTop-v.offsetHeight,Fe=Math.max(Ee,de+(ae?ie:0)+re+q),Xe=O+Fe;a.style.height=Xe+"px"}else{const ae=M.length>0&&g===M[0].ref.current;a.style.top="0px";const Fe=Math.max(he,W+v.offsetTop+(ae?fe:0)+de)+K;a.style.height=Fe+"px",v.scrollTop=O-he+v.offsetTop}a.style.margin=`${Xt}px 0`,a.style.minHeight=U+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,v,g,x,s.dir,r]);pt(()=>y(),[y]);const[E,C]=m.useState();pt(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const T=m.useCallback(I=>{I&&w.current===!0&&(y(),b==null||b(),w.current=!1)},[y,b]);return c.jsx(PS,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:E},children:c.jsx(Se.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Ph.displayName=_S;var RS="SelectPopperPosition",Ia=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Xt,...s}=e,i=Ns(n);return c.jsx(Bd,{...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)"}})});Ia.displayName=RS;var[PS,Na]=vr(Xn,{}),Aa="SelectViewport",Oh=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=jn(Aa,n),i=Na(Aa,n),a=Oe(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.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}),c.jsx(Es.Slot,{scope:n,children:c.jsx(Se.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:se(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const w=window.innerHeight-Xt*2,v=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),x=Math.max(v,g);if(x<w){const b=x+p,y=Math.min(w,b),E=b-y;f.style.height=y+"px",f.style.bottom==="0px"&&(d.scrollTop=E>0?E:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Oh.displayName=Aa;var Mh="SelectGroup",[OS,MS]=vr(Mh),DS=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=rn();return c.jsx(OS,{scope:n,id:o,children:c.jsx(Se.div,{role:"group","aria-labelledby":o,...r,ref:t})})});DS.displayName=Mh;var Dh="SelectLabel",Lh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=MS(Dh,n);return c.jsx(Se.div,{id:o.id,...r,ref:t})});Lh.displayName=Dh;var As="SelectItem",[LS,Fh]=vr(As),$h=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=An(As,n),l=jn(As,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),w=Oe(t,b=>{var y;return(y=l.itemRefCallback)==null?void 0:y.call(l,b,r,o)}),v=rn(),g=m.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 c.jsx(LS,{scope:n,value:r,disabled:o,textId:v,isSelected:u,onItemTextChange:m.useCallback(b=>{f(y=>y||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(Es.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Se.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:se(i.onFocus,()=>p(!0)),onBlur:se(i.onBlur,()=>p(!1)),onClick:se(i.onClick,()=>{g.current!=="mouse"&&x()}),onPointerUp:se(i.onPointerUp,()=>{g.current==="mouse"&&x()}),onPointerDown:se(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:se(i.onPointerMove,b=>{var y;g.current=b.pointerType,o?(y=l.onItemLeave)==null||y.call(l):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:se(i.onPointerLeave,b=>{var y;b.currentTarget===document.activeElement&&((y=l.onItemLeave)==null||y.call(l))}),onKeyDown:se(i.onKeyDown,b=>{var E;((E=l.searchRef)==null?void 0:E.current)!==""&&b.key===" "||(SS.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});$h.displayName=As;var Zr="SelectItemText",zh=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=An(Zr,n),a=jn(Zr,n),l=Fh(Zr,n),u=ES(Zr,n),[d,f]=m.useState(null),h=Oe(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,w=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:v,onNativeOptionRemove:g}=u;return pt(()=>(v(w),()=>g(w)),[v,g,w]),c.jsxs(c.Fragment,{children:[c.jsx(Se.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?no.createPortal(s.children,i.valueNode):null]})});zh.displayName=Zr;var Bh="SelectItemIndicator",Hh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Fh(Bh,n).isSelected?c.jsx(Se.span,{"aria-hidden":!0,...r,ref:t}):null});Hh.displayName=Bh;var ja="SelectScrollUpButton",Uh=m.forwardRef((e,t)=>{const n=jn(ja,e.__scopeSelect),r=Na(ja,e.__scopeSelect),[o,s]=m.useState(!1),i=Oe(t,r.onScrollButtonChange);return pt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Uh.displayName=ja;var _a="SelectScrollDownButton",Wh=m.forwardRef((e,t)=>{const n=jn(_a,e.__scopeSelect),r=Na(_a,e.__scopeSelect),[o,s]=m.useState(!1),i=Oe(t,r.onScrollButtonChange);return pt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Wh.displayName=_a;var Vh=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=jn("SelectScrollButton",n),i=m.useRef(null),a=Is(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),pt(()=>{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]),c.jsx(Se.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:se(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:se(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:se(o.onPointerLeave,()=>{l()})})}),FS="SelectSeparator",Kh=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Se.div,{"aria-hidden":!0,...r,ref:t})});Kh.displayName=FS;var Ra="SelectArrow",$S=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ns(n),s=An(Ra,n),i=jn(Ra,n);return s.open&&i.position==="popper"?c.jsx(Hd,{...o,...r,ref:t}):null});$S.displayName=Ra;var zS="SelectBubbleInput",qh=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Oe(r,o),i=mh(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(Se.select,{...n,style:{...Sh,...n.style},ref:s,defaultValue:t})});qh.displayName=zS;function Gh(e){return e===""||e===void 0}function Yh(e){const t=mt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Xh(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=BS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function BS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var HS=Ch,Jh=kh,US=Ih,WS=Nh,VS=Ah,Zh=jh,KS=Oh,Qh=Lh,ep=$h,qS=zh,GS=Hh,tp=Uh,np=Wh,rp=Kh;const op=HS,sp=US,Pa=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Jh,{ref:r,className:X("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,c.jsx(WS,{asChild:!0,children:c.jsx(Q.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Pa.displayName=Jh.displayName;const ip=m.forwardRef(({className:e,...t},n)=>c.jsx(tp,{ref:n,className:X("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(Q.ChevronUp,{className:"h-4 w-4"})}));ip.displayName=tp.displayName;const ap=m.forwardRef(({className:e,...t},n)=>c.jsx(np,{ref:n,className:X("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(Q.ChevronDown,{className:"h-4 w-4"})}));ap.displayName=np.displayName;const Oa=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(VS,{children:c.jsxs(Zh,{ref:o,className:X("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:[c.jsx(ip,{}),c.jsx(KS,{className:X("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(ap,{})]})}));Oa.displayName=Zh.displayName;const YS=m.forwardRef(({className:e,...t},n)=>c.jsx(Qh,{ref:n,className:X("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));YS.displayName=Qh.displayName;const Jn=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(ep,{ref:r,className:X("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(GS,{children:c.jsx(Q.Check,{className:"h-4 w-4"})})}),c.jsx(qS,{children:t})]}));Jn.displayName=ep.displayName;const XS=m.forwardRef(({className:e,...t},n)=>c.jsx(rp,{ref:n,className:X("-mx-1 my-1 h-px bg-muted",e),...t}));XS.displayName=rp.displayName;var JS="Separator",lp="horizontal",ZS=["horizontal","vertical"],cp=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=lp,...o}=e,s=QS(r)?r:lp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Se.div,{"data-orientation":s,...a,...o,ref:t})});cp.displayName=JS;function QS(e){return ZS.includes(e)}var up=cp;const dp=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(up,{ref:o,decorative:n,orientation:t,className:X("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));dp.displayName=up.displayName;const eC=Gu,tC=Ow,nC=Yu,fp=m.forwardRef(({className:e,...t},n)=>c.jsx(Zo,{className:X("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}));fp.displayName=Zo.displayName;const rC=to.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"}}),hp=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(nC,{children:[c.jsx(fp,{}),c.jsxs(Qo,{ref:o,className:X(rC({side:e}),t),...r,children:[n,c.jsxs(Xu,{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:[c.jsx(Q.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));hp.displayName=Qo.displayName;const pp=({className:e,...t})=>c.jsx("div",{className:X("flex flex-col space-y-2 text-center sm:text-left",e),...t});pp.displayName="SheetHeader";const mp=m.forwardRef(({className:e,...t},n)=>c.jsx(Wn,{ref:n,className:X("text-lg font-semibold text-foreground",e),...t}));mp.displayName=Wn.displayName;const gp=m.forwardRef(({className:e,...t},n)=>c.jsx(es,{ref:n,className:X("text-sm text-muted-foreground",e),...t}));gp.displayName=es.displayName;const oC={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 sC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=S.useState(!1),[s,i]=S.useState(!1),[a,l]=S.useState(e),[u,d]=S.useState(!1),{toast:f}=Ri();S.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),S.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(oC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{l(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 c.jsxs(eC,{open:r,onOpenChange:o,children:[c.jsx(tC,{asChild:!0,children:c.jsxs(Be,{variant:"outline",size:"sm",className:n,children:[c.jsx(Q.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Si,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(hp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(pp,{children:[c.jsx(mp,{children:"Chat Settings"}),c.jsx(gp,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(Fr,{children:[c.jsx($r,{className:"pb-3",children:c.jsxs(zr,{className:"text-lg flex items-center gap-2",children:[c.jsx(Q.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(Ro,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ht,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(bs,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(x=>({...x,api:{...x.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(Be,{variant:"outline",onClick:v,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Ht,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Nn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(x=>({...x,api:{...x.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ht,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(bs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(x=>({...x,api:{...x.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(Be,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(Q.EyeOff,{className:"h-4 w-4"}):c.jsx(Q.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(Fr,{children:[c.jsx($r,{className:"pb-3",children:c.jsxs(zr,{className:"text-lg flex items-center gap-2",children:[c.jsx(Q.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(Ro,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ht,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(op,{value:a.ui.layout,onValueChange:g=>l(x=>({...x,ui:{...x.ui,layout:g}})),children:[c.jsx(Pa,{children:c.jsx(sp,{})}),c.jsxs(Oa,{children:[c.jsx(Jn,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(Jn,{value:"fullscreen",children:"Fullscreen"}),c.jsx(Jn,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ht,{htmlFor:"theme",children:"Theme"}),c.jsxs(op,{value:a.ui.theme,onValueChange:g=>l(x=>({...x,ui:{...x.ui,theme:g}})),children:[c.jsx(Pa,{children:c.jsx(sp,{})}),c.jsxs(Oa,{children:[c.jsx(Jn,{value:"light",children:"Light"}),c.jsx(Jn,{value:"dark",children:"Dark"}),c.jsx(Jn,{value:"system",children:"System"})]})]})]}),c.jsx(dp,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Ht,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Nn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Ht,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Nn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Ht,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Nn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(Fr,{children:[c.jsx($r,{className:"pb-3",children:c.jsxs(zr,{className:"text-lg flex items-center gap-2",children:[c.jsx(Q.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(Ro,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Ht,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Nn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Ht,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Nn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Ht,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Nn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(Be,{variant:"outline",onClick:p,children:[c.jsx(Q.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Be,{variant:"outline",onClick:w,children:"Cancel"}),c.jsxs(Be,{onClick:h,disabled:!u,children:[c.jsx(Q.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function iC({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"}),l=S.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(go,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(ws,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(go,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(Ea,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(ws,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(go,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(Ea,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(ws,{onError:s.onError,enableFileUpload:!0})})]})})}ke.ChatApi=jl,ke.ChatInterface=ws,ke.ChatProviders=go,ke.ChatSettings=sC,ke.MarkdownContent=Ai,ke.MessageComponent=sd,ke.MessageList=Gi,ke.ThreadManager=Ea,ke.applySettings=dS,ke.chatApiClient=vn,ke.default=iC,ke.del=Al,ke.get=At,ke.getChatToken=El,ke.getCurrentSettings=uS,ke.getDefaultApiConfig=uh,ke.getDefaultChatSettings=dh,ke.onChatTokenChanged=Il,ke.post=qs,ke.put=Nl,ke.setChatToken=Ks,ke.useApi=Gs,ke.useChatStream=Ol,ke.useMessages=Zs,ke.useMessagesReducer=Rl,ke.useStream=Fl,ke.useThreads=mo,Object.defineProperties(ke,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|