teodor-new-chat-ui 4.3.241 → 4.3.243
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 +2 -6
- package/dist/index.umd.js +10 -10
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
`+q+I}}var H=!1,te;{var se=typeof WeakMap=="function"?WeakMap:Map;te=new se}function ne(I,K){if(!I||H)return"";{var ie=te.get(I);if(ie!==void 0)return ie}var be;H=!0;var Ge=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var it;it=ee.current,ee.current=null,_e();try{if(K){var He=function(){throw Error()};if(Object.defineProperty(He.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(He,[])}catch($t){be=$t}Reflect.construct(I,[],He)}else{try{He.call()}catch($t){be=$t}I.call(He.prototype)}}else{try{throw Error()}catch($t){be=$t}I()}}catch($t){if($t&&be&&typeof $t.stack=="string"){for(var $e=$t.stack.split(`
|
|
19
19
|
`),Pt=be.stack.split(`
|
|
20
20
|
`),vt=$e.length-1,yt=Pt.length-1;vt>=1&&yt>=0&&$e[vt]!==Pt[yt];)yt--;for(;vt>=1&&yt>=0;vt--,yt--)if($e[vt]!==Pt[yt]){if(vt!==1||yt!==1)do if(vt--,yt--,yt<0||$e[vt]!==Pt[yt]){var qt=`
|
|
21
|
-
`+$e[vt].replace(" at new "," at ");return I.displayName&&qt.includes("<anonymous>")&&(qt=qt.replace("<anonymous>",I.displayName)),typeof I=="function"&&te.set(I,qt),qt}while(vt>=1&&yt>=0);break}}}finally{H=!1,ee.current=it,V(),Error.prepareStackTrace=Ge}var Gn=I?I.displayName||I.name:"",Rn=Gn?D(Gn):"";return typeof I=="function"&&te.set(I,Rn),Rn}function ke(I,K,ie){return ne(I,!1)}function
|
|
21
|
+
`+$e[vt].replace(" at new "," at ");return I.displayName&&qt.includes("<anonymous>")&&(qt=qt.replace("<anonymous>",I.displayName)),typeof I=="function"&&te.set(I,qt),qt}while(vt>=1&&yt>=0);break}}}finally{H=!1,ee.current=it,V(),Error.prepareStackTrace=Ge}var Gn=I?I.displayName||I.name:"",Rn=Gn?D(Gn):"";return typeof I=="function"&&te.set(I,Rn),Rn}function ke(I,K,ie){return ne(I,!1)}function Q(I){var K=I.prototype;return!!(K&&K.isReactComponent)}function fe(I,K,ie){if(I==null)return"";if(typeof I=="function")return ne(I,Q(I));if(typeof I=="string")return D(I);switch(I){case c:return D("Suspense");case d:return D("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return ke(I.render);case f:return fe(I.type,K,ie);case p:{var be=I,Ge=be._payload,it=be._init;try{return fe(it(Ge),K,ie)}catch{}}}return""}var Ie=Object.prototype.hasOwnProperty,Ae={},Fe=g.ReactDebugCurrentFrame;function Ze(I){if(I){var K=I._owner,ie=fe(I.type,I._source,K?K.type:null);Fe.setExtraStackFrame(ie)}else Fe.setExtraStackFrame(null)}function Ve(I,K,ie,be,Ge){{var it=Function.call.bind(Ie);for(var He in I)if(it(I,He)){var $e=void 0;try{if(typeof I[He]!="function"){var Pt=Error((be||"React class")+": "+ie+" type `"+He+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[He]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Pt.name="Invariant Violation",Pt}$e=I[He](K,He,be,ie,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(vt){$e=vt}$e&&!($e instanceof Error)&&(Ze(Ge),w("%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).",be||"React class",ie,He,typeof $e),Ze(null)),$e instanceof Error&&!($e.message in Ae)&&(Ae[$e.message]=!0,Ze(Ge),w("Failed %s type: %s",ie,$e.message),Ze(null))}}}var Ke=Array.isArray;function qe(I){return Ke(I)}function Xe(I){{var K=typeof Symbol=="function"&&Symbol.toStringTag,ie=K&&I[Symbol.toStringTag]||I.constructor.name||"Object";return ie}}function Qe(I){try{return et(I),!1}catch{return!0}}function et(I){return""+I}function Nt(I){if(Qe(I))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Xe(I)),et(I)}var mt=g.ReactCurrentOwner,at={key:!0,ref:!0,__self:!0,__source:!0},de,pe;function me(I){if(Ie.call(I,"ref")){var K=Object.getOwnPropertyDescriptor(I,"ref").get;if(K&&K.isReactWarning)return!1}return I.ref!==void 0}function ze(I){if(Ie.call(I,"key")){var K=Object.getOwnPropertyDescriptor(I,"key").get;if(K&&K.isReactWarning)return!1}return I.key!==void 0}function De(I,K){typeof I.ref=="string"&&mt.current}function ot(I,K){{var ie=function(){de||(de=!0,w("%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)",K))};ie.isReactWarning=!0,Object.defineProperty(I,"key",{get:ie,configurable:!0})}}function Et(I,K){{var ie=function(){pe||(pe=!0,w("%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)",K))};ie.isReactWarning=!0,Object.defineProperty(I,"ref",{get:ie,configurable:!0})}}var st=function(I,K,ie,be,Ge,it,He){var $e={$$typeof:t,type:I,key:K,ref:ie,props:He,_owner:it};return $e._store={},Object.defineProperty($e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty($e,"_self",{configurable:!1,enumerable:!1,writable:!1,value:be}),Object.defineProperty($e,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ge}),Object.freeze&&(Object.freeze($e.props),Object.freeze($e)),$e};function Be(I,K,ie,be,Ge){{var it,He={},$e=null,Pt=null;ie!==void 0&&(Nt(ie),$e=""+ie),ze(K)&&(Nt(K.key),$e=""+K.key),me(K)&&(Pt=K.ref,De(K,Ge));for(it in K)Ie.call(K,it)&&!at.hasOwnProperty(it)&&(He[it]=K[it]);if(I&&I.defaultProps){var vt=I.defaultProps;for(it in vt)He[it]===void 0&&(He[it]=vt[it])}if($e||Pt){var yt=typeof I=="function"?I.displayName||I.name||"Unknown":I;$e&&ot(He,yt),Pt&&Et(He,yt)}return st(I,$e,Pt,Ge,be,mt.current,He)}}var jt=g.ReactCurrentOwner,At=g.ReactDebugCurrentFrame;function W(I){if(I){var K=I._owner,ie=fe(I.type,I._source,K?K.type:null);At.setExtraStackFrame(ie)}else At.setExtraStackFrame(null)}var we;we=!1;function ye(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function ft(){{if(jt.current){var I=$(jt.current.type);if(I)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+I+"`."}return""}}function gt(I){return""}var St={};function Oe(I){{var K=ft();if(!K){var ie=typeof I=="string"?I:I.displayName||I.name;ie&&(K=`
|
|
24
24
|
|
|
@@ -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[bl]=this[bl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Fr(i);r[a]||(Qm(o,i),r[a]=!0)}return P.isArray(t)?t.forEach(s):s(t),this}};Ut.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),P.reduceDescriptors(Ut.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),P.freezeMethods(Ut);function ii(e,t){const n=this||Lr,r=t||n,o=Ut.from(r.headers);let s=r.data;return P.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Sl(e){return!!(e&&e.__CANCEL__)}function gr(e,t,n){Pe.call(this,e??"canceled",Pe.ERR_CANCELED,t,n),this.name="CanceledError"}P.inherits(gr,Pe,{__CANCEL__:!0});function Cl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Pe("Request failed with status code "+n.status,[Pe.ERR_BAD_REQUEST,Pe.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function eg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function tg(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,p=0;for(;f!==o;)p+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const h=d&&c-d;return h?Math.round(p*1e3/h):void 0}}function ng(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const ko=(e,t,n=3)=>{let r=0;const o=tg(50,250);return ng(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},Tl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},kl=e=>(...t)=>P.asap(()=>e(...t)),rg=Mt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Mt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Mt.origin),Mt.navigator&&/(msie|trident)/i.test(Mt.navigator.userAgent)):()=>!0,og=Mt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];P.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),P.isString(r)&&i.push("path="+r),P.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function sg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function ig(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function El(e,t,n){let r=!sg(t);return e&&(r||n==!1)?ig(e,t):t}const Il=e=>e instanceof Ut?{...e}:e;function Jn(e,t){t=t||{};const n={};function r(c,d,f,p){return P.isPlainObject(c)&&P.isPlainObject(d)?P.merge.call({caseless:p},c,d):P.isPlainObject(d)?P.merge({},d):P.isArray(d)?d.slice():d}function o(c,d,f,p){if(P.isUndefined(d)){if(!P.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!P.isUndefined(d))return r(void 0,d)}function i(c,d){if(P.isUndefined(d)){if(!P.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(Il(c),Il(d),f,!0)};return P.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);P.isUndefined(p)&&f!==a||(n[d]=p)}),n}const Nl=e=>{const t=Jn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ut.from(i),t.url=xl(El(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),P.isFormData(n)){if(Mt.hasStandardBrowserEnv||Mt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(P.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Mt.hasStandardBrowserEnv&&(r&&P.isFunction(r)&&(r=r(t)),r||r!==!1&&rg(t.url))){const l=o&&s&&og.read(s);l&&i.set(o,l)}return t},ag=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Nl(e);let s=o.data;const i=Ut.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,m;function x(){h&&h(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function g(){if(!y)return;const S=Ut.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),T={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};Cl(function(E){n(E),x()},function(E){r(E),x()},T),y=null}"onloadend"in y?y.onloadend=g:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(g)},y.onabort=function(){y&&(r(new Pe("Request aborted",Pe.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const T=k&&k.message?k.message:"Network Error",C=new Pe(T,Pe.ERR_NETWORK,e,y);C.event=k||null,r(C),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const T=o.transitional||vl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Pe(k,T.clarifyTimeoutError?Pe.ETIMEDOUT:Pe.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&P.forEach(i.toJSON(),function(k,T){y.setRequestHeader(T,k)}),P.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,m]=ko(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=ko(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new gr(null,e,y):S),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const w=eg(o.url);if(w&&Mt.protocols.indexOf(w)===-1){r(new Pe("Unsupported protocol "+w+":",Pe.ERR_BAD_REQUEST,e));return}y.send(s||null)})},lg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Pe?d:new gr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Pe(`timeout ${t} of ms exceeded`,Pe.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>P.asap(a),l}},cg=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},ug=async function*(e,t){for await(const n of dg(e))yield*cg(n,t)},dg=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()}},Al=(e,t,n,r)=>{const o=ug(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let p=s+=f;n(p)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},jl=64*1024,{isFunction:Eo}=P,fg=(({Request:e,Response:t})=>({Request:e,Response:t}))(P.global),{ReadableStream:_l,TextEncoder:Rl}=P.global,Pl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},pg=e=>{e=P.merge.call({skipUndefined:!0},fg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Eo(t):typeof fetch=="function",s=Eo(n),i=Eo(r);if(!o)return!1;const a=o&&Eo(_l),l=o&&(typeof Rl=="function"?(m=>x=>m.encode(x))(new Rl):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Pl(()=>{let m=!1;const x=new n(Mt.origin,{body:new _l,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!x}),d=i&&a&&Pl(()=>P.isReadableStream(new r("").body)),f={stream:d&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(x,y)=>{let g=x&&x[m];if(g)return g.call(x);throw new Pe(`Response type '${m}' is not supported`,Pe.ERR_NOT_SUPPORT,y)})});const p=async m=>{if(m==null)return 0;if(P.isBlob(m))return m.size;if(P.isSpecCompliantForm(m))return(await new n(Mt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(P.isArrayBufferView(m)||P.isArrayBuffer(m))return m.byteLength;if(P.isURLSearchParams(m)&&(m=m+""),P.isString(m))return(await l(m)).byteLength},h=async(m,x)=>{const y=P.toFiniteNumber(m.getContentLength());return y??p(x)};return async m=>{let{url:x,method:y,data:g,signal:w,cancelToken:S,timeout:k,onDownloadProgress:T,onUploadProgress:C,responseType:E,headers:j,withCredentials:N="same-origin",fetchOptions:A}=Nl(m),O=t||fetch;E=E?(E+"").toLowerCase():"text";let F=lg([w,S&&S.toAbortSignal()],k),$=null;const R=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let z;try{if(C&&c&&y!=="get"&&y!=="head"&&(z=await h(j,g))!==0){let X=new n(x,{method:"POST",body:g,duplex:"half"}),he;if(P.isFormData(g)&&(he=X.headers.get("content-type"))&&j.setContentType(he),X.body){const[Ne,_e]=Tl(z,ko(kl(C)));g=Al(X.body,jl,Ne,_e)}}P.isString(N)||(N=N?"include":"omit");const _=s&&"credentials"in n.prototype,B={...A,signal:F,method:y.toUpperCase(),headers:j.normalize().toJSON(),body:g,duplex:"half",credentials:_?N:void 0};$=s&&new n(x,B);let L=await(s?O($,A):O(x,B));const M=d&&(E==="stream"||E==="response");if(d&&(T||M&&R)){const X={};["status","statusText","headers"].forEach(V=>{X[V]=L[V]});const he=P.toFiniteNumber(L.headers.get("content-length")),[Ne,_e]=T&&Tl(he,ko(kl(T),!0))||[];L=new r(Al(L.body,jl,Ne,()=>{_e&&_e(),R&&R()}),X)}E=E||"text";let J=await f[P.findKey(f,E)||"text"](L,m);return!M&&R&&R(),await new Promise((X,he)=>{Cl(X,he,{data:J,headers:Ut.from(L.headers),status:L.status,statusText:L.statusText,config:m,request:$})})}catch(_){throw R&&R(),_&&_.name==="TypeError"&&/Load failed|fetch/i.test(_.message)?Object.assign(new Pe("Network Error",Pe.ERR_NETWORK,m,$),{cause:_.cause||_}):Pe.from(_,_&&_.code,m,$)}}},hg=new Map,Ol=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=hg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:pg(t)),d=c;return c};Ol();const ai={http:Dm,xhr:ag,fetch:{get:Ol}};P.forEach(ai,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Ml=e=>`- ${e}`,mg=e=>P.isFunction(e)||e===null||e===!1,Dl={getAdapter:(e,t)=>{e=P.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!mg(r)&&(o=ai[(a=String(r)).toLowerCase()],o===void 0))throw new Pe(`Unknown adapter '${a}'`);if(o&&(P.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
33
|
`+i.map(Ml).join(`
|
|
34
34
|
`):" "+Ml(i[0]):"as no adapter specified";throw new Pe("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:ai};function li(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new gr(null,e)}function Ll(e){return li(e),e.headers=Ut.from(e.headers),e.data=ii.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Dl.getAdapter(e.adapter||Lr.adapter,e)(e).then(function(r){return li(e),r.data=ii.call(e,e.transformResponse,r),r.headers=Ut.from(r.headers),r},function(r){return Sl(r)||(li(e),r&&r.response&&(r.response.data=ii.call(e,e.transformResponse,r.response),r.response.headers=Ut.from(r.response.headers))),Promise.reject(r)})}const Fl="1.12.2",Io={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Io[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const $l={};Io.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Fl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Pe(o(i," has been removed"+(n?" in "+n:"")),Pe.ERR_DEPRECATED);return n&&!$l[i]&&($l[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}},Io.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function gg(e,t,n){if(typeof e!="object")throw new Pe("options must be an object",Pe.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 Pe("option "+s+" must be "+l,Pe.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Pe("Unknown option "+s,Pe.ERR_BAD_OPTION)}}const No={assertOptions:gg,validators:Io},gn=No.validators;let Zn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new yl,response:new yl}}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=Jn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&No.assertOptions(r,{silentJSONParsing:gn.transitional(gn.boolean),forcedJSONParsing:gn.transitional(gn.boolean),clarifyTimeoutError:gn.transitional(gn.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:No.assertOptions(o,{encode:gn.function,serialize:gn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),No.assertOptions(n,{baseUrl:gn.spelling("baseURL"),withXsrfToken:gn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Ut.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const c=[];this.interceptors.response.forEach(function(x){c.push(x.fulfilled,x.rejected)});let d,f=0,p;if(!l){const m=[Ll.bind(this),void 0];for(m.unshift(...a),m.push(...c),p=m.length,d=Promise.resolve(n);f<p;)d=d.then(m[f++],m[f++]);return d}p=a.length;let h=n;for(;f<p;){const m=a[f++],x=a[f++];try{h=m(h)}catch(y){x.call(this,y);break}}try{d=Ll.call(this,h)}catch(m){return Promise.reject(m)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Jn(this.defaults,t);const n=El(t.baseURL,t.url,t.allowAbsoluteUrls);return xl(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){Zn.prototype[t]=function(n,r){return this.request(Jn(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Jn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Zn.prototype[t]=n(),Zn.prototype[t+"Form"]=n(!0)});let xg=class qh{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 gr(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 qh(function(o){t=o}),cancel:t}}};function yg(e){return function(n){return e.apply(null,n)}}function vg(e){return P.isObject(e)&&e.isAxiosError===!0}const ci={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(ci).forEach(([e,t])=>{ci[t]=e});function zl(e){const t=new Zn(e),n=nl(Zn.prototype.request,t);return P.extend(n,Zn.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return zl(Jn(e,o))},n}const wt=zl(Lr);wt.Axios=Zn,wt.CanceledError=gr,wt.CancelToken=xg,wt.isCancel=Sl,wt.VERSION=Fl,wt.toFormData=Co,wt.AxiosError=Pe,wt.Cancel=wt.CanceledError,wt.all=function(t){return Promise.all(t)},wt.spread=yg,wt.isAxiosError=vg,wt.mergeConfig=Jn,wt.AxiosHeaders=Ut,wt.formToJSON=e=>wl(P.isHTMLForm(e)?new FormData(e):e),wt.getAdapter=Dl.getAdapter,wt.HttpStatusCode=ci,wt.default=wt;const{Axios:eT,AxiosError:tT,CanceledError:nT,isCancel:rT,CancelToken:oT,VERSION:sT,all:iT,Cancel:aT,isAxiosError:lT,spread:cT,toFormData:uT,AxiosHeaders:dT,HttpStatusCode:fT,formToJSON:pT,getAdapter:hT,mergeConfig:mT}=wt,Bl=typeof window<"u"?window.__API_BASE_URL__:void 0,Hl=Bl?En(Bl):void 0;function En(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Ao=null;const ui=new Set;function Ul(){return Ao}function jo(e){Ao=e,ui.forEach(t=>t(e))}function Wl(e){return ui.add(e),()=>ui.delete(e)}const wg=3e4,bg=9e4,Zt=wt.create({...Hl?{baseURL:Hl}:{},timeout:wg,withCredentials:!0});Zt.interceptors.request.use(e=>(Ao&&(e.headers.Authorization=`Bearer ${Ao}`),e)),Zt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),jo(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Qt(e,t){return Zt.defaults.baseURL?(await Zt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function di(e,t,n){return Zt.defaults.baseURL?(await Zt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Vl(e,t,n){return Zt.defaults.baseURL?(await Zt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Kl(e,t){return Zt.defaults.baseURL?(await Zt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function en(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class ql{get baseUrl(){const t=Zt.defaults.baseURL;return t?En(String(t)):""}updateConfig(t){t.baseUrl&&(Zt.defaults.baseURL=En(String(t.baseUrl))),t.authToken!==void 0&&jo(t.authToken)}getAuthToken(){return Ul()}setAuthToken(t){jo(t)}onTokenChange(t){return Wl(t)}async listThreads(){const t=await Qt("/threads"),n=en(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await di("/threads",t?{title:t}:void 0);return en(r)}async updateThread(t,n){const r=await Vl(`/threads/${t}`,{title:n});return en(r)}async deleteThread(t){const n=await Kl(`/threads/${t}`);return en(n)}async threadInfo(t){const n=await Qt(`/threads/${t}/info`);return en(n)}async listAgents(){const t=await Qt("/agents"),n=en(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Qt(`/agents/${t}`);return en(n)}async getAgentSchema(t){const n=await Qt(`/agents/${t}/schema`);return en(n)}async getState(t){const n=await Qt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return en(n)}async getStateHistory(t){const n=await Qt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:bg});return en(n)}async cancelRun(t){const n=await di("/runs/cancel",{threadId:t});return en(n)}async listCheckpointSummaries(t){const n=await Qt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=en(n);return(r==null?void 0:r.items)??[]}}const Pn=new ql,Gl=b.createContext(null);function Sg({children:e,apiConfig:t}){const n=Pn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Gl.Provider,{value:r,children:e})}function fi(){const e=b.useContext(Gl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Cg(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 Tg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Cg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const kg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function pi(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Eg(e,t){return`${e??""}::${t??""}`}function $r(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!pi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Ng(t),i=Yl(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Yl(e,t){if(!pi(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(N=>!!N&&typeof N=="object").map(N=>({...N})):a===null?null:void 0,c=r.map((N,A)=>Mg(N,A)).filter(N=>!!N),d=Wt(e.config),f=Wt(d==null?void 0:d.configurable),p=Tt(f,["checkpoint_id","checkpointId"]),h=Tt(f,["checkpoint_ns","checkpointNs"]),m=Wt(e==null?void 0:e.parentConfig),x=Wt(m==null?void 0:m.configurable),y=Tt(x,["checkpoint_id","checkpointId"])??null,g=Tt(x,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,S=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),k=c[c.length-1]??null,T=Wt(e==null?void 0:e.metadata),C=Tt(T,["branch_label","branchLabel"]),E=Tt(x,["checkpoint_id","checkpointId"]),j=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:g,interrupt:Ig(a,c,t),createdAt:S,parentId:E??null,branchLabel:C??null,lastMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:T??null,config:d??null,parentConfig:m??null,next:j??null,tasks:l??null,values:i??null}}function Ig(e,t,n){const r=Pg(e,n);return r||Rg(t,n)}function Ng(e){const t=new Map;e.forEach((o,s)=>{if(!pi(o))return;const i=Yl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Eg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ag(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Jl(s.createdAt??"")-Jl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Ag(e,t){return{...e,metadata:_o(e.metadata,t.metadata)??null,config:_o(e.config,t.config)??null,parentConfig:_o(e.parentConfig,t.parentConfig)??null,next:jg(e.next,t.next)??null,tasks:_g(e.tasks,t.tasks)??null,values:_o(e.values,t.values)??null}}function _o(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function jg(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function _g(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Rg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function Pg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Og(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=zr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=zr(r.state,`${o}-state`);if(s)return s}}return null}function Og(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",x=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:m,interrupts:x,state:y!==void 0?y:f}}const n=Wt(e);if(!n)return null;const r=Tt(n,["id","task_id","taskId"])??t,o=Tt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function zr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Xl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=zr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=zr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=zr(l,t,n+1,r);if(c)return c}}return null}function Xl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=Tt(n,["type","event","kind"]),o=Tt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Xl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Jl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Mg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Wt(e)??{},o=Wt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=kg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Wt(o.additional_kwargs)??Wt(o.additionalKwargs),d=Wt(o.response_metadata)??Wt(o.responseMetadata),f=Tt(c,["createdAt","created_at"])??Tt(o,["created_at","createdAt"]),p=Tt(c,["checkpointId","checkpoint_id"]),h=Tt(c,["checkpointNs","checkpoint_ns"]),m=Dg(o.content),x={id:l,role:i,content:m};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),p&&(x.checkpointId=p),h&&(x.checkpointNs=h);const y=zg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),g=d?{...d}:void 0;y&&Object.keys(y).length&&(x.additionalKwargs=y),g&&Object.keys(g).length&&(x.responseMetadata=g);const w=Lg((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(x.content=[...x.content,...w]),i==="tool"){const S=Fg(o,x.content);S&&(x.content=S)}return x}function Dg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Zl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Zl(e);return t?[t]:[]}return[]}function Zl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=Tt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=Tt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Ql(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=Tt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Ql(e,t){var s;const n=Tt(e,["id","call_id"])??t,r=Tt(e,["name"])??Tt(Wt(e.function),["name"]);if(!n||!r)return null;const o=$g(e.args??e.arguments??((s=Wt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Lg(e){return Array.isArray(e)?e.map((t,n)=>Ql(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Fg(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function $g(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function Wt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Tt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function zg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function Bg(){const e=b.useRef(new Map),t=b.useCallback((a,l)=>{const c=e.current.get(a),d=new Map;c&&c.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),l.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),e.current.set(a,Array.from(d.values()))},[]),n=b.useCallback((a,l)=>{const c=e.current.get(a);return c==null?void 0:c.find(d=>d.checkpointId===l)},[]),r=b.useCallback((a,l)=>{const c=e.current.get(a);return(c==null?void 0:c.some(d=>d.checkpointId===l))??!1},[]),o=b.useCallback(a=>e.current.get(a),[]),s=b.useCallback(a=>{e.current.delete(a)},[]),i=b.useCallback(()=>{e.current.clear()},[]);return{cache:e.current,setCacheForThread:t,getCachedMetadata:n,checkpointExists:r,getThreadMetadata:o,clearThreadCache:s,clearAllCache:i}}function Hg(e){return e.type!=="thread_info"&&e.type!=="token"}const Ug={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Wg(e,t){var n;switch(t.type){case"reset":return{messages:hi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=hi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=hi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return tc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>tc(o,s),e):e}case"interrupt_response":return{...e,messages:nc(e.messages),pendingInterrupt:null};default:return e}}function ec(e=[]){const[t,n]=b.useReducer(Wg,{...Ug,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=b.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function tc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Gg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},p={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:p}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??rc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},p=f[a]??{lastSeq:null,lastText:ic(d.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof p.lastSeq=="number"&&h<=p.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:p.lastSeq}),e;const{newParts:m,newMeta:x,changed:y}=Vg(d.content,t.delta,p,h);if(!y)return e;const g={...d,content:m},w=Ro(l,c,g),S={...f,[a]:x};return{...e,messages:w,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??rc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(p=>{var h;return(p==null?void 0:p.type)==="text"&&((h=p.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=d.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const p=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:p}}}return e}if(t.type==="tool_start"){const a=oc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=sc(e,d,c),p=f>=0?e.messages[f]:null,h=l??d[0]??`${c}-${Date.now()}`,m=(p==null?void 0:p.id)??`tool-${h}`,x=d[0]??h,y={type:"tool_call",id:x,name:c,args:t.args};if(p){const S=gi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},T=f,C=T>=0?Ro(e.messages,T,k):e.messages,E=Po(k,d),j=xi(e.toolIndex,m,E);return{...e,messages:C,toolIndex:j}}const g={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:gi(void 0,d.length?d:[x],c,t.args)},w=Po(g,d.length?d:[x]);return{...e,messages:[...e.messages,g],toolIndex:xi(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=oc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=sc(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",p=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,h=(d==null?void 0:d.id)??`tool-${p}`,m=Po(d,a);let x=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(x=JSON.parse(C))}catch{x=t.output}const y={type:"text",text:typeof x=="string"?x:JSON.stringify(x)},g=(d==null?void 0:d.createdAt)??new Date().toISOString(),w=gi(d??void 0,m.length?m:a,f),S={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[y],createdAt:g,additionalKwargs:w},k=c>=0?Ro(e.messages,c,S):[...e.messages,S],T=Po(S,a.length?a:m);return{...e,messages:k,toolIndex:xi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=qg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=$r(t),l=a.interrupt,c=a.latest,d=l===null?nc(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return e}function hi(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 Ro(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function nc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function rc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function oc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function mi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function gi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=mi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Po(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=mi(e);for(const o of r)n.add(o);return Array.from(n)}function xi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function sc(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(mi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function ic(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Vg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??ic(e);let l="",c=e.slice();if(s){const f=Kg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",m={...p,text:h+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function ac(e){return e.replace(/\s+/g," ").trim()}function Kg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=ac(e),o=ac(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function qg(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 Ro(e,r,s)}return e}function Gg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function lc(e={}){const t=b.useMemo(()=>En(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[f,p]=b.useState(""),[h,m]=b.useState(null),[x,y]=b.useState(0),[g,w]=b.useState(!1),S=b.useRef(null),k=b.useRef(!0),T=b.useRef(0),C=b.useRef(null),E=b.useRef(null),j=b.useRef(null),N=b.useRef(null),A=b.useCallback(R=>{o(R)},[]),O=b.useCallback(()=>{p(""),m(null),d(null),E.current=null,j.current=null,N.current=null},[]),F=b.useCallback(()=>{var R;console.debug("[use-chat] stop() invoked - aborting stream"),(R=S.current)==null||R.abort(),S.current=null,C.current=null,l(!1),w(!1),T.current=0,y(0)},[]),$=b.useCallback((R,z,_)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),m(null),E.current=null,j.current=null,N.current=null;const B=new AbortController;S.current=B;let L=null,M=null,J=!1;return C.current={threadId:R.threadId??null,headers:{}},(async()=>{var he,Ne,_e,V,ee,q,D,H,te,se,ne,ke,Z,fe,Ie,Ae,Fe,Ze;const X=Ve=>{var Ke;try{const qe=JSON.parse(JSON.stringify(Ve));return(Ke=qe==null?void 0:qe.payload)!=null&&Ke.files_info&&Array.isArray(qe.payload.files_info)&&(qe.payload.files_info=qe.payload.files_info.map(Xe=>({...Xe,data:Xe!=null&&Xe.data?`<base64 ${String(Xe.data).length} chars>`:Xe==null?void 0:Xe.data}))),qe}catch{return Ve}};try{let Ve={};try{if(r)Ve={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Be=window.__AUTH_TOKEN__,jt=((he=window.localStorage)==null?void 0:he.getItem("authToken"))||null;let At=null;try{const we=(Ne=window.localStorage)==null?void 0:Ne.getItem("chat-settings");we&&(At=((_e=JSON.parse(we))==null?void 0:_e.apiKey)||null)}catch{}const W=Be||jt||At||null;W&&(Ve={Authorization:`Bearer ${W}`})}}catch{}console.debug("[use-chat] POST",t+n,X(R));let Ke={};if(typeof window<"u")try{const st=(V=window.localStorage)==null?void 0:V.getItem("authSessionId");st&&(Ke={"X-Session-Id":st})}catch{}const qe={...Ve,...Ke,...s.current},Xe={"Content-Type":"application/json",Accept:"text/event-stream",...qe},Qe=await fetch(t+n,{method:"POST",headers:Xe,body:JSON.stringify(R),signal:B.signal,credentials:i});if(C.current&&(C.current.headers=qe),!Qe.ok||!Qe.body){const st=await Qe.text().catch(()=>"");console.debug("[use-chat] non-OK response",Qe.status,st==null?void 0:st.slice(0,500));const Be=`stream ${Qe.status}${st?": "+st:""}`;throw(ee=_==null?void 0:_.onConnectionError)==null||ee.call(_,Be),J=!0,L="error",M=Be,new Error(Be)}w(!0);const et=Qe.body.getReader(),Nt=new TextDecoder;let mt="",at=[];T.current=0,y(0);let de=0,pe=null;const me=()=>{if(at.length){const st=at.join("");at=[],k.current&&p(Be=>Be+st)}pe=null},ze=()=>{typeof window<"u"&&pe==null&&(pe=requestAnimationFrame(me))};let De=Date.now();const ot=setInterval(()=>{var st;if(Date.now()-De>18e5){const Be="Stream idle timeout";d(Be),L="error",M=Be,B.abort(),(st=_==null?void 0:_.onError)==null||st.call(_,Be)}},5e3),Et=1024*1024;try{const st=Qe.headers.get("X-Thread-Id")||Qe.headers.get("x-thread-id"),Be=Qe.headers.get("X-Thread-Created")||Qe.headers.get("x-thread-created"),jt=st??null,At=String(Be??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:jt}),(q=_==null?void 0:_.onOpen)==null||q.call(_,{threadId:jt,created:At});;){const{value:W,done:we}=await et.read();if(we)break;mt+=Nt.decode(W,{stream:!0}),mt.length>Et&&(mt="",console.warn("Stream buffer reset: exceeded 1MB"));let ye;for(;(ye=mt.indexOf(`
|
|
35
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Jn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&No.assertOptions(r,{silentJSONParsing:gn.transitional(gn.boolean),forcedJSONParsing:gn.transitional(gn.boolean),clarifyTimeoutError:gn.transitional(gn.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:No.assertOptions(o,{encode:gn.function,serialize:gn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),No.assertOptions(n,{baseUrl:gn.spelling("baseURL"),withXsrfToken:gn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Ut.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const c=[];this.interceptors.response.forEach(function(x){c.push(x.fulfilled,x.rejected)});let d,f=0,p;if(!l){const m=[Ll.bind(this),void 0];for(m.unshift(...a),m.push(...c),p=m.length,d=Promise.resolve(n);f<p;)d=d.then(m[f++],m[f++]);return d}p=a.length;let h=n;for(;f<p;){const m=a[f++],x=a[f++];try{h=m(h)}catch(y){x.call(this,y);break}}try{d=Ll.call(this,h)}catch(m){return Promise.reject(m)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Jn(this.defaults,t);const n=El(t.baseURL,t.url,t.allowAbsoluteUrls);return xl(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){Zn.prototype[t]=function(n,r){return this.request(Jn(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Jn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Zn.prototype[t]=n(),Zn.prototype[t+"Form"]=n(!0)});let xg=class qh{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 gr(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 qh(function(o){t=o}),cancel:t}}};function yg(e){return function(n){return e.apply(null,n)}}function vg(e){return P.isObject(e)&&e.isAxiosError===!0}const ci={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(ci).forEach(([e,t])=>{ci[t]=e});function zl(e){const t=new Zn(e),n=nl(Zn.prototype.request,t);return P.extend(n,Zn.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return zl(Jn(e,o))},n}const wt=zl(Lr);wt.Axios=Zn,wt.CanceledError=gr,wt.CancelToken=xg,wt.isCancel=Sl,wt.VERSION=Fl,wt.toFormData=Co,wt.AxiosError=Pe,wt.Cancel=wt.CanceledError,wt.all=function(t){return Promise.all(t)},wt.spread=yg,wt.isAxiosError=vg,wt.mergeConfig=Jn,wt.AxiosHeaders=Ut,wt.formToJSON=e=>wl(P.isHTMLForm(e)?new FormData(e):e),wt.getAdapter=Dl.getAdapter,wt.HttpStatusCode=ci,wt.default=wt;const{Axios:eT,AxiosError:tT,CanceledError:nT,isCancel:rT,CancelToken:oT,VERSION:sT,all:iT,Cancel:aT,isAxiosError:lT,spread:cT,toFormData:uT,AxiosHeaders:dT,HttpStatusCode:fT,formToJSON:pT,getAdapter:hT,mergeConfig:mT}=wt,Bl=typeof window<"u"?window.__API_BASE_URL__:void 0,Hl=Bl?En(Bl):void 0;function En(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Ao=null;const ui=new Set;function Ul(){return Ao}function jo(e){Ao=e,ui.forEach(t=>t(e))}function Wl(e){return ui.add(e),()=>ui.delete(e)}const wg=3e4,bg=9e4,Zt=wt.create({...Hl?{baseURL:Hl}:{},timeout:wg,withCredentials:!0});Zt.interceptors.request.use(e=>(Ao&&(e.headers.Authorization=`Bearer ${Ao}`),e)),Zt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),jo(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Qt(e,t){return Zt.defaults.baseURL?(await Zt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function di(e,t,n){return Zt.defaults.baseURL?(await Zt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Vl(e,t,n){return Zt.defaults.baseURL?(await Zt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Kl(e,t){return Zt.defaults.baseURL?(await Zt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function en(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class ql{get baseUrl(){const t=Zt.defaults.baseURL;return t?En(String(t)):""}updateConfig(t){t.baseUrl&&(Zt.defaults.baseURL=En(String(t.baseUrl))),t.authToken!==void 0&&jo(t.authToken)}getAuthToken(){return Ul()}setAuthToken(t){jo(t)}onTokenChange(t){return Wl(t)}async listThreads(){const t=await Qt("/threads"),n=en(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await di("/threads",t?{title:t}:void 0);return en(r)}async updateThread(t,n){const r=await Vl(`/threads/${t}`,{title:n});return en(r)}async deleteThread(t){const n=await Kl(`/threads/${t}`);return en(n)}async threadInfo(t){const n=await Qt(`/threads/${t}/info`);return en(n)}async listAgents(){const t=await Qt("/agents"),n=en(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Qt(`/agents/${t}`);return en(n)}async getAgentSchema(t){const n=await Qt(`/agents/${t}/schema`);return en(n)}async getState(t){const n=await Qt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return en(n)}async getStateHistory(t){const n=await Qt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:bg});return en(n)}async cancelRun(t){const n=await di("/runs/cancel",{threadId:t});return en(n)}async listCheckpointSummaries(t){const n=await Qt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=en(n);return(r==null?void 0:r.items)??[]}}const Pn=new ql,Gl=b.createContext(null);function Sg({children:e,apiConfig:t}){const n=Pn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Gl.Provider,{value:r,children:e})}function fi(){const e=b.useContext(Gl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Cg(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 Tg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Cg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const kg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function pi(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Eg(e,t){return`${e??""}::${t??""}`}function $r(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!pi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Ng(t),i=Yl(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Yl(e,t){if(!pi(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(N=>!!N&&typeof N=="object").map(N=>({...N})):a===null?null:void 0,c=r.map((N,A)=>Mg(N,A)).filter(N=>!!N),d=Wt(e.config),f=Wt(d==null?void 0:d.configurable),p=Tt(f,["checkpoint_id","checkpointId"]),h=Tt(f,["checkpoint_ns","checkpointNs"]),m=Wt(e==null?void 0:e.parentConfig),x=Wt(m==null?void 0:m.configurable),y=Tt(x,["checkpoint_id","checkpointId"])??null,g=Tt(x,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,S=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),k=c[c.length-1]??null,T=Wt(e==null?void 0:e.metadata),C=Tt(T,["branch_label","branchLabel"]),E=Tt(x,["checkpoint_id","checkpointId"]),j=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:g,interrupt:Ig(a,c,t),createdAt:S,parentId:E??null,branchLabel:C??null,lastMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:T??null,config:d??null,parentConfig:m??null,next:j??null,tasks:l??null,values:i??null}}function Ig(e,t,n){const r=Pg(e,n);return r||Rg(t,n)}function Ng(e){const t=new Map;e.forEach((o,s)=>{if(!pi(o))return;const i=Yl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Eg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ag(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Jl(s.createdAt??"")-Jl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Ag(e,t){return{...e,metadata:_o(e.metadata,t.metadata)??null,config:_o(e.config,t.config)??null,parentConfig:_o(e.parentConfig,t.parentConfig)??null,next:jg(e.next,t.next)??null,tasks:_g(e.tasks,t.tasks)??null,values:_o(e.values,t.values)??null}}function _o(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function jg(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function _g(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Rg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function Pg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Og(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=zr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=zr(r.state,`${o}-state`);if(s)return s}}return null}function Og(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",x=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:m,interrupts:x,state:y!==void 0?y:f}}const n=Wt(e);if(!n)return null;const r=Tt(n,["id","task_id","taskId"])??t,o=Tt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function zr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Xl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=zr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=zr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=zr(l,t,n+1,r);if(c)return c}}return null}function Xl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=Tt(n,["type","event","kind"]),o=Tt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Xl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Jl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Mg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Wt(e)??{},o=Wt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=kg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Wt(o.additional_kwargs)??Wt(o.additionalKwargs),d=Wt(o.response_metadata)??Wt(o.responseMetadata),f=Tt(c,["createdAt","created_at"])??Tt(o,["created_at","createdAt"]),p=Tt(c,["checkpointId","checkpoint_id"]),h=Tt(c,["checkpointNs","checkpoint_ns"]),m=Dg(o.content),x={id:l,role:i,content:m};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),p&&(x.checkpointId=p),h&&(x.checkpointNs=h);const y=zg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),g=d?{...d}:void 0;y&&Object.keys(y).length&&(x.additionalKwargs=y),g&&Object.keys(g).length&&(x.responseMetadata=g);const w=Lg((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(x.content=[...x.content,...w]),i==="tool"){const S=Fg(o,x.content);S&&(x.content=S)}return x}function Dg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Zl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Zl(e);return t?[t]:[]}return[]}function Zl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=Tt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=Tt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Ql(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=Tt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Ql(e,t){var s;const n=Tt(e,["id","call_id"])??t,r=Tt(e,["name"])??Tt(Wt(e.function),["name"]);if(!n||!r)return null;const o=$g(e.args??e.arguments??((s=Wt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Lg(e){return Array.isArray(e)?e.map((t,n)=>Ql(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Fg(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function $g(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function Wt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Tt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function zg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function Bg(){const e=b.useRef(new Map),t=b.useCallback((a,l)=>{const c=e.current.get(a),d=new Map;c&&c.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),l.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),e.current.set(a,Array.from(d.values()))},[]),n=b.useCallback((a,l)=>{const c=e.current.get(a);return c==null?void 0:c.find(d=>d.checkpointId===l)},[]),r=b.useCallback((a,l)=>{const c=e.current.get(a);return(c==null?void 0:c.some(d=>d.checkpointId===l))??!1},[]),o=b.useCallback(a=>e.current.get(a),[]),s=b.useCallback(a=>{e.current.delete(a)},[]),i=b.useCallback(()=>{e.current.clear()},[]);return{cache:e.current,setCacheForThread:t,getCachedMetadata:n,checkpointExists:r,getThreadMetadata:o,clearThreadCache:s,clearAllCache:i}}function Hg(e){return e.type!=="thread_info"&&e.type!=="token"}const Ug={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Wg(e,t){var n;switch(t.type){case"reset":return{messages:hi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=hi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=hi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return tc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>tc(o,s),e):e}case"interrupt_response":return{...e,messages:nc(e.messages),pendingInterrupt:null};default:return e}}function ec(e=[]){const[t,n]=b.useReducer(Wg,{...Ug,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=b.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function tc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Gg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},p={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:p}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??rc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},p=f[a]??{lastSeq:null,lastText:ic(d.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof p.lastSeq=="number"&&h<=p.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:p.lastSeq}),e;const{newParts:m,newMeta:x,changed:y}=Vg(d.content,t.delta,p,h);if(!y)return e;const g={...d,content:m},w=Ro(l,c,g),S={...f,[a]:x};return{...e,messages:w,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??rc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(p=>{var h;return(p==null?void 0:p.type)==="text"&&((h=p.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=d.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const p=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:p}}}return e}if(t.type==="tool_start"){const a=oc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=sc(e,d,c),p=f>=0?e.messages[f]:null,h=l??d[0]??`${c}-${Date.now()}`,m=(p==null?void 0:p.id)??`tool-${h}`,x=d[0]??h,y={type:"tool_call",id:x,name:c,args:t.args};if(p){const S=gi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},T=f,C=T>=0?Ro(e.messages,T,k):e.messages,E=Po(k,d),j=xi(e.toolIndex,m,E);return{...e,messages:C,toolIndex:j}}const g={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:gi(void 0,d.length?d:[x],c,t.args)},w=Po(g,d.length?d:[x]);return{...e,messages:[...e.messages,g],toolIndex:xi(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=oc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=sc(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",p=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,h=(d==null?void 0:d.id)??`tool-${p}`,m=Po(d,a);let x=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(x=JSON.parse(C))}catch{x=t.output}const y={type:"text",text:typeof x=="string"?x:JSON.stringify(x)},g=(d==null?void 0:d.createdAt)??new Date().toISOString(),w=gi(d??void 0,m.length?m:a,f),S={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[y],createdAt:g,additionalKwargs:w},k=c>=0?Ro(e.messages,c,S):[...e.messages,S],T=Po(S,a.length?a:m);return{...e,messages:k,toolIndex:xi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=qg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=$r(t),l=a.interrupt,c=a.latest,d=l===null?nc(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return e}function hi(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 Ro(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function nc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function rc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function oc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function mi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function gi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=mi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Po(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=mi(e);for(const o of r)n.add(o);return Array.from(n)}function xi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function sc(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(mi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function ic(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Vg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??ic(e);let l="",c=e.slice();if(s){const f=Kg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",m={...p,text:h+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function ac(e){return e.replace(/\s+/g," ").trim()}function Kg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=ac(e),o=ac(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function qg(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 Ro(e,r,s)}return e}function Gg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function lc(e={}){const t=b.useMemo(()=>En(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[f,p]=b.useState(""),[h,m]=b.useState(null),[x,y]=b.useState(0),[g,w]=b.useState(!1),S=b.useRef(null),k=b.useRef(!0),T=b.useRef(0),C=b.useRef(null),E=b.useRef(null),j=b.useRef(null),N=b.useRef(null),A=b.useCallback(R=>{o(R)},[]),O=b.useCallback(()=>{p(""),m(null),d(null),E.current=null,j.current=null,N.current=null},[]),F=b.useCallback(()=>{var R;console.debug("[use-chat] stop() invoked - aborting stream"),(R=S.current)==null||R.abort(),S.current=null,C.current=null,l(!1),w(!1),T.current=0,y(0)},[]),$=b.useCallback((R,z,_)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),m(null),E.current=null,j.current=null,N.current=null;const B=new AbortController;S.current=B;let L=null,M=null,J=!1;return C.current={threadId:R.threadId??null,headers:{}},(async()=>{var he,Ne,_e,V,ee,q,D,H,te,se,ne,ke,Q,fe,Ie,Ae,Fe,Ze;const X=Ve=>{var Ke;try{const qe=JSON.parse(JSON.stringify(Ve));return(Ke=qe==null?void 0:qe.payload)!=null&&Ke.files_info&&Array.isArray(qe.payload.files_info)&&(qe.payload.files_info=qe.payload.files_info.map(Xe=>({...Xe,data:Xe!=null&&Xe.data?`<base64 ${String(Xe.data).length} chars>`:Xe==null?void 0:Xe.data}))),qe}catch{return Ve}};try{let Ve={};try{if(r)Ve={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Be=window.__AUTH_TOKEN__,jt=((he=window.localStorage)==null?void 0:he.getItem("authToken"))||null;let At=null;try{const we=(Ne=window.localStorage)==null?void 0:Ne.getItem("chat-settings");we&&(At=((_e=JSON.parse(we))==null?void 0:_e.apiKey)||null)}catch{}const W=Be||jt||At||null;W&&(Ve={Authorization:`Bearer ${W}`})}}catch{}console.debug("[use-chat] POST",t+n,X(R));let Ke={};if(typeof window<"u")try{const st=(V=window.localStorage)==null?void 0:V.getItem("authSessionId");st&&(Ke={"X-Session-Id":st})}catch{}const qe={...Ve,...Ke,...s.current},Xe={"Content-Type":"application/json",Accept:"text/event-stream",...qe},Qe=await fetch(t+n,{method:"POST",headers:Xe,body:JSON.stringify(R),signal:B.signal,credentials:i});if(C.current&&(C.current.headers=qe),!Qe.ok||!Qe.body){const st=await Qe.text().catch(()=>"");console.debug("[use-chat] non-OK response",Qe.status,st==null?void 0:st.slice(0,500));const Be=`stream ${Qe.status}${st?": "+st:""}`;throw(ee=_==null?void 0:_.onConnectionError)==null||ee.call(_,Be),J=!0,L="error",M=Be,new Error(Be)}w(!0);const et=Qe.body.getReader(),Nt=new TextDecoder;let mt="",at=[];T.current=0,y(0);let de=0,pe=null;const me=()=>{if(at.length){const st=at.join("");at=[],k.current&&p(Be=>Be+st)}pe=null},ze=()=>{typeof window<"u"&&pe==null&&(pe=requestAnimationFrame(me))};let De=Date.now();const ot=setInterval(()=>{var st;if(Date.now()-De>18e5){const Be="Stream idle timeout";d(Be),L="error",M=Be,B.abort(),(st=_==null?void 0:_.onError)==null||st.call(_,Be)}},5e3),Et=1024*1024;try{const st=Qe.headers.get("X-Thread-Id")||Qe.headers.get("x-thread-id"),Be=Qe.headers.get("X-Thread-Created")||Qe.headers.get("x-thread-created"),jt=st??null,At=String(Be??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:jt}),(q=_==null?void 0:_.onOpen)==null||q.call(_,{threadId:jt,created:At});;){const{value:W,done:we}=await et.read();if(we)break;mt+=Nt.decode(W,{stream:!0}),mt.length>Et&&(mt="",console.warn("Stream buffer reset: exceeded 1MB"));let ye;for(;(ye=mt.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const ft=mt.slice(0,ye);mt=mt.slice(ye+2);const gt=Xg(ft);if(!gt)continue;let St;try{St=JSON.parse(gt)}catch{console.debug("[use-chat] malformed SSE:",gt.slice(0,200));continue}const Oe=Yg(St)?St.data:St;De=Date.now();const Kt=Oe.seq;if(Kt!==void 0){if(Kt<=de){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Kt,lastProcessedSeq:de,type:Oe.type});continue}de>0&&Kt>de+1&&((D=_==null?void 0:_.onGap)==null||D.call(_,{from:de,to:Kt})),de=Kt,T.current=Kt,y(Kt)}if(console.debug("[use-chat] received event",{seq:Oe.seq,type:Oe.type,preview:(()=>{var lt;try{return Oe.type==="message_delta"?{deltaTypes:(lt=Oe.delta)==null?void 0:lt.map(Ct=>Ct.type),textLen:(Oe.delta||[]).filter(Ct=>Ct.type==="text").map(Ct=>String(Ct.text||"").length)}:Oe.content||Oe.delta?{hasContent:!0}:{}}catch(Ct){return{err:String(Ct)}}})()}),Oe.type==="checkpoint")E.current=Oe.checkpointId??null,j.current=Oe.checkpointNs??null,m(Oe.checkpointId??null);else if(Oe.type==="state_history"){N.current=Oe;try{const Ct=$r(Oe).latest;Ct&&(E.current=Ct.checkpointId??null,j.current=Ct.checkpointNs??null,m(Ct.checkpointId??null))}catch(lt){console.warn("[use-chat] Failed to hydrate state_history payload",lt)}}try{z==null||z(Oe)}catch(lt){console.error("[use-chat] Error in onEvent callback:",lt,"for event:",Oe.type)}if(Oe.type==="token"&&e.autoAppendAssistant!==!1)at.push(Oe.content),ze();else if(Oe.type==="message_delta"){const lt=Oe.delta.filter(Ct=>Ct.type==="text").map(Ct=>Ct.text).join("");lt&&e.autoAppendAssistant!==!1&&(at.push(lt),ze())}else if(Oe.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(H=_==null?void 0:_.onHeartbeat)==null||H.call(_,Oe)}catch(lt){console.warn("[use-chat] heartbeat callback failed",lt)}}else if(pe!==null&&cancelAnimationFrame(pe),me(),Oe.type==="checkpoint")m(Oe.checkpointId);else if(Oe.type==="error"){const lt=Oe;if(d(lt.message),L="error",M=lt.message,lt.error_type==="auth_error"||lt.code==="TOKEN_EXPIRED"||((te=lt.message)==null?void 0:te.includes("token"))||((se=lt.message)==null?void 0:se.includes("401"))||((ne=lt.message)==null?void 0:ne.includes("unauthorized"))||((ke=lt.message)==null?void 0:ke.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",lt.message);try{(
|
|
38
|
-
`)}const cc=200;function Jg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),p=b.useRef(null),h=b.useCallback(N=>{try{const A=globalThis.structuredClone;if(typeof A=="function")return A(N)}catch{}try{return JSON.parse(JSON.stringify(N))}catch{return N}},[]),m=b.useCallback((N,A)=>{if(!N)return;const O=f.current.get(N)??[],F=h(A),$=O.length>=cc?[...O.slice(O.length-cc+1),F]:[...O,F];f.current.set(N,$)},[h]),x=b.useCallback(N=>{N&&f.current.set(N,[])},[]),y=b.useCallback(N=>{const A=N??d.current;if(!A)return;const O=f.current.get(A);O!=null&&O.length&&O.forEach(F=>{try{n(F)}catch($){console.error("[useChatStreamingService] Failed to replay buffered event",$)}})},[n]),g=b.useCallback(N=>{var F,$,R,z,_;const A=N.seq??null;if(A!==null){const B=c.current;if(B!==null){if(A<=B)return;A>B+1&&(o==null||o({from:B,to:A}))}c.current=A}if(N.type==="thread_info"){d.current=N.threadId,p.current&&(p.current.threadIdGuess=N.threadId),x(N.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",N);try{t(N)}catch(B){console.error("[useChatStreamingService] Error in onThreadInfo handler:",B)}return}if(N.type==="heartbeat"){try{l==null||l(N)}catch(B){console.error("[useChatStreamingService] Error in onHeartbeat handler:",B)}return}if(N.type==="error"){const B=N;if(B.error_type==="auth_error"||B.code==="TOKEN_EXPIRED"||((F=B.message)==null?void 0:F.includes("token"))||(($=B.message)==null?void 0:$.includes("401"))||((R=B.message)==null?void 0:R.includes("unauthorized"))||((z=B.message)==null?void 0:z.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",B.message);try{a==null||a(B.message)}catch(M){console.warn("[useChatStreamingService] onAuthError handler failed",M)}}}const O=N.threadId??(N.type==="state_history"?N.threadId:void 0)??d.current??((_=p.current)==null?void 0:_.threadIdGuess)??null;if(N.type==="state_history"&&(d.current=O??d.current),Hg(N)){N.type==="checkpoint"||N.type==="state_history"?x(O??null):m(O??null,N);try{n(N)}catch(B){console.error("[useChatStreamingService] Error in onMessageEvent handler:",B)}return}try{r==null||r(N)}catch(B){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",B)}},[m,x,n,o,t,r]),{stream:w,stop:S,isStreaming:k,error:T,setToken:C}=lc({baseUrl:e,token:void 0}),E=b.useCallback((N,A)=>{c.current=null,d.current=N.threadId??null,p.current={request:N,callbacks:A,manualStop:!1,threadIdGuess:N.threadId??null},w(N,g,{onOpen:A==null?void 0:A.onOpen,onError:O=>{var F;(F=A==null?void 0:A.onError)==null||F.call(A,O)},onGap:(A==null?void 0:A.onGap)??o,onConnectionError:O=>{var F;i==null||i(O),(F=A==null?void 0:A.onConnectionError)==null||F.call(A,O)},onAuthError:O=>{var F;a==null||a(O),(F=A==null?void 0:A.onAuthError)==null||F.call(A,O)},onHeartbeat:O=>{var F;try{l==null||l(O)}catch($){console.warn("[useChatStreamingService] onHeartbeat handler failed",$)}try{(F=A==null?void 0:A.onHeartbeat)==null||F.call(A,O)}catch($){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",$)}},onClosed:O=>{var z,_,B,L;const F=((z=p.current)==null?void 0:z.manualStop)??!1,$=d.current??((_=p.current)==null?void 0:_.threadIdGuess)??((B=O.lastStateHistory)==null?void 0:B.threadId)??null;(O.reason==="complete"||O.reason==="aborted"&&F)&&x($);const R={...O,threadId:$,manualStop:F};try{s==null||s(R)}catch(M){console.warn("[useChatStreamingService] onStreamClosed handler failed",M)}try{(L=A==null?void 0:A.onClosed)==null||L.call(A,R)}catch(M){console.warn("[useChatStreamingService] downstream onClosed handler failed",M)}p.current&&(p.current=null)}})},[x,g,a,i,l,o,s,w]),j=b.useCallback(()=>{p.current&&(p.current.manualStop=!0),S()},[S]);return b.useMemo(()=>({startStream:E,stop:j,isStreaming:k,error:T,setAuthToken:C,replayBufferedEvents:y}),[E,j,k,T,C,y])}const uc=b.createContext(null),dc=b.createContext(null),fc=b.createContext(null);b.createContext(!1);function Zg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,checkpointMetadataCache:l}){const{api:c,baseUrl:d}=fi(),f=b.useMemo(()=>En(d),[d]),[p,h]=b.useState([]),[m,x]=b.useState(t),[y,g]=b.useState(!1),[w,S]=b.useState(null),[k,T]=b.useState(!1),[C,E]=b.useState(null),{state:j,seed:N,prepend:A,pushUser:O,onEvent:F}=ec(),[$,R]=b.useState(!1),[z,_]=b.useState(!1),[B,L]=b.useState(null),[M,J]=b.useState([]),[X,he]=b.useState(!1),Ne=l??Bg(),{setCacheForThread:_e}=Ne,V=b.useRef(m),ee=b.useRef(null);b.useEffect(()=>{V.current=m},[m]);const q=b.useRef(),{startStream:D,stop:H,isStreaming:te,error:se,setAuthToken:ne}=Jg({baseUrl:f,onThreadInfo:de=>{console.log("[ChatSessionProvider] Thread info:",de.threadId),V.current!==de.threadId&&x(de.threadId)},onMessageEvent:F,onUnhandledEvent:de=>{console.warn("[ChatSessionProvider] Unhandled event:",de.type)},onAuthError:i}),ke=b.useCallback(async()=>{g(!0),S(null);try{const de=await c.listThreads();h(de??[])}catch(de){const pe=String(de);S(pe),s==null||s(pe)}finally{g(!1)}},[c,s]),Z=b.useCallback(async de=>{try{const pe=await c.createThread(de);return x(pe.threadId),await ke(),pe.threadId}catch(pe){return s==null||s(String(pe)),null}},[c,ke,s]),fe=b.useCallback(async de=>{try{await c.deleteThread(de),V.current===de&&(x(null),N([],{})),await ke()}catch(pe){s==null||s(String(pe))}},[c,ke,N,s]),Ie=b.useCallback(async(de,pe)=>{try{await c.updateThread(de,pe),await ke()}catch(me){s==null||s(String(me))}},[c,ke,s]),Ae=b.useCallback((de,pe,me)=>{const ze=pe.filter(De=>De.checkpointId).map(De=>({checkpointId:De.checkpointId,checkpointNs:De.checkpointNs??void 0,createdAt:De.createdAt??""}));console.log(`[ChatSessionProvider] Cached metadata for ${ze.length} checkpoints from ${me}`),_e(de,ze)},[_e]),Fe=b.useCallback(async(de,pe)=>{if(de){T(!0),E(null);try{const me=await c.getStateHistory({threadId:de,checkpointId:pe||void 0}),{checkpoints:ze}=$r(me);Ae(de,ze,`thread load (requested: ${pe})`);const De=ze.find(ot=>ot.messages&&ot.messages.length>0)??(pe?ze.find(ot=>ot.checkpointId===pe):null)??ze[0];N((De==null?void 0:De.messages)??[],{checkpointId:(De==null?void 0:De.checkpointId)??null,checkpointNs:(De==null?void 0:De.checkpointNs)??null}),J(ze),R(!!(De!=null&&De.nextCursor)),L((De==null?void 0:De.nextCursor)??null)}catch(me){const ze=String(me);E(ze),s==null||s(ze)}finally{T(!1)}}},[c,N,s,Ae]);b.useEffect(()=>{q.current=Fe},[Fe]);const Ze=b.useCallback(async(de,pe)=>{const me=V.current;if(me){he(!0);try{const ze=await c.getStateHistory({threadId:me,checkpointId:de,checkpointNs:pe??void 0}),{checkpoints:De}=$r(ze);Ae(me,De,"checkpoint navigation");const ot=De.find(Et=>Et.checkpointId===de&&(pe?Et.checkpointNs===pe:!0));if(!ot){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:de,checkpointNs:pe});return}J(De),N(ot.messages??[],{checkpointId:ot.checkpointId??null,checkpointNs:ot.checkpointNs??null})}catch(ze){s==null||s(String(ze))}finally{he(!1)}}},[c,N,s,Ae]),Ve=b.useCallback((de,pe)=>{N(j.messages,{checkpointId:de??null,checkpointNs:pe??null})},[N,j.messages]),Ke=b.useCallback(async()=>{V.current&&await Fe(V.current)},[Fe]),qe=b.useCallback(async()=>{if(!(!V.current||!B)){_(!0);try{const de=await c.getStateHistory({threadId:V.current,checkpointId:B}),{checkpoints:pe}=$r(de);if(pe.length>0){const me=pe[pe.length-1];A((me==null?void 0:me.messages)??[]),R(!!(me!=null&&me.nextCursor)),L((me==null?void 0:me.nextCursor)??null)}}catch(de){s==null||s(String(de))}finally{_(!1)}}},[c,B,A,s]),Xe=b.useCallback(async()=>{N([],{}),J([]),R(!1),L(null)},[N]),Qe=b.useCallback(async(de,pe,me)=>{const ze=V.current;if(!ze)throw new Error("No active thread to handle interrupt");const De=pe?me??!0:!1;try{const ot={threadId:ze,checkpointId:j.lastCheckpointId??void 0,checkpointNs:j.lastCheckpointNs??void 0,command:{kind:"resume",value:De}};D(ot)}catch(ot){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${de}:`,ot),ot}},[j.lastCheckpointId,j.lastCheckpointNs,D]);b.useEffect(()=>{ke()},[ke]),b.useEffect(()=>{var de,pe;!o||!m||k||ee.current!==m&&(ee.current=m,n?(console.log("[ChatSessionProvider] Loading thread with checkpoint:",n),(de=q.current)==null||de.call(q,m,n)):(console.log("[ChatSessionProvider] Loading thread with latest checkpoint"),(pe=q.current)==null||pe.call(q,m)))},[o,m,k,n,r]),b.useEffect(()=>{a==null||a(m)},[m,a]);const et=b.useCallback(async(de,pe)=>{const me=V.current,ze=(de==null?void 0:de.text)??"";if(!me&&!ze)return;if(!me){await Z("New Chat");return}const{contentParts:De}=await Tg(c,(de==null?void 0:de.attachments)??[]),ot=[...De];ze!=null&&ze.trim()&&ot.push({type:"text",text:ze});const Et={id:`msg-${Date.now()}`,role:"user",content:ot,createdAt:new Date().toISOString()};O(Et);const st={threadId:me,payload:{messages:[Et]},checkpointId:(pe==null?void 0:pe.checkpointId)??j.lastCheckpointId??void 0,checkpointNs:(pe==null?void 0:pe.checkpointNs)??j.lastCheckpointNs??void 0};D(st)},[c,Z,O,j,D]),Nt=b.useMemo(()=>({threads:p,currentThreadId:m,setCurrentThreadId:x,isLoading:y,error:w,actions:{createThread:Z,deleteThread:fe,renameThread:Ie,refreshThreads:ke}}),[p,m,y,w,Z,fe,Ie,ke]),mt=b.useMemo(()=>({threadId:m,messages:j.messages,interrupt:null,checkpoint:{id:j.lastCheckpointId??null,namespace:j.lastCheckpointNs??null},checkpoints:M,metadata:null,isLoading:k,isHistoryLoading:z,isLoadingCheckpoint:X,error:C,hasMore:$,loadOlder:qe,clearState:Xe,navigateToCheckpoint:Ze,setCurrentCheckpointId:Ve,returnToLatest:Ke,loadThread:Fe,clearThread:Xe,respondToInterrupt:Qe}),[m,j,M,k,z,X,C,$,qe,Xe,Ze,Ve,Ke,Fe,Qe]),at=b.useMemo(()=>({isStreaming:te,error:se,connectionState:te?"connected":"idle",submit:et,send:et,stop:H,setAuthToken:ne}),[te,se,et,H,ne]);return u.jsx(uc.Provider,{value:Nt,children:u.jsx(dc.Provider,{value:mt,children:u.jsx(fc.Provider,{value:at,children:e})})})}function Oo(){const e=b.useContext(uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){const e=b.useContext(dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function pc(){const e=b.useContext(fc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Do({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c}){return u.jsx(Sg,{apiConfig:t,children:u.jsx(Zg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c,children:e})})}function Q(...e){return Yh.twMerge(Gh.clsx(e))}const Qg=xo.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"}}),nt=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yn.Slot:"button";return u.jsx(i,{className:Q(Qg({variant:t,size:n,className:e})),ref:s,...o})});nt.displayName="Button";const hc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:Q("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}));hc.displayName="Textarea";function mc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const m=i!==void 0,[x,y]=b.useState(e),g=(m?i:x)??"",[w,S]=b.useTransition(),k=b.useRef(null),T=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{m||(y(e??""),C.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const z=k.current;z&&(z.style.height="auto",z.style.height=`${z.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,g]);const j=b.useCallback((z,{fromUser:_})=>{m||y(z),_&&(a==null||a(z))},[m,a]),N=b.useCallback(async z=>{z&&z.preventDefault();const _=(g??"").trim();if(!_&&!h)return;const B=++T.current;C.current={id:B,shouldClear:!0},S(()=>{var L,M,J;try{const X=l(_);X&&typeof X.then=="function"?X.then(()=>{var he,Ne;((he=C.current)==null?void 0:he.id)===B&&C.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((Ne=C.current)==null?void 0:Ne.id)===B&&(C.current=null)}).catch(()=>{var he;((he=C.current)==null?void 0:he.id)===B&&(C.current=null)}):(((L=C.current)==null?void 0:L.id)===B&&C.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=C.current)==null?void 0:M.id)===B&&(C.current=null))}catch{((J=C.current)==null?void 0:J.id)===B&&(C.current=null)}})},[g,l,h,m,a]),A=b.useCallback(z=>{const _=z.target.value;j(_,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[j]),O=b.useCallback(z=>{z.key==="Enter"&&!z.shiftKey?(z.preventDefault(),N()):z.key==="Escape"&&t&&(z.preventDefault(),c==null||c())},[N,t,c]),R=`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))]":""} ${p}`;return u.jsx("form",{onSubmit:z=>void N(z),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(hc,{ref:k,value:g,onChange:A,onKeyDown:O,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(nt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(oe.Square,{size:16})}):u.jsx(nt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||w,children:u.jsx(oe.Send,{size:16})})})]})})}const ex=b.memo(mc);function ue(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 gc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=gc(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():gc(e[o],null)}}}}function Ue(...e){return v.useCallback(yi(...e),e)}function tx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function In(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:p,children:h,...m}=f,x=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(x.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var x;const h=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,m=v.useContext(h);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,nx(o,...t)]}function nx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var _t=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},rx=v[" useInsertionEffect ".trim().toString()]||_t;function xr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ox({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=sx(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function ox({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return rx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function sx(e){return typeof e=="function"}var ix=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Re=ix.reduce((e,t)=>{const n=Yn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xc(e,t){e&&yo.flushSync(()=>e.dispatchEvent(t))}function vi(e){const t=e+"CollectionProvider",[n,r]=In(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:y,children:g}=x,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:w,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Yn.createSlot(a),c=b.forwardRef((x,y)=>{const{scope:g,children:w}=x,S=s(a,g),k=Ue(y,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Yn.createSlot(d),h=b.forwardRef((x,y)=>{const{scope:g,children:w,...S}=x,k=b.useRef(null),T=Ue(y,k),C=s(d,g);return b.useEffect(()=>(C.itemMap.set(k,{ref:k,...S}),()=>void C.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:T,children:w})});h.displayName=d;function m(x){const y=s(e+"CollectionConsumer",x);return b.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},m,r]}var ax=v.createContext(void 0);function Lo(e){const t=v.useContext(ax);return e||t||"ltr"}function Rt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function lx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var cx="DismissableLayer",wi="dismissableLayer.update",ux="dismissableLayer.pointerDownOutside",dx="dismissableLayer.focusOutside",yc,vc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Fo=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(vc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),m=Ue(t,E=>f(E)),x=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=x.indexOf(y),w=d?x.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=g,T=hx(E=>{const j=E.target,N=[...c.branches].some(A=>A.contains(j));!k||N||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),C=mx(E=>{const j=E.target;[...c.branches].some(A=>A.contains(j))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return lx(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(yc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=yc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wc())},[d,c]),v.useEffect(()=>{const E=()=>h({});return document.addEventListener(wi,E),()=>document.removeEventListener(wi,E)},[]),u.jsx(Re.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:ue(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ue(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ue(e.onPointerDownCapture,T.onPointerDownCapture)})});Fo.displayName=cx;var fx="DismissableLayerBranch",px=v.forwardRef((e,t)=>{const n=v.useContext(vc),r=v.useRef(null),o=Ue(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Re.div,{...e,ref:o})});px.displayName=fx;function hx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){bc(ux,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function mx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&bc(dx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function wc(){const e=new CustomEvent(wi);document.dispatchEvent(e)}function bc(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?xc(o,s):o.dispatchEvent(s)}var bi=0;function Si(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sc()),document.body.insertAdjacentElement("beforeend",e[1]??Sc()),bi++,()=>{bi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),bi--}},[])}function Sc(){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 Ci="focusScope.autoFocusOnMount",Ti="focusScope.autoFocusOnUnmount",Cc={bubbles:!1,cancelable:!0},gx="FocusScope",$o=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Rt(o),d=Rt(s),f=v.useRef(null),p=Ue(t,x=>l(x)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let x=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:On(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||On(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const T of S)T.removedNodes.length>0&&On(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",y);const w=new MutationObserver(g);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",y),w.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){Ec.add(h);const x=document.activeElement;if(!a.contains(x)){const g=new CustomEvent(Ci,Cc);a.addEventListener(Ci,c),a.dispatchEvent(g),g.defaultPrevented||(xx(Sx(Tc(a)),{select:!0}),document.activeElement===x&&On(a))}return()=>{a.removeEventListener(Ci,c),setTimeout(()=>{const g=new CustomEvent(Ti,Cc);a.addEventListener(Ti,d),a.dispatchEvent(g),g.defaultPrevented||On(x??document.body,{select:!0}),a.removeEventListener(Ti,d),Ec.remove(h)},0)}}},[a,c,d,h]);const m=v.useCallback(x=>{if(!n&&!r||h.paused)return;const y=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,g=document.activeElement;if(y&&g){const w=x.currentTarget,[S,k]=yx(w);S&&k?!x.shiftKey&&g===k?(x.preventDefault(),n&&On(S,{select:!0})):x.shiftKey&&g===S&&(x.preventDefault(),n&&On(k,{select:!0})):g===w&&x.preventDefault()}},[n,r,h.paused]);return u.jsx(Re.div,{tabIndex:-1,...i,ref:p,onKeyDown:m})});$o.displayName=gx;function xx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(On(r,{select:t}),document.activeElement!==n)return}function yx(e){const t=Tc(e),n=kc(t,e),r=kc(t.reverse(),e);return[n,r]}function Tc(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 kc(e,t){for(const n of e)if(!vx(n,{upTo:t}))return n}function vx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function wx(e){return e instanceof HTMLInputElement&&"select"in e}function On(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var Ec=bx();function bx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Ic(e,t),e.unshift(t)},remove(t){var n;e=Ic(e,t),(n=e[0])==null||n.resume()}}}function Ic(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Sx(e){return e.filter(t=>t.tagName!=="A")}var Cx=v[" useId ".trim().toString()]||(()=>{}),Tx=0;function Nn(e){const[t,n]=v.useState(Cx());return _t(()=>{n(r=>r??String(Tx++))},[e]),t?`radix-${t}`:""}const kx=["top","right","bottom","left"],Mn=Math.min,Gt=Math.max,zo=Math.round,Bo=Math.floor,xn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ix={start:"end",end:"start"};function ki(e,t,n){return Gt(e,Mn(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function jn(e){return e.split("-")[0]}function yr(e){return e.split("-")[1]}function Ei(e){return e==="x"?"y":"x"}function Ii(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function yn(e){return Nx.has(jn(e))?"y":"x"}function Ni(e){return Ei(yn(e))}function Ax(e,t,n){n===void 0&&(n=!1);const r=yr(e),o=Ni(e),s=Ii(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ho(i)),[i,Ho(i)]}function jx(e){const t=Ho(e);return[Ai(e),t,Ai(t)]}function Ai(e){return e.replace(/start|end/g,t=>Ix[t])}const Nc=["left","right"],Ac=["right","left"],_x=["top","bottom"],Rx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Ac:Nc:t?Nc:Ac;case"left":case"right":return t?_x:Rx;default:return[]}}function Ox(e,t,n,r){const o=yr(e);let s=Px(jn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ai)))),s}function Ho(e){return e.replace(/left|right|bottom|top/g,t=>Ex[t])}function Mx(e){return{top:0,right:0,bottom:0,left:0,...e}}function jc(e){return typeof e!="number"?Mx(e):{top:e,right:e,bottom:e,left:e}}function Uo(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 _c(e,t,n){let{reference:r,floating:o}=e;const s=yn(t),i=Ni(t),a=Ii(i),l=jn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(yr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Dx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=_c(c,r,l),p=r,h={},m=0;for(let x=0;x<a.length;x++){const{name:y,fn:g}=a[x],{x:w,y:S,data:k,reset:T}=await g({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,h={...h,[y]:{...h[y],...k}},T&&m<=50&&(m++,typeof T=="object"&&(T.placement&&(p=T.placement),T.rects&&(c=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=_c(c,p,l)),x=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Br(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=An(t,e),m=jc(h),y=a[p?f==="floating"?"reference":"floating":f],g=Uo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},T=Uo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(g.top-T.top+m.top)/k.y,bottom:(T.bottom-g.bottom+m.bottom)/k.y,left:(g.left-T.left+m.left)/k.x,right:(T.right-g.right+m.right)/k.x}}const Lx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const f=jc(d),p={x:n,y:r},h=Ni(o),m=Ii(h),x=await i.getDimensions(c),y=h==="y",g=y?"top":"left",w=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[h]-p[h]-s.floating[m],T=p[h]-s.reference[h],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[m]);const j=k/2-T/2,N=E/2-x[m]/2-1,A=Mn(f[g],N),O=Mn(f[w],N),F=A,$=E-x[m]-O,R=E/2-x[m]/2+j,z=ki(F,R,$),_=!l.arrow&&yr(o)!=null&&R!==z&&s.reference[m]/2-(R<F?A:O)-x[m]/2<0,B=_?R<F?R-F:R-$:0;return{[h]:p[h]+B,data:{[h]:z,centerOffset:R-z-B,..._&&{alignmentOffset:B}},reset:_}}}),Fx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:x=!0,...y}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=jn(o),w=yn(a),S=jn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),T=p||(S||!x?[Ho(a)]:jx(a)),C=m!=="none";!p&&C&&T.push(...Ox(a,x,m,k));const E=[a,...T],j=await Br(t,y),N=[];let A=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&N.push(j[g]),f){const R=Ax(o,i,k);N.push(j[R[0]],j[R[1]])}if(A=[...A,{placement:o,overflows:N}],!N.every(R=>R<=0)){var O,F;const R=(((O=s.flip)==null?void 0:O.index)||0)+1,z=E[R];if(z&&(!(f==="alignment"?w!==yn(z):!1)||A.every(L=>yn(L.placement)===w?L.overflows[0]>0:!0)))return{data:{index:R,overflows:A},reset:{placement:z}};let _=(F=A.filter(B=>B.overflows[0]<=0).sort((B,L)=>B.overflows[1]-L.overflows[1])[0])==null?void 0:F.placement;if(!_)switch(h){case"bestFit":{var $;const B=($=A.filter(L=>{if(C){const M=yn(L.placement);return M===w||M==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(M=>M>0).reduce((M,J)=>M+J,0)]).sort((L,M)=>L[1]-M[1])[0])==null?void 0:$[0];B&&(_=B);break}case"initialPlacement":_=a;break}if(o!==_)return{reset:{placement:_}}}return{}}}};function Rc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pc(e){return kx.some(t=>e[t]>=0)}const $x=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=An(e,t);switch(r){case"referenceHidden":{const s=await Br(t,{...o,elementContext:"reference"}),i=Rc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pc(i)}}}case"escaped":{const s=await Br(t,{...o,altBoundary:!0}),i=Rc(s,n.floating);return{data:{escapedOffsets:i,escaped:Pc(i)}}}default:return{}}}}},Oc=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=jn(n),a=yr(n),l=yn(n)==="y",c=Oc.has(i)?-1:1,d=s&&l?-1:1,f=An(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(h=a==="end"?m*-1:m),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Bx=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 zx(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}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:g,y:w}=y;return{x:g,y:w}}},...l}=An(e,t),c={x:n,y:r},d=await Br(t,l),f=yn(jn(o)),p=Ei(f);let h=c[p],m=c[f];if(s){const y=p==="y"?"top":"left",g=p==="y"?"bottom":"right",w=h+d[y],S=h-d[g];h=ki(w,h,S)}if(i){const y=f==="y"?"top":"left",g=f==="y"?"bottom":"right",w=m+d[y],S=m-d[g];m=ki(w,m,S)}const x=a.fn({...t,[p]:h,[f]:m});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[p]:s,[f]:i}}}}}},Ux=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=An(e,t),d={x:n,y:r},f=yn(o),p=Ei(f);let h=d[p],m=d[f];const x=An(a,t),y=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,T=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>T&&(h=T)}if(c){var g,w;const S=p==="y"?"width":"height",k=Oc.has(jn(o)),T=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:y.crossAxis),C=s.reference[f]+s.reference[S]+(k?0:((w=i.offset)==null?void 0:w[f])||0)-(k?y.crossAxis:0);m<T?m=T:m>C&&(m=C)}return{[p]:h,[f]:m}}}},Wx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=An(e,t),d=await Br(t,c),f=jn(o),p=yr(o),h=yn(o)==="y",{width:m,height:x}=s.floating;let y,g;f==="top"||f==="bottom"?(y=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,y=p==="end"?"top":"bottom");const w=x-d.top-d.bottom,S=m-d.left-d.right,k=Mn(x-d[y],w),T=Mn(m-d[g],S),C=!t.middlewareData.shift;let E=k,j=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),C&&!p){const A=Gt(d.left,0),O=Gt(d.right,0),F=Gt(d.top,0),$=Gt(d.bottom,0);h?j=m-2*(A!==0||O!==0?A+O:Gt(d.left,d.right)):E=x-2*(F!==0||$!==0?F+$:Gt(d.top,d.bottom))}await l({...t,availableWidth:j,availableHeight:E});const N=await i.getDimensions(a.floating);return m!==N.width||x!==N.height?{reset:{rects:!0}}:{}}}};function Wo(){return typeof window<"u"}function vr(e){return Mc(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function vn(e){var t;return(t=(Mc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Mc(e){return Wo()?e instanceof Node||e instanceof Yt(e).Node:!1}function un(e){return Wo()?e instanceof Element||e instanceof Yt(e).Element:!1}function wn(e){return Wo()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function Dc(e){return!Wo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const Vx=new Set(["inline","contents"]);function Hr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Vx.has(o)}const Kx=new Set(["table","td","th"]);function qx(e){return Kx.has(vr(e))}const Gx=[":popover-open",":modal"];function Vo(e){return Gx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Yx=["transform","translate","scale","rotate","perspective"],Xx=["transform","translate","scale","rotate","perspective","filter"],Jx=["paint","layout","strict","content"];function ji(e){const t=_i(),n=un(e)?dn(e):e;return Yx.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)||Xx.some(r=>(n.willChange||"").includes(r))||Jx.some(r=>(n.contain||"").includes(r))}function Zx(e){let t=Dn(e);for(;wn(t)&&!wr(t);){if(ji(t))return t;if(Vo(t))return null;t=Dn(t)}return null}function _i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Qx=new Set(["html","body","#document"]);function wr(e){return Qx.has(vr(e))}function dn(e){return Yt(e).getComputedStyle(e)}function Ko(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Dn(e){if(vr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Dc(e)&&e.host||vn(e);return Dc(t)?t.host:t}function Lc(e){const t=Dn(e);return wr(t)?e.ownerDocument?e.ownerDocument.body:e.body:wn(t)&&Hr(t)?t:Lc(t)}function Ur(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Lc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Ri(i);return t.concat(i,i.visualViewport||[],Hr(o)?o:[],a&&n?Ur(a):[])}return t.concat(o,Ur(o,[],n))}function Ri(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Fc(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=wn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=zo(n)!==s||zo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Pi(e){return un(e)?e:e.contextElement}function br(e){const t=Pi(e);if(!wn(t))return xn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Fc(t);let i=(s?zo(n.width):n.width)/r,a=(s?zo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ey=xn(0);function $c(e){const t=Yt(e);return!_i()||!t.visualViewport?ey:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ty(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function Qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Pi(e);let i=xn(1);t&&(r?un(r)&&(i=br(r)):i=br(e));const a=ty(s,n,r)?$c(s):xn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Yt(s),h=r&&un(r)?Yt(r):r;let m=p,x=Ri(m);for(;x&&r&&h!==m;){const y=br(x),g=x.getBoundingClientRect(),w=dn(x),S=g.left+(x.clientLeft+parseFloat(w.paddingLeft))*y.x,k=g.top+(x.clientTop+parseFloat(w.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,m=Yt(x),x=Ri(m)}}return Uo({width:d,height:f,x:l,y:c})}function qo(e,t){const n=Ko(e).scrollLeft;return t?t.left+n:Qn(vn(e)).left+n}function zc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-qo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=vn(r),a=t?Vo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=xn(1);const d=xn(0),f=wn(r);if((f||!f&&!s)&&((vr(r)!=="body"||Hr(i))&&(l=Ko(r)),wn(r))){const h=Qn(r);c=br(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?zc(i,l):xn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function ry(e){return Array.from(e.getClientRects())}function oy(e){const t=vn(e),n=Ko(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+qo(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Bc=25;function sy(e,t){const n=Yt(e),r=vn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=_i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=qo(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-h);m<=Bc&&(s-=m)}else c<=Bc&&(s+=c);return{width:s,height:i,x:a,y:l}}const iy=new Set(["absolute","fixed"]);function ay(e,t){const n=Qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=wn(e)?br(e):xn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Hc(e,t,n){let r;if(t==="viewport")r=sy(e,n);else if(t==="document")r=oy(vn(e));else if(un(t))r=ay(t,n);else{const o=$c(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Uo(r)}function Uc(e,t){const n=Dn(e);return n===t||!un(n)||wr(n)?!1:dn(n).position==="fixed"||Uc(n,t)}function ly(e,t){const n=t.get(e);if(n)return n;let r=Ur(e,[],!1).filter(a=>un(a)&&vr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Dn(e):e;for(;un(i)&&!wr(i);){const a=dn(i),l=ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&iy.has(o.position)||Hr(i)&&!l&&Uc(e,i))?r=r.filter(d=>d!==i):o=a,i=Dn(i)}return t.set(e,r),r}function cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Vo(t)?[]:ly(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Hc(t,d,o);return c.top=Gt(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Gt(f.left,c.left),c},Hc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function uy(e){const{width:t,height:n}=Fc(e);return{width:t,height:n}}function dy(e,t,n){const r=wn(t),o=vn(t),s=n==="fixed",i=Qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=xn(0);function c(){l.x=qo(o)}if(r||!r&&!s)if((vr(t)!=="body"||Hr(o))&&(a=Ko(t)),r){const h=Qn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?zc(o,a):xn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function Oi(e){return dn(e).position==="static"}function Wc(e,t){if(!wn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return vn(e)===n&&(n=n.ownerDocument.body),n}function Vc(e,t){const n=Yt(e);if(Vo(e))return n;if(!wn(e)){let o=Dn(e);for(;o&&!wr(o);){if(un(o)&&!Oi(o))return o;o=Dn(o)}return n}let r=Wc(e,t);for(;r&&qx(r)&&Oi(r);)r=Wc(r,t);return r&&wr(r)&&Oi(r)&&!ji(r)?n:r||Zx(e)||n}const fy=async function(e){const t=this.getOffsetParent||Vc,n=this.getDimensions,r=await n(e.floating);return{reference:dy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function py(e){return dn(e).direction==="rtl"}const hy={convertOffsetParentRelativeRectToViewportRelativeRect:ny,getDocumentElement:vn,getClippingRect:cy,getOffsetParent:Vc,getElementRects:fy,getClientRects:ry,getDimensions:uy,getScale:br,isElement:un,isRTL:py};function Kc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function my(e,t){let n=null,r;const o=vn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const m=Bo(f),x=Bo(o.clientWidth-(d+p)),y=Bo(o.clientHeight-(f+h)),g=Bo(d),S={rootMargin:-m+"px "+-x+"px "+-y+"px "+-g+"px",threshold:Gt(0,Mn(1,l))||1};let k=!0;function T(C){const E=C[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Kc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(T,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,S)}n.observe(e)}return i(!0),s}function gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Pi(e),d=o||s?[...c?Ur(c):[],...Ur(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?my(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(g=>{let[w]=g;w&&w.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let m,x=l?Qn(e):null;l&&y();function y(){const g=Qn(e);x&&!Kc(x,g)&&n(),x=g,m=requestAnimationFrame(y)}return n(),()=>{var g;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(g=h)==null||g.disconnect(),h=null,l&&cancelAnimationFrame(m)}}const xy=Bx,yy=Hx,vy=Fx,wy=Wx,by=$x,qc=Lx,Sy=Ux,Cy=(e,t,n)=>{const r=new Map,o={platform:hy,...n},s={...o.platform,_c:r};return Dx(e,t,{...o,platform:s})};var Ty=typeof document<"u",ky=function(){},Go=Ty?b.useLayoutEffect:ky;function Yo(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(!Yo(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)&&!Yo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Gc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yc(e,t){const n=Gc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Go(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Yo(p,r)||h(r);const[m,x]=v.useState(null),[y,g]=v.useState(null),w=v.useCallback(L=>{L!==C.current&&(C.current=L,x(L))},[]),S=v.useCallback(L=>{L!==E.current&&(E.current=L,g(L))},[]),k=s||m,T=i||y,C=v.useRef(null),E=v.useRef(null),j=v.useRef(d),N=l!=null,A=Mi(l),O=Mi(o),F=Mi(c),$=v.useCallback(()=>{if(!C.current||!E.current)return;const L={placement:t,strategy:n,middleware:p};O.current&&(L.platform=O.current),Cy(C.current,E.current,L).then(M=>{const J={...M,isPositioned:F.current!==!1};R.current&&!Yo(j.current,J)&&(j.current=J,yo.flushSync(()=>{f(J)}))})},[p,t,n,O,F]);Go(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[c]);const R=v.useRef(!1);Go(()=>(R.current=!0,()=>{R.current=!1}),[]),Go(()=>{if(k&&(C.current=k),T&&(E.current=T),k&&T){if(A.current)return A.current(k,T,$);$()}},[k,T,$,A,N]);const z=v.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),_=v.useMemo(()=>({reference:k,floating:T}),[k,T]),B=v.useMemo(()=>{const L={position:n,left:0,top:0};if(!_.floating)return L;const M=Yc(_.floating,d.x),J=Yc(_.floating,d.y);return a?{...L,transform:"translate("+M+"px, "+J+"px)",...Gc(_.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:J}},[n,a,_.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:$,refs:z,elements:_,floatingStyles:B}),[d,$,z,_,B])}const Iy=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?qc({element:r.current,padding:o}).fn(n):{}:r?qc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...xy(e),options:[e,t]}),Ay=(e,t)=>({...yy(e),options:[e,t]}),jy=(e,t)=>({...Sy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),Ry=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...by(e),options:[e,t]}),Oy=(e,t)=>({...Iy(e),options:[e,t]});var My="Arrow",Xc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Re.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Xc.displayName=My;var Dy=Xc;function Jc(e){const[t,n]=v.useState(void 0);return _t(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Di="Popper",[Zc,Xo]=In(Di),[Ly,Qc]=Zc(Di),eu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(Ly,{scope:t,anchor:r,onAnchorChange:o,children:n})};eu.displayName=Di;var tu="PopperAnchor",nu=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Qc(tu,n),i=v.useRef(null),a=Ue(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Re.div,{...o,ref:a})});nu.displayName=tu;var Li="PopperContent",[Fy,$y]=Zc(Li),ru=v.forwardRef((e,t)=>{var q,D,H,te,se,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:m,...x}=e,y=Qc(Li,n),[g,w]=v.useState(null),S=Ue(t,ke=>w(ke)),[k,T]=v.useState(null),C=Jc(k),E=(C==null?void 0:C.width)??0,j=(C==null?void 0:C.height)??0,N=r+(s!=="center"?"-"+s:""),A=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},O=Array.isArray(c)?c:[c],F=O.length>0,$={padding:A,boundary:O.filter(By),altBoundary:F},{refs:R,floatingStyles:z,placement:_,isPositioned:B,middlewareData:L}=Ey({strategy:"fixed",placement:N,whileElementsMounted:(...ke)=>gy(...ke,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Ny({mainAxis:o+j,alignmentAxis:i}),l&&Ay({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...$}),l&&_y({...$}),Ry({...$,apply:({elements:ke,rects:Z,availableWidth:fe,availableHeight:Ie})=>{const{width:Ae,height:Fe}=Z.reference,Ze=ke.floating.style;Ze.setProperty("--radix-popper-available-width",`${fe}px`),Ze.setProperty("--radix-popper-available-height",`${Ie}px`),Ze.setProperty("--radix-popper-anchor-width",`${Ae}px`),Ze.setProperty("--radix-popper-anchor-height",`${Fe}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:E,arrowHeight:j}),p&&Py({strategy:"referenceHidden",...$})]}),[M,J]=iu(_),X=Rt(m);_t(()=>{B&&(X==null||X())},[B,X]);const he=(q=L.arrow)==null?void 0:q.x,Ne=(D=L.arrow)==null?void 0:D.y,_e=((H=L.arrow)==null?void 0:H.centerOffset)!==0,[V,ee]=v.useState();return _t(()=>{g&&ee(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:B?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:V,"--radix-popper-transform-origin":[(te=L.transformOrigin)==null?void 0:te.x,(se=L.transformOrigin)==null?void 0:se.y].join(" "),...((ne=L.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Fy,{scope:n,placedSide:M,onArrowChange:T,arrowX:he,arrowY:Ne,shouldHideArrow:_e,children:u.jsx(Re.div,{"data-side":M,"data-align":J,...x,ref:S,style:{...x.style,animation:B?void 0:"none"}})})})});ru.displayName=Li;var ou="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},su=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=$y(ou,r),i=zy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Dy,{...o,ref:n,style:{...o.style,display:"block"}})})});su.displayName=ou;function By(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var y,g,w;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=iu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,h=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",x="";return c==="bottom"?(m=i?f:`${p}px`,x=`${-l}px`):c==="top"?(m=i?f:`${p}px`,x=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,x=i?f:`${h}px`):c==="left"&&(m=`${r.floating.width+l}px`,x=i?f:`${h}px`),{data:{x:m,y:x}}}});function iu(e){const[t,n="center"]=e.split("-");return[t,n]}var au=eu,lu=nu,cu=ru,uu=su,Uy="Portal",Jo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);_t(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Js.createPortal(u.jsx(Re.div,{...r,ref:t}),i):null});Jo.displayName=Uy;function Wy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var tn=e=>{const{present:t,children:n}=e,r=Vy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Ue(r.ref,Ky(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};tn.displayName="Presence";function Vy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Zo(r.current);s.current=a==="mounted"?c:"none"},[a]),_t(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Zo(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),_t(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const x=Zo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&x&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Zo(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Zo(e){return(e==null?void 0:e.animationName)||"none"}function Ky(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 Fi="rovingFocusGroup.onEntryFocus",qy={bubbles:!1,cancelable:!0},Wr="RovingFocusGroup",[$i,du,Gy]=vi(Wr),[Yy,fu]=In(Wr,[Gy]),[Xy,Jy]=Yy(Wr),pu=v.forwardRef((e,t)=>u.jsx($i.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx($i.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Zy,{...e,ref:t})})}));pu.displayName=Wr;var Zy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Ue(t,p),m=Lo(s),[x,y]=xr({prop:i,defaultProp:a??null,onChange:l,caller:Wr}),[g,w]=v.useState(!1),S=Rt(c),k=du(n),T=v.useRef(!1),[C,E]=v.useState(0);return v.useEffect(()=>{const j=p.current;if(j)return j.addEventListener(Fi,S),()=>j.removeEventListener(Fi,S)},[S]),u.jsx(Xy,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:x,onItemFocus:v.useCallback(j=>y(j),[y]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>E(j=>j-1),[]),children:u.jsx(Re.div,{tabIndex:g||C===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:ue(e.onMouseDown,()=>{T.current=!0}),onFocus:ue(e.onFocus,j=>{const N=!T.current;if(j.target===j.currentTarget&&N&&!g){const A=new CustomEvent(Fi,qy);if(j.currentTarget.dispatchEvent(A),!A.defaultPrevented){const O=k().filter(_=>_.focusable),F=O.find(_=>_.active),$=O.find(_=>_.id===x),z=[F,$,...O].filter(Boolean).map(_=>_.ref.current);gu(z,d)}}T.current=!1}),onBlur:ue(e.onBlur,()=>w(!1))})})}),hu="RovingFocusGroupItem",mu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Nn(),c=s||l,d=Jy(hu,n),f=d.currentTabStopId===c,p=du(n),{onFocusableItemAdd:h,onFocusableItemRemove:m,currentTabStopId:x}=d;return v.useEffect(()=>{if(r)return h(),()=>m()},[r,h,m]),u.jsx($i.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Re.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ue(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:ue(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ue(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=tv(y,d.orientation,d.dir);if(g!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?nv(S,k+1):S.slice(k+1)}setTimeout(()=>gu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});mu.displayName=hu;var Qy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ev(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function tv(e,t,n){const r=ev(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Qy[r]}function gu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function nv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rv=pu,ov=mu,sv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Sr=new WeakMap,Qo=new WeakMap,es={},zi=0,xu=function(e){return e&&(e.host||xu(e.parentNode))},iv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=xu(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},av=function(e,t,n,r){var o=iv(t,Array.isArray(e)?e:[e]);es[n]||(es[n]=new WeakMap);var s=es[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),m=h!==null&&h!=="false",x=(Sr.get(p)||0)+1,y=(s.get(p)||0)+1;Sr.set(p,x),s.set(p,y),i.push(p),x===1&&m&&Qo.set(p,!0),y===1&&p.setAttribute(n,"true"),m||p.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",p,g)}})};return d(t),a.clear(),zi++,function(){i.forEach(function(f){var p=Sr.get(f)-1,h=s.get(f)-1;Sr.set(f,p),s.set(f,h),p||(Qo.has(f)||f.removeAttribute(r),Qo.delete(f)),h||f.removeAttribute(n)}),zi--,zi||(Sr=new WeakMap,Sr=new WeakMap,Qo=new WeakMap,es={})}},Bi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=sv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),av(r,o,n,"aria-hidden")):function(){return null}},bn=function(){return bn=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},bn.apply(this,arguments)};function yu(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 lv(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 ts="right-scroll-bar-position",ns="width-before-scroll-bar",cv="with-scroll-bars-hidden",uv="--removed-body-scroll-bar-size";function Hi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function dv(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var fv=typeof window<"u"?v.useLayoutEffect:v.useEffect,vu=new WeakMap;function pv(e,t){var n=dv(null,function(r){return e.forEach(function(o){return Hi(o,r)})});return fv(function(){var r=vu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Hi(a,null)}),s.forEach(function(a){o.has(a)||Hi(a,i)})}vu.set(n,e)},[e]),n}function hv(e){return e}function mv(e,t){t===void 0&&(t=hv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function gv(e){e===void 0&&(e={});var t=mv(null);return t.options=bn({async:!0,ssr:!1},e),t}var wu=function(e){var t=e.sideCar,n=yu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,bn({},n))};wu.isSideCarExport=!0;function xv(e,t){return e.useMedium(t),wu}var bu=gv(),Ui=function(){},rs=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Ui,onWheelCapture:Ui,onTouchMoveCapture:Ui}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,m=e.noIsolation,x=e.inert,y=e.allowPinchZoom,g=e.as,w=g===void 0?"div":g,S=e.gapMode,k=yu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=p,C=pv([n,t]),E=bn(bn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(T,{sideCar:bu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:m,inert:x,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),bn(bn({},E),{ref:C})):v.createElement(w,bn({},E,{className:l,ref:C}),a))});rs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},rs.classNames={fullWidth:ns,zeroRight:ts};var yv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function vv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function bv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Sv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=vv())&&(wv(t,n),bv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Cv=function(){var e=Sv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Su=function(){var e=Cv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Tv={left:0,top:0,right:0,gap:0},Wi=function(e){return parseInt(e||"",10)||0},kv=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[Wi(n),Wi(r),Wi(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Tv;var t=kv(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])}},Iv=Su(),Cr="data-scroll-locked",Nv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
37
|
+
`))>=0;){const ft=mt.slice(0,ye);mt=mt.slice(ye+2);const gt=Xg(ft);if(!gt)continue;let St;try{St=JSON.parse(gt)}catch{console.debug("[use-chat] malformed SSE:",gt.slice(0,200));continue}const Oe=Yg(St)?St.data:St;De=Date.now();const Kt=Oe.seq;if(Kt!==void 0){if(Kt<=de){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Kt,lastProcessedSeq:de,type:Oe.type});continue}de>0&&Kt>de+1&&((D=_==null?void 0:_.onGap)==null||D.call(_,{from:de,to:Kt})),de=Kt,T.current=Kt,y(Kt)}if(console.debug("[use-chat] received event",{seq:Oe.seq,type:Oe.type,preview:(()=>{var lt;try{return Oe.type==="message_delta"?{deltaTypes:(lt=Oe.delta)==null?void 0:lt.map(Ct=>Ct.type),textLen:(Oe.delta||[]).filter(Ct=>Ct.type==="text").map(Ct=>String(Ct.text||"").length)}:Oe.content||Oe.delta?{hasContent:!0}:{}}catch(Ct){return{err:String(Ct)}}})()}),Oe.type==="checkpoint")E.current=Oe.checkpointId??null,j.current=Oe.checkpointNs??null,m(Oe.checkpointId??null);else if(Oe.type==="state_history"){N.current=Oe;try{const Ct=$r(Oe).latest;Ct&&(E.current=Ct.checkpointId??null,j.current=Ct.checkpointNs??null,m(Ct.checkpointId??null))}catch(lt){console.warn("[use-chat] Failed to hydrate state_history payload",lt)}}try{z==null||z(Oe)}catch(lt){console.error("[use-chat] Error in onEvent callback:",lt,"for event:",Oe.type)}if(Oe.type==="token"&&e.autoAppendAssistant!==!1)at.push(Oe.content),ze();else if(Oe.type==="message_delta"){const lt=Oe.delta.filter(Ct=>Ct.type==="text").map(Ct=>Ct.text).join("");lt&&e.autoAppendAssistant!==!1&&(at.push(lt),ze())}else if(Oe.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(H=_==null?void 0:_.onHeartbeat)==null||H.call(_,Oe)}catch(lt){console.warn("[use-chat] heartbeat callback failed",lt)}}else if(pe!==null&&cancelAnimationFrame(pe),me(),Oe.type==="checkpoint")m(Oe.checkpointId);else if(Oe.type==="error"){const lt=Oe;if(d(lt.message),L="error",M=lt.message,lt.error_type==="auth_error"||lt.code==="TOKEN_EXPIRED"||((te=lt.message)==null?void 0:te.includes("token"))||((se=lt.message)==null?void 0:se.includes("401"))||((ne=lt.message)==null?void 0:ne.includes("unauthorized"))||((ke=lt.message)==null?void 0:ke.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",lt.message);try{(Q=_==null?void 0:_.onAuthError)==null||Q.call(_,lt.message)}catch(Kn){console.warn("[use-chat] onAuthError handler failed",Kn)}B.abort()}}}}me(),L===null&&!B.signal.aborted&&(L="complete")}catch(st){if(st.name==="AbortError")L=L??"aborted";else{const Be=st.message||String(st);L="error",M=Be,d(Be),(fe=_==null?void 0:_.onError)==null||fe.call(_,Be)}}finally{try{await et.cancel()}catch{}finally{(Ie=et.releaseLock)==null||Ie.call(et)}pe!==null&&typeof window<"u"&&window.cancelAnimationFrame(pe),clearInterval(ot)}}catch(Ve){if(Ve.name==="AbortError")L=L??"aborted";else{const Ke=Ve.message||String(Ve);L="error",M=Ke,d(Ke),(Ae=_==null?void 0:_.onError)==null||Ae.call(_,Ke),J||((Fe=_==null?void 0:_.onConnectionError)==null||Fe.call(_,Ke),J=!0)}}finally{const Ve=T.current,Ke=E.current,qe=j.current,Xe=N.current,Qe=L??(B.signal.aborted?"aborted":M?"error":"complete");try{(Ze=_==null?void 0:_.onClosed)==null||Ze.call(_,{reason:Qe,lastSeq:Ve,lastCheckpointId:Ke,lastCheckpointNs:qe,lastStateHistory:Xe,error:M})}catch(et){console.warn("[use-chat] onClosed callback failed",et)}l(!1),w(!1),S.current=null,T.current=0,y(0),C.current=null}})(),{close:()=>B.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var R;k.current=!1,(R=S.current)==null||R.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:x,connected:g,stream:$,stop:F,clear:O,setToken:A}}function Yg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Xg(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
|
|
38
|
+
`)}const cc=200;function Jg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),p=b.useRef(null),h=b.useCallback(N=>{try{const A=globalThis.structuredClone;if(typeof A=="function")return A(N)}catch{}try{return JSON.parse(JSON.stringify(N))}catch{return N}},[]),m=b.useCallback((N,A)=>{if(!N)return;const O=f.current.get(N)??[],F=h(A),$=O.length>=cc?[...O.slice(O.length-cc+1),F]:[...O,F];f.current.set(N,$)},[h]),x=b.useCallback(N=>{N&&f.current.set(N,[])},[]),y=b.useCallback(N=>{const A=N??d.current;if(!A)return;const O=f.current.get(A);O!=null&&O.length&&O.forEach(F=>{try{n(F)}catch($){console.error("[useChatStreamingService] Failed to replay buffered event",$)}})},[n]),g=b.useCallback(N=>{var F,$,R,z,_;const A=N.seq??null;if(A!==null){const B=c.current;if(B!==null){if(A<=B)return;A>B+1&&(o==null||o({from:B,to:A}))}c.current=A}if(N.type==="thread_info"){d.current=N.threadId,p.current&&(p.current.threadIdGuess=N.threadId),x(N.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",N);try{t(N)}catch(B){console.error("[useChatStreamingService] Error in onThreadInfo handler:",B)}return}if(N.type==="heartbeat"){try{l==null||l(N)}catch(B){console.error("[useChatStreamingService] Error in onHeartbeat handler:",B)}return}if(N.type==="error"){const B=N;if(B.error_type==="auth_error"||B.code==="TOKEN_EXPIRED"||((F=B.message)==null?void 0:F.includes("token"))||(($=B.message)==null?void 0:$.includes("401"))||((R=B.message)==null?void 0:R.includes("unauthorized"))||((z=B.message)==null?void 0:z.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",B.message);try{a==null||a(B.message)}catch(M){console.warn("[useChatStreamingService] onAuthError handler failed",M)}}}const O=N.threadId??(N.type==="state_history"?N.threadId:void 0)??d.current??((_=p.current)==null?void 0:_.threadIdGuess)??null;if(N.type==="state_history"&&(d.current=O??d.current),Hg(N)){N.type==="checkpoint"||N.type==="state_history"?x(O??null):m(O??null,N);try{n(N)}catch(B){console.error("[useChatStreamingService] Error in onMessageEvent handler:",B)}return}try{r==null||r(N)}catch(B){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",B)}},[m,x,n,o,t,r]),{stream:w,stop:S,isStreaming:k,error:T,setToken:C}=lc({baseUrl:e,token:void 0}),E=b.useCallback((N,A)=>{c.current=null,d.current=N.threadId??null,p.current={request:N,callbacks:A,manualStop:!1,threadIdGuess:N.threadId??null},w(N,g,{onOpen:A==null?void 0:A.onOpen,onError:O=>{var F;(F=A==null?void 0:A.onError)==null||F.call(A,O)},onGap:(A==null?void 0:A.onGap)??o,onConnectionError:O=>{var F;i==null||i(O),(F=A==null?void 0:A.onConnectionError)==null||F.call(A,O)},onAuthError:O=>{var F;a==null||a(O),(F=A==null?void 0:A.onAuthError)==null||F.call(A,O)},onHeartbeat:O=>{var F;try{l==null||l(O)}catch($){console.warn("[useChatStreamingService] onHeartbeat handler failed",$)}try{(F=A==null?void 0:A.onHeartbeat)==null||F.call(A,O)}catch($){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",$)}},onClosed:O=>{var z,_,B,L;const F=((z=p.current)==null?void 0:z.manualStop)??!1,$=d.current??((_=p.current)==null?void 0:_.threadIdGuess)??((B=O.lastStateHistory)==null?void 0:B.threadId)??null;(O.reason==="complete"||O.reason==="aborted"&&F)&&x($);const R={...O,threadId:$,manualStop:F};try{s==null||s(R)}catch(M){console.warn("[useChatStreamingService] onStreamClosed handler failed",M)}try{(L=A==null?void 0:A.onClosed)==null||L.call(A,R)}catch(M){console.warn("[useChatStreamingService] downstream onClosed handler failed",M)}p.current&&(p.current=null)}})},[x,g,a,i,l,o,s,w]),j=b.useCallback(()=>{p.current&&(p.current.manualStop=!0),S()},[S]);return b.useMemo(()=>({startStream:E,stop:j,isStreaming:k,error:T,setAuthToken:C,replayBufferedEvents:y}),[E,j,k,T,C,y])}const uc=b.createContext(null),dc=b.createContext(null),fc=b.createContext(null);b.createContext(!1);function Zg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,checkpointMetadataCache:l}){const{api:c,baseUrl:d}=fi(),f=b.useMemo(()=>En(d),[d]),[p,h]=b.useState([]),[m,x]=b.useState(t),[y,g]=b.useState(!1),[w,S]=b.useState(null),[k,T]=b.useState(!1),[C,E]=b.useState(null),{state:j,seed:N,prepend:A,pushUser:O,onEvent:F}=ec(),[$,R]=b.useState(!1),[z,_]=b.useState(!1),[B,L]=b.useState(null),[M,J]=b.useState([]),[X,he]=b.useState(!1),Ne=l??Bg(),{setCacheForThread:_e}=Ne,V=b.useRef(m),ee=b.useRef(null);b.useEffect(()=>{V.current=m},[m]);const q=b.useRef(),{startStream:D,stop:H,isStreaming:te,error:se,setAuthToken:ne}=Jg({baseUrl:f,onThreadInfo:de=>{console.log("[ChatSessionProvider] Thread info:",de.threadId),V.current!==de.threadId&&x(de.threadId)},onMessageEvent:F,onUnhandledEvent:de=>{console.warn("[ChatSessionProvider] Unhandled event:",de.type)},onAuthError:i}),ke=b.useCallback(async()=>{g(!0),S(null);try{const de=await c.listThreads();h(de??[])}catch(de){const pe=String(de);S(pe),s==null||s(pe)}finally{g(!1)}},[c,s]),Q=b.useCallback(async de=>{try{const pe=await c.createThread(de);return x(pe.threadId),await ke(),pe.threadId}catch(pe){return s==null||s(String(pe)),null}},[c,ke,s]),fe=b.useCallback(async de=>{try{await c.deleteThread(de),V.current===de&&(x(null),N([],{})),await ke()}catch(pe){s==null||s(String(pe))}},[c,ke,N,s]),Ie=b.useCallback(async(de,pe)=>{try{await c.updateThread(de,pe),await ke()}catch(me){s==null||s(String(me))}},[c,ke,s]),Ae=b.useCallback((de,pe,me)=>{const ze=pe.filter(De=>De.checkpointId).map(De=>({checkpointId:De.checkpointId,checkpointNs:De.checkpointNs??void 0,createdAt:De.createdAt??""}));console.log(`[ChatSessionProvider] Cached metadata for ${ze.length} checkpoints from ${me}`),_e(de,ze)},[_e]),Fe=b.useCallback(async(de,pe)=>{if(de){T(!0),E(null);try{const me=await c.getStateHistory({threadId:de,checkpointId:pe||void 0}),{checkpoints:ze}=$r(me);Ae(de,ze,`thread load (requested: ${pe})`);const De=ze.find(ot=>ot.messages&&ot.messages.length>0)??(pe?ze.find(ot=>ot.checkpointId===pe):null)??ze[0];N((De==null?void 0:De.messages)??[],{checkpointId:(De==null?void 0:De.checkpointId)??null,checkpointNs:(De==null?void 0:De.checkpointNs)??null}),J(ze),R(!!(De!=null&&De.nextCursor)),L((De==null?void 0:De.nextCursor)??null)}catch(me){const ze=String(me);E(ze),s==null||s(ze)}finally{T(!1)}}},[c,N,s,Ae]);b.useEffect(()=>{q.current=Fe},[Fe]);const Ze=b.useCallback(async(de,pe)=>{const me=V.current;if(me){he(!0);try{const ze=await c.getStateHistory({threadId:me,checkpointId:de,checkpointNs:pe??void 0}),{checkpoints:De}=$r(ze);Ae(me,De,"checkpoint navigation");const ot=De.find(Et=>Et.checkpointId===de&&(pe?Et.checkpointNs===pe:!0));if(!ot){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:de,checkpointNs:pe});return}J(De),N(ot.messages??[],{checkpointId:ot.checkpointId??null,checkpointNs:ot.checkpointNs??null})}catch(ze){s==null||s(String(ze))}finally{he(!1)}}},[c,N,s,Ae]),Ve=b.useCallback((de,pe)=>{N(j.messages,{checkpointId:de??null,checkpointNs:pe??null})},[N,j.messages]),Ke=b.useCallback(async()=>{V.current&&await Fe(V.current)},[Fe]),qe=b.useCallback(async()=>{if(!(!V.current||!B)){_(!0);try{const de=await c.getStateHistory({threadId:V.current,checkpointId:B}),{checkpoints:pe}=$r(de);if(pe.length>0){const me=pe[pe.length-1];A((me==null?void 0:me.messages)??[]),R(!!(me!=null&&me.nextCursor)),L((me==null?void 0:me.nextCursor)??null)}}catch(de){s==null||s(String(de))}finally{_(!1)}}},[c,B,A,s]),Xe=b.useCallback(async()=>{N([],{}),x(null),H(),J([]),R(!1),L(null)},[N,H]),Qe=b.useCallback(async(de,pe,me)=>{const ze=V.current;if(!ze)throw new Error("No active thread to handle interrupt");const De=pe?me??!0:!1;try{const ot={threadId:ze,checkpointId:j.lastCheckpointId??void 0,checkpointNs:j.lastCheckpointNs??void 0,command:{kind:"resume",value:De}};D(ot)}catch(ot){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${de}:`,ot),ot}},[j.lastCheckpointId,j.lastCheckpointNs,D]);b.useEffect(()=>{ke()},[ke]),b.useEffect(()=>{var de,pe;!o||!m||k||ee.current!==m&&(ee.current=m,n?(console.log("[ChatSessionProvider] Loading thread with checkpoint:",n),(de=q.current)==null||de.call(q,m,n)):(console.log("[ChatSessionProvider] Loading thread with latest checkpoint"),(pe=q.current)==null||pe.call(q,m)))},[o,m,k,n,r]),b.useEffect(()=>{a==null||a(m)},[m,a]);const et=b.useCallback(async(de,pe)=>{const me=V.current,ze=(de==null?void 0:de.text)??"";if(!me&&!ze)return;const{contentParts:De}=await Tg(c,(de==null?void 0:de.attachments)??[]),ot=[...De];ze!=null&&ze.trim()&&ot.push({type:"text",text:ze});const Et={id:`msg-${Date.now()}`,role:"user",content:ot,createdAt:new Date().toISOString()};O(Et);const st={threadId:me,payload:{messages:[Et]},checkpointId:(pe==null?void 0:pe.checkpointId)??j.lastCheckpointId??void 0,checkpointNs:(pe==null?void 0:pe.checkpointNs)??j.lastCheckpointNs??void 0};D(st)},[c,Q,O,j,D]),Nt=b.useMemo(()=>({threads:p,currentThreadId:m,setCurrentThreadId:x,isLoading:y,error:w,actions:{createThread:Q,deleteThread:fe,renameThread:Ie,refreshThreads:ke}}),[p,m,y,w,Q,fe,Ie,ke]),mt=b.useMemo(()=>({threadId:m,messages:j.messages,interrupt:null,checkpoint:{id:j.lastCheckpointId??null,namespace:j.lastCheckpointNs??null},checkpoints:M,metadata:null,isLoading:k,isHistoryLoading:z,isLoadingCheckpoint:X,error:C,hasMore:$,loadOlder:qe,clearState:Xe,navigateToCheckpoint:Ze,setCurrentCheckpointId:Ve,returnToLatest:Ke,loadThread:Fe,clearThread:Xe,respondToInterrupt:Qe}),[m,j,M,k,z,X,C,$,qe,Xe,Ze,Ve,Ke,Fe,Qe]),at=b.useMemo(()=>({isStreaming:te,error:se,connectionState:te?"connected":"idle",submit:et,send:et,stop:H,setAuthToken:ne}),[te,se,et,H,ne]);return u.jsx(uc.Provider,{value:Nt,children:u.jsx(dc.Provider,{value:mt,children:u.jsx(fc.Provider,{value:at,children:e})})})}function Oo(){const e=b.useContext(uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){const e=b.useContext(dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function pc(){const e=b.useContext(fc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Do({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c}){return u.jsx(Sg,{apiConfig:t,children:u.jsx(Zg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c,children:e})})}function Z(...e){return Yh.twMerge(Gh.clsx(e))}const Qg=xo.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"}}),nt=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yn.Slot:"button";return u.jsx(i,{className:Z(Qg({variant:t,size:n,className:e})),ref:s,...o})});nt.displayName="Button";const hc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:Z("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));hc.displayName="Textarea";function mc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const m=i!==void 0,[x,y]=b.useState(e),g=(m?i:x)??"",[w,S]=b.useTransition(),k=b.useRef(null),T=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{m||(y(e??""),C.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const z=k.current;z&&(z.style.height="auto",z.style.height=`${z.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,g]);const j=b.useCallback((z,{fromUser:_})=>{m||y(z),_&&(a==null||a(z))},[m,a]),N=b.useCallback(async z=>{z&&z.preventDefault();const _=(g??"").trim();if(!_&&!h)return;const B=++T.current;C.current={id:B,shouldClear:!0},S(()=>{var L,M,J;try{const X=l(_);X&&typeof X.then=="function"?X.then(()=>{var he,Ne;((he=C.current)==null?void 0:he.id)===B&&C.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((Ne=C.current)==null?void 0:Ne.id)===B&&(C.current=null)}).catch(()=>{var he;((he=C.current)==null?void 0:he.id)===B&&(C.current=null)}):(((L=C.current)==null?void 0:L.id)===B&&C.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=C.current)==null?void 0:M.id)===B&&(C.current=null))}catch{((J=C.current)==null?void 0:J.id)===B&&(C.current=null)}})},[g,l,h,m,a]),A=b.useCallback(z=>{const _=z.target.value;j(_,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[j]),O=b.useCallback(z=>{z.key==="Enter"&&!z.shiftKey?(z.preventDefault(),N()):z.key==="Escape"&&t&&(z.preventDefault(),c==null||c())},[N,t,c]),R=`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))]":""} ${p}`;return u.jsx("form",{onSubmit:z=>void N(z),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(hc,{ref:k,value:g,onChange:A,onKeyDown:O,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(nt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(oe.Square,{size:16})}):u.jsx(nt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||w,children:u.jsx(oe.Send,{size:16})})})]})})}const ex=b.memo(mc);function ue(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 gc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=gc(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():gc(e[o],null)}}}}function Ue(...e){return v.useCallback(yi(...e),e)}function tx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function In(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:p,children:h,...m}=f,x=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(x.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var x;const h=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,m=v.useContext(h);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,nx(o,...t)]}function nx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var _t=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},rx=v[" useInsertionEffect ".trim().toString()]||_t;function xr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ox({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=sx(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function ox({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return rx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function sx(e){return typeof e=="function"}var ix=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Re=ix.reduce((e,t)=>{const n=Yn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xc(e,t){e&&yo.flushSync(()=>e.dispatchEvent(t))}function vi(e){const t=e+"CollectionProvider",[n,r]=In(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:y,children:g}=x,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:w,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Yn.createSlot(a),c=b.forwardRef((x,y)=>{const{scope:g,children:w}=x,S=s(a,g),k=Ue(y,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Yn.createSlot(d),h=b.forwardRef((x,y)=>{const{scope:g,children:w,...S}=x,k=b.useRef(null),T=Ue(y,k),C=s(d,g);return b.useEffect(()=>(C.itemMap.set(k,{ref:k,...S}),()=>void C.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:T,children:w})});h.displayName=d;function m(x){const y=s(e+"CollectionConsumer",x);return b.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},m,r]}var ax=v.createContext(void 0);function Lo(e){const t=v.useContext(ax);return e||t||"ltr"}function Rt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function lx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var cx="DismissableLayer",wi="dismissableLayer.update",ux="dismissableLayer.pointerDownOutside",dx="dismissableLayer.focusOutside",yc,vc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Fo=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(vc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),m=Ue(t,E=>f(E)),x=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=x.indexOf(y),w=d?x.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=g,T=hx(E=>{const j=E.target,N=[...c.branches].some(A=>A.contains(j));!k||N||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),C=mx(E=>{const j=E.target;[...c.branches].some(A=>A.contains(j))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return lx(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(yc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=yc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wc())},[d,c]),v.useEffect(()=>{const E=()=>h({});return document.addEventListener(wi,E),()=>document.removeEventListener(wi,E)},[]),u.jsx(Re.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:ue(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ue(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ue(e.onPointerDownCapture,T.onPointerDownCapture)})});Fo.displayName=cx;var fx="DismissableLayerBranch",px=v.forwardRef((e,t)=>{const n=v.useContext(vc),r=v.useRef(null),o=Ue(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Re.div,{...e,ref:o})});px.displayName=fx;function hx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){bc(ux,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function mx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&bc(dx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function wc(){const e=new CustomEvent(wi);document.dispatchEvent(e)}function bc(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?xc(o,s):o.dispatchEvent(s)}var bi=0;function Si(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sc()),document.body.insertAdjacentElement("beforeend",e[1]??Sc()),bi++,()=>{bi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),bi--}},[])}function Sc(){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 Ci="focusScope.autoFocusOnMount",Ti="focusScope.autoFocusOnUnmount",Cc={bubbles:!1,cancelable:!0},gx="FocusScope",$o=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Rt(o),d=Rt(s),f=v.useRef(null),p=Ue(t,x=>l(x)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let x=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:On(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||On(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const T of S)T.removedNodes.length>0&&On(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",y);const w=new MutationObserver(g);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",y),w.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){Ec.add(h);const x=document.activeElement;if(!a.contains(x)){const g=new CustomEvent(Ci,Cc);a.addEventListener(Ci,c),a.dispatchEvent(g),g.defaultPrevented||(xx(Sx(Tc(a)),{select:!0}),document.activeElement===x&&On(a))}return()=>{a.removeEventListener(Ci,c),setTimeout(()=>{const g=new CustomEvent(Ti,Cc);a.addEventListener(Ti,d),a.dispatchEvent(g),g.defaultPrevented||On(x??document.body,{select:!0}),a.removeEventListener(Ti,d),Ec.remove(h)},0)}}},[a,c,d,h]);const m=v.useCallback(x=>{if(!n&&!r||h.paused)return;const y=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,g=document.activeElement;if(y&&g){const w=x.currentTarget,[S,k]=yx(w);S&&k?!x.shiftKey&&g===k?(x.preventDefault(),n&&On(S,{select:!0})):x.shiftKey&&g===S&&(x.preventDefault(),n&&On(k,{select:!0})):g===w&&x.preventDefault()}},[n,r,h.paused]);return u.jsx(Re.div,{tabIndex:-1,...i,ref:p,onKeyDown:m})});$o.displayName=gx;function xx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(On(r,{select:t}),document.activeElement!==n)return}function yx(e){const t=Tc(e),n=kc(t,e),r=kc(t.reverse(),e);return[n,r]}function Tc(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 kc(e,t){for(const n of e)if(!vx(n,{upTo:t}))return n}function vx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function wx(e){return e instanceof HTMLInputElement&&"select"in e}function On(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var Ec=bx();function bx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Ic(e,t),e.unshift(t)},remove(t){var n;e=Ic(e,t),(n=e[0])==null||n.resume()}}}function Ic(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Sx(e){return e.filter(t=>t.tagName!=="A")}var Cx=v[" useId ".trim().toString()]||(()=>{}),Tx=0;function Nn(e){const[t,n]=v.useState(Cx());return _t(()=>{n(r=>r??String(Tx++))},[e]),t?`radix-${t}`:""}const kx=["top","right","bottom","left"],Mn=Math.min,Gt=Math.max,zo=Math.round,Bo=Math.floor,xn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ix={start:"end",end:"start"};function ki(e,t,n){return Gt(e,Mn(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function jn(e){return e.split("-")[0]}function yr(e){return e.split("-")[1]}function Ei(e){return e==="x"?"y":"x"}function Ii(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function yn(e){return Nx.has(jn(e))?"y":"x"}function Ni(e){return Ei(yn(e))}function Ax(e,t,n){n===void 0&&(n=!1);const r=yr(e),o=Ni(e),s=Ii(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ho(i)),[i,Ho(i)]}function jx(e){const t=Ho(e);return[Ai(e),t,Ai(t)]}function Ai(e){return e.replace(/start|end/g,t=>Ix[t])}const Nc=["left","right"],Ac=["right","left"],_x=["top","bottom"],Rx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Ac:Nc:t?Nc:Ac;case"left":case"right":return t?_x:Rx;default:return[]}}function Ox(e,t,n,r){const o=yr(e);let s=Px(jn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ai)))),s}function Ho(e){return e.replace(/left|right|bottom|top/g,t=>Ex[t])}function Mx(e){return{top:0,right:0,bottom:0,left:0,...e}}function jc(e){return typeof e!="number"?Mx(e):{top:e,right:e,bottom:e,left:e}}function Uo(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 _c(e,t,n){let{reference:r,floating:o}=e;const s=yn(t),i=Ni(t),a=Ii(i),l=jn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(yr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Dx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=_c(c,r,l),p=r,h={},m=0;for(let x=0;x<a.length;x++){const{name:y,fn:g}=a[x],{x:w,y:S,data:k,reset:T}=await g({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,h={...h,[y]:{...h[y],...k}},T&&m<=50&&(m++,typeof T=="object"&&(T.placement&&(p=T.placement),T.rects&&(c=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=_c(c,p,l)),x=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Br(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=An(t,e),m=jc(h),y=a[p?f==="floating"?"reference":"floating":f],g=Uo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},T=Uo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(g.top-T.top+m.top)/k.y,bottom:(T.bottom-g.bottom+m.bottom)/k.y,left:(g.left-T.left+m.left)/k.x,right:(T.right-g.right+m.right)/k.x}}const Lx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const f=jc(d),p={x:n,y:r},h=Ni(o),m=Ii(h),x=await i.getDimensions(c),y=h==="y",g=y?"top":"left",w=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[h]-p[h]-s.floating[m],T=p[h]-s.reference[h],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[m]);const j=k/2-T/2,N=E/2-x[m]/2-1,A=Mn(f[g],N),O=Mn(f[w],N),F=A,$=E-x[m]-O,R=E/2-x[m]/2+j,z=ki(F,R,$),_=!l.arrow&&yr(o)!=null&&R!==z&&s.reference[m]/2-(R<F?A:O)-x[m]/2<0,B=_?R<F?R-F:R-$:0;return{[h]:p[h]+B,data:{[h]:z,centerOffset:R-z-B,..._&&{alignmentOffset:B}},reset:_}}}),Fx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:x=!0,...y}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=jn(o),w=yn(a),S=jn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),T=p||(S||!x?[Ho(a)]:jx(a)),C=m!=="none";!p&&C&&T.push(...Ox(a,x,m,k));const E=[a,...T],j=await Br(t,y),N=[];let A=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&N.push(j[g]),f){const R=Ax(o,i,k);N.push(j[R[0]],j[R[1]])}if(A=[...A,{placement:o,overflows:N}],!N.every(R=>R<=0)){var O,F;const R=(((O=s.flip)==null?void 0:O.index)||0)+1,z=E[R];if(z&&(!(f==="alignment"?w!==yn(z):!1)||A.every(L=>yn(L.placement)===w?L.overflows[0]>0:!0)))return{data:{index:R,overflows:A},reset:{placement:z}};let _=(F=A.filter(B=>B.overflows[0]<=0).sort((B,L)=>B.overflows[1]-L.overflows[1])[0])==null?void 0:F.placement;if(!_)switch(h){case"bestFit":{var $;const B=($=A.filter(L=>{if(C){const M=yn(L.placement);return M===w||M==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(M=>M>0).reduce((M,J)=>M+J,0)]).sort((L,M)=>L[1]-M[1])[0])==null?void 0:$[0];B&&(_=B);break}case"initialPlacement":_=a;break}if(o!==_)return{reset:{placement:_}}}return{}}}};function Rc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pc(e){return kx.some(t=>e[t]>=0)}const $x=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=An(e,t);switch(r){case"referenceHidden":{const s=await Br(t,{...o,elementContext:"reference"}),i=Rc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pc(i)}}}case"escaped":{const s=await Br(t,{...o,altBoundary:!0}),i=Rc(s,n.floating);return{data:{escapedOffsets:i,escaped:Pc(i)}}}default:return{}}}}},Oc=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=jn(n),a=yr(n),l=yn(n)==="y",c=Oc.has(i)?-1:1,d=s&&l?-1:1,f=An(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(h=a==="end"?m*-1:m),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Bx=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 zx(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}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:g,y:w}=y;return{x:g,y:w}}},...l}=An(e,t),c={x:n,y:r},d=await Br(t,l),f=yn(jn(o)),p=Ei(f);let h=c[p],m=c[f];if(s){const y=p==="y"?"top":"left",g=p==="y"?"bottom":"right",w=h+d[y],S=h-d[g];h=ki(w,h,S)}if(i){const y=f==="y"?"top":"left",g=f==="y"?"bottom":"right",w=m+d[y],S=m-d[g];m=ki(w,m,S)}const x=a.fn({...t,[p]:h,[f]:m});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[p]:s,[f]:i}}}}}},Ux=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=An(e,t),d={x:n,y:r},f=yn(o),p=Ei(f);let h=d[p],m=d[f];const x=An(a,t),y=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,T=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>T&&(h=T)}if(c){var g,w;const S=p==="y"?"width":"height",k=Oc.has(jn(o)),T=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:y.crossAxis),C=s.reference[f]+s.reference[S]+(k?0:((w=i.offset)==null?void 0:w[f])||0)-(k?y.crossAxis:0);m<T?m=T:m>C&&(m=C)}return{[p]:h,[f]:m}}}},Wx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=An(e,t),d=await Br(t,c),f=jn(o),p=yr(o),h=yn(o)==="y",{width:m,height:x}=s.floating;let y,g;f==="top"||f==="bottom"?(y=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,y=p==="end"?"top":"bottom");const w=x-d.top-d.bottom,S=m-d.left-d.right,k=Mn(x-d[y],w),T=Mn(m-d[g],S),C=!t.middlewareData.shift;let E=k,j=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),C&&!p){const A=Gt(d.left,0),O=Gt(d.right,0),F=Gt(d.top,0),$=Gt(d.bottom,0);h?j=m-2*(A!==0||O!==0?A+O:Gt(d.left,d.right)):E=x-2*(F!==0||$!==0?F+$:Gt(d.top,d.bottom))}await l({...t,availableWidth:j,availableHeight:E});const N=await i.getDimensions(a.floating);return m!==N.width||x!==N.height?{reset:{rects:!0}}:{}}}};function Wo(){return typeof window<"u"}function vr(e){return Mc(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function vn(e){var t;return(t=(Mc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Mc(e){return Wo()?e instanceof Node||e instanceof Yt(e).Node:!1}function un(e){return Wo()?e instanceof Element||e instanceof Yt(e).Element:!1}function wn(e){return Wo()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function Dc(e){return!Wo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const Vx=new Set(["inline","contents"]);function Hr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Vx.has(o)}const Kx=new Set(["table","td","th"]);function qx(e){return Kx.has(vr(e))}const Gx=[":popover-open",":modal"];function Vo(e){return Gx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Yx=["transform","translate","scale","rotate","perspective"],Xx=["transform","translate","scale","rotate","perspective","filter"],Jx=["paint","layout","strict","content"];function ji(e){const t=_i(),n=un(e)?dn(e):e;return Yx.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)||Xx.some(r=>(n.willChange||"").includes(r))||Jx.some(r=>(n.contain||"").includes(r))}function Zx(e){let t=Dn(e);for(;wn(t)&&!wr(t);){if(ji(t))return t;if(Vo(t))return null;t=Dn(t)}return null}function _i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Qx=new Set(["html","body","#document"]);function wr(e){return Qx.has(vr(e))}function dn(e){return Yt(e).getComputedStyle(e)}function Ko(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Dn(e){if(vr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Dc(e)&&e.host||vn(e);return Dc(t)?t.host:t}function Lc(e){const t=Dn(e);return wr(t)?e.ownerDocument?e.ownerDocument.body:e.body:wn(t)&&Hr(t)?t:Lc(t)}function Ur(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Lc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Ri(i);return t.concat(i,i.visualViewport||[],Hr(o)?o:[],a&&n?Ur(a):[])}return t.concat(o,Ur(o,[],n))}function Ri(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Fc(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=wn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=zo(n)!==s||zo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Pi(e){return un(e)?e:e.contextElement}function br(e){const t=Pi(e);if(!wn(t))return xn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Fc(t);let i=(s?zo(n.width):n.width)/r,a=(s?zo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ey=xn(0);function $c(e){const t=Yt(e);return!_i()||!t.visualViewport?ey:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ty(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function Qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Pi(e);let i=xn(1);t&&(r?un(r)&&(i=br(r)):i=br(e));const a=ty(s,n,r)?$c(s):xn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Yt(s),h=r&&un(r)?Yt(r):r;let m=p,x=Ri(m);for(;x&&r&&h!==m;){const y=br(x),g=x.getBoundingClientRect(),w=dn(x),S=g.left+(x.clientLeft+parseFloat(w.paddingLeft))*y.x,k=g.top+(x.clientTop+parseFloat(w.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,m=Yt(x),x=Ri(m)}}return Uo({width:d,height:f,x:l,y:c})}function qo(e,t){const n=Ko(e).scrollLeft;return t?t.left+n:Qn(vn(e)).left+n}function zc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-qo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=vn(r),a=t?Vo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=xn(1);const d=xn(0),f=wn(r);if((f||!f&&!s)&&((vr(r)!=="body"||Hr(i))&&(l=Ko(r)),wn(r))){const h=Qn(r);c=br(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?zc(i,l):xn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function ry(e){return Array.from(e.getClientRects())}function oy(e){const t=vn(e),n=Ko(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+qo(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Bc=25;function sy(e,t){const n=Yt(e),r=vn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=_i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=qo(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-h);m<=Bc&&(s-=m)}else c<=Bc&&(s+=c);return{width:s,height:i,x:a,y:l}}const iy=new Set(["absolute","fixed"]);function ay(e,t){const n=Qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=wn(e)?br(e):xn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Hc(e,t,n){let r;if(t==="viewport")r=sy(e,n);else if(t==="document")r=oy(vn(e));else if(un(t))r=ay(t,n);else{const o=$c(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Uo(r)}function Uc(e,t){const n=Dn(e);return n===t||!un(n)||wr(n)?!1:dn(n).position==="fixed"||Uc(n,t)}function ly(e,t){const n=t.get(e);if(n)return n;let r=Ur(e,[],!1).filter(a=>un(a)&&vr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Dn(e):e;for(;un(i)&&!wr(i);){const a=dn(i),l=ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&iy.has(o.position)||Hr(i)&&!l&&Uc(e,i))?r=r.filter(d=>d!==i):o=a,i=Dn(i)}return t.set(e,r),r}function cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Vo(t)?[]:ly(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Hc(t,d,o);return c.top=Gt(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Gt(f.left,c.left),c},Hc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function uy(e){const{width:t,height:n}=Fc(e);return{width:t,height:n}}function dy(e,t,n){const r=wn(t),o=vn(t),s=n==="fixed",i=Qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=xn(0);function c(){l.x=qo(o)}if(r||!r&&!s)if((vr(t)!=="body"||Hr(o))&&(a=Ko(t)),r){const h=Qn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?zc(o,a):xn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function Oi(e){return dn(e).position==="static"}function Wc(e,t){if(!wn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return vn(e)===n&&(n=n.ownerDocument.body),n}function Vc(e,t){const n=Yt(e);if(Vo(e))return n;if(!wn(e)){let o=Dn(e);for(;o&&!wr(o);){if(un(o)&&!Oi(o))return o;o=Dn(o)}return n}let r=Wc(e,t);for(;r&&qx(r)&&Oi(r);)r=Wc(r,t);return r&&wr(r)&&Oi(r)&&!ji(r)?n:r||Zx(e)||n}const fy=async function(e){const t=this.getOffsetParent||Vc,n=this.getDimensions,r=await n(e.floating);return{reference:dy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function py(e){return dn(e).direction==="rtl"}const hy={convertOffsetParentRelativeRectToViewportRelativeRect:ny,getDocumentElement:vn,getClippingRect:cy,getOffsetParent:Vc,getElementRects:fy,getClientRects:ry,getDimensions:uy,getScale:br,isElement:un,isRTL:py};function Kc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function my(e,t){let n=null,r;const o=vn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const m=Bo(f),x=Bo(o.clientWidth-(d+p)),y=Bo(o.clientHeight-(f+h)),g=Bo(d),S={rootMargin:-m+"px "+-x+"px "+-y+"px "+-g+"px",threshold:Gt(0,Mn(1,l))||1};let k=!0;function T(C){const E=C[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Kc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(T,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,S)}n.observe(e)}return i(!0),s}function gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Pi(e),d=o||s?[...c?Ur(c):[],...Ur(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?my(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(g=>{let[w]=g;w&&w.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let m,x=l?Qn(e):null;l&&y();function y(){const g=Qn(e);x&&!Kc(x,g)&&n(),x=g,m=requestAnimationFrame(y)}return n(),()=>{var g;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(g=h)==null||g.disconnect(),h=null,l&&cancelAnimationFrame(m)}}const xy=Bx,yy=Hx,vy=Fx,wy=Wx,by=$x,qc=Lx,Sy=Ux,Cy=(e,t,n)=>{const r=new Map,o={platform:hy,...n},s={...o.platform,_c:r};return Dx(e,t,{...o,platform:s})};var Ty=typeof document<"u",ky=function(){},Go=Ty?b.useLayoutEffect:ky;function Yo(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(!Yo(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)&&!Yo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Gc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yc(e,t){const n=Gc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Go(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Yo(p,r)||h(r);const[m,x]=v.useState(null),[y,g]=v.useState(null),w=v.useCallback(L=>{L!==C.current&&(C.current=L,x(L))},[]),S=v.useCallback(L=>{L!==E.current&&(E.current=L,g(L))},[]),k=s||m,T=i||y,C=v.useRef(null),E=v.useRef(null),j=v.useRef(d),N=l!=null,A=Mi(l),O=Mi(o),F=Mi(c),$=v.useCallback(()=>{if(!C.current||!E.current)return;const L={placement:t,strategy:n,middleware:p};O.current&&(L.platform=O.current),Cy(C.current,E.current,L).then(M=>{const J={...M,isPositioned:F.current!==!1};R.current&&!Yo(j.current,J)&&(j.current=J,yo.flushSync(()=>{f(J)}))})},[p,t,n,O,F]);Go(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[c]);const R=v.useRef(!1);Go(()=>(R.current=!0,()=>{R.current=!1}),[]),Go(()=>{if(k&&(C.current=k),T&&(E.current=T),k&&T){if(A.current)return A.current(k,T,$);$()}},[k,T,$,A,N]);const z=v.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),_=v.useMemo(()=>({reference:k,floating:T}),[k,T]),B=v.useMemo(()=>{const L={position:n,left:0,top:0};if(!_.floating)return L;const M=Yc(_.floating,d.x),J=Yc(_.floating,d.y);return a?{...L,transform:"translate("+M+"px, "+J+"px)",...Gc(_.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:J}},[n,a,_.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:$,refs:z,elements:_,floatingStyles:B}),[d,$,z,_,B])}const Iy=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?qc({element:r.current,padding:o}).fn(n):{}:r?qc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...xy(e),options:[e,t]}),Ay=(e,t)=>({...yy(e),options:[e,t]}),jy=(e,t)=>({...Sy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),Ry=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...by(e),options:[e,t]}),Oy=(e,t)=>({...Iy(e),options:[e,t]});var My="Arrow",Xc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Re.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Xc.displayName=My;var Dy=Xc;function Jc(e){const[t,n]=v.useState(void 0);return _t(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Di="Popper",[Zc,Xo]=In(Di),[Ly,Qc]=Zc(Di),eu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(Ly,{scope:t,anchor:r,onAnchorChange:o,children:n})};eu.displayName=Di;var tu="PopperAnchor",nu=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Qc(tu,n),i=v.useRef(null),a=Ue(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Re.div,{...o,ref:a})});nu.displayName=tu;var Li="PopperContent",[Fy,$y]=Zc(Li),ru=v.forwardRef((e,t)=>{var q,D,H,te,se,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:m,...x}=e,y=Qc(Li,n),[g,w]=v.useState(null),S=Ue(t,ke=>w(ke)),[k,T]=v.useState(null),C=Jc(k),E=(C==null?void 0:C.width)??0,j=(C==null?void 0:C.height)??0,N=r+(s!=="center"?"-"+s:""),A=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},O=Array.isArray(c)?c:[c],F=O.length>0,$={padding:A,boundary:O.filter(By),altBoundary:F},{refs:R,floatingStyles:z,placement:_,isPositioned:B,middlewareData:L}=Ey({strategy:"fixed",placement:N,whileElementsMounted:(...ke)=>gy(...ke,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Ny({mainAxis:o+j,alignmentAxis:i}),l&&Ay({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...$}),l&&_y({...$}),Ry({...$,apply:({elements:ke,rects:Q,availableWidth:fe,availableHeight:Ie})=>{const{width:Ae,height:Fe}=Q.reference,Ze=ke.floating.style;Ze.setProperty("--radix-popper-available-width",`${fe}px`),Ze.setProperty("--radix-popper-available-height",`${Ie}px`),Ze.setProperty("--radix-popper-anchor-width",`${Ae}px`),Ze.setProperty("--radix-popper-anchor-height",`${Fe}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:E,arrowHeight:j}),p&&Py({strategy:"referenceHidden",...$})]}),[M,J]=iu(_),X=Rt(m);_t(()=>{B&&(X==null||X())},[B,X]);const he=(q=L.arrow)==null?void 0:q.x,Ne=(D=L.arrow)==null?void 0:D.y,_e=((H=L.arrow)==null?void 0:H.centerOffset)!==0,[V,ee]=v.useState();return _t(()=>{g&&ee(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:B?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:V,"--radix-popper-transform-origin":[(te=L.transformOrigin)==null?void 0:te.x,(se=L.transformOrigin)==null?void 0:se.y].join(" "),...((ne=L.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Fy,{scope:n,placedSide:M,onArrowChange:T,arrowX:he,arrowY:Ne,shouldHideArrow:_e,children:u.jsx(Re.div,{"data-side":M,"data-align":J,...x,ref:S,style:{...x.style,animation:B?void 0:"none"}})})})});ru.displayName=Li;var ou="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},su=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=$y(ou,r),i=zy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Dy,{...o,ref:n,style:{...o.style,display:"block"}})})});su.displayName=ou;function By(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var y,g,w;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=iu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,h=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",x="";return c==="bottom"?(m=i?f:`${p}px`,x=`${-l}px`):c==="top"?(m=i?f:`${p}px`,x=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,x=i?f:`${h}px`):c==="left"&&(m=`${r.floating.width+l}px`,x=i?f:`${h}px`),{data:{x:m,y:x}}}});function iu(e){const[t,n="center"]=e.split("-");return[t,n]}var au=eu,lu=nu,cu=ru,uu=su,Uy="Portal",Jo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);_t(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Js.createPortal(u.jsx(Re.div,{...r,ref:t}),i):null});Jo.displayName=Uy;function Wy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var tn=e=>{const{present:t,children:n}=e,r=Vy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Ue(r.ref,Ky(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};tn.displayName="Presence";function Vy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Zo(r.current);s.current=a==="mounted"?c:"none"},[a]),_t(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Zo(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),_t(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const x=Zo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&x&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Zo(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Zo(e){return(e==null?void 0:e.animationName)||"none"}function Ky(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 Fi="rovingFocusGroup.onEntryFocus",qy={bubbles:!1,cancelable:!0},Wr="RovingFocusGroup",[$i,du,Gy]=vi(Wr),[Yy,fu]=In(Wr,[Gy]),[Xy,Jy]=Yy(Wr),pu=v.forwardRef((e,t)=>u.jsx($i.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx($i.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Zy,{...e,ref:t})})}));pu.displayName=Wr;var Zy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Ue(t,p),m=Lo(s),[x,y]=xr({prop:i,defaultProp:a??null,onChange:l,caller:Wr}),[g,w]=v.useState(!1),S=Rt(c),k=du(n),T=v.useRef(!1),[C,E]=v.useState(0);return v.useEffect(()=>{const j=p.current;if(j)return j.addEventListener(Fi,S),()=>j.removeEventListener(Fi,S)},[S]),u.jsx(Xy,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:x,onItemFocus:v.useCallback(j=>y(j),[y]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>E(j=>j-1),[]),children:u.jsx(Re.div,{tabIndex:g||C===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:ue(e.onMouseDown,()=>{T.current=!0}),onFocus:ue(e.onFocus,j=>{const N=!T.current;if(j.target===j.currentTarget&&N&&!g){const A=new CustomEvent(Fi,qy);if(j.currentTarget.dispatchEvent(A),!A.defaultPrevented){const O=k().filter(_=>_.focusable),F=O.find(_=>_.active),$=O.find(_=>_.id===x),z=[F,$,...O].filter(Boolean).map(_=>_.ref.current);gu(z,d)}}T.current=!1}),onBlur:ue(e.onBlur,()=>w(!1))})})}),hu="RovingFocusGroupItem",mu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Nn(),c=s||l,d=Jy(hu,n),f=d.currentTabStopId===c,p=du(n),{onFocusableItemAdd:h,onFocusableItemRemove:m,currentTabStopId:x}=d;return v.useEffect(()=>{if(r)return h(),()=>m()},[r,h,m]),u.jsx($i.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Re.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ue(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:ue(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ue(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=tv(y,d.orientation,d.dir);if(g!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?nv(S,k+1):S.slice(k+1)}setTimeout(()=>gu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});mu.displayName=hu;var Qy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ev(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function tv(e,t,n){const r=ev(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Qy[r]}function gu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function nv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rv=pu,ov=mu,sv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Sr=new WeakMap,Qo=new WeakMap,es={},zi=0,xu=function(e){return e&&(e.host||xu(e.parentNode))},iv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=xu(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},av=function(e,t,n,r){var o=iv(t,Array.isArray(e)?e:[e]);es[n]||(es[n]=new WeakMap);var s=es[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),m=h!==null&&h!=="false",x=(Sr.get(p)||0)+1,y=(s.get(p)||0)+1;Sr.set(p,x),s.set(p,y),i.push(p),x===1&&m&&Qo.set(p,!0),y===1&&p.setAttribute(n,"true"),m||p.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",p,g)}})};return d(t),a.clear(),zi++,function(){i.forEach(function(f){var p=Sr.get(f)-1,h=s.get(f)-1;Sr.set(f,p),s.set(f,h),p||(Qo.has(f)||f.removeAttribute(r),Qo.delete(f)),h||f.removeAttribute(n)}),zi--,zi||(Sr=new WeakMap,Sr=new WeakMap,Qo=new WeakMap,es={})}},Bi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=sv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),av(r,o,n,"aria-hidden")):function(){return null}},bn=function(){return bn=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},bn.apply(this,arguments)};function yu(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 lv(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 ts="right-scroll-bar-position",ns="width-before-scroll-bar",cv="with-scroll-bars-hidden",uv="--removed-body-scroll-bar-size";function Hi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function dv(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var fv=typeof window<"u"?v.useLayoutEffect:v.useEffect,vu=new WeakMap;function pv(e,t){var n=dv(null,function(r){return e.forEach(function(o){return Hi(o,r)})});return fv(function(){var r=vu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Hi(a,null)}),s.forEach(function(a){o.has(a)||Hi(a,i)})}vu.set(n,e)},[e]),n}function hv(e){return e}function mv(e,t){t===void 0&&(t=hv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function gv(e){e===void 0&&(e={});var t=mv(null);return t.options=bn({async:!0,ssr:!1},e),t}var wu=function(e){var t=e.sideCar,n=yu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,bn({},n))};wu.isSideCarExport=!0;function xv(e,t){return e.useMedium(t),wu}var bu=gv(),Ui=function(){},rs=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Ui,onWheelCapture:Ui,onTouchMoveCapture:Ui}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,m=e.noIsolation,x=e.inert,y=e.allowPinchZoom,g=e.as,w=g===void 0?"div":g,S=e.gapMode,k=yu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=p,C=pv([n,t]),E=bn(bn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(T,{sideCar:bu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:m,inert:x,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),bn(bn({},E),{ref:C})):v.createElement(w,bn({},E,{className:l,ref:C}),a))});rs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},rs.classNames={fullWidth:ns,zeroRight:ts};var yv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function vv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function bv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Sv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=vv())&&(wv(t,n),bv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Cv=function(){var e=Sv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Su=function(){var e=Cv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Tv={left:0,top:0,right:0,gap:0},Wi=function(e){return parseInt(e||"",10)||0},kv=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[Wi(n),Wi(r),Wi(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Tv;var t=kv(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])}},Iv=Su(),Cr="data-scroll-locked",Nv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
39
39
|
.`.concat(cv,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -75,7 +75,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
75
75
|
`)},Cu=function(){var e=parseInt(document.body.getAttribute(Cr)||"0",10);return isFinite(e)?e:0},Av=function(){v.useEffect(function(){return document.body.setAttribute(Cr,(Cu()+1).toString()),function(){var e=Cu()-1;e<=0?document.body.removeAttribute(Cr):document.body.setAttribute(Cr,e.toString())}},[])},jv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Av();var s=v.useMemo(function(){return Ev(o)},[o]);return v.createElement(Iv,{styles:Nv(s,!t,o,n?"":"!important")})},Vi=!1;if(typeof window<"u")try{var os=Object.defineProperty({},"passive",{get:function(){return Vi=!0,!0}});window.addEventListener("test",os,os),window.removeEventListener("test",os,os)}catch{Vi=!1}var Tr=Vi?{passive:!1}:!1,_v=function(e){return e.tagName==="TEXTAREA"},Tu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!_v(e)&&n[t]==="visible")},Rv=function(e){return Tu(e,"overflowY")},Pv=function(e){return Tu(e,"overflowX")},ku=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Eu(e,r);if(o){var s=Iu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Ov=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Mv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Eu=function(e,t){return e==="v"?Rv(t):Pv(t)},Iu=function(e,t){return e==="v"?Ov(t):Mv(t)},Dv=function(e,t){return e==="h"&&t==="rtl"?-1:1},Lv=function(e,t,n,r,o){var s=Dv(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,p=0;do{if(!a)break;var h=Iu(e,a),m=h[0],x=h[1],y=h[2],g=x-y-s*m;(m||g)&&Eu(e,a)&&(f+=g,p+=m);var w=a.parentNode;a=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(p)<1)&&(c=!0),c},ss=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Nu=function(e){return[e.deltaX,e.deltaY]},Au=function(e){return e&&"current"in e?e.current:e},Fv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},$v=function(e){return`
|
|
76
76
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
77
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
78
|
-
`)},zv=0,kr=[];function Bv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(zv++)[0],s=v.useState(Su)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var x=lv([e.lockRef.current],(e.shards||[]).map(Au),!0).filter(Boolean);return x.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),x.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(x,y){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var g=ss(x),w=n.current,S="deltaX"in x?x.deltaX:w[0]-g[0],k="deltaY"in x?x.deltaY:w[1]-g[1],T,C=x.target,E=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in x&&E==="h"&&C.type==="range")return!1;var j=ku(E,C);if(!j)return!0;if(j?T=E:(T=E==="v"?"h":"v",j=ku(E,C)),!j)return!1;if(!r.current&&"changedTouches"in x&&(S||k)&&(r.current=T),!T)return!0;var N=r.current||T;return Lv(N,y,x,N==="h"?S:k)},[]),l=v.useCallback(function(x){var y=x;if(!(!kr.length||kr[kr.length-1]!==s)){var g="deltaY"in y?Nu(y):ss(y),w=t.current.filter(function(T){return T.name===y.type&&(T.target===y.target||y.target===T.shadowParent)&&Fv(T.delta,g)})[0];if(w&&w.should){y.cancelable&&y.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(Au).filter(Boolean).filter(function(T){return T.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(x,y,g,w){var S={name:x,delta:y,target:g,should:w,shadowParent:Hv(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(x){n.current=ss(x),r.current=void 0},[]),f=v.useCallback(function(x){c(x.type,Nu(x),x.target,a(x,e.lockRef.current))},[]),p=v.useCallback(function(x){c(x.type,ss(x),x.target,a(x,e.lockRef.current))},[]);v.useEffect(function(){return kr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,Tr),document.addEventListener("touchmove",l,Tr),document.addEventListener("touchstart",d,Tr),function(){kr=kr.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,Tr),document.removeEventListener("touchmove",l,Tr),document.removeEventListener("touchstart",d,Tr)}},[]);var h=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:$v(o)}):null,h?v.createElement(jv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Hv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Uv=xv(bu,Bv);var is=v.forwardRef(function(e,t){return v.createElement(rs,bn({},e,{ref:t,sideCar:Uv}))});is.classNames=rs.classNames;var Ki=["Enter"," "],Wv=["ArrowDown","PageUp","Home"],ju=["ArrowUp","PageDown","End"],Vv=[...Wv,...ju],Kv={ltr:[...Ki,"ArrowRight"],rtl:[...Ki,"ArrowLeft"]},qv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Vr="Menu",[Kr,Gv,Yv]=vi(Vr),[er,_u]=In(Vr,[Yv,Xo,fu]),as=Xo(),Ru=fu(),[Xv,tr]=er(Vr),[Jv,qr]=er(Vr),Pu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=as(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Rt(s),p=Lo(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(au,{...a,children:u.jsx(Xv,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Jv,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Pu.displayName=Vr;var Zv="MenuAnchor",qi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=as(n);return u.jsx(lu,{...o,...r,ref:t})});qi.displayName=Zv;var Gi="MenuPortal",[Qv,Ou]=er(Gi,{forceMount:void 0}),Mu=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=tr(Gi,t);return u.jsx(Qv,{scope:t,forceMount:n,children:u.jsx(tn,{present:n||s.open,children:u.jsx(Jo,{asChild:!0,container:o,children:r})})})};Mu.displayName=Gi;var nn="MenuContent",[ew,Yi]=er(nn),Du=v.forwardRef((e,t)=>{const n=Ou(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=tr(nn,e.__scopeMenu),i=qr(nn,e.__scopeMenu);return u.jsx(Kr.Provider,{scope:e.__scopeMenu,children:u.jsx(tn,{present:r||s.open,children:u.jsx(Kr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(tw,{...o,ref:t}):u.jsx(nw,{...o,ref:t})})})})}),tw=v.forwardRef((e,t)=>{const n=tr(nn,e.__scopeMenu),r=v.useRef(null),o=Ue(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Bi(s)},[]),u.jsx(Xi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),nw=v.forwardRef((e,t)=>{const n=tr(nn,e.__scopeMenu);return u.jsx(Xi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),rw=Yn.createSlot("MenuContent.ScrollLock"),Xi=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:m,...x}=e,y=tr(nn,n),g=qr(nn,n),w=as(n),S=Ru(n),k=Gv(n),[T,C]=v.useState(null),E=v.useRef(null),j=Ue(t,E,y.onContentChange),N=v.useRef(0),A=v.useRef(""),O=v.useRef(0),F=v.useRef(null),$=v.useRef("right"),R=v.useRef(0),z=m?is:v.Fragment,_=m?{as:rw,allowPinchZoom:!0}:void 0,B=M=>{var q,D;const J=A.current+M,X=k().filter(H=>!H.disabled),he=document.activeElement,Ne=(q=X.find(H=>H.ref.current===he))==null?void 0:q.textValue,_e=X.map(H=>H.textValue),V=mw(_e,J,Ne),ee=(D=X.find(H=>H.textValue===V))==null?void 0:D.ref.current;(function H(te){A.current=te,window.clearTimeout(N.current),te!==""&&(N.current=window.setTimeout(()=>H(""),1e3))})(J),ee&&setTimeout(()=>ee.focus())};v.useEffect(()=>()=>window.clearTimeout(N.current),[]),Si();const L=v.useCallback(M=>{var X,he;return $.current===((X=F.current)==null?void 0:X.side)&&xw(M,(he=F.current)==null?void 0:he.area)},[]);return u.jsx(ew,{scope:n,searchRef:A,onItemEnter:v.useCallback(M=>{L(M)&&M.preventDefault()},[L]),onItemLeave:v.useCallback(M=>{var J;L(M)||((J=E.current)==null||J.focus(),C(null))},[L]),onTriggerLeave:v.useCallback(M=>{L(M)&&M.preventDefault()},[L]),pointerGraceTimerRef:O,onPointerGraceIntentChange:v.useCallback(M=>{F.current=M},[]),children:u.jsx(z,{..._,children:u.jsx($o,{asChild:!0,trapped:o,onMountAutoFocus:ue(s,M=>{var J;M.preventDefault(),(J=E.current)==null||J.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Fo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(rv,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:C,onEntryFocus:ue(l,M=>{g.isUsingKeyboardRef.current||M.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(cu,{role:"menu","aria-orientation":"vertical","data-state":Qu(y.open),"data-radix-menu-content":"",dir:g.dir,...w,...x,ref:j,style:{outline:"none",...x.style},onKeyDown:ue(x.onKeyDown,M=>{const X=M.target.closest("[data-radix-menu-content]")===M.currentTarget,he=M.ctrlKey||M.altKey||M.metaKey,Ne=M.key.length===1;X&&(M.key==="Tab"&&M.preventDefault(),!he&&Ne&&B(M.key));const _e=E.current;if(M.target!==_e||!Vv.includes(M.key))return;M.preventDefault();const ee=k().filter(q=>!q.disabled).map(q=>q.ref.current);ju.includes(M.key)&&ee.reverse(),pw(ee)}),onBlur:ue(e.onBlur,M=>{M.currentTarget.contains(M.target)||(window.clearTimeout(N.current),A.current="")}),onPointerMove:ue(e.onPointerMove,Yr(M=>{const J=M.target,X=R.current!==M.clientX;if(M.currentTarget.contains(J)&&X){const he=M.clientX>R.current?"right":"left";$.current=he,R.current=M.clientX}}))})})})})})})});Du.displayName=nn;var ow="MenuGroup",Ji=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Re.div,{role:"group",...r,ref:t})});Ji.displayName=ow;var sw="MenuLabel",Lu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Re.div,{...r,ref:t})});Lu.displayName=sw;var ls="MenuItem",Fu="menu.itemSelect",cs=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=qr(ls,e.__scopeMenu),a=Yi(ls,e.__scopeMenu),l=Ue(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Fu,{bubbles:!0,cancelable:!0});f.addEventListener(Fu,h=>r==null?void 0:r(h),{once:!0}),xc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx($u,{...o,ref:l,disabled:n,onClick:ue(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:ue(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:ue(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Ki.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});cs.displayName=ls;var $u=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Yi(ls,n),a=Ru(n),l=v.useRef(null),c=Ue(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&h((m.textContent??"").trim())},[s.children]),u.jsx(Kr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(ov,{asChild:!0,...a,focusable:!r,children:u.jsx(Re.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ue(e.onPointerMove,Yr(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ue(e.onPointerLeave,Yr(m=>i.onItemLeave(m))),onFocus:ue(e.onFocus,()=>f(!0)),onBlur:ue(e.onBlur,()=>f(!1))})})})}),iw="MenuCheckboxItem",zu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Vu,{scope:e.__scopeMenu,checked:n,children:u.jsx(cs,{role:"menuitemcheckbox","aria-checked":us(n)?"mixed":n,...o,ref:t,"data-state":Qi(n),onSelect:ue(o.onSelect,()=>r==null?void 0:r(us(n)?!0:!n),{checkForDefaultPrevented:!1})})})});zu.displayName=iw;var Bu="MenuRadioGroup",[aw,lw]=er(Bu,{value:void 0,onValueChange:()=>{}}),Hu=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Rt(r);return u.jsx(aw,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Ji,{...o,ref:t})})});Hu.displayName=Bu;var Uu="MenuRadioItem",Wu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=lw(Uu,e.__scopeMenu),s=n===o.value;return u.jsx(Vu,{scope:e.__scopeMenu,checked:s,children:u.jsx(cs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Qi(s),onSelect:ue(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Wu.displayName=Uu;var Zi="MenuItemIndicator",[Vu,cw]=er(Zi,{checked:!1}),Ku=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=cw(Zi,n);return u.jsx(tn,{present:r||us(s.checked)||s.checked===!0,children:u.jsx(Re.span,{...o,ref:t,"data-state":Qi(s.checked)})})});Ku.displayName=Zi;var uw="MenuSeparator",qu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Re.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});qu.displayName=uw;var dw="MenuArrow",Gu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=as(n);return u.jsx(uu,{...o,...r,ref:t})});Gu.displayName=dw;var fw="MenuSub",[gT,Yu]=er(fw),Gr="MenuSubTrigger",Xu=v.forwardRef((e,t)=>{const n=tr(Gr,e.__scopeMenu),r=qr(Gr,e.__scopeMenu),o=Yu(Gr,e.__scopeMenu),s=Yi(Gr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(qi,{asChild:!0,...c,children:u.jsx($u,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Qu(n.open),...e,ref:yi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ue(e.onPointerMove,Yr(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:ue(e.onPointerLeave,Yr(f=>{var h,m;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const x=(m=n.content)==null?void 0:m.dataset.side,y=x==="right",g=y?-5:5,w=p[y?"left":"right"],S=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+g,y:f.clientY},{x:w,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:w,y:p.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ue(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||Kv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Xu.displayName=Gr;var Ju="MenuSubContent",Zu=v.forwardRef((e,t)=>{const n=Ou(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=tr(nn,e.__scopeMenu),i=qr(nn,e.__scopeMenu),a=Yu(Ju,e.__scopeMenu),l=v.useRef(null),c=Ue(t,l);return u.jsx(Kr.Provider,{scope:e.__scopeMenu,children:u.jsx(tn,{present:r||s.open,children:u.jsx(Kr.Slot,{scope:e.__scopeMenu,children:u.jsx(Xi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ue(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ue(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ue(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=qv[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Zu.displayName=Ju;function Qu(e){return e?"open":"closed"}function us(e){return e==="indeterminate"}function Qi(e){return us(e)?"indeterminate":e?"checked":"unchecked"}function pw(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function hw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function mw(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=hw(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function gw(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,p=l.y;d>r!=p>r&&n<(f-c)*(r-d)/(p-d)+c&&(o=!o)}return o}function xw(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return gw(n,t)}function Yr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var yw=Pu,vw=qi,ww=Mu,bw=Du,Sw=Ji,Cw=Lu,Tw=cs,kw=zu,Ew=Hu,Iw=Wu,Nw=Ku,Aw=qu,jw=Gu,_w=Xu,Rw=Zu,ds="DropdownMenu",[Pw,xT]=In(ds,[_u]),zt=_u(),[Ow,ed]=Pw(ds),td=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=zt(t),c=v.useRef(null),[d,f]=xr({prop:o,defaultProp:s??!1,onChange:i,caller:ds});return u.jsx(Ow,{scope:t,triggerId:Nn(),triggerRef:c,contentId:Nn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(yw,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};td.displayName=ds;var nd="DropdownMenuTrigger",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=ed(nd,n),i=zt(n);return u.jsx(vw,{asChild:!0,...i,children:u.jsx(Re.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:yi(t,s.triggerRef),onPointerDown:ue(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ue(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});rd.displayName=nd;var Mw="DropdownMenuPortal",od=e=>{const{__scopeDropdownMenu:t,...n}=e,r=zt(t);return u.jsx(ww,{...r,...n})};od.displayName=Mw;var sd="DropdownMenuContent",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=ed(sd,n),s=zt(n),i=v.useRef(!1);return u.jsx(bw,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ue(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ue(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});id.displayName=sd;var Dw="DropdownMenuGroup",Lw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Sw,{...o,...r,ref:t})});Lw.displayName=Dw;var Fw="DropdownMenuLabel",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Cw,{...o,...r,ref:t})});ad.displayName=Fw;var $w="DropdownMenuItem",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Tw,{...o,...r,ref:t})});ld.displayName=$w;var zw="DropdownMenuCheckboxItem",cd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(kw,{...o,...r,ref:t})});cd.displayName=zw;var Bw="DropdownMenuRadioGroup",Hw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Ew,{...o,...r,ref:t})});Hw.displayName=Bw;var Uw="DropdownMenuRadioItem",ud=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Iw,{...o,...r,ref:t})});ud.displayName=Uw;var Ww="DropdownMenuItemIndicator",dd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Nw,{...o,...r,ref:t})});dd.displayName=Ww;var Vw="DropdownMenuSeparator",fd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Aw,{...o,...r,ref:t})});fd.displayName=Vw;var Kw="DropdownMenuArrow",qw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(jw,{...o,...r,ref:t})});qw.displayName=Kw;var Gw="DropdownMenuSubTrigger",pd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(_w,{...o,...r,ref:t})});pd.displayName=Gw;var Yw="DropdownMenuSubContent",hd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Rw,{...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)"}})});hd.displayName=Yw;var Xw=td,Jw=rd,Zw=od,md=id,gd=ad,xd=ld,yd=cd,vd=ud,wd=dd,bd=fd,Sd=pd,Cd=hd;const Qw=Xw,eb=Jw,tb=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(Sd,{ref:o,className:Q("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(oe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));tb.displayName=Sd.displayName;const nb=v.forwardRef(({className:e,...t},n)=>u.jsx(Cd,{ref:n,className:Q("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}));nb.displayName=Cd.displayName;const Td=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Zw,{children:u.jsx(md,{ref:r,sideOffset:t,className:Q("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})}));Td.displayName=md.displayName;const ea=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(xd,{ref:r,className:Q("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}));ea.displayName=xd.displayName;const rb=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(yd,{ref:o,className:Q("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wd,{children:u.jsx(oe.Check,{className:"h-4 w-4"})})}),t]}));rb.displayName=yd.displayName;const ob=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vd,{ref:r,className:Q("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wd,{children:u.jsx(oe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));ob.displayName=vd.displayName;const sb=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(gd,{ref:r,className:Q("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));sb.displayName=gd.displayName;const ib=v.forwardRef(({className:e,...t},n)=>u.jsx(bd,{ref:n,className:Q("-mx-1 my-1 h-px bg-muted",e),...t}));ib.displayName=bd.displayName;const fs=1e4;function ab(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
78
|
+
`)},zv=0,kr=[];function Bv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(zv++)[0],s=v.useState(Su)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var x=lv([e.lockRef.current],(e.shards||[]).map(Au),!0).filter(Boolean);return x.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),x.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(x,y){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var g=ss(x),w=n.current,S="deltaX"in x?x.deltaX:w[0]-g[0],k="deltaY"in x?x.deltaY:w[1]-g[1],T,C=x.target,E=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in x&&E==="h"&&C.type==="range")return!1;var j=ku(E,C);if(!j)return!0;if(j?T=E:(T=E==="v"?"h":"v",j=ku(E,C)),!j)return!1;if(!r.current&&"changedTouches"in x&&(S||k)&&(r.current=T),!T)return!0;var N=r.current||T;return Lv(N,y,x,N==="h"?S:k)},[]),l=v.useCallback(function(x){var y=x;if(!(!kr.length||kr[kr.length-1]!==s)){var g="deltaY"in y?Nu(y):ss(y),w=t.current.filter(function(T){return T.name===y.type&&(T.target===y.target||y.target===T.shadowParent)&&Fv(T.delta,g)})[0];if(w&&w.should){y.cancelable&&y.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(Au).filter(Boolean).filter(function(T){return T.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(x,y,g,w){var S={name:x,delta:y,target:g,should:w,shadowParent:Hv(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(x){n.current=ss(x),r.current=void 0},[]),f=v.useCallback(function(x){c(x.type,Nu(x),x.target,a(x,e.lockRef.current))},[]),p=v.useCallback(function(x){c(x.type,ss(x),x.target,a(x,e.lockRef.current))},[]);v.useEffect(function(){return kr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,Tr),document.addEventListener("touchmove",l,Tr),document.addEventListener("touchstart",d,Tr),function(){kr=kr.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,Tr),document.removeEventListener("touchmove",l,Tr),document.removeEventListener("touchstart",d,Tr)}},[]);var h=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:$v(o)}):null,h?v.createElement(jv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Hv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Uv=xv(bu,Bv);var is=v.forwardRef(function(e,t){return v.createElement(rs,bn({},e,{ref:t,sideCar:Uv}))});is.classNames=rs.classNames;var Ki=["Enter"," "],Wv=["ArrowDown","PageUp","Home"],ju=["ArrowUp","PageDown","End"],Vv=[...Wv,...ju],Kv={ltr:[...Ki,"ArrowRight"],rtl:[...Ki,"ArrowLeft"]},qv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Vr="Menu",[Kr,Gv,Yv]=vi(Vr),[er,_u]=In(Vr,[Yv,Xo,fu]),as=Xo(),Ru=fu(),[Xv,tr]=er(Vr),[Jv,qr]=er(Vr),Pu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=as(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Rt(s),p=Lo(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(au,{...a,children:u.jsx(Xv,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Jv,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Pu.displayName=Vr;var Zv="MenuAnchor",qi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=as(n);return u.jsx(lu,{...o,...r,ref:t})});qi.displayName=Zv;var Gi="MenuPortal",[Qv,Ou]=er(Gi,{forceMount:void 0}),Mu=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=tr(Gi,t);return u.jsx(Qv,{scope:t,forceMount:n,children:u.jsx(tn,{present:n||s.open,children:u.jsx(Jo,{asChild:!0,container:o,children:r})})})};Mu.displayName=Gi;var nn="MenuContent",[ew,Yi]=er(nn),Du=v.forwardRef((e,t)=>{const n=Ou(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=tr(nn,e.__scopeMenu),i=qr(nn,e.__scopeMenu);return u.jsx(Kr.Provider,{scope:e.__scopeMenu,children:u.jsx(tn,{present:r||s.open,children:u.jsx(Kr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(tw,{...o,ref:t}):u.jsx(nw,{...o,ref:t})})})})}),tw=v.forwardRef((e,t)=>{const n=tr(nn,e.__scopeMenu),r=v.useRef(null),o=Ue(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Bi(s)},[]),u.jsx(Xi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),nw=v.forwardRef((e,t)=>{const n=tr(nn,e.__scopeMenu);return u.jsx(Xi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),rw=Yn.createSlot("MenuContent.ScrollLock"),Xi=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:m,...x}=e,y=tr(nn,n),g=qr(nn,n),w=as(n),S=Ru(n),k=Gv(n),[T,C]=v.useState(null),E=v.useRef(null),j=Ue(t,E,y.onContentChange),N=v.useRef(0),A=v.useRef(""),O=v.useRef(0),F=v.useRef(null),$=v.useRef("right"),R=v.useRef(0),z=m?is:v.Fragment,_=m?{as:rw,allowPinchZoom:!0}:void 0,B=M=>{var q,D;const J=A.current+M,X=k().filter(H=>!H.disabled),he=document.activeElement,Ne=(q=X.find(H=>H.ref.current===he))==null?void 0:q.textValue,_e=X.map(H=>H.textValue),V=mw(_e,J,Ne),ee=(D=X.find(H=>H.textValue===V))==null?void 0:D.ref.current;(function H(te){A.current=te,window.clearTimeout(N.current),te!==""&&(N.current=window.setTimeout(()=>H(""),1e3))})(J),ee&&setTimeout(()=>ee.focus())};v.useEffect(()=>()=>window.clearTimeout(N.current),[]),Si();const L=v.useCallback(M=>{var X,he;return $.current===((X=F.current)==null?void 0:X.side)&&xw(M,(he=F.current)==null?void 0:he.area)},[]);return u.jsx(ew,{scope:n,searchRef:A,onItemEnter:v.useCallback(M=>{L(M)&&M.preventDefault()},[L]),onItemLeave:v.useCallback(M=>{var J;L(M)||((J=E.current)==null||J.focus(),C(null))},[L]),onTriggerLeave:v.useCallback(M=>{L(M)&&M.preventDefault()},[L]),pointerGraceTimerRef:O,onPointerGraceIntentChange:v.useCallback(M=>{F.current=M},[]),children:u.jsx(z,{..._,children:u.jsx($o,{asChild:!0,trapped:o,onMountAutoFocus:ue(s,M=>{var J;M.preventDefault(),(J=E.current)==null||J.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Fo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(rv,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:C,onEntryFocus:ue(l,M=>{g.isUsingKeyboardRef.current||M.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(cu,{role:"menu","aria-orientation":"vertical","data-state":Qu(y.open),"data-radix-menu-content":"",dir:g.dir,...w,...x,ref:j,style:{outline:"none",...x.style},onKeyDown:ue(x.onKeyDown,M=>{const X=M.target.closest("[data-radix-menu-content]")===M.currentTarget,he=M.ctrlKey||M.altKey||M.metaKey,Ne=M.key.length===1;X&&(M.key==="Tab"&&M.preventDefault(),!he&&Ne&&B(M.key));const _e=E.current;if(M.target!==_e||!Vv.includes(M.key))return;M.preventDefault();const ee=k().filter(q=>!q.disabled).map(q=>q.ref.current);ju.includes(M.key)&&ee.reverse(),pw(ee)}),onBlur:ue(e.onBlur,M=>{M.currentTarget.contains(M.target)||(window.clearTimeout(N.current),A.current="")}),onPointerMove:ue(e.onPointerMove,Yr(M=>{const J=M.target,X=R.current!==M.clientX;if(M.currentTarget.contains(J)&&X){const he=M.clientX>R.current?"right":"left";$.current=he,R.current=M.clientX}}))})})})})})})});Du.displayName=nn;var ow="MenuGroup",Ji=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Re.div,{role:"group",...r,ref:t})});Ji.displayName=ow;var sw="MenuLabel",Lu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Re.div,{...r,ref:t})});Lu.displayName=sw;var ls="MenuItem",Fu="menu.itemSelect",cs=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=qr(ls,e.__scopeMenu),a=Yi(ls,e.__scopeMenu),l=Ue(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Fu,{bubbles:!0,cancelable:!0});f.addEventListener(Fu,h=>r==null?void 0:r(h),{once:!0}),xc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx($u,{...o,ref:l,disabled:n,onClick:ue(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:ue(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:ue(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Ki.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});cs.displayName=ls;var $u=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Yi(ls,n),a=Ru(n),l=v.useRef(null),c=Ue(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&h((m.textContent??"").trim())},[s.children]),u.jsx(Kr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(ov,{asChild:!0,...a,focusable:!r,children:u.jsx(Re.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ue(e.onPointerMove,Yr(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ue(e.onPointerLeave,Yr(m=>i.onItemLeave(m))),onFocus:ue(e.onFocus,()=>f(!0)),onBlur:ue(e.onBlur,()=>f(!1))})})})}),iw="MenuCheckboxItem",zu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Vu,{scope:e.__scopeMenu,checked:n,children:u.jsx(cs,{role:"menuitemcheckbox","aria-checked":us(n)?"mixed":n,...o,ref:t,"data-state":Qi(n),onSelect:ue(o.onSelect,()=>r==null?void 0:r(us(n)?!0:!n),{checkForDefaultPrevented:!1})})})});zu.displayName=iw;var Bu="MenuRadioGroup",[aw,lw]=er(Bu,{value:void 0,onValueChange:()=>{}}),Hu=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Rt(r);return u.jsx(aw,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Ji,{...o,ref:t})})});Hu.displayName=Bu;var Uu="MenuRadioItem",Wu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=lw(Uu,e.__scopeMenu),s=n===o.value;return u.jsx(Vu,{scope:e.__scopeMenu,checked:s,children:u.jsx(cs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Qi(s),onSelect:ue(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Wu.displayName=Uu;var Zi="MenuItemIndicator",[Vu,cw]=er(Zi,{checked:!1}),Ku=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=cw(Zi,n);return u.jsx(tn,{present:r||us(s.checked)||s.checked===!0,children:u.jsx(Re.span,{...o,ref:t,"data-state":Qi(s.checked)})})});Ku.displayName=Zi;var uw="MenuSeparator",qu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Re.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});qu.displayName=uw;var dw="MenuArrow",Gu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=as(n);return u.jsx(uu,{...o,...r,ref:t})});Gu.displayName=dw;var fw="MenuSub",[gT,Yu]=er(fw),Gr="MenuSubTrigger",Xu=v.forwardRef((e,t)=>{const n=tr(Gr,e.__scopeMenu),r=qr(Gr,e.__scopeMenu),o=Yu(Gr,e.__scopeMenu),s=Yi(Gr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(qi,{asChild:!0,...c,children:u.jsx($u,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Qu(n.open),...e,ref:yi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ue(e.onPointerMove,Yr(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:ue(e.onPointerLeave,Yr(f=>{var h,m;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const x=(m=n.content)==null?void 0:m.dataset.side,y=x==="right",g=y?-5:5,w=p[y?"left":"right"],S=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+g,y:f.clientY},{x:w,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:w,y:p.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ue(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||Kv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Xu.displayName=Gr;var Ju="MenuSubContent",Zu=v.forwardRef((e,t)=>{const n=Ou(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=tr(nn,e.__scopeMenu),i=qr(nn,e.__scopeMenu),a=Yu(Ju,e.__scopeMenu),l=v.useRef(null),c=Ue(t,l);return u.jsx(Kr.Provider,{scope:e.__scopeMenu,children:u.jsx(tn,{present:r||s.open,children:u.jsx(Kr.Slot,{scope:e.__scopeMenu,children:u.jsx(Xi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ue(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ue(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ue(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=qv[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Zu.displayName=Ju;function Qu(e){return e?"open":"closed"}function us(e){return e==="indeterminate"}function Qi(e){return us(e)?"indeterminate":e?"checked":"unchecked"}function pw(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function hw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function mw(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=hw(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function gw(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,p=l.y;d>r!=p>r&&n<(f-c)*(r-d)/(p-d)+c&&(o=!o)}return o}function xw(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return gw(n,t)}function Yr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var yw=Pu,vw=qi,ww=Mu,bw=Du,Sw=Ji,Cw=Lu,Tw=cs,kw=zu,Ew=Hu,Iw=Wu,Nw=Ku,Aw=qu,jw=Gu,_w=Xu,Rw=Zu,ds="DropdownMenu",[Pw,xT]=In(ds,[_u]),zt=_u(),[Ow,ed]=Pw(ds),td=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=zt(t),c=v.useRef(null),[d,f]=xr({prop:o,defaultProp:s??!1,onChange:i,caller:ds});return u.jsx(Ow,{scope:t,triggerId:Nn(),triggerRef:c,contentId:Nn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(yw,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};td.displayName=ds;var nd="DropdownMenuTrigger",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=ed(nd,n),i=zt(n);return u.jsx(vw,{asChild:!0,...i,children:u.jsx(Re.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:yi(t,s.triggerRef),onPointerDown:ue(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ue(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});rd.displayName=nd;var Mw="DropdownMenuPortal",od=e=>{const{__scopeDropdownMenu:t,...n}=e,r=zt(t);return u.jsx(ww,{...r,...n})};od.displayName=Mw;var sd="DropdownMenuContent",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=ed(sd,n),s=zt(n),i=v.useRef(!1);return u.jsx(bw,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ue(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ue(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});id.displayName=sd;var Dw="DropdownMenuGroup",Lw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Sw,{...o,...r,ref:t})});Lw.displayName=Dw;var Fw="DropdownMenuLabel",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Cw,{...o,...r,ref:t})});ad.displayName=Fw;var $w="DropdownMenuItem",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Tw,{...o,...r,ref:t})});ld.displayName=$w;var zw="DropdownMenuCheckboxItem",cd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(kw,{...o,...r,ref:t})});cd.displayName=zw;var Bw="DropdownMenuRadioGroup",Hw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Ew,{...o,...r,ref:t})});Hw.displayName=Bw;var Uw="DropdownMenuRadioItem",ud=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Iw,{...o,...r,ref:t})});ud.displayName=Uw;var Ww="DropdownMenuItemIndicator",dd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Nw,{...o,...r,ref:t})});dd.displayName=Ww;var Vw="DropdownMenuSeparator",fd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Aw,{...o,...r,ref:t})});fd.displayName=Vw;var Kw="DropdownMenuArrow",qw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(jw,{...o,...r,ref:t})});qw.displayName=Kw;var Gw="DropdownMenuSubTrigger",pd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(_w,{...o,...r,ref:t})});pd.displayName=Gw;var Yw="DropdownMenuSubContent",hd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=zt(n);return u.jsx(Rw,{...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)"}})});hd.displayName=Yw;var Xw=td,Jw=rd,Zw=od,md=id,gd=ad,xd=ld,yd=cd,vd=ud,wd=dd,bd=fd,Sd=pd,Cd=hd;const Qw=Xw,eb=Jw,tb=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(Sd,{ref:o,className:Z("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(oe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));tb.displayName=Sd.displayName;const nb=v.forwardRef(({className:e,...t},n)=>u.jsx(Cd,{ref:n,className:Z("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));nb.displayName=Cd.displayName;const Td=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Zw,{children:u.jsx(md,{ref:r,sideOffset:t,className:Z("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Td.displayName=md.displayName;const ea=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(xd,{ref:r,className:Z("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));ea.displayName=xd.displayName;const rb=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(yd,{ref:o,className:Z("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wd,{children:u.jsx(oe.Check,{className:"h-4 w-4"})})}),t]}));rb.displayName=yd.displayName;const ob=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vd,{ref:r,className:Z("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wd,{children:u.jsx(oe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));ob.displayName=vd.displayName;const sb=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(gd,{ref:r,className:Z("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));sb.displayName=gd.displayName;const ib=v.forwardRef(({className:e,...t},n)=>u.jsx(bd,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));ib.displayName=bd.displayName;const fs=1e4;function ab(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
79
79
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
80
80
|
|
|
81
81
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -83,11 +83,11 @@ React keys must be passed directly to JSX without using spread:
|
|
|
83
83
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
84
84
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
85
85
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
86
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function lb(e,t=fs){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function cb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),lb(t),ab(t)}const ps=0,Ln=1,Er=2,kd=4;function Ed(e){return()=>e}function ub(e){e()}function Id(e,t){return n=>e(t(n))}function Nd(e,t){return()=>e(t)}function db(e,t){return n=>e(t,n)}function ta(e){return e!==void 0}function fb(...e){return()=>{e.map(ub)}}function Ir(){}function hs(e,t){return t(e),e}function pb(e,t){return t(e)}function pt(...e){return e}function rt(e,t){return e(Ln,t)}function Me(e,t){e(ps,t)}function na(e){e(Er)}function bt(e){return e(kd)}function ge(e,t){return rt(e,db(t,ps))}function fn(e,t){const n=e(Ln,r=>{n(),t(r)});return n}function Ad(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function jd(e,t){return e===t}function ht(e=jd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Te(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>Id(t,e)}function Sn(e){return t=>()=>{t(e)}}function U(e,...t){const n=hb(...t);return(r,o)=>{switch(r){case Er:na(e);return;case Ln:return rt(e,n(o))}}}function Cn(e,t){return n=>r=>{n(t=e(t,r))}}function nr(e){return t=>n=>{e>0?e--:t(n)}}function _n(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Le(...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);rt(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function hb(...e){return t=>e.reduceRight(pb,t)}function mb(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Ln:return s?n===s?void 0:(r(),n=s,t=rt(e,s),t):(r(),Ir);case Er:r(),n=null;return}}}function Y(e){let t=e;const n=We();return(r,o)=>{switch(r){case ps:t=o;break;case Ln:{o(t);break}case kd:return t}return n(r,o)}}function Dt(e,t){return hs(Y(t),n=>ge(e,n))}function We(){const e=[];return(t,n)=>{switch(t){case ps:e.slice().forEach(r=>{r(n)});return;case Er:e.splice(0,e.length);return;case Ln:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Xt(e){return hs(We(),t=>ge(e,t))}function Je(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:gb(),singleton:n}}const gb=()=>Symbol();function xb(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 kt(...e){const t=We(),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);rt(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case Er:{na(t);return}case Ln:return r===o&&i(n),rt(t,i)}}}function Ce(e,t=jd){return U(e,ht(t))}function ra(...e){return function(t,n){switch(t){case Er:return;case Ln:return fb(...e.map(r=>rt(r,n)))}}}var Vt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Vt||{});const yb={0:"debug",3:"error",1:"log",2:"warn"},vb=()=>typeof globalThis>"u"?window:globalThis,Fn=Je(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=vb().VIRTUOSO_LOG_LEVEL)!=null?o:bt(e);r>=s&&console[yb[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function rr(e,t,n){return oa(e,t,n).callbackRef}function oa(e,t,n){const r=b.useRef(null);let o=i=>{};const s=b.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function wb(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const f=bb(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const h=p.lastElementChild.dataset.viewportType==="window";let m;h&&(m=p.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:h?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,g=i?a?i.offsetWidth:i.offsetHeight:h?a?m.innerWidth:m.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(x,0),viewportHeight:g}),s==null||s(a?_d("column-gap",getComputedStyle(d).columnGap,o):_d("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return oa(c,n,l)}function bb(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Vt.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function _d(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Vt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Rd(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),m=c.top-h.top;p=h.height-Math.max(0,m),f=m+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=oa(o,!0,n),a=b.useCallback(()=>{o(i.current)},[o,i]);return b.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Bt=Je(()=>{const e=We(),t=We(),n=Y(0),r=We(),o=Y(0),s=We(),i=We(),a=Y(0),l=Y(0),c=Y(0),d=Y(0),f=We(),p=We(),h=Y(!1),m=Y(!1),x=Y(!1);return ge(U(e,le(({scrollTop:y})=>y)),t),ge(U(e,le(({scrollHeight:y})=>y)),i),ge(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Xr={lvl:0};function Pd(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 ct(e){return e===Xr}function Jr(e,t){if(!ct(e))return t===e.k?e.v:t<e.k?Jr(e.l,t):Jr(e.r,t)}function pn(e,t,n="k"){if(ct(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=pn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return pn(e.l,t,n)}function Jt(e,t,n){return ct(e)?Dd(t,n,1):t===e.k?It(e,{k:t,v:n}):t<e.k?Ld(It(e,{l:Jt(e.l,t,n)})):Ld(It(e,{r:Jt(e.r,t,n)}))}function Nr(){return Xr}function ms(e,t,n){if(ct(e))return[];const r=pn(e,t)[0];return Sb(ia(e,r,n))}function sa(e,t){if(ct(e))return Xr;const{k:n,l:r,r:o}=e;if(t===n){if(ct(r))return o;if(ct(o))return r;{const[s,i]=Md(r);return gs(It(e,{k:s,l:Od(r),v:i}))}}else return t<n?gs(It(e,{l:sa(r,t)})):gs(It(e,{r:sa(o,t)}))}function or(e){return ct(e)?[]:[...or(e.l),{k:e.k,v:e.v},...or(e.r)]}function ia(e,t,n){if(ct(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ia(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ia(s,t,n))),a}function gs(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(aa(t))return Fd(It(e,{lvl:n-1}));if(!ct(t)&&!ct(t.r))return It(t.r,{l:It(t,{r:t.r.l}),lvl:n,r:It(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(aa(e))return la(It(e,{lvl:n-1}));if(!ct(r)&&!ct(r.l)){const o=r.l,s=aa(o)?r.lvl-1:r.lvl;return It(o,{l:It(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:la(It(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function It(e,t){return Dd(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 Od(e){return ct(e.r)?e.l:gs(It(e,{r:Od(e.r)}))}function aa(e){return ct(e)||e.lvl>e.r.lvl}function Md(e){return ct(e.r)?[e.k,e.v]:Md(e.r)}function Dd(e,t,n,r=Xr,o=Xr){return{k:e,l:r,lvl:n,r:o,v:t}}function Ld(e){return la(Fd(e))}function Fd(e){const{l:t}=e;return!ct(t)&&t.lvl===e.lvl?It(t,{r:It(e,{l:t.r})}):e}function la(e){const{lvl:t,r:n}=e;return!ct(n)&&!ct(n.r)&&n.lvl===t&&n.r.lvl===t?It(n,{l:It(e,{r:n.l}),lvl:t+1}):e}function Sb(e){return Pd(e,({k:t,v:n})=>({index:t,value:n}))}function $d(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Zr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ca=Je(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function zd(e,t,n){return e[xs(e,t,n)]}function xs(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 Cb(e,t,n,r){const o=xs(e,t,r),s=xs(e,n,r,o);return e.slice(o,s+1)}function $n(e,t){return Math.round(e.getBoundingClientRect()[t])}function ys(e){return!ct(e.groupOffsetTree)}function ua({index:e},t){return t===e?0:t<e?-1:1}function Tb(){return{groupIndices:[],groupOffsetTree:Nr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Nr()}}function kb(e,t){let n=ct(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ct(e)){e=Jt(e,0,s);continue}const a=ms(e,i-1,o+1);if(a.some(Rb(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=sa(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Jt(e,o+1,p));c&&(e=Jt(e,i,s))}return[e,n]}function Eb(e){return typeof e.groupIndex<"u"}function Ib({offset:e},t){return t===e?0:t<e?-1:1}function Qr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=zd(t,e,ua),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Bd(e,t){if(!ys(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Hd(e,t,n){if(Eb(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Bd(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Nb(e,t,n,r=0){return r>0&&(t=Math.max(t,zd(e,r,ua).offset)),Pd(Cb(e,t,n,Ib),_b)}function Ab(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Vt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ct(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((m,x)=>Jt(Jt(m,x,p),x+1,h),i)}else[i,a]=kb(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=da(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Jt(p,h,Qr(h,f,o)),Nr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function jb(e){return or(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 Ud(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 da(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=xs(o,t-1,ua),a=o[l].offset;const c=pn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===pn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of ms(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function _b(e){return{index:e.index,value:e}}function Rb(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 Pb={offsetHeight:"height",offsetWidth:"width"},Tn=Je(([{log:e},{recalcInProgress:t}])=>{const n=We(),r=We(),o=Dt(r,0),s=We(),i=We(),a=Y(0),l=Y([]),c=Y(void 0),d=Y(void 0),f=Y((T,C)=>$n(T,Pb[C])),p=Y(void 0),h=Y(0),m=Tb(),x=Dt(U(n,Le(l,e,h),Cn(Ab,m),ht()),m),y=Dt(U(l,ht(),Cn((T,C)=>({current:C,prev:T.current}),{current:[],prev:[]}),le(({prev:T})=>T)),[]);ge(U(l,Te(T=>T.length>0),Le(x,h),le(([T,C,E])=>{const j=T.reduce((N,A,O)=>Jt(N,A,Qr(A,C.offsetTree,E)||O),Nr());return{...C,groupIndices:T,groupOffsetTree:j}})),x),ge(U(r,Le(x),Te(([T,{lastIndex:C}])=>T<C),le(([T,{lastIndex:C,lastSize:E}])=>[{endIndex:C,size:E,startIndex:T}])),n),ge(c,d);const g=Dt(U(c,le(T=>T===void 0)),!0);ge(U(d,Te(T=>T!==void 0&&ct(bt(x).sizeTree)),le(T=>[{endIndex:0,size:T,startIndex:0}])),n);const w=Xt(U(n,Le(x),Cn(({sizes:T},[C,E])=>({changed:E!==T,sizes:E}),{changed:!1,sizes:m}),le(T=>T.changed)));rt(U(a,Cn((T,C)=>({diff:T.prev-C,prev:C}),{diff:0,prev:0}),le(T=>T.diff)),T=>{const{groupIndices:C}=bt(x);if(T>0)Me(t,!0),Me(s,T+Ud(T,C));else if(T<0){const E=bt(y);E.length>0&&(T-=Ud(-T,E)),Me(i,T)}}),rt(U(a,Le(e)),([T,C])=>{T<0&&C("`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},Vt.ERROR)});const S=Xt(s);ge(U(s,Le(x),le(([T,C])=>{const E=C.groupIndices.length>0,j=[],N=C.lastSize;if(E){const A=Jr(C.sizeTree,0);let O=0,F=0;for(;O<T;){const R=C.groupIndices[F],z=C.groupIndices.length===F+1?1/0:C.groupIndices[F+1]-R-1;j.push({endIndex:R,size:A,startIndex:R}),j.push({endIndex:R+1+z-1,size:N,startIndex:R+1}),F++,O+=z+1}const $=or(C.sizeTree);return O!==T&&$.shift(),$.reduce((R,{k:z,v:_})=>{let B=R.ranges;return R.prevSize!==0&&(B=[...R.ranges,{endIndex:z+T-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:z+T,prevSize:_,ranges:B}},{prevIndex:T,prevSize:0,ranges:j}).ranges}return or(C.sizeTree).reduce((A,{k:O,v:F})=>({prevIndex:O+T,prevSize:F,ranges:[...A.ranges,{endIndex:O+T-1,size:A.prevSize,startIndex:A.prevIndex}]}),{prevIndex:0,prevSize:N,ranges:[]}).ranges})),n);const k=Xt(U(i,Le(x,h),le(([T,{offsetTree:C},E])=>{const j=-T;return Qr(j,C,E)})));return ge(U(i,Le(x,h),le(([T,C,E])=>{if(C.groupIndices.length>0){if(ct(C.sizeTree))return C;let j=Nr();const N=bt(y);let A=0,O=0,F=0;for(;A<-T;){F=N[O];const $=N[O+1]-F-1;O++,A+=$+1}if(j=or(C.sizeTree).reduce(($,{k:R,v:z})=>Jt($,Math.max(0,R+T),z),j),A!==-T){const $=Jr(C.sizeTree,F);j=Jt(j,0,$);const R=pn(C.sizeTree,-T+1)[1];j=Jt(j,1,R)}return{...C,sizeTree:j,...da(C.offsetTree,0,j,E)}}else{const j=or(C.sizeTree).reduce((N,{k:A,v:O})=>Jt(N,Math.max(0,A+T),O),Nr());return{...C,sizeTree:j,...da(C.offsetTree,0,j,E)}}})),x),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:g,unshiftWith:s}},pt(Fn,ca),{singleton:!0});function Ob(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Wd=Je(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=We(),i=We(),a=Xt(U(s,le(Ob)));return ge(U(a,le(l=>l.totalCount)),n),ge(U(a,le(l=>l.groupIndices)),e),ge(U(kt(o,t,r),Te(([l,c])=>ys(c)),le(([l,c,d])=>pn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ht(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},pt(Tn,Bt)),zn=Je(([{log:e}])=>{const t=Y(!1),n=Xt(U(t,Te(r=>r),ht()));return rt(t,r=>{r&&bt(e)("props updated",{},Vt.DEBUG)}),{didMount:n,propsReady:t}},pt(Fn),{singleton:!0}),Mb=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Vd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Mb)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const eo=Je(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=We(),m=We(),x=Y(0);let y=null,g=null,w=null;function S(){y&&(y(),y=null),w&&(w(),w=null),g&&(clearTimeout(g),g=null),Me(l,!1)}return ge(U(h,Le(n,f,r,x,a,i,p),Le(e,s,o),le(([[k,T,C,E,j,N,A,O],F,$,R])=>{const z=Vd(k),{align:_,behavior:B,offset:L}=z,M=E-1,J=Hd(z,T,M);let X=Qr(J,T.offsetTree,F)+N;_==="end"?(X+=$+pn(T.sizeTree,J)[1]-C+R,J===M&&(X+=A)):_==="center"?X+=($+pn(T.sizeTree,J)[1]-C+R)/2:X-=j,L&&(X+=L);const he=Ne=>{S(),Ne?(O("retrying to scroll to",{location:k},Vt.DEBUG),Me(h,k)):(Me(m,!0),O("list did not change, scroll successful",{},Vt.DEBUG))};if(S(),B==="smooth"){let Ne=!1;w=rt(t,_e=>{Ne=Ne||_e}),y=fn(d,()=>{he(Ne)})}else y=fn(U(t,Db(150)),he);return g=setTimeout(()=>{S()},1200),Me(l,!0),O("scrolling from index to",{behavior:B,index:J,top:X},Vt.DEBUG),{behavior:B,top:X}})),c),{scrollTargetReached:m,scrollToIndex:h,topListHeight:x}},pt(Tn,Bt,Fn),{singleton:!0});function Db(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function fa(e,t){e==0?t():requestAnimationFrame(()=>{fa(e-1,t)})}function pa(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const to=Je(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Y(!0),l=Y(0),c=Y(!0);return ge(U(i,Le(l),Te(([d,f])=>!!f),Sn(!1)),a),ge(U(i,Le(l),Te(([d,f])=>!!f),Sn(!1)),c),rt(U(kt(t,i),Le(a,n,e,c),Te(([[,d],f,{sizeTree:p},h,m])=>d&&(!ct(p)||ta(h))&&!f&&!m),Le(l)),([,d])=>{fn(o,()=>{Me(c,!0)}),fa(4,()=>{fn(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},pt(Tn,Bt,eo,zn),{singleton:!0});function Kd(e,t){return Math.abs(e-t)<1.01}const no="up",ro="down",Lb="none",Fb={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},$b=0,oo=Je(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=We(),c=We(),d=Y(4),f=Y($b),p=Dt(U(ra(U(Ce(o),nr(1),Sn(!0)),U(Ce(o),nr(1),Sn(!1),Ad(100))),ht()),!1),h=Dt(U(ra(U(n,Sn(!0)),U(n,Sn(!1),Ad(200))),ht()),!1);ge(U(kt(Ce(o),Ce(f)),le(([w,S])=>w<=S),ht()),a),ge(U(a,_n(50)),c);const m=Xt(U(kt(r,Ce(s),Ce(t),Ce(e),Ce(d)),Cn((w,[{scrollHeight:S,scrollTop:k},T,C,E,j])=>{const N=k+T-S>-j,A={scrollHeight:S,scrollTop:k,viewportHeight:T};if(N){let F,$;return k>w.state.scrollTop?(F="SCROLLED_DOWN",$=w.state.scrollTop-k):(F="SIZE_DECREASED",$=w.state.scrollTop-k||w.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:$,state:A}}let O;return A.scrollHeight>w.state.scrollHeight?O="SIZE_INCREASED":T<w.state.viewportHeight?O="VIEWPORT_HEIGHT_DECREASING":k<w.state.scrollTop?O="SCROLLING_UPWARDS":O="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:O,state:A}},Fb),ht((w,S)=>w&&w.atBottom===S.atBottom))),x=Dt(U(r,Cn((w,{scrollHeight:S,scrollTop:k,viewportHeight:T})=>{if(Kd(w.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const C=S-(k+T)<1;return w.scrollTop!==k&&C?{changed:!0,jump:w.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Te(w=>w.changed),le(w=>w.jump)),0);ge(U(m,le(w=>w.atBottom)),i),ge(U(i,_n(50)),l);const y=Y(ro);ge(U(r,le(({scrollTop:w})=>w),ht(),Cn((w,S)=>bt(h)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?no:ro,prevScrollTop:S},{direction:ro,prevScrollTop:0}),le(w=>w.direction)),y),ge(U(r,_n(50),Sn(Lb)),y);const g=Y(0);return ge(U(p,Te(w=>!w),Sn(0)),g),ge(U(o,_n(100),Le(p),Te(([w,S])=>!!S),Cn(([w,S],[k])=>[S,k],[0,0]),le(([w,S])=>S-w)),g),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:x,scrollDirection:y,scrollVelocity:g}},pt(Bt)),vs="top",ws="bottom",qd="none";function Gd(e,t,n){return typeof e=="number"?n===no&&t===vs||n===ro&&t===ws?e:0:n===no?t===vs?e.main:e.reverse:t===ws?e.main:e.reverse}function Yd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ha=Je(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=We(),i=Y(0),a=Y(0),l=Y(0),c=Dt(U(kt(Ce(r),Ce(o),Ce(n),Ce(s,Zr),Ce(l),Ce(i),Ce(t),Ce(e),Ce(a)),le(([d,f,p,[h,m],x,y,g,w,S])=>{const k=d-w,T=y+g,C=Math.max(p-k,0);let E=qd;const j=Yd(S,vs),N=Yd(S,ws);return h-=w,h+=p+g,m+=p+g,m-=w,h>d+T-j&&(E=no),m<d-C+f+N&&(E=ro),E!==qd?[Math.max(k-p-Gd(x,vs,E)-j,0),k-C-g+f+Gd(x,ws,E)+N]:null}),Te(d=>d!=null),ht(Zr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},pt(Bt),{singleton:!0});function zb(e,t,n){if(ys(t)){const r=Bd(e,t);return[{index:pn(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 ma={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function bs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,m=p-d;return{bottom:d,firstItemIndex:s,items:Jd(e,o,s),offsetBottom:m,offsetTop:c,top:h,topItems:Jd(t,o,s),topListHeight:t.reduce((x,y)=>y.size+x,0),totalCount:n}}function Xd(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=pa(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return bs(c,[],a,o,n,r)}function Jd(e,t,n){if(e.length===0)return[];if(!ys(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=ms(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const sr=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:m}])=>{const x=Y([]),y=Y(0),g=We();ge(s.topItemsIndexes,x);const w=Dt(U(kt(h,m,Ce(l,Zr),Ce(o),Ce(r),Ce(c),d,Ce(x),Ce(t),Ce(n),e),Te(([C,E,,j,,,,,,,N])=>{const A=N&&N.length!==j;return C&&!E&&!A}),le(([,,[C,E],j,N,A,O,F,$,R,z])=>{const _=N,{offsetTree:B,sizeTree:L}=_,M=bt(y);if(j===0)return{...ma,totalCount:j};if(C===0&&E===0)return M===0?{...ma,totalCount:j}:Xd(M,A,N,$,R,z||[]);if(ct(L))return M>0?null:bs(zb(pa(A,j),_,z),[],j,R,_,$);const J=[];if(F.length>0){const V=F[0],ee=F[F.length-1];let q=0;for(const D of ms(L,V,ee)){const H=D.value,te=Math.max(D.start,V),se=Math.min(D.end,ee);for(let ne=te;ne<=se;ne++)J.push({data:z==null?void 0:z[ne],index:ne,offset:q,size:H}),q+=H}}if(!O)return bs([],J,j,R,_,$);const X=F.length>0?F[F.length-1]+1:0,he=Nb(B,C,E,X);if(he.length===0)return null;const Ne=j-1,_e=hs([],V=>{for(const ee of he){const q=ee.value;let D=q.offset,H=ee.start;const te=q.size;if(q.offset<C){H+=Math.floor((C-q.offset+R)/(te+R));const ne=H-ee.start;D+=ne*te+ne*R}H<X&&(D+=(X-H)*te,H=X);const se=Math.min(ee.end,Ne);for(let ne=H;ne<=se&&!(D>=E);ne++)V.push({data:z==null?void 0:z[ne],index:ne,offset:D,size:te}),D+=te+R}});return bs(_e,J,j,R,_,$)}),Te(C=>C!==null),ht()),ma);ge(U(e,Te(ta),le(C=>C==null?void 0:C.length)),o),ge(U(w,le(C=>C.topListHeight)),f),ge(f,a),ge(U(w,le(C=>[C.top,C.bottom])),i),ge(U(w,le(C=>C.items)),g);const S=Xt(U(w,Te(({items:C})=>C.length>0),Le(o,e),Te(([{items:C},E])=>C[C.length-1].originalIndex===E-1),le(([,C,E])=>[C-1,E]),ht(Zr),le(([C])=>C))),k=Xt(U(w,_n(200),Te(({items:C,topItems:E})=>C.length>0&&C[0].originalIndex===E.length),le(({items:C})=>C[0].index),ht())),T=Xt(U(w,Te(({items:C})=>C.length>0),le(({items:C})=>{let E=0,j=C.length-1;for(;C[E].type==="group"&&E<j;)E++;for(;C[j].type==="group"&&j>E;)j--;return{endIndex:C[j].index,startIndex:C[E].index}}),ht($d)));return{endReached:S,initialItemCount:y,itemsRendered:g,listState:w,rangeChanged:T,startReached:k,topItemsIndexes:x,...p}},pt(Tn,Wd,ha,to,eo,oo,zn,ca),{singleton:!0}),Zd=Je(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=We(),i=Dt(U(kt(n,e,r,t,o),le(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ge(Ce(i),s),{totalListHeight:i,totalListHeightChanged:s}},pt(Bt,sr),{singleton:!0}),Bb=Je(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=Dt(U(kt(n,e,t),Te(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),_n(0),ht()),0);return{alignToBottom:n,paddingTopAddition:r}},pt(Bt,Zd),{singleton:!0}),Qd=Je(()=>({context:Y(null)})),Hb=({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,ef=Je(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=We();return ge(U(d,Le(t,l,n,s,o,r,a),Le(e),le(([[f,p,h,m,x,y,g,w],S])=>{const{align:k,behavior:T,calculateViewLocation:C=Hb,done:E,...j}=f,N=Hd(f,p,m-1),A=Qr(N,p.offsetTree,S)+x+y,O=A+pn(p.sizeTree,N)[1],F=w+y,$=w+h-g,R=C({itemBottom:O,itemTop:A,locationParams:{align:k,behavior:T,...j},viewportBottom:$,viewportTop:F});return R?E&&fn(U(i,Te(z=>!z),nr(bt(i)?1:2)),E):E&&E(),R}),Te(f=>f!==null)),c),{scrollIntoView:d}},pt(Tn,Bt,eo,sr,Fn),{singleton:!0});function tf(e){return e?e==="smooth"?"smooth":"auto":!1}const Ub=(e,t)=>typeof e=="function"?tf(e(t)):t&&tf(e),Wb=Je(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const m=Y(!1),x=We();let y=null;function g(T){Me(i,{align:"end",behavior:T,index:"LAST"})}rt(U(kt(U(Ce(t),nr(1)),l),Le(Ce(m),s,a,f),le(([[T,C],E,j,N,A])=>{let O=C&&N,F="auto";return O&&(F=Ub(E,j||A),O=O&&!!F),{followOutputBehavior:F,shouldFollow:O,totalCount:T}}),Te(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:C})=>{y&&(y(),y=null),bt(n)?requestAnimationFrame(()=>{bt(d)("following output to ",{totalCount:C},Vt.DEBUG),g(T)}):y=fn(e,()=>{bt(d)("following output to ",{totalCount:C},Vt.DEBUG),g(T),y=null})});function w(T){const C=fn(o,E=>{T&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(bt(d)("scrolling to bottom due to increased size",{},Vt.DEBUG),g("auto"))});setTimeout(C,100)}rt(U(kt(Ce(m),t,c),Te(([T,,C])=>T&&C),Cn(({value:T},[,C])=>({refreshed:T===C,value:C}),{refreshed:!1,value:0}),Te(({refreshed:T})=>T),Le(m,t)),([,T])=>{bt(a)&&w(T!==!1)}),rt(x,()=>{w(bt(m)!==!1)}),rt(kt(Ce(m),o),([T,C])=>{T&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=Y(null),k=We();return ge(ra(U(Ce(r),le(T=>{var C;return(C=T==null?void 0:T.length)!=null?C:0})),U(Ce(t))),k),rt(U(kt(U(k,nr(1)),l),Le(Ce(S),a,f,p),le(([[T,C],E,j,N,A])=>C&&j&&(E==null?void 0:E({context:A,totalCount:T,scrollingInProgress:N}))),Te(T=>!!T),_n(0)),T=>{y&&(y(),y=null),bt(n)?requestAnimationFrame(()=>{bt(d)("scrolling into view",{}),Me(h,T)}):y=fn(e,()=>{bt(d)("scrolling into view",{}),Me(h,T),y=null})}),{autoscrollToBottom:x,followOutput:m,scrollIntoViewOnChange:S}},pt(Tn,oo,eo,to,zn,Fn,Bt,Qd,ef)),Vb=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ge(U(a,Le(s),Te(([,l])=>l!==0),Le(o,r,t,n,e),le(([[,l],c,d,f,p,h=[]])=>Xd(l,c,d,f,p,h))),i),{}),pt(Tn,to,sr,zn),{singleton:!0}),Kb=Je(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return rt(U(e,Le(r),Te(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{fn(U(n,nr(1),Te(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},pt(zn,Bt,sr),{singleton:!0}),nf=Je(([{scrollVelocity:e}])=>{const t=Y(!1),n=We(),r=Y(!1);return ge(U(e,Le(r,t,n),Te(([o,s])=>!!s),le(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ht()),t),rt(U(kt(t,e,n),Le(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},pt(oo),{singleton:!0}),ga=Je(([{scrollContainerState:e,scrollTo:t}])=>{const n=We(),r=We(),o=We(),s=Y(!1),i=Y(void 0);return ge(U(kt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ge(U(t,Le(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},pt(Bt)),qb=Je(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=We(),d=Y(void 0),f=Y(null),p=Y(null);return ge(a,f),ge(l,p),rt(U(c,Le(t,r,i,f,p,n)),([h,m,x,y,g,w,S])=>{const k=jb(m.sizeTree);y&&g!==null&&w!==null&&(x=g.scrollTop-w.offsetTop),x-=S,h({ranges:k,scrollTop:x})}),ge(U(d,Te(ta),le(Gb)),o),ge(U(s,Le(d),Te(([,h])=>h!==void 0),ht(),le(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},pt(Tn,Bt,to,zn,ga));function Gb(e){return{align:"start",index:0,offset:e.scrollTop}}const Yb=Je(([{topItemsIndexes:e}])=>{const t=Y(0);return ge(U(t,Te(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},pt(sr));function rf(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Xb=rf(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Jb=Je(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:m}])=>{const x=Xt(U(l,Le(i),Cn(([,g,w,S],[{bottom:k,items:T,offsetBottom:C,totalCount:E},j])=>{const N=k+C;let A=0;return w===E&&g.length>0&&T.length>0&&(T[0].originalIndex===0&&g[0].originalIndex===0||(A=N-S,A!==0&&(A+=j))),[A,T,E,N]},[0,[],0,0]),Te(([g])=>g!==0),Le(r,a,n,o,h,m),Te(([,g,w,S,,,k])=>!k&&!S&&g!==0&&w===no),le(([[g],,,,,w])=>(w("Upward scrolling compensation",{amount:g},Vt.DEBUG),g))));function y(g){g>0?(Me(t,{behavior:"auto",top:-g}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-g}))}return rt(U(x,Le(e,s)),([g,w,S])=>{S&&Xb()?Me(e,w-g):y(-g)}),rt(U(kt(Dt(s,!1),e,m),Te(([g,w,S])=>!g&&!S&&w!==0),le(([g,w])=>w),_n(1)),y),ge(U(f,le(g=>({top:-g}))),t),rt(U(c,Le(p,d),le(([g,{groupIndices:w,lastSize:S,sizeTree:k},T])=>{function C(E){return E*(S+T)}if(w.length===0)return C(g);{let E=0;const j=Jr(k,0);let N=0,A=0;for(;N<g;){N++,E+=j;let O=w.length===A+1?1/0:w[A+1]-w[A]-1;N+O>g&&(E-=j,O=g-N+1),N+=O,E+=C(O),A++}return E}})),g=>{Me(e,g),requestAnimationFrame(()=>{Me(t,{top:g}),requestAnimationFrame(()=>{Me(e,0),Me(m,!1)})})}),{deviation:e}},pt(Bt,oo,sr,Tn,Fn,ca)),Zb=Je(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),pt(ha,Vb,zn,nf,Zd,Kb,Bb,ga,ef,Fn,Qd)),of=Je(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m},x,y,g,{listState:w,topItemsIndexes:S,...k},{scrollToIndex:T},C,{topItemCount:E},{groupCounts:j},N])=>(ge(k.rangeChanged,N.scrollSeekRangeChanged),ge(U(N.windowViewportRect,le(A=>A.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:j,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...g,groupIndices:s,itemSize:i,listState:w,scrollToIndex:T,statefulTotalCount:c,trackItemSizes:f,...k,...N,...x,sizes:l,...y}),pt(Tn,to,Bt,qb,Wb,sr,eo,Jb,Yb,Wd,Zb));function Qb(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 Ss=typeof document<"u"?b.useLayoutEffect:b.useEffect;function sf(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=b.createContext({});function l(y,g){y.propsReady&&Me(y.propsReady,!1);for(const w of r){const S=y[t.required[w]];Me(S,g[w])}for(const w of o)if(w in g){const S=y[t.optional[w]];Me(S,g[w])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((g,w)=>(g[w]=S=>{const k=y[t.methods[w]];Me(k,S)},g),{})}function d(y){return i.reduce((g,w)=>(g[w]=mb(y[t.events[w]]),g),{})}const f=b.forwardRef((y,g)=>{const{children:w,...S}=y,[k]=b.useState(()=>hs(xb(e),E=>{l(E,S)})),[T]=b.useState(Nd(d,k));Ss(()=>{for(const E of i)E in S&&rt(T[E],S[E]);return()=>{Object.values(T).map(na)}},[S,T,k]),Ss(()=>{l(k,S)}),b.useImperativeHandle(g,Ed(c(k)));const C=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(C,{...Qb([...r,...o,...i],S),children:w}):w})}),p=y=>{const g=b.useContext(a);return b.useCallback(w=>{Me(g[y],w)},[g,y])},h=y=>{const g=b.useContext(a)[y],w=b.useCallback(S=>rt(g,S),[g]);return b.useSyncExternalStore(w,()=>bt(g),()=>bt(g))},m=y=>{const g=b.useContext(a)[y],[w,S]=b.useState(Nd(bt,g));return Ss(()=>rt(g,k=>{k!==w&&S(Ed(k))}),[g,w]),w},x=b.version.startsWith("18")?h:m;return{Component:f,useEmitter:(y,g)=>{const w=b.useContext(a)[y];Ss(()=>rt(w,g),[g,w])},useEmitterValue:x,usePublisher:p}}const af=b.createContext(void 0),lf=b.createContext(void 0),cf=typeof document<"u"?b.useLayoutEffect:b.useEffect;function xa(e){return"self"in e}function e0(e){return"body"in e}function uf(e,t,n,r=Ir,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(p=>{let h,m,x;const y=p.target;if(e0(y)||xa(y)){const w=xa(y)?y:y.defaultView;x=s?w.scrollX:w.scrollY,h=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else x=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const g=()=>{e({scrollHeight:h,scrollTop:Math.max(x,0),viewportHeight:m})};p.suppressFlushSync?g():Js.flushSync(g),a.current!==null&&(x===a.current||x<=0||x===h-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const m=p.behavior==="smooth";let x,y,g;xa(h)?(y=Math.max($n(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),x=s?h.innerWidth:h.innerHeight,g=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],x=$n(h,s?"width":"height"),g=h[s?"scrollLeft":"scrollTop"]);const w=y-x;if(p.top=Math.ceil(Math.max(Math.min(w,p.top),0)),Kd(x,y)||p.top===g){e({scrollHeight:y,scrollTop:g,viewportHeight:x}),m&&t(!0);return}m?(a.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),h.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ya="-webkit-sticky",df="sticky",va=rf(()=>{if(typeof document>"u")return df;const e=document.createElement("div");return e.style.position=ya,e.style.position===ya?ya:df});function wa(e){return e}const t0=Je(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(wa),o=Y("div"),s=Y(Ir),i=(a,l=null)=>Dt(U(n,le(c=>c[a]),ht()),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")}}),n0=Je(([e,t])=>({...e,...t}),pt(of,t0)),r0=({height:e})=>u.jsx("div",{style:{height:e}}),o0={overflowAnchor:"none",position:va(),zIndex:1},ff={overflowAnchor:"none"},s0={...ff,display:"inline-block",height:"100%"},pf=b.memo(function({showTopList:e=!1}){const t=je("listState"),n=rn("sizeRanges"),r=je("useWindowScroll"),o=je("customScrollParent"),s=rn("windowScrollContainerState"),i=rn("scrollContainerState"),a=o||r?s:i,l=je("itemContent"),c=je("context"),d=je("groupContent"),f=je("trackItemSizes"),p=je("itemSize"),h=je("log"),m=rn("gap"),x=je("horizontalDirection"),{callbackRef:y}=wb(n,p,f,e?Ir:a,h,m,o,x,je("skipAnimationFrameInResizeObserver")),[g,w]=b.useState(0);ba("deviation",R=>{g!==R&&w(R)});const S=je("EmptyPlaceholder"),k=je("ScrollSeekPlaceholder")||r0,T=je("ListComponent"),C=je("ItemComponent"),E=je("GroupComponent"),j=je("computeItemKey"),N=je("isSeeking"),A=je("groupIndices").length>0,O=je("alignToBottom"),F=je("initialItemFinalLocationReached"),$=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:g!==0?g:O?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:O?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Lt(S,c)}):u.jsx(T,{...Lt(T,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:$,children:(e?t.topItems:t.items).map(R=>{const z=R.originalIndex,_=j(z+t.firstItemIndex,R.data,c);return N?b.createElement(k,{...Lt(k,c),height:R.size,index:R.index,key:_,type:R.type||"item",...R.type==="group"?{}:{groupIndex:R.groupIndex}}):R.type==="group"?b.createElement(E,{...Lt(E,c),"data-index":z,"data-item-index":R.index,"data-known-size":R.size,key:_,style:o0},d(R.index,c)):b.createElement(C,{...Lt(C,c),...c0(C,R.data),"data-index":z,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:_,style:x?s0:ff},A?l(R.index,R.groupIndex,R.data,c):l(R.index,R.data,c))})})}),i0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},a0={outline:"none",overflowX:"auto",position:"relative"},Cs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),l0={position:va(),top:0,width:"100%",zIndex:1};function Lt(e,t){if(typeof e!="string")return{context:t}}function c0(e,t){return{item:typeof e=="string"?void 0:t}}const u0=b.memo(function(){const e=je("HeaderComponent"),t=rn("headerHeight"),n=je("HeaderFooterTag"),r=rr(b.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Lt(e,o)})}):null}),d0=b.memo(function(){const e=je("FooterComponent"),t=rn("footerHeight"),n=je("HeaderFooterTag"),r=rr(b.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Lt(e,o)})}):null});function hf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:h,scrollToCallback:m}=uf(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?a0:i0,...o},tabIndex:0,...i,...Lt(l,s),children:r})})}function mf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),h=b.useRef(null),m=t("scrollerRef"),{scrollByCallback:x,scrollerRef:y,scrollToCallback:g}=uf(a,c,l,m,p);return cf(()=>{var w;return y.current=p||((w=h.current)==null?void 0:w.ownerDocument.defaultView),()=>{y.current=null}},[y,p]),e("windowScrollTo",g),e("scrollBy",x),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Lt(l,s),children:r})})}const f0=({children:e})=>{const t=b.useContext(af),n=rn("viewportHeight"),r=rn("fixedItemHeight"),o=je("alignToBottom"),s=je("horizontalDirection"),i=b.useMemo(()=>Id(n,l=>$n(l,s?"width":"height")),[n,s]),a=rr(i,!0,je("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:Cs(o),children:e})},p0=({children:e})=>{const t=b.useContext(af),n=rn("windowViewportRect"),r=rn("fixedItemHeight"),o=je("customScrollParent"),s=Rd(n,o,je("skipAnimationFrameInResizeObserver")),i=je("alignToBottom");return b.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:Cs(i),children:e})},h0=({children:e})=>{const t=je("TopItemListComponent")||"div",n=je("headerHeight"),r={...l0,marginTop:`${n}px`},o=je("context");return u.jsx(t,{style:r,...Lt(t,o),children:e})},m0=b.memo(function(e){const t=je("useWindowScroll"),n=je("topItemsIndexes").length>0,r=je("customScrollParent"),o=je("context");return u.jsxs(r||t?y0:x0,{...e,context:o,children:[n&&u.jsx(h0,{children:u.jsx(pf,{showTopList:!0})}),u.jsxs(r||t?p0:f0,{children:[u.jsx(u0,{}),u.jsx(pf,{}),u.jsx(d0,{})]})]})}),{Component:g0,useEmitter:ba,useEmitterValue:je,usePublisher:rn}=sf(n0,{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"}},m0),x0=hf({useEmitter:ba,useEmitterValue:je,usePublisher:rn}),y0=mf({useEmitter:ba,useEmitterValue:je,usePublisher:rn}),v0=g0;pt(of,Je(()=>{const e=Y(c=>u.jsxs("td",{children:["Item $",c]})),t=Y(null),n=Y(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=Y(null),o=Y(null),s=Y({}),i=Y(wa),a=Y(Ir),l=(c,d=null)=>Dt(U(s,le(f=>f[c]),ht()),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")}})),va();const gf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},w0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:xf,floor:Ts,max:so,min:Sa,round:yf}=Math;function vf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function b0(e){return{...w0,items:e}}function ks(e,t){return e&&e.width===t.width&&e.height===t.height}function S0(e,t){return e&&e.column===t.column&&e.row===t.row}const C0=Je(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:m,propsReady:x},{customScrollParent:y,useWindowScroll:g,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k},T])=>{const C=Y(0),E=Y(0),j=Y(gf),N=Y({height:0,width:0}),A=Y({height:0,width:0}),O=We(),F=We(),$=Y(0),R=Y(null),z=Y({column:0,row:0}),_=We(),B=We(),L=Y(!1),M=Y(0),J=Y(!0),X=Y(!1),he=Y(!1);rt(U(m,Le(M),Te(([D,H])=>!!H)),()=>{Me(J,!1)}),rt(U(kt(m,J,A,N,M,X),Te(([D,H,te,se,,ne])=>D&&!H&&te.height!==0&&se.height!==0&&!ne)),([,,,,D])=>{Me(X,!0),fa(1,()=>{Me(O,D)}),fn(U(c),()=>{Me(t,[0,0]),Me(J,!0)})}),ge(U(B,Te(D=>D!=null&&D.scrollTop>0),Sn(0)),E),rt(U(m,Le(B),Te(([,D])=>D!=null)),([,D])=>{D&&(Me(N,D.viewport),Me(A,D.item),Me(z,D.gap),D.scrollTop>0&&(Me(L,!0),fn(U(c,nr(1)),H=>{Me(L,!1)}),Me(l,{top:D.scrollTop})))}),ge(U(N,le(({height:D})=>D)),f),ge(U(kt(Ce(N,ks),Ce(A,ks),Ce(z,(D,H)=>D&&D.column===H.column&&D.row===H.row),Ce(c)),le(([D,H,te,se])=>({gap:te,item:H,scrollTop:se,viewport:D}))),_),ge(U(kt(Ce(C),r,Ce(z,S0),Ce(A,ks),Ce(N,ks),Ce(R),Ce(E),Ce(L),Ce(J),Ce(M)),Te(([,,,,,,,D])=>!D),le(([D,[H,te],se,ne,ke,Z,fe,,Ie,Ae])=>{const{column:Fe,row:Ze}=se,{height:Ve,width:Ke}=ne,{width:qe}=ke;if(fe===0&&(D===0||qe===0))return gf;if(Ke===0){const me=pa(Ae,D),ze=me+Math.max(fe-1,0);return b0(vf(me,ze,Z))}const Xe=wf(qe,Ke,Fe);let Qe,et;Ie?H===0&&te===0&&fe>0?(Qe=0,et=fe-1):(Qe=Xe*Ts((H+Ze)/(Ve+Ze)),et=Xe*xf((te+Ze)/(Ve+Ze))-1,et=Sa(D-1,so(et,Xe-1)),Qe=Sa(et,so(0,Qe))):(Qe=0,et=-1);const Nt=vf(Qe,et,Z),{bottom:mt,top:at}=bf(ke,se,ne,Nt),de=xf(D/Xe),pe=de*Ve+(de-1)*Ze-mt;return{bottom:mt,itemHeight:Ve,items:Nt,itemWidth:Ke,offsetBottom:pe,offsetTop:at,top:at}})),j),ge(U(R,Te(D=>D!==null),le(D=>D.length)),C),ge(U(kt(N,A,j,z),Te(([D,H,{items:te}])=>te.length>0&&H.height!==0&&D.height!==0),le(([D,H,{items:te},se])=>{const{bottom:ne,top:ke}=bf(D,se,H,te);return[ke,ne]}),ht(Zr)),t);const Ne=Y(!1);ge(U(c,Le(Ne),le(([D,H])=>H||D!==0)),Ne);const _e=Xt(U(kt(j,C),Te(([{items:D}])=>D.length>0),Le(Ne),Te(([[D,H],te])=>{const se=D.items[D.items.length-1].index===H-1;return(te||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===H)&&se}),le(([[,D]])=>D-1),ht())),V=Xt(U(Ce(j),Te(({items:D})=>D.length>0&&D[0].index===0),Sn(0),ht())),ee=Xt(U(Ce(j),Le(L),Te(([{items:D},H])=>D.length>0&&!H),le(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),ht($d),_n(0)));ge(ee,h.scrollSeekRangeChanged),ge(U(O,Le(N,A,C,z),le(([D,H,te,se,ne])=>{const ke=Vd(D),{align:Z,behavior:fe,offset:Ie}=ke;let Ae=ke.index;Ae==="LAST"&&(Ae=se-1),Ae=so(0,Ae,Sa(se-1,Ae));let Fe=Ca(H,ne,te,Ae);return Z==="end"?Fe=yf(Fe-H.height+te.height):Z==="center"&&(Fe=yf(Fe-H.height/2+te.height/2)),Ie&&(Fe+=Ie),{behavior:fe,top:Fe}})),l);const q=Dt(U(j,le(D=>D.offsetBottom+D.bottom)),0);return ge(U(k,le(D=>({height:D.visibleHeight,width:D.visibleWidth}))),N),{customScrollParent:y,data:R,deviation:$,footerHeight:o,gap:z,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:A,overscan:n,restoreStateFrom:B,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:l,scrollToIndex:O,scrollTop:c,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:g,viewportDimensions:N,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k,...h,gridState:j,horizontalDirection:he,initialTopMostItemIndex:M,totalListHeight:q,...p,endReached:_e,propsReady:x,rangeChanged:ee,startReached:V,stateChanged:_,stateRestoreInProgress:L,...T}},pt(ha,Bt,oo,nf,zn,ga,Fn));function wf(e,t,n){return so(1,Ts((e+n)/(Ts(t)+n)))}function bf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ca(e,t,n,r[0].index);return{bottom:Ca(e,t,n,r[r.length-1].index)+o,top:s}}function Ca(e,t,n,r){const o=wf(e.width,n.width,t.column),s=Ts(r/o),i=s*n.height+so(0,s-1)*t.row;return i>0?i+t.row:i}const T0=Je(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(wa),i=Y("div"),a=Y(Ir),l=(f,p=null)=>Dt(U(t,le(h=>h[f]),ht()),p),c=Y(!1),d=Y(!1);return ge(Ce(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),k0=Je(([e,t])=>({...e,...t}),pt(C0,T0)),E0=b.memo(function(){const e=xt("gridState"),t=xt("listClassName"),n=xt("itemClassName"),r=xt("itemContent"),o=xt("computeItemKey"),s=xt("isSeeking"),i=on("scrollHeight"),a=xt("ItemComponent"),l=xt("ListComponent"),c=xt("ScrollSeekPlaceholder"),d=xt("context"),f=on("itemDimensions"),p=on("gap"),h=xt("log"),m=xt("stateRestoreInProgress"),x=on("reportReadyState"),y=rr(b.useMemo(()=>g=>{const w=g.parentElement.parentElement.scrollHeight;i(w);const S=g.firstChild;if(S){const{height:k,width:T}=S.getBoundingClientRect();f({height:k,width:T})}p({column:Cf("column-gap",getComputedStyle(g).columnGap,h),row:Cf("row-gap",getComputedStyle(g).rowGap,h)})},[i,f,p,h]),!0,!1);return cf(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),m?null:u.jsx(l,{className:t,ref:y,...Lt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(g=>{const w=o(g.index,g.data,d);return s?u.jsx(c,{...Lt(c,d),height:e.itemHeight,index:g.index,width:e.itemWidth},w):b.createElement(a,{...Lt(a,d),className:n,"data-index":g.index,key:w},r(g.index,g.data,d))})})}),I0=b.memo(function(){const e=xt("HeaderComponent"),t=on("headerHeight"),n=xt("headerFooterTag"),r=rr(b.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,!1),o=xt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Lt(e,o)})}):null}),N0=b.memo(function(){const e=xt("FooterComponent"),t=on("footerHeight"),n=xt("headerFooterTag"),r=rr(b.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,!1),o=xt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Lt(e,o)})}):null}),A0=({children:e})=>{const t=b.useContext(lf),n=on("itemDimensions"),r=on("viewportDimensions"),o=rr(b.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return b.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:Cs(!1),children:e})},j0=({children:e})=>{const t=b.useContext(lf),n=on("windowViewportRect"),r=on("itemDimensions"),o=xt("customScrollParent"),s=Rd(n,o,!1);return b.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:Cs(!1),children:e})},_0=b.memo(function({...e}){const t=xt("useWindowScroll"),n=xt("customScrollParent"),r=n||t?P0:R0,o=n||t?j0:A0,s=xt("context");return u.jsx(r,{...e,...Lt(r,s),children:u.jsxs(o,{children:[u.jsx(I0,{}),u.jsx(E0,{}),u.jsx(N0,{})]})})}),{useEmitter:Sf,useEmitterValue:xt,usePublisher:on}=sf(k0,{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"}},_0),R0=hf({useEmitter:Sf,useEmitterValue:xt,usePublisher:on}),P0=mf({useEmitter:Sf,useEmitterValue:xt,usePublisher:on});function Cf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Vt.WARN),t==="normal"?0:parseInt(t??"0",10)}const O0=xo.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 Tf({className:e,variant:t,...n}){return u.jsx("div",{className:Q(O0({variant:t}),e),...n})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:Q("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:Q("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:Q("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const kf=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));kf.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:Q("p-6 pt-0",e),...t}));co.displayName="CardContent";const Ef=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:Q("flex items-center p-6 pt-0",e),...t}));Ef.displayName="CardFooter";const M0=1,D0=1e6;let Ta=0;function L0(){return Ta=(Ta+1)%Number.MAX_SAFE_INTEGER,Ta.toString()}const ka=new Map,If=e=>{if(ka.has(e))return;const t=setTimeout(()=>{ka.delete(e),uo({type:"REMOVE_TOAST",toastId:e})},D0);ka.set(e,t)},F0=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,M0)};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?If(n):e.toasts.forEach(r=>{If(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)}}},Es=[];let Is={toasts:[]};function uo(e){Is=F0(Is,e),Es.forEach(t=>{t(Is)})}function $0({...e}){const t=L0(),n=o=>uo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>uo({type:"DISMISS_TOAST",toastId:t});return uo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ea(){const[e,t]=v.useState(Is);return v.useEffect(()=>(Es.push(t),()=>{const n=Es.indexOf(t);n>-1&&Es.splice(n,1)}),[e]),{...e,toast:$0,dismiss:n=>uo({type:"DISMISS_TOAST",toastId:n})}}async function Nf(e,t){return await Qt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Af(e,t){return await(await Nf(`/files/${e}/view`,t)).text()}async function z0(e,t){const n=await Nf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Qt(`/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 B0(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Qt("/files",{params:r})}function Ia(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 jf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function fo(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(fo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(jf(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=fo(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function po(e){if(typeof e=="string")return e;if(jf(e))return"";try{const t=fo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function H0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function U0(e){const t=po(e);return typeof e=="string"&&H0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Ns(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ia(t);if(n!==null)return Ns(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Ns(e.content):e}var As="Dialog",[_f,vT]=In(As),[W0,hn]=_f(As),Rf=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=xr({prop:r,defaultProp:o??!1,onChange:s,caller:As});return u.jsx(W0,{scope:t,triggerRef:a,contentRef:l,contentId:Nn(),titleId:Nn(),descriptionId:Nn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Rf.displayName=As;var Pf="DialogTrigger",Of=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Pf,n),s=Ue(t,o.triggerRef);return u.jsx(Re.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":ja(o.open),...r,ref:s,onClick:ue(e.onClick,o.onOpenToggle)})});Of.displayName=Pf;var Na="DialogPortal",[V0,Mf]=_f(Na,{forceMount:void 0}),Df=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=hn(Na,t);return u.jsx(V0,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(tn,{present:n||s.open,children:u.jsx(Jo,{asChild:!0,container:o,children:i})}))})};Df.displayName=Na;var js="DialogOverlay",Lf=v.forwardRef((e,t)=>{const n=Mf(js,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(js,e.__scopeDialog);return s.modal?u.jsx(tn,{present:r||s.open,children:u.jsx(q0,{...o,ref:t})}):null});Lf.displayName=js;var K0=Yn.createSlot("DialogOverlay.RemoveScroll"),q0=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(js,n);return u.jsx(is,{as:K0,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Re.div,{"data-state":ja(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),ir="DialogContent",Ff=v.forwardRef((e,t)=>{const n=Mf(ir,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(ir,e.__scopeDialog);return u.jsx(tn,{present:r||s.open,children:s.modal?u.jsx(G0,{...o,ref:t}):u.jsx(Y0,{...o,ref:t})})});Ff.displayName=ir;var G0=v.forwardRef((e,t)=>{const n=hn(ir,e.__scopeDialog),r=v.useRef(null),o=Ue(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Bi(s)},[]),u.jsx($f,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ue(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ue(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault())})}),Y0=v.forwardRef((e,t)=>{const n=hn(ir,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx($f,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),$f=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=hn(ir,n),l=v.useRef(null),c=Ue(t,l);return Si(),u.jsxs(u.Fragment,{children:[u.jsx($o,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Fo,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ja(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(X0,{titleId:a.titleId}),u.jsx(Z0,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Aa="DialogTitle",zf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Aa,n);return u.jsx(Re.h2,{id:o.titleId,...r,ref:t})});zf.displayName=Aa;var Bf="DialogDescription",Hf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Bf,n);return u.jsx(Re.p,{id:o.descriptionId,...r,ref:t})});Hf.displayName=Bf;var Uf="DialogClose",Wf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Uf,n);return u.jsx(Re.button,{type:"button",...r,ref:t,onClick:ue(e.onClick,()=>o.onOpenChange(!1))})});Wf.displayName=Uf;function ja(e){return e?"open":"closed"}var Vf="DialogTitleWarning",[wT,Kf]=tx(Vf,{contentName:ir,titleName:Aa,docsSlug:"dialog"}),X0=({titleId:e})=>{const t=Kf(Vf),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
86
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function lb(e,t=fs){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function cb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),lb(t),ab(t)}const ps=0,Ln=1,Er=2,kd=4;function Ed(e){return()=>e}function ub(e){e()}function Id(e,t){return n=>e(t(n))}function Nd(e,t){return()=>e(t)}function db(e,t){return n=>e(t,n)}function ta(e){return e!==void 0}function fb(...e){return()=>{e.map(ub)}}function Ir(){}function hs(e,t){return t(e),e}function pb(e,t){return t(e)}function pt(...e){return e}function rt(e,t){return e(Ln,t)}function Me(e,t){e(ps,t)}function na(e){e(Er)}function bt(e){return e(kd)}function ge(e,t){return rt(e,db(t,ps))}function fn(e,t){const n=e(Ln,r=>{n(),t(r)});return n}function Ad(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function jd(e,t){return e===t}function ht(e=jd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Te(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>Id(t,e)}function Sn(e){return t=>()=>{t(e)}}function U(e,...t){const n=hb(...t);return(r,o)=>{switch(r){case Er:na(e);return;case Ln:return rt(e,n(o))}}}function Cn(e,t){return n=>r=>{n(t=e(t,r))}}function nr(e){return t=>n=>{e>0?e--:t(n)}}function _n(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Le(...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);rt(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function hb(...e){return t=>e.reduceRight(pb,t)}function mb(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Ln:return s?n===s?void 0:(r(),n=s,t=rt(e,s),t):(r(),Ir);case Er:r(),n=null;return}}}function Y(e){let t=e;const n=We();return(r,o)=>{switch(r){case ps:t=o;break;case Ln:{o(t);break}case kd:return t}return n(r,o)}}function Dt(e,t){return hs(Y(t),n=>ge(e,n))}function We(){const e=[];return(t,n)=>{switch(t){case ps:e.slice().forEach(r=>{r(n)});return;case Er:e.splice(0,e.length);return;case Ln:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Xt(e){return hs(We(),t=>ge(e,t))}function Je(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:gb(),singleton:n}}const gb=()=>Symbol();function xb(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 kt(...e){const t=We(),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);rt(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case Er:{na(t);return}case Ln:return r===o&&i(n),rt(t,i)}}}function Ce(e,t=jd){return U(e,ht(t))}function ra(...e){return function(t,n){switch(t){case Er:return;case Ln:return fb(...e.map(r=>rt(r,n)))}}}var Vt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Vt||{});const yb={0:"debug",3:"error",1:"log",2:"warn"},vb=()=>typeof globalThis>"u"?window:globalThis,Fn=Je(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=vb().VIRTUOSO_LOG_LEVEL)!=null?o:bt(e);r>=s&&console[yb[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function rr(e,t,n){return oa(e,t,n).callbackRef}function oa(e,t,n){const r=b.useRef(null);let o=i=>{};const s=b.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function wb(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const f=bb(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const h=p.lastElementChild.dataset.viewportType==="window";let m;h&&(m=p.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:h?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,g=i?a?i.offsetWidth:i.offsetHeight:h?a?m.innerWidth:m.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(x,0),viewportHeight:g}),s==null||s(a?_d("column-gap",getComputedStyle(d).columnGap,o):_d("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return oa(c,n,l)}function bb(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Vt.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function _d(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Vt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Rd(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),m=c.top-h.top;p=h.height-Math.max(0,m),f=m+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=oa(o,!0,n),a=b.useCallback(()=>{o(i.current)},[o,i]);return b.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Bt=Je(()=>{const e=We(),t=We(),n=Y(0),r=We(),o=Y(0),s=We(),i=We(),a=Y(0),l=Y(0),c=Y(0),d=Y(0),f=We(),p=We(),h=Y(!1),m=Y(!1),x=Y(!1);return ge(U(e,le(({scrollTop:y})=>y)),t),ge(U(e,le(({scrollHeight:y})=>y)),i),ge(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Xr={lvl:0};function Pd(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 ct(e){return e===Xr}function Jr(e,t){if(!ct(e))return t===e.k?e.v:t<e.k?Jr(e.l,t):Jr(e.r,t)}function pn(e,t,n="k"){if(ct(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=pn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return pn(e.l,t,n)}function Jt(e,t,n){return ct(e)?Dd(t,n,1):t===e.k?It(e,{k:t,v:n}):t<e.k?Ld(It(e,{l:Jt(e.l,t,n)})):Ld(It(e,{r:Jt(e.r,t,n)}))}function Nr(){return Xr}function ms(e,t,n){if(ct(e))return[];const r=pn(e,t)[0];return Sb(ia(e,r,n))}function sa(e,t){if(ct(e))return Xr;const{k:n,l:r,r:o}=e;if(t===n){if(ct(r))return o;if(ct(o))return r;{const[s,i]=Md(r);return gs(It(e,{k:s,l:Od(r),v:i}))}}else return t<n?gs(It(e,{l:sa(r,t)})):gs(It(e,{r:sa(o,t)}))}function or(e){return ct(e)?[]:[...or(e.l),{k:e.k,v:e.v},...or(e.r)]}function ia(e,t,n){if(ct(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ia(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ia(s,t,n))),a}function gs(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(aa(t))return Fd(It(e,{lvl:n-1}));if(!ct(t)&&!ct(t.r))return It(t.r,{l:It(t,{r:t.r.l}),lvl:n,r:It(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(aa(e))return la(It(e,{lvl:n-1}));if(!ct(r)&&!ct(r.l)){const o=r.l,s=aa(o)?r.lvl-1:r.lvl;return It(o,{l:It(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:la(It(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function It(e,t){return Dd(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 Od(e){return ct(e.r)?e.l:gs(It(e,{r:Od(e.r)}))}function aa(e){return ct(e)||e.lvl>e.r.lvl}function Md(e){return ct(e.r)?[e.k,e.v]:Md(e.r)}function Dd(e,t,n,r=Xr,o=Xr){return{k:e,l:r,lvl:n,r:o,v:t}}function Ld(e){return la(Fd(e))}function Fd(e){const{l:t}=e;return!ct(t)&&t.lvl===e.lvl?It(t,{r:It(e,{l:t.r})}):e}function la(e){const{lvl:t,r:n}=e;return!ct(n)&&!ct(n.r)&&n.lvl===t&&n.r.lvl===t?It(n,{l:It(e,{r:n.l}),lvl:t+1}):e}function Sb(e){return Pd(e,({k:t,v:n})=>({index:t,value:n}))}function $d(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Zr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ca=Je(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function zd(e,t,n){return e[xs(e,t,n)]}function xs(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 Cb(e,t,n,r){const o=xs(e,t,r),s=xs(e,n,r,o);return e.slice(o,s+1)}function $n(e,t){return Math.round(e.getBoundingClientRect()[t])}function ys(e){return!ct(e.groupOffsetTree)}function ua({index:e},t){return t===e?0:t<e?-1:1}function Tb(){return{groupIndices:[],groupOffsetTree:Nr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Nr()}}function kb(e,t){let n=ct(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ct(e)){e=Jt(e,0,s);continue}const a=ms(e,i-1,o+1);if(a.some(Rb(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=sa(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Jt(e,o+1,p));c&&(e=Jt(e,i,s))}return[e,n]}function Eb(e){return typeof e.groupIndex<"u"}function Ib({offset:e},t){return t===e?0:t<e?-1:1}function Qr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=zd(t,e,ua),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Bd(e,t){if(!ys(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Hd(e,t,n){if(Eb(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Bd(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Nb(e,t,n,r=0){return r>0&&(t=Math.max(t,zd(e,r,ua).offset)),Pd(Cb(e,t,n,Ib),_b)}function Ab(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Vt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ct(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((m,x)=>Jt(Jt(m,x,p),x+1,h),i)}else[i,a]=kb(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=da(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Jt(p,h,Qr(h,f,o)),Nr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function jb(e){return or(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 Ud(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 da(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=xs(o,t-1,ua),a=o[l].offset;const c=pn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===pn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of ms(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function _b(e){return{index:e.index,value:e}}function Rb(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 Pb={offsetHeight:"height",offsetWidth:"width"},Tn=Je(([{log:e},{recalcInProgress:t}])=>{const n=We(),r=We(),o=Dt(r,0),s=We(),i=We(),a=Y(0),l=Y([]),c=Y(void 0),d=Y(void 0),f=Y((T,C)=>$n(T,Pb[C])),p=Y(void 0),h=Y(0),m=Tb(),x=Dt(U(n,Le(l,e,h),Cn(Ab,m),ht()),m),y=Dt(U(l,ht(),Cn((T,C)=>({current:C,prev:T.current}),{current:[],prev:[]}),le(({prev:T})=>T)),[]);ge(U(l,Te(T=>T.length>0),Le(x,h),le(([T,C,E])=>{const j=T.reduce((N,A,O)=>Jt(N,A,Qr(A,C.offsetTree,E)||O),Nr());return{...C,groupIndices:T,groupOffsetTree:j}})),x),ge(U(r,Le(x),Te(([T,{lastIndex:C}])=>T<C),le(([T,{lastIndex:C,lastSize:E}])=>[{endIndex:C,size:E,startIndex:T}])),n),ge(c,d);const g=Dt(U(c,le(T=>T===void 0)),!0);ge(U(d,Te(T=>T!==void 0&&ct(bt(x).sizeTree)),le(T=>[{endIndex:0,size:T,startIndex:0}])),n);const w=Xt(U(n,Le(x),Cn(({sizes:T},[C,E])=>({changed:E!==T,sizes:E}),{changed:!1,sizes:m}),le(T=>T.changed)));rt(U(a,Cn((T,C)=>({diff:T.prev-C,prev:C}),{diff:0,prev:0}),le(T=>T.diff)),T=>{const{groupIndices:C}=bt(x);if(T>0)Me(t,!0),Me(s,T+Ud(T,C));else if(T<0){const E=bt(y);E.length>0&&(T-=Ud(-T,E)),Me(i,T)}}),rt(U(a,Le(e)),([T,C])=>{T<0&&C("`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},Vt.ERROR)});const S=Xt(s);ge(U(s,Le(x),le(([T,C])=>{const E=C.groupIndices.length>0,j=[],N=C.lastSize;if(E){const A=Jr(C.sizeTree,0);let O=0,F=0;for(;O<T;){const R=C.groupIndices[F],z=C.groupIndices.length===F+1?1/0:C.groupIndices[F+1]-R-1;j.push({endIndex:R,size:A,startIndex:R}),j.push({endIndex:R+1+z-1,size:N,startIndex:R+1}),F++,O+=z+1}const $=or(C.sizeTree);return O!==T&&$.shift(),$.reduce((R,{k:z,v:_})=>{let B=R.ranges;return R.prevSize!==0&&(B=[...R.ranges,{endIndex:z+T-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:z+T,prevSize:_,ranges:B}},{prevIndex:T,prevSize:0,ranges:j}).ranges}return or(C.sizeTree).reduce((A,{k:O,v:F})=>({prevIndex:O+T,prevSize:F,ranges:[...A.ranges,{endIndex:O+T-1,size:A.prevSize,startIndex:A.prevIndex}]}),{prevIndex:0,prevSize:N,ranges:[]}).ranges})),n);const k=Xt(U(i,Le(x,h),le(([T,{offsetTree:C},E])=>{const j=-T;return Qr(j,C,E)})));return ge(U(i,Le(x,h),le(([T,C,E])=>{if(C.groupIndices.length>0){if(ct(C.sizeTree))return C;let j=Nr();const N=bt(y);let A=0,O=0,F=0;for(;A<-T;){F=N[O];const $=N[O+1]-F-1;O++,A+=$+1}if(j=or(C.sizeTree).reduce(($,{k:R,v:z})=>Jt($,Math.max(0,R+T),z),j),A!==-T){const $=Jr(C.sizeTree,F);j=Jt(j,0,$);const R=pn(C.sizeTree,-T+1)[1];j=Jt(j,1,R)}return{...C,sizeTree:j,...da(C.offsetTree,0,j,E)}}else{const j=or(C.sizeTree).reduce((N,{k:A,v:O})=>Jt(N,Math.max(0,A+T),O),Nr());return{...C,sizeTree:j,...da(C.offsetTree,0,j,E)}}})),x),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:g,unshiftWith:s}},pt(Fn,ca),{singleton:!0});function Ob(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Wd=Je(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=We(),i=We(),a=Xt(U(s,le(Ob)));return ge(U(a,le(l=>l.totalCount)),n),ge(U(a,le(l=>l.groupIndices)),e),ge(U(kt(o,t,r),Te(([l,c])=>ys(c)),le(([l,c,d])=>pn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ht(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},pt(Tn,Bt)),zn=Je(([{log:e}])=>{const t=Y(!1),n=Xt(U(t,Te(r=>r),ht()));return rt(t,r=>{r&&bt(e)("props updated",{},Vt.DEBUG)}),{didMount:n,propsReady:t}},pt(Fn),{singleton:!0}),Mb=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Vd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Mb)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const eo=Je(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=We(),m=We(),x=Y(0);let y=null,g=null,w=null;function S(){y&&(y(),y=null),w&&(w(),w=null),g&&(clearTimeout(g),g=null),Me(l,!1)}return ge(U(h,Le(n,f,r,x,a,i,p),Le(e,s,o),le(([[k,T,C,E,j,N,A,O],F,$,R])=>{const z=Vd(k),{align:_,behavior:B,offset:L}=z,M=E-1,J=Hd(z,T,M);let X=Qr(J,T.offsetTree,F)+N;_==="end"?(X+=$+pn(T.sizeTree,J)[1]-C+R,J===M&&(X+=A)):_==="center"?X+=($+pn(T.sizeTree,J)[1]-C+R)/2:X-=j,L&&(X+=L);const he=Ne=>{S(),Ne?(O("retrying to scroll to",{location:k},Vt.DEBUG),Me(h,k)):(Me(m,!0),O("list did not change, scroll successful",{},Vt.DEBUG))};if(S(),B==="smooth"){let Ne=!1;w=rt(t,_e=>{Ne=Ne||_e}),y=fn(d,()=>{he(Ne)})}else y=fn(U(t,Db(150)),he);return g=setTimeout(()=>{S()},1200),Me(l,!0),O("scrolling from index to",{behavior:B,index:J,top:X},Vt.DEBUG),{behavior:B,top:X}})),c),{scrollTargetReached:m,scrollToIndex:h,topListHeight:x}},pt(Tn,Bt,Fn),{singleton:!0});function Db(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function fa(e,t){e==0?t():requestAnimationFrame(()=>{fa(e-1,t)})}function pa(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const to=Je(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Y(!0),l=Y(0),c=Y(!0);return ge(U(i,Le(l),Te(([d,f])=>!!f),Sn(!1)),a),ge(U(i,Le(l),Te(([d,f])=>!!f),Sn(!1)),c),rt(U(kt(t,i),Le(a,n,e,c),Te(([[,d],f,{sizeTree:p},h,m])=>d&&(!ct(p)||ta(h))&&!f&&!m),Le(l)),([,d])=>{fn(o,()=>{Me(c,!0)}),fa(4,()=>{fn(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},pt(Tn,Bt,eo,zn),{singleton:!0});function Kd(e,t){return Math.abs(e-t)<1.01}const no="up",ro="down",Lb="none",Fb={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},$b=0,oo=Je(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=We(),c=We(),d=Y(4),f=Y($b),p=Dt(U(ra(U(Ce(o),nr(1),Sn(!0)),U(Ce(o),nr(1),Sn(!1),Ad(100))),ht()),!1),h=Dt(U(ra(U(n,Sn(!0)),U(n,Sn(!1),Ad(200))),ht()),!1);ge(U(kt(Ce(o),Ce(f)),le(([w,S])=>w<=S),ht()),a),ge(U(a,_n(50)),c);const m=Xt(U(kt(r,Ce(s),Ce(t),Ce(e),Ce(d)),Cn((w,[{scrollHeight:S,scrollTop:k},T,C,E,j])=>{const N=k+T-S>-j,A={scrollHeight:S,scrollTop:k,viewportHeight:T};if(N){let F,$;return k>w.state.scrollTop?(F="SCROLLED_DOWN",$=w.state.scrollTop-k):(F="SIZE_DECREASED",$=w.state.scrollTop-k||w.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:$,state:A}}let O;return A.scrollHeight>w.state.scrollHeight?O="SIZE_INCREASED":T<w.state.viewportHeight?O="VIEWPORT_HEIGHT_DECREASING":k<w.state.scrollTop?O="SCROLLING_UPWARDS":O="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:O,state:A}},Fb),ht((w,S)=>w&&w.atBottom===S.atBottom))),x=Dt(U(r,Cn((w,{scrollHeight:S,scrollTop:k,viewportHeight:T})=>{if(Kd(w.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const C=S-(k+T)<1;return w.scrollTop!==k&&C?{changed:!0,jump:w.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Te(w=>w.changed),le(w=>w.jump)),0);ge(U(m,le(w=>w.atBottom)),i),ge(U(i,_n(50)),l);const y=Y(ro);ge(U(r,le(({scrollTop:w})=>w),ht(),Cn((w,S)=>bt(h)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?no:ro,prevScrollTop:S},{direction:ro,prevScrollTop:0}),le(w=>w.direction)),y),ge(U(r,_n(50),Sn(Lb)),y);const g=Y(0);return ge(U(p,Te(w=>!w),Sn(0)),g),ge(U(o,_n(100),Le(p),Te(([w,S])=>!!S),Cn(([w,S],[k])=>[S,k],[0,0]),le(([w,S])=>S-w)),g),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:x,scrollDirection:y,scrollVelocity:g}},pt(Bt)),vs="top",ws="bottom",qd="none";function Gd(e,t,n){return typeof e=="number"?n===no&&t===vs||n===ro&&t===ws?e:0:n===no?t===vs?e.main:e.reverse:t===ws?e.main:e.reverse}function Yd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ha=Je(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=We(),i=Y(0),a=Y(0),l=Y(0),c=Dt(U(kt(Ce(r),Ce(o),Ce(n),Ce(s,Zr),Ce(l),Ce(i),Ce(t),Ce(e),Ce(a)),le(([d,f,p,[h,m],x,y,g,w,S])=>{const k=d-w,T=y+g,C=Math.max(p-k,0);let E=qd;const j=Yd(S,vs),N=Yd(S,ws);return h-=w,h+=p+g,m+=p+g,m-=w,h>d+T-j&&(E=no),m<d-C+f+N&&(E=ro),E!==qd?[Math.max(k-p-Gd(x,vs,E)-j,0),k-C-g+f+Gd(x,ws,E)+N]:null}),Te(d=>d!=null),ht(Zr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},pt(Bt),{singleton:!0});function zb(e,t,n){if(ys(t)){const r=Bd(e,t);return[{index:pn(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 ma={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function bs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,m=p-d;return{bottom:d,firstItemIndex:s,items:Jd(e,o,s),offsetBottom:m,offsetTop:c,top:h,topItems:Jd(t,o,s),topListHeight:t.reduce((x,y)=>y.size+x,0),totalCount:n}}function Xd(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=pa(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return bs(c,[],a,o,n,r)}function Jd(e,t,n){if(e.length===0)return[];if(!ys(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=ms(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const sr=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:m}])=>{const x=Y([]),y=Y(0),g=We();ge(s.topItemsIndexes,x);const w=Dt(U(kt(h,m,Ce(l,Zr),Ce(o),Ce(r),Ce(c),d,Ce(x),Ce(t),Ce(n),e),Te(([C,E,,j,,,,,,,N])=>{const A=N&&N.length!==j;return C&&!E&&!A}),le(([,,[C,E],j,N,A,O,F,$,R,z])=>{const _=N,{offsetTree:B,sizeTree:L}=_,M=bt(y);if(j===0)return{...ma,totalCount:j};if(C===0&&E===0)return M===0?{...ma,totalCount:j}:Xd(M,A,N,$,R,z||[]);if(ct(L))return M>0?null:bs(zb(pa(A,j),_,z),[],j,R,_,$);const J=[];if(F.length>0){const V=F[0],ee=F[F.length-1];let q=0;for(const D of ms(L,V,ee)){const H=D.value,te=Math.max(D.start,V),se=Math.min(D.end,ee);for(let ne=te;ne<=se;ne++)J.push({data:z==null?void 0:z[ne],index:ne,offset:q,size:H}),q+=H}}if(!O)return bs([],J,j,R,_,$);const X=F.length>0?F[F.length-1]+1:0,he=Nb(B,C,E,X);if(he.length===0)return null;const Ne=j-1,_e=hs([],V=>{for(const ee of he){const q=ee.value;let D=q.offset,H=ee.start;const te=q.size;if(q.offset<C){H+=Math.floor((C-q.offset+R)/(te+R));const ne=H-ee.start;D+=ne*te+ne*R}H<X&&(D+=(X-H)*te,H=X);const se=Math.min(ee.end,Ne);for(let ne=H;ne<=se&&!(D>=E);ne++)V.push({data:z==null?void 0:z[ne],index:ne,offset:D,size:te}),D+=te+R}});return bs(_e,J,j,R,_,$)}),Te(C=>C!==null),ht()),ma);ge(U(e,Te(ta),le(C=>C==null?void 0:C.length)),o),ge(U(w,le(C=>C.topListHeight)),f),ge(f,a),ge(U(w,le(C=>[C.top,C.bottom])),i),ge(U(w,le(C=>C.items)),g);const S=Xt(U(w,Te(({items:C})=>C.length>0),Le(o,e),Te(([{items:C},E])=>C[C.length-1].originalIndex===E-1),le(([,C,E])=>[C-1,E]),ht(Zr),le(([C])=>C))),k=Xt(U(w,_n(200),Te(({items:C,topItems:E})=>C.length>0&&C[0].originalIndex===E.length),le(({items:C})=>C[0].index),ht())),T=Xt(U(w,Te(({items:C})=>C.length>0),le(({items:C})=>{let E=0,j=C.length-1;for(;C[E].type==="group"&&E<j;)E++;for(;C[j].type==="group"&&j>E;)j--;return{endIndex:C[j].index,startIndex:C[E].index}}),ht($d)));return{endReached:S,initialItemCount:y,itemsRendered:g,listState:w,rangeChanged:T,startReached:k,topItemsIndexes:x,...p}},pt(Tn,Wd,ha,to,eo,oo,zn,ca),{singleton:!0}),Zd=Je(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=We(),i=Dt(U(kt(n,e,r,t,o),le(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ge(Ce(i),s),{totalListHeight:i,totalListHeightChanged:s}},pt(Bt,sr),{singleton:!0}),Bb=Je(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=Dt(U(kt(n,e,t),Te(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),_n(0),ht()),0);return{alignToBottom:n,paddingTopAddition:r}},pt(Bt,Zd),{singleton:!0}),Qd=Je(()=>({context:Y(null)})),Hb=({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,ef=Je(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=We();return ge(U(d,Le(t,l,n,s,o,r,a),Le(e),le(([[f,p,h,m,x,y,g,w],S])=>{const{align:k,behavior:T,calculateViewLocation:C=Hb,done:E,...j}=f,N=Hd(f,p,m-1),A=Qr(N,p.offsetTree,S)+x+y,O=A+pn(p.sizeTree,N)[1],F=w+y,$=w+h-g,R=C({itemBottom:O,itemTop:A,locationParams:{align:k,behavior:T,...j},viewportBottom:$,viewportTop:F});return R?E&&fn(U(i,Te(z=>!z),nr(bt(i)?1:2)),E):E&&E(),R}),Te(f=>f!==null)),c),{scrollIntoView:d}},pt(Tn,Bt,eo,sr,Fn),{singleton:!0});function tf(e){return e?e==="smooth"?"smooth":"auto":!1}const Ub=(e,t)=>typeof e=="function"?tf(e(t)):t&&tf(e),Wb=Je(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const m=Y(!1),x=We();let y=null;function g(T){Me(i,{align:"end",behavior:T,index:"LAST"})}rt(U(kt(U(Ce(t),nr(1)),l),Le(Ce(m),s,a,f),le(([[T,C],E,j,N,A])=>{let O=C&&N,F="auto";return O&&(F=Ub(E,j||A),O=O&&!!F),{followOutputBehavior:F,shouldFollow:O,totalCount:T}}),Te(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:C})=>{y&&(y(),y=null),bt(n)?requestAnimationFrame(()=>{bt(d)("following output to ",{totalCount:C},Vt.DEBUG),g(T)}):y=fn(e,()=>{bt(d)("following output to ",{totalCount:C},Vt.DEBUG),g(T),y=null})});function w(T){const C=fn(o,E=>{T&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(bt(d)("scrolling to bottom due to increased size",{},Vt.DEBUG),g("auto"))});setTimeout(C,100)}rt(U(kt(Ce(m),t,c),Te(([T,,C])=>T&&C),Cn(({value:T},[,C])=>({refreshed:T===C,value:C}),{refreshed:!1,value:0}),Te(({refreshed:T})=>T),Le(m,t)),([,T])=>{bt(a)&&w(T!==!1)}),rt(x,()=>{w(bt(m)!==!1)}),rt(kt(Ce(m),o),([T,C])=>{T&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=Y(null),k=We();return ge(ra(U(Ce(r),le(T=>{var C;return(C=T==null?void 0:T.length)!=null?C:0})),U(Ce(t))),k),rt(U(kt(U(k,nr(1)),l),Le(Ce(S),a,f,p),le(([[T,C],E,j,N,A])=>C&&j&&(E==null?void 0:E({context:A,totalCount:T,scrollingInProgress:N}))),Te(T=>!!T),_n(0)),T=>{y&&(y(),y=null),bt(n)?requestAnimationFrame(()=>{bt(d)("scrolling into view",{}),Me(h,T)}):y=fn(e,()=>{bt(d)("scrolling into view",{}),Me(h,T),y=null})}),{autoscrollToBottom:x,followOutput:m,scrollIntoViewOnChange:S}},pt(Tn,oo,eo,to,zn,Fn,Bt,Qd,ef)),Vb=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ge(U(a,Le(s),Te(([,l])=>l!==0),Le(o,r,t,n,e),le(([[,l],c,d,f,p,h=[]])=>Xd(l,c,d,f,p,h))),i),{}),pt(Tn,to,sr,zn),{singleton:!0}),Kb=Je(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return rt(U(e,Le(r),Te(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{fn(U(n,nr(1),Te(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},pt(zn,Bt,sr),{singleton:!0}),nf=Je(([{scrollVelocity:e}])=>{const t=Y(!1),n=We(),r=Y(!1);return ge(U(e,Le(r,t,n),Te(([o,s])=>!!s),le(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ht()),t),rt(U(kt(t,e,n),Le(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},pt(oo),{singleton:!0}),ga=Je(([{scrollContainerState:e,scrollTo:t}])=>{const n=We(),r=We(),o=We(),s=Y(!1),i=Y(void 0);return ge(U(kt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ge(U(t,Le(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},pt(Bt)),qb=Je(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=We(),d=Y(void 0),f=Y(null),p=Y(null);return ge(a,f),ge(l,p),rt(U(c,Le(t,r,i,f,p,n)),([h,m,x,y,g,w,S])=>{const k=jb(m.sizeTree);y&&g!==null&&w!==null&&(x=g.scrollTop-w.offsetTop),x-=S,h({ranges:k,scrollTop:x})}),ge(U(d,Te(ta),le(Gb)),o),ge(U(s,Le(d),Te(([,h])=>h!==void 0),ht(),le(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},pt(Tn,Bt,to,zn,ga));function Gb(e){return{align:"start",index:0,offset:e.scrollTop}}const Yb=Je(([{topItemsIndexes:e}])=>{const t=Y(0);return ge(U(t,Te(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},pt(sr));function rf(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Xb=rf(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Jb=Je(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:m}])=>{const x=Xt(U(l,Le(i),Cn(([,g,w,S],[{bottom:k,items:T,offsetBottom:C,totalCount:E},j])=>{const N=k+C;let A=0;return w===E&&g.length>0&&T.length>0&&(T[0].originalIndex===0&&g[0].originalIndex===0||(A=N-S,A!==0&&(A+=j))),[A,T,E,N]},[0,[],0,0]),Te(([g])=>g!==0),Le(r,a,n,o,h,m),Te(([,g,w,S,,,k])=>!k&&!S&&g!==0&&w===no),le(([[g],,,,,w])=>(w("Upward scrolling compensation",{amount:g},Vt.DEBUG),g))));function y(g){g>0?(Me(t,{behavior:"auto",top:-g}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-g}))}return rt(U(x,Le(e,s)),([g,w,S])=>{S&&Xb()?Me(e,w-g):y(-g)}),rt(U(kt(Dt(s,!1),e,m),Te(([g,w,S])=>!g&&!S&&w!==0),le(([g,w])=>w),_n(1)),y),ge(U(f,le(g=>({top:-g}))),t),rt(U(c,Le(p,d),le(([g,{groupIndices:w,lastSize:S,sizeTree:k},T])=>{function C(E){return E*(S+T)}if(w.length===0)return C(g);{let E=0;const j=Jr(k,0);let N=0,A=0;for(;N<g;){N++,E+=j;let O=w.length===A+1?1/0:w[A+1]-w[A]-1;N+O>g&&(E-=j,O=g-N+1),N+=O,E+=C(O),A++}return E}})),g=>{Me(e,g),requestAnimationFrame(()=>{Me(t,{top:g}),requestAnimationFrame(()=>{Me(e,0),Me(m,!1)})})}),{deviation:e}},pt(Bt,oo,sr,Tn,Fn,ca)),Zb=Je(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),pt(ha,Vb,zn,nf,Zd,Kb,Bb,ga,ef,Fn,Qd)),of=Je(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m},x,y,g,{listState:w,topItemsIndexes:S,...k},{scrollToIndex:T},C,{topItemCount:E},{groupCounts:j},N])=>(ge(k.rangeChanged,N.scrollSeekRangeChanged),ge(U(N.windowViewportRect,le(A=>A.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:j,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...g,groupIndices:s,itemSize:i,listState:w,scrollToIndex:T,statefulTotalCount:c,trackItemSizes:f,...k,...N,...x,sizes:l,...y}),pt(Tn,to,Bt,qb,Wb,sr,eo,Jb,Yb,Wd,Zb));function Qb(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 Ss=typeof document<"u"?b.useLayoutEffect:b.useEffect;function sf(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=b.createContext({});function l(y,g){y.propsReady&&Me(y.propsReady,!1);for(const w of r){const S=y[t.required[w]];Me(S,g[w])}for(const w of o)if(w in g){const S=y[t.optional[w]];Me(S,g[w])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((g,w)=>(g[w]=S=>{const k=y[t.methods[w]];Me(k,S)},g),{})}function d(y){return i.reduce((g,w)=>(g[w]=mb(y[t.events[w]]),g),{})}const f=b.forwardRef((y,g)=>{const{children:w,...S}=y,[k]=b.useState(()=>hs(xb(e),E=>{l(E,S)})),[T]=b.useState(Nd(d,k));Ss(()=>{for(const E of i)E in S&&rt(T[E],S[E]);return()=>{Object.values(T).map(na)}},[S,T,k]),Ss(()=>{l(k,S)}),b.useImperativeHandle(g,Ed(c(k)));const C=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(C,{...Qb([...r,...o,...i],S),children:w}):w})}),p=y=>{const g=b.useContext(a);return b.useCallback(w=>{Me(g[y],w)},[g,y])},h=y=>{const g=b.useContext(a)[y],w=b.useCallback(S=>rt(g,S),[g]);return b.useSyncExternalStore(w,()=>bt(g),()=>bt(g))},m=y=>{const g=b.useContext(a)[y],[w,S]=b.useState(Nd(bt,g));return Ss(()=>rt(g,k=>{k!==w&&S(Ed(k))}),[g,w]),w},x=b.version.startsWith("18")?h:m;return{Component:f,useEmitter:(y,g)=>{const w=b.useContext(a)[y];Ss(()=>rt(w,g),[g,w])},useEmitterValue:x,usePublisher:p}}const af=b.createContext(void 0),lf=b.createContext(void 0),cf=typeof document<"u"?b.useLayoutEffect:b.useEffect;function xa(e){return"self"in e}function e0(e){return"body"in e}function uf(e,t,n,r=Ir,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(p=>{let h,m,x;const y=p.target;if(e0(y)||xa(y)){const w=xa(y)?y:y.defaultView;x=s?w.scrollX:w.scrollY,h=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else x=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const g=()=>{e({scrollHeight:h,scrollTop:Math.max(x,0),viewportHeight:m})};p.suppressFlushSync?g():Js.flushSync(g),a.current!==null&&(x===a.current||x<=0||x===h-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const m=p.behavior==="smooth";let x,y,g;xa(h)?(y=Math.max($n(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),x=s?h.innerWidth:h.innerHeight,g=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],x=$n(h,s?"width":"height"),g=h[s?"scrollLeft":"scrollTop"]);const w=y-x;if(p.top=Math.ceil(Math.max(Math.min(w,p.top),0)),Kd(x,y)||p.top===g){e({scrollHeight:y,scrollTop:g,viewportHeight:x}),m&&t(!0);return}m?(a.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),h.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ya="-webkit-sticky",df="sticky",va=rf(()=>{if(typeof document>"u")return df;const e=document.createElement("div");return e.style.position=ya,e.style.position===ya?ya:df});function wa(e){return e}const t0=Je(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(wa),o=Y("div"),s=Y(Ir),i=(a,l=null)=>Dt(U(n,le(c=>c[a]),ht()),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")}}),n0=Je(([e,t])=>({...e,...t}),pt(of,t0)),r0=({height:e})=>u.jsx("div",{style:{height:e}}),o0={overflowAnchor:"none",position:va(),zIndex:1},ff={overflowAnchor:"none"},s0={...ff,display:"inline-block",height:"100%"},pf=b.memo(function({showTopList:e=!1}){const t=je("listState"),n=rn("sizeRanges"),r=je("useWindowScroll"),o=je("customScrollParent"),s=rn("windowScrollContainerState"),i=rn("scrollContainerState"),a=o||r?s:i,l=je("itemContent"),c=je("context"),d=je("groupContent"),f=je("trackItemSizes"),p=je("itemSize"),h=je("log"),m=rn("gap"),x=je("horizontalDirection"),{callbackRef:y}=wb(n,p,f,e?Ir:a,h,m,o,x,je("skipAnimationFrameInResizeObserver")),[g,w]=b.useState(0);ba("deviation",R=>{g!==R&&w(R)});const S=je("EmptyPlaceholder"),k=je("ScrollSeekPlaceholder")||r0,T=je("ListComponent"),C=je("ItemComponent"),E=je("GroupComponent"),j=je("computeItemKey"),N=je("isSeeking"),A=je("groupIndices").length>0,O=je("alignToBottom"),F=je("initialItemFinalLocationReached"),$=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:g!==0?g:O?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:O?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Lt(S,c)}):u.jsx(T,{...Lt(T,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:$,children:(e?t.topItems:t.items).map(R=>{const z=R.originalIndex,_=j(z+t.firstItemIndex,R.data,c);return N?b.createElement(k,{...Lt(k,c),height:R.size,index:R.index,key:_,type:R.type||"item",...R.type==="group"?{}:{groupIndex:R.groupIndex}}):R.type==="group"?b.createElement(E,{...Lt(E,c),"data-index":z,"data-item-index":R.index,"data-known-size":R.size,key:_,style:o0},d(R.index,c)):b.createElement(C,{...Lt(C,c),...c0(C,R.data),"data-index":z,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:_,style:x?s0:ff},A?l(R.index,R.groupIndex,R.data,c):l(R.index,R.data,c))})})}),i0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},a0={outline:"none",overflowX:"auto",position:"relative"},Cs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),l0={position:va(),top:0,width:"100%",zIndex:1};function Lt(e,t){if(typeof e!="string")return{context:t}}function c0(e,t){return{item:typeof e=="string"?void 0:t}}const u0=b.memo(function(){const e=je("HeaderComponent"),t=rn("headerHeight"),n=je("HeaderFooterTag"),r=rr(b.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Lt(e,o)})}):null}),d0=b.memo(function(){const e=je("FooterComponent"),t=rn("footerHeight"),n=je("HeaderFooterTag"),r=rr(b.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Lt(e,o)})}):null});function hf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:h,scrollToCallback:m}=uf(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?a0:i0,...o},tabIndex:0,...i,...Lt(l,s),children:r})})}function mf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),h=b.useRef(null),m=t("scrollerRef"),{scrollByCallback:x,scrollerRef:y,scrollToCallback:g}=uf(a,c,l,m,p);return cf(()=>{var w;return y.current=p||((w=h.current)==null?void 0:w.ownerDocument.defaultView),()=>{y.current=null}},[y,p]),e("windowScrollTo",g),e("scrollBy",x),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Lt(l,s),children:r})})}const f0=({children:e})=>{const t=b.useContext(af),n=rn("viewportHeight"),r=rn("fixedItemHeight"),o=je("alignToBottom"),s=je("horizontalDirection"),i=b.useMemo(()=>Id(n,l=>$n(l,s?"width":"height")),[n,s]),a=rr(i,!0,je("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:Cs(o),children:e})},p0=({children:e})=>{const t=b.useContext(af),n=rn("windowViewportRect"),r=rn("fixedItemHeight"),o=je("customScrollParent"),s=Rd(n,o,je("skipAnimationFrameInResizeObserver")),i=je("alignToBottom");return b.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:Cs(i),children:e})},h0=({children:e})=>{const t=je("TopItemListComponent")||"div",n=je("headerHeight"),r={...l0,marginTop:`${n}px`},o=je("context");return u.jsx(t,{style:r,...Lt(t,o),children:e})},m0=b.memo(function(e){const t=je("useWindowScroll"),n=je("topItemsIndexes").length>0,r=je("customScrollParent"),o=je("context");return u.jsxs(r||t?y0:x0,{...e,context:o,children:[n&&u.jsx(h0,{children:u.jsx(pf,{showTopList:!0})}),u.jsxs(r||t?p0:f0,{children:[u.jsx(u0,{}),u.jsx(pf,{}),u.jsx(d0,{})]})]})}),{Component:g0,useEmitter:ba,useEmitterValue:je,usePublisher:rn}=sf(n0,{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"}},m0),x0=hf({useEmitter:ba,useEmitterValue:je,usePublisher:rn}),y0=mf({useEmitter:ba,useEmitterValue:je,usePublisher:rn}),v0=g0;pt(of,Je(()=>{const e=Y(c=>u.jsxs("td",{children:["Item $",c]})),t=Y(null),n=Y(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=Y(null),o=Y(null),s=Y({}),i=Y(wa),a=Y(Ir),l=(c,d=null)=>Dt(U(s,le(f=>f[c]),ht()),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")}})),va();const gf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},w0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:xf,floor:Ts,max:so,min:Sa,round:yf}=Math;function vf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function b0(e){return{...w0,items:e}}function ks(e,t){return e&&e.width===t.width&&e.height===t.height}function S0(e,t){return e&&e.column===t.column&&e.row===t.row}const C0=Je(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:m,propsReady:x},{customScrollParent:y,useWindowScroll:g,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k},T])=>{const C=Y(0),E=Y(0),j=Y(gf),N=Y({height:0,width:0}),A=Y({height:0,width:0}),O=We(),F=We(),$=Y(0),R=Y(null),z=Y({column:0,row:0}),_=We(),B=We(),L=Y(!1),M=Y(0),J=Y(!0),X=Y(!1),he=Y(!1);rt(U(m,Le(M),Te(([D,H])=>!!H)),()=>{Me(J,!1)}),rt(U(kt(m,J,A,N,M,X),Te(([D,H,te,se,,ne])=>D&&!H&&te.height!==0&&se.height!==0&&!ne)),([,,,,D])=>{Me(X,!0),fa(1,()=>{Me(O,D)}),fn(U(c),()=>{Me(t,[0,0]),Me(J,!0)})}),ge(U(B,Te(D=>D!=null&&D.scrollTop>0),Sn(0)),E),rt(U(m,Le(B),Te(([,D])=>D!=null)),([,D])=>{D&&(Me(N,D.viewport),Me(A,D.item),Me(z,D.gap),D.scrollTop>0&&(Me(L,!0),fn(U(c,nr(1)),H=>{Me(L,!1)}),Me(l,{top:D.scrollTop})))}),ge(U(N,le(({height:D})=>D)),f),ge(U(kt(Ce(N,ks),Ce(A,ks),Ce(z,(D,H)=>D&&D.column===H.column&&D.row===H.row),Ce(c)),le(([D,H,te,se])=>({gap:te,item:H,scrollTop:se,viewport:D}))),_),ge(U(kt(Ce(C),r,Ce(z,S0),Ce(A,ks),Ce(N,ks),Ce(R),Ce(E),Ce(L),Ce(J),Ce(M)),Te(([,,,,,,,D])=>!D),le(([D,[H,te],se,ne,ke,Q,fe,,Ie,Ae])=>{const{column:Fe,row:Ze}=se,{height:Ve,width:Ke}=ne,{width:qe}=ke;if(fe===0&&(D===0||qe===0))return gf;if(Ke===0){const me=pa(Ae,D),ze=me+Math.max(fe-1,0);return b0(vf(me,ze,Q))}const Xe=wf(qe,Ke,Fe);let Qe,et;Ie?H===0&&te===0&&fe>0?(Qe=0,et=fe-1):(Qe=Xe*Ts((H+Ze)/(Ve+Ze)),et=Xe*xf((te+Ze)/(Ve+Ze))-1,et=Sa(D-1,so(et,Xe-1)),Qe=Sa(et,so(0,Qe))):(Qe=0,et=-1);const Nt=vf(Qe,et,Q),{bottom:mt,top:at}=bf(ke,se,ne,Nt),de=xf(D/Xe),pe=de*Ve+(de-1)*Ze-mt;return{bottom:mt,itemHeight:Ve,items:Nt,itemWidth:Ke,offsetBottom:pe,offsetTop:at,top:at}})),j),ge(U(R,Te(D=>D!==null),le(D=>D.length)),C),ge(U(kt(N,A,j,z),Te(([D,H,{items:te}])=>te.length>0&&H.height!==0&&D.height!==0),le(([D,H,{items:te},se])=>{const{bottom:ne,top:ke}=bf(D,se,H,te);return[ke,ne]}),ht(Zr)),t);const Ne=Y(!1);ge(U(c,Le(Ne),le(([D,H])=>H||D!==0)),Ne);const _e=Xt(U(kt(j,C),Te(([{items:D}])=>D.length>0),Le(Ne),Te(([[D,H],te])=>{const se=D.items[D.items.length-1].index===H-1;return(te||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===H)&&se}),le(([[,D]])=>D-1),ht())),V=Xt(U(Ce(j),Te(({items:D})=>D.length>0&&D[0].index===0),Sn(0),ht())),ee=Xt(U(Ce(j),Le(L),Te(([{items:D},H])=>D.length>0&&!H),le(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),ht($d),_n(0)));ge(ee,h.scrollSeekRangeChanged),ge(U(O,Le(N,A,C,z),le(([D,H,te,se,ne])=>{const ke=Vd(D),{align:Q,behavior:fe,offset:Ie}=ke;let Ae=ke.index;Ae==="LAST"&&(Ae=se-1),Ae=so(0,Ae,Sa(se-1,Ae));let Fe=Ca(H,ne,te,Ae);return Q==="end"?Fe=yf(Fe-H.height+te.height):Q==="center"&&(Fe=yf(Fe-H.height/2+te.height/2)),Ie&&(Fe+=Ie),{behavior:fe,top:Fe}})),l);const q=Dt(U(j,le(D=>D.offsetBottom+D.bottom)),0);return ge(U(k,le(D=>({height:D.visibleHeight,width:D.visibleWidth}))),N),{customScrollParent:y,data:R,deviation:$,footerHeight:o,gap:z,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:A,overscan:n,restoreStateFrom:B,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:l,scrollToIndex:O,scrollTop:c,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:g,viewportDimensions:N,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k,...h,gridState:j,horizontalDirection:he,initialTopMostItemIndex:M,totalListHeight:q,...p,endReached:_e,propsReady:x,rangeChanged:ee,startReached:V,stateChanged:_,stateRestoreInProgress:L,...T}},pt(ha,Bt,oo,nf,zn,ga,Fn));function wf(e,t,n){return so(1,Ts((e+n)/(Ts(t)+n)))}function bf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ca(e,t,n,r[0].index);return{bottom:Ca(e,t,n,r[r.length-1].index)+o,top:s}}function Ca(e,t,n,r){const o=wf(e.width,n.width,t.column),s=Ts(r/o),i=s*n.height+so(0,s-1)*t.row;return i>0?i+t.row:i}const T0=Je(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(wa),i=Y("div"),a=Y(Ir),l=(f,p=null)=>Dt(U(t,le(h=>h[f]),ht()),p),c=Y(!1),d=Y(!1);return ge(Ce(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),k0=Je(([e,t])=>({...e,...t}),pt(C0,T0)),E0=b.memo(function(){const e=xt("gridState"),t=xt("listClassName"),n=xt("itemClassName"),r=xt("itemContent"),o=xt("computeItemKey"),s=xt("isSeeking"),i=on("scrollHeight"),a=xt("ItemComponent"),l=xt("ListComponent"),c=xt("ScrollSeekPlaceholder"),d=xt("context"),f=on("itemDimensions"),p=on("gap"),h=xt("log"),m=xt("stateRestoreInProgress"),x=on("reportReadyState"),y=rr(b.useMemo(()=>g=>{const w=g.parentElement.parentElement.scrollHeight;i(w);const S=g.firstChild;if(S){const{height:k,width:T}=S.getBoundingClientRect();f({height:k,width:T})}p({column:Cf("column-gap",getComputedStyle(g).columnGap,h),row:Cf("row-gap",getComputedStyle(g).rowGap,h)})},[i,f,p,h]),!0,!1);return cf(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),m?null:u.jsx(l,{className:t,ref:y,...Lt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(g=>{const w=o(g.index,g.data,d);return s?u.jsx(c,{...Lt(c,d),height:e.itemHeight,index:g.index,width:e.itemWidth},w):b.createElement(a,{...Lt(a,d),className:n,"data-index":g.index,key:w},r(g.index,g.data,d))})})}),I0=b.memo(function(){const e=xt("HeaderComponent"),t=on("headerHeight"),n=xt("headerFooterTag"),r=rr(b.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,!1),o=xt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Lt(e,o)})}):null}),N0=b.memo(function(){const e=xt("FooterComponent"),t=on("footerHeight"),n=xt("headerFooterTag"),r=rr(b.useMemo(()=>s=>{t($n(s,"height"))},[t]),!0,!1),o=xt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Lt(e,o)})}):null}),A0=({children:e})=>{const t=b.useContext(lf),n=on("itemDimensions"),r=on("viewportDimensions"),o=rr(b.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return b.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:Cs(!1),children:e})},j0=({children:e})=>{const t=b.useContext(lf),n=on("windowViewportRect"),r=on("itemDimensions"),o=xt("customScrollParent"),s=Rd(n,o,!1);return b.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:Cs(!1),children:e})},_0=b.memo(function({...e}){const t=xt("useWindowScroll"),n=xt("customScrollParent"),r=n||t?P0:R0,o=n||t?j0:A0,s=xt("context");return u.jsx(r,{...e,...Lt(r,s),children:u.jsxs(o,{children:[u.jsx(I0,{}),u.jsx(E0,{}),u.jsx(N0,{})]})})}),{useEmitter:Sf,useEmitterValue:xt,usePublisher:on}=sf(k0,{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"}},_0),R0=hf({useEmitter:Sf,useEmitterValue:xt,usePublisher:on}),P0=mf({useEmitter:Sf,useEmitterValue:xt,usePublisher:on});function Cf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Vt.WARN),t==="normal"?0:parseInt(t??"0",10)}const O0=xo.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 Tf({className:e,variant:t,...n}){return u.jsx("div",{className:Z(O0({variant:t}),e),...n})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:Z("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:Z("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:Z("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const kf=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));kf.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:Z("p-6 pt-0",e),...t}));co.displayName="CardContent";const Ef=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:Z("flex items-center p-6 pt-0",e),...t}));Ef.displayName="CardFooter";const M0=1,D0=1e6;let Ta=0;function L0(){return Ta=(Ta+1)%Number.MAX_SAFE_INTEGER,Ta.toString()}const ka=new Map,If=e=>{if(ka.has(e))return;const t=setTimeout(()=>{ka.delete(e),uo({type:"REMOVE_TOAST",toastId:e})},D0);ka.set(e,t)},F0=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,M0)};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?If(n):e.toasts.forEach(r=>{If(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)}}},Es=[];let Is={toasts:[]};function uo(e){Is=F0(Is,e),Es.forEach(t=>{t(Is)})}function $0({...e}){const t=L0(),n=o=>uo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>uo({type:"DISMISS_TOAST",toastId:t});return uo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ea(){const[e,t]=v.useState(Is);return v.useEffect(()=>(Es.push(t),()=>{const n=Es.indexOf(t);n>-1&&Es.splice(n,1)}),[e]),{...e,toast:$0,dismiss:n=>uo({type:"DISMISS_TOAST",toastId:n})}}async function Nf(e,t){return await Qt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Af(e,t){return await(await Nf(`/files/${e}/view`,t)).text()}async function z0(e,t){const n=await Nf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Qt(`/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 B0(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Qt("/files",{params:r})}function Ia(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 jf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function fo(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(fo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(jf(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=fo(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function po(e){if(typeof e=="string")return e;if(jf(e))return"";try{const t=fo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function H0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function U0(e){const t=po(e);return typeof e=="string"&&H0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Ns(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ia(t);if(n!==null)return Ns(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Ns(e.content):e}var As="Dialog",[_f,vT]=In(As),[W0,hn]=_f(As),Rf=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=xr({prop:r,defaultProp:o??!1,onChange:s,caller:As});return u.jsx(W0,{scope:t,triggerRef:a,contentRef:l,contentId:Nn(),titleId:Nn(),descriptionId:Nn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Rf.displayName=As;var Pf="DialogTrigger",Of=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Pf,n),s=Ue(t,o.triggerRef);return u.jsx(Re.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":ja(o.open),...r,ref:s,onClick:ue(e.onClick,o.onOpenToggle)})});Of.displayName=Pf;var Na="DialogPortal",[V0,Mf]=_f(Na,{forceMount:void 0}),Df=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=hn(Na,t);return u.jsx(V0,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(tn,{present:n||s.open,children:u.jsx(Jo,{asChild:!0,container:o,children:i})}))})};Df.displayName=Na;var js="DialogOverlay",Lf=v.forwardRef((e,t)=>{const n=Mf(js,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(js,e.__scopeDialog);return s.modal?u.jsx(tn,{present:r||s.open,children:u.jsx(q0,{...o,ref:t})}):null});Lf.displayName=js;var K0=Yn.createSlot("DialogOverlay.RemoveScroll"),q0=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(js,n);return u.jsx(is,{as:K0,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Re.div,{"data-state":ja(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),ir="DialogContent",Ff=v.forwardRef((e,t)=>{const n=Mf(ir,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(ir,e.__scopeDialog);return u.jsx(tn,{present:r||s.open,children:s.modal?u.jsx(G0,{...o,ref:t}):u.jsx(Y0,{...o,ref:t})})});Ff.displayName=ir;var G0=v.forwardRef((e,t)=>{const n=hn(ir,e.__scopeDialog),r=v.useRef(null),o=Ue(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Bi(s)},[]),u.jsx($f,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ue(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ue(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault())})}),Y0=v.forwardRef((e,t)=>{const n=hn(ir,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx($f,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),$f=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=hn(ir,n),l=v.useRef(null),c=Ue(t,l);return Si(),u.jsxs(u.Fragment,{children:[u.jsx($o,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Fo,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ja(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(X0,{titleId:a.titleId}),u.jsx(Z0,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Aa="DialogTitle",zf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Aa,n);return u.jsx(Re.h2,{id:o.titleId,...r,ref:t})});zf.displayName=Aa;var Bf="DialogDescription",Hf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Bf,n);return u.jsx(Re.p,{id:o.descriptionId,...r,ref:t})});Hf.displayName=Bf;var Uf="DialogClose",Wf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Uf,n);return u.jsx(Re.button,{type:"button",...r,ref:t,onClick:ue(e.onClick,()=>o.onOpenChange(!1))})});Wf.displayName=Uf;function ja(e){return e?"open":"closed"}var Vf="DialogTitleWarning",[wT,Kf]=tx(Vf,{contentName:ir,titleName:Aa,docsSlug:"dialog"}),X0=({titleId:e})=>{const t=Kf(Vf),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
87
87
|
|
|
88
88
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
89
89
|
|
|
90
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},J0="DialogDescriptionWarning",Z0=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Kf(J0).contentName}}.`;return v.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},qf=Rf,Q0=Of,Gf=Df,_s=Lf,Rs=Ff,ar=zf,Ps=Hf,Yf=Wf;const eS=qf,tS=Gf,Xf=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{ref:n,className:
|
|
90
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},J0="DialogDescriptionWarning",Z0=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Kf(J0).contentName}}.`;return v.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},qf=Rf,Q0=Of,Gf=Df,_s=Lf,Rs=Ff,ar=zf,Ps=Hf,Yf=Wf;const eS=qf,tS=Gf,Xf=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{ref:n,className:Z("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Xf.displayName=_s.displayName;const Jf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===ar||(c==null?void 0:c.displayName)===ar.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(tS,{children:[u.jsx(Xf,{}),u.jsxs(Rs,{ref:r,className:Z("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(ar,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Yf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(oe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Jf.displayName=Rs.displayName;const Zf=({className:e,...t})=>u.jsx("div",{className:Z("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Zf.displayName="DialogHeader";const Qf=v.forwardRef(({className:e,...t},n)=>u.jsx(ar,{ref:n,className:Z("text-lg font-semibold leading-none tracking-tight",e),...t}));Qf.displayName=ar.displayName;const nS=v.forwardRef(({className:e,...t},n)=>u.jsx(Ps,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));nS.displayName=Ps.displayName;function rS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=b.useState(!1),[a,l]=b.useState(null),[c,d]=b.useState(null),{toast:f}=Ea(),p=b.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const g=await Af(n);l(g)}catch(g){console.error("Failed to load file:",g),d(g instanceof Error?g.message:"Failed to load file")}finally{i(!1)}}},[n]);b.useEffect(()=>{e&&n&&p()},[e,n,p]);const h=async()=>{if(n)try{await z0(n),f({title:"Download started",description:`Downloading ${r}`})}catch(g){console.error("Failed to download file:",g),f({title:"Download failed",description:String(g),variant:"destructive"})}},m=async()=>{if(n)try{const g=await Af(n),w=new Blob([g],{type:o}),S=URL.createObjectURL(w);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(g){console.error("Failed to open file externally:",g),f({title:"Failed to open file",description:String(g),variant:"destructive"})}},x=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(oe.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(nt,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(oe.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(oe.Image,{className:"h-5 w-5"}):u.jsx(oe.FileText,{className:"h-5 w-5"});return u.jsx(eS,{open:e,onOpenChange:t,children:u.jsxs(Jf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Zf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(Qf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(nt,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(oe.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(nt,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(oe.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:x()})]})})}function ep(){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 lr=ep();function oS(e){lr=e}const tp=/[&<>"']/,sS=new RegExp(tp.source,"g"),np=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,iS=new RegExp(np.source,"g"),aS={"&":"&","<":"<",">":">",'"':""","'":"'"},rp=e=>aS[e];function Ft(e,t){if(t){if(tp.test(e))return e.replace(sS,rp)}else if(np.test(e))return e.replace(iS,rp);return e}const lS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function op(e){return e.replace(lS,(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 cS=/(^|[^\[])\^/g;function ut(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(cS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const uS=/[^\w:]/g,dS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function sp(e,t,n){if(e){let r;try{r=decodeURIComponent(op(n)).replace(uS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!dS.test(n)&&(n=mS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Os={},fS=/^[^:]+:\/*[^/]*$/,pS=/^([^:]+:)[\s\S]*$/,hS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function mS(e,t){Os[" "+e]||(fS.test(e)?Os[" "+e]=e+"/":Os[" "+e]=Ds(e,"/",!0)),e=Os[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(pS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(hS,"$1")+t:e+t}const Ms={exec:function(){}};function ip(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ds(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 gS(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 xS(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 ap(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function lp(e,t,n,r){const o=t.href,s=t.title?Ft(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:Ft(i)}}function yS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
91
91
|
`).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
|
|
92
92
|
`)}class _a{constructor(t){this.options=t||lr}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:Ds(r,`
|
|
93
93
|
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=yS(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=Ds(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,p,h,m,x=n[1].trim();const y=x.length>1,g={type:"list",raw:"",ordered:y,start:y?+x.slice(0,-1):"",loose:!1,items:[]};x=y?`\\d{1,9}\\${x.slice(-1)}`:`\\${x}`,this.options.pedantic&&(x=y?x:"[*+-]");const w=new RegExp(`^( {0,3}${x})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(m=!1,!(!(n=w.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
@@ -132,6 +132,6 @@ ${t}</tr>
|
|
|
132
132
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
133
133
|
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=sp(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=sp(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 up{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 dp{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 Hn{constructor(t){this.options=t||lr,this.options.renderer=this.options.renderer||new Ra,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new up,this.slugger=new dp}static parse(t,n){return new Hn(n).parse(t)}static parseInline(t,n){return new Hn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,m,x,y,g,w,S,k,T,C;const E=t.length;for(o=0;o<E;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(C=this.options.extensions.renderers[h.type].call({parser:this},h),C!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=C||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,op(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(m=h.ordered,x=h.start,y=h.loose,a=h.items.length,p="",s=0;s<a;s++)w=h.items[s],S=w.checked,k=w.task,g="",w.task&&(T=this.renderer.checkbox(S),y?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=T+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=T+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:T}):g+=T),g+=this.parse(w.tokens,y),p+=this.renderer.listitem(g,k,S);r+=this.renderer.list(p,m,x);continue}case"html":{r+=this.renderer.html(h.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(h.tokens));continue}case"text":{for(p=h.tokens?this.parseInline(h.tokens):h.text;o+1<E&&t[o+1].type==="text";)h=t[++o],p+=`
|
|
134
134
|
`+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const j='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(j);return}else throw new Error(j)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ls{constructor(t){this.options=t||lr}preprocess(t){return t}postprocess(t){return t}}Kh(Ls,"passThroughHooks",new Set(["preprocess","postprocess"]));function wS(e,t,n){return r=>{if(r.message+=`
|
|
135
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Ft(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 fp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...xe.defaults,...s};const i=wS(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(xS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&xe.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;xe.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(xe.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&&xe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function xe(e,t,n){return fp(Bn.lex,Hn.parse)(e,t,n)}xe.options=xe.setOptions=function(e){return xe.defaults={...xe.defaults,...e},oS(xe.defaults),xe},xe.getDefaults=ep,xe.defaults=lr,xe.use=function(...e){const t=xe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=xe.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=xe.defaults.renderer||new Ra;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=xe.defaults.tokenizer||new _a;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=xe.defaults.hooks||new Ls;for(const s in n.hooks){const i=o[s];Ls.passThroughHooks.has(s)?o[s]=a=>{if(xe.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=xe.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}}xe.setOptions(r)})},xe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(xe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(xe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(xe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(xe.walkTokens(r.items,t));break}default:xe.defaults.extensions&&xe.defaults.extensions.childTokens&&xe.defaults.extensions.childTokens[r.type]?xe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(xe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(xe.walkTokens(r.tokens,t)))}return n},xe.parseInline=fp(Bn.lexInline,Hn.parseInline),xe.Parser=Hn,xe.parser=Hn.parse,xe.Renderer=Ra,xe.TextRenderer=up,xe.Lexer=Bn,xe.lexer=Bn.lex,xe.Tokenizer=_a,xe.Slugger=dp,xe.Hooks=Ls,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,Hn.parse,Bn.lex;function ho({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof xe.parse=="function"?xe.parse(i):xe(i)}return typeof xe.parse=="function"?xe.parse(e):xe(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=b.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:
|
|
136
|
-
`)):r=t(e),r||""}function TS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function hp(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function kS({className:e}){const[t,n]=b.useState(0);return b.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:
|
|
137
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[_e[we]?u.jsx(oe.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ft,_e[we]?" (processing)":""]})]},we)}if(W.type==="interrupt"){const ye=W,ft=Fs((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id)),gt=!!(Ie&&ft&&ft===Ie),St=gt?Ae??(ye==null?void 0:ye.value):ye==null?void 0:ye.value,Oe=ft?{...ye,id:ft,interrupt_id:ft}:ye;return u.jsx(ES,{interruptPart:Oe,onApprove:et,onReject:Nt,disabled:w,isActive:gt,payload:St},we)}return null},[V,_e,et,Nt,M,c,d,R,L,Ie,Ae,g,w,Z]),at=b.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(oe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),de=b.useCallback(()=>{const W=te.trim().length>0||ne.length>0||ke.length>0||Z.length>0;if(!J&&ke.length>0&&!r)return at();if(!J&&!W&&!r)return null;if(J)return u.jsx(AS,{message:t,viewMode:F},t.id);if(!J&&!X){const we=t,ye=u.jsx("div",{className:"space-y-2",children:we.content.map((ft,gt)=>u.jsx(mt,{part:ft,i:gt},gt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ye,u.jsx(kS,{className:H})]}):ye}},[te,ne.length,ke.length,Z.length,r,J,F,at,H]),pe=b.useMemo(()=>X?"Assistant":TS(t),[X,t]),me=b.useMemo(()=>X?[]:Array.isArray(T)?T:[],[T,X]),ze=b.useMemo(()=>{var W;return me.length?j&&me.some(we=>we.id===j)?j:((W=me[0])==null?void 0:W.id)??null:null},[j,me]),ot=b.useMemo(()=>!me.length||!C?null:me.some(W=>W.id===C)?C:null,[C,me])??ze,Et=M==="user"&&me.length>0&&typeof E=="function",st=b.useCallback(W=>{if(!E)return;const we=(W==null?void 0:W.id)??null,ye=(W==null?void 0:W.parentId)??N??null;E(we,ye)},[N,E]),Be=b.useMemo(()=>ot?me.findIndex(W=>W.id===ot):-1,[ot,me]),jt=b.useMemo(()=>Be<0?null:me[Be]??null,[Be,me]),At=b.useCallback(W=>{const we=[];if(W.step!==null&&we.push(`Step ${W.step}`),W.source&&we.push(W.source),!W.createdAt)return we.length?we.join(" • "):W.id.slice(0,8);let ye="";try{const ft=new Date(W.createdAt);Number.isNaN(ft.getTime())||(ye=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(ft))}catch{ye=""}return`${ye}`},[]);return J&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:Q(Xe(),p.container),children:u.jsxs("div",{className:Q(Qe(),p.content),children:[(i||a||J)&&u.jsxs("div",{className:Q("flex items-center justify-between mb-2 pb-2 border-b border-current/10",L&&"mb-1 pb-1",H,p.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[qe(),a&&pe&&u.jsx("span",{className:Q("font-medium",L?"text-xs":"text-sm"),children:pe}),J&&u.jsxs(Tf,{variant:"outline",className:Q("text-xs flex items-center gap-1 cursor-pointer select-none",H,"border border-current/40",L&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>$(W=>W==="expanded"?"preview":"expanded"),onKeyDown:W=>{(W.key==="Enter"||W.key===" ")&&(W.preventDefault(),$(we=>we==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:se.name??"Tool Output"}),se.toolCallId&&u.jsx("span",{className:"opacity-70",children:se.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(oe.ChevronUp,{className:"h-3 w-3"}):u.jsx(oe.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Et&&jt&&Be>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:Q("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Be>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Be<=0)return;const W=me[Be-1];W&&st(W)},"aria-label":"Previous checkpoint",disabled:Be<=0,children:u.jsx(oe.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[Be+1," / ",me.length]}),u.jsx("span",{className:"text-muted-foreground",children:At(jt)})]}),u.jsx("button",{type:"button",className:Q("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Be<me.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Be>=me.length-1)return;const W=me[Be+1];W&&st(W)},"aria-label":"Next checkpoint",disabled:Be>=me.length-1,children:u.jsx(oe.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:Q("text-xs opacity-60",H,L&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:Q("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ze(),className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(oe.Copy,{className:Q(A?"text-success":H,L?"h-3 w-3":"h-4 w-4")})})}),M==="user"&&h&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ve,className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(oe.Edit,{className:Q(H,L?"h-3 w-3":"h-4 w-4")})}),M==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ke,className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(oe.RotateCcw,{className:Q(H,L?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:de()}),J&&F==="expanded"&&(se.toolCallId||se.name)&&u.jsxs("div",{className:Q("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",L&&"text-xs"),children:[se.name&&u.jsxs("div",{children:["Function: ",se.name]}),se.toolCallId&&u.jsxs("div",{children:["Call ID: ",se.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:Q("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ze(),className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.Copy,{className:Q(A?"text-success":"text-current",L?"h-3 w-3":"h-4 w-4")})}),M==="user"&&h&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ve,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.Edit,{className:Q("text-current",L?"h-3 w-3":"h-4 w-4")})}),M==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ke,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.RotateCcw,{className:Q("text-current",L?"h-3 w-3":"h-4 w-4")})})]})]})}),q&&u.jsx(rS,{isOpen:ee,onClose:D,fileId:q.id,fileName:q.name,mimeType:q.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&hp(e.message)===hp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});function mp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:bS,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:po(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:po(e)})}function ES({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=po(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:Q("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(kf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(Ef,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(nt,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(nt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function IS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ea(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(h=>{a(h),c(!0)},[]),p=b.useCallback(async(h,m,x)=>{var y,g;if(!t){h.preventDefault();return}if(o[x]){h.preventDefault();return}try{const w=String(m.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],T=m.name||`file_${k}`,C=m.mimeType||"application/octet-stream";f({id:k,name:T,mimeType:C});return}if(w.startsWith("data:")){h.preventDefault(),s(T=>({...T,[x]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const T=await B0(n??void 0);if(!T||!Array.isArray(T))throw new Error("Invalid file list response");const C=T.find(E=>!E||typeof E!="object"||!((E.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:m.name||C.filename||`file_${C.id}`,mimeType:m.mimeType||C.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(T){console.error("Failed to fetch server file:",T);const C=T instanceof Error?T.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(T=>({...T,[x]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function NS({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:Q("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(ho,{content:e,allowHtml:!1}):u.jsxs("pre",{className:Q("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(nt,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(oe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(oe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function AS({message:e,viewMode:t}){const r=pp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Ia(c)??c:c;if(d&&typeof d=="object")return u.jsx(mp,{data:d});const f=typeof d=="string"?d:(()=>{try{return po(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=U0(c);return f?u.jsx(ho,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(oe.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Ns(d);return s(f)}const a=fo(i),l=Ns(a);return s(l)}const gp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,jS=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},Oa=b.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:m=!0,isNavigatingCheckpoint:x=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C=!0,checkpointMetaById:E,checkpointIndexByKey:j,activeCheckpointId:N,onSelectCheckpoint:A,timelineCheckpoints:O},F)=>{const $=b.useRef(null),R=b.useRef(null),z=b.useRef(!1),[_,B]=b.useState(!0),L=b.useMemo(()=>w?e.some(Z=>"type"in Z&&Z.type==="default_message"?!1:Array.isArray(Z==null?void 0:Z.content)&&Z.content.some(fe=>fe&&fe.type==="interrupt"&&(fe.id??fe.interrupt_id)===w.id)):!1,[w,e]),M=b.useMemo(()=>{if(!w||L)return null;const Z=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let fe;const Ie=w.value;if(Ie&&typeof Ie=="object"&&!Array.isArray(Ie)){const Ae=Ie.title;typeof Ae=="string"&&Ae.trim()&&(fe=Ae.trim())}return{id:`interrupt-${Z}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:Z,value:Ie,title:fe}]}},[w,L]),J=b.useMemo(()=>M?[...e,M]:e,[e,M]),X=b.useMemo(()=>C?J:J.filter(Z=>(Z==null?void 0:Z.role)!=="tool"),[J,C]),he=b.useMemo(()=>{const Z=new Set,fe=[];for(let Ie=X.length-1;Ie>=0;Ie--){const Ae=X[Ie];if(!Ae)continue;if("type"in Ae&&Ae.type==="default_message"){fe.push(Ae);continue}const Fe=Ae,Ze=jS(Fe);Z.has(Ze)||(Z.add(Ze),fe.push(Fe))}return fe.reverse()},[X]),Ne=b.useCallback(Z=>{B(Z),y&&y(!Z),g&&g(Z)},[y,g]),_e=b.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),V=b.useMemo(()=>!m||x?!1:_?"auto":!1,[_,m,x]),ee=b.useMemo(()=>O??[],[O]),q=N??(ee.length?ee[ee.length-1].id:null),D=ee.length>0,H=b.useMemo(()=>{if(typeof h!="string")return null;const Z=h.trim();return Z?{id:"default-message",role:"assistant",type:"default_message",content:Z,createdAt:new Date().toISOString()}:null},[h]),te=D?u.jsxs("div",{className:"w-48 flex-shrink-0 flex-col border-r border-border/40 pr-4 flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-5 pb-5 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative z-50",children:[u.jsx(oe.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-56 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.'})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-5 top-0 bottom-0 w-px bg-border/50"}),u.jsx("div",{className:"flex flex-col gap-4",children:ee.map(Z=>{const fe=q===Z.id;return u.jsxs("button",{type:"button",disabled:!A,onClick:()=>A==null?void 0:A(Z.id),className:`relative flex items-start gap-3 text-left text-xs transition ${fe?"text-primary":"text-muted-foreground"} ${A?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-4 w-4 items-center justify-center rounded-full border ${fe?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${fe?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:Z.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[Z.step!==null?`STEP ${Z.step}`:"STEP —",Z.next?` - ${Z.next}`:""]})]})]},Z.id)})})]}),A&&u.jsx("button",{type:"button",onClick:()=>A==null?void 0:A(null),className:"mt-auto rounded-md border border-border/70 px-3 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null,se=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),ne=()=>H?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Pa,{message:H,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),ke=he.length>0;return b.useImperativeHandle(F,()=>({scrollToLatest:()=>{var Z,fe;if($.current&&he.length>0){const Ie=he.length-1;(fe=(Z=$.current).scrollToIndex)==null||fe.call(Z,{index:Ie,align:"end",behavior:"auto"})}else R.current&&(R.current.scrollTop=R.current.scrollHeight)},scrollToTop:()=>{var Z,fe;$.current&&he.length>0?(fe=(Z=$.current).scrollToIndex)==null||fe.call(Z,{index:0,align:"start",behavior:"auto"}):R.current&&(R.current.scrollTop=0)}}),[he]),u.jsxs("div",{className:se,style:p,children:[te,u.jsx("div",{className:"relative flex-1 min-h-0",children:ke?u.jsx(v0,{ref:Z=>{$.current=Z},scrollerRef:Z=>{R.current=Z instanceof HTMLDivElement?Z:null},data:he,followOutput:V,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_e&&_e()},atBottomStateChange:Ne,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(Z,fe)=>gp(fe,Z),itemContent:(Z,fe)=>{var et;const Ie=gp(fe,Z),Ae="type"in fe&&fe.type==="default_message";let Fe=[],Ze=null,Ve={},Ke={},qe=null,Xe=null;if(!Ae){const Nt=fe,mt=Nt.checkpointId??null;Ve=Nt.additionalKwargs??{},Ke=Nt.responseMetadata??{};const at=mt&&E?E.get(mt)??null:null;qe=typeof Ve.step=="number"?Ve.step:typeof Ke.step=="number"?Ke.step:(at==null?void 0:at.step)??null;const de=typeof Ve.source=="string"?Ve.source:typeof Ke.source=="string"?Ke.source:(at==null?void 0:at.source)??null;Xe=de?String(de):null;const pe=qe!==null&&Xe?`${qe}:${Xe}`:null;pe&&(j!=null&&j.has(pe))?Fe=j.get(pe)??[]:mt&&at&&(Fe=[at]),Ze=mt??((et=Fe[0])==null?void 0:et.id)??null}const Qe=(()=>{if(typeof Ve.parentCheckpointId=="string")return Ve.parentCheckpointId;if(typeof Ke.parentCheckpointId=="string")return Ke.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":Ie,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Pa,{message:fe,messageIndex:Z,isStreamingMessage:t&&n===fe.id,streamingDebounceMs:r,isEditing:i===fe.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(Z),onCancelEdit:d,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C,checkpointCandidates:Fe,activeCheckpointId:N??null,onSelectCheckpoint:A,defaultCheckpointId:Ze,messageParentCheckpointId:Qe})})}}):ne()})]})});Oa.displayName="MessageList";const xp={value:""};function $s({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,customStyles:f={},onMessageSent:p,onExcelUploadSuccess:h,onError:m}){const{api:x}=fi(),{currentThreadId:y}=Oo(),{threadId:g,messages:w,hasMore:S,isHistoryLoading:k,isLoading:T,loadOlder:C,navigateToCheckpoint:E,returnToLatest:j,checkpoint:N,checkpoints:A,interrupt:O,metadata:F}=Mo(),{isStreaming:$,error:R,connectionState:z,submit:_,stop:B}=pc(),L=g??y??null,M=(N==null?void 0:N.id)??null,J=(N==null?void 0:N.namespace)??null,X=(F==null?void 0:F.assemblingMessageId)??null,he=O,[Ne,_e]=b.useState(!1);b.useEffect(()=>{he||_e(!1)},[he]);const V=b.useCallback(()=>{_e(!0)},[]),ee=b.useCallback(()=>{_e(!1)},[]),q=!!he||Ne,[D,H]=b.useState(null),[te,se]=b.useState(""),[ne,ke]=b.useState(null),[Z,fe]=b.useState(null),[Ie,Ae]=b.useState([]),[Fe,Ze]=b.useState(0),[Ve,Ke]=b.useState(0),[qe,Xe]=b.useState(!1),[Qe,et]=b.useState(null),[Nt,mt]=b.useState(null),[at,de]=b.useState(!1),[pe,me]=b.useState(null),[ze,De]=b.useState(!1),ot=b.useRef(!1),[Et,st]=b.useState(()=>xp.value),Be=b.useRef(Et),jt=b.useRef(null),At=b.useCallback(G=>{xp.value=G,st(G)},[]),[W,we]=b.useState(!1),ye=b.useRef(null),ft=b.useCallback(G=>{if(!Array.isArray(G))return{text:null,messageId:null};for(let re=G.length-1;re>=0;re--){const ae=G[re];if(!ae||ae.role!=="user")continue;const Se=(ae.content??[]).filter(Ye=>(Ye==null?void 0:Ye.type)==="text").map(Ye=>Ye.text).filter(Ye=>typeof Ye=="string"&&Ye.trim().length>0);return{text:Se.length?Se.join(" ").trim():null,messageId:ae.id??null}}return{text:null,messageId:null}},[]),gt=b.useCallback((G,re)=>{if(!G||typeof G!="object")return null;const ae=G[re];return typeof ae=="number"?ae:null},[]),St=b.useCallback((G,re)=>{if(!G||typeof G!="object")return null;const ae=G[re];return typeof ae=="string"&&ae.trim()?ae:null},[]),Oe=b.useMemo(()=>{const G=Se=>{if(!Array.isArray(Se)||Se.length===0)return null;const dt=Se.map(Ye=>{if(typeof Ye=="string")return Ye.trim();if(Ye&&typeof Ye=="object"&&"type"in Ye){const tt=Ye;if(typeof tt.type=="string")return tt.type}return null}).filter(Ye=>!!(Ye&&Ye.length));return dt.length?dt.join(", "):null},re=Array.isArray(A)?A.map(Se=>{const dt=G(Se.next);return dt?{...Se,metadata:{...Se.metadata??{},next:dt}}:Se}):[];return re.some(Se=>gt(Se.metadata,"step")!==null)&&re.sort((Se,dt)=>{const Ye=gt(Se.metadata,"step"),tt=gt(dt.metadata,"step");if(Ye!==null||tt!==null)return(tt??Number.NEGATIVE_INFINITY)-(Ye??Number.NEGATIVE_INFINITY);const Ot=Date.parse(Se.createdAt??""),ln=Date.parse(dt.createdAt??"");return Number.isNaN(Ot)||Number.isNaN(ln)?0:ln-Ot}),re},[A,gt]),{checkpointMetaById:Kt,checkpointIndexByKey:lt}=b.useMemo(()=>{const G=new Map,re=new Map;for(const ae of Oe){const Se=ae.checkpointId??null;if(!Se)continue;const dt=gt(ae.metadata,"step"),Ye=St(ae.metadata,"source"),tt={id:Se,step:dt,source:Ye,createdAt:ae.createdAt??null,namespace:ae.checkpointNs??null,parentId:ae.parentId??null};if(G.set(Se,tt),dt!==null&&Ye){const Ot=`${dt}:${Ye}`,ln=re.get(Ot)??[];ln.push(tt),re.set(Ot,ln)}}for(const ae of re.values())ae.sort((Se,dt)=>{const Ye=Se.createdAt??"";return(dt.createdAt??"").localeCompare(Ye)});return{checkpointMetaById:G,checkpointIndexByKey:re}},[Oe,gt,St]),Ct=b.useMemo(()=>{var Ye;if(!Oe.length)return[];const G=[...Oe].reverse(),re=(tt,Ot)=>{const ln=tt.checkpointId??null;if(!ln)return null;const pr=St(tt.metadata,"source");St(tt.metadata,"next");const{text:Vh,messageId:WC}=ft(tt.messages),Za=Vh&&Vh.replace(/\s+/g," ").trim()||St(tt.metadata,"title")||St(tt.metadata,"label")||Ot||pr||"Checkpoint",VC=Za.length>60?`${Za.slice(0,57)}…`:Za;return{id:ln,label:VC,messageId:WC??null,createdAt:tt.createdAt??null,step:gt(tt.metadata,"step"),source:pr??null,next:St(tt.metadata,"next")}},ae=[],Se=new Set;for(const tt of G){const Ot=((Ye=St(tt.metadata,"source"))==null?void 0:Ye.toLowerCase())??null;if(!(Ot==="input"||Ot==="user_input"||Ot==="user"))continue;const pr=re(tt,"User input");pr&&!Se.has(pr.id)&&(ae.push(pr),Se.add(pr.id))}if(!ae.length)for(const tt of G){const Ot=re(tt);Ot&&!Se.has(Ot.id)&&(ae.push(Ot),Se.add(Ot.id))}const dt=Oe.find(tt=>{var ln;return(((ln=St(tt.metadata,"source"))==null?void 0:ln.toLowerCase())??null)==="loop"});if(dt){const tt=re(dt,"Latest loop");tt&&!Se.has(tt.id)&&(ae.push(tt),Se.add(tt.id))}return ae},[Oe,ft,gt,St]),Kn=b.useRef(null),fr=b.useRef(null),qn=b.useCallback(()=>{Kn.current&&(Kn.current.value=""),fr.current&&(fr.current.value=""),Ze(G=>G+1),Ke(G=>G+1)},[]),Ya=b.useCallback(G=>{At(G)},[At]),Xs=b.useRef(!1);b.useEffect(()=>{Xs.current&&!$&&(Ae([]),qn()),Xs.current=$},[$,qn]);const[Xa,Ja]=b.useState("desktop");b.useEffect(()=>{const G=()=>{const re=window.innerWidth;Ja(re<640?"phone":re<1024?"tablet":"desktop")};return G(),window.addEventListener("resize",G),()=>window.removeEventListener("resize",G)},[]),b.useEffect(()=>{De(!1),ot.current=!1},[L]),b.useEffect(()=>{Be.current=Et},[Et]),b.useEffect(()=>{if(!D){jt.current=null;return}jt.current===null&&(jt.current=Be.current),At(te??"")},[te,D,At]);const I=b.useCallback(async()=>{if(!(!S||k||!ze))try{await C()}catch(G){console.warn("loadOlder failed",G)}},[S,ze,k,C]);b.useEffect(()=>{(async()=>{if(!x.baseUrl){me(null);return}try{const ae=(await x.getAgent("default")).uiDefaultMessage||"";me(ae||null)}catch(re){console.warn("Failed to fetch default message:",re),me(null)}})()},[x.baseUrl]),b.useEffect(()=>{R&&!at&&(m==null||m(R))},[R,at,m]);const K=G=>{if(G.length>fs)return`Message too long (${G.length}/${fs} characters)`;try{return cb(G),null}catch(re){return(re==null?void 0:re.message)||"Invalid message"}},ie=async G=>{const re=G.trim();if(!(!re&&Ie.length===0)){if(re){const ae=K(re);if(ae){fe(ae);return}}try{const ae=M??void 0,Se=J??void 0,dt=D?{edit:!0,originalMessageId:D,...ne!=null&&ne.checkpointId?{originalCheckpointId:ne.checkpointId}:{},...ne!=null&&ne.checkpointNs?{originalCheckpointNs:ne.checkpointNs}:{}}:void 0;await _({text:re||"",attachments:Ie,messageAdditionalKwargs:dt},{checkpointId:ae,checkpointNs:Se}),p==null||p(re),At(""),fe(null),Ae([]),qn(),H(null),se(""),ke(null)}catch(ae){const Se=(ae==null?void 0:ae.message)||"Failed to send message";fe(Se),m==null||m(Se)}}},be=b.useCallback((G,re,ae)=>{c&&(jt.current=Et,H(G),se(re),At(re),fe(null),ke({checkpointId:(ae==null?void 0:ae.checkpointId)??null,checkpointNs:(ae==null?void 0:ae.checkpointNs)??null}))},[Et,c,At]),Ge=b.useCallback(()=>{H(null),se(""),ke(null),fe(null),At(jt.current??Et),jt.current=null},[Et,At]),it=b.useCallback((G,re,ae)=>{be(G,re,ae)},[be]),He=b.useCallback(G=>{for(let re=G-1;re>=0;re--)if(w[re].role==="user"){const ae=w[re].content||[],dt=ae.filter(Ye=>Ye.type==="text").map(Ye=>Ye.text).join("")||(()=>{try{return JSON.stringify(ae,null,2)}catch{return String(ae)}})();dt&&_({text:dt},{checkpointId:M??void 0,checkpointNs:J??void 0});break}},[w,_,M,J]),$e=G=>{const re=Array.from(G.target.files||[]);Ae(ae=>[...ae,...re]),G.target.value=""},Pt=G=>{Ae(re=>{const ae=re.filter((Se,dt)=>G!==dt);return ae.length===0&&qn(),ae})},vt=async G=>{const re=(G.target.files||[])[0];if(re){et(null),mt(null),Xe(!0);try{await _({attachments:[re]},{checkpointId:M??void 0,checkpointNs:J??void 0});const ae=`Uploaded ${re.name} - processing through chat stream`;mt(ae)}catch(ae){const Se=ae instanceof Error?ae.message:"Failed to upload Excel file";console.error("Excel upload failed",ae),et(Se),m==null||m(Se)}finally{Xe(!1),G.target.value="",qn()}}},yt=async G=>{if(y){we(!0);try{if(!G){await j(),De(!1),requestAnimationFrame(()=>{var Se;(Se=ye.current)==null||Se.scrollToLatest()});return}const re=Oe.find(Se=>Se.checkpointId===G),ae=(re==null?void 0:re.checkpointNs)??null;await E(G,ae),De(!0),requestAnimationFrame(()=>{var Se;(Se=ye.current)==null||Se.scrollToTop()})}finally{we(!1)}}},qt=b.useCallback(async G=>{await yt(G)},[yt]),Gn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,Rn=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${f.messagesArea||""}`,$t=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,go=b.useCallback(G=>{if(!G)return"Latest";const re=[];G.step!==null&&re.push(`Step ${G.step}`),G.source&&re.push(G.source);const ae=G.createdAt?new Date(G.createdAt):null,Se=ae&&!Number.isNaN(ae.getTime())?ae.toLocaleString():G.createdAt??G.id,dt=re.length?` — ${re.join(" • ")}`:"";return`${Se}${dt}`},[]);return u.jsxs("div",{className:Gn,children:[!!R&&!at&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:R}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>de(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(oe.X,{size:16})})]}),y&&Oe.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:M??"",onChange:G=>{const re=G.target.value||null;yt(re)},children:[u.jsx("option",{value:"",children:"Latest"}),Oe.map(G=>{const re=Kt.get(G.checkpointId??"")??null;return u.jsx("option",{value:G.checkpointId??void 0,children:go(re)},G.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${Rn}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Oa,{ref:ye,className:"h-full",style:{height:"100%"},messages:w,isStreaming:$,streamingAssistantId:X,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Xa,enableMessageEditing:c,editingMessageId:D,onStartReached:()=>{ze&&I()},onScrollAway:G=>{if(!ot.current){ot.current=!0;return}G&&De(!0)},onEdit:it,onRegenerate:He,onCancelEdit:Ge,emptyMessage:pe??void 0,isNavigatingCheckpoint:W,activeInterrupt:he,disableInterruptActions:Ne,onInterruptActionStart:V,onInterruptActionEnd:ee,showToolMessages:d,checkpointMetaById:Kt,checkpointIndexByKey:lt,activeCheckpointId:M,onSelectCheckpoint:qt,timelineCheckpoints:Ct}),(z==="reconnecting"||z==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(oe.Loader2,{className:"h-3 w-3 animate-spin"}),z==="reconnecting"?"Reconnecting…":"Connecting…"]})}),z==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),T&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(oe.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||W)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(oe.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:$t,children:[D&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(oe.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(oe.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Kn,type:"file",multiple:!0,onChange:G=>$e(G),className:"hidden"},Fe),Ie.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Ie.map((G,re)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(oe.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:G.name}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Pt(re),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 ${G.name}`,children:u.jsx(oe.X,{size:12})})]},re))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:fr,type:"file",accept:".xls,.xlsx,.xlsm",onChange:vt,className:"hidden"},Ve),qe&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(oe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Nt&&!qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Nt}),Qe&&!qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Qe})]})]}),Z&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Z}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(Qw,{children:[u.jsx(eb,{asChild:!0,children:u.jsx(nt,{type:"button",size:"icon",variant:"outline",disabled:$||q,title:"More input actions",className:f.moreButton||"",children:u.jsx(oe.Plus,{size:16})})}),u.jsxs(Td,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(ea,{onClick:()=>{var G;return(G=Kn.current)==null?void 0:G.click()},className:"cursor-pointer",children:[u.jsx(oe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(ea,{onClick:()=>{var G;qe||(G=fr.current)==null||G.click()},className:`cursor-pointer ${qe?"opacity-60 pointer-events-none":""}`,children:[u.jsx(oe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(ex,{initialValue:te,editingMessageId:D,value:Et,onValueChange:Ya,placeholder:D?"Edit your message...":t,isStreaming:$,disabled:q,maxLength:fs,onSend:ie,onCancelEdit:Ge,onStop:B,allowEmptySend:Ie.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${D?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Z?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const zs=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:Q("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}));zs.displayName="Input";function Ma(e,[t,n]){return Math.min(n,Math.max(t,e))}function _S(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Da="ScrollArea",[yp,bT]=In(Da),[RS,sn]=yp(Da),vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,m]=v.useState(null),[x,y]=v.useState(null),[g,w]=v.useState(0),[S,k]=v.useState(0),[T,C]=v.useState(!1),[E,j]=v.useState(!1),N=Ue(t,O=>l(O)),A=Lo(o);return u.jsx(RS,{scope:n,type:r,dir:A,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:m,scrollbarXEnabled:T,onScrollbarXEnabledChange:C,scrollbarY:x,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:w,onCornerHeightChange:k,children:u.jsx(Re.div,{dir:A,...i,ref:N,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});vp.displayName=Da;var wp="ScrollAreaViewport",bp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=sn(wp,n),a=v.useRef(null),l=Ue(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(Re.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});bp.displayName=wp;var kn="ScrollAreaScrollbar",La=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(PS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(OS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Sp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Fa,{...r,ref:t}):null});La.displayName=kn;var PS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(tn,{present:n||s,children:u.jsx(Sp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),OS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ws(()=>l("SCROLL_END"),100),[a,l]=_S("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(tn,{present:n||a!=="hidden",children:u.jsx(Fa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ue(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ue(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Sp=v.forwardRef((e,t)=>{const n=sn(kn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ws(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Ar(n.viewport,l),Ar(n.content,l),u.jsx(tn,{present:r||s,children:u.jsx(Fa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Fa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=sn(kn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Ip(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return zS(p,i.current,a,h)}return n==="horizontal"?u.jsx(MS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Np(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(DS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Np(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),MS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Ue(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Tp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Us(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),jp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Hs(i.paddingLeft),paddingEnd:Hs(i.paddingRight)}})}})}),DS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Ue(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Tp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Us(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),jp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Hs(i.paddingTop),paddingEnd:Hs(i.paddingBottom)}})}})}),[LS,Cp]=yp(kn),Tp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=sn(kn,n),[m,x]=v.useState(null),y=Ue(t,N=>x(N)),g=v.useRef(null),w=v.useRef(""),S=h.viewport,k=r.content-r.viewport,T=Rt(d),C=Rt(l),E=Ws(f,10);function j(N){if(g.current){const A=N.clientX-g.current.left,O=N.clientY-g.current.top;c({x:A,y:O})}}return v.useEffect(()=>{const N=A=>{const O=A.target;(m==null?void 0:m.contains(O))&&T(A,k)};return document.addEventListener("wheel",N,{passive:!1}),()=>document.removeEventListener("wheel",N,{passive:!1})},[S,m,k,T]),v.useEffect(C,[r,C]),Ar(m,E),Ar(h.content,E),u.jsx(LS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Rt(s),onThumbPointerUp:Rt(i),onThumbPositionChange:C,onThumbPointerDown:Rt(a),children:u.jsx(Re.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:ue(e.onPointerDown,N=>{N.button===0&&(N.target.setPointerCapture(N.pointerId),g.current=m.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),j(N))}),onPointerMove:ue(e.onPointerMove,j),onPointerUp:ue(e.onPointerUp,N=>{const A=N.target;A.hasPointerCapture(N.pointerId)&&A.releasePointerCapture(N.pointerId),document.body.style.webkitUserSelect=w.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Bs="ScrollAreaThumb",kp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Cp(Bs,e.__scopeScrollArea);return u.jsx(tn,{present:n||o.hasThumb,children:u.jsx(FS,{ref:t,...r})})}),FS=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=sn(Bs,n),i=Cp(Bs,n),{onThumbPositionChange:a}=i,l=Ue(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ws(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=BS(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Re.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:ue(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),m=f.clientX-h.left,x=f.clientY-h.top;i.onThumbPointerDown({x:m,y:x})}),onPointerUp:ue(e.onPointerUp,i.onThumbPointerUp)})});kp.displayName=Bs;var $a="ScrollAreaCorner",Ep=v.forwardRef((e,t)=>{const n=sn($a,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx($S,{...e,ref:t}):null});Ep.displayName=$a;var $S=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=sn($a,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Ar(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Ar(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Re.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Hs(e){return e?parseInt(e,10):0}function Ip(e,t){const n=e/t;return isNaN(n)?0:n}function Us(e){const t=Ip(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function zS(e,t,n,r="ltr"){const o=Us(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ap([l,c],f)(e)}function Np(e,t,n="ltr"){const r=Us(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Ma(e,l);return Ap([0,i],[0,a])(c)}function Ap(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function jp(e,t){return e>0&&e<t}var BS=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Ws(e,t){const n=Rt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Ar(e,t){const n=Rt(t);_t(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var _p=vp,HS=bp,US=Ep;const Rp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_p,{ref:r,className:Q("relative overflow-hidden",e),...n,children:[u.jsx(HS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Pp,{}),u.jsx(US,{})]}));Rp.displayName=_p.displayName;const Pp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(La,{ref:r,orientation:t,className:Q("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(kp,{className:"relative flex-1 rounded-full bg-border"})}));Pp.displayName=La.displayName;const Op=25;function za({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:m,actions:x}=Oo(),{loadThread:y}=Mo(),{createThread:g,deleteThread:w,renameThread:S}=x,[k,T]=b.useState(Array.isArray(f)?f:[]),C=b.useRef(k.length>0),E=b.useRef(null),j=b.useRef(0),[N,A]=b.useState(null),[O,F]=b.useState(""),[$,R]=b.useState(!1);b.useEffect(()=>{const V=Array.isArray(f)?f:[];if(V.length>0){C.current=!0,T(V);return}m||(C.current=!1,T(V))},[f,m]),b.useEffect(()=>{if(!E.current)return;const V=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!V)return;let ee=null,q=null;return ee=requestAnimationFrame(()=>{q=requestAnimationFrame(()=>{V.scrollTop=j.current})}),()=>{ee!==null&&cancelAnimationFrame(ee),q!==null&&cancelAnimationFrame(q)}},[k]);const z=async V=>{try{h(V),await y(V),a==null||a(V),l==null||l(V)}catch(ee){console.error("Failed to select thread:",ee)}},_=async()=>{try{R(!0);const V=await g();V&&(c==null||c(V),a==null||a(V))}catch(V){console.error("Failed to create thread:",V)}finally{R(!1)}},B=async(V,ee)=>{if(ee.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const q=E.current.querySelector("[data-radix-scroll-area-viewport]");q&&(j.current=q.scrollTop)}try{await w(V),d==null||d(V)}catch(q){console.error("Failed to delete thread:",q)}}},L=(V,ee)=>{ee.stopPropagation(),A(V.threadId),F(V.title||`Thread ${V.threadId.slice(0,8)}`)},M=async V=>{if(O.trim())try{await S(V,O.trim()),A(null),F("")}catch(ee){console.error("Failed to update title:",ee)}},J=()=>{A(null),F("")},X=(V,ee)=>{V.key==="Enter"?M(ee):V.key==="Escape"&&J()},he=V=>{if(!V)return"";try{const ee=new Date(V),D=new Date().getTime()-ee.getTime(),H=Math.floor(D/(1e3*60*60*24));return H===0?ee.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):H===1?"Yesterday":H<7?`${H} days ago`:ee.toLocaleDateString()}catch{return""}},Ne=V=>V.title||`Thread ${V.threadId.slice(0,8)}`,_e=V=>{const ee=Ne(V);return ee.length<=Op?ee:`${ee.slice(0,Op)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(nt,{onClick:_,disabled:$||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:$?"Creating...":"New Chat",children:u.jsx(oe.MessageSquarePlus,{size:20})})}),u.jsx(Rp,{ref:E,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:m?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(oe.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(oe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((V,ee)=>new Date(ee.updatedAt||ee.createdAt||"").getTime()-new Date(V.updatedAt||V.createdAt||"").getTime()).map(V=>u.jsxs("div",{onClick:()=>z(V.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===V.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:N===V.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ee=>ee.stopPropagation(),children:[u.jsx(zs,{value:O,onChange:ee=>F(ee.target.value),onKeyDown:ee=>X(ee,V.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>M(V.threadId),className:"h-6 w-6 p-0",children:u.jsx(oe.Check,{size:12})}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:J,className:"h-6 w-6 p-0",children:u.jsx(oe.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:_e(V)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(oe.Calendar,{size:10}),u.jsx("span",{children:he(V.updatedAt||V.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&N!==V.threadId&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ee=>L(V,ee),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(oe.Edit3,{size:12})}),n&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ee=>B(V.threadId,ee),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(oe.Trash2,{size:12})})]})]}),i===V.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},V.threadId))})})]})}function jr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function WS(e){if(typeof e!="string")return;const t=e.trim();if(t)return En(t)}function Mp(){const e=[jr("__API_BASE_URL__"),jr("__CHAT_API_BASE_URL__"),jr("__CHAT_API_URL__")];for(const t of e){const n=WS(t);if(n)return n}}function Dp(){const e=[jr("__API_AUTH_TOKEN__"),jr("__CHAT_API_KEY__"),jr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Lp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return En(t);return En()}function Fp(){const e={},t=Mp(),n=Dp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function $p(){const e=Fp(),t=Pn.getAuthToken(),n=Mp();return{apiBaseUrl:Lp(e.baseUrl,Pn.baseUrl,n),apiKey:t||e.apiKey||Dp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const zp="chat-settings";function VS(){try{const e=localStorage.getItem(zp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function KS(e){try{const t={...e,apiBaseUrl:En(e.apiBaseUrl)};localStorage.setItem(zp,JSON.stringify(t)),t.apiKey&&Pn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function qS(){const e=$p(),t=VS(),n=Pn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Lp(Pn.baseUrl,r,e.apiBaseUrl)}}function GS(e){Pn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),KS(e)}var YS="Label",Bp=v.forwardRef((e,t)=>u.jsx(Re.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Bp.displayName=YS;var Hp=Bp;const XS=xo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),an=v.forwardRef(({className:e,...t},n)=>u.jsx(Hp,{ref:n,className:Q(XS(),e),...t}));an.displayName=Hp.displayName;function Up(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Vs="Switch",[JS,ST]=In(Vs),[ZS,QS]=JS(Vs),Wp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),m=Ue(t,S=>h(S)),x=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,w]=xr({prop:o,defaultProp:s??!1,onChange:c,caller:Vs});return u.jsxs(ZS,{scope:n,checked:g,disabled:a,children:[u.jsx(Re.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Gp(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ue(e.onClick,S=>{w(k=>!k),y&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),y&&u.jsx(qp,{control:p,bubbles:!x.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Wp.displayName=Vs;var Vp="SwitchThumb",Kp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=QS(Vp,n);return u.jsx(Re.span,{"data-state":Gp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Kp.displayName=Vp;var eC="SwitchBubbleInput",qp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Ue(i,s),l=Up(n),c=Jc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const m=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(m)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});qp.displayName=eC;function Gp(e){return e?"checked":"unchecked"}var Yp=Wp,tC=Kp;const Un=v.forwardRef(({className:e,...t},n)=>u.jsx(Yp,{className:Q("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(tC,{className:Q("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")})}));Un.displayName=Yp.displayName;var Xp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),nC="VisuallyHidden",rC=v.forwardRef((e,t)=>u.jsx(Re.span,{...e,ref:t,style:{...Xp,...e.style}}));rC.displayName=nC;var oC=[" ","Enter","ArrowUp","ArrowDown"],sC=[" ","Enter"],cr="Select",[Ks,qs,iC]=vi(cr),[_r,CT]=In(cr,[iC,Xo]),Gs=Xo(),[aC,Wn]=_r(cr),[lC,cC]=_r(cr),Jp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:m}=e,x=Gs(t),[y,g]=v.useState(null),[w,S]=v.useState(null),[k,T]=v.useState(!1),C=Lo(c),[E,j]=xr({prop:r,defaultProp:o??!1,onChange:s,caller:cr}),[N,A]=xr({prop:i,defaultProp:a,onChange:l,caller:cr}),O=v.useRef(null),F=y?m||!!y.closest("form"):!0,[$,R]=v.useState(new Set),z=Array.from($).map(_=>_.props.value).join(";");return u.jsx(au,{...x,children:u.jsxs(aC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:T,contentId:Nn(),value:N,onValueChange:A,open:E,onOpenChange:j,dir:C,triggerPointerDownPosRef:O,disabled:p,children:[u.jsx(Ks.Provider,{scope:t,children:u.jsx(lC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(_=>{R(B=>new Set(B).add(_))},[]),onNativeOptionRemove:v.useCallback(_=>{R(B=>{const L=new Set(B);return L.delete(_),L})},[]),children:n})}),F?u.jsxs(bh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:N,onChange:_=>A(_.target.value),disabled:p,form:m,children:[N===void 0?u.jsx("option",{value:""}):null,Array.from($)]},z):null]})})};Jp.displayName=cr;var Zp="SelectTrigger",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Gs(n),i=Wn(Zp,n),a=i.disabled||r,l=Ue(t,i.onTriggerChange),c=qs(n),d=v.useRef("touch"),[f,p,h]=Ch(x=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),w=Th(y,x,g);w!==void 0&&i.onValueChange(w.value)}),m=x=>{a||(i.onOpenChange(!0),h()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return u.jsx(lu,{asChild:!0,...s,children:u.jsx(Re.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":Sh(i.value)?"":void 0,...o,ref:l,onClick:ue(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&m(x)}),onPointerDown:ue(o.onPointerDown,x=>{d.current=x.pointerType;const y=x.target;y.hasPointerCapture(x.pointerId)&&y.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(m(x),x.preventDefault())}),onKeyDown:ue(o.onKeyDown,x=>{const y=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&p(x.key),!(y&&x.key===" ")&&oC.includes(x.key)&&(m(),x.preventDefault())})})})});Qp.displayName=Zp;var eh="SelectValue",th=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Wn(eh,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Ue(t,l.onValueNodeChange);return _t(()=>{c(d)},[c,d]),u.jsx(Re.span,{...a,ref:f,style:{pointerEvents:"none"},children:Sh(l.value)?u.jsx(u.Fragment,{children:i}):s})});th.displayName=eh;var uC="SelectIcon",nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Re.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});nh.displayName=uC;var dC="SelectPortal",rh=e=>u.jsx(Jo,{asChild:!0,...e});rh.displayName=dC;var ur="SelectContent",oh=v.forwardRef((e,t)=>{const n=Wn(ur,e.__scopeSelect),[r,o]=v.useState();if(_t(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?yo.createPortal(u.jsx(sh,{scope:e.__scopeSelect,children:u.jsx(Ks.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(ih,{...e,ref:t})});oh.displayName=ur;var mn=10,[sh,Vn]=_r(ur),fC="SelectContentImpl",pC=Yn.createSlot("SelectContent.RemoveScroll"),ih=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:x,avoidCollisions:y,...g}=e,w=Wn(ur,n),[S,k]=v.useState(null),[T,C]=v.useState(null),E=Ue(t,q=>k(q)),[j,N]=v.useState(null),[A,O]=v.useState(null),F=qs(n),[$,R]=v.useState(!1),z=v.useRef(!1);v.useEffect(()=>{if(S)return Bi(S)},[S]),Si();const _=v.useCallback(q=>{const[D,...H]=F().map(ne=>ne.ref.current),[te]=H.slice(-1),se=document.activeElement;for(const ne of q)if(ne===se||(ne==null||ne.scrollIntoView({block:"nearest"}),ne===D&&T&&(T.scrollTop=0),ne===te&&T&&(T.scrollTop=T.scrollHeight),ne==null||ne.focus(),document.activeElement!==se))return},[F,T]),B=v.useCallback(()=>_([j,S]),[_,j,S]);v.useEffect(()=>{$&&B()},[$,B]);const{onOpenChange:L,triggerPointerDownPosRef:M}=w;v.useEffect(()=>{if(S){let q={x:0,y:0};const D=te=>{var se,ne;q={x:Math.abs(Math.round(te.pageX)-(((se=M.current)==null?void 0:se.x)??0)),y:Math.abs(Math.round(te.pageY)-(((ne=M.current)==null?void 0:ne.y)??0))}},H=te=>{q.x<=10&&q.y<=10?te.preventDefault():S.contains(te.target)||L(!1),document.removeEventListener("pointermove",D),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",H,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",H,{capture:!0})}}},[S,L,M]),v.useEffect(()=>{const q=()=>L(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[L]);const[J,X]=Ch(q=>{const D=F().filter(se=>!se.disabled),H=D.find(se=>se.ref.current===document.activeElement),te=Th(D,q,H);te&&setTimeout(()=>te.ref.current.focus())}),he=v.useCallback((q,D,H)=>{const te=!z.current&&!H;(w.value!==void 0&&w.value===D||te)&&(N(q),te&&(z.current=!0))},[w.value]),Ne=v.useCallback(()=>S==null?void 0:S.focus(),[S]),_e=v.useCallback((q,D,H)=>{const te=!z.current&&!H;(w.value!==void 0&&w.value===D||te)&&O(q)},[w.value]),V=r==="popper"?Ba:ah,ee=V===Ba?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:x,avoidCollisions:y}:{};return u.jsx(sh,{scope:n,content:S,viewport:T,onViewportChange:C,itemRefCallback:he,selectedItem:j,onItemLeave:Ne,itemTextRefCallback:_e,focusSelectedItem:B,selectedItemText:A,position:r,isPositioned:$,searchRef:J,children:u.jsx(is,{as:pC,allowPinchZoom:!0,children:u.jsx($o,{asChild:!0,trapped:w.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ue(o,q=>{var D;(D=w.trigger)==null||D.focus({preventScroll:!0}),q.preventDefault()}),children:u.jsx(Fo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(V,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:q=>q.preventDefault(),...g,...ee,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:ue(g.onKeyDown,q=>{const D=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!D&&q.key.length===1&&X(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let te=F().filter(se=>!se.disabled).map(se=>se.ref.current);if(["ArrowUp","End"].includes(q.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const se=q.target,ne=te.indexOf(se);te=te.slice(ne+1)}setTimeout(()=>_(te)),q.preventDefault()}})})})})})})});ih.displayName=fC;var hC="SelectItemAlignedPosition",ah=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Wn(ur,n),i=Vn(ur,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Ue(t,E=>d(E)),p=qs(n),h=v.useRef(!1),m=v.useRef(!0),{viewport:x,selectedItem:y,selectedItemText:g,focusSelectedItem:w}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&x&&y&&g){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),N=s.valueNode.getBoundingClientRect(),A=g.getBoundingClientRect();if(s.dir!=="rtl"){const se=A.left-j.left,ne=N.left-se,ke=E.left-ne,Z=E.width+ke,fe=Math.max(Z,j.width),Ie=window.innerWidth-mn,Ae=Ma(ne,[mn,Math.max(mn,Ie-fe)]);a.style.minWidth=Z+"px",a.style.left=Ae+"px"}else{const se=j.right-A.right,ne=window.innerWidth-N.right-se,ke=window.innerWidth-E.right-ne,Z=E.width+ke,fe=Math.max(Z,j.width),Ie=window.innerWidth-mn,Ae=Ma(ne,[mn,Math.max(mn,Ie-fe)]);a.style.minWidth=Z+"px",a.style.right=Ae+"px"}const O=p(),F=window.innerHeight-mn*2,$=x.scrollHeight,R=window.getComputedStyle(c),z=parseInt(R.borderTopWidth,10),_=parseInt(R.paddingTop,10),B=parseInt(R.borderBottomWidth,10),L=parseInt(R.paddingBottom,10),M=z+_+$+L+B,J=Math.min(y.offsetHeight*5,M),X=window.getComputedStyle(x),he=parseInt(X.paddingTop,10),Ne=parseInt(X.paddingBottom,10),_e=E.top+E.height/2-mn,V=F-_e,ee=y.offsetHeight/2,q=y.offsetTop+ee,D=z+_+q,H=M-D;if(D<=_e){const se=O.length>0&&y===O[O.length-1].ref.current;a.style.bottom="0px";const ne=c.clientHeight-x.offsetTop-x.offsetHeight,ke=Math.max(V,ee+(se?Ne:0)+ne+B),Z=D+ke;a.style.height=Z+"px"}else{const se=O.length>0&&y===O[0].ref.current;a.style.top="0px";const ke=Math.max(_e,z+x.offsetTop+(se?he:0)+ee)+H;a.style.height=ke+"px",x.scrollTop=D-_e+x.offsetTop}a.style.margin=`${mn}px 0`,a.style.minHeight=J+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,x,y,g,s.dir,r]);_t(()=>S(),[S]);const[k,T]=v.useState();_t(()=>{c&&T(window.getComputedStyle(c).zIndex)},[c]);const C=v.useCallback(E=>{E&&m.current===!0&&(S(),w==null||w(),m.current=!1)},[S,w]);return u.jsx(gC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Re.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});ah.displayName=hC;var mC="SelectPopperPosition",Ba=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=mn,...s}=e,i=Gs(n);return u.jsx(cu,{...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)"}})});Ba.displayName=mC;var[gC,Ha]=_r(ur,{}),Ua="SelectViewport",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Vn(Ua,n),i=Ha(Ua,n),a=Ue(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Ks.Slot,{scope:n,children:u.jsx(Re.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ue(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const m=window.innerHeight-mn*2,x=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(x,y);if(g<m){const w=g+h,S=Math.min(m,w),k=w-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});lh.displayName=Ua;var ch="SelectGroup",[xC,yC]=_r(ch),vC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Nn();return u.jsx(xC,{scope:n,id:o,children:u.jsx(Re.div,{role:"group","aria-labelledby":o,...r,ref:t})})});vC.displayName=ch;var uh="SelectLabel",dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=yC(uh,n);return u.jsx(Re.div,{id:o.id,...r,ref:t})});dh.displayName=uh;var Ys="SelectItem",[wC,fh]=_r(Ys),ph=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Wn(Ys,n),l=Vn(Ys,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),m=Ue(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),x=Nn(),y=v.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(wC,{scope:n,value:r,disabled:o,textId:x,isSelected:c,onItemTextChange:v.useCallback(w=>{f(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(Ks.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Re.div,{role:"option","aria-labelledby":x,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:ue(i.onFocus,()=>h(!0)),onBlur:ue(i.onBlur,()=>h(!1)),onClick:ue(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:ue(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:ue(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:ue(i.onPointerMove,w=>{var S;y.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ue(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ue(i.onKeyDown,w=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&w.key===" "||(sC.includes(w.key)&&g(),w.key===" "&&w.preventDefault())})})})})});ph.displayName=Ys;var mo="SelectItemText",hh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Wn(mo,n),a=Vn(mo,n),l=fh(mo,n),c=cC(mo,n),[d,f]=v.useState(null),p=Ue(t,g=>f(g),l.onItemTextChange,g=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,g,l.value,l.disabled)}),h=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:x,onNativeOptionRemove:y}=c;return _t(()=>(x(m),()=>y(m)),[x,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Re.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?yo.createPortal(s.children,i.valueNode):null]})});hh.displayName=mo;var mh="SelectItemIndicator",gh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return fh(mh,n).isSelected?u.jsx(Re.span,{"aria-hidden":!0,...r,ref:t}):null});gh.displayName=mh;var Wa="SelectScrollUpButton",xh=v.forwardRef((e,t)=>{const n=Vn(Wa,e.__scopeSelect),r=Ha(Wa,e.__scopeSelect),[o,s]=v.useState(!1),i=Ue(t,r.onScrollButtonChange);return _t(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});xh.displayName=Wa;var Va="SelectScrollDownButton",yh=v.forwardRef((e,t)=>{const n=Vn(Va,e.__scopeSelect),r=Ha(Va,e.__scopeSelect),[o,s]=v.useState(!1),i=Ue(t,r.onScrollButtonChange);return _t(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});yh.displayName=Va;var vh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Vn("SelectScrollButton",n),i=v.useRef(null),a=qs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),_t(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Re.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ue(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ue(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ue(o.onPointerLeave,()=>{l()})})}),bC="SelectSeparator",wh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Re.div,{"aria-hidden":!0,...r,ref:t})});wh.displayName=bC;var Ka="SelectArrow",SC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Gs(n),s=Wn(Ka,n),i=Vn(Ka,n);return s.open&&i.position==="popper"?u.jsx(uu,{...o,...r,ref:t}):null});SC.displayName=Ka;var CC="SelectBubbleInput",bh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Ue(r,o),i=Up(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Re.select,{...n,style:{...Xp,...n.style},ref:s,defaultValue:t})});bh.displayName=CC;function Sh(e){return e===""||e===void 0}function Ch(e){const t=Rt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Th(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=TC(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function TC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var kC=Jp,kh=Qp,EC=th,IC=nh,NC=rh,Eh=oh,AC=lh,Ih=dh,Nh=ph,jC=hh,_C=gh,Ah=xh,jh=yh,_h=wh;const Rh=kC,Ph=EC,qa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(kh,{ref:r,className:Q("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(IC,{asChild:!0,children:u.jsx(oe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));qa.displayName=kh.displayName;const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ah,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(oe.ChevronUp,{className:"h-4 w-4"})}));Oh.displayName=Ah.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(jh,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(oe.ChevronDown,{className:"h-4 w-4"})}));Mh.displayName=jh.displayName;const Ga=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(NC,{children:u.jsxs(Eh,{ref:o,className:Q("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Oh,{}),u.jsx(AC,{className:Q("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Mh,{})]})}));Ga.displayName=Eh.displayName;const RC=v.forwardRef(({className:e,...t},n)=>u.jsx(Ih,{ref:n,className:Q("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));RC.displayName=Ih.displayName;const dr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Nh,{ref:r,className:Q("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(_C,{children:u.jsx(oe.Check,{className:"h-4 w-4"})})}),u.jsx(jC,{children:t})]}));dr.displayName=Nh.displayName;const PC=v.forwardRef(({className:e,...t},n)=>u.jsx(_h,{ref:n,className:Q("-mx-1 my-1 h-px bg-muted",e),...t}));PC.displayName=_h.displayName;var OC="Separator",Dh="horizontal",MC=["horizontal","vertical"],Lh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Dh,...o}=e,s=DC(r)?r:Dh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Re.div,{"data-orientation":s,...a,...o,ref:t})});Lh.displayName=OC;function DC(e){return MC.includes(e)}var Fh=Lh;const $h=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Fh,{ref:o,decorative:n,orientation:t,className:Q("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));$h.displayName=Fh.displayName;const LC=qf,FC=Q0,$C=Gf,zh=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{className:Q("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}));zh.displayName=_s.displayName;const zC=xo.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"}}),Bh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs($C,{children:[u.jsx(zh,{}),u.jsxs(Rs,{ref:o,className:Q(zC({side:e}),t),...r,children:[n,u.jsxs(Yf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(oe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Bh.displayName=Rs.displayName;const Hh=({className:e,...t})=>u.jsx("div",{className:Q("flex flex-col space-y-2 text-center sm:text-left",e),...t});Hh.displayName="SheetHeader";const Uh=v.forwardRef(({className:e,...t},n)=>u.jsx(ar,{ref:n,className:Q("text-lg font-semibold text-foreground",e),...t}));Uh.displayName=ar.displayName;const Wh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ps,{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));Wh.displayName=Ps.displayName;const BC={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 HC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,d]=b.useState(!1),{toast:f}=Ea();b.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),b.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(BC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(LC,{open:r,onOpenChange:o,children:[u.jsx(FC,{asChild:!0,children:u.jsxs(nt,{variant:"outline",size:"sm",className:n,children:[u.jsx(oe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Tf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Bh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Hh,{children:[u.jsx(Uh,{children:"Chat Settings"}),u.jsx(Wh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(zs,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(nt,{variant:"outline",onClick:x,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Un,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(zs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(nt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(oe.EyeOff,{className:"h-4 w-4"}):u.jsx(oe.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Rh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(qa,{children:u.jsx(Ph,{})}),u.jsxs(Ga,{children:[u.jsx(dr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(dr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(dr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"theme",children:"Theme"}),u.jsxs(Rh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(qa,{children:u.jsx(Ph,{})}),u.jsxs(Ga,{children:[u.jsx(dr,{value:"light",children:"Light"}),u.jsx(dr,{value:"dark",children:"Dark"}),u.jsx(dr,{value:"system",children:"System"})]})]})]}),u.jsx($h,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Un,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Un,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(an,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Un,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(an,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Un,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(an,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Un,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(nt,{variant:"outline",onClick:h,children:[u.jsx(oe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(nt,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(nt,{onClick:p,disabled:!c,children:[u.jsx(oe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function UC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Do,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx($s,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Do,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(za,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx($s,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Do,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(za,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx($s,{onError:s.onError,enableFileUpload:!0})})]})})}Ee.ChatApi=ql,Ee.ChatInput=mc,Ee.ChatInterface=$s,Ee.ChatProviders=Do,Ee.ChatSettings=HC,Ee.MarkdownContent=ho,Ee.MessageComponent=Pa,Ee.MessageList=Oa,Ee.ThreadManager=za,Ee.applySettings=GS,Ee.chatApiClient=Pn,Ee.default=UC,Ee.del=Kl,Ee.get=Qt,Ee.getChatToken=Ul,Ee.getCurrentSettings=qS,Ee.getDefaultApiConfig=Fp,Ee.getDefaultChatSettings=$p,Ee.onChatTokenChanged=Wl,Ee.post=di,Ee.put=Vl,Ee.setChatToken=jo,Ee.useApi=fi,Ee.useChatStream=lc,Ee.useMessagesReducer=ec,Ee.useStream=pc,Ee.useThreadState=Mo,Ee.useThreads=Oo,Object.defineProperties(Ee,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
135
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Ft(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 fp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...xe.defaults,...s};const i=wS(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(xS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&xe.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;xe.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(xe.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&&xe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function xe(e,t,n){return fp(Bn.lex,Hn.parse)(e,t,n)}xe.options=xe.setOptions=function(e){return xe.defaults={...xe.defaults,...e},oS(xe.defaults),xe},xe.getDefaults=ep,xe.defaults=lr,xe.use=function(...e){const t=xe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=xe.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=xe.defaults.renderer||new Ra;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=xe.defaults.tokenizer||new _a;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=xe.defaults.hooks||new Ls;for(const s in n.hooks){const i=o[s];Ls.passThroughHooks.has(s)?o[s]=a=>{if(xe.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=xe.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}}xe.setOptions(r)})},xe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(xe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(xe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(xe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(xe.walkTokens(r.items,t));break}default:xe.defaults.extensions&&xe.defaults.extensions.childTokens&&xe.defaults.extensions.childTokens[r.type]?xe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(xe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(xe.walkTokens(r.tokens,t)))}return n},xe.parseInline=fp(Bn.lexInline,Hn.parseInline),xe.Parser=Hn,xe.parser=Hn.parse,xe.Renderer=Ra,xe.TextRenderer=up,xe.Lexer=Bn,xe.lexer=Bn.lex,xe.Tokenizer=_a,xe.Slugger=dp,xe.Hooks=Ls,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,Hn.parse,Bn.lex;function ho({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof xe.parse=="function"?xe.parse(i):xe(i)}return typeof xe.parse=="function"?xe.parse(e):xe(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=b.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:Z("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const bS="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function SS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function pp(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Fs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function CS(e){const t=o=>{try{const s=fo(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
|
|
136
|
+
`)):r=t(e),r||""}function TS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function hp(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function kS({className:e}){const[t,n]=b.useState(0);return b.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:Z("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Pa=b.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,customStyles:p={},onEdit:h,onRegenerate:m,onCancelEdit:x,onCopy:y,activeInterrupt:g,disableInterruptActions:w=!1,onInterruptActionStart:S,onInterruptActionEnd:k,checkpointCandidates:T=[],activeCheckpointId:C=null,onSelectCheckpoint:E,defaultCheckpointId:j=null,messageParentCheckpointId:N=null}){const[A,O]=b.useState(!1),[F,$]=b.useState("preview"),[R,z]=b.useState(!1),{currentThreadId:_}=Oo(),{respondToInterrupt:B}=Mo(),L=l==="phone"||l==="half-screen",M=t.role,J=M==="tool",X=b.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),he=!!X,Ne=!(r&&M!=="user"),{uploadingFiles:_e,handleFileClick:V,fileViewerOpen:ee,currentFileInfo:q,closeFileViewer:D}=IS({allowFileOpen:Ne,currentThreadId:_}),H=b.useMemo(()=>{switch(M){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))]"}},[M]),te=b.useMemo(()=>X?"":SS(t.content),[X,t]),se=b.useMemo(()=>X?{}:pp(t),[X,t]),ne=b.useMemo(()=>X?[]:t.content.filter(W=>W.type==="image_url"),[X,t]),ke=b.useMemo(()=>X?[]:t.content.filter(W=>W.type==="file"),[X,t]),Q=b.useMemo(()=>X?[]:t.content.filter(W=>W.type==="interrupt"),[X,t]),fe=(g==null?void 0:g.id)??(g==null?void 0:g.interrupt_id),Ie=Fs(fe),Ae=g==null?void 0:g.value,Fe=b.useMemo(()=>X?"":CS(t.content),[X,t]),Ze=b.useCallback(async()=>{const W=J?Fe:te;async function we(ye){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ye);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ft=new Blob([ye],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":ft})]);return}throw new Error("Clipboard API not supported in this context.")}try{await we(W),O(!0),setTimeout(()=>O(!1),2e3),y==null||y(W)}catch(ye){console.error("Failed to copy:",ye)}},[J,Fe,te,y]),Ve=b.useCallback(()=>{if(!h)return;const W=J?Fe:te,we="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};h(t.id,W,we)},[h,t.id,J,Fe,te,t]),Ke=b.useCallback(()=>{m==null||m(n)},[m,n]),qe=b.useCallback(()=>{const we=Z(L?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",H);switch(M){case"user":return u.jsx(oe.User,{className:we});case"assistant":return u.jsx(oe.Bot,{className:we});case"tool":return u.jsx(oe.Wrench,{className:we});default:return u.jsx(oe.Bot,{className:we})}},[L,H,M]),Xe=b.useCallback(()=>{const W="group relative mb-4 flex w-full";switch(M){case"user":return Z(W,"justify-end");case"assistant":case"tool":case"system":return Z(W,"justify-start");default:return W}},[M]),Qe=b.useCallback(()=>{const W=Z("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",L&&"px-3 py-2 text-sm");if(he)return Z(W,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(M){case"user":return Z(W,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return Z(W,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return Z(W,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return Z(W,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return Z(W,"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")}},[L,he,M]);if(he&&X)return u.jsx("div",{className:Z(Xe(),p.container),children:u.jsxs("div",{className:Z(Qe(),p.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(oe.Bot,{className:Z("h-4 w-4",H)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(ho,{content:X.content,className:"text-current"})]})});const et=b.useCallback(async W=>{if(w)return;const we=Fs((W==null?void 0:W.id)??(W==null?void 0:W.interrupt_id));if(!we){console.warn("Interrupt part missing id",W);return}try{S==null||S(),await B(we,!0)}catch(ye){console.error("Failed to approve interrupt:",ye)}finally{k==null||k()}},[w,k,S,B]),Nt=b.useCallback(async W=>{if(w)return;const we=Fs((W==null?void 0:W.id)??(W==null?void 0:W.interrupt_id));if(!we){console.warn("Interrupt part missing id",W);return}try{S==null||S(),await B(we,!1)}catch(ye){console.error("Failed to reject interrupt:",ye)}finally{k==null||k()}},[w,k,S,B]),mt=b.useCallback(({part:W,i:we})=>{if(W.type==="text"){const ye=W.text??"",ft=ye.trim(),gt=Ia(ft);return gt&&M!=="tool"?u.jsx(mp,{data:gt},we):M==="user"&&c&&ft.length>d?u.jsx(NS,{text:ft,expanded:R,onExpandedChange:z,previewLength:d,isCompact:L},we):u.jsx(ho,{content:ye,allowHtml:!1},we)}if(W.type==="image_url"){const ye=W;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ye.url,alt:ye.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},we)}if(W.type==="file"){const ye=W,ft=ye.name||"file";return u.jsxs("a",{href:ye.url,onClick:gt=>V(gt,ye,we),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
137
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[_e[we]?u.jsx(oe.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ft,_e[we]?" (processing)":""]})]},we)}if(W.type==="interrupt"){const ye=W,ft=Fs((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id)),gt=!!(Ie&&ft&&ft===Ie),St=gt?Ae??(ye==null?void 0:ye.value):ye==null?void 0:ye.value,Oe=ft?{...ye,id:ft,interrupt_id:ft}:ye;return u.jsx(ES,{interruptPart:Oe,onApprove:et,onReject:Nt,disabled:w,isActive:gt,payload:St},we)}return null},[V,_e,et,Nt,M,c,d,R,L,Ie,Ae,g,w,Q]),at=b.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(oe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),de=b.useCallback(()=>{const W=te.trim().length>0||ne.length>0||ke.length>0||Q.length>0;if(!J&&ke.length>0&&!r)return at();if(!J&&!W&&!r)return null;if(J)return u.jsx(AS,{message:t,viewMode:F},t.id);if(!J&&!X){const we=t,ye=u.jsx("div",{className:"space-y-2",children:we.content.map((ft,gt)=>u.jsx(mt,{part:ft,i:gt},gt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ye,u.jsx(kS,{className:H})]}):ye}},[te,ne.length,ke.length,Q.length,r,J,F,at,H]),pe=b.useMemo(()=>X?"Assistant":TS(t),[X,t]),me=b.useMemo(()=>X?[]:Array.isArray(T)?T:[],[T,X]),ze=b.useMemo(()=>{var W;return me.length?j&&me.some(we=>we.id===j)?j:((W=me[0])==null?void 0:W.id)??null:null},[j,me]),ot=b.useMemo(()=>!me.length||!C?null:me.some(W=>W.id===C)?C:null,[C,me])??ze,Et=M==="user"&&me.length>0&&typeof E=="function",st=b.useCallback(W=>{if(!E)return;const we=(W==null?void 0:W.id)??null,ye=(W==null?void 0:W.parentId)??N??null;E(we,ye)},[N,E]),Be=b.useMemo(()=>ot?me.findIndex(W=>W.id===ot):-1,[ot,me]),jt=b.useMemo(()=>Be<0?null:me[Be]??null,[Be,me]),At=b.useCallback(W=>{const we=[];if(W.step!==null&&we.push(`Step ${W.step}`),W.source&&we.push(W.source),!W.createdAt)return we.length?we.join(" • "):W.id.slice(0,8);let ye="";try{const ft=new Date(W.createdAt);Number.isNaN(ft.getTime())||(ye=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(ft))}catch{ye=""}return`${ye}`},[]);return J&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:Z(Xe(),p.container),children:u.jsxs("div",{className:Z(Qe(),p.content),children:[(i||a||J)&&u.jsxs("div",{className:Z("flex items-center justify-between mb-2 pb-2 border-b border-current/10",L&&"mb-1 pb-1",H,p.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[qe(),a&&pe&&u.jsx("span",{className:Z("font-medium",L?"text-xs":"text-sm"),children:pe}),J&&u.jsxs(Tf,{variant:"outline",className:Z("text-xs flex items-center gap-1 cursor-pointer select-none",H,"border border-current/40",L&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>$(W=>W==="expanded"?"preview":"expanded"),onKeyDown:W=>{(W.key==="Enter"||W.key===" ")&&(W.preventDefault(),$(we=>we==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:se.name??"Tool Output"}),se.toolCallId&&u.jsx("span",{className:"opacity-70",children:se.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(oe.ChevronUp,{className:"h-3 w-3"}):u.jsx(oe.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Et&&jt&&Be>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:Z("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Be>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Be<=0)return;const W=me[Be-1];W&&st(W)},"aria-label":"Previous checkpoint",disabled:Be<=0,children:u.jsx(oe.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[Be+1," / ",me.length]}),u.jsx("span",{className:"text-muted-foreground",children:At(jt)})]}),u.jsx("button",{type:"button",className:Z("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Be<me.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Be>=me.length-1)return;const W=me[Be+1];W&&st(W)},"aria-label":"Next checkpoint",disabled:Be>=me.length-1,children:u.jsx(oe.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:Z("text-xs opacity-60",H,L&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:Z("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ze(),className:Z("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(oe.Copy,{className:Z(A?"text-success":H,L?"h-3 w-3":"h-4 w-4")})})}),M==="user"&&h&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ve,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(oe.Edit,{className:Z(H,L?"h-3 w-3":"h-4 w-4")})}),M==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ke,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(oe.RotateCcw,{className:Z(H,L?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:de()}),J&&F==="expanded"&&(se.toolCallId||se.name)&&u.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",L&&"text-xs"),children:[se.name&&u.jsxs("div",{children:["Function: ",se.name]}),se.toolCallId&&u.jsxs("div",{children:["Call ID: ",se.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:Z("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ze(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.Copy,{className:Z(A?"text-success":"text-current",L?"h-3 w-3":"h-4 w-4")})}),M==="user"&&h&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ve,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.Edit,{className:Z("text-current",L?"h-3 w-3":"h-4 w-4")})}),M==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ke,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.RotateCcw,{className:Z("text-current",L?"h-3 w-3":"h-4 w-4")})})]})]})}),q&&u.jsx(rS,{isOpen:ee,onClose:D,fileId:q.id,fileName:q.name,mimeType:q.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&hp(e.message)===hp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});function mp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:bS,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:po(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:po(e)})}function ES({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=po(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:Z("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(kf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(Ef,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(nt,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(nt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function IS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ea(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(h=>{a(h),c(!0)},[]),p=b.useCallback(async(h,m,x)=>{var y,g;if(!t){h.preventDefault();return}if(o[x]){h.preventDefault();return}try{const w=String(m.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],T=m.name||`file_${k}`,C=m.mimeType||"application/octet-stream";f({id:k,name:T,mimeType:C});return}if(w.startsWith("data:")){h.preventDefault(),s(T=>({...T,[x]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const T=await B0(n??void 0);if(!T||!Array.isArray(T))throw new Error("Invalid file list response");const C=T.find(E=>!E||typeof E!="object"||!((E.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:m.name||C.filename||`file_${C.id}`,mimeType:m.mimeType||C.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(T){console.error("Failed to fetch server file:",T);const C=T instanceof Error?T.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(T=>({...T,[x]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function NS({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:Z("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(ho,{content:e,allowHtml:!1}):u.jsxs("pre",{className:Z("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(nt,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(oe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(oe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function AS({message:e,viewMode:t}){const r=pp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Ia(c)??c:c;if(d&&typeof d=="object")return u.jsx(mp,{data:d});const f=typeof d=="string"?d:(()=>{try{return po(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=U0(c);return f?u.jsx(ho,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(oe.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Ns(d);return s(f)}const a=fo(i),l=Ns(a);return s(l)}const gp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,jS=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},Oa=b.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:m=!0,isNavigatingCheckpoint:x=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C=!0,checkpointMetaById:E,checkpointIndexByKey:j,activeCheckpointId:N,onSelectCheckpoint:A,timelineCheckpoints:O},F)=>{const $=b.useRef(null),R=b.useRef(null),z=b.useRef(!1),[_,B]=b.useState(!0),L=b.useMemo(()=>w?e.some(Q=>"type"in Q&&Q.type==="default_message"?!1:Array.isArray(Q==null?void 0:Q.content)&&Q.content.some(fe=>fe&&fe.type==="interrupt"&&(fe.id??fe.interrupt_id)===w.id)):!1,[w,e]),M=b.useMemo(()=>{if(!w||L)return null;const Q=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let fe;const Ie=w.value;if(Ie&&typeof Ie=="object"&&!Array.isArray(Ie)){const Ae=Ie.title;typeof Ae=="string"&&Ae.trim()&&(fe=Ae.trim())}return{id:`interrupt-${Q}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:Q,value:Ie,title:fe}]}},[w,L]),J=b.useMemo(()=>M?[...e,M]:e,[e,M]),X=b.useMemo(()=>C?J:J.filter(Q=>(Q==null?void 0:Q.role)!=="tool"),[J,C]),he=b.useMemo(()=>{const Q=new Set,fe=[];for(let Ie=X.length-1;Ie>=0;Ie--){const Ae=X[Ie];if(!Ae)continue;if("type"in Ae&&Ae.type==="default_message"){fe.push(Ae);continue}const Fe=Ae,Ze=jS(Fe);Q.has(Ze)||(Q.add(Ze),fe.push(Fe))}return fe.reverse()},[X]),Ne=b.useCallback(Q=>{B(Q),y&&y(!Q),g&&g(Q)},[y,g]),_e=b.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),V=b.useMemo(()=>!m||x?!1:_?"auto":!1,[_,m,x]),ee=b.useMemo(()=>O??[],[O]),q=N??(ee.length?ee[ee.length-1].id:null),D=ee.length>0,H=b.useMemo(()=>{if(typeof h!="string")return null;const Q=h.trim();return Q?{id:"default-message",role:"assistant",type:"default_message",content:Q,createdAt:new Date().toISOString()}:null},[h]),te=D?u.jsxs("div",{className:"w-48 flex-shrink-0 flex-col border-r border-border/40 pr-4 flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-5 pb-5 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative z-50",children:[u.jsx(oe.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-56 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.'})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-5 top-0 bottom-0 w-px bg-border/50"}),u.jsx("div",{className:"flex flex-col gap-4",children:ee.map(Q=>{const fe=q===Q.id;return u.jsxs("button",{type:"button",disabled:!A,onClick:()=>A==null?void 0:A(Q.id),className:`relative flex items-start gap-3 text-left text-xs transition ${fe?"text-primary":"text-muted-foreground"} ${A?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-4 w-4 items-center justify-center rounded-full border ${fe?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${fe?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:Q.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[Q.step!==null?`STEP ${Q.step}`:"STEP —",Q.next?` - ${Q.next}`:""]})]})]},Q.id)})})]}),A&&u.jsx("button",{type:"button",onClick:()=>A==null?void 0:A(null),className:"mt-auto rounded-md border border-border/70 px-3 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null,se=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),ne=()=>H?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Pa,{message:H,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),ke=he.length>0;return b.useImperativeHandle(F,()=>({scrollToLatest:()=>{var Q,fe;if($.current&&he.length>0){const Ie=he.length-1;(fe=(Q=$.current).scrollToIndex)==null||fe.call(Q,{index:Ie,align:"end",behavior:"auto"})}else R.current&&(R.current.scrollTop=R.current.scrollHeight)},scrollToTop:()=>{var Q,fe;$.current&&he.length>0?(fe=(Q=$.current).scrollToIndex)==null||fe.call(Q,{index:0,align:"start",behavior:"auto"}):R.current&&(R.current.scrollTop=0)}}),[he]),u.jsxs("div",{className:se,style:p,children:[te,u.jsx("div",{className:"relative flex-1 min-h-0",children:ke?u.jsx(v0,{ref:Q=>{$.current=Q},scrollerRef:Q=>{R.current=Q instanceof HTMLDivElement?Q:null},data:he,followOutput:V,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_e&&_e()},atBottomStateChange:Ne,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(Q,fe)=>gp(fe,Q),itemContent:(Q,fe)=>{var et;const Ie=gp(fe,Q),Ae="type"in fe&&fe.type==="default_message";let Fe=[],Ze=null,Ve={},Ke={},qe=null,Xe=null;if(!Ae){const Nt=fe,mt=Nt.checkpointId??null;Ve=Nt.additionalKwargs??{},Ke=Nt.responseMetadata??{};const at=mt&&E?E.get(mt)??null:null;qe=typeof Ve.step=="number"?Ve.step:typeof Ke.step=="number"?Ke.step:(at==null?void 0:at.step)??null;const de=typeof Ve.source=="string"?Ve.source:typeof Ke.source=="string"?Ke.source:(at==null?void 0:at.source)??null;Xe=de?String(de):null;const pe=qe!==null&&Xe?`${qe}:${Xe}`:null;pe&&(j!=null&&j.has(pe))?Fe=j.get(pe)??[]:mt&&at&&(Fe=[at]),Ze=mt??((et=Fe[0])==null?void 0:et.id)??null}const Qe=(()=>{if(typeof Ve.parentCheckpointId=="string")return Ve.parentCheckpointId;if(typeof Ke.parentCheckpointId=="string")return Ke.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":Ie,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Pa,{message:fe,messageIndex:Q,isStreamingMessage:t&&n===fe.id,streamingDebounceMs:r,isEditing:i===fe.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(Q),onCancelEdit:d,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C,checkpointCandidates:Fe,activeCheckpointId:N??null,onSelectCheckpoint:A,defaultCheckpointId:Ze,messageParentCheckpointId:Qe})})}}):ne()})]})});Oa.displayName="MessageList";const xp={value:""};function $s({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,customStyles:f={},onMessageSent:p,onExcelUploadSuccess:h,onError:m}){const{api:x}=fi(),{currentThreadId:y}=Oo(),{threadId:g,messages:w,hasMore:S,isHistoryLoading:k,isLoading:T,loadOlder:C,navigateToCheckpoint:E,returnToLatest:j,checkpoint:N,checkpoints:A,interrupt:O,metadata:F}=Mo(),{isStreaming:$,error:R,connectionState:z,submit:_,stop:B}=pc(),L=g??y??null,M=(N==null?void 0:N.id)??null,J=(N==null?void 0:N.namespace)??null,X=(F==null?void 0:F.assemblingMessageId)??null,he=O,[Ne,_e]=b.useState(!1);b.useEffect(()=>{he||_e(!1)},[he]);const V=b.useCallback(()=>{_e(!0)},[]),ee=b.useCallback(()=>{_e(!1)},[]),q=!!he||Ne,[D,H]=b.useState(null),[te,se]=b.useState(""),[ne,ke]=b.useState(null),[Q,fe]=b.useState(null),[Ie,Ae]=b.useState([]),[Fe,Ze]=b.useState(0),[Ve,Ke]=b.useState(0),[qe,Xe]=b.useState(!1),[Qe,et]=b.useState(null),[Nt,mt]=b.useState(null),[at,de]=b.useState(!1),[pe,me]=b.useState(null),[ze,De]=b.useState(!1),ot=b.useRef(!1),[Et,st]=b.useState(()=>xp.value),Be=b.useRef(Et),jt=b.useRef(null),At=b.useCallback(G=>{xp.value=G,st(G)},[]),[W,we]=b.useState(!1),ye=b.useRef(null),ft=b.useCallback(G=>{if(!Array.isArray(G))return{text:null,messageId:null};for(let re=G.length-1;re>=0;re--){const ae=G[re];if(!ae||ae.role!=="user")continue;const Se=(ae.content??[]).filter(Ye=>(Ye==null?void 0:Ye.type)==="text").map(Ye=>Ye.text).filter(Ye=>typeof Ye=="string"&&Ye.trim().length>0);return{text:Se.length?Se.join(" ").trim():null,messageId:ae.id??null}}return{text:null,messageId:null}},[]),gt=b.useCallback((G,re)=>{if(!G||typeof G!="object")return null;const ae=G[re];return typeof ae=="number"?ae:null},[]),St=b.useCallback((G,re)=>{if(!G||typeof G!="object")return null;const ae=G[re];return typeof ae=="string"&&ae.trim()?ae:null},[]),Oe=b.useMemo(()=>{const G=Se=>{if(!Array.isArray(Se)||Se.length===0)return null;const dt=Se.map(Ye=>{if(typeof Ye=="string")return Ye.trim();if(Ye&&typeof Ye=="object"&&"type"in Ye){const tt=Ye;if(typeof tt.type=="string")return tt.type}return null}).filter(Ye=>!!(Ye&&Ye.length));return dt.length?dt.join(", "):null},re=Array.isArray(A)?A.map(Se=>{const dt=G(Se.next);return dt?{...Se,metadata:{...Se.metadata??{},next:dt}}:Se}):[];return re.some(Se=>gt(Se.metadata,"step")!==null)&&re.sort((Se,dt)=>{const Ye=gt(Se.metadata,"step"),tt=gt(dt.metadata,"step");if(Ye!==null||tt!==null)return(tt??Number.NEGATIVE_INFINITY)-(Ye??Number.NEGATIVE_INFINITY);const Ot=Date.parse(Se.createdAt??""),ln=Date.parse(dt.createdAt??"");return Number.isNaN(Ot)||Number.isNaN(ln)?0:ln-Ot}),re},[A,gt]),{checkpointMetaById:Kt,checkpointIndexByKey:lt}=b.useMemo(()=>{const G=new Map,re=new Map;for(const ae of Oe){const Se=ae.checkpointId??null;if(!Se)continue;const dt=gt(ae.metadata,"step"),Ye=St(ae.metadata,"source"),tt={id:Se,step:dt,source:Ye,createdAt:ae.createdAt??null,namespace:ae.checkpointNs??null,parentId:ae.parentId??null};if(G.set(Se,tt),dt!==null&&Ye){const Ot=`${dt}:${Ye}`,ln=re.get(Ot)??[];ln.push(tt),re.set(Ot,ln)}}for(const ae of re.values())ae.sort((Se,dt)=>{const Ye=Se.createdAt??"";return(dt.createdAt??"").localeCompare(Ye)});return{checkpointMetaById:G,checkpointIndexByKey:re}},[Oe,gt,St]),Ct=b.useMemo(()=>{var Ye;if(!Oe.length)return[];const G=[...Oe].reverse(),re=(tt,Ot)=>{const ln=tt.checkpointId??null;if(!ln)return null;const pr=St(tt.metadata,"source");St(tt.metadata,"next");const{text:Vh,messageId:WC}=ft(tt.messages),Za=Vh&&Vh.replace(/\s+/g," ").trim()||St(tt.metadata,"title")||St(tt.metadata,"label")||Ot||pr||"Checkpoint",VC=Za.length>60?`${Za.slice(0,57)}…`:Za;return{id:ln,label:VC,messageId:WC??null,createdAt:tt.createdAt??null,step:gt(tt.metadata,"step"),source:pr??null,next:St(tt.metadata,"next")}},ae=[],Se=new Set;for(const tt of G){const Ot=((Ye=St(tt.metadata,"source"))==null?void 0:Ye.toLowerCase())??null;if(!(Ot==="input"||Ot==="user_input"||Ot==="user"))continue;const pr=re(tt,"User input");pr&&!Se.has(pr.id)&&(ae.push(pr),Se.add(pr.id))}if(!ae.length)for(const tt of G){const Ot=re(tt);Ot&&!Se.has(Ot.id)&&(ae.push(Ot),Se.add(Ot.id))}const dt=Oe.find(tt=>{var ln;return(((ln=St(tt.metadata,"source"))==null?void 0:ln.toLowerCase())??null)==="loop"});if(dt){const tt=re(dt,"Latest loop");tt&&!Se.has(tt.id)&&(ae.push(tt),Se.add(tt.id))}return ae},[Oe,ft,gt,St]),Kn=b.useRef(null),fr=b.useRef(null),qn=b.useCallback(()=>{Kn.current&&(Kn.current.value=""),fr.current&&(fr.current.value=""),Ze(G=>G+1),Ke(G=>G+1)},[]),Ya=b.useCallback(G=>{At(G)},[At]),Xs=b.useRef(!1);b.useEffect(()=>{Xs.current&&!$&&(Ae([]),qn()),Xs.current=$},[$,qn]);const[Xa,Ja]=b.useState("desktop");b.useEffect(()=>{const G=()=>{const re=window.innerWidth;Ja(re<640?"phone":re<1024?"tablet":"desktop")};return G(),window.addEventListener("resize",G),()=>window.removeEventListener("resize",G)},[]),b.useEffect(()=>{De(!1),ot.current=!1},[L]),b.useEffect(()=>{Be.current=Et},[Et]),b.useEffect(()=>{if(!D){jt.current=null;return}jt.current===null&&(jt.current=Be.current),At(te??"")},[te,D,At]);const I=b.useCallback(async()=>{if(!(!S||k||!ze))try{await C()}catch(G){console.warn("loadOlder failed",G)}},[S,ze,k,C]);b.useEffect(()=>{(async()=>{if(!x.baseUrl){me(null);return}try{const ae=(await x.getAgent("default")).uiDefaultMessage||"";me(ae||null)}catch(re){console.warn("Failed to fetch default message:",re),me(null)}})()},[x.baseUrl]),b.useEffect(()=>{R&&!at&&(m==null||m(R))},[R,at,m]);const K=G=>{if(G.length>fs)return`Message too long (${G.length}/${fs} characters)`;try{return cb(G),null}catch(re){return(re==null?void 0:re.message)||"Invalid message"}},ie=async G=>{const re=G.trim();if(!(!re&&Ie.length===0)){if(re){const ae=K(re);if(ae){fe(ae);return}}try{const ae=M??void 0,Se=J??void 0,dt=D?{edit:!0,originalMessageId:D,...ne!=null&&ne.checkpointId?{originalCheckpointId:ne.checkpointId}:{},...ne!=null&&ne.checkpointNs?{originalCheckpointNs:ne.checkpointNs}:{}}:void 0;await _({text:re||"",attachments:Ie,messageAdditionalKwargs:dt},{checkpointId:ae,checkpointNs:Se}),p==null||p(re),At(""),fe(null),Ae([]),qn(),H(null),se(""),ke(null)}catch(ae){const Se=(ae==null?void 0:ae.message)||"Failed to send message";fe(Se),m==null||m(Se)}}},be=b.useCallback((G,re,ae)=>{c&&(jt.current=Et,H(G),se(re),At(re),fe(null),ke({checkpointId:(ae==null?void 0:ae.checkpointId)??null,checkpointNs:(ae==null?void 0:ae.checkpointNs)??null}))},[Et,c,At]),Ge=b.useCallback(()=>{H(null),se(""),ke(null),fe(null),At(jt.current??Et),jt.current=null},[Et,At]),it=b.useCallback((G,re,ae)=>{be(G,re,ae)},[be]),He=b.useCallback(G=>{for(let re=G-1;re>=0;re--)if(w[re].role==="user"){const ae=w[re].content||[],dt=ae.filter(Ye=>Ye.type==="text").map(Ye=>Ye.text).join("")||(()=>{try{return JSON.stringify(ae,null,2)}catch{return String(ae)}})();dt&&_({text:dt},{checkpointId:M??void 0,checkpointNs:J??void 0});break}},[w,_,M,J]),$e=G=>{const re=Array.from(G.target.files||[]);Ae(ae=>[...ae,...re]),G.target.value=""},Pt=G=>{Ae(re=>{const ae=re.filter((Se,dt)=>G!==dt);return ae.length===0&&qn(),ae})},vt=async G=>{const re=(G.target.files||[])[0];if(re){et(null),mt(null),Xe(!0);try{await _({attachments:[re]},{checkpointId:M??void 0,checkpointNs:J??void 0});const ae=`Uploaded ${re.name} - processing through chat stream`;mt(ae)}catch(ae){const Se=ae instanceof Error?ae.message:"Failed to upload Excel file";console.error("Excel upload failed",ae),et(Se),m==null||m(Se)}finally{Xe(!1),G.target.value="",qn()}}},yt=async G=>{if(y){we(!0);try{if(!G){await j(),De(!1),requestAnimationFrame(()=>{var Se;(Se=ye.current)==null||Se.scrollToLatest()});return}const re=Oe.find(Se=>Se.checkpointId===G),ae=(re==null?void 0:re.checkpointNs)??null;await E(G,ae),De(!0),requestAnimationFrame(()=>{var Se;(Se=ye.current)==null||Se.scrollToTop()})}finally{we(!1)}}},qt=b.useCallback(async G=>{await yt(G)},[yt]),Gn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,Rn=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${f.messagesArea||""}`,$t=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,go=b.useCallback(G=>{if(!G)return"Latest";const re=[];G.step!==null&&re.push(`Step ${G.step}`),G.source&&re.push(G.source);const ae=G.createdAt?new Date(G.createdAt):null,Se=ae&&!Number.isNaN(ae.getTime())?ae.toLocaleString():G.createdAt??G.id,dt=re.length?` — ${re.join(" • ")}`:"";return`${Se}${dt}`},[]);return u.jsxs("div",{className:Gn,children:[!!R&&!at&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:R}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>de(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(oe.X,{size:16})})]}),y&&Oe.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:M??"",onChange:G=>{const re=G.target.value||null;yt(re)},children:[u.jsx("option",{value:"",children:"Latest"}),Oe.map(G=>{const re=Kt.get(G.checkpointId??"")??null;return u.jsx("option",{value:G.checkpointId??void 0,children:go(re)},G.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${Rn}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Oa,{ref:ye,className:"h-full",style:{height:"100%"},messages:w,isStreaming:$,streamingAssistantId:X,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Xa,enableMessageEditing:c,editingMessageId:D,onStartReached:()=>{ze&&I()},onScrollAway:G=>{if(!ot.current){ot.current=!0;return}G&&De(!0)},onEdit:it,onRegenerate:He,onCancelEdit:Ge,emptyMessage:pe??void 0,isNavigatingCheckpoint:W,activeInterrupt:he,disableInterruptActions:Ne,onInterruptActionStart:V,onInterruptActionEnd:ee,showToolMessages:d,checkpointMetaById:Kt,checkpointIndexByKey:lt,activeCheckpointId:M,onSelectCheckpoint:qt,timelineCheckpoints:Ct}),(z==="reconnecting"||z==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(oe.Loader2,{className:"h-3 w-3 animate-spin"}),z==="reconnecting"?"Reconnecting…":"Connecting…"]})}),z==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),T&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(oe.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||W)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(oe.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:$t,children:[D&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(oe.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(oe.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Kn,type:"file",multiple:!0,onChange:G=>$e(G),className:"hidden"},Fe),Ie.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Ie.map((G,re)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(oe.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:G.name}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Pt(re),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 ${G.name}`,children:u.jsx(oe.X,{size:12})})]},re))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:fr,type:"file",accept:".xls,.xlsx,.xlsm",onChange:vt,className:"hidden"},Ve),qe&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(oe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Nt&&!qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Nt}),Qe&&!qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Qe})]})]}),Q&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Q}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(Qw,{children:[u.jsx(eb,{asChild:!0,children:u.jsx(nt,{type:"button",size:"icon",variant:"outline",disabled:$||q,title:"More input actions",className:f.moreButton||"",children:u.jsx(oe.Plus,{size:16})})}),u.jsxs(Td,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(ea,{onClick:()=>{var G;return(G=Kn.current)==null?void 0:G.click()},className:"cursor-pointer",children:[u.jsx(oe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(ea,{onClick:()=>{var G;qe||(G=fr.current)==null||G.click()},className:`cursor-pointer ${qe?"opacity-60 pointer-events-none":""}`,children:[u.jsx(oe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(ex,{initialValue:te,editingMessageId:D,value:Et,onValueChange:Ya,placeholder:D?"Edit your message...":t,isStreaming:$,disabled:q,maxLength:fs,onSend:ie,onCancelEdit:Ge,onStop:B,allowEmptySend:Ie.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${D?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Q?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const zs=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:Z("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));zs.displayName="Input";function Ma(e,[t,n]){return Math.min(n,Math.max(t,e))}function _S(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Da="ScrollArea",[yp,bT]=In(Da),[RS,sn]=yp(Da),vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,m]=v.useState(null),[x,y]=v.useState(null),[g,w]=v.useState(0),[S,k]=v.useState(0),[T,C]=v.useState(!1),[E,j]=v.useState(!1),N=Ue(t,O=>l(O)),A=Lo(o);return u.jsx(RS,{scope:n,type:r,dir:A,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:m,scrollbarXEnabled:T,onScrollbarXEnabledChange:C,scrollbarY:x,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:w,onCornerHeightChange:k,children:u.jsx(Re.div,{dir:A,...i,ref:N,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});vp.displayName=Da;var wp="ScrollAreaViewport",bp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=sn(wp,n),a=v.useRef(null),l=Ue(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(Re.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});bp.displayName=wp;var kn="ScrollAreaScrollbar",La=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(PS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(OS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Sp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Fa,{...r,ref:t}):null});La.displayName=kn;var PS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(tn,{present:n||s,children:u.jsx(Sp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),OS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ws(()=>l("SCROLL_END"),100),[a,l]=_S("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(tn,{present:n||a!=="hidden",children:u.jsx(Fa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ue(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ue(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Sp=v.forwardRef((e,t)=>{const n=sn(kn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ws(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Ar(n.viewport,l),Ar(n.content,l),u.jsx(tn,{present:r||s,children:u.jsx(Fa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Fa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=sn(kn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Ip(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return zS(p,i.current,a,h)}return n==="horizontal"?u.jsx(MS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Np(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(DS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Np(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),MS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Ue(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Tp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Us(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),jp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Hs(i.paddingLeft),paddingEnd:Hs(i.paddingRight)}})}})}),DS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Ue(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Tp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Us(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),jp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Hs(i.paddingTop),paddingEnd:Hs(i.paddingBottom)}})}})}),[LS,Cp]=yp(kn),Tp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=sn(kn,n),[m,x]=v.useState(null),y=Ue(t,N=>x(N)),g=v.useRef(null),w=v.useRef(""),S=h.viewport,k=r.content-r.viewport,T=Rt(d),C=Rt(l),E=Ws(f,10);function j(N){if(g.current){const A=N.clientX-g.current.left,O=N.clientY-g.current.top;c({x:A,y:O})}}return v.useEffect(()=>{const N=A=>{const O=A.target;(m==null?void 0:m.contains(O))&&T(A,k)};return document.addEventListener("wheel",N,{passive:!1}),()=>document.removeEventListener("wheel",N,{passive:!1})},[S,m,k,T]),v.useEffect(C,[r,C]),Ar(m,E),Ar(h.content,E),u.jsx(LS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Rt(s),onThumbPointerUp:Rt(i),onThumbPositionChange:C,onThumbPointerDown:Rt(a),children:u.jsx(Re.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:ue(e.onPointerDown,N=>{N.button===0&&(N.target.setPointerCapture(N.pointerId),g.current=m.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),j(N))}),onPointerMove:ue(e.onPointerMove,j),onPointerUp:ue(e.onPointerUp,N=>{const A=N.target;A.hasPointerCapture(N.pointerId)&&A.releasePointerCapture(N.pointerId),document.body.style.webkitUserSelect=w.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Bs="ScrollAreaThumb",kp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Cp(Bs,e.__scopeScrollArea);return u.jsx(tn,{present:n||o.hasThumb,children:u.jsx(FS,{ref:t,...r})})}),FS=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=sn(Bs,n),i=Cp(Bs,n),{onThumbPositionChange:a}=i,l=Ue(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ws(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=BS(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Re.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:ue(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),m=f.clientX-h.left,x=f.clientY-h.top;i.onThumbPointerDown({x:m,y:x})}),onPointerUp:ue(e.onPointerUp,i.onThumbPointerUp)})});kp.displayName=Bs;var $a="ScrollAreaCorner",Ep=v.forwardRef((e,t)=>{const n=sn($a,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx($S,{...e,ref:t}):null});Ep.displayName=$a;var $S=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=sn($a,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Ar(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Ar(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Re.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Hs(e){return e?parseInt(e,10):0}function Ip(e,t){const n=e/t;return isNaN(n)?0:n}function Us(e){const t=Ip(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function zS(e,t,n,r="ltr"){const o=Us(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ap([l,c],f)(e)}function Np(e,t,n="ltr"){const r=Us(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Ma(e,l);return Ap([0,i],[0,a])(c)}function Ap(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function jp(e,t){return e>0&&e<t}var BS=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Ws(e,t){const n=Rt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Ar(e,t){const n=Rt(t);_t(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var _p=vp,HS=bp,US=Ep;const Rp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_p,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[u.jsx(HS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Pp,{}),u.jsx(US,{})]}));Rp.displayName=_p.displayName;const Pp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(La,{ref:r,orientation:t,className:Z("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(kp,{className:"relative flex-1 rounded-full bg-border"})}));Pp.displayName=La.displayName;const Op=25;function za({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:m,actions:x}=Oo(),{loadThread:y}=Mo(),{createThread:g,deleteThread:w,renameThread:S}=x,[k,T]=b.useState(Array.isArray(f)?f:[]),C=b.useRef(k.length>0),E=b.useRef(null),j=b.useRef(0),[N,A]=b.useState(null),[O,F]=b.useState(""),[$,R]=b.useState(!1);b.useEffect(()=>{const V=Array.isArray(f)?f:[];if(V.length>0){C.current=!0,T(V);return}m||(C.current=!1,T(V))},[f,m]),b.useEffect(()=>{if(!E.current)return;const V=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!V)return;let ee=null,q=null;return ee=requestAnimationFrame(()=>{q=requestAnimationFrame(()=>{V.scrollTop=j.current})}),()=>{ee!==null&&cancelAnimationFrame(ee),q!==null&&cancelAnimationFrame(q)}},[k]);const z=async V=>{try{h(V),await y(V),a==null||a(V),l==null||l(V)}catch(ee){console.error("Failed to select thread:",ee)}},_=async()=>{try{R(!0);const V=await g();V&&(c==null||c(V),a==null||a(V))}catch(V){console.error("Failed to create thread:",V)}finally{R(!1)}},B=async(V,ee)=>{if(ee.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const q=E.current.querySelector("[data-radix-scroll-area-viewport]");q&&(j.current=q.scrollTop)}try{await w(V),d==null||d(V)}catch(q){console.error("Failed to delete thread:",q)}}},L=(V,ee)=>{ee.stopPropagation(),A(V.threadId),F(V.title||`Thread ${V.threadId.slice(0,8)}`)},M=async V=>{if(O.trim())try{await S(V,O.trim()),A(null),F("")}catch(ee){console.error("Failed to update title:",ee)}},J=()=>{A(null),F("")},X=(V,ee)=>{V.key==="Enter"?M(ee):V.key==="Escape"&&J()},he=V=>{if(!V)return"";try{const ee=new Date(V),D=new Date().getTime()-ee.getTime(),H=Math.floor(D/(1e3*60*60*24));return H===0?ee.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):H===1?"Yesterday":H<7?`${H} days ago`:ee.toLocaleDateString()}catch{return""}},Ne=V=>V.title||`Thread ${V.threadId.slice(0,8)}`,_e=V=>{const ee=Ne(V);return ee.length<=Op?ee:`${ee.slice(0,Op)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(nt,{onClick:_,disabled:$||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:$?"Creating...":"New Chat",children:u.jsx(oe.MessageSquarePlus,{size:20})})}),u.jsx(Rp,{ref:E,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:m?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(oe.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(oe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((V,ee)=>new Date(ee.updatedAt||ee.createdAt||"").getTime()-new Date(V.updatedAt||V.createdAt||"").getTime()).map(V=>u.jsxs("div",{onClick:()=>z(V.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===V.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:N===V.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ee=>ee.stopPropagation(),children:[u.jsx(zs,{value:O,onChange:ee=>F(ee.target.value),onKeyDown:ee=>X(ee,V.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>M(V.threadId),className:"h-6 w-6 p-0",children:u.jsx(oe.Check,{size:12})}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:J,className:"h-6 w-6 p-0",children:u.jsx(oe.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:_e(V)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(oe.Calendar,{size:10}),u.jsx("span",{children:he(V.updatedAt||V.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&N!==V.threadId&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ee=>L(V,ee),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(oe.Edit3,{size:12})}),n&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ee=>B(V.threadId,ee),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(oe.Trash2,{size:12})})]})]}),i===V.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},V.threadId))})})]})}function jr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function WS(e){if(typeof e!="string")return;const t=e.trim();if(t)return En(t)}function Mp(){const e=[jr("__API_BASE_URL__"),jr("__CHAT_API_BASE_URL__"),jr("__CHAT_API_URL__")];for(const t of e){const n=WS(t);if(n)return n}}function Dp(){const e=[jr("__API_AUTH_TOKEN__"),jr("__CHAT_API_KEY__"),jr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Lp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return En(t);return En()}function Fp(){const e={},t=Mp(),n=Dp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function $p(){const e=Fp(),t=Pn.getAuthToken(),n=Mp();return{apiBaseUrl:Lp(e.baseUrl,Pn.baseUrl,n),apiKey:t||e.apiKey||Dp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const zp="chat-settings";function VS(){try{const e=localStorage.getItem(zp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function KS(e){try{const t={...e,apiBaseUrl:En(e.apiBaseUrl)};localStorage.setItem(zp,JSON.stringify(t)),t.apiKey&&Pn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function qS(){const e=$p(),t=VS(),n=Pn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Lp(Pn.baseUrl,r,e.apiBaseUrl)}}function GS(e){Pn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),KS(e)}var YS="Label",Bp=v.forwardRef((e,t)=>u.jsx(Re.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Bp.displayName=YS;var Hp=Bp;const XS=xo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),an=v.forwardRef(({className:e,...t},n)=>u.jsx(Hp,{ref:n,className:Z(XS(),e),...t}));an.displayName=Hp.displayName;function Up(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Vs="Switch",[JS,ST]=In(Vs),[ZS,QS]=JS(Vs),Wp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),m=Ue(t,S=>h(S)),x=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,w]=xr({prop:o,defaultProp:s??!1,onChange:c,caller:Vs});return u.jsxs(ZS,{scope:n,checked:g,disabled:a,children:[u.jsx(Re.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Gp(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ue(e.onClick,S=>{w(k=>!k),y&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),y&&u.jsx(qp,{control:p,bubbles:!x.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Wp.displayName=Vs;var Vp="SwitchThumb",Kp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=QS(Vp,n);return u.jsx(Re.span,{"data-state":Gp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Kp.displayName=Vp;var eC="SwitchBubbleInput",qp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Ue(i,s),l=Up(n),c=Jc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const m=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(m)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});qp.displayName=eC;function Gp(e){return e?"checked":"unchecked"}var Yp=Wp,tC=Kp;const Un=v.forwardRef(({className:e,...t},n)=>u.jsx(Yp,{className:Z("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(tC,{className:Z("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));Un.displayName=Yp.displayName;var Xp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),nC="VisuallyHidden",rC=v.forwardRef((e,t)=>u.jsx(Re.span,{...e,ref:t,style:{...Xp,...e.style}}));rC.displayName=nC;var oC=[" ","Enter","ArrowUp","ArrowDown"],sC=[" ","Enter"],cr="Select",[Ks,qs,iC]=vi(cr),[_r,CT]=In(cr,[iC,Xo]),Gs=Xo(),[aC,Wn]=_r(cr),[lC,cC]=_r(cr),Jp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:m}=e,x=Gs(t),[y,g]=v.useState(null),[w,S]=v.useState(null),[k,T]=v.useState(!1),C=Lo(c),[E,j]=xr({prop:r,defaultProp:o??!1,onChange:s,caller:cr}),[N,A]=xr({prop:i,defaultProp:a,onChange:l,caller:cr}),O=v.useRef(null),F=y?m||!!y.closest("form"):!0,[$,R]=v.useState(new Set),z=Array.from($).map(_=>_.props.value).join(";");return u.jsx(au,{...x,children:u.jsxs(aC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:T,contentId:Nn(),value:N,onValueChange:A,open:E,onOpenChange:j,dir:C,triggerPointerDownPosRef:O,disabled:p,children:[u.jsx(Ks.Provider,{scope:t,children:u.jsx(lC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(_=>{R(B=>new Set(B).add(_))},[]),onNativeOptionRemove:v.useCallback(_=>{R(B=>{const L=new Set(B);return L.delete(_),L})},[]),children:n})}),F?u.jsxs(bh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:N,onChange:_=>A(_.target.value),disabled:p,form:m,children:[N===void 0?u.jsx("option",{value:""}):null,Array.from($)]},z):null]})})};Jp.displayName=cr;var Zp="SelectTrigger",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Gs(n),i=Wn(Zp,n),a=i.disabled||r,l=Ue(t,i.onTriggerChange),c=qs(n),d=v.useRef("touch"),[f,p,h]=Ch(x=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),w=Th(y,x,g);w!==void 0&&i.onValueChange(w.value)}),m=x=>{a||(i.onOpenChange(!0),h()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return u.jsx(lu,{asChild:!0,...s,children:u.jsx(Re.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":Sh(i.value)?"":void 0,...o,ref:l,onClick:ue(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&m(x)}),onPointerDown:ue(o.onPointerDown,x=>{d.current=x.pointerType;const y=x.target;y.hasPointerCapture(x.pointerId)&&y.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(m(x),x.preventDefault())}),onKeyDown:ue(o.onKeyDown,x=>{const y=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&p(x.key),!(y&&x.key===" ")&&oC.includes(x.key)&&(m(),x.preventDefault())})})})});Qp.displayName=Zp;var eh="SelectValue",th=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Wn(eh,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Ue(t,l.onValueNodeChange);return _t(()=>{c(d)},[c,d]),u.jsx(Re.span,{...a,ref:f,style:{pointerEvents:"none"},children:Sh(l.value)?u.jsx(u.Fragment,{children:i}):s})});th.displayName=eh;var uC="SelectIcon",nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Re.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});nh.displayName=uC;var dC="SelectPortal",rh=e=>u.jsx(Jo,{asChild:!0,...e});rh.displayName=dC;var ur="SelectContent",oh=v.forwardRef((e,t)=>{const n=Wn(ur,e.__scopeSelect),[r,o]=v.useState();if(_t(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?yo.createPortal(u.jsx(sh,{scope:e.__scopeSelect,children:u.jsx(Ks.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(ih,{...e,ref:t})});oh.displayName=ur;var mn=10,[sh,Vn]=_r(ur),fC="SelectContentImpl",pC=Yn.createSlot("SelectContent.RemoveScroll"),ih=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:x,avoidCollisions:y,...g}=e,w=Wn(ur,n),[S,k]=v.useState(null),[T,C]=v.useState(null),E=Ue(t,q=>k(q)),[j,N]=v.useState(null),[A,O]=v.useState(null),F=qs(n),[$,R]=v.useState(!1),z=v.useRef(!1);v.useEffect(()=>{if(S)return Bi(S)},[S]),Si();const _=v.useCallback(q=>{const[D,...H]=F().map(ne=>ne.ref.current),[te]=H.slice(-1),se=document.activeElement;for(const ne of q)if(ne===se||(ne==null||ne.scrollIntoView({block:"nearest"}),ne===D&&T&&(T.scrollTop=0),ne===te&&T&&(T.scrollTop=T.scrollHeight),ne==null||ne.focus(),document.activeElement!==se))return},[F,T]),B=v.useCallback(()=>_([j,S]),[_,j,S]);v.useEffect(()=>{$&&B()},[$,B]);const{onOpenChange:L,triggerPointerDownPosRef:M}=w;v.useEffect(()=>{if(S){let q={x:0,y:0};const D=te=>{var se,ne;q={x:Math.abs(Math.round(te.pageX)-(((se=M.current)==null?void 0:se.x)??0)),y:Math.abs(Math.round(te.pageY)-(((ne=M.current)==null?void 0:ne.y)??0))}},H=te=>{q.x<=10&&q.y<=10?te.preventDefault():S.contains(te.target)||L(!1),document.removeEventListener("pointermove",D),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",H,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",H,{capture:!0})}}},[S,L,M]),v.useEffect(()=>{const q=()=>L(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[L]);const[J,X]=Ch(q=>{const D=F().filter(se=>!se.disabled),H=D.find(se=>se.ref.current===document.activeElement),te=Th(D,q,H);te&&setTimeout(()=>te.ref.current.focus())}),he=v.useCallback((q,D,H)=>{const te=!z.current&&!H;(w.value!==void 0&&w.value===D||te)&&(N(q),te&&(z.current=!0))},[w.value]),Ne=v.useCallback(()=>S==null?void 0:S.focus(),[S]),_e=v.useCallback((q,D,H)=>{const te=!z.current&&!H;(w.value!==void 0&&w.value===D||te)&&O(q)},[w.value]),V=r==="popper"?Ba:ah,ee=V===Ba?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:x,avoidCollisions:y}:{};return u.jsx(sh,{scope:n,content:S,viewport:T,onViewportChange:C,itemRefCallback:he,selectedItem:j,onItemLeave:Ne,itemTextRefCallback:_e,focusSelectedItem:B,selectedItemText:A,position:r,isPositioned:$,searchRef:J,children:u.jsx(is,{as:pC,allowPinchZoom:!0,children:u.jsx($o,{asChild:!0,trapped:w.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ue(o,q=>{var D;(D=w.trigger)==null||D.focus({preventScroll:!0}),q.preventDefault()}),children:u.jsx(Fo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(V,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:q=>q.preventDefault(),...g,...ee,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:ue(g.onKeyDown,q=>{const D=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!D&&q.key.length===1&&X(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let te=F().filter(se=>!se.disabled).map(se=>se.ref.current);if(["ArrowUp","End"].includes(q.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const se=q.target,ne=te.indexOf(se);te=te.slice(ne+1)}setTimeout(()=>_(te)),q.preventDefault()}})})})})})})});ih.displayName=fC;var hC="SelectItemAlignedPosition",ah=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Wn(ur,n),i=Vn(ur,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Ue(t,E=>d(E)),p=qs(n),h=v.useRef(!1),m=v.useRef(!0),{viewport:x,selectedItem:y,selectedItemText:g,focusSelectedItem:w}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&x&&y&&g){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),N=s.valueNode.getBoundingClientRect(),A=g.getBoundingClientRect();if(s.dir!=="rtl"){const se=A.left-j.left,ne=N.left-se,ke=E.left-ne,Q=E.width+ke,fe=Math.max(Q,j.width),Ie=window.innerWidth-mn,Ae=Ma(ne,[mn,Math.max(mn,Ie-fe)]);a.style.minWidth=Q+"px",a.style.left=Ae+"px"}else{const se=j.right-A.right,ne=window.innerWidth-N.right-se,ke=window.innerWidth-E.right-ne,Q=E.width+ke,fe=Math.max(Q,j.width),Ie=window.innerWidth-mn,Ae=Ma(ne,[mn,Math.max(mn,Ie-fe)]);a.style.minWidth=Q+"px",a.style.right=Ae+"px"}const O=p(),F=window.innerHeight-mn*2,$=x.scrollHeight,R=window.getComputedStyle(c),z=parseInt(R.borderTopWidth,10),_=parseInt(R.paddingTop,10),B=parseInt(R.borderBottomWidth,10),L=parseInt(R.paddingBottom,10),M=z+_+$+L+B,J=Math.min(y.offsetHeight*5,M),X=window.getComputedStyle(x),he=parseInt(X.paddingTop,10),Ne=parseInt(X.paddingBottom,10),_e=E.top+E.height/2-mn,V=F-_e,ee=y.offsetHeight/2,q=y.offsetTop+ee,D=z+_+q,H=M-D;if(D<=_e){const se=O.length>0&&y===O[O.length-1].ref.current;a.style.bottom="0px";const ne=c.clientHeight-x.offsetTop-x.offsetHeight,ke=Math.max(V,ee+(se?Ne:0)+ne+B),Q=D+ke;a.style.height=Q+"px"}else{const se=O.length>0&&y===O[0].ref.current;a.style.top="0px";const ke=Math.max(_e,z+x.offsetTop+(se?he:0)+ee)+H;a.style.height=ke+"px",x.scrollTop=D-_e+x.offsetTop}a.style.margin=`${mn}px 0`,a.style.minHeight=J+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,x,y,g,s.dir,r]);_t(()=>S(),[S]);const[k,T]=v.useState();_t(()=>{c&&T(window.getComputedStyle(c).zIndex)},[c]);const C=v.useCallback(E=>{E&&m.current===!0&&(S(),w==null||w(),m.current=!1)},[S,w]);return u.jsx(gC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Re.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});ah.displayName=hC;var mC="SelectPopperPosition",Ba=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=mn,...s}=e,i=Gs(n);return u.jsx(cu,{...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)"}})});Ba.displayName=mC;var[gC,Ha]=_r(ur,{}),Ua="SelectViewport",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Vn(Ua,n),i=Ha(Ua,n),a=Ue(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Ks.Slot,{scope:n,children:u.jsx(Re.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ue(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const m=window.innerHeight-mn*2,x=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(x,y);if(g<m){const w=g+h,S=Math.min(m,w),k=w-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});lh.displayName=Ua;var ch="SelectGroup",[xC,yC]=_r(ch),vC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Nn();return u.jsx(xC,{scope:n,id:o,children:u.jsx(Re.div,{role:"group","aria-labelledby":o,...r,ref:t})})});vC.displayName=ch;var uh="SelectLabel",dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=yC(uh,n);return u.jsx(Re.div,{id:o.id,...r,ref:t})});dh.displayName=uh;var Ys="SelectItem",[wC,fh]=_r(Ys),ph=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Wn(Ys,n),l=Vn(Ys,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),m=Ue(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),x=Nn(),y=v.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(wC,{scope:n,value:r,disabled:o,textId:x,isSelected:c,onItemTextChange:v.useCallback(w=>{f(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(Ks.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Re.div,{role:"option","aria-labelledby":x,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:ue(i.onFocus,()=>h(!0)),onBlur:ue(i.onBlur,()=>h(!1)),onClick:ue(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:ue(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:ue(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:ue(i.onPointerMove,w=>{var S;y.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ue(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ue(i.onKeyDown,w=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&w.key===" "||(sC.includes(w.key)&&g(),w.key===" "&&w.preventDefault())})})})})});ph.displayName=Ys;var mo="SelectItemText",hh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Wn(mo,n),a=Vn(mo,n),l=fh(mo,n),c=cC(mo,n),[d,f]=v.useState(null),p=Ue(t,g=>f(g),l.onItemTextChange,g=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,g,l.value,l.disabled)}),h=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:x,onNativeOptionRemove:y}=c;return _t(()=>(x(m),()=>y(m)),[x,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Re.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?yo.createPortal(s.children,i.valueNode):null]})});hh.displayName=mo;var mh="SelectItemIndicator",gh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return fh(mh,n).isSelected?u.jsx(Re.span,{"aria-hidden":!0,...r,ref:t}):null});gh.displayName=mh;var Wa="SelectScrollUpButton",xh=v.forwardRef((e,t)=>{const n=Vn(Wa,e.__scopeSelect),r=Ha(Wa,e.__scopeSelect),[o,s]=v.useState(!1),i=Ue(t,r.onScrollButtonChange);return _t(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});xh.displayName=Wa;var Va="SelectScrollDownButton",yh=v.forwardRef((e,t)=>{const n=Vn(Va,e.__scopeSelect),r=Ha(Va,e.__scopeSelect),[o,s]=v.useState(!1),i=Ue(t,r.onScrollButtonChange);return _t(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});yh.displayName=Va;var vh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Vn("SelectScrollButton",n),i=v.useRef(null),a=qs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),_t(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Re.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ue(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ue(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ue(o.onPointerLeave,()=>{l()})})}),bC="SelectSeparator",wh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Re.div,{"aria-hidden":!0,...r,ref:t})});wh.displayName=bC;var Ka="SelectArrow",SC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Gs(n),s=Wn(Ka,n),i=Vn(Ka,n);return s.open&&i.position==="popper"?u.jsx(uu,{...o,...r,ref:t}):null});SC.displayName=Ka;var CC="SelectBubbleInput",bh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Ue(r,o),i=Up(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Re.select,{...n,style:{...Xp,...n.style},ref:s,defaultValue:t})});bh.displayName=CC;function Sh(e){return e===""||e===void 0}function Ch(e){const t=Rt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Th(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=TC(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function TC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var kC=Jp,kh=Qp,EC=th,IC=nh,NC=rh,Eh=oh,AC=lh,Ih=dh,Nh=ph,jC=hh,_C=gh,Ah=xh,jh=yh,_h=wh;const Rh=kC,Ph=EC,qa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(kh,{ref:r,className:Z("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(IC,{asChild:!0,children:u.jsx(oe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));qa.displayName=kh.displayName;const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ah,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(oe.ChevronUp,{className:"h-4 w-4"})}));Oh.displayName=Ah.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(jh,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(oe.ChevronDown,{className:"h-4 w-4"})}));Mh.displayName=jh.displayName;const Ga=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(NC,{children:u.jsxs(Eh,{ref:o,className:Z("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Oh,{}),u.jsx(AC,{className:Z("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Mh,{})]})}));Ga.displayName=Eh.displayName;const RC=v.forwardRef(({className:e,...t},n)=>u.jsx(Ih,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));RC.displayName=Ih.displayName;const dr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Nh,{ref:r,className:Z("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(_C,{children:u.jsx(oe.Check,{className:"h-4 w-4"})})}),u.jsx(jC,{children:t})]}));dr.displayName=Nh.displayName;const PC=v.forwardRef(({className:e,...t},n)=>u.jsx(_h,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));PC.displayName=_h.displayName;var OC="Separator",Dh="horizontal",MC=["horizontal","vertical"],Lh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Dh,...o}=e,s=DC(r)?r:Dh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Re.div,{"data-orientation":s,...a,...o,ref:t})});Lh.displayName=OC;function DC(e){return MC.includes(e)}var Fh=Lh;const $h=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Fh,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));$h.displayName=Fh.displayName;const LC=qf,FC=Q0,$C=Gf,zh=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{className:Z("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));zh.displayName=_s.displayName;const zC=xo.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"}}),Bh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs($C,{children:[u.jsx(zh,{}),u.jsxs(Rs,{ref:o,className:Z(zC({side:e}),t),...r,children:[n,u.jsxs(Yf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(oe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Bh.displayName=Rs.displayName;const Hh=({className:e,...t})=>u.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});Hh.displayName="SheetHeader";const Uh=v.forwardRef(({className:e,...t},n)=>u.jsx(ar,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));Uh.displayName=ar.displayName;const Wh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ps,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));Wh.displayName=Ps.displayName;const BC={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 HC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,d]=b.useState(!1),{toast:f}=Ea();b.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),b.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(BC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(LC,{open:r,onOpenChange:o,children:[u.jsx(FC,{asChild:!0,children:u.jsxs(nt,{variant:"outline",size:"sm",className:n,children:[u.jsx(oe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Tf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Bh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Hh,{children:[u.jsx(Uh,{children:"Chat Settings"}),u.jsx(Wh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(zs,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(nt,{variant:"outline",onClick:x,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Un,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(zs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(nt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(oe.EyeOff,{className:"h-4 w-4"}):u.jsx(oe.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Rh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(qa,{children:u.jsx(Ph,{})}),u.jsxs(Ga,{children:[u.jsx(dr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(dr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(dr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"theme",children:"Theme"}),u.jsxs(Rh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(qa,{children:u.jsx(Ph,{})}),u.jsxs(Ga,{children:[u.jsx(dr,{value:"light",children:"Light"}),u.jsx(dr,{value:"dark",children:"Dark"}),u.jsx(dr,{value:"system",children:"System"})]})]})]}),u.jsx($h,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Un,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Un,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(an,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Un,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(an,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Un,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(an,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Un,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(nt,{variant:"outline",onClick:h,children:[u.jsx(oe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(nt,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(nt,{onClick:p,disabled:!c,children:[u.jsx(oe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function UC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Do,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx($s,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Do,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(za,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx($s,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Do,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(za,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx($s,{onError:s.onError,enableFileUpload:!0})})]})})}Ee.ChatApi=ql,Ee.ChatInput=mc,Ee.ChatInterface=$s,Ee.ChatProviders=Do,Ee.ChatSettings=HC,Ee.MarkdownContent=ho,Ee.MessageComponent=Pa,Ee.MessageList=Oa,Ee.ThreadManager=za,Ee.applySettings=GS,Ee.chatApiClient=Pn,Ee.default=UC,Ee.del=Kl,Ee.get=Qt,Ee.getChatToken=Ul,Ee.getCurrentSettings=qS,Ee.getDefaultApiConfig=Fp,Ee.getDefaultChatSettings=$p,Ee.onChatTokenChanged=Wl,Ee.post=di,Ee.put=Vl,Ee.setChatToken=jo,Ee.useApi=fi,Ee.useChatStream=lc,Ee.useMessagesReducer=ec,Ee.useStream=pc,Ee.useThreadState=Mo,Ee.useThreads=Oo,Object.defineProperties(Ee,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|