teodor-new-chat-ui 4.3.526 → 4.3.528
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 +3 -3
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3886,10 +3886,10 @@ function Ew(e, t) {
|
|
|
3886
3886
|
const s = e.messages.findIndex((a) => a.id === o);
|
|
3887
3887
|
if (s >= 0) {
|
|
3888
3888
|
const a = e.messages.slice(0, s);
|
|
3889
|
-
return { ...e, messages: [...a, r] };
|
|
3889
|
+
return { ...e, messages: [...a, r], assemblingId: null };
|
|
3890
3890
|
}
|
|
3891
3891
|
}
|
|
3892
|
-
return { ...e, messages: [...e.messages, r] };
|
|
3892
|
+
return { ...e, messages: [...e.messages, r], assemblingId: null };
|
|
3893
3893
|
}
|
|
3894
3894
|
case "seed": {
|
|
3895
3895
|
const r = Ca(t.payload.messages), o = {
|
|
@@ -4007,7 +4007,7 @@ function Sc(e, t) {
|
|
|
4007
4007
|
return { ...e, assemblingId: null, messages: d };
|
|
4008
4008
|
}
|
|
4009
4009
|
}
|
|
4010
|
-
return e;
|
|
4010
|
+
return { ...e, assemblingId: null };
|
|
4011
4011
|
}
|
|
4012
4012
|
if (t.type === "checkpoint") {
|
|
4013
4013
|
const s = t.checkpointNs ?? e.lastCheckpointNs ?? null, a = iw(e.messages, t.checkpointId, s);
|
package/dist/index.umd.js
CHANGED
|
@@ -36,7 +36,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
36
36
|
|
|
37
37
|
`))>=0;){const Oe=et.slice(0,me);et=et.slice(me+2);const qe=Oe.split(/\r?\n/),ut=[];for(const be of qe)if(!(!be||be.startsWith(":"))&&be.startsWith("data:")){const Xe=be.slice(5);ut.push(Xe.startsWith(" ")?Xe.slice(1):Xe)}const at=ut.join(`
|
|
38
38
|
`);if(!at)continue;let lt;try{lt=JSON.parse(at)}catch{console.debug("[use-chat] malformed SSE:",at.slice(0,200));continue}const Et=du(lt)?lt.data:lt;if(!Et){console.warn("[use-chat] dropped envelope event without payload",lt);continue}const ke=Et;Pt=Date.now();const Ee=ke.seq;if(Ee!==void 0){if(Ee<=mt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Ee,lastProcessedSeq:mt,type:ke.type});continue}mt>0&&Ee>mt+1&&((se=I==null?void 0:I.onGap)==null||se.call(I,{from:mt,to:Ee})),mt=Ee,E.current=Ee,x(Ee)}if(ke.type==="message.start"&&ke.role==="assistant"){const be=mu(ke.model);F.current={messageId:ke.id,lastSeq:Ee??null,lastText:""},k({id:ke.id,role:"assistant",name:be??void 0,model:ke.model,createdAt:new Date().toISOString(),content:[]})}if(ke.type==="checkpoint")_.current=ke.checkpointId??null,$.current=ke.checkpointNs??null,v(ke.checkpointId??null);else if(ke.type==="state_history"){L.current=ke;try{const Xe=Yn(ke).latest;Xe&&(_.current=Xe.checkpointId??null,$.current=Xe.checkpointNs??null,v(Xe.checkpointId??null))}catch(be){console.warn("[use-chat] Failed to hydrate state_history payload",be)}}try{j==null||j(ke)}catch(be){console.error("[use-chat] Error in onEvent callback:",be,"for event:",ke.type)}if(ke.type==="message.delta"){k(Xe=>{const At=F.current;if(!Xe||At.messageId!==Xe.id)return Xe;const{newParts:A,newMeta:ee,changed:Q}=hu(Xe.content??[],ke.delta,{lastSeq:At.lastSeq,lastText:At.lastText},Ee??null);return Q?(F.current={...At,lastSeq:ee.lastSeq??At.lastSeq,lastText:ee.lastText??At.lastText},{...Xe,content:A}):Xe});const be=ke.delta.filter(Xe=>Xe.type==="text").map(Xe=>Xe.text).join("");be&&e.autoAppendAssistant!==!1&&(bt.push(be),Dt())}else if(ke.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(ae=I==null?void 0:I.onHeartbeat)==null||ae.call(I,ke)}catch(be){console.warn("[use-chat] heartbeat callback failed",be)}}else if(Ct!==null&&cancelAnimationFrame(Ct),Tt(),ke.type==="checkpoint")v(ke.checkpointId);else if(ke.type==="error"){const be=ke;if(d(be.message),J="error",D=be.message,be.error_type==="auth_error"||be.code==="TOKEN_EXPIRED"||((Ce=be.message)==null?void 0:Ce.includes("token"))||((we=be.message)==null?void 0:we.includes("401"))||((je=be.message)==null?void 0:je.includes("unauthorized"))||((We=be.message)==null?void 0:We.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",be.message);try{(Fe=I==null?void 0:I.onAuthError)==null||Fe.call(I,be.message)}catch(At){console.warn("[use-chat] onAuthError handler failed",At)}Y.abort()}}}}Tt(),J===null&&!Y.signal.aborted&&(J="complete")}catch(Ue){if(Ue.name==="AbortError")J=J??"aborted";else{const $e=Ue.message||String(Ue);J="error",D=$e,d($e),(Ye=I==null?void 0:I.onError)==null||Ye.call(I,$e)}}finally{try{await Qe.cancel()}catch{}finally{(He=Qe.releaseLock)==null||He.call(Qe)}Ct!==null&&typeof window<"u"&&window.cancelAnimationFrame(Ct),clearInterval(kt)}}catch(Ve){if(Ve.name==="AbortError")J=J??"aborted";else{const Ae=Ve.message||String(Ve);J="error",D=Ae,d(Ae),(vt=I==null?void 0:I.onError)==null||vt.call(I,Ae),V||((wt=I==null?void 0:I.onConnectionError)==null||wt.call(I,Ae),V=!0)}}finally{const Ve=E.current,Ae=_.current,Ke=$.current,_e=L.current,Be=J??(Y.signal.aborted?"aborted":D?"error":"complete");try{(dt=I==null?void 0:I.onClosed)==null||dt.call(I,{reason:Be,lastSeq:Ve,lastCheckpointId:Ae,lastCheckpointNs:Ke,lastStateHistory:_e,error:D})}catch(Qe){console.warn("[use-chat] onClosed callback failed",Qe)}l(!1),b(!1),S.current=null,E.current=0,x(0),P.current=null}})(),{close:()=>Y.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var H;T.current=!1,(H=S.current)==null||H.abort()},[]),{isStreaming:a,error:c,assistantText:p,assistantMessage:C,lastCheckpointId:f,lastSeq:g,connected:y,stream:q,stop:K,clear:O,setToken:G}}const sw=["detail","message","error","description","title"];function Xo(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=Xo(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of sw){const r=Xo(t[n]);if(r)return r}if("errors"in t){const n=Xo(t.errors);if(n)return n}}return null}function iw(e){if(!e)return"Request failed";const t=e.response,n=Xo(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function gu({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=w.useState([]),[a,l]=w.useState(t),[c,d]=w.useState(!1),[p,m]=w.useState(null),[f,v]=w.useState([]),[g,x]=w.useState(!1),[,y]=w.useState(null),[b,C]=w.useState(null),[k,S]=w.useState(!1),T=w.useRef(a),E=w.useRef(new Map);w.useEffect(()=>{T.current=a},[a]);const P=w.useCallback(async()=>{d(!0),m(null);try{const j=await e.listThreads();i(j??[])}catch(j){const I=String(j);m(I),n==null||n(I)}finally{d(!1)}},[e,n]),_=w.useCallback(async()=>{x(!0),y(null);try{const j=await e.listSharedThreads();v(j??[])}catch(j){const I=String(j);y(I),n==null||n(I)}finally{x(!1)}},[e,n]);w.useEffect(()=>{P()},[P]),w.useEffect(()=>{_()},[_]),w.useEffect(()=>{r==null||r(a)},[a,r]);const $=w.useCallback(async j=>{try{const I=await e.createThread(j);return l(I.threadId),await P(),I.threadId}catch(I){const Y=String(I);return n==null||n(Y),null}},[e,n,P]),L=w.useCallback(async j=>{const I=s;i(J=>J.filter(D=>D.threadId!==j));const Y=new AbortController;E.current.set(j,Y);try{await e.deleteThread(j),T.current===j&&(l(null),o==null||o())}catch(J){i(I);const D=String(J);n==null||n(D)}finally{E.current.delete(j)}},[e,o,n,s]),F=w.useCallback(async(j,I)=>{try{await e.updateThread(j,I),await P()}catch(Y){n==null||n(String(Y))}},[e,n,P]),G=w.useCallback(async(j,I)=>{S(!0),C("Sharing thread…");try{await e.shareThread(j,I),await _(),C("Shared successfully")}catch(Y){const J=iw(Y);throw n==null||n(J),C(`Failed to share: ${J}`),new Error(J)}finally{S(!1)}},[e,n,_]),O=w.useCallback(async(j,I)=>{try{await e.unshareThread(j,I),await _()}catch(Y){const J=String(Y);throw n==null||n(J),Y}},[e,n,_]),K=w.useMemo(()=>({createThread:$,deleteThread:L,renameThread:F,refreshThreads:P,refreshSharedThreads:_,shareThread:G,unshareThread:O}),[$,L,F,P,_,G,O]),q=w.useCallback(j=>{if(!(j!=null&&j.threadId))return;const I={threadId:j.threadId,title:j.title||`Thread ${j.threadId.slice(0,8)}`,createdAt:j.createdAt||new Date().toISOString(),updatedAt:j.updatedAt||new Date().toISOString(),messageCount:j.messageCount??1};i(Y=>{let J=!1;const D=Y.map(V=>V.threadId===I.threadId?(J=!0,console.debug("[useThreadsState] thread_info: updating existing thread",I.threadId),{...V,title:I.title??V.title,updatedAt:I.updatedAt??V.updatedAt,messageCount:I.messageCount??V.messageCount}):V);return J?D:(console.debug("[useThreadsState] thread_info: adding thread to list",I.threadId),[I,...Y])})},[]),H=w.useCallback(()=>C(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:T,setCurrentThreadId:l,isLoadingThreads:c,threadsError:p,sharedThreads:f,isLoadingSharedThreads:g,actions:K,addThreadFromEvent:q,shareInFlight:k,shareStatus:b,clearShareStatus:H}}const xu=w.createContext(null);function vu({children:e,initialThreadId:t=null,onError:n,onThreadChange:r}){const{api:o}=eo(),{threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoadingThreads:c,threadsError:d,sharedThreads:p,isLoadingSharedThreads:m,actions:f,addThreadFromEvent:v,shareInFlight:g,shareStatus:x,clearShareStatus:y}=gu({api:o,initialThreadId:t,onError:n,onThreadChange:r}),b=w.useMemo(()=>({threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoading:c,error:d,sharedThreads:p,isLoadingSharedThreads:m,actions:f,shareInFlight:g,shareStatus:x,clearShareStatus:y,addThreadFromEvent:v}),[s,i,a,l,c,d,p,m,f,g,x,y,v]);return u.jsx(xu.Provider,{value:b,children:e})}function br(){const e=w.useContext(xu);if(!e)throw new Error("useThreads must be used within a ThreadsProvider");return e}function Qn(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{const n=aw(t);if(n)try{return JSON.parse(n)}catch{return null}return null}}function aw(e){let t=!1,n="";for(const o of e){if(o==="\\"){n+=o,t=!t;continue}if(o==="'"&&!t){n+='"';continue}n+=o,t=!1}return n.replace(/\bTrue\b/g,"true").replace(/\bFalse\b/g,"false").replace(/\bNone\b/g,"null")}function $i(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function yr(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(yr).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if($i(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=yr(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 er(e){if(typeof e=="string")return e;if($i(e))return"";try{const t=yr(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function wu(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function bu(e){const t=er(e);return typeof e=="string"&&wu(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function tr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Qn(t);if(n!==null)return tr(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?tr(e.content):e}function yu(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Jo(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 Fi(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Su(e){const t=r=>{try{const o=yr(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
|
|
39
|
-
`)):t(e)}function Cu(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Bi(e){if(e.role==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(i=>{switch(i.type){case"text":return`t:${i.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"",r="checkpointId"in e&&e.checkpointId?`cp:${e.checkpointId}`:"",o="checkpointNs"in e&&e.checkpointNs?`ns:${e.checkpointNs}`:"",s=[r,o].filter(Boolean).join("|");return`${e.id}:${t}:${n}${s?`:${s}`:""}`}function Tu(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function ku(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function Eu({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=Tu(n),i=o?`data:${s};base64,${e}`:t,a=ku(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function Iu(e){var o,s;const t=((o=e.content_base64)==null?void 0:o.trim())||void 0,n=((s=e.url)==null?void 0:s.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return Eu({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}function zi(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}function Sr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim(),n=Qn(t);return n!==null?Sr(n):t}if(Array.isArray(e))return e.map(t=>Sr(t));if(typeof e=="object"){const t=e.value;if(t!==void 0)return Sr(t)}return e}function Nu(e){const t=Sr(e.value);return t===e.value?e:{...e,value:t}}const lw={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,messagesStreamMeta:{},pendingInterrupt:null};function cw(e,t){var n;switch(t.type){case"reset":return{messages:Li(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,pendingInterrupt:null,messagesStreamMeta:{}};case"user_message":{const{message:r,editingMessageId:o}=t.payload;if(o){const s=e.messages.findIndex(i=>i.id===o);if(s>=0){const i=e.messages.slice(0,s);return{...e,messages:[...i,r]}}}return{...e,messages:[...e.messages,r]}}case"seed":{const r=Li(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=Li(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(a=>a.id)),s=r.filter(a=>!o.has(a.id));if(!s.length)return e;const i=[...s,...e.messages];return{...e,messages:i}}case"event":return Au(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Au(o,s),e):e}default:return e}}function uw(e=[]){const[t,n]=w.useReducer(cw,{...lw,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,p)=>n({type:"seed",payload:{messages:d,...p??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:(d,p)=>n({type:"user_message",payload:{message:d,editingMessageId:p}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Au(e,t){var n,r,o;if(t.type==="message.start"&&t.role==="assistant"){const s=t.id,i=mu(t.model);if(e.messages.some(c=>c.id===s)){const c=e.messagesStreamMeta??{},d={...c,[s]:c[s]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:s,messagesStreamMeta:d}}const l={id:s,role:"assistant",name:i||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:s,messages:[...e.messages,l]}}if(t.type==="tool.start")return fw(e,t);if(t.type==="tool.progress")return pw(e,t);if(t.type==="tool.end")return hw(e,t);if(t.type==="message.delta"){const s=e.assemblingId??fu(e.messages);if(!s)return e;const i=e.messages,a=i.findIndex(S=>S.id===s&&S.role==="assistant");if(a===-1)return e;const l=i[a],c=e.messagesStreamMeta,d=c??{},p=d[s],m=p??{lastSeq:null,lastText:pu(l.content)},f=t.seq??null;if(f!==null&&typeof f=="number"&&typeof m.lastSeq=="number"&&f<=m.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:f,lastSeq:m.lastSeq}),e;const{newParts:v,newMeta:g,changed:x}=hu(l.content,t.delta,m,f);if(!x)return e;const y={...l,content:v},b=to(i,a,y),C=!p||p.lastSeq!==g.lastSeq||p.lastText!==g.lastText,k=C?{...d,[s]:g}:c;return C?{...e,messages:b,messagesStreamMeta:k}:{...e,messages:b}}if(t.type==="message.end"){const s=e.assemblingId??fu(e.messages);if(!s)return{...e,assemblingId:null};const i=e.messages,a=i.findIndex(l=>l.id===s&&l.role==="assistant");if(a>=0){const l=i[a];if(!((n=l.content)==null?void 0:n.some(d=>{var p;return(d==null?void 0:d.type)==="text"&&((p=d.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:l.id,contentTypes:(r=l.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=l.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const d=[...i.slice(0,a),...i.slice(a+1)];return{...e,assemblingId:null,messages:d}}}return e}if(t.type==="checkpoint"){const s=t.checkpointNs??e.lastCheckpointNs??null,i=rw(e.messages,t.checkpointId,s);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:s,messages:i}}if(t.type==="error"){const s={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,s]}}if(t.type==="state_history"){const s=Yn(t),i=s.interrupt,a=s.latest,l=i===null?ew(e.messages):e.messages;return{...e,messages:l,pendingInterrupt:i,lastCheckpointId:(a==null?void 0:a.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(a==null?void 0:a.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function Hi(e){return e.call_id??e.id??null}function Pu(e){return e.id??e.call_id??`tool-${Date.now()}-${Math.random().toString(16).slice(2)}`}function ju(e,t,n,r){const o=t??`call-${Date.now()}-${Math.random().toString(16).slice(2)}`;return{id:e,role:"tool",name:n??void 0,content:[{type:"tool_call",id:o,name:n??"tool",args:r??{}}],createdAt:new Date().toISOString(),additionalKwargs:{toolCallId:o,toolName:n??void 0,toolStreaming:!0,toolProgress:[]}}}function Ui(e,t){if(!t)return-1;for(let n=0;n<e.length;n+=1){const r=e[n];if(r.role!=="tool")continue;const o=r.additionalKwargs??{};if(typeof o.toolCallId=="string"&&o.toolCallId===t||Jo(r).toolCallId===t)return n}return-1}function dw(e){if(e==null)return[];const t=tr(e);if(typeof t=="string"&&t.trim())return[{type:"text",text:t}];const n=er(t??e);return n?[{type:"text",text:n}]:[]}function _u(e,t){const n=e.additionalKwargs??{},r=Array.isArray(n.toolProgress)?[...n.toolProgress]:[],o={...n,toolProgress:[...r,t]};return{...e,additionalKwargs:o}}function fw(e,t){const n=Hi(t),r=Ui(e.messages,n),o=t.name??t.tool??void 0,s=Pu(t);if(r>=0){const a=e.messages[r],c={...a.additionalKwargs??{},toolStreaming:!0,toolProgress:[]},d={...a,name:o??a.name,additionalKwargs:c};return{...e,messages:to(e.messages,r,d)}}const i=ju(s,n,o,t.args);return{...e,messages:[...e.messages,i]}}function pw(e,t){const n=Hi(t);if(!n)return e;const r=Ui(e.messages,n);if(r===-1)return e;const o={type:t.type,content:typeof t.content=="string"?t.content:void 0,seq:t.seq??null,timestamp:new Date().toISOString()},s=t.metadata;s&&(o.metadata=s);const i=t.idx;typeof i=="number"&&(o.idx=i);const a=_u(e.messages[r],o);return{...e,messages:to(e.messages,r,a)}}function hw(e,t){const n=Hi(t),r=Pu(t);let o=e.messages,s=Ui(o,n);if(s===-1){const v=t.name??t.tool??void 0;o=[...o,ju(r,n,v,{})],s=o.length-1}const i=o[s],a=t.output??t.error??null,l=dw(a),c=[...i.content,...l],d={type:t.type,content:typeof t.output=="string"?t.output:void 0,seq:t.seq??null,timestamp:new Date().toISOString()};t.artifact&&(d.artifact=t.artifact);const p=_u(i,d),m=t.artifact??i.artifact,f={...p,name:t.name??t.tool??i.name,content:c,artifact:m,additionalKwargs:{...p.additionalKwargs??{},toolStreaming:!1}};return{...e,messages:to(o,s,f)}}function Ru({api:e,seed:t,onError:n,currentThreadId:r,initialThreadId:o=null,initialCheckpointId:s=null,initialCheckpointNs:i=null,autoLoadInitial:a=!0,isStreaming:l,getMessages:c}){const[d,p]=w.useState(null),f=w.useMemo(()=>Yn(d),[d]).checkpoints,v=ac(f),g=v.timeline,[x,y]=w.useState(!1),[b,C]=w.useState(!1),[k,S]=w.useState(null),T=w.useRef(r),E=w.useRef(null),P=w.useRef(null),_=w.useRef(null),$=w.useRef(null),L=w.useRef(null),F=w.useRef(new Map),G=w.useRef(null);w.useEffect(()=>{T.current=r},[r]);const O=w.useCallback(async R=>{var X,N;if(!R.threadId)return;const B=R.threadId;(X=R.onStart)==null||X.call(R),R.setLoading(!0);try{await R.action(B)}catch(M){if(!Jc(M)&&T.current===B){const Z=String(M);(N=R.handleError)==null||N.call(R,Z),n==null||n(Z)}throw M}finally{R.setLoading(!1)}},[n]),K=w.useCallback(async(R,B)=>{var Z;if(!R)return;const X=`${R}:${B??"latest"}`,N=F.current.get(X);if(N)return N;(Z=G.current)==null||Z.abort();const M=new AbortController;G.current=M;const U=O({threadId:R,setLoading:y,onStart:()=>S(null),handleError:se=>S(se),action:async se=>{const ae=await e.getStateHistory({threadId:se,checkpointId:B??void 0,signal:M.signal});if(T.current!==se){console.log(`[useThreadHistoryState] Thread changed during load (was ${se}, now ${T.current}), discarding stale data`);return}const{checkpoints:Ce}=Yn(ae),we=Ce.find(je=>je.messages&&je.messages.length>0)??(B?Ce.find(je=>je.checkpointId===B):null)??Ce[0];t((we==null?void 0:we.messages)??[],{checkpointId:(we==null?void 0:we.checkpointId)??null,checkpointNs:(we==null?void 0:we.checkpointNs)??null,pendingInterrupt:(we==null?void 0:we.interrupt)??null}),p(ae)}});F.current.set(X,U);try{await U}finally{F.current.delete(X),G.current===M&&(G.current=null)}return T.current===R&&(L.current=X),U},[e,t,O]),q=w.useCallback(async(R,B)=>{$.current=R;try{await K(R,B)}catch(X){if(!Jc(X))throw X}finally{$.current===R&&($.current=null)}},[K]),H=w.useCallback(R=>{P.current=R},[]),j=w.useCallback(R=>{_.current=R},[]),I=w.useCallback(R=>{const B=R.threadId??T.current;if(!B||T.current&&T.current!==B)return;const{checkpoints:X}=Yn(R);if(!X.length)return;const N=X.find(U=>U.messages&&U.messages.length>0)??X.find(U=>!!U.checkpointId)??X[0],M=_.current===B;!l&&!M&&t((N==null?void 0:N.messages)??[],{checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null,pendingInterrupt:(N==null?void 0:N.interrupt)??null}),p(R),L.current=`${B}:latest`,P.current=null,_.current===B&&(_.current=null)},[t,l]),Y=w.useCallback(async(R,B)=>{const X=T.current;await O({threadId:X,setLoading:C,action:async N=>{const M=await e.getStateHistory({threadId:N,checkpointId:R,checkpointNs:B??void 0});if(T.current!==N)return;const{checkpoints:U}=Yn(M),Z=U.find(se=>se.checkpointId===R&&(B?se.checkpointNs===B:!0));if(!Z){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:R,checkpointNs:B});return}p(M),t(Z.messages??[],{checkpointId:Z.checkpointId??null,checkpointNs:Z.checkpointNs??null})}}).catch(()=>{})},[e,t,O]),J=w.useCallback((R,B)=>{t(c(),{checkpointId:R??null,checkpointNs:B??null})},[c,t]),D=w.useCallback(async()=>{T.current&&await q(T.current)},[q]);w.useEffect(()=>{if(!a||!r||x||l)return;if(P.current===r){P.current=null,E.current=r;return}if(_.current===r){E.current=r;return}if($.current===r){$.current=null,E.current=r;return}if(E.current===r)return;E.current=r;let R;const B=`${r}:latest`;L.current!==B&&q(r,R)},[a,r,s,i,o,x,l,q]);const V=w.useCallback(()=>{p(null),y(!1),C(!1),S(null),P.current=null,_.current=null,E.current=null,L.current=null,$.current=null},[]);return{threadCheckpoints:f,threadTimeline:g,checkpointIndex:v,isLoadingThread:x,isLoadingCheckpoint:b,threadStateError:k,loadThread:q,navigateToCheckpoint:Y,setCurrentCheckpointId:J,returnToLatest:D,handleStateHistoryEvent:I,markSkipNextLoad:H,markStreamPendingThread:j,resetHistoryState:V}}const Mu=w.createContext(null),Ou=w.createContext(null);function no(){const e=w.useContext(Mu);if(!e)throw new Error("useThreadState must be used within a ThreadStateProvider");return e}function Du(){const e=w.useContext(Ou);if(!e)throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");return e}function Lu({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,isStreaming:s,onError:i}){const{api:a}=eo(),{currentThreadId:l}=br(),{state:c,seed:d,pushUser:p,onEvent:m}=uw(),{threadCheckpoints:f,threadTimeline:v,checkpointIndex:g,isLoadingThread:x,isLoadingCheckpoint:y,threadStateError:b,loadThread:C,navigateToCheckpoint:k,setCurrentCheckpointId:S,returnToLatest:T,handleStateHistoryEvent:E,markSkipNextLoad:P,markStreamPendingThread:_,resetHistoryState:$}=Ru({api:a,seed:d,onError:i,currentThreadId:l,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:s,getMessages:w.useCallback(()=>c.messages,[c.messages])}),[L,F]=w.useState(()=>async()=>{throw new Error("clearThread is not ready")}),[G,O]=w.useState(()=>async()=>{throw new Error("respondToInterrupt is not ready")});w.useEffect(()=>{l||(d([],{}),$())},[l,d,$]);const K=w.useCallback(Y=>F(()=>Y),[]),q=w.useCallback(Y=>O(()=>Y),[]),H=w.useMemo(()=>({assemblingMessageId:c.assemblingId??null}),[c.assemblingId]),j=w.useMemo(()=>({threadId:l,messages:c.messages,interrupt:c.pendingInterrupt,checkpoint:{id:c.lastCheckpointId??null,namespace:c.lastCheckpointNs??null},checkpoints:f,checkpointIndex:g,timelineCheckpoints:v,metadata:H,isLoading:x,isLoadingCheckpoint:y,error:b,clearState:L,navigateToCheckpoint:k,setCurrentCheckpointId:S,returnToLatest:T,loadThread:C,clearThread:L,respondToInterrupt:G,messagePreviews:g.messagePreviews,handleStateHistoryEvent:E,markSkipNextLoad:P,markStreamPendingThread:_,resetHistoryState:$,pushUser:p,onEvent:m}),[l,c,f,v,g,H,x,y,b,L,k,S,T,C,G,g.messagePreviews,E,P,_,$,p,m]),I=w.useMemo(()=>({registerClearThread:K,registerRespondToInterrupt:q}),[K,q]);return u.jsx(Ou.Provider,{value:I,children:u.jsx(Mu.Provider,{value:j,children:e})})}function $u(e,t){if(!e)return null;const n=_n(e);if(!n)return null;const r=_n(n.configurable)??n;return Rn(r,t)??null}function mw(e){const t=$u(e,["checkpoint_id","checkpointId"]);if(!t)return null;const n=$u(e,["checkpoint_ns","checkpointNs"]);return{checkpointId:t,checkpointNs:n}}function gw(e,t){const n=typeof e.step=="number"?e.step:Number.POSITIVE_INFINITY,r=typeof t.step=="number"?t.step:Number.POSITIVE_INFINITY;if(n!==r)return n-r;const o=e.createdAt?Date.parse(e.createdAt):0,s=t.createdAt?Date.parse(t.createdAt):0;return o-s}function xw(e,t){const n=[...e].sort(gw);for(const r of n){if(r.messageId!==t)continue;const o=mw(r.parentConfig);if(!o)throw new Error(`Parent checkpoint info missing for message ${t}`);return o}throw new Error(`Message ${t} not found in timeline`)}const Fu=w.createContext(null),Bu=w.createContext(!1);function vw({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l,onToolEnd:c}){const{api:d,baseUrl:p}=eo(),m=w.useMemo(()=>vn(p),[p]),{stream:f,stop:v,isStreaming:g,error:x,setToken:y}=ow({baseUrl:m}),[b,C]=w.useState(!1);return w.useEffect(()=>{C(g)},[g]),u.jsx(vu,{initialThreadId:t,onError:s,onThreadChange:a,children:u.jsx(Lu,{initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,onError:s,isStreaming:b,children:u.jsx(Bu.Provider,{value:!0,children:u.jsx(ww,{api:d,streamApi:{stream:f,stop:v,isStreaming:g,error:x,setToken:y},onError:s,onAuthError:i,onConnectionError:l,onToolEnd:c,children:e})})})})}function ww({children:e,api:t,streamApi:n,onError:r,onAuthError:o,onConnectionError:s,onToolEnd:i}){const{stream:a,stop:l,isStreaming:c,error:d,setToken:p}=n,{setCurrentThreadId:m,currentThreadIdRef:f,addThreadFromEvent:v}=br(),{checkpoint:g,timelineCheckpoints:x,handleStateHistoryEvent:y,markSkipNextLoad:b,markStreamPendingThread:C,resetHistoryState:k,pushUser:S,onEvent:T}=no(),{registerClearThread:E,registerRespondToInterrupt:P}=Du(),_=w.useCallback(H=>{v(H),f.current!==H.threadId&&((H.created??!f.current)&&b(H.threadId),C(H.threadId),m(H.threadId))},[v,b,C,m,f]),$=w.useCallback(H=>{H.type==="thread_info"?_(H):H.type==="state_history"?y(H):H.type==="tool.end"?i==null||i(H):T(H)},[_,y,T,i]),L=w.useCallback(H=>{a(H,$,{onError:j=>{console.error("[StreamingProvider] Stream error:",j),r==null||r(j)},onAuthError:j=>{console.error("[StreamingProvider] Auth error:",j),o==null||o(j)},onConnectionError:j=>{console.error("[StreamingProvider] Connection error:",j),s==null||s(j)}})},[a,$,r,o,s]),F=w.useRef(g);w.useEffect(()=>{F.current=g},[g]);const G=w.useCallback(async(H,j,I)=>{const Y=f.current;if(!Y)throw new Error("No active thread to handle interrupt");const J=H?j??!0:!1,D=F.current,V={threadId:Y,checkpointId:D.id??void 0,checkpointNs:D.namespace??void 0,command:{kind:"resume",value:J},payload:I==null?void 0:I.payload,config:I==null?void 0:I.config,nodeFilter:I==null?void 0:I.nodeFilter,branchLabel:I==null?void 0:I.branchLabel,active_agent:I==null?void 0:I.active_agent,timelineCheckpoints:I==null?void 0:I.timelineCheckpoints};L(V)},[f,L]);w.useEffect(()=>{P(G)},[G,P]);const O=w.useCallback(async()=>{l(),k(),m(null)},[k,m,l]);w.useEffect(()=>{E(O)},[O,E]);const K=w.useCallback(async(H,j)=>{let I=f.current;const Y=(H==null?void 0:H.text)??"",J=(H==null?void 0:H.attachments)??[],D=(Y==null?void 0:Y.trim())??"",V={...(H==null?void 0:H.payload)??{}},R=Array.isArray(V.messages)?V.messages:void 0;R&&delete V.messages;const B=!!(R&&R.length);if(!I&&!D&&J.length===0&&!B)return;if(!I){const Ye=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),He=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);I=`${Ye}${He}`,b(I),m(I)}const{contentParts:X,filesInfo:N}=await uu(J),M=[...X];D&&M.push({type:"text",text:Y});const U=j==null?void 0:j.originalMessageId,Z=!!(j!=null&&j.edit&&U),se=!B&&M.length>0;let ae=null;se&&(ae={id:Z?U:`msg-${Date.now()}`,role:"user",content:M,createdAt:new Date().toISOString()},Z?S(ae,U):S(ae));const Ce=B?R:ae?[ae]:[],we={...V,...N.length?{files_info:N}:{}};Ce.length?we.messages=Ce:"messages"in we||(we.messages=[]);let je=(j==null?void 0:j.checkpointId)??g.id??void 0,We=(j==null?void 0:j.checkpointNs)??g.namespace??void 0;if(Z&&U){const Ye=xw(x,U);je=Ye.checkpointId,We=Ye.checkpointNs??void 0}const Fe={threadId:I,payload:we,checkpointId:je,checkpointNs:We,edit:!!(j!=null&&j.edit)};L(Fe)},[g,f,b,S,L,x]),q=w.useMemo(()=>({isStreaming:c,error:d,connectionState:c?"connected":"idle",submit:K,send:K,stop:l,setAuthToken:p}),[c,d,K,l,p]);return u.jsx(Fu.Provider,{value:q,children:e})}function Wi(){const e=w.useContext(Fu);if(!e)throw new Error("useStream must be used within StreamingProvider");return e}function bw(){return w.useContext(Bu)}function zu(e){return typeof e=="object"&&e!==null}function yw(e,t){if(Object.is(e,t))return!0;if(!zu(e)||!zu(t))return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}function Hu(e){const t=w.useRef(e),n=w.useRef(e);return yw(t.current,e)||(t.current=e,n.current=e),n.current}function Cr({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:c,onToolEnd:d}){const p=Hu(t),m=ro(a),f=ro(l),v=ro(i),g=ro(c),x=ro(d),y=w.useMemo(()=>({initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:m,onAuthError:f,onConnectionError:v,onThreadChange:g,onToolEnd:x}),[n,r,o,s,m,f,v,g,x]);return u.jsx(lu,{apiConfig:p,children:u.jsx(vw,{...y,children:e})})}function ro(e){const t=w.useRef(e);return w.useEffect(()=>{t.current=e},[e]),w.useCallback((...n)=>{const r=t.current;if(r)return r(...n)},[])}function Tr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function Sw(e){if(typeof e!="string")return;const t=e.trim();if(t)return vn(t)}function Uu(){const e=[Tr("__API_BASE_URL__"),Tr("__CHAT_API_BASE_URL__"),Tr("__CHAT_API_URL__")];for(const t of e){const n=Sw(t);if(n)return n}}function Wu(){const e=[Tr("__API_AUTH_TOKEN__"),Tr("__CHAT_API_KEY__"),Tr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Vu(...e){for(const t of e)if(typeof t=="string"&&t.trim())return vn(t);return vn()}function Ku(){const e={},t=Uu(),n=Wu();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function qu(){const e=Ku(),t=Nn.getAuthToken(),n=Uu();return{apiBaseUrl:Vu(e.baseUrl,Nn.baseUrl,n),apiKey:t||e.apiKey||Wu()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Vi="chat-settings";function Gu(){try{const e=localStorage.getItem(Vi);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function Yu(e){try{const t={...e,apiBaseUrl:vn(e.apiBaseUrl)};localStorage.setItem(Vi,JSON.stringify(t)),t.apiKey&&Nn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function Cw(){const e=qu(),t=Gu(),n=Nn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Vu(Nn.baseUrl,r,e.apiBaseUrl)}}function Tw(e){Nn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),Yu(e)}function re(...e){return hx.twMerge(px.clsx(e))}const kw=Vr.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"}}),Je=h.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yt.Slot:"button";return u.jsx(i,{className:re(kw({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";function ie(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function Xu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Mn(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Xu(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():Xu(e[o],null)}}}}function De(...e){return h.useCallback(Mn(...e),e)}function Ew(e,t){const n=h.createContext(t),r=s=>{const{children:i,...a}=s,l=h.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=h.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 cn(e,t=[]){let n=[];function r(s,i){const a=h.createContext(i),l=n.length;n=[...n,i];const c=p=>{var y;const{scope:m,children:f,...v}=p,g=((y=m==null?void 0:m[e])==null?void 0:y[l])||a,x=h.useMemo(()=>v,Object.values(v));return u.jsx(g.Provider,{value:x,children:f})};c.displayName=s+"Provider";function d(p,m){var g;const f=((g=m==null?void 0:m[e])==null?void 0:g[l])||a,v=h.useContext(f);if(v)return v;if(i!==void 0)return i;throw new Error(`\`${p}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>h.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return h.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Iw(o,...t)]}function Iw(...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 p=l(s)[`__scope${c}`];return{...a,...p}},{});return h.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var It=globalThis!=null&&globalThis.document?h.useLayoutEffect:()=>{},Nw=h[" useInsertionEffect ".trim().toString()]||It;function On({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Aw({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=h.useRef(e!==void 0);h.useEffect(()=>{const p=d.current;p!==a&&console.warn(`${r} is changing from ${p?"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=h.useCallback(d=>{var p;if(a){const m=Pw(d)?d(e):d;m!==e&&((p=i.current)==null||p.call(i,m))}else s(d)},[a,e,s,i]);return[l,c]}function Aw({defaultProp:e,onChange:t}){const[n,r]=h.useState(e),o=h.useRef(n),s=h.useRef(t);return Nw(()=>{s.current=t},[t]),h.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Pw(e){return typeof e=="function"}var jw=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],fe=jw.reduce((e,t)=>{const n=Yt.createSlot(`Primitive.${t}`),r=h.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 Ki(e,t){e&&Kr.flushSync(()=>e.dispatchEvent(t))}function Zo(e){const t=e+"CollectionProvider",[n,r]=cn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:x,children:y}=g,b=w.useRef(null),C=w.useRef(new Map).current;return u.jsx(o,{scope:x,itemMap:C,collectionRef:b,children:y})};i.displayName=t;const a=e+"CollectionSlot",l=Yt.createSlot(a),c=w.forwardRef((g,x)=>{const{scope:y,children:b}=g,C=s(a,y),k=De(x,C.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",p="data-radix-collection-item",m=Yt.createSlot(d),f=w.forwardRef((g,x)=>{const{scope:y,children:b,...C}=g,k=w.useRef(null),S=De(x,k),T=s(d,y);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...C}),()=>void T.itemMap.delete(k))),u.jsx(m,{[p]:"",ref:S,children:b})});f.displayName=d;function v(g){const x=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=x.collectionRef.current;if(!b)return[];const C=Array.from(b.querySelectorAll(`[${p}]`));return Array.from(x.itemMap.values()).sort((T,E)=>C.indexOf(T.ref.current)-C.indexOf(E.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:i,Slot:c,ItemSlot:f},v,r]}var _w=h.createContext(void 0);function Qo(e){const t=h.useContext(_w);return e||t||"ltr"}function pt(e){const t=h.useRef(e);return h.useEffect(()=>{t.current=e}),h.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Rw(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e);h.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 Mw="DismissableLayer",qi="dismissableLayer.update",Ow="dismissableLayer.pointerDownOutside",Dw="dismissableLayer.focusOutside",Ju,Zu=h.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),kr=h.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=h.useContext(Zu),[d,p]=h.useState(null),m=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=h.useState({}),v=De(t,E=>p(E)),g=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=g.indexOf(x),b=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=y,S=$w(E=>{const P=E.target,_=[...c.branches].some($=>$.contains(P));!k||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},m),T=Fw(E=>{const P=E.target;[...c.branches].some($=>$.contains(P))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},m);return Rw(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},m),h.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(Ju=m.body.style.pointerEvents,m.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),ed(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(m.body.style.pointerEvents=Ju)}},[d,m,n,c]),h.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),ed())},[d,c]),h.useEffect(()=>{const E=()=>f({});return document.addEventListener(qi,E),()=>document.removeEventListener(qi,E)},[]),u.jsx(fe.div,{...l,ref:v,style:{pointerEvents:C?k?"auto":"none":void 0,...e.style},onFocusCapture:ie(e.onFocusCapture,T.onFocusCapture),onBlurCapture:ie(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:ie(e.onPointerDownCapture,S.onPointerDownCapture)})});kr.displayName=Mw;var Lw="DismissableLayerBranch",Qu=h.forwardRef((e,t)=>{const n=h.useContext(Zu),r=h.useRef(null),o=De(t,r);return h.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(fe.div,{...e,ref:o})});Qu.displayName=Lw;function $w(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e),r=h.useRef(!1),o=h.useRef(()=>{});return h.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){td(Ow,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 Fw(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e),r=h.useRef(!1);return h.useEffect(()=>{const o=s=>{s.target&&!r.current&&td(Dw,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 ed(){const e=new CustomEvent(qi);document.dispatchEvent(e)}function td(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?Ki(o,s):o.dispatchEvent(s)}var Bw=kr,zw=Qu,Gi=0;function Yi(){h.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??nd()),document.body.insertAdjacentElement("beforeend",e[1]??nd()),Gi++,()=>{Gi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Gi--}},[])}function nd(){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 Xi="focusScope.autoFocusOnMount",Ji="focusScope.autoFocusOnUnmount",rd={bubbles:!1,cancelable:!0},Hw="FocusScope",es=h.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=h.useState(null),c=pt(o),d=pt(s),p=h.useRef(null),m=De(t,g=>l(g)),f=h.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;h.useEffect(()=>{if(r){let g=function(C){if(f.paused||!a)return;const k=C.target;a.contains(k)?p.current=k:Dn(p.current,{select:!0})},x=function(C){if(f.paused||!a)return;const k=C.relatedTarget;k!==null&&(a.contains(k)||Dn(p.current,{select:!0}))},y=function(C){if(document.activeElement===document.body)for(const S of C)S.removedNodes.length>0&&Dn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",x);const b=new MutationObserver(y);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",x),b.disconnect()}}},[r,a,f.paused]),h.useEffect(()=>{if(a){id.add(f);const g=document.activeElement;if(!a.contains(g)){const y=new CustomEvent(Xi,rd);a.addEventListener(Xi,c),a.dispatchEvent(y),y.defaultPrevented||(Uw(Gw(od(a)),{select:!0}),document.activeElement===g&&Dn(a))}return()=>{a.removeEventListener(Xi,c),setTimeout(()=>{const y=new CustomEvent(Ji,rd);a.addEventListener(Ji,d),a.dispatchEvent(y),y.defaultPrevented||Dn(g??document.body,{select:!0}),a.removeEventListener(Ji,d),id.remove(f)},0)}}},[a,c,d,f]);const v=h.useCallback(g=>{if(!n&&!r||f.paused)return;const x=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,y=document.activeElement;if(x&&y){const b=g.currentTarget,[C,k]=Ww(b);C&&k?!g.shiftKey&&y===k?(g.preventDefault(),n&&Dn(C,{select:!0})):g.shiftKey&&y===C&&(g.preventDefault(),n&&Dn(k,{select:!0})):y===b&&g.preventDefault()}},[n,r,f.paused]);return u.jsx(fe.div,{tabIndex:-1,...i,ref:m,onKeyDown:v})});es.displayName=Hw;function Uw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Dn(r,{select:t}),document.activeElement!==n)return}function Ww(e){const t=od(e),n=sd(t,e),r=sd(t.reverse(),e);return[n,r]}function od(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 sd(e,t){for(const n of e)if(!Vw(n,{upTo:t}))return n}function Vw(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 Kw(e){return e instanceof HTMLInputElement&&"select"in e}function Dn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Kw(e)&&t&&e.select()}}var id=qw();function qw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=ad(e,t),e.unshift(t)},remove(t){var n;e=ad(e,t),(n=e[0])==null||n.resume()}}}function ad(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Gw(e){return e.filter(t=>t.tagName!=="A")}var Yw=h[" useId ".trim().toString()]||(()=>{}),Xw=0;function _t(e){const[t,n]=h.useState(Yw());return It(()=>{n(r=>r??String(Xw++))},[e]),t?`radix-${t}`:""}const Jw=["top","right","bottom","left"],Ln=Math.min,Zt=Math.max,ts=Math.round,ns=Math.floor,wn=e=>({x:e,y:e}),Zw={left:"right",right:"left",bottom:"top",top:"bottom"},Qw={start:"end",end:"start"};function Zi(e,t,n){return Zt(e,Ln(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function Pn(e){return e.split("-")[0]}function Er(e){return e.split("-")[1]}function Qi(e){return e==="x"?"y":"x"}function ea(e){return e==="y"?"height":"width"}const eb=new Set(["top","bottom"]);function bn(e){return eb.has(Pn(e))?"y":"x"}function ta(e){return Qi(bn(e))}function tb(e,t,n){n===void 0&&(n=!1);const r=Er(e),o=ta(e),s=ea(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=rs(i)),[i,rs(i)]}function nb(e){const t=rs(e);return[na(e),t,na(t)]}function na(e){return e.replace(/start|end/g,t=>Qw[t])}const ld=["left","right"],cd=["right","left"],rb=["top","bottom"],ob=["bottom","top"];function sb(e,t,n){switch(e){case"top":case"bottom":return n?t?cd:ld:t?ld:cd;case"left":case"right":return t?rb:ob;default:return[]}}function ib(e,t,n,r){const o=Er(e);let s=sb(Pn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(na)))),s}function rs(e){return e.replace(/left|right|bottom|top/g,t=>Zw[t])}function ab(e){return{top:0,right:0,bottom:0,left:0,...e}}function ud(e){return typeof e!="number"?ab(e):{top:e,right:e,bottom:e,left:e}}function os(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 dd(e,t,n){let{reference:r,floating:o}=e;const s=bn(t),i=ta(t),a=ea(i),l=Pn(t),c=s==="y",d=r.x+r.width/2-o.width/2,p=r.y+r.height/2-o.height/2,m=r[a]/2-o[a]/2;let f;switch(l){case"top":f={x:d,y:r.y-o.height};break;case"bottom":f={x:d,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:p};break;case"left":f={x:r.x-o.width,y:p};break;default:f={x:r.x,y:r.y}}switch(Er(t)){case"start":f[i]-=m*(n&&c?-1:1);break;case"end":f[i]+=m*(n&&c?-1:1);break}return f}const lb=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:p}=dd(c,r,l),m=r,f={},v=0;for(let g=0;g<a.length;g++){const{name:x,fn:y}=a[g],{x:b,y:C,data:k,reset:S}=await y({x:d,y:p,initialPlacement:r,placement:m,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,p=C??p,f={...f,[x]:{...f[x],...k}},S&&v<=50&&(v++,typeof S=="object"&&(S.placement&&(m=S.placement),S.rects&&(c=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:d,y:p}=dd(c,m,l)),g=-1)}return{x:d,y:p,placement:m,strategy:o,middlewareData:f}};async function oo(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:p="floating",altBoundary:m=!1,padding:f=0}=An(t,e),v=ud(f),x=a[m?p==="floating"?"reference":"floating":p],y=os(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=p==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},S=os(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:C,strategy:l}):b);return{top:(y.top-S.top+v.top)/k.y,bottom:(S.bottom-y.bottom+v.bottom)/k.y,left:(y.left-S.left+v.left)/k.x,right:(S.right-y.right+v.right)/k.x}}const cb=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const p=ud(d),m={x:n,y:r},f=ta(o),v=ea(f),g=await i.getDimensions(c),x=f==="y",y=x?"top":"left",b=x?"bottom":"right",C=x?"clientHeight":"clientWidth",k=s.reference[v]+s.reference[f]-m[f]-s.floating[v],S=m[f]-s.reference[f],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[C]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[C]||s.floating[v]);const P=k/2-S/2,_=E/2-g[v]/2-1,$=Ln(p[y],_),L=Ln(p[b],_),F=$,G=E-g[v]-L,O=E/2-g[v]/2+P,K=Zi(F,O,G),q=!l.arrow&&Er(o)!=null&&O!==K&&s.reference[v]/2-(O<F?$:L)-g[v]/2<0,H=q?O<F?O-F:O-G:0;return{[f]:m[f]+H,data:{[f]:K,centerOffset:O-K-H,...q&&{alignmentOffset:H}},reset:q}}}),ub=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:p=!0,fallbackPlacements:m,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:g=!0,...x}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=Pn(o),b=bn(a),C=Pn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),S=m||(C||!g?[rs(a)]:nb(a)),T=v!=="none";!m&&T&&S.push(...ib(a,g,v,k));const E=[a,...S],P=await oo(t,x),_=[];let $=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(P[y]),p){const O=tb(o,i,k);_.push(P[O[0]],P[O[1]])}if($=[...$,{placement:o,overflows:_}],!_.every(O=>O<=0)){var L,F;const O=(((L=s.flip)==null?void 0:L.index)||0)+1,K=E[O];if(K&&(!(p==="alignment"?b!==bn(K):!1)||$.every(j=>bn(j.placement)===b?j.overflows[0]>0:!0)))return{data:{index:O,overflows:$},reset:{placement:K}};let q=(F=$.filter(H=>H.overflows[0]<=0).sort((H,j)=>H.overflows[1]-j.overflows[1])[0])==null?void 0:F.placement;if(!q)switch(f){case"bestFit":{var G;const H=(G=$.filter(j=>{if(T){const I=bn(j.placement);return I===b||I==="y"}return!0}).map(j=>[j.placement,j.overflows.filter(I=>I>0).reduce((I,Y)=>I+Y,0)]).sort((j,I)=>j[1]-I[1])[0])==null?void 0:G[0];H&&(q=H);break}case"initialPlacement":q=a;break}if(o!==q)return{reset:{placement:q}}}return{}}}};function fd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function pd(e){return Jw.some(t=>e[t]>=0)}const db=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 oo(t,{...o,elementContext:"reference"}),i=fd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:pd(i)}}}case"escaped":{const s=await oo(t,{...o,altBoundary:!0}),i=fd(s,n.floating);return{data:{escapedOffsets:i,escaped:pd(i)}}}default:return{}}}}},hd=new Set(["left","top"]);async function fb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Pn(n),a=Er(n),l=bn(n)==="y",c=hd.has(i)?-1:1,d=s&&l?-1:1,p=An(t,e);let{mainAxis:m,crossAxis:f,alignmentAxis:v}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return a&&typeof v=="number"&&(f=a==="end"?v*-1:v),l?{x:f*d,y:m*c}:{x:m*c,y:f*d}}const pb=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 fb(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}}}}},hb=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:x=>{let{x:y,y:b}=x;return{x:y,y:b}}},...l}=An(e,t),c={x:n,y:r},d=await oo(t,l),p=bn(Pn(o)),m=Qi(p);let f=c[m],v=c[p];if(s){const x=m==="y"?"top":"left",y=m==="y"?"bottom":"right",b=f+d[x],C=f-d[y];f=Zi(b,f,C)}if(i){const x=p==="y"?"top":"left",y=p==="y"?"bottom":"right",b=v+d[x],C=v-d[y];v=Zi(b,v,C)}const g=a.fn({...t,[m]:f,[p]:v});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[m]:s,[p]:i}}}}}},mb=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},p=bn(o),m=Qi(p);let f=d[m],v=d[p];const g=An(a,t),x=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=m==="y"?"height":"width",k=s.reference[m]-s.floating[C]+x.mainAxis,S=s.reference[m]+s.reference[C]-x.mainAxis;f<k?f=k:f>S&&(f=S)}if(c){var y,b;const C=m==="y"?"width":"height",k=hd.has(Pn(o)),S=s.reference[p]-s.floating[C]+(k&&((y=i.offset)==null?void 0:y[p])||0)+(k?0:x.crossAxis),T=s.reference[p]+s.reference[C]+(k?0:((b=i.offset)==null?void 0:b[p])||0)-(k?x.crossAxis:0);v<S?v=S:v>T&&(v=T)}return{[m]:f,[p]:v}}}},gb=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 oo(t,c),p=Pn(o),m=Er(o),f=bn(o)==="y",{width:v,height:g}=s.floating;let x,y;p==="top"||p==="bottom"?(x=p,y=m===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=p,x=m==="end"?"top":"bottom");const b=g-d.top-d.bottom,C=v-d.left-d.right,k=Ln(g-d[x],b),S=Ln(v-d[y],C),T=!t.middlewareData.shift;let E=k,P=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!m){const $=Zt(d.left,0),L=Zt(d.right,0),F=Zt(d.top,0),G=Zt(d.bottom,0);f?P=v-2*($!==0||L!==0?$+L:Zt(d.left,d.right)):E=g-2*(F!==0||G!==0?F+G:Zt(d.top,d.bottom))}await l({...t,availableWidth:P,availableHeight:E});const _=await i.getDimensions(a.floating);return v!==_.width||g!==_.height?{reset:{rects:!0}}:{}}}};function ss(){return typeof window<"u"}function Ir(e){return md(e)?(e.nodeName||"").toLowerCase():"#document"}function Qt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function yn(e){var t;return(t=(md(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function md(e){return ss()?e instanceof Node||e instanceof Qt(e).Node:!1}function un(e){return ss()?e instanceof Element||e instanceof Qt(e).Element:!1}function Sn(e){return ss()?e instanceof HTMLElement||e instanceof Qt(e).HTMLElement:!1}function gd(e){return!ss()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Qt(e).ShadowRoot}const xb=new Set(["inline","contents"]);function so(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!xb.has(o)}const vb=new Set(["table","td","th"]);function wb(e){return vb.has(Ir(e))}const bb=[":popover-open",":modal"];function is(e){return bb.some(t=>{try{return e.matches(t)}catch{return!1}})}const yb=["transform","translate","scale","rotate","perspective"],Sb=["transform","translate","scale","rotate","perspective","filter"],Cb=["paint","layout","strict","content"];function ra(e){const t=oa(),n=un(e)?dn(e):e;return yb.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)||Sb.some(r=>(n.willChange||"").includes(r))||Cb.some(r=>(n.contain||"").includes(r))}function Tb(e){let t=$n(e);for(;Sn(t)&&!Nr(t);){if(ra(t))return t;if(is(t))return null;t=$n(t)}return null}function oa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const kb=new Set(["html","body","#document"]);function Nr(e){return kb.has(Ir(e))}function dn(e){return Qt(e).getComputedStyle(e)}function as(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $n(e){if(Ir(e)==="html")return e;const t=e.assignedSlot||e.parentNode||gd(e)&&e.host||yn(e);return gd(t)?t.host:t}function xd(e){const t=$n(e);return Nr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sn(t)&&so(t)?t:xd(t)}function io(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=xd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Qt(o);if(s){const a=sa(i);return t.concat(i,i.visualViewport||[],so(o)?o:[],a&&n?io(a):[])}return t.concat(o,io(o,[],n))}function sa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function vd(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Sn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=ts(n)!==s||ts(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ia(e){return un(e)?e:e.contextElement}function Ar(e){const t=ia(e);if(!Sn(t))return wn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=vd(t);let i=(s?ts(n.width):n.width)/r,a=(s?ts(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Eb=wn(0);function wd(e){const t=Qt(e);return!oa()||!t.visualViewport?Eb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ib(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Qt(e)?!1:t}function nr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ia(e);let i=wn(1);t&&(r?un(r)&&(i=Ar(r)):i=Ar(e));const a=Ib(s,n,r)?wd(s):wn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,p=o.height/i.y;if(s){const m=Qt(s),f=r&&un(r)?Qt(r):r;let v=m,g=sa(v);for(;g&&r&&f!==v;){const x=Ar(g),y=g.getBoundingClientRect(),b=dn(g),C=y.left+(g.clientLeft+parseFloat(b.paddingLeft))*x.x,k=y.top+(g.clientTop+parseFloat(b.paddingTop))*x.y;l*=x.x,c*=x.y,d*=x.x,p*=x.y,l+=C,c+=k,v=Qt(g),g=sa(v)}}return os({width:d,height:p,x:l,y:c})}function ls(e,t){const n=as(e).scrollLeft;return t?t.left+n:nr(yn(e)).left+n}function bd(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ls(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Nb(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=yn(r),a=t?is(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=wn(1);const d=wn(0),p=Sn(r);if((p||!p&&!s)&&((Ir(r)!=="body"||so(i))&&(l=as(r)),Sn(r))){const f=nr(r);c=Ar(r),d.x=f.x+r.clientLeft,d.y=f.y+r.clientTop}const m=i&&!p&&!s?bd(i,l):wn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+m.x,y:n.y*c.y-l.scrollTop*c.y+d.y+m.y}}function Ab(e){return Array.from(e.getClientRects())}function Pb(e){const t=yn(e),n=as(e),r=e.ownerDocument.body,o=Zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ls(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const yd=25;function jb(e,t){const n=Qt(e),r=yn(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=oa();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=ls(r);if(c<=0){const d=r.ownerDocument,p=d.body,m=getComputedStyle(p),f=d.compatMode==="CSS1Compat"&&parseFloat(m.marginLeft)+parseFloat(m.marginRight)||0,v=Math.abs(r.clientWidth-p.clientWidth-f);v<=yd&&(s-=v)}else c<=yd&&(s+=c);return{width:s,height:i,x:a,y:l}}const _b=new Set(["absolute","fixed"]);function Rb(e,t){const n=nr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Sn(e)?Ar(e):wn(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 Sd(e,t,n){let r;if(t==="viewport")r=jb(e,n);else if(t==="document")r=Pb(yn(e));else if(un(t))r=Rb(t,n);else{const o=wd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return os(r)}function Cd(e,t){const n=$n(e);return n===t||!un(n)||Nr(n)?!1:dn(n).position==="fixed"||Cd(n,t)}function Mb(e,t){const n=t.get(e);if(n)return n;let r=io(e,[],!1).filter(a=>un(a)&&Ir(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?$n(e):e;for(;un(i)&&!Nr(i);){const a=dn(i),l=ra(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&_b.has(o.position)||so(i)&&!l&&Cd(e,i))?r=r.filter(d=>d!==i):o=a,i=$n(i)}return t.set(e,r),r}function Ob(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?is(t)?[]:Mb(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const p=Sd(t,d,o);return c.top=Zt(p.top,c.top),c.right=Ln(p.right,c.right),c.bottom=Ln(p.bottom,c.bottom),c.left=Zt(p.left,c.left),c},Sd(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Db(e){const{width:t,height:n}=vd(e);return{width:t,height:n}}function Lb(e,t,n){const r=Sn(t),o=yn(t),s=n==="fixed",i=nr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=wn(0);function c(){l.x=ls(o)}if(r||!r&&!s)if((Ir(t)!=="body"||so(o))&&(a=as(t)),r){const f=nr(t,!0,s,t);l.x=f.x+t.clientLeft,l.y=f.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?bd(o,a):wn(0),p=i.left+a.scrollLeft-l.x-d.x,m=i.top+a.scrollTop-l.y-d.y;return{x:p,y:m,width:i.width,height:i.height}}function aa(e){return dn(e).position==="static"}function Td(e,t){if(!Sn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return yn(e)===n&&(n=n.ownerDocument.body),n}function kd(e,t){const n=Qt(e);if(is(e))return n;if(!Sn(e)){let o=$n(e);for(;o&&!Nr(o);){if(un(o)&&!aa(o))return o;o=$n(o)}return n}let r=Td(e,t);for(;r&&wb(r)&&aa(r);)r=Td(r,t);return r&&Nr(r)&&aa(r)&&!ra(r)?n:r||Tb(e)||n}const $b=async function(e){const t=this.getOffsetParent||kd,n=this.getDimensions,r=await n(e.floating);return{reference:Lb(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Fb(e){return dn(e).direction==="rtl"}const Bb={convertOffsetParentRelativeRectToViewportRelativeRect:Nb,getDocumentElement:yn,getClippingRect:Ob,getOffsetParent:kd,getElementRects:$b,getClientRects:Ab,getDimensions:Db,getScale:Ar,isElement:un,isRTL:Fb};function Ed(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function zb(e,t){let n=null,r;const o=yn(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:p,width:m,height:f}=c;if(a||t(),!m||!f)return;const v=ns(p),g=ns(o.clientWidth-(d+m)),x=ns(o.clientHeight-(p+f)),y=ns(d),C={rootMargin:-v+"px "+-g+"px "+-x+"px "+-y+"px",threshold:Zt(0,Ln(1,l))||1};let k=!0;function S(T){const E=T[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Ed(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(S,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,C)}n.observe(e)}return i(!0),s}function Hb(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=ia(e),d=o||s?[...c?io(c):[],...io(t)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const p=c&&a?zb(c,n):null;let m=-1,f=null;i&&(f=new ResizeObserver(y=>{let[b]=y;b&&b.target===c&&f&&(f.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var C;(C=f)==null||C.observe(t)})),n()}),c&&!l&&f.observe(c),f.observe(t));let v,g=l?nr(e):null;l&&x();function x(){const y=nr(e);g&&!Ed(g,y)&&n(),g=y,v=requestAnimationFrame(x)}return n(),()=>{var y;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),p==null||p(),(y=f)==null||y.disconnect(),f=null,l&&cancelAnimationFrame(v)}}const Ub=pb,Wb=hb,Vb=ub,Kb=gb,qb=db,Id=cb,Gb=mb,Yb=(e,t,n)=>{const r=new Map,o={platform:Bb,...n},s={...o.platform,_c:r};return lb(e,t,{...o,platform:s})};var Xb=typeof document<"u",Jb=function(){},cs=Xb?w.useLayoutEffect:Jb;function us(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(!us(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)&&!us(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Nd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ad(e,t){const n=Nd(e);return Math.round(t*n)/n}function la(e){const t=h.useRef(e);return cs(()=>{t.current=e}),t}function Zb(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,p]=h.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,f]=h.useState(r);us(m,r)||f(r);const[v,g]=h.useState(null),[x,y]=h.useState(null),b=h.useCallback(j=>{j!==T.current&&(T.current=j,g(j))},[]),C=h.useCallback(j=>{j!==E.current&&(E.current=j,y(j))},[]),k=s||v,S=i||x,T=h.useRef(null),E=h.useRef(null),P=h.useRef(d),_=l!=null,$=la(l),L=la(o),F=la(c),G=h.useCallback(()=>{if(!T.current||!E.current)return;const j={placement:t,strategy:n,middleware:m};L.current&&(j.platform=L.current),Yb(T.current,E.current,j).then(I=>{const Y={...I,isPositioned:F.current!==!1};O.current&&!us(P.current,Y)&&(P.current=Y,Kr.flushSync(()=>{p(Y)}))})},[m,t,n,L,F]);cs(()=>{c===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(j=>({...j,isPositioned:!1})))},[c]);const O=h.useRef(!1);cs(()=>(O.current=!0,()=>{O.current=!1}),[]),cs(()=>{if(k&&(T.current=k),S&&(E.current=S),k&&S){if($.current)return $.current(k,S,G);G()}},[k,S,G,$,_]);const K=h.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:C}),[b,C]),q=h.useMemo(()=>({reference:k,floating:S}),[k,S]),H=h.useMemo(()=>{const j={position:n,left:0,top:0};if(!q.floating)return j;const I=Ad(q.floating,d.x),Y=Ad(q.floating,d.y);return a?{...j,transform:"translate("+I+"px, "+Y+"px)",...Nd(q.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:I,top:Y}},[n,a,q.floating,d.x,d.y]);return h.useMemo(()=>({...d,update:G,refs:K,elements:q,floatingStyles:H}),[d,G,K,q,H])}const Qb=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?Id({element:r.current,padding:o}).fn(n):{}:r?Id({element:r,padding:o}).fn(n):{}}}},ey=(e,t)=>({...Ub(e),options:[e,t]}),ty=(e,t)=>({...Wb(e),options:[e,t]}),ny=(e,t)=>({...Gb(e),options:[e,t]}),ry=(e,t)=>({...Vb(e),options:[e,t]}),oy=(e,t)=>({...Kb(e),options:[e,t]}),sy=(e,t)=>({...qb(e),options:[e,t]}),iy=(e,t)=>({...Qb(e),options:[e,t]});var ay="Arrow",Pd=h.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(fe.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"})})});Pd.displayName=ay;var ly=Pd;function jd(e){const[t,n]=h.useState(void 0);return It(()=>{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 ca="Popper",[_d,Pr]=cn(ca),[cy,Rd]=_d(ca),Md=e=>{const{__scopePopper:t,children:n}=e,[r,o]=h.useState(null);return u.jsx(cy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Md.displayName=ca;var Od="PopperAnchor",Dd=h.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Rd(Od,n),i=h.useRef(null),a=De(t,i),l=h.useRef(null);return h.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(fe.div,{...o,ref:a})});Dd.displayName=Od;var ua="PopperContent",[uy,dy]=_d(ua),Ld=h.forwardRef((e,t)=>{var N,M,U,Z,se,ae;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:p="partial",hideWhenDetached:m=!1,updatePositionStrategy:f="optimized",onPlaced:v,...g}=e,x=Rd(ua,n),[y,b]=h.useState(null),C=De(t,Ce=>b(Ce)),[k,S]=h.useState(null),T=jd(k),E=(T==null?void 0:T.width)??0,P=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),$=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(c)?c:[c],F=L.length>0,G={padding:$,boundary:L.filter(py),altBoundary:F},{refs:O,floatingStyles:K,placement:q,isPositioned:H,middlewareData:j}=Zb({strategy:"fixed",placement:_,whileElementsMounted:(...Ce)=>Hb(...Ce,{animationFrame:f==="always"}),elements:{reference:x.anchor},middleware:[ey({mainAxis:o+P,alignmentAxis:i}),l&&ty({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?ny():void 0,...G}),l&&ry({...G}),oy({...G,apply:({elements:Ce,rects:we,availableWidth:je,availableHeight:We})=>{const{width:Fe,height:Ye}=we.reference,He=Ce.floating.style;He.setProperty("--radix-popper-available-width",`${je}px`),He.setProperty("--radix-popper-available-height",`${We}px`),He.setProperty("--radix-popper-anchor-width",`${Fe}px`),He.setProperty("--radix-popper-anchor-height",`${Ye}px`)}}),k&&iy({element:k,padding:a}),hy({arrowWidth:E,arrowHeight:P}),m&&sy({strategy:"referenceHidden",...G})]}),[I,Y]=Bd(q),J=pt(v);It(()=>{H&&(J==null||J())},[H,J]);const D=(N=j.arrow)==null?void 0:N.x,V=(M=j.arrow)==null?void 0:M.y,R=((U=j.arrow)==null?void 0:U.centerOffset)!==0,[B,X]=h.useState();return It(()=>{y&&X(window.getComputedStyle(y).zIndex)},[y]),u.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...K,transform:H?K.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:B,"--radix-popper-transform-origin":[(Z=j.transformOrigin)==null?void 0:Z.x,(se=j.transformOrigin)==null?void 0:se.y].join(" "),...((ae=j.hide)==null?void 0:ae.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(uy,{scope:n,placedSide:I,onArrowChange:S,arrowX:D,arrowY:V,shouldHideArrow:R,children:u.jsx(fe.div,{"data-side":I,"data-align":Y,...g,ref:C,style:{...g.style,animation:H?void 0:"none"}})})})});Ld.displayName=ua;var $d="PopperArrow",fy={top:"bottom",right:"left",bottom:"top",left:"right"},Fd=h.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=dy($d,r),i=fy[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(ly,{...o,ref:n,style:{...o.style,display:"block"}})})});Fd.displayName=$d;function py(e){return e!==null}var hy=e=>({name:"transformOrigin",options:e,fn(t){var x,y,b;const{placement:n,rects:r,middlewareData:o}=t,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=Bd(n),p={start:"0%",center:"50%",end:"100%"}[d],m=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,f=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let v="",g="";return c==="bottom"?(v=i?p:`${m}px`,g=`${-l}px`):c==="top"?(v=i?p:`${m}px`,g=`${r.floating.height+l}px`):c==="right"?(v=`${-l}px`,g=i?p:`${f}px`):c==="left"&&(v=`${r.floating.width+l}px`,g=i?p:`${f}px`),{data:{x:v,y:g}}}});function Bd(e){const[t,n="center"]=e.split("-");return[t,n]}var da=Md,fa=Dd,pa=Ld,ha=Fd,my="Portal",ao=h.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=h.useState(!1);It(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Oo.createPortal(u.jsx(fe.div,{...r,ref:t}),i):null});ao.displayName=my;function gy(e,t){return h.useReducer((n,r)=>t[n][r]??n,e)}var Ut=e=>{const{present:t,children:n}=e,r=xy(t),o=typeof n=="function"?n({present:r.isPresent}):h.Children.only(n),s=De(r.ref,vy(o));return typeof n=="function"||r.isPresent?h.cloneElement(o,{ref:s}):null};Ut.displayName="Presence";function xy(e){const[t,n]=h.useState(),r=h.useRef(null),o=h.useRef(e),s=h.useRef("none"),i=e?"mounted":"unmounted",[a,l]=gy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return h.useEffect(()=>{const c=ds(r.current);s.current=a==="mounted"?c:"none"},[a]),It(()=>{const c=r.current,d=o.current;if(d!==e){const m=s.current,f=ds(c);e?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&m!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),It(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,p=f=>{const g=ds(r.current).includes(CSS.escape(f.animationName));if(f.target===t&&g&&(l("ANIMATION_END"),!o.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},m=f=>{f.target===t&&(s.current=ds(r.current))};return t.addEventListener("animationstart",m),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",m),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:h.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function ds(e){return(e==null?void 0:e.animationName)||"none"}function vy(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 ma="rovingFocusGroup.onEntryFocus",wy={bubbles:!1,cancelable:!0},lo="RovingFocusGroup",[ga,zd,by]=Zo(lo),[yy,Hd]=cn(lo,[by]),[Sy,Cy]=yy(lo),Ud=h.forwardRef((e,t)=>u.jsx(ga.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(ga.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Ty,{...e,ref:t})})}));Ud.displayName=lo;var Ty=h.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...p}=e,m=h.useRef(null),f=De(t,m),v=Qo(s),[g,x]=On({prop:i,defaultProp:a??null,onChange:l,caller:lo}),[y,b]=h.useState(!1),C=pt(c),k=zd(n),S=h.useRef(!1),[T,E]=h.useState(0);return h.useEffect(()=>{const P=m.current;if(P)return P.addEventListener(ma,C),()=>P.removeEventListener(ma,C)},[C]),u.jsx(Sy,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:g,onItemFocus:h.useCallback(P=>x(P),[x]),onItemShiftTab:h.useCallback(()=>b(!0),[]),onFocusableItemAdd:h.useCallback(()=>E(P=>P+1),[]),onFocusableItemRemove:h.useCallback(()=>E(P=>P-1),[]),children:u.jsx(fe.div,{tabIndex:y||T===0?-1:0,"data-orientation":r,...p,ref:f,style:{outline:"none",...e.style},onMouseDown:ie(e.onMouseDown,()=>{S.current=!0}),onFocus:ie(e.onFocus,P=>{const _=!S.current;if(P.target===P.currentTarget&&_&&!y){const $=new CustomEvent(ma,wy);if(P.currentTarget.dispatchEvent($),!$.defaultPrevented){const L=k().filter(q=>q.focusable),F=L.find(q=>q.active),G=L.find(q=>q.id===g),K=[F,G,...L].filter(Boolean).map(q=>q.ref.current);Kd(K,d)}}S.current=!1}),onBlur:ie(e.onBlur,()=>b(!1))})})}),Wd="RovingFocusGroupItem",Vd=h.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=_t(),c=s||l,d=Cy(Wd,n),p=d.currentTabStopId===c,m=zd(n),{onFocusableItemAdd:f,onFocusableItemRemove:v,currentTabStopId:g}=d;return h.useEffect(()=>{if(r)return f(),()=>v()},[r,f,v]),u.jsx(ga.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(fe.span,{tabIndex:p?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ie(e.onMouseDown,x=>{r?d.onItemFocus(c):x.preventDefault()}),onFocus:ie(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ie(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){d.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const y=Iy(x,d.orientation,d.dir);if(y!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let C=m().filter(k=>k.focusable).map(k=>k.ref.current);if(y==="last")C.reverse();else if(y==="prev"||y==="next"){y==="prev"&&C.reverse();const k=C.indexOf(x.currentTarget);C=d.loop?Ny(C,k+1):C.slice(k+1)}setTimeout(()=>Kd(C))}}),children:typeof i=="function"?i({isCurrentTabStop:p,hasTabStop:g!=null}):i})})});Vd.displayName=Wd;var ky={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ey(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Iy(e,t,n){const r=Ey(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ky[r]}function Kd(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ny(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ay=Ud,Py=Vd,jy=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},jr=new WeakMap,fs=new WeakMap,ps={},xa=0,qd=function(e){return e&&(e.host||qd(e.parentNode))},_y=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=qd(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})},Ry=function(e,t,n,r){var o=_y(t,Array.isArray(e)?e:[e]);ps[n]||(ps[n]=new WeakMap);var s=ps[n],i=[],a=new Set,l=new Set(o),c=function(p){!p||a.has(p)||(a.add(p),c(p.parentNode))};o.forEach(c);var d=function(p){!p||l.has(p)||Array.prototype.forEach.call(p.children,function(m){if(a.has(m))d(m);else try{var f=m.getAttribute(r),v=f!==null&&f!=="false",g=(jr.get(m)||0)+1,x=(s.get(m)||0)+1;jr.set(m,g),s.set(m,x),i.push(m),g===1&&v&&fs.set(m,!0),x===1&&m.setAttribute(n,"true"),v||m.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",m,y)}})};return d(t),a.clear(),xa++,function(){i.forEach(function(p){var m=jr.get(p)-1,f=s.get(p)-1;jr.set(p,m),s.set(p,f),m||(fs.has(p)||p.removeAttribute(r),fs.delete(p)),f||p.removeAttribute(n)}),xa--,xa||(jr=new WeakMap,jr=new WeakMap,fs=new WeakMap,ps={})}},va=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=jy(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Ry(r,o,n,"aria-hidden")):function(){return null}},Cn=function(){return Cn=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},Cn.apply(this,arguments)};function Gd(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 My(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 hs="right-scroll-bar-position",ms="width-before-scroll-bar",Oy="with-scroll-bars-hidden",Dy="--removed-body-scroll-bar-size";function wa(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Ly(e,t){var n=w.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var $y=typeof window<"u"?h.useLayoutEffect:h.useEffect,Yd=new WeakMap;function Fy(e,t){var n=Ly(null,function(r){return e.forEach(function(o){return wa(o,r)})});return $y(function(){var r=Yd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||wa(a,null)}),s.forEach(function(a){o.has(a)||wa(a,i)})}Yd.set(n,e)},[e]),n}function By(e){return e}function zy(e,t){t===void 0&&(t=By);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 Hy(e){e===void 0&&(e={});var t=zy(null);return t.options=Cn({async:!0,ssr:!1},e),t}var Xd=function(e){var t=e.sideCar,n=Gd(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 h.createElement(r,Cn({},n))};Xd.isSideCarExport=!0;function Uy(e,t){return e.useMedium(t),Xd}var Jd=Hy(),ba=function(){},gs=h.forwardRef(function(e,t){var n=h.useRef(null),r=h.useState({onScrollCapture:ba,onWheelCapture:ba,onTouchMoveCapture:ba}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,p=e.shards,m=e.sideCar,f=e.noRelative,v=e.noIsolation,g=e.inert,x=e.allowPinchZoom,y=e.as,b=y===void 0?"div":y,C=e.gapMode,k=Gd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=m,T=Fy([n,t]),E=Cn(Cn({},k),o);return h.createElement(h.Fragment,null,d&&h.createElement(S,{sideCar:Jd,removeScrollBar:c,shards:p,noRelative:f,noIsolation:v,inert:g,setCallbacks:s,allowPinchZoom:!!x,lockRef:n,gapMode:C}),i?h.cloneElement(h.Children.only(a),Cn(Cn({},E),{ref:T})):h.createElement(b,Cn({},E,{className:l,ref:T}),a))});gs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},gs.classNames={fullWidth:ms,zeroRight:hs};var Wy=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Vy(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Wy();return t&&e.setAttribute("nonce",t),e}function Ky(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function qy(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Gy=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Vy())&&(Ky(t,n),qy(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Yy=function(){var e=Gy();return function(t,n){h.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Zd=function(){var e=Yy(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Xy={left:0,top:0,right:0,gap:0},ya=function(e){return parseInt(e||"",10)||0},Jy=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[ya(n),ya(r),ya(o)]},Zy=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Xy;var t=Jy(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])}},Qy=Zd(),_r="data-scroll-locked",e0=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
|
+
`)):t(e)}function Cu(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Bi(e){if(e.role==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(i=>{switch(i.type){case"text":return`t:${i.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"",r="checkpointId"in e&&e.checkpointId?`cp:${e.checkpointId}`:"",o="checkpointNs"in e&&e.checkpointNs?`ns:${e.checkpointNs}`:"",s=[r,o].filter(Boolean).join("|");return`${e.id}:${t}:${n}${s?`:${s}`:""}`}function Tu(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function ku(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function Eu({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=Tu(n),i=o?`data:${s};base64,${e}`:t,a=ku(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function Iu(e){var o,s;const t=((o=e.content_base64)==null?void 0:o.trim())||void 0,n=((s=e.url)==null?void 0:s.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return Eu({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}function zi(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}function Sr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim(),n=Qn(t);return n!==null?Sr(n):t}if(Array.isArray(e))return e.map(t=>Sr(t));if(typeof e=="object"){const t=e.value;if(t!==void 0)return Sr(t)}return e}function Nu(e){const t=Sr(e.value);return t===e.value?e:{...e,value:t}}const lw={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,messagesStreamMeta:{},pendingInterrupt:null};function cw(e,t){var n;switch(t.type){case"reset":return{messages:Li(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,pendingInterrupt:null,messagesStreamMeta:{}};case"user_message":{const{message:r,editingMessageId:o}=t.payload;if(o){const s=e.messages.findIndex(i=>i.id===o);if(s>=0){const i=e.messages.slice(0,s);return{...e,messages:[...i,r],assemblingId:null}}}return{...e,messages:[...e.messages,r],assemblingId:null}}case"seed":{const r=Li(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=Li(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(a=>a.id)),s=r.filter(a=>!o.has(a.id));if(!s.length)return e;const i=[...s,...e.messages];return{...e,messages:i}}case"event":return Au(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Au(o,s),e):e}default:return e}}function uw(e=[]){const[t,n]=w.useReducer(cw,{...lw,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,p)=>n({type:"seed",payload:{messages:d,...p??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:(d,p)=>n({type:"user_message",payload:{message:d,editingMessageId:p}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Au(e,t){var n,r,o;if(t.type==="message.start"&&t.role==="assistant"){const s=t.id,i=mu(t.model);if(e.messages.some(c=>c.id===s)){const c=e.messagesStreamMeta??{},d={...c,[s]:c[s]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:s,messagesStreamMeta:d}}const l={id:s,role:"assistant",name:i||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:s,messages:[...e.messages,l]}}if(t.type==="tool.start")return fw(e,t);if(t.type==="tool.progress")return pw(e,t);if(t.type==="tool.end")return hw(e,t);if(t.type==="message.delta"){const s=e.assemblingId??fu(e.messages);if(!s)return e;const i=e.messages,a=i.findIndex(S=>S.id===s&&S.role==="assistant");if(a===-1)return e;const l=i[a],c=e.messagesStreamMeta,d=c??{},p=d[s],m=p??{lastSeq:null,lastText:pu(l.content)},f=t.seq??null;if(f!==null&&typeof f=="number"&&typeof m.lastSeq=="number"&&f<=m.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:f,lastSeq:m.lastSeq}),e;const{newParts:v,newMeta:g,changed:x}=hu(l.content,t.delta,m,f);if(!x)return e;const y={...l,content:v},b=to(i,a,y),C=!p||p.lastSeq!==g.lastSeq||p.lastText!==g.lastText,k=C?{...d,[s]:g}:c;return C?{...e,messages:b,messagesStreamMeta:k}:{...e,messages:b}}if(t.type==="message.end"){const s=e.assemblingId??fu(e.messages);if(!s)return{...e,assemblingId:null};const i=e.messages,a=i.findIndex(l=>l.id===s&&l.role==="assistant");if(a>=0){const l=i[a];if(!((n=l.content)==null?void 0:n.some(d=>{var p;return(d==null?void 0:d.type)==="text"&&((p=d.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:l.id,contentTypes:(r=l.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=l.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const d=[...i.slice(0,a),...i.slice(a+1)];return{...e,assemblingId:null,messages:d}}}return{...e,assemblingId:null}}if(t.type==="checkpoint"){const s=t.checkpointNs??e.lastCheckpointNs??null,i=rw(e.messages,t.checkpointId,s);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:s,messages:i}}if(t.type==="error"){const s={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,s]}}if(t.type==="state_history"){const s=Yn(t),i=s.interrupt,a=s.latest,l=i===null?ew(e.messages):e.messages;return{...e,messages:l,pendingInterrupt:i,lastCheckpointId:(a==null?void 0:a.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(a==null?void 0:a.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function Hi(e){return e.call_id??e.id??null}function Pu(e){return e.id??e.call_id??`tool-${Date.now()}-${Math.random().toString(16).slice(2)}`}function ju(e,t,n,r){const o=t??`call-${Date.now()}-${Math.random().toString(16).slice(2)}`;return{id:e,role:"tool",name:n??void 0,content:[{type:"tool_call",id:o,name:n??"tool",args:r??{}}],createdAt:new Date().toISOString(),additionalKwargs:{toolCallId:o,toolName:n??void 0,toolStreaming:!0,toolProgress:[]}}}function Ui(e,t){if(!t)return-1;for(let n=0;n<e.length;n+=1){const r=e[n];if(r.role!=="tool")continue;const o=r.additionalKwargs??{};if(typeof o.toolCallId=="string"&&o.toolCallId===t||Jo(r).toolCallId===t)return n}return-1}function dw(e){if(e==null)return[];const t=tr(e);if(typeof t=="string"&&t.trim())return[{type:"text",text:t}];const n=er(t??e);return n?[{type:"text",text:n}]:[]}function _u(e,t){const n=e.additionalKwargs??{},r=Array.isArray(n.toolProgress)?[...n.toolProgress]:[],o={...n,toolProgress:[...r,t]};return{...e,additionalKwargs:o}}function fw(e,t){const n=Hi(t),r=Ui(e.messages,n),o=t.name??t.tool??void 0,s=Pu(t);if(r>=0){const a=e.messages[r],c={...a.additionalKwargs??{},toolStreaming:!0,toolProgress:[]},d={...a,name:o??a.name,additionalKwargs:c};return{...e,messages:to(e.messages,r,d)}}const i=ju(s,n,o,t.args);return{...e,messages:[...e.messages,i]}}function pw(e,t){const n=Hi(t);if(!n)return e;const r=Ui(e.messages,n);if(r===-1)return e;const o={type:t.type,content:typeof t.content=="string"?t.content:void 0,seq:t.seq??null,timestamp:new Date().toISOString()},s=t.metadata;s&&(o.metadata=s);const i=t.idx;typeof i=="number"&&(o.idx=i);const a=_u(e.messages[r],o);return{...e,messages:to(e.messages,r,a)}}function hw(e,t){const n=Hi(t),r=Pu(t);let o=e.messages,s=Ui(o,n);if(s===-1){const v=t.name??t.tool??void 0;o=[...o,ju(r,n,v,{})],s=o.length-1}const i=o[s],a=t.output??t.error??null,l=dw(a),c=[...i.content,...l],d={type:t.type,content:typeof t.output=="string"?t.output:void 0,seq:t.seq??null,timestamp:new Date().toISOString()};t.artifact&&(d.artifact=t.artifact);const p=_u(i,d),m=t.artifact??i.artifact,f={...p,name:t.name??t.tool??i.name,content:c,artifact:m,additionalKwargs:{...p.additionalKwargs??{},toolStreaming:!1}};return{...e,messages:to(o,s,f)}}function Ru({api:e,seed:t,onError:n,currentThreadId:r,initialThreadId:o=null,initialCheckpointId:s=null,initialCheckpointNs:i=null,autoLoadInitial:a=!0,isStreaming:l,getMessages:c}){const[d,p]=w.useState(null),f=w.useMemo(()=>Yn(d),[d]).checkpoints,v=ac(f),g=v.timeline,[x,y]=w.useState(!1),[b,C]=w.useState(!1),[k,S]=w.useState(null),T=w.useRef(r),E=w.useRef(null),P=w.useRef(null),_=w.useRef(null),$=w.useRef(null),L=w.useRef(null),F=w.useRef(new Map),G=w.useRef(null);w.useEffect(()=>{T.current=r},[r]);const O=w.useCallback(async R=>{var X,N;if(!R.threadId)return;const B=R.threadId;(X=R.onStart)==null||X.call(R),R.setLoading(!0);try{await R.action(B)}catch(M){if(!Jc(M)&&T.current===B){const Z=String(M);(N=R.handleError)==null||N.call(R,Z),n==null||n(Z)}throw M}finally{R.setLoading(!1)}},[n]),K=w.useCallback(async(R,B)=>{var Z;if(!R)return;const X=`${R}:${B??"latest"}`,N=F.current.get(X);if(N)return N;(Z=G.current)==null||Z.abort();const M=new AbortController;G.current=M;const U=O({threadId:R,setLoading:y,onStart:()=>S(null),handleError:se=>S(se),action:async se=>{const ae=await e.getStateHistory({threadId:se,checkpointId:B??void 0,signal:M.signal});if(T.current!==se){console.log(`[useThreadHistoryState] Thread changed during load (was ${se}, now ${T.current}), discarding stale data`);return}const{checkpoints:Ce}=Yn(ae),we=Ce.find(je=>je.messages&&je.messages.length>0)??(B?Ce.find(je=>je.checkpointId===B):null)??Ce[0];t((we==null?void 0:we.messages)??[],{checkpointId:(we==null?void 0:we.checkpointId)??null,checkpointNs:(we==null?void 0:we.checkpointNs)??null,pendingInterrupt:(we==null?void 0:we.interrupt)??null}),p(ae)}});F.current.set(X,U);try{await U}finally{F.current.delete(X),G.current===M&&(G.current=null)}return T.current===R&&(L.current=X),U},[e,t,O]),q=w.useCallback(async(R,B)=>{$.current=R;try{await K(R,B)}catch(X){if(!Jc(X))throw X}finally{$.current===R&&($.current=null)}},[K]),H=w.useCallback(R=>{P.current=R},[]),j=w.useCallback(R=>{_.current=R},[]),I=w.useCallback(R=>{const B=R.threadId??T.current;if(!B||T.current&&T.current!==B)return;const{checkpoints:X}=Yn(R);if(!X.length)return;const N=X.find(U=>U.messages&&U.messages.length>0)??X.find(U=>!!U.checkpointId)??X[0],M=_.current===B;!l&&!M&&t((N==null?void 0:N.messages)??[],{checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null,pendingInterrupt:(N==null?void 0:N.interrupt)??null}),p(R),L.current=`${B}:latest`,P.current=null,_.current===B&&(_.current=null)},[t,l]),Y=w.useCallback(async(R,B)=>{const X=T.current;await O({threadId:X,setLoading:C,action:async N=>{const M=await e.getStateHistory({threadId:N,checkpointId:R,checkpointNs:B??void 0});if(T.current!==N)return;const{checkpoints:U}=Yn(M),Z=U.find(se=>se.checkpointId===R&&(B?se.checkpointNs===B:!0));if(!Z){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:R,checkpointNs:B});return}p(M),t(Z.messages??[],{checkpointId:Z.checkpointId??null,checkpointNs:Z.checkpointNs??null})}}).catch(()=>{})},[e,t,O]),J=w.useCallback((R,B)=>{t(c(),{checkpointId:R??null,checkpointNs:B??null})},[c,t]),D=w.useCallback(async()=>{T.current&&await q(T.current)},[q]);w.useEffect(()=>{if(!a||!r||x||l)return;if(P.current===r){P.current=null,E.current=r;return}if(_.current===r){E.current=r;return}if($.current===r){$.current=null,E.current=r;return}if(E.current===r)return;E.current=r;let R;const B=`${r}:latest`;L.current!==B&&q(r,R)},[a,r,s,i,o,x,l,q]);const V=w.useCallback(()=>{p(null),y(!1),C(!1),S(null),P.current=null,_.current=null,E.current=null,L.current=null,$.current=null},[]);return{threadCheckpoints:f,threadTimeline:g,checkpointIndex:v,isLoadingThread:x,isLoadingCheckpoint:b,threadStateError:k,loadThread:q,navigateToCheckpoint:Y,setCurrentCheckpointId:J,returnToLatest:D,handleStateHistoryEvent:I,markSkipNextLoad:H,markStreamPendingThread:j,resetHistoryState:V}}const Mu=w.createContext(null),Ou=w.createContext(null);function no(){const e=w.useContext(Mu);if(!e)throw new Error("useThreadState must be used within a ThreadStateProvider");return e}function Du(){const e=w.useContext(Ou);if(!e)throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");return e}function Lu({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,isStreaming:s,onError:i}){const{api:a}=eo(),{currentThreadId:l}=br(),{state:c,seed:d,pushUser:p,onEvent:m}=uw(),{threadCheckpoints:f,threadTimeline:v,checkpointIndex:g,isLoadingThread:x,isLoadingCheckpoint:y,threadStateError:b,loadThread:C,navigateToCheckpoint:k,setCurrentCheckpointId:S,returnToLatest:T,handleStateHistoryEvent:E,markSkipNextLoad:P,markStreamPendingThread:_,resetHistoryState:$}=Ru({api:a,seed:d,onError:i,currentThreadId:l,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:s,getMessages:w.useCallback(()=>c.messages,[c.messages])}),[L,F]=w.useState(()=>async()=>{throw new Error("clearThread is not ready")}),[G,O]=w.useState(()=>async()=>{throw new Error("respondToInterrupt is not ready")});w.useEffect(()=>{l||(d([],{}),$())},[l,d,$]);const K=w.useCallback(Y=>F(()=>Y),[]),q=w.useCallback(Y=>O(()=>Y),[]),H=w.useMemo(()=>({assemblingMessageId:c.assemblingId??null}),[c.assemblingId]),j=w.useMemo(()=>({threadId:l,messages:c.messages,interrupt:c.pendingInterrupt,checkpoint:{id:c.lastCheckpointId??null,namespace:c.lastCheckpointNs??null},checkpoints:f,checkpointIndex:g,timelineCheckpoints:v,metadata:H,isLoading:x,isLoadingCheckpoint:y,error:b,clearState:L,navigateToCheckpoint:k,setCurrentCheckpointId:S,returnToLatest:T,loadThread:C,clearThread:L,respondToInterrupt:G,messagePreviews:g.messagePreviews,handleStateHistoryEvent:E,markSkipNextLoad:P,markStreamPendingThread:_,resetHistoryState:$,pushUser:p,onEvent:m}),[l,c,f,v,g,H,x,y,b,L,k,S,T,C,G,g.messagePreviews,E,P,_,$,p,m]),I=w.useMemo(()=>({registerClearThread:K,registerRespondToInterrupt:q}),[K,q]);return u.jsx(Ou.Provider,{value:I,children:u.jsx(Mu.Provider,{value:j,children:e})})}function $u(e,t){if(!e)return null;const n=_n(e);if(!n)return null;const r=_n(n.configurable)??n;return Rn(r,t)??null}function mw(e){const t=$u(e,["checkpoint_id","checkpointId"]);if(!t)return null;const n=$u(e,["checkpoint_ns","checkpointNs"]);return{checkpointId:t,checkpointNs:n}}function gw(e,t){const n=typeof e.step=="number"?e.step:Number.POSITIVE_INFINITY,r=typeof t.step=="number"?t.step:Number.POSITIVE_INFINITY;if(n!==r)return n-r;const o=e.createdAt?Date.parse(e.createdAt):0,s=t.createdAt?Date.parse(t.createdAt):0;return o-s}function xw(e,t){const n=[...e].sort(gw);for(const r of n){if(r.messageId!==t)continue;const o=mw(r.parentConfig);if(!o)throw new Error(`Parent checkpoint info missing for message ${t}`);return o}throw new Error(`Message ${t} not found in timeline`)}const Fu=w.createContext(null),Bu=w.createContext(!1);function vw({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l,onToolEnd:c}){const{api:d,baseUrl:p}=eo(),m=w.useMemo(()=>vn(p),[p]),{stream:f,stop:v,isStreaming:g,error:x,setToken:y}=ow({baseUrl:m}),[b,C]=w.useState(!1);return w.useEffect(()=>{C(g)},[g]),u.jsx(vu,{initialThreadId:t,onError:s,onThreadChange:a,children:u.jsx(Lu,{initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,onError:s,isStreaming:b,children:u.jsx(Bu.Provider,{value:!0,children:u.jsx(ww,{api:d,streamApi:{stream:f,stop:v,isStreaming:g,error:x,setToken:y},onError:s,onAuthError:i,onConnectionError:l,onToolEnd:c,children:e})})})})}function ww({children:e,api:t,streamApi:n,onError:r,onAuthError:o,onConnectionError:s,onToolEnd:i}){const{stream:a,stop:l,isStreaming:c,error:d,setToken:p}=n,{setCurrentThreadId:m,currentThreadIdRef:f,addThreadFromEvent:v}=br(),{checkpoint:g,timelineCheckpoints:x,handleStateHistoryEvent:y,markSkipNextLoad:b,markStreamPendingThread:C,resetHistoryState:k,pushUser:S,onEvent:T}=no(),{registerClearThread:E,registerRespondToInterrupt:P}=Du(),_=w.useCallback(H=>{v(H),f.current!==H.threadId&&((H.created??!f.current)&&b(H.threadId),C(H.threadId),m(H.threadId))},[v,b,C,m,f]),$=w.useCallback(H=>{H.type==="thread_info"?_(H):H.type==="state_history"?y(H):H.type==="tool.end"?i==null||i(H):T(H)},[_,y,T,i]),L=w.useCallback(H=>{a(H,$,{onError:j=>{console.error("[StreamingProvider] Stream error:",j),r==null||r(j)},onAuthError:j=>{console.error("[StreamingProvider] Auth error:",j),o==null||o(j)},onConnectionError:j=>{console.error("[StreamingProvider] Connection error:",j),s==null||s(j)}})},[a,$,r,o,s]),F=w.useRef(g);w.useEffect(()=>{F.current=g},[g]);const G=w.useCallback(async(H,j,I)=>{const Y=f.current;if(!Y)throw new Error("No active thread to handle interrupt");const J=H?j??!0:!1,D=F.current,V={threadId:Y,checkpointId:D.id??void 0,checkpointNs:D.namespace??void 0,command:{kind:"resume",value:J},payload:I==null?void 0:I.payload,config:I==null?void 0:I.config,nodeFilter:I==null?void 0:I.nodeFilter,branchLabel:I==null?void 0:I.branchLabel,active_agent:I==null?void 0:I.active_agent,timelineCheckpoints:I==null?void 0:I.timelineCheckpoints};L(V)},[f,L]);w.useEffect(()=>{P(G)},[G,P]);const O=w.useCallback(async()=>{l(),k(),m(null)},[k,m,l]);w.useEffect(()=>{E(O)},[O,E]);const K=w.useCallback(async(H,j)=>{let I=f.current;const Y=(H==null?void 0:H.text)??"",J=(H==null?void 0:H.attachments)??[],D=(Y==null?void 0:Y.trim())??"",V={...(H==null?void 0:H.payload)??{}},R=Array.isArray(V.messages)?V.messages:void 0;R&&delete V.messages;const B=!!(R&&R.length);if(!I&&!D&&J.length===0&&!B)return;if(!I){const Ye=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),He=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);I=`${Ye}${He}`,b(I),m(I)}const{contentParts:X,filesInfo:N}=await uu(J),M=[...X];D&&M.push({type:"text",text:Y});const U=j==null?void 0:j.originalMessageId,Z=!!(j!=null&&j.edit&&U),se=!B&&M.length>0;let ae=null;se&&(ae={id:Z?U:`msg-${Date.now()}`,role:"user",content:M,createdAt:new Date().toISOString()},Z?S(ae,U):S(ae));const Ce=B?R:ae?[ae]:[],we={...V,...N.length?{files_info:N}:{}};Ce.length?we.messages=Ce:"messages"in we||(we.messages=[]);let je=(j==null?void 0:j.checkpointId)??g.id??void 0,We=(j==null?void 0:j.checkpointNs)??g.namespace??void 0;if(Z&&U){const Ye=xw(x,U);je=Ye.checkpointId,We=Ye.checkpointNs??void 0}const Fe={threadId:I,payload:we,checkpointId:je,checkpointNs:We,edit:!!(j!=null&&j.edit)};L(Fe)},[g,f,b,S,L,x]),q=w.useMemo(()=>({isStreaming:c,error:d,connectionState:c?"connected":"idle",submit:K,send:K,stop:l,setAuthToken:p}),[c,d,K,l,p]);return u.jsx(Fu.Provider,{value:q,children:e})}function Wi(){const e=w.useContext(Fu);if(!e)throw new Error("useStream must be used within StreamingProvider");return e}function bw(){return w.useContext(Bu)}function zu(e){return typeof e=="object"&&e!==null}function yw(e,t){if(Object.is(e,t))return!0;if(!zu(e)||!zu(t))return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}function Hu(e){const t=w.useRef(e),n=w.useRef(e);return yw(t.current,e)||(t.current=e,n.current=e),n.current}function Cr({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:c,onToolEnd:d}){const p=Hu(t),m=ro(a),f=ro(l),v=ro(i),g=ro(c),x=ro(d),y=w.useMemo(()=>({initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:m,onAuthError:f,onConnectionError:v,onThreadChange:g,onToolEnd:x}),[n,r,o,s,m,f,v,g,x]);return u.jsx(lu,{apiConfig:p,children:u.jsx(vw,{...y,children:e})})}function ro(e){const t=w.useRef(e);return w.useEffect(()=>{t.current=e},[e]),w.useCallback((...n)=>{const r=t.current;if(r)return r(...n)},[])}function Tr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function Sw(e){if(typeof e!="string")return;const t=e.trim();if(t)return vn(t)}function Uu(){const e=[Tr("__API_BASE_URL__"),Tr("__CHAT_API_BASE_URL__"),Tr("__CHAT_API_URL__")];for(const t of e){const n=Sw(t);if(n)return n}}function Wu(){const e=[Tr("__API_AUTH_TOKEN__"),Tr("__CHAT_API_KEY__"),Tr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Vu(...e){for(const t of e)if(typeof t=="string"&&t.trim())return vn(t);return vn()}function Ku(){const e={},t=Uu(),n=Wu();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function qu(){const e=Ku(),t=Nn.getAuthToken(),n=Uu();return{apiBaseUrl:Vu(e.baseUrl,Nn.baseUrl,n),apiKey:t||e.apiKey||Wu()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Vi="chat-settings";function Gu(){try{const e=localStorage.getItem(Vi);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function Yu(e){try{const t={...e,apiBaseUrl:vn(e.apiBaseUrl)};localStorage.setItem(Vi,JSON.stringify(t)),t.apiKey&&Nn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function Cw(){const e=qu(),t=Gu(),n=Nn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Vu(Nn.baseUrl,r,e.apiBaseUrl)}}function Tw(e){Nn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),Yu(e)}function re(...e){return hx.twMerge(px.clsx(e))}const kw=Vr.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"}}),Je=h.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yt.Slot:"button";return u.jsx(i,{className:re(kw({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";function ie(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function Xu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Mn(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Xu(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():Xu(e[o],null)}}}}function De(...e){return h.useCallback(Mn(...e),e)}function Ew(e,t){const n=h.createContext(t),r=s=>{const{children:i,...a}=s,l=h.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=h.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 cn(e,t=[]){let n=[];function r(s,i){const a=h.createContext(i),l=n.length;n=[...n,i];const c=p=>{var y;const{scope:m,children:f,...v}=p,g=((y=m==null?void 0:m[e])==null?void 0:y[l])||a,x=h.useMemo(()=>v,Object.values(v));return u.jsx(g.Provider,{value:x,children:f})};c.displayName=s+"Provider";function d(p,m){var g;const f=((g=m==null?void 0:m[e])==null?void 0:g[l])||a,v=h.useContext(f);if(v)return v;if(i!==void 0)return i;throw new Error(`\`${p}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>h.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return h.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Iw(o,...t)]}function Iw(...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 p=l(s)[`__scope${c}`];return{...a,...p}},{});return h.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var It=globalThis!=null&&globalThis.document?h.useLayoutEffect:()=>{},Nw=h[" useInsertionEffect ".trim().toString()]||It;function On({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Aw({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=h.useRef(e!==void 0);h.useEffect(()=>{const p=d.current;p!==a&&console.warn(`${r} is changing from ${p?"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=h.useCallback(d=>{var p;if(a){const m=Pw(d)?d(e):d;m!==e&&((p=i.current)==null||p.call(i,m))}else s(d)},[a,e,s,i]);return[l,c]}function Aw({defaultProp:e,onChange:t}){const[n,r]=h.useState(e),o=h.useRef(n),s=h.useRef(t);return Nw(()=>{s.current=t},[t]),h.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Pw(e){return typeof e=="function"}var jw=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],fe=jw.reduce((e,t)=>{const n=Yt.createSlot(`Primitive.${t}`),r=h.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 Ki(e,t){e&&Kr.flushSync(()=>e.dispatchEvent(t))}function Zo(e){const t=e+"CollectionProvider",[n,r]=cn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:x,children:y}=g,b=w.useRef(null),C=w.useRef(new Map).current;return u.jsx(o,{scope:x,itemMap:C,collectionRef:b,children:y})};i.displayName=t;const a=e+"CollectionSlot",l=Yt.createSlot(a),c=w.forwardRef((g,x)=>{const{scope:y,children:b}=g,C=s(a,y),k=De(x,C.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",p="data-radix-collection-item",m=Yt.createSlot(d),f=w.forwardRef((g,x)=>{const{scope:y,children:b,...C}=g,k=w.useRef(null),S=De(x,k),T=s(d,y);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...C}),()=>void T.itemMap.delete(k))),u.jsx(m,{[p]:"",ref:S,children:b})});f.displayName=d;function v(g){const x=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=x.collectionRef.current;if(!b)return[];const C=Array.from(b.querySelectorAll(`[${p}]`));return Array.from(x.itemMap.values()).sort((T,E)=>C.indexOf(T.ref.current)-C.indexOf(E.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:i,Slot:c,ItemSlot:f},v,r]}var _w=h.createContext(void 0);function Qo(e){const t=h.useContext(_w);return e||t||"ltr"}function pt(e){const t=h.useRef(e);return h.useEffect(()=>{t.current=e}),h.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Rw(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e);h.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 Mw="DismissableLayer",qi="dismissableLayer.update",Ow="dismissableLayer.pointerDownOutside",Dw="dismissableLayer.focusOutside",Ju,Zu=h.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),kr=h.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=h.useContext(Zu),[d,p]=h.useState(null),m=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=h.useState({}),v=De(t,E=>p(E)),g=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=g.indexOf(x),b=d?g.indexOf(d):-1,C=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=y,S=$w(E=>{const P=E.target,_=[...c.branches].some($=>$.contains(P));!k||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},m),T=Fw(E=>{const P=E.target;[...c.branches].some($=>$.contains(P))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},m);return Rw(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},m),h.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(Ju=m.body.style.pointerEvents,m.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),ed(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(m.body.style.pointerEvents=Ju)}},[d,m,n,c]),h.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),ed())},[d,c]),h.useEffect(()=>{const E=()=>f({});return document.addEventListener(qi,E),()=>document.removeEventListener(qi,E)},[]),u.jsx(fe.div,{...l,ref:v,style:{pointerEvents:C?k?"auto":"none":void 0,...e.style},onFocusCapture:ie(e.onFocusCapture,T.onFocusCapture),onBlurCapture:ie(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:ie(e.onPointerDownCapture,S.onPointerDownCapture)})});kr.displayName=Mw;var Lw="DismissableLayerBranch",Qu=h.forwardRef((e,t)=>{const n=h.useContext(Zu),r=h.useRef(null),o=De(t,r);return h.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(fe.div,{...e,ref:o})});Qu.displayName=Lw;function $w(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e),r=h.useRef(!1),o=h.useRef(()=>{});return h.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){td(Ow,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 Fw(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e),r=h.useRef(!1);return h.useEffect(()=>{const o=s=>{s.target&&!r.current&&td(Dw,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 ed(){const e=new CustomEvent(qi);document.dispatchEvent(e)}function td(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?Ki(o,s):o.dispatchEvent(s)}var Bw=kr,zw=Qu,Gi=0;function Yi(){h.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??nd()),document.body.insertAdjacentElement("beforeend",e[1]??nd()),Gi++,()=>{Gi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Gi--}},[])}function nd(){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 Xi="focusScope.autoFocusOnMount",Ji="focusScope.autoFocusOnUnmount",rd={bubbles:!1,cancelable:!0},Hw="FocusScope",es=h.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=h.useState(null),c=pt(o),d=pt(s),p=h.useRef(null),m=De(t,g=>l(g)),f=h.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;h.useEffect(()=>{if(r){let g=function(C){if(f.paused||!a)return;const k=C.target;a.contains(k)?p.current=k:Dn(p.current,{select:!0})},x=function(C){if(f.paused||!a)return;const k=C.relatedTarget;k!==null&&(a.contains(k)||Dn(p.current,{select:!0}))},y=function(C){if(document.activeElement===document.body)for(const S of C)S.removedNodes.length>0&&Dn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",x);const b=new MutationObserver(y);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",x),b.disconnect()}}},[r,a,f.paused]),h.useEffect(()=>{if(a){id.add(f);const g=document.activeElement;if(!a.contains(g)){const y=new CustomEvent(Xi,rd);a.addEventListener(Xi,c),a.dispatchEvent(y),y.defaultPrevented||(Uw(Gw(od(a)),{select:!0}),document.activeElement===g&&Dn(a))}return()=>{a.removeEventListener(Xi,c),setTimeout(()=>{const y=new CustomEvent(Ji,rd);a.addEventListener(Ji,d),a.dispatchEvent(y),y.defaultPrevented||Dn(g??document.body,{select:!0}),a.removeEventListener(Ji,d),id.remove(f)},0)}}},[a,c,d,f]);const v=h.useCallback(g=>{if(!n&&!r||f.paused)return;const x=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,y=document.activeElement;if(x&&y){const b=g.currentTarget,[C,k]=Ww(b);C&&k?!g.shiftKey&&y===k?(g.preventDefault(),n&&Dn(C,{select:!0})):g.shiftKey&&y===C&&(g.preventDefault(),n&&Dn(k,{select:!0})):y===b&&g.preventDefault()}},[n,r,f.paused]);return u.jsx(fe.div,{tabIndex:-1,...i,ref:m,onKeyDown:v})});es.displayName=Hw;function Uw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Dn(r,{select:t}),document.activeElement!==n)return}function Ww(e){const t=od(e),n=sd(t,e),r=sd(t.reverse(),e);return[n,r]}function od(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 sd(e,t){for(const n of e)if(!Vw(n,{upTo:t}))return n}function Vw(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 Kw(e){return e instanceof HTMLInputElement&&"select"in e}function Dn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Kw(e)&&t&&e.select()}}var id=qw();function qw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=ad(e,t),e.unshift(t)},remove(t){var n;e=ad(e,t),(n=e[0])==null||n.resume()}}}function ad(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Gw(e){return e.filter(t=>t.tagName!=="A")}var Yw=h[" useId ".trim().toString()]||(()=>{}),Xw=0;function _t(e){const[t,n]=h.useState(Yw());return It(()=>{n(r=>r??String(Xw++))},[e]),t?`radix-${t}`:""}const Jw=["top","right","bottom","left"],Ln=Math.min,Zt=Math.max,ts=Math.round,ns=Math.floor,wn=e=>({x:e,y:e}),Zw={left:"right",right:"left",bottom:"top",top:"bottom"},Qw={start:"end",end:"start"};function Zi(e,t,n){return Zt(e,Ln(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function Pn(e){return e.split("-")[0]}function Er(e){return e.split("-")[1]}function Qi(e){return e==="x"?"y":"x"}function ea(e){return e==="y"?"height":"width"}const eb=new Set(["top","bottom"]);function bn(e){return eb.has(Pn(e))?"y":"x"}function ta(e){return Qi(bn(e))}function tb(e,t,n){n===void 0&&(n=!1);const r=Er(e),o=ta(e),s=ea(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=rs(i)),[i,rs(i)]}function nb(e){const t=rs(e);return[na(e),t,na(t)]}function na(e){return e.replace(/start|end/g,t=>Qw[t])}const ld=["left","right"],cd=["right","left"],rb=["top","bottom"],ob=["bottom","top"];function sb(e,t,n){switch(e){case"top":case"bottom":return n?t?cd:ld:t?ld:cd;case"left":case"right":return t?rb:ob;default:return[]}}function ib(e,t,n,r){const o=Er(e);let s=sb(Pn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(na)))),s}function rs(e){return e.replace(/left|right|bottom|top/g,t=>Zw[t])}function ab(e){return{top:0,right:0,bottom:0,left:0,...e}}function ud(e){return typeof e!="number"?ab(e):{top:e,right:e,bottom:e,left:e}}function os(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 dd(e,t,n){let{reference:r,floating:o}=e;const s=bn(t),i=ta(t),a=ea(i),l=Pn(t),c=s==="y",d=r.x+r.width/2-o.width/2,p=r.y+r.height/2-o.height/2,m=r[a]/2-o[a]/2;let f;switch(l){case"top":f={x:d,y:r.y-o.height};break;case"bottom":f={x:d,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:p};break;case"left":f={x:r.x-o.width,y:p};break;default:f={x:r.x,y:r.y}}switch(Er(t)){case"start":f[i]-=m*(n&&c?-1:1);break;case"end":f[i]+=m*(n&&c?-1:1);break}return f}const lb=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:p}=dd(c,r,l),m=r,f={},v=0;for(let g=0;g<a.length;g++){const{name:x,fn:y}=a[g],{x:b,y:C,data:k,reset:S}=await y({x:d,y:p,initialPlacement:r,placement:m,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,p=C??p,f={...f,[x]:{...f[x],...k}},S&&v<=50&&(v++,typeof S=="object"&&(S.placement&&(m=S.placement),S.rects&&(c=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:d,y:p}=dd(c,m,l)),g=-1)}return{x:d,y:p,placement:m,strategy:o,middlewareData:f}};async function oo(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:p="floating",altBoundary:m=!1,padding:f=0}=An(t,e),v=ud(f),x=a[m?p==="floating"?"reference":"floating":p],y=os(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=p==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},S=os(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:C,strategy:l}):b);return{top:(y.top-S.top+v.top)/k.y,bottom:(S.bottom-y.bottom+v.bottom)/k.y,left:(y.left-S.left+v.left)/k.x,right:(S.right-y.right+v.right)/k.x}}const cb=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const p=ud(d),m={x:n,y:r},f=ta(o),v=ea(f),g=await i.getDimensions(c),x=f==="y",y=x?"top":"left",b=x?"bottom":"right",C=x?"clientHeight":"clientWidth",k=s.reference[v]+s.reference[f]-m[f]-s.floating[v],S=m[f]-s.reference[f],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[C]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[C]||s.floating[v]);const P=k/2-S/2,_=E/2-g[v]/2-1,$=Ln(p[y],_),L=Ln(p[b],_),F=$,G=E-g[v]-L,O=E/2-g[v]/2+P,K=Zi(F,O,G),q=!l.arrow&&Er(o)!=null&&O!==K&&s.reference[v]/2-(O<F?$:L)-g[v]/2<0,H=q?O<F?O-F:O-G:0;return{[f]:m[f]+H,data:{[f]:K,centerOffset:O-K-H,...q&&{alignmentOffset:H}},reset:q}}}),ub=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:p=!0,fallbackPlacements:m,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:g=!0,...x}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=Pn(o),b=bn(a),C=Pn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),S=m||(C||!g?[rs(a)]:nb(a)),T=v!=="none";!m&&T&&S.push(...ib(a,g,v,k));const E=[a,...S],P=await oo(t,x),_=[];let $=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(P[y]),p){const O=tb(o,i,k);_.push(P[O[0]],P[O[1]])}if($=[...$,{placement:o,overflows:_}],!_.every(O=>O<=0)){var L,F;const O=(((L=s.flip)==null?void 0:L.index)||0)+1,K=E[O];if(K&&(!(p==="alignment"?b!==bn(K):!1)||$.every(j=>bn(j.placement)===b?j.overflows[0]>0:!0)))return{data:{index:O,overflows:$},reset:{placement:K}};let q=(F=$.filter(H=>H.overflows[0]<=0).sort((H,j)=>H.overflows[1]-j.overflows[1])[0])==null?void 0:F.placement;if(!q)switch(f){case"bestFit":{var G;const H=(G=$.filter(j=>{if(T){const I=bn(j.placement);return I===b||I==="y"}return!0}).map(j=>[j.placement,j.overflows.filter(I=>I>0).reduce((I,Y)=>I+Y,0)]).sort((j,I)=>j[1]-I[1])[0])==null?void 0:G[0];H&&(q=H);break}case"initialPlacement":q=a;break}if(o!==q)return{reset:{placement:q}}}return{}}}};function fd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function pd(e){return Jw.some(t=>e[t]>=0)}const db=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 oo(t,{...o,elementContext:"reference"}),i=fd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:pd(i)}}}case"escaped":{const s=await oo(t,{...o,altBoundary:!0}),i=fd(s,n.floating);return{data:{escapedOffsets:i,escaped:pd(i)}}}default:return{}}}}},hd=new Set(["left","top"]);async function fb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Pn(n),a=Er(n),l=bn(n)==="y",c=hd.has(i)?-1:1,d=s&&l?-1:1,p=An(t,e);let{mainAxis:m,crossAxis:f,alignmentAxis:v}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return a&&typeof v=="number"&&(f=a==="end"?v*-1:v),l?{x:f*d,y:m*c}:{x:m*c,y:f*d}}const pb=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 fb(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}}}}},hb=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:x=>{let{x:y,y:b}=x;return{x:y,y:b}}},...l}=An(e,t),c={x:n,y:r},d=await oo(t,l),p=bn(Pn(o)),m=Qi(p);let f=c[m],v=c[p];if(s){const x=m==="y"?"top":"left",y=m==="y"?"bottom":"right",b=f+d[x],C=f-d[y];f=Zi(b,f,C)}if(i){const x=p==="y"?"top":"left",y=p==="y"?"bottom":"right",b=v+d[x],C=v-d[y];v=Zi(b,v,C)}const g=a.fn({...t,[m]:f,[p]:v});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[m]:s,[p]:i}}}}}},mb=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},p=bn(o),m=Qi(p);let f=d[m],v=d[p];const g=An(a,t),x=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=m==="y"?"height":"width",k=s.reference[m]-s.floating[C]+x.mainAxis,S=s.reference[m]+s.reference[C]-x.mainAxis;f<k?f=k:f>S&&(f=S)}if(c){var y,b;const C=m==="y"?"width":"height",k=hd.has(Pn(o)),S=s.reference[p]-s.floating[C]+(k&&((y=i.offset)==null?void 0:y[p])||0)+(k?0:x.crossAxis),T=s.reference[p]+s.reference[C]+(k?0:((b=i.offset)==null?void 0:b[p])||0)-(k?x.crossAxis:0);v<S?v=S:v>T&&(v=T)}return{[m]:f,[p]:v}}}},gb=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 oo(t,c),p=Pn(o),m=Er(o),f=bn(o)==="y",{width:v,height:g}=s.floating;let x,y;p==="top"||p==="bottom"?(x=p,y=m===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=p,x=m==="end"?"top":"bottom");const b=g-d.top-d.bottom,C=v-d.left-d.right,k=Ln(g-d[x],b),S=Ln(v-d[y],C),T=!t.middlewareData.shift;let E=k,P=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(P=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!m){const $=Zt(d.left,0),L=Zt(d.right,0),F=Zt(d.top,0),G=Zt(d.bottom,0);f?P=v-2*($!==0||L!==0?$+L:Zt(d.left,d.right)):E=g-2*(F!==0||G!==0?F+G:Zt(d.top,d.bottom))}await l({...t,availableWidth:P,availableHeight:E});const _=await i.getDimensions(a.floating);return v!==_.width||g!==_.height?{reset:{rects:!0}}:{}}}};function ss(){return typeof window<"u"}function Ir(e){return md(e)?(e.nodeName||"").toLowerCase():"#document"}function Qt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function yn(e){var t;return(t=(md(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function md(e){return ss()?e instanceof Node||e instanceof Qt(e).Node:!1}function un(e){return ss()?e instanceof Element||e instanceof Qt(e).Element:!1}function Sn(e){return ss()?e instanceof HTMLElement||e instanceof Qt(e).HTMLElement:!1}function gd(e){return!ss()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Qt(e).ShadowRoot}const xb=new Set(["inline","contents"]);function so(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!xb.has(o)}const vb=new Set(["table","td","th"]);function wb(e){return vb.has(Ir(e))}const bb=[":popover-open",":modal"];function is(e){return bb.some(t=>{try{return e.matches(t)}catch{return!1}})}const yb=["transform","translate","scale","rotate","perspective"],Sb=["transform","translate","scale","rotate","perspective","filter"],Cb=["paint","layout","strict","content"];function ra(e){const t=oa(),n=un(e)?dn(e):e;return yb.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)||Sb.some(r=>(n.willChange||"").includes(r))||Cb.some(r=>(n.contain||"").includes(r))}function Tb(e){let t=$n(e);for(;Sn(t)&&!Nr(t);){if(ra(t))return t;if(is(t))return null;t=$n(t)}return null}function oa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const kb=new Set(["html","body","#document"]);function Nr(e){return kb.has(Ir(e))}function dn(e){return Qt(e).getComputedStyle(e)}function as(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $n(e){if(Ir(e)==="html")return e;const t=e.assignedSlot||e.parentNode||gd(e)&&e.host||yn(e);return gd(t)?t.host:t}function xd(e){const t=$n(e);return Nr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sn(t)&&so(t)?t:xd(t)}function io(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=xd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Qt(o);if(s){const a=sa(i);return t.concat(i,i.visualViewport||[],so(o)?o:[],a&&n?io(a):[])}return t.concat(o,io(o,[],n))}function sa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function vd(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Sn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=ts(n)!==s||ts(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ia(e){return un(e)?e:e.contextElement}function Ar(e){const t=ia(e);if(!Sn(t))return wn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=vd(t);let i=(s?ts(n.width):n.width)/r,a=(s?ts(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Eb=wn(0);function wd(e){const t=Qt(e);return!oa()||!t.visualViewport?Eb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ib(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Qt(e)?!1:t}function nr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ia(e);let i=wn(1);t&&(r?un(r)&&(i=Ar(r)):i=Ar(e));const a=Ib(s,n,r)?wd(s):wn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,p=o.height/i.y;if(s){const m=Qt(s),f=r&&un(r)?Qt(r):r;let v=m,g=sa(v);for(;g&&r&&f!==v;){const x=Ar(g),y=g.getBoundingClientRect(),b=dn(g),C=y.left+(g.clientLeft+parseFloat(b.paddingLeft))*x.x,k=y.top+(g.clientTop+parseFloat(b.paddingTop))*x.y;l*=x.x,c*=x.y,d*=x.x,p*=x.y,l+=C,c+=k,v=Qt(g),g=sa(v)}}return os({width:d,height:p,x:l,y:c})}function ls(e,t){const n=as(e).scrollLeft;return t?t.left+n:nr(yn(e)).left+n}function bd(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ls(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Nb(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=yn(r),a=t?is(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=wn(1);const d=wn(0),p=Sn(r);if((p||!p&&!s)&&((Ir(r)!=="body"||so(i))&&(l=as(r)),Sn(r))){const f=nr(r);c=Ar(r),d.x=f.x+r.clientLeft,d.y=f.y+r.clientTop}const m=i&&!p&&!s?bd(i,l):wn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+m.x,y:n.y*c.y-l.scrollTop*c.y+d.y+m.y}}function Ab(e){return Array.from(e.getClientRects())}function Pb(e){const t=yn(e),n=as(e),r=e.ownerDocument.body,o=Zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ls(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const yd=25;function jb(e,t){const n=Qt(e),r=yn(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=oa();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=ls(r);if(c<=0){const d=r.ownerDocument,p=d.body,m=getComputedStyle(p),f=d.compatMode==="CSS1Compat"&&parseFloat(m.marginLeft)+parseFloat(m.marginRight)||0,v=Math.abs(r.clientWidth-p.clientWidth-f);v<=yd&&(s-=v)}else c<=yd&&(s+=c);return{width:s,height:i,x:a,y:l}}const _b=new Set(["absolute","fixed"]);function Rb(e,t){const n=nr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Sn(e)?Ar(e):wn(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 Sd(e,t,n){let r;if(t==="viewport")r=jb(e,n);else if(t==="document")r=Pb(yn(e));else if(un(t))r=Rb(t,n);else{const o=wd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return os(r)}function Cd(e,t){const n=$n(e);return n===t||!un(n)||Nr(n)?!1:dn(n).position==="fixed"||Cd(n,t)}function Mb(e,t){const n=t.get(e);if(n)return n;let r=io(e,[],!1).filter(a=>un(a)&&Ir(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?$n(e):e;for(;un(i)&&!Nr(i);){const a=dn(i),l=ra(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&_b.has(o.position)||so(i)&&!l&&Cd(e,i))?r=r.filter(d=>d!==i):o=a,i=$n(i)}return t.set(e,r),r}function Ob(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?is(t)?[]:Mb(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const p=Sd(t,d,o);return c.top=Zt(p.top,c.top),c.right=Ln(p.right,c.right),c.bottom=Ln(p.bottom,c.bottom),c.left=Zt(p.left,c.left),c},Sd(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Db(e){const{width:t,height:n}=vd(e);return{width:t,height:n}}function Lb(e,t,n){const r=Sn(t),o=yn(t),s=n==="fixed",i=nr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=wn(0);function c(){l.x=ls(o)}if(r||!r&&!s)if((Ir(t)!=="body"||so(o))&&(a=as(t)),r){const f=nr(t,!0,s,t);l.x=f.x+t.clientLeft,l.y=f.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?bd(o,a):wn(0),p=i.left+a.scrollLeft-l.x-d.x,m=i.top+a.scrollTop-l.y-d.y;return{x:p,y:m,width:i.width,height:i.height}}function aa(e){return dn(e).position==="static"}function Td(e,t){if(!Sn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return yn(e)===n&&(n=n.ownerDocument.body),n}function kd(e,t){const n=Qt(e);if(is(e))return n;if(!Sn(e)){let o=$n(e);for(;o&&!Nr(o);){if(un(o)&&!aa(o))return o;o=$n(o)}return n}let r=Td(e,t);for(;r&&wb(r)&&aa(r);)r=Td(r,t);return r&&Nr(r)&&aa(r)&&!ra(r)?n:r||Tb(e)||n}const $b=async function(e){const t=this.getOffsetParent||kd,n=this.getDimensions,r=await n(e.floating);return{reference:Lb(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Fb(e){return dn(e).direction==="rtl"}const Bb={convertOffsetParentRelativeRectToViewportRelativeRect:Nb,getDocumentElement:yn,getClippingRect:Ob,getOffsetParent:kd,getElementRects:$b,getClientRects:Ab,getDimensions:Db,getScale:Ar,isElement:un,isRTL:Fb};function Ed(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function zb(e,t){let n=null,r;const o=yn(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:p,width:m,height:f}=c;if(a||t(),!m||!f)return;const v=ns(p),g=ns(o.clientWidth-(d+m)),x=ns(o.clientHeight-(p+f)),y=ns(d),C={rootMargin:-v+"px "+-g+"px "+-x+"px "+-y+"px",threshold:Zt(0,Ln(1,l))||1};let k=!0;function S(T){const E=T[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Ed(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(S,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,C)}n.observe(e)}return i(!0),s}function Hb(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=ia(e),d=o||s?[...c?io(c):[],...io(t)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const p=c&&a?zb(c,n):null;let m=-1,f=null;i&&(f=new ResizeObserver(y=>{let[b]=y;b&&b.target===c&&f&&(f.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var C;(C=f)==null||C.observe(t)})),n()}),c&&!l&&f.observe(c),f.observe(t));let v,g=l?nr(e):null;l&&x();function x(){const y=nr(e);g&&!Ed(g,y)&&n(),g=y,v=requestAnimationFrame(x)}return n(),()=>{var y;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),p==null||p(),(y=f)==null||y.disconnect(),f=null,l&&cancelAnimationFrame(v)}}const Ub=pb,Wb=hb,Vb=ub,Kb=gb,qb=db,Id=cb,Gb=mb,Yb=(e,t,n)=>{const r=new Map,o={platform:Bb,...n},s={...o.platform,_c:r};return lb(e,t,{...o,platform:s})};var Xb=typeof document<"u",Jb=function(){},cs=Xb?w.useLayoutEffect:Jb;function us(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(!us(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)&&!us(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Nd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ad(e,t){const n=Nd(e);return Math.round(t*n)/n}function la(e){const t=h.useRef(e);return cs(()=>{t.current=e}),t}function Zb(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,p]=h.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,f]=h.useState(r);us(m,r)||f(r);const[v,g]=h.useState(null),[x,y]=h.useState(null),b=h.useCallback(j=>{j!==T.current&&(T.current=j,g(j))},[]),C=h.useCallback(j=>{j!==E.current&&(E.current=j,y(j))},[]),k=s||v,S=i||x,T=h.useRef(null),E=h.useRef(null),P=h.useRef(d),_=l!=null,$=la(l),L=la(o),F=la(c),G=h.useCallback(()=>{if(!T.current||!E.current)return;const j={placement:t,strategy:n,middleware:m};L.current&&(j.platform=L.current),Yb(T.current,E.current,j).then(I=>{const Y={...I,isPositioned:F.current!==!1};O.current&&!us(P.current,Y)&&(P.current=Y,Kr.flushSync(()=>{p(Y)}))})},[m,t,n,L,F]);cs(()=>{c===!1&&P.current.isPositioned&&(P.current.isPositioned=!1,p(j=>({...j,isPositioned:!1})))},[c]);const O=h.useRef(!1);cs(()=>(O.current=!0,()=>{O.current=!1}),[]),cs(()=>{if(k&&(T.current=k),S&&(E.current=S),k&&S){if($.current)return $.current(k,S,G);G()}},[k,S,G,$,_]);const K=h.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:C}),[b,C]),q=h.useMemo(()=>({reference:k,floating:S}),[k,S]),H=h.useMemo(()=>{const j={position:n,left:0,top:0};if(!q.floating)return j;const I=Ad(q.floating,d.x),Y=Ad(q.floating,d.y);return a?{...j,transform:"translate("+I+"px, "+Y+"px)",...Nd(q.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:I,top:Y}},[n,a,q.floating,d.x,d.y]);return h.useMemo(()=>({...d,update:G,refs:K,elements:q,floatingStyles:H}),[d,G,K,q,H])}const Qb=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?Id({element:r.current,padding:o}).fn(n):{}:r?Id({element:r,padding:o}).fn(n):{}}}},ey=(e,t)=>({...Ub(e),options:[e,t]}),ty=(e,t)=>({...Wb(e),options:[e,t]}),ny=(e,t)=>({...Gb(e),options:[e,t]}),ry=(e,t)=>({...Vb(e),options:[e,t]}),oy=(e,t)=>({...Kb(e),options:[e,t]}),sy=(e,t)=>({...qb(e),options:[e,t]}),iy=(e,t)=>({...Qb(e),options:[e,t]});var ay="Arrow",Pd=h.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(fe.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"})})});Pd.displayName=ay;var ly=Pd;function jd(e){const[t,n]=h.useState(void 0);return It(()=>{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 ca="Popper",[_d,Pr]=cn(ca),[cy,Rd]=_d(ca),Md=e=>{const{__scopePopper:t,children:n}=e,[r,o]=h.useState(null);return u.jsx(cy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Md.displayName=ca;var Od="PopperAnchor",Dd=h.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Rd(Od,n),i=h.useRef(null),a=De(t,i),l=h.useRef(null);return h.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(fe.div,{...o,ref:a})});Dd.displayName=Od;var ua="PopperContent",[uy,dy]=_d(ua),Ld=h.forwardRef((e,t)=>{var N,M,U,Z,se,ae;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:p="partial",hideWhenDetached:m=!1,updatePositionStrategy:f="optimized",onPlaced:v,...g}=e,x=Rd(ua,n),[y,b]=h.useState(null),C=De(t,Ce=>b(Ce)),[k,S]=h.useState(null),T=jd(k),E=(T==null?void 0:T.width)??0,P=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),$=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(c)?c:[c],F=L.length>0,G={padding:$,boundary:L.filter(py),altBoundary:F},{refs:O,floatingStyles:K,placement:q,isPositioned:H,middlewareData:j}=Zb({strategy:"fixed",placement:_,whileElementsMounted:(...Ce)=>Hb(...Ce,{animationFrame:f==="always"}),elements:{reference:x.anchor},middleware:[ey({mainAxis:o+P,alignmentAxis:i}),l&&ty({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?ny():void 0,...G}),l&&ry({...G}),oy({...G,apply:({elements:Ce,rects:we,availableWidth:je,availableHeight:We})=>{const{width:Fe,height:Ye}=we.reference,He=Ce.floating.style;He.setProperty("--radix-popper-available-width",`${je}px`),He.setProperty("--radix-popper-available-height",`${We}px`),He.setProperty("--radix-popper-anchor-width",`${Fe}px`),He.setProperty("--radix-popper-anchor-height",`${Ye}px`)}}),k&&iy({element:k,padding:a}),hy({arrowWidth:E,arrowHeight:P}),m&&sy({strategy:"referenceHidden",...G})]}),[I,Y]=Bd(q),J=pt(v);It(()=>{H&&(J==null||J())},[H,J]);const D=(N=j.arrow)==null?void 0:N.x,V=(M=j.arrow)==null?void 0:M.y,R=((U=j.arrow)==null?void 0:U.centerOffset)!==0,[B,X]=h.useState();return It(()=>{y&&X(window.getComputedStyle(y).zIndex)},[y]),u.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...K,transform:H?K.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:B,"--radix-popper-transform-origin":[(Z=j.transformOrigin)==null?void 0:Z.x,(se=j.transformOrigin)==null?void 0:se.y].join(" "),...((ae=j.hide)==null?void 0:ae.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(uy,{scope:n,placedSide:I,onArrowChange:S,arrowX:D,arrowY:V,shouldHideArrow:R,children:u.jsx(fe.div,{"data-side":I,"data-align":Y,...g,ref:C,style:{...g.style,animation:H?void 0:"none"}})})})});Ld.displayName=ua;var $d="PopperArrow",fy={top:"bottom",right:"left",bottom:"top",left:"right"},Fd=h.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=dy($d,r),i=fy[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(ly,{...o,ref:n,style:{...o.style,display:"block"}})})});Fd.displayName=$d;function py(e){return e!==null}var hy=e=>({name:"transformOrigin",options:e,fn(t){var x,y,b;const{placement:n,rects:r,middlewareData:o}=t,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=Bd(n),p={start:"0%",center:"50%",end:"100%"}[d],m=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,f=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let v="",g="";return c==="bottom"?(v=i?p:`${m}px`,g=`${-l}px`):c==="top"?(v=i?p:`${m}px`,g=`${r.floating.height+l}px`):c==="right"?(v=`${-l}px`,g=i?p:`${f}px`):c==="left"&&(v=`${r.floating.width+l}px`,g=i?p:`${f}px`),{data:{x:v,y:g}}}});function Bd(e){const[t,n="center"]=e.split("-");return[t,n]}var da=Md,fa=Dd,pa=Ld,ha=Fd,my="Portal",ao=h.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=h.useState(!1);It(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Oo.createPortal(u.jsx(fe.div,{...r,ref:t}),i):null});ao.displayName=my;function gy(e,t){return h.useReducer((n,r)=>t[n][r]??n,e)}var Ut=e=>{const{present:t,children:n}=e,r=xy(t),o=typeof n=="function"?n({present:r.isPresent}):h.Children.only(n),s=De(r.ref,vy(o));return typeof n=="function"||r.isPresent?h.cloneElement(o,{ref:s}):null};Ut.displayName="Presence";function xy(e){const[t,n]=h.useState(),r=h.useRef(null),o=h.useRef(e),s=h.useRef("none"),i=e?"mounted":"unmounted",[a,l]=gy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return h.useEffect(()=>{const c=ds(r.current);s.current=a==="mounted"?c:"none"},[a]),It(()=>{const c=r.current,d=o.current;if(d!==e){const m=s.current,f=ds(c);e?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&m!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),It(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,p=f=>{const g=ds(r.current).includes(CSS.escape(f.animationName));if(f.target===t&&g&&(l("ANIMATION_END"),!o.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},m=f=>{f.target===t&&(s.current=ds(r.current))};return t.addEventListener("animationstart",m),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",m),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:h.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function ds(e){return(e==null?void 0:e.animationName)||"none"}function vy(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 ma="rovingFocusGroup.onEntryFocus",wy={bubbles:!1,cancelable:!0},lo="RovingFocusGroup",[ga,zd,by]=Zo(lo),[yy,Hd]=cn(lo,[by]),[Sy,Cy]=yy(lo),Ud=h.forwardRef((e,t)=>u.jsx(ga.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(ga.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Ty,{...e,ref:t})})}));Ud.displayName=lo;var Ty=h.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...p}=e,m=h.useRef(null),f=De(t,m),v=Qo(s),[g,x]=On({prop:i,defaultProp:a??null,onChange:l,caller:lo}),[y,b]=h.useState(!1),C=pt(c),k=zd(n),S=h.useRef(!1),[T,E]=h.useState(0);return h.useEffect(()=>{const P=m.current;if(P)return P.addEventListener(ma,C),()=>P.removeEventListener(ma,C)},[C]),u.jsx(Sy,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:g,onItemFocus:h.useCallback(P=>x(P),[x]),onItemShiftTab:h.useCallback(()=>b(!0),[]),onFocusableItemAdd:h.useCallback(()=>E(P=>P+1),[]),onFocusableItemRemove:h.useCallback(()=>E(P=>P-1),[]),children:u.jsx(fe.div,{tabIndex:y||T===0?-1:0,"data-orientation":r,...p,ref:f,style:{outline:"none",...e.style},onMouseDown:ie(e.onMouseDown,()=>{S.current=!0}),onFocus:ie(e.onFocus,P=>{const _=!S.current;if(P.target===P.currentTarget&&_&&!y){const $=new CustomEvent(ma,wy);if(P.currentTarget.dispatchEvent($),!$.defaultPrevented){const L=k().filter(q=>q.focusable),F=L.find(q=>q.active),G=L.find(q=>q.id===g),K=[F,G,...L].filter(Boolean).map(q=>q.ref.current);Kd(K,d)}}S.current=!1}),onBlur:ie(e.onBlur,()=>b(!1))})})}),Wd="RovingFocusGroupItem",Vd=h.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=_t(),c=s||l,d=Cy(Wd,n),p=d.currentTabStopId===c,m=zd(n),{onFocusableItemAdd:f,onFocusableItemRemove:v,currentTabStopId:g}=d;return h.useEffect(()=>{if(r)return f(),()=>v()},[r,f,v]),u.jsx(ga.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(fe.span,{tabIndex:p?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ie(e.onMouseDown,x=>{r?d.onItemFocus(c):x.preventDefault()}),onFocus:ie(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ie(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){d.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const y=Iy(x,d.orientation,d.dir);if(y!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let C=m().filter(k=>k.focusable).map(k=>k.ref.current);if(y==="last")C.reverse();else if(y==="prev"||y==="next"){y==="prev"&&C.reverse();const k=C.indexOf(x.currentTarget);C=d.loop?Ny(C,k+1):C.slice(k+1)}setTimeout(()=>Kd(C))}}),children:typeof i=="function"?i({isCurrentTabStop:p,hasTabStop:g!=null}):i})})});Vd.displayName=Wd;var ky={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ey(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Iy(e,t,n){const r=Ey(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ky[r]}function Kd(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Ny(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ay=Ud,Py=Vd,jy=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},jr=new WeakMap,fs=new WeakMap,ps={},xa=0,qd=function(e){return e&&(e.host||qd(e.parentNode))},_y=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=qd(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})},Ry=function(e,t,n,r){var o=_y(t,Array.isArray(e)?e:[e]);ps[n]||(ps[n]=new WeakMap);var s=ps[n],i=[],a=new Set,l=new Set(o),c=function(p){!p||a.has(p)||(a.add(p),c(p.parentNode))};o.forEach(c);var d=function(p){!p||l.has(p)||Array.prototype.forEach.call(p.children,function(m){if(a.has(m))d(m);else try{var f=m.getAttribute(r),v=f!==null&&f!=="false",g=(jr.get(m)||0)+1,x=(s.get(m)||0)+1;jr.set(m,g),s.set(m,x),i.push(m),g===1&&v&&fs.set(m,!0),x===1&&m.setAttribute(n,"true"),v||m.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",m,y)}})};return d(t),a.clear(),xa++,function(){i.forEach(function(p){var m=jr.get(p)-1,f=s.get(p)-1;jr.set(p,m),s.set(p,f),m||(fs.has(p)||p.removeAttribute(r),fs.delete(p)),f||p.removeAttribute(n)}),xa--,xa||(jr=new WeakMap,jr=new WeakMap,fs=new WeakMap,ps={})}},va=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=jy(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Ry(r,o,n,"aria-hidden")):function(){return null}},Cn=function(){return Cn=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},Cn.apply(this,arguments)};function Gd(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 My(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 hs="right-scroll-bar-position",ms="width-before-scroll-bar",Oy="with-scroll-bars-hidden",Dy="--removed-body-scroll-bar-size";function wa(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Ly(e,t){var n=w.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var $y=typeof window<"u"?h.useLayoutEffect:h.useEffect,Yd=new WeakMap;function Fy(e,t){var n=Ly(null,function(r){return e.forEach(function(o){return wa(o,r)})});return $y(function(){var r=Yd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||wa(a,null)}),s.forEach(function(a){o.has(a)||wa(a,i)})}Yd.set(n,e)},[e]),n}function By(e){return e}function zy(e,t){t===void 0&&(t=By);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 Hy(e){e===void 0&&(e={});var t=zy(null);return t.options=Cn({async:!0,ssr:!1},e),t}var Xd=function(e){var t=e.sideCar,n=Gd(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 h.createElement(r,Cn({},n))};Xd.isSideCarExport=!0;function Uy(e,t){return e.useMedium(t),Xd}var Jd=Hy(),ba=function(){},gs=h.forwardRef(function(e,t){var n=h.useRef(null),r=h.useState({onScrollCapture:ba,onWheelCapture:ba,onTouchMoveCapture:ba}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,p=e.shards,m=e.sideCar,f=e.noRelative,v=e.noIsolation,g=e.inert,x=e.allowPinchZoom,y=e.as,b=y===void 0?"div":y,C=e.gapMode,k=Gd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=m,T=Fy([n,t]),E=Cn(Cn({},k),o);return h.createElement(h.Fragment,null,d&&h.createElement(S,{sideCar:Jd,removeScrollBar:c,shards:p,noRelative:f,noIsolation:v,inert:g,setCallbacks:s,allowPinchZoom:!!x,lockRef:n,gapMode:C}),i?h.cloneElement(h.Children.only(a),Cn(Cn({},E),{ref:T})):h.createElement(b,Cn({},E,{className:l,ref:T}),a))});gs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},gs.classNames={fullWidth:ms,zeroRight:hs};var Wy=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Vy(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Wy();return t&&e.setAttribute("nonce",t),e}function Ky(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function qy(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Gy=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Vy())&&(Ky(t,n),qy(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Yy=function(){var e=Gy();return function(t,n){h.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Zd=function(){var e=Yy(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Xy={left:0,top:0,right:0,gap:0},ya=function(e){return parseInt(e||"",10)||0},Jy=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[ya(n),ya(r),ya(o)]},Zy=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Xy;var t=Jy(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])}},Qy=Zd(),_r="data-scroll-locked",e0=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
40
40
|
.`.concat(Oy,` {
|
|
41
41
|
overflow: hidden `).concat(r,`;
|
|
42
42
|
padding-right: `).concat(a,"px ").concat(r,`;
|
package/package.json
CHANGED