teodor-new-chat-ui 4.3.241 → 4.3.242
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +2 -2
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -4027,8 +4027,8 @@ function Xx({
|
|
|
4027
4027
|
}
|
|
4028
4028
|
}
|
|
4029
4029
|
}, [c, B, I, s]), Xe = ke(async () => {
|
|
4030
|
-
E([], {}), J([]), j(!1), D(null);
|
|
4031
|
-
}, [E]), Ze = ke(
|
|
4030
|
+
E([], {}), x(null), H(), J([]), j(!1), D(null);
|
|
4031
|
+
}, [E, H]), Ze = ke(
|
|
4032
4032
|
async (ce, fe, he) => {
|
|
4033
4033
|
const ze = V.current;
|
|
4034
4034
|
if (!ze)
|
package/dist/index.umd.js
CHANGED
|
@@ -35,7 +35,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
35
35
|
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Jn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&No.assertOptions(r,{silentJSONParsing:gn.transitional(gn.boolean),forcedJSONParsing:gn.transitional(gn.boolean),clarifyTimeoutError:gn.transitional(gn.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:No.assertOptions(o,{encode:gn.function,serialize:gn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),No.assertOptions(n,{baseUrl:gn.spelling("baseURL"),withXsrfToken:gn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Ut.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const c=[];this.interceptors.response.forEach(function(x){c.push(x.fulfilled,x.rejected)});let d,f=0,p;if(!l){const m=[Ll.bind(this),void 0];for(m.unshift(...a),m.push(...c),p=m.length,d=Promise.resolve(n);f<p;)d=d.then(m[f++],m[f++]);return d}p=a.length;let h=n;for(;f<p;){const m=a[f++],x=a[f++];try{h=m(h)}catch(y){x.call(this,y);break}}try{d=Ll.call(this,h)}catch(m){return Promise.reject(m)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Jn(this.defaults,t);const n=El(t.baseURL,t.url,t.allowAbsoluteUrls);return xl(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){Zn.prototype[t]=function(n,r){return this.request(Jn(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Jn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Zn.prototype[t]=n(),Zn.prototype[t+"Form"]=n(!0)});let xg=class qh{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new gr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new qh(function(o){t=o}),cancel:t}}};function yg(e){return function(n){return e.apply(null,n)}}function vg(e){return P.isObject(e)&&e.isAxiosError===!0}const ci={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(ci).forEach(([e,t])=>{ci[t]=e});function zl(e){const t=new Zn(e),n=nl(Zn.prototype.request,t);return P.extend(n,Zn.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return zl(Jn(e,o))},n}const wt=zl(Lr);wt.Axios=Zn,wt.CanceledError=gr,wt.CancelToken=xg,wt.isCancel=Sl,wt.VERSION=Fl,wt.toFormData=Co,wt.AxiosError=Pe,wt.Cancel=wt.CanceledError,wt.all=function(t){return Promise.all(t)},wt.spread=yg,wt.isAxiosError=vg,wt.mergeConfig=Jn,wt.AxiosHeaders=Ut,wt.formToJSON=e=>wl(P.isHTMLForm(e)?new FormData(e):e),wt.getAdapter=Dl.getAdapter,wt.HttpStatusCode=ci,wt.default=wt;const{Axios:eT,AxiosError:tT,CanceledError:nT,isCancel:rT,CancelToken:oT,VERSION:sT,all:iT,Cancel:aT,isAxiosError:lT,spread:cT,toFormData:uT,AxiosHeaders:dT,HttpStatusCode:fT,formToJSON:pT,getAdapter:hT,mergeConfig:mT}=wt,Bl=typeof window<"u"?window.__API_BASE_URL__:void 0,Hl=Bl?En(Bl):void 0;function En(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Ao=null;const ui=new Set;function Ul(){return Ao}function jo(e){Ao=e,ui.forEach(t=>t(e))}function Wl(e){return ui.add(e),()=>ui.delete(e)}const wg=3e4,bg=9e4,Zt=wt.create({...Hl?{baseURL:Hl}:{},timeout:wg,withCredentials:!0});Zt.interceptors.request.use(e=>(Ao&&(e.headers.Authorization=`Bearer ${Ao}`),e)),Zt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),jo(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Qt(e,t){return Zt.defaults.baseURL?(await Zt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function di(e,t,n){return Zt.defaults.baseURL?(await Zt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Vl(e,t,n){return Zt.defaults.baseURL?(await Zt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Kl(e,t){return Zt.defaults.baseURL?(await Zt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function en(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class ql{get baseUrl(){const t=Zt.defaults.baseURL;return t?En(String(t)):""}updateConfig(t){t.baseUrl&&(Zt.defaults.baseURL=En(String(t.baseUrl))),t.authToken!==void 0&&jo(t.authToken)}getAuthToken(){return Ul()}setAuthToken(t){jo(t)}onTokenChange(t){return Wl(t)}async listThreads(){const t=await Qt("/threads"),n=en(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await di("/threads",t?{title:t}:void 0);return en(r)}async updateThread(t,n){const r=await Vl(`/threads/${t}`,{title:n});return en(r)}async deleteThread(t){const n=await Kl(`/threads/${t}`);return en(n)}async threadInfo(t){const n=await Qt(`/threads/${t}/info`);return en(n)}async listAgents(){const t=await Qt("/agents"),n=en(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Qt(`/agents/${t}`);return en(n)}async getAgentSchema(t){const n=await Qt(`/agents/${t}/schema`);return en(n)}async getState(t){const n=await Qt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return en(n)}async getStateHistory(t){const n=await Qt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:bg});return en(n)}async cancelRun(t){const n=await di("/runs/cancel",{threadId:t});return en(n)}async listCheckpointSummaries(t){const n=await Qt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=en(n);return(r==null?void 0:r.items)??[]}}const Pn=new ql,Gl=b.createContext(null);function Sg({children:e,apiConfig:t}){const n=Pn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Gl.Provider,{value:r,children:e})}function fi(){const e=b.useContext(Gl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Cg(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Tg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Cg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const kg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function pi(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Eg(e,t){return`${e??""}::${t??""}`}function $r(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!pi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Ng(t),i=Yl(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Yl(e,t){if(!pi(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(N=>!!N&&typeof N=="object").map(N=>({...N})):a===null?null:void 0,c=r.map((N,A)=>Mg(N,A)).filter(N=>!!N),d=Wt(e.config),f=Wt(d==null?void 0:d.configurable),p=Tt(f,["checkpoint_id","checkpointId"]),h=Tt(f,["checkpoint_ns","checkpointNs"]),m=Wt(e==null?void 0:e.parentConfig),x=Wt(m==null?void 0:m.configurable),y=Tt(x,["checkpoint_id","checkpointId"])??null,g=Tt(x,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,S=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),k=c[c.length-1]??null,T=Wt(e==null?void 0:e.metadata),C=Tt(T,["branch_label","branchLabel"]),E=Tt(x,["checkpoint_id","checkpointId"]),j=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:g,interrupt:Ig(a,c,t),createdAt:S,parentId:E??null,branchLabel:C??null,lastMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:T??null,config:d??null,parentConfig:m??null,next:j??null,tasks:l??null,values:i??null}}function Ig(e,t,n){const r=Pg(e,n);return r||Rg(t,n)}function Ng(e){const t=new Map;e.forEach((o,s)=>{if(!pi(o))return;const i=Yl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Eg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ag(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Jl(s.createdAt??"")-Jl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Ag(e,t){return{...e,metadata:_o(e.metadata,t.metadata)??null,config:_o(e.config,t.config)??null,parentConfig:_o(e.parentConfig,t.parentConfig)??null,next:jg(e.next,t.next)??null,tasks:_g(e.tasks,t.tasks)??null,values:_o(e.values,t.values)??null}}function _o(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function jg(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function _g(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Rg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function Pg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Og(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=zr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=zr(r.state,`${o}-state`);if(s)return s}}return null}function Og(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",x=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:m,interrupts:x,state:y!==void 0?y:f}}const n=Wt(e);if(!n)return null;const r=Tt(n,["id","task_id","taskId"])??t,o=Tt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function zr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Xl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=zr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=zr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=zr(l,t,n+1,r);if(c)return c}}return null}function Xl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=Tt(n,["type","event","kind"]),o=Tt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Xl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Jl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Mg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Wt(e)??{},o=Wt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=kg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Wt(o.additional_kwargs)??Wt(o.additionalKwargs),d=Wt(o.response_metadata)??Wt(o.responseMetadata),f=Tt(c,["createdAt","created_at"])??Tt(o,["created_at","createdAt"]),p=Tt(c,["checkpointId","checkpoint_id"]),h=Tt(c,["checkpointNs","checkpoint_ns"]),m=Dg(o.content),x={id:l,role:i,content:m};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),p&&(x.checkpointId=p),h&&(x.checkpointNs=h);const y=zg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),g=d?{...d}:void 0;y&&Object.keys(y).length&&(x.additionalKwargs=y),g&&Object.keys(g).length&&(x.responseMetadata=g);const w=Lg((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(x.content=[...x.content,...w]),i==="tool"){const S=Fg(o,x.content);S&&(x.content=S)}return x}function Dg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Zl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Zl(e);return t?[t]:[]}return[]}function Zl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=Tt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=Tt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Ql(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=Tt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Ql(e,t){var s;const n=Tt(e,["id","call_id"])??t,r=Tt(e,["name"])??Tt(Wt(e.function),["name"]);if(!n||!r)return null;const o=$g(e.args??e.arguments??((s=Wt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Lg(e){return Array.isArray(e)?e.map((t,n)=>Ql(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Fg(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function $g(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function Wt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Tt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function zg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function Bg(){const e=b.useRef(new Map),t=b.useCallback((a,l)=>{const c=e.current.get(a),d=new Map;c&&c.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),l.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),e.current.set(a,Array.from(d.values()))},[]),n=b.useCallback((a,l)=>{const c=e.current.get(a);return c==null?void 0:c.find(d=>d.checkpointId===l)},[]),r=b.useCallback((a,l)=>{const c=e.current.get(a);return(c==null?void 0:c.some(d=>d.checkpointId===l))??!1},[]),o=b.useCallback(a=>e.current.get(a),[]),s=b.useCallback(a=>{e.current.delete(a)},[]),i=b.useCallback(()=>{e.current.clear()},[]);return{cache:e.current,setCacheForThread:t,getCachedMetadata:n,checkpointExists:r,getThreadMetadata:o,clearThreadCache:s,clearAllCache:i}}function Hg(e){return e.type!=="thread_info"&&e.type!=="token"}const Ug={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Wg(e,t){var n;switch(t.type){case"reset":return{messages:hi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=hi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=hi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return tc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>tc(o,s),e):e}case"interrupt_response":return{...e,messages:nc(e.messages),pendingInterrupt:null};default:return e}}function ec(e=[]){const[t,n]=b.useReducer(Wg,{...Ug,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=b.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function tc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Gg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},p={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:p}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??rc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},p=f[a]??{lastSeq:null,lastText:ic(d.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof p.lastSeq=="number"&&h<=p.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:p.lastSeq}),e;const{newParts:m,newMeta:x,changed:y}=Vg(d.content,t.delta,p,h);if(!y)return e;const g={...d,content:m},w=Ro(l,c,g),S={...f,[a]:x};return{...e,messages:w,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??rc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(p=>{var h;return(p==null?void 0:p.type)==="text"&&((h=p.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=d.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const p=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:p}}}return e}if(t.type==="tool_start"){const a=oc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=sc(e,d,c),p=f>=0?e.messages[f]:null,h=l??d[0]??`${c}-${Date.now()}`,m=(p==null?void 0:p.id)??`tool-${h}`,x=d[0]??h,y={type:"tool_call",id:x,name:c,args:t.args};if(p){const S=gi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},T=f,C=T>=0?Ro(e.messages,T,k):e.messages,E=Po(k,d),j=xi(e.toolIndex,m,E);return{...e,messages:C,toolIndex:j}}const g={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:gi(void 0,d.length?d:[x],c,t.args)},w=Po(g,d.length?d:[x]);return{...e,messages:[...e.messages,g],toolIndex:xi(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=oc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=sc(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",p=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,h=(d==null?void 0:d.id)??`tool-${p}`,m=Po(d,a);let x=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(x=JSON.parse(C))}catch{x=t.output}const y={type:"text",text:typeof x=="string"?x:JSON.stringify(x)},g=(d==null?void 0:d.createdAt)??new Date().toISOString(),w=gi(d??void 0,m.length?m:a,f),S={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[y],createdAt:g,additionalKwargs:w},k=c>=0?Ro(e.messages,c,S):[...e.messages,S],T=Po(S,a.length?a:m);return{...e,messages:k,toolIndex:xi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=qg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=$r(t),l=a.interrupt,c=a.latest,d=l===null?nc(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return e}function hi(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function Ro(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function nc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function rc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function oc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function mi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function gi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=mi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Po(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=mi(e);for(const o of r)n.add(o);return Array.from(n)}function xi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function sc(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(mi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function ic(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Vg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??ic(e);let l="",c=e.slice();if(s){const f=Kg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",m={...p,text:h+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function ac(e){return e.replace(/\s+/g," ").trim()}function Kg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=ac(e),o=ac(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function qg(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return Ro(e,r,s)}return e}function Gg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function lc(e={}){const t=b.useMemo(()=>En(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[f,p]=b.useState(""),[h,m]=b.useState(null),[x,y]=b.useState(0),[g,w]=b.useState(!1),S=b.useRef(null),k=b.useRef(!0),T=b.useRef(0),C=b.useRef(null),E=b.useRef(null),j=b.useRef(null),N=b.useRef(null),A=b.useCallback(R=>{o(R)},[]),O=b.useCallback(()=>{p(""),m(null),d(null),E.current=null,j.current=null,N.current=null},[]),F=b.useCallback(()=>{var R;console.debug("[use-chat] stop() invoked - aborting stream"),(R=S.current)==null||R.abort(),S.current=null,C.current=null,l(!1),w(!1),T.current=0,y(0)},[]),$=b.useCallback((R,z,_)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),m(null),E.current=null,j.current=null,N.current=null;const B=new AbortController;S.current=B;let L=null,M=null,J=!1;return C.current={threadId:R.threadId??null,headers:{}},(async()=>{var he,Ne,_e,V,ee,q,D,H,te,se,ne,ke,Z,fe,Ie,Ae,Fe,Ze;const X=Ve=>{var Ke;try{const qe=JSON.parse(JSON.stringify(Ve));return(Ke=qe==null?void 0:qe.payload)!=null&&Ke.files_info&&Array.isArray(qe.payload.files_info)&&(qe.payload.files_info=qe.payload.files_info.map(Xe=>({...Xe,data:Xe!=null&&Xe.data?`<base64 ${String(Xe.data).length} chars>`:Xe==null?void 0:Xe.data}))),qe}catch{return Ve}};try{let Ve={};try{if(r)Ve={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Be=window.__AUTH_TOKEN__,jt=((he=window.localStorage)==null?void 0:he.getItem("authToken"))||null;let At=null;try{const we=(Ne=window.localStorage)==null?void 0:Ne.getItem("chat-settings");we&&(At=((_e=JSON.parse(we))==null?void 0:_e.apiKey)||null)}catch{}const W=Be||jt||At||null;W&&(Ve={Authorization:`Bearer ${W}`})}}catch{}console.debug("[use-chat] POST",t+n,X(R));let Ke={};if(typeof window<"u")try{const st=(V=window.localStorage)==null?void 0:V.getItem("authSessionId");st&&(Ke={"X-Session-Id":st})}catch{}const qe={...Ve,...Ke,...s.current},Xe={"Content-Type":"application/json",Accept:"text/event-stream",...qe},Qe=await fetch(t+n,{method:"POST",headers:Xe,body:JSON.stringify(R),signal:B.signal,credentials:i});if(C.current&&(C.current.headers=qe),!Qe.ok||!Qe.body){const st=await Qe.text().catch(()=>"");console.debug("[use-chat] non-OK response",Qe.status,st==null?void 0:st.slice(0,500));const Be=`stream ${Qe.status}${st?": "+st:""}`;throw(ee=_==null?void 0:_.onConnectionError)==null||ee.call(_,Be),J=!0,L="error",M=Be,new Error(Be)}w(!0);const et=Qe.body.getReader(),Nt=new TextDecoder;let mt="",at=[];T.current=0,y(0);let de=0,pe=null;const me=()=>{if(at.length){const st=at.join("");at=[],k.current&&p(Be=>Be+st)}pe=null},ze=()=>{typeof window<"u"&&pe==null&&(pe=requestAnimationFrame(me))};let De=Date.now();const ot=setInterval(()=>{var st;if(Date.now()-De>18e5){const Be="Stream idle timeout";d(Be),L="error",M=Be,B.abort(),(st=_==null?void 0:_.onError)==null||st.call(_,Be)}},5e3),Et=1024*1024;try{const st=Qe.headers.get("X-Thread-Id")||Qe.headers.get("x-thread-id"),Be=Qe.headers.get("X-Thread-Created")||Qe.headers.get("x-thread-created"),jt=st??null,At=String(Be??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:jt}),(q=_==null?void 0:_.onOpen)==null||q.call(_,{threadId:jt,created:At});;){const{value:W,done:we}=await et.read();if(we)break;mt+=Nt.decode(W,{stream:!0}),mt.length>Et&&(mt="",console.warn("Stream buffer reset: exceeded 1MB"));let ye;for(;(ye=mt.indexOf(`
|
|
36
36
|
|
|
37
37
|
`))>=0;){const ft=mt.slice(0,ye);mt=mt.slice(ye+2);const gt=Xg(ft);if(!gt)continue;let St;try{St=JSON.parse(gt)}catch{console.debug("[use-chat] malformed SSE:",gt.slice(0,200));continue}const Oe=Yg(St)?St.data:St;De=Date.now();const Kt=Oe.seq;if(Kt!==void 0){if(Kt<=de){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Kt,lastProcessedSeq:de,type:Oe.type});continue}de>0&&Kt>de+1&&((D=_==null?void 0:_.onGap)==null||D.call(_,{from:de,to:Kt})),de=Kt,T.current=Kt,y(Kt)}if(console.debug("[use-chat] received event",{seq:Oe.seq,type:Oe.type,preview:(()=>{var lt;try{return Oe.type==="message_delta"?{deltaTypes:(lt=Oe.delta)==null?void 0:lt.map(Ct=>Ct.type),textLen:(Oe.delta||[]).filter(Ct=>Ct.type==="text").map(Ct=>String(Ct.text||"").length)}:Oe.content||Oe.delta?{hasContent:!0}:{}}catch(Ct){return{err:String(Ct)}}})()}),Oe.type==="checkpoint")E.current=Oe.checkpointId??null,j.current=Oe.checkpointNs??null,m(Oe.checkpointId??null);else if(Oe.type==="state_history"){N.current=Oe;try{const Ct=$r(Oe).latest;Ct&&(E.current=Ct.checkpointId??null,j.current=Ct.checkpointNs??null,m(Ct.checkpointId??null))}catch(lt){console.warn("[use-chat] Failed to hydrate state_history payload",lt)}}try{z==null||z(Oe)}catch(lt){console.error("[use-chat] Error in onEvent callback:",lt,"for event:",Oe.type)}if(Oe.type==="token"&&e.autoAppendAssistant!==!1)at.push(Oe.content),ze();else if(Oe.type==="message_delta"){const lt=Oe.delta.filter(Ct=>Ct.type==="text").map(Ct=>Ct.text).join("");lt&&e.autoAppendAssistant!==!1&&(at.push(lt),ze())}else if(Oe.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(H=_==null?void 0:_.onHeartbeat)==null||H.call(_,Oe)}catch(lt){console.warn("[use-chat] heartbeat callback failed",lt)}}else if(pe!==null&&cancelAnimationFrame(pe),me(),Oe.type==="checkpoint")m(Oe.checkpointId);else if(Oe.type==="error"){const lt=Oe;if(d(lt.message),L="error",M=lt.message,lt.error_type==="auth_error"||lt.code==="TOKEN_EXPIRED"||((te=lt.message)==null?void 0:te.includes("token"))||((se=lt.message)==null?void 0:se.includes("401"))||((ne=lt.message)==null?void 0:ne.includes("unauthorized"))||((ke=lt.message)==null?void 0:ke.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",lt.message);try{(Z=_==null?void 0:_.onAuthError)==null||Z.call(_,lt.message)}catch(Kn){console.warn("[use-chat] onAuthError handler failed",Kn)}B.abort()}}}}me(),L===null&&!B.signal.aborted&&(L="complete")}catch(st){if(st.name==="AbortError")L=L??"aborted";else{const Be=st.message||String(st);L="error",M=Be,d(Be),(fe=_==null?void 0:_.onError)==null||fe.call(_,Be)}}finally{try{await et.cancel()}catch{}finally{(Ie=et.releaseLock)==null||Ie.call(et)}pe!==null&&typeof window<"u"&&window.cancelAnimationFrame(pe),clearInterval(ot)}}catch(Ve){if(Ve.name==="AbortError")L=L??"aborted";else{const Ke=Ve.message||String(Ve);L="error",M=Ke,d(Ke),(Ae=_==null?void 0:_.onError)==null||Ae.call(_,Ke),J||((Fe=_==null?void 0:_.onConnectionError)==null||Fe.call(_,Ke),J=!0)}}finally{const Ve=T.current,Ke=E.current,qe=j.current,Xe=N.current,Qe=L??(B.signal.aborted?"aborted":M?"error":"complete");try{(Ze=_==null?void 0:_.onClosed)==null||Ze.call(_,{reason:Qe,lastSeq:Ve,lastCheckpointId:Ke,lastCheckpointNs:qe,lastStateHistory:Xe,error:M})}catch(et){console.warn("[use-chat] onClosed callback failed",et)}l(!1),w(!1),S.current=null,T.current=0,y(0),C.current=null}})(),{close:()=>B.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var R;k.current=!1,(R=S.current)==null||R.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:x,connected:g,stream:$,stop:F,clear:O,setToken:A}}function Yg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Xg(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
|
|
38
|
-
`)}const cc=200;function Jg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),p=b.useRef(null),h=b.useCallback(N=>{try{const A=globalThis.structuredClone;if(typeof A=="function")return A(N)}catch{}try{return JSON.parse(JSON.stringify(N))}catch{return N}},[]),m=b.useCallback((N,A)=>{if(!N)return;const O=f.current.get(N)??[],F=h(A),$=O.length>=cc?[...O.slice(O.length-cc+1),F]:[...O,F];f.current.set(N,$)},[h]),x=b.useCallback(N=>{N&&f.current.set(N,[])},[]),y=b.useCallback(N=>{const A=N??d.current;if(!A)return;const O=f.current.get(A);O!=null&&O.length&&O.forEach(F=>{try{n(F)}catch($){console.error("[useChatStreamingService] Failed to replay buffered event",$)}})},[n]),g=b.useCallback(N=>{var F,$,R,z,_;const A=N.seq??null;if(A!==null){const B=c.current;if(B!==null){if(A<=B)return;A>B+1&&(o==null||o({from:B,to:A}))}c.current=A}if(N.type==="thread_info"){d.current=N.threadId,p.current&&(p.current.threadIdGuess=N.threadId),x(N.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",N);try{t(N)}catch(B){console.error("[useChatStreamingService] Error in onThreadInfo handler:",B)}return}if(N.type==="heartbeat"){try{l==null||l(N)}catch(B){console.error("[useChatStreamingService] Error in onHeartbeat handler:",B)}return}if(N.type==="error"){const B=N;if(B.error_type==="auth_error"||B.code==="TOKEN_EXPIRED"||((F=B.message)==null?void 0:F.includes("token"))||(($=B.message)==null?void 0:$.includes("401"))||((R=B.message)==null?void 0:R.includes("unauthorized"))||((z=B.message)==null?void 0:z.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",B.message);try{a==null||a(B.message)}catch(M){console.warn("[useChatStreamingService] onAuthError handler failed",M)}}}const O=N.threadId??(N.type==="state_history"?N.threadId:void 0)??d.current??((_=p.current)==null?void 0:_.threadIdGuess)??null;if(N.type==="state_history"&&(d.current=O??d.current),Hg(N)){N.type==="checkpoint"||N.type==="state_history"?x(O??null):m(O??null,N);try{n(N)}catch(B){console.error("[useChatStreamingService] Error in onMessageEvent handler:",B)}return}try{r==null||r(N)}catch(B){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",B)}},[m,x,n,o,t,r]),{stream:w,stop:S,isStreaming:k,error:T,setToken:C}=lc({baseUrl:e,token:void 0}),E=b.useCallback((N,A)=>{c.current=null,d.current=N.threadId??null,p.current={request:N,callbacks:A,manualStop:!1,threadIdGuess:N.threadId??null},w(N,g,{onOpen:A==null?void 0:A.onOpen,onError:O=>{var F;(F=A==null?void 0:A.onError)==null||F.call(A,O)},onGap:(A==null?void 0:A.onGap)??o,onConnectionError:O=>{var F;i==null||i(O),(F=A==null?void 0:A.onConnectionError)==null||F.call(A,O)},onAuthError:O=>{var F;a==null||a(O),(F=A==null?void 0:A.onAuthError)==null||F.call(A,O)},onHeartbeat:O=>{var F;try{l==null||l(O)}catch($){console.warn("[useChatStreamingService] onHeartbeat handler failed",$)}try{(F=A==null?void 0:A.onHeartbeat)==null||F.call(A,O)}catch($){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",$)}},onClosed:O=>{var z,_,B,L;const F=((z=p.current)==null?void 0:z.manualStop)??!1,$=d.current??((_=p.current)==null?void 0:_.threadIdGuess)??((B=O.lastStateHistory)==null?void 0:B.threadId)??null;(O.reason==="complete"||O.reason==="aborted"&&F)&&x($);const R={...O,threadId:$,manualStop:F};try{s==null||s(R)}catch(M){console.warn("[useChatStreamingService] onStreamClosed handler failed",M)}try{(L=A==null?void 0:A.onClosed)==null||L.call(A,R)}catch(M){console.warn("[useChatStreamingService] downstream onClosed handler failed",M)}p.current&&(p.current=null)}})},[x,g,a,i,l,o,s,w]),j=b.useCallback(()=>{p.current&&(p.current.manualStop=!0),S()},[S]);return b.useMemo(()=>({startStream:E,stop:j,isStreaming:k,error:T,setAuthToken:C,replayBufferedEvents:y}),[E,j,k,T,C,y])}const uc=b.createContext(null),dc=b.createContext(null),fc=b.createContext(null);b.createContext(!1);function Zg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,checkpointMetadataCache:l}){const{api:c,baseUrl:d}=fi(),f=b.useMemo(()=>En(d),[d]),[p,h]=b.useState([]),[m,x]=b.useState(t),[y,g]=b.useState(!1),[w,S]=b.useState(null),[k,T]=b.useState(!1),[C,E]=b.useState(null),{state:j,seed:N,prepend:A,pushUser:O,onEvent:F}=ec(),[$,R]=b.useState(!1),[z,_]=b.useState(!1),[B,L]=b.useState(null),[M,J]=b.useState([]),[X,he]=b.useState(!1),Ne=l??Bg(),{setCacheForThread:_e}=Ne,V=b.useRef(m),ee=b.useRef(null);b.useEffect(()=>{V.current=m},[m]);const q=b.useRef(),{startStream:D,stop:H,isStreaming:te,error:se,setAuthToken:ne}=Jg({baseUrl:f,onThreadInfo:de=>{console.log("[ChatSessionProvider] Thread info:",de.threadId),V.current!==de.threadId&&x(de.threadId)},onMessageEvent:F,onUnhandledEvent:de=>{console.warn("[ChatSessionProvider] Unhandled event:",de.type)},onAuthError:i}),ke=b.useCallback(async()=>{g(!0),S(null);try{const de=await c.listThreads();h(de??[])}catch(de){const pe=String(de);S(pe),s==null||s(pe)}finally{g(!1)}},[c,s]),Z=b.useCallback(async de=>{try{const pe=await c.createThread(de);return x(pe.threadId),await ke(),pe.threadId}catch(pe){return s==null||s(String(pe)),null}},[c,ke,s]),fe=b.useCallback(async de=>{try{await c.deleteThread(de),V.current===de&&(x(null),N([],{})),await ke()}catch(pe){s==null||s(String(pe))}},[c,ke,N,s]),Ie=b.useCallback(async(de,pe)=>{try{await c.updateThread(de,pe),await ke()}catch(me){s==null||s(String(me))}},[c,ke,s]),Ae=b.useCallback((de,pe,me)=>{const ze=pe.filter(De=>De.checkpointId).map(De=>({checkpointId:De.checkpointId,checkpointNs:De.checkpointNs??void 0,createdAt:De.createdAt??""}));console.log(`[ChatSessionProvider] Cached metadata for ${ze.length} checkpoints from ${me}`),_e(de,ze)},[_e]),Fe=b.useCallback(async(de,pe)=>{if(de){T(!0),E(null);try{const me=await c.getStateHistory({threadId:de,checkpointId:pe||void 0}),{checkpoints:ze}=$r(me);Ae(de,ze,`thread load (requested: ${pe})`);const De=ze.find(ot=>ot.messages&&ot.messages.length>0)??(pe?ze.find(ot=>ot.checkpointId===pe):null)??ze[0];N((De==null?void 0:De.messages)??[],{checkpointId:(De==null?void 0:De.checkpointId)??null,checkpointNs:(De==null?void 0:De.checkpointNs)??null}),J(ze),R(!!(De!=null&&De.nextCursor)),L((De==null?void 0:De.nextCursor)??null)}catch(me){const ze=String(me);E(ze),s==null||s(ze)}finally{T(!1)}}},[c,N,s,Ae]);b.useEffect(()=>{q.current=Fe},[Fe]);const Ze=b.useCallback(async(de,pe)=>{const me=V.current;if(me){he(!0);try{const ze=await c.getStateHistory({threadId:me,checkpointId:de,checkpointNs:pe??void 0}),{checkpoints:De}=$r(ze);Ae(me,De,"checkpoint navigation");const ot=De.find(Et=>Et.checkpointId===de&&(pe?Et.checkpointNs===pe:!0));if(!ot){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:de,checkpointNs:pe});return}J(De),N(ot.messages??[],{checkpointId:ot.checkpointId??null,checkpointNs:ot.checkpointNs??null})}catch(ze){s==null||s(String(ze))}finally{he(!1)}}},[c,N,s,Ae]),Ve=b.useCallback((de,pe)=>{N(j.messages,{checkpointId:de??null,checkpointNs:pe??null})},[N,j.messages]),Ke=b.useCallback(async()=>{V.current&&await Fe(V.current)},[Fe]),qe=b.useCallback(async()=>{if(!(!V.current||!B)){_(!0);try{const de=await c.getStateHistory({threadId:V.current,checkpointId:B}),{checkpoints:pe}=$r(de);if(pe.length>0){const me=pe[pe.length-1];A((me==null?void 0:me.messages)??[]),R(!!(me!=null&&me.nextCursor)),L((me==null?void 0:me.nextCursor)??null)}}catch(de){s==null||s(String(de))}finally{_(!1)}}},[c,B,A,s]),Xe=b.useCallback(async()=>{N([],{}),J([]),R(!1),L(null)},[N]),Qe=b.useCallback(async(de,pe,me)=>{const ze=V.current;if(!ze)throw new Error("No active thread to handle interrupt");const De=pe?me??!0:!1;try{const ot={threadId:ze,checkpointId:j.lastCheckpointId??void 0,checkpointNs:j.lastCheckpointNs??void 0,command:{kind:"resume",value:De}};D(ot)}catch(ot){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${de}:`,ot),ot}},[j.lastCheckpointId,j.lastCheckpointNs,D]);b.useEffect(()=>{ke()},[ke]),b.useEffect(()=>{var de,pe;!o||!m||k||ee.current!==m&&(ee.current=m,n?(console.log("[ChatSessionProvider] Loading thread with checkpoint:",n),(de=q.current)==null||de.call(q,m,n)):(console.log("[ChatSessionProvider] Loading thread with latest checkpoint"),(pe=q.current)==null||pe.call(q,m)))},[o,m,k,n,r]),b.useEffect(()=>{a==null||a(m)},[m,a]);const et=b.useCallback(async(de,pe)=>{const me=V.current,ze=(de==null?void 0:de.text)??"";if(!me&&!ze)return;if(!me){await Z("New Chat");return}const{contentParts:De}=await Tg(c,(de==null?void 0:de.attachments)??[]),ot=[...De];ze!=null&&ze.trim()&&ot.push({type:"text",text:ze});const Et={id:`msg-${Date.now()}`,role:"user",content:ot,createdAt:new Date().toISOString()};O(Et);const st={threadId:me,payload:{messages:[Et]},checkpointId:(pe==null?void 0:pe.checkpointId)??j.lastCheckpointId??void 0,checkpointNs:(pe==null?void 0:pe.checkpointNs)??j.lastCheckpointNs??void 0};D(st)},[c,Z,O,j,D]),Nt=b.useMemo(()=>({threads:p,currentThreadId:m,setCurrentThreadId:x,isLoading:y,error:w,actions:{createThread:Z,deleteThread:fe,renameThread:Ie,refreshThreads:ke}}),[p,m,y,w,Z,fe,Ie,ke]),mt=b.useMemo(()=>({threadId:m,messages:j.messages,interrupt:null,checkpoint:{id:j.lastCheckpointId??null,namespace:j.lastCheckpointNs??null},checkpoints:M,metadata:null,isLoading:k,isHistoryLoading:z,isLoadingCheckpoint:X,error:C,hasMore:$,loadOlder:qe,clearState:Xe,navigateToCheckpoint:Ze,setCurrentCheckpointId:Ve,returnToLatest:Ke,loadThread:Fe,clearThread:Xe,respondToInterrupt:Qe}),[m,j,M,k,z,X,C,$,qe,Xe,Ze,Ve,Ke,Fe,Qe]),at=b.useMemo(()=>({isStreaming:te,error:se,connectionState:te?"connected":"idle",submit:et,send:et,stop:H,setAuthToken:ne}),[te,se,et,H,ne]);return u.jsx(uc.Provider,{value:Nt,children:u.jsx(dc.Provider,{value:mt,children:u.jsx(fc.Provider,{value:at,children:e})})})}function Oo(){const e=b.useContext(uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){const e=b.useContext(dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function pc(){const e=b.useContext(fc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Do({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c}){return u.jsx(Sg,{apiConfig:t,children:u.jsx(Zg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c,children:e})})}function Q(...e){return Yh.twMerge(Gh.clsx(e))}const Qg=xo.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),nt=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yn.Slot:"button";return u.jsx(i,{className:Q(Qg({variant:t,size:n,className:e})),ref:s,...o})});nt.displayName="Button";const hc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:Q("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));hc.displayName="Textarea";function mc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const m=i!==void 0,[x,y]=b.useState(e),g=(m?i:x)??"",[w,S]=b.useTransition(),k=b.useRef(null),T=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{m||(y(e??""),C.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const z=k.current;z&&(z.style.height="auto",z.style.height=`${z.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,g]);const j=b.useCallback((z,{fromUser:_})=>{m||y(z),_&&(a==null||a(z))},[m,a]),N=b.useCallback(async z=>{z&&z.preventDefault();const _=(g??"").trim();if(!_&&!h)return;const B=++T.current;C.current={id:B,shouldClear:!0},S(()=>{var L,M,J;try{const X=l(_);X&&typeof X.then=="function"?X.then(()=>{var he,Ne;((he=C.current)==null?void 0:he.id)===B&&C.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((Ne=C.current)==null?void 0:Ne.id)===B&&(C.current=null)}).catch(()=>{var he;((he=C.current)==null?void 0:he.id)===B&&(C.current=null)}):(((L=C.current)==null?void 0:L.id)===B&&C.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=C.current)==null?void 0:M.id)===B&&(C.current=null))}catch{((J=C.current)==null?void 0:J.id)===B&&(C.current=null)}})},[g,l,h,m,a]),A=b.useCallback(z=>{const _=z.target.value;j(_,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[j]),O=b.useCallback(z=>{z.key==="Enter"&&!z.shiftKey?(z.preventDefault(),N()):z.key==="Escape"&&t&&(z.preventDefault(),c==null||c())},[N,t,c]),R=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:z=>void N(z),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(hc,{ref:k,value:g,onChange:A,onKeyDown:O,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(nt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(oe.Square,{size:16})}):u.jsx(nt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||w,children:u.jsx(oe.Send,{size:16})})})]})})}const ex=b.memo(mc);function ue(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function gc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=gc(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():gc(e[o],null)}}}}function Ue(...e){return v.useCallback(yi(...e),e)}function tx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function In(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:p,children:h,...m}=f,x=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(x.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var x;const h=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,m=v.useContext(h);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,nx(o,...t)]}function nx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var _t=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},rx=v[" useInsertionEffect ".trim().toString()]||_t;function xr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ox({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=sx(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function ox({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return rx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function sx(e){return typeof e=="function"}var ix=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Re=ix.reduce((e,t)=>{const n=Yn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xc(e,t){e&&yo.flushSync(()=>e.dispatchEvent(t))}function vi(e){const t=e+"CollectionProvider",[n,r]=In(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:y,children:g}=x,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:w,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Yn.createSlot(a),c=b.forwardRef((x,y)=>{const{scope:g,children:w}=x,S=s(a,g),k=Ue(y,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Yn.createSlot(d),h=b.forwardRef((x,y)=>{const{scope:g,children:w,...S}=x,k=b.useRef(null),T=Ue(y,k),C=s(d,g);return b.useEffect(()=>(C.itemMap.set(k,{ref:k,...S}),()=>void C.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:T,children:w})});h.displayName=d;function m(x){const y=s(e+"CollectionConsumer",x);return b.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},m,r]}var ax=v.createContext(void 0);function Lo(e){const t=v.useContext(ax);return e||t||"ltr"}function Rt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function lx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var cx="DismissableLayer",wi="dismissableLayer.update",ux="dismissableLayer.pointerDownOutside",dx="dismissableLayer.focusOutside",yc,vc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Fo=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(vc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),m=Ue(t,E=>f(E)),x=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=x.indexOf(y),w=d?x.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=g,T=hx(E=>{const j=E.target,N=[...c.branches].some(A=>A.contains(j));!k||N||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),C=mx(E=>{const j=E.target;[...c.branches].some(A=>A.contains(j))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return lx(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(yc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=yc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wc())},[d,c]),v.useEffect(()=>{const E=()=>h({});return document.addEventListener(wi,E),()=>document.removeEventListener(wi,E)},[]),u.jsx(Re.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:ue(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ue(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ue(e.onPointerDownCapture,T.onPointerDownCapture)})});Fo.displayName=cx;var fx="DismissableLayerBranch",px=v.forwardRef((e,t)=>{const n=v.useContext(vc),r=v.useRef(null),o=Ue(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Re.div,{...e,ref:o})});px.displayName=fx;function hx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){bc(ux,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function mx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&bc(dx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function wc(){const e=new CustomEvent(wi);document.dispatchEvent(e)}function bc(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?xc(o,s):o.dispatchEvent(s)}var bi=0;function Si(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sc()),document.body.insertAdjacentElement("beforeend",e[1]??Sc()),bi++,()=>{bi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),bi--}},[])}function Sc(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Ci="focusScope.autoFocusOnMount",Ti="focusScope.autoFocusOnUnmount",Cc={bubbles:!1,cancelable:!0},gx="FocusScope",$o=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Rt(o),d=Rt(s),f=v.useRef(null),p=Ue(t,x=>l(x)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let x=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:On(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||On(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const T of S)T.removedNodes.length>0&&On(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",y);const w=new MutationObserver(g);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",y),w.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){Ec.add(h);const x=document.activeElement;if(!a.contains(x)){const g=new CustomEvent(Ci,Cc);a.addEventListener(Ci,c),a.dispatchEvent(g),g.defaultPrevented||(xx(Sx(Tc(a)),{select:!0}),document.activeElement===x&&On(a))}return()=>{a.removeEventListener(Ci,c),setTimeout(()=>{const g=new CustomEvent(Ti,Cc);a.addEventListener(Ti,d),a.dispatchEvent(g),g.defaultPrevented||On(x??document.body,{select:!0}),a.removeEventListener(Ti,d),Ec.remove(h)},0)}}},[a,c,d,h]);const m=v.useCallback(x=>{if(!n&&!r||h.paused)return;const y=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,g=document.activeElement;if(y&&g){const w=x.currentTarget,[S,k]=yx(w);S&&k?!x.shiftKey&&g===k?(x.preventDefault(),n&&On(S,{select:!0})):x.shiftKey&&g===S&&(x.preventDefault(),n&&On(k,{select:!0})):g===w&&x.preventDefault()}},[n,r,h.paused]);return u.jsx(Re.div,{tabIndex:-1,...i,ref:p,onKeyDown:m})});$o.displayName=gx;function xx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(On(r,{select:t}),document.activeElement!==n)return}function yx(e){const t=Tc(e),n=kc(t,e),r=kc(t.reverse(),e);return[n,r]}function Tc(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function kc(e,t){for(const n of e)if(!vx(n,{upTo:t}))return n}function vx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function wx(e){return e instanceof HTMLInputElement&&"select"in e}function On(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var Ec=bx();function bx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Ic(e,t),e.unshift(t)},remove(t){var n;e=Ic(e,t),(n=e[0])==null||n.resume()}}}function Ic(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Sx(e){return e.filter(t=>t.tagName!=="A")}var Cx=v[" useId ".trim().toString()]||(()=>{}),Tx=0;function Nn(e){const[t,n]=v.useState(Cx());return _t(()=>{n(r=>r??String(Tx++))},[e]),t?`radix-${t}`:""}const kx=["top","right","bottom","left"],Mn=Math.min,Gt=Math.max,zo=Math.round,Bo=Math.floor,xn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ix={start:"end",end:"start"};function ki(e,t,n){return Gt(e,Mn(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function jn(e){return e.split("-")[0]}function yr(e){return e.split("-")[1]}function Ei(e){return e==="x"?"y":"x"}function Ii(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function yn(e){return Nx.has(jn(e))?"y":"x"}function Ni(e){return Ei(yn(e))}function Ax(e,t,n){n===void 0&&(n=!1);const r=yr(e),o=Ni(e),s=Ii(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ho(i)),[i,Ho(i)]}function jx(e){const t=Ho(e);return[Ai(e),t,Ai(t)]}function Ai(e){return e.replace(/start|end/g,t=>Ix[t])}const Nc=["left","right"],Ac=["right","left"],_x=["top","bottom"],Rx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Ac:Nc:t?Nc:Ac;case"left":case"right":return t?_x:Rx;default:return[]}}function Ox(e,t,n,r){const o=yr(e);let s=Px(jn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ai)))),s}function Ho(e){return e.replace(/left|right|bottom|top/g,t=>Ex[t])}function Mx(e){return{top:0,right:0,bottom:0,left:0,...e}}function jc(e){return typeof e!="number"?Mx(e):{top:e,right:e,bottom:e,left:e}}function Uo(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function _c(e,t,n){let{reference:r,floating:o}=e;const s=yn(t),i=Ni(t),a=Ii(i),l=jn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(yr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Dx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=_c(c,r,l),p=r,h={},m=0;for(let x=0;x<a.length;x++){const{name:y,fn:g}=a[x],{x:w,y:S,data:k,reset:T}=await g({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,h={...h,[y]:{...h[y],...k}},T&&m<=50&&(m++,typeof T=="object"&&(T.placement&&(p=T.placement),T.rects&&(c=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=_c(c,p,l)),x=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Br(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=An(t,e),m=jc(h),y=a[p?f==="floating"?"reference":"floating":f],g=Uo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},T=Uo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(g.top-T.top+m.top)/k.y,bottom:(T.bottom-g.bottom+m.bottom)/k.y,left:(g.left-T.left+m.left)/k.x,right:(T.right-g.right+m.right)/k.x}}const Lx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const f=jc(d),p={x:n,y:r},h=Ni(o),m=Ii(h),x=await i.getDimensions(c),y=h==="y",g=y?"top":"left",w=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[h]-p[h]-s.floating[m],T=p[h]-s.reference[h],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[m]);const j=k/2-T/2,N=E/2-x[m]/2-1,A=Mn(f[g],N),O=Mn(f[w],N),F=A,$=E-x[m]-O,R=E/2-x[m]/2+j,z=ki(F,R,$),_=!l.arrow&&yr(o)!=null&&R!==z&&s.reference[m]/2-(R<F?A:O)-x[m]/2<0,B=_?R<F?R-F:R-$:0;return{[h]:p[h]+B,data:{[h]:z,centerOffset:R-z-B,..._&&{alignmentOffset:B}},reset:_}}}),Fx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:x=!0,...y}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=jn(o),w=yn(a),S=jn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),T=p||(S||!x?[Ho(a)]:jx(a)),C=m!=="none";!p&&C&&T.push(...Ox(a,x,m,k));const E=[a,...T],j=await Br(t,y),N=[];let A=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&N.push(j[g]),f){const R=Ax(o,i,k);N.push(j[R[0]],j[R[1]])}if(A=[...A,{placement:o,overflows:N}],!N.every(R=>R<=0)){var O,F;const R=(((O=s.flip)==null?void 0:O.index)||0)+1,z=E[R];if(z&&(!(f==="alignment"?w!==yn(z):!1)||A.every(L=>yn(L.placement)===w?L.overflows[0]>0:!0)))return{data:{index:R,overflows:A},reset:{placement:z}};let _=(F=A.filter(B=>B.overflows[0]<=0).sort((B,L)=>B.overflows[1]-L.overflows[1])[0])==null?void 0:F.placement;if(!_)switch(h){case"bestFit":{var $;const B=($=A.filter(L=>{if(C){const M=yn(L.placement);return M===w||M==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(M=>M>0).reduce((M,J)=>M+J,0)]).sort((L,M)=>L[1]-M[1])[0])==null?void 0:$[0];B&&(_=B);break}case"initialPlacement":_=a;break}if(o!==_)return{reset:{placement:_}}}return{}}}};function Rc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pc(e){return kx.some(t=>e[t]>=0)}const $x=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=An(e,t);switch(r){case"referenceHidden":{const s=await Br(t,{...o,elementContext:"reference"}),i=Rc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pc(i)}}}case"escaped":{const s=await Br(t,{...o,altBoundary:!0}),i=Rc(s,n.floating);return{data:{escapedOffsets:i,escaped:Pc(i)}}}default:return{}}}}},Oc=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=jn(n),a=yr(n),l=yn(n)==="y",c=Oc.has(i)?-1:1,d=s&&l?-1:1,f=An(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(h=a==="end"?m*-1:m),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Bx=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await zx(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:g,y:w}=y;return{x:g,y:w}}},...l}=An(e,t),c={x:n,y:r},d=await Br(t,l),f=yn(jn(o)),p=Ei(f);let h=c[p],m=c[f];if(s){const y=p==="y"?"top":"left",g=p==="y"?"bottom":"right",w=h+d[y],S=h-d[g];h=ki(w,h,S)}if(i){const y=f==="y"?"top":"left",g=f==="y"?"bottom":"right",w=m+d[y],S=m-d[g];m=ki(w,m,S)}const x=a.fn({...t,[p]:h,[f]:m});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[p]:s,[f]:i}}}}}},Ux=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=An(e,t),d={x:n,y:r},f=yn(o),p=Ei(f);let h=d[p],m=d[f];const x=An(a,t),y=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,T=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>T&&(h=T)}if(c){var g,w;const S=p==="y"?"width":"height",k=Oc.has(jn(o)),T=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:y.crossAxis),C=s.reference[f]+s.reference[S]+(k?0:((w=i.offset)==null?void 0:w[f])||0)-(k?y.crossAxis:0);m<T?m=T:m>C&&(m=C)}return{[p]:h,[f]:m}}}},Wx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=An(e,t),d=await Br(t,c),f=jn(o),p=yr(o),h=yn(o)==="y",{width:m,height:x}=s.floating;let y,g;f==="top"||f==="bottom"?(y=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,y=p==="end"?"top":"bottom");const w=x-d.top-d.bottom,S=m-d.left-d.right,k=Mn(x-d[y],w),T=Mn(m-d[g],S),C=!t.middlewareData.shift;let E=k,j=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),C&&!p){const A=Gt(d.left,0),O=Gt(d.right,0),F=Gt(d.top,0),$=Gt(d.bottom,0);h?j=m-2*(A!==0||O!==0?A+O:Gt(d.left,d.right)):E=x-2*(F!==0||$!==0?F+$:Gt(d.top,d.bottom))}await l({...t,availableWidth:j,availableHeight:E});const N=await i.getDimensions(a.floating);return m!==N.width||x!==N.height?{reset:{rects:!0}}:{}}}};function Wo(){return typeof window<"u"}function vr(e){return Mc(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function vn(e){var t;return(t=(Mc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Mc(e){return Wo()?e instanceof Node||e instanceof Yt(e).Node:!1}function un(e){return Wo()?e instanceof Element||e instanceof Yt(e).Element:!1}function wn(e){return Wo()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function Dc(e){return!Wo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const Vx=new Set(["inline","contents"]);function Hr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Vx.has(o)}const Kx=new Set(["table","td","th"]);function qx(e){return Kx.has(vr(e))}const Gx=[":popover-open",":modal"];function Vo(e){return Gx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Yx=["transform","translate","scale","rotate","perspective"],Xx=["transform","translate","scale","rotate","perspective","filter"],Jx=["paint","layout","strict","content"];function ji(e){const t=_i(),n=un(e)?dn(e):e;return Yx.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||Xx.some(r=>(n.willChange||"").includes(r))||Jx.some(r=>(n.contain||"").includes(r))}function Zx(e){let t=Dn(e);for(;wn(t)&&!wr(t);){if(ji(t))return t;if(Vo(t))return null;t=Dn(t)}return null}function _i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Qx=new Set(["html","body","#document"]);function wr(e){return Qx.has(vr(e))}function dn(e){return Yt(e).getComputedStyle(e)}function Ko(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Dn(e){if(vr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Dc(e)&&e.host||vn(e);return Dc(t)?t.host:t}function Lc(e){const t=Dn(e);return wr(t)?e.ownerDocument?e.ownerDocument.body:e.body:wn(t)&&Hr(t)?t:Lc(t)}function Ur(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Lc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Ri(i);return t.concat(i,i.visualViewport||[],Hr(o)?o:[],a&&n?Ur(a):[])}return t.concat(o,Ur(o,[],n))}function Ri(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Fc(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=wn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=zo(n)!==s||zo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Pi(e){return un(e)?e:e.contextElement}function br(e){const t=Pi(e);if(!wn(t))return xn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Fc(t);let i=(s?zo(n.width):n.width)/r,a=(s?zo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ey=xn(0);function $c(e){const t=Yt(e);return!_i()||!t.visualViewport?ey:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ty(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function Qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Pi(e);let i=xn(1);t&&(r?un(r)&&(i=br(r)):i=br(e));const a=ty(s,n,r)?$c(s):xn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Yt(s),h=r&&un(r)?Yt(r):r;let m=p,x=Ri(m);for(;x&&r&&h!==m;){const y=br(x),g=x.getBoundingClientRect(),w=dn(x),S=g.left+(x.clientLeft+parseFloat(w.paddingLeft))*y.x,k=g.top+(x.clientTop+parseFloat(w.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,m=Yt(x),x=Ri(m)}}return Uo({width:d,height:f,x:l,y:c})}function qo(e,t){const n=Ko(e).scrollLeft;return t?t.left+n:Qn(vn(e)).left+n}function zc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-qo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=vn(r),a=t?Vo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=xn(1);const d=xn(0),f=wn(r);if((f||!f&&!s)&&((vr(r)!=="body"||Hr(i))&&(l=Ko(r)),wn(r))){const h=Qn(r);c=br(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?zc(i,l):xn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function ry(e){return Array.from(e.getClientRects())}function oy(e){const t=vn(e),n=Ko(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+qo(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Bc=25;function sy(e,t){const n=Yt(e),r=vn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=_i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=qo(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-h);m<=Bc&&(s-=m)}else c<=Bc&&(s+=c);return{width:s,height:i,x:a,y:l}}const iy=new Set(["absolute","fixed"]);function ay(e,t){const n=Qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=wn(e)?br(e):xn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Hc(e,t,n){let r;if(t==="viewport")r=sy(e,n);else if(t==="document")r=oy(vn(e));else if(un(t))r=ay(t,n);else{const o=$c(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Uo(r)}function Uc(e,t){const n=Dn(e);return n===t||!un(n)||wr(n)?!1:dn(n).position==="fixed"||Uc(n,t)}function ly(e,t){const n=t.get(e);if(n)return n;let r=Ur(e,[],!1).filter(a=>un(a)&&vr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Dn(e):e;for(;un(i)&&!wr(i);){const a=dn(i),l=ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&iy.has(o.position)||Hr(i)&&!l&&Uc(e,i))?r=r.filter(d=>d!==i):o=a,i=Dn(i)}return t.set(e,r),r}function cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Vo(t)?[]:ly(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Hc(t,d,o);return c.top=Gt(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Gt(f.left,c.left),c},Hc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function uy(e){const{width:t,height:n}=Fc(e);return{width:t,height:n}}function dy(e,t,n){const r=wn(t),o=vn(t),s=n==="fixed",i=Qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=xn(0);function c(){l.x=qo(o)}if(r||!r&&!s)if((vr(t)!=="body"||Hr(o))&&(a=Ko(t)),r){const h=Qn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?zc(o,a):xn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function Oi(e){return dn(e).position==="static"}function Wc(e,t){if(!wn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return vn(e)===n&&(n=n.ownerDocument.body),n}function Vc(e,t){const n=Yt(e);if(Vo(e))return n;if(!wn(e)){let o=Dn(e);for(;o&&!wr(o);){if(un(o)&&!Oi(o))return o;o=Dn(o)}return n}let r=Wc(e,t);for(;r&&qx(r)&&Oi(r);)r=Wc(r,t);return r&&wr(r)&&Oi(r)&&!ji(r)?n:r||Zx(e)||n}const fy=async function(e){const t=this.getOffsetParent||Vc,n=this.getDimensions,r=await n(e.floating);return{reference:dy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function py(e){return dn(e).direction==="rtl"}const hy={convertOffsetParentRelativeRectToViewportRelativeRect:ny,getDocumentElement:vn,getClippingRect:cy,getOffsetParent:Vc,getElementRects:fy,getClientRects:ry,getDimensions:uy,getScale:br,isElement:un,isRTL:py};function Kc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function my(e,t){let n=null,r;const o=vn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const m=Bo(f),x=Bo(o.clientWidth-(d+p)),y=Bo(o.clientHeight-(f+h)),g=Bo(d),S={rootMargin:-m+"px "+-x+"px "+-y+"px "+-g+"px",threshold:Gt(0,Mn(1,l))||1};let k=!0;function T(C){const E=C[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Kc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(T,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,S)}n.observe(e)}return i(!0),s}function gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Pi(e),d=o||s?[...c?Ur(c):[],...Ur(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?my(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(g=>{let[w]=g;w&&w.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let m,x=l?Qn(e):null;l&&y();function y(){const g=Qn(e);x&&!Kc(x,g)&&n(),x=g,m=requestAnimationFrame(y)}return n(),()=>{var g;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(g=h)==null||g.disconnect(),h=null,l&&cancelAnimationFrame(m)}}const xy=Bx,yy=Hx,vy=Fx,wy=Wx,by=$x,qc=Lx,Sy=Ux,Cy=(e,t,n)=>{const r=new Map,o={platform:hy,...n},s={...o.platform,_c:r};return Dx(e,t,{...o,platform:s})};var Ty=typeof document<"u",ky=function(){},Go=Ty?b.useLayoutEffect:ky;function Yo(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Yo(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Yo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Gc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yc(e,t){const n=Gc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Go(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Yo(p,r)||h(r);const[m,x]=v.useState(null),[y,g]=v.useState(null),w=v.useCallback(L=>{L!==C.current&&(C.current=L,x(L))},[]),S=v.useCallback(L=>{L!==E.current&&(E.current=L,g(L))},[]),k=s||m,T=i||y,C=v.useRef(null),E=v.useRef(null),j=v.useRef(d),N=l!=null,A=Mi(l),O=Mi(o),F=Mi(c),$=v.useCallback(()=>{if(!C.current||!E.current)return;const L={placement:t,strategy:n,middleware:p};O.current&&(L.platform=O.current),Cy(C.current,E.current,L).then(M=>{const J={...M,isPositioned:F.current!==!1};R.current&&!Yo(j.current,J)&&(j.current=J,yo.flushSync(()=>{f(J)}))})},[p,t,n,O,F]);Go(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[c]);const R=v.useRef(!1);Go(()=>(R.current=!0,()=>{R.current=!1}),[]),Go(()=>{if(k&&(C.current=k),T&&(E.current=T),k&&T){if(A.current)return A.current(k,T,$);$()}},[k,T,$,A,N]);const z=v.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),_=v.useMemo(()=>({reference:k,floating:T}),[k,T]),B=v.useMemo(()=>{const L={position:n,left:0,top:0};if(!_.floating)return L;const M=Yc(_.floating,d.x),J=Yc(_.floating,d.y);return a?{...L,transform:"translate("+M+"px, "+J+"px)",...Gc(_.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:J}},[n,a,_.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:$,refs:z,elements:_,floatingStyles:B}),[d,$,z,_,B])}const Iy=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?qc({element:r.current,padding:o}).fn(n):{}:r?qc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...xy(e),options:[e,t]}),Ay=(e,t)=>({...yy(e),options:[e,t]}),jy=(e,t)=>({...Sy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),Ry=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...by(e),options:[e,t]}),Oy=(e,t)=>({...Iy(e),options:[e,t]});var My="Arrow",Xc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Re.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Xc.displayName=My;var Dy=Xc;function Jc(e){const[t,n]=v.useState(void 0);return _t(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Di="Popper",[Zc,Xo]=In(Di),[Ly,Qc]=Zc(Di),eu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(Ly,{scope:t,anchor:r,onAnchorChange:o,children:n})};eu.displayName=Di;var tu="PopperAnchor",nu=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Qc(tu,n),i=v.useRef(null),a=Ue(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Re.div,{...o,ref:a})});nu.displayName=tu;var Li="PopperContent",[Fy,$y]=Zc(Li),ru=v.forwardRef((e,t)=>{var q,D,H,te,se,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:m,...x}=e,y=Qc(Li,n),[g,w]=v.useState(null),S=Ue(t,ke=>w(ke)),[k,T]=v.useState(null),C=Jc(k),E=(C==null?void 0:C.width)??0,j=(C==null?void 0:C.height)??0,N=r+(s!=="center"?"-"+s:""),A=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},O=Array.isArray(c)?c:[c],F=O.length>0,$={padding:A,boundary:O.filter(By),altBoundary:F},{refs:R,floatingStyles:z,placement:_,isPositioned:B,middlewareData:L}=Ey({strategy:"fixed",placement:N,whileElementsMounted:(...ke)=>gy(...ke,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Ny({mainAxis:o+j,alignmentAxis:i}),l&&Ay({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...$}),l&&_y({...$}),Ry({...$,apply:({elements:ke,rects:Z,availableWidth:fe,availableHeight:Ie})=>{const{width:Ae,height:Fe}=Z.reference,Ze=ke.floating.style;Ze.setProperty("--radix-popper-available-width",`${fe}px`),Ze.setProperty("--radix-popper-available-height",`${Ie}px`),Ze.setProperty("--radix-popper-anchor-width",`${Ae}px`),Ze.setProperty("--radix-popper-anchor-height",`${Fe}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:E,arrowHeight:j}),p&&Py({strategy:"referenceHidden",...$})]}),[M,J]=iu(_),X=Rt(m);_t(()=>{B&&(X==null||X())},[B,X]);const he=(q=L.arrow)==null?void 0:q.x,Ne=(D=L.arrow)==null?void 0:D.y,_e=((H=L.arrow)==null?void 0:H.centerOffset)!==0,[V,ee]=v.useState();return _t(()=>{g&&ee(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:B?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:V,"--radix-popper-transform-origin":[(te=L.transformOrigin)==null?void 0:te.x,(se=L.transformOrigin)==null?void 0:se.y].join(" "),...((ne=L.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Fy,{scope:n,placedSide:M,onArrowChange:T,arrowX:he,arrowY:Ne,shouldHideArrow:_e,children:u.jsx(Re.div,{"data-side":M,"data-align":J,...x,ref:S,style:{...x.style,animation:B?void 0:"none"}})})})});ru.displayName=Li;var ou="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},su=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=$y(ou,r),i=zy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Dy,{...o,ref:n,style:{...o.style,display:"block"}})})});su.displayName=ou;function By(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var y,g,w;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=iu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,h=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",x="";return c==="bottom"?(m=i?f:`${p}px`,x=`${-l}px`):c==="top"?(m=i?f:`${p}px`,x=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,x=i?f:`${h}px`):c==="left"&&(m=`${r.floating.width+l}px`,x=i?f:`${h}px`),{data:{x:m,y:x}}}});function iu(e){const[t,n="center"]=e.split("-");return[t,n]}var au=eu,lu=nu,cu=ru,uu=su,Uy="Portal",Jo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);_t(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Js.createPortal(u.jsx(Re.div,{...r,ref:t}),i):null});Jo.displayName=Uy;function Wy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var tn=e=>{const{present:t,children:n}=e,r=Vy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Ue(r.ref,Ky(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};tn.displayName="Presence";function Vy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Zo(r.current);s.current=a==="mounted"?c:"none"},[a]),_t(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Zo(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),_t(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const x=Zo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&x&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Zo(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Zo(e){return(e==null?void 0:e.animationName)||"none"}function Ky(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Fi="rovingFocusGroup.onEntryFocus",qy={bubbles:!1,cancelable:!0},Wr="RovingFocusGroup",[$i,du,Gy]=vi(Wr),[Yy,fu]=In(Wr,[Gy]),[Xy,Jy]=Yy(Wr),pu=v.forwardRef((e,t)=>u.jsx($i.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx($i.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Zy,{...e,ref:t})})}));pu.displayName=Wr;var Zy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Ue(t,p),m=Lo(s),[x,y]=xr({prop:i,defaultProp:a??null,onChange:l,caller:Wr}),[g,w]=v.useState(!1),S=Rt(c),k=du(n),T=v.useRef(!1),[C,E]=v.useState(0);return v.useEffect(()=>{const j=p.current;if(j)return j.addEventListener(Fi,S),()=>j.removeEventListener(Fi,S)},[S]),u.jsx(Xy,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:x,onItemFocus:v.useCallback(j=>y(j),[y]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>E(j=>j-1),[]),children:u.jsx(Re.div,{tabIndex:g||C===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:ue(e.onMouseDown,()=>{T.current=!0}),onFocus:ue(e.onFocus,j=>{const N=!T.current;if(j.target===j.currentTarget&&N&&!g){const A=new CustomEvent(Fi,qy);if(j.currentTarget.dispatchEvent(A),!A.defaultPrevented){const O=k().filter(_=>_.focusable),F=O.find(_=>_.active),$=O.find(_=>_.id===x),z=[F,$,...O].filter(Boolean).map(_=>_.ref.current);gu(z,d)}}T.current=!1}),onBlur:ue(e.onBlur,()=>w(!1))})})}),hu="RovingFocusGroupItem",mu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Nn(),c=s||l,d=Jy(hu,n),f=d.currentTabStopId===c,p=du(n),{onFocusableItemAdd:h,onFocusableItemRemove:m,currentTabStopId:x}=d;return v.useEffect(()=>{if(r)return h(),()=>m()},[r,h,m]),u.jsx($i.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Re.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ue(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:ue(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ue(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=tv(y,d.orientation,d.dir);if(g!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?nv(S,k+1):S.slice(k+1)}setTimeout(()=>gu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});mu.displayName=hu;var Qy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ev(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function tv(e,t,n){const r=ev(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Qy[r]}function gu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function nv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rv=pu,ov=mu,sv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Sr=new WeakMap,Qo=new WeakMap,es={},zi=0,xu=function(e){return e&&(e.host||xu(e.parentNode))},iv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=xu(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},av=function(e,t,n,r){var o=iv(t,Array.isArray(e)?e:[e]);es[n]||(es[n]=new WeakMap);var s=es[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),m=h!==null&&h!=="false",x=(Sr.get(p)||0)+1,y=(s.get(p)||0)+1;Sr.set(p,x),s.set(p,y),i.push(p),x===1&&m&&Qo.set(p,!0),y===1&&p.setAttribute(n,"true"),m||p.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",p,g)}})};return d(t),a.clear(),zi++,function(){i.forEach(function(f){var p=Sr.get(f)-1,h=s.get(f)-1;Sr.set(f,p),s.set(f,h),p||(Qo.has(f)||f.removeAttribute(r),Qo.delete(f)),h||f.removeAttribute(n)}),zi--,zi||(Sr=new WeakMap,Sr=new WeakMap,Qo=new WeakMap,es={})}},Bi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=sv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),av(r,o,n,"aria-hidden")):function(){return null}},bn=function(){return bn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},bn.apply(this,arguments)};function yu(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function lv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var ts="right-scroll-bar-position",ns="width-before-scroll-bar",cv="with-scroll-bars-hidden",uv="--removed-body-scroll-bar-size";function Hi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function dv(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var fv=typeof window<"u"?v.useLayoutEffect:v.useEffect,vu=new WeakMap;function pv(e,t){var n=dv(null,function(r){return e.forEach(function(o){return Hi(o,r)})});return fv(function(){var r=vu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Hi(a,null)}),s.forEach(function(a){o.has(a)||Hi(a,i)})}vu.set(n,e)},[e]),n}function hv(e){return e}function mv(e,t){t===void 0&&(t=hv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function gv(e){e===void 0&&(e={});var t=mv(null);return t.options=bn({async:!0,ssr:!1},e),t}var wu=function(e){var t=e.sideCar,n=yu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,bn({},n))};wu.isSideCarExport=!0;function xv(e,t){return e.useMedium(t),wu}var bu=gv(),Ui=function(){},rs=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Ui,onWheelCapture:Ui,onTouchMoveCapture:Ui}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,m=e.noIsolation,x=e.inert,y=e.allowPinchZoom,g=e.as,w=g===void 0?"div":g,S=e.gapMode,k=yu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=p,C=pv([n,t]),E=bn(bn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(T,{sideCar:bu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:m,inert:x,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),bn(bn({},E),{ref:C})):v.createElement(w,bn({},E,{className:l,ref:C}),a))});rs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},rs.classNames={fullWidth:ns,zeroRight:ts};var yv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function vv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function bv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Sv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=vv())&&(wv(t,n),bv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Cv=function(){var e=Sv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Su=function(){var e=Cv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Tv={left:0,top:0,right:0,gap:0},Wi=function(e){return parseInt(e||"",10)||0},kv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Wi(n),Wi(r),Wi(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Tv;var t=kv(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Iv=Su(),Cr="data-scroll-locked",Nv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
38
|
+
`)}const cc=200;function Jg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),p=b.useRef(null),h=b.useCallback(N=>{try{const A=globalThis.structuredClone;if(typeof A=="function")return A(N)}catch{}try{return JSON.parse(JSON.stringify(N))}catch{return N}},[]),m=b.useCallback((N,A)=>{if(!N)return;const O=f.current.get(N)??[],F=h(A),$=O.length>=cc?[...O.slice(O.length-cc+1),F]:[...O,F];f.current.set(N,$)},[h]),x=b.useCallback(N=>{N&&f.current.set(N,[])},[]),y=b.useCallback(N=>{const A=N??d.current;if(!A)return;const O=f.current.get(A);O!=null&&O.length&&O.forEach(F=>{try{n(F)}catch($){console.error("[useChatStreamingService] Failed to replay buffered event",$)}})},[n]),g=b.useCallback(N=>{var F,$,R,z,_;const A=N.seq??null;if(A!==null){const B=c.current;if(B!==null){if(A<=B)return;A>B+1&&(o==null||o({from:B,to:A}))}c.current=A}if(N.type==="thread_info"){d.current=N.threadId,p.current&&(p.current.threadIdGuess=N.threadId),x(N.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",N);try{t(N)}catch(B){console.error("[useChatStreamingService] Error in onThreadInfo handler:",B)}return}if(N.type==="heartbeat"){try{l==null||l(N)}catch(B){console.error("[useChatStreamingService] Error in onHeartbeat handler:",B)}return}if(N.type==="error"){const B=N;if(B.error_type==="auth_error"||B.code==="TOKEN_EXPIRED"||((F=B.message)==null?void 0:F.includes("token"))||(($=B.message)==null?void 0:$.includes("401"))||((R=B.message)==null?void 0:R.includes("unauthorized"))||((z=B.message)==null?void 0:z.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",B.message);try{a==null||a(B.message)}catch(M){console.warn("[useChatStreamingService] onAuthError handler failed",M)}}}const O=N.threadId??(N.type==="state_history"?N.threadId:void 0)??d.current??((_=p.current)==null?void 0:_.threadIdGuess)??null;if(N.type==="state_history"&&(d.current=O??d.current),Hg(N)){N.type==="checkpoint"||N.type==="state_history"?x(O??null):m(O??null,N);try{n(N)}catch(B){console.error("[useChatStreamingService] Error in onMessageEvent handler:",B)}return}try{r==null||r(N)}catch(B){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",B)}},[m,x,n,o,t,r]),{stream:w,stop:S,isStreaming:k,error:T,setToken:C}=lc({baseUrl:e,token:void 0}),E=b.useCallback((N,A)=>{c.current=null,d.current=N.threadId??null,p.current={request:N,callbacks:A,manualStop:!1,threadIdGuess:N.threadId??null},w(N,g,{onOpen:A==null?void 0:A.onOpen,onError:O=>{var F;(F=A==null?void 0:A.onError)==null||F.call(A,O)},onGap:(A==null?void 0:A.onGap)??o,onConnectionError:O=>{var F;i==null||i(O),(F=A==null?void 0:A.onConnectionError)==null||F.call(A,O)},onAuthError:O=>{var F;a==null||a(O),(F=A==null?void 0:A.onAuthError)==null||F.call(A,O)},onHeartbeat:O=>{var F;try{l==null||l(O)}catch($){console.warn("[useChatStreamingService] onHeartbeat handler failed",$)}try{(F=A==null?void 0:A.onHeartbeat)==null||F.call(A,O)}catch($){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",$)}},onClosed:O=>{var z,_,B,L;const F=((z=p.current)==null?void 0:z.manualStop)??!1,$=d.current??((_=p.current)==null?void 0:_.threadIdGuess)??((B=O.lastStateHistory)==null?void 0:B.threadId)??null;(O.reason==="complete"||O.reason==="aborted"&&F)&&x($);const R={...O,threadId:$,manualStop:F};try{s==null||s(R)}catch(M){console.warn("[useChatStreamingService] onStreamClosed handler failed",M)}try{(L=A==null?void 0:A.onClosed)==null||L.call(A,R)}catch(M){console.warn("[useChatStreamingService] downstream onClosed handler failed",M)}p.current&&(p.current=null)}})},[x,g,a,i,l,o,s,w]),j=b.useCallback(()=>{p.current&&(p.current.manualStop=!0),S()},[S]);return b.useMemo(()=>({startStream:E,stop:j,isStreaming:k,error:T,setAuthToken:C,replayBufferedEvents:y}),[E,j,k,T,C,y])}const uc=b.createContext(null),dc=b.createContext(null),fc=b.createContext(null);b.createContext(!1);function Zg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,checkpointMetadataCache:l}){const{api:c,baseUrl:d}=fi(),f=b.useMemo(()=>En(d),[d]),[p,h]=b.useState([]),[m,x]=b.useState(t),[y,g]=b.useState(!1),[w,S]=b.useState(null),[k,T]=b.useState(!1),[C,E]=b.useState(null),{state:j,seed:N,prepend:A,pushUser:O,onEvent:F}=ec(),[$,R]=b.useState(!1),[z,_]=b.useState(!1),[B,L]=b.useState(null),[M,J]=b.useState([]),[X,he]=b.useState(!1),Ne=l??Bg(),{setCacheForThread:_e}=Ne,V=b.useRef(m),ee=b.useRef(null);b.useEffect(()=>{V.current=m},[m]);const q=b.useRef(),{startStream:D,stop:H,isStreaming:te,error:se,setAuthToken:ne}=Jg({baseUrl:f,onThreadInfo:de=>{console.log("[ChatSessionProvider] Thread info:",de.threadId),V.current!==de.threadId&&x(de.threadId)},onMessageEvent:F,onUnhandledEvent:de=>{console.warn("[ChatSessionProvider] Unhandled event:",de.type)},onAuthError:i}),ke=b.useCallback(async()=>{g(!0),S(null);try{const de=await c.listThreads();h(de??[])}catch(de){const pe=String(de);S(pe),s==null||s(pe)}finally{g(!1)}},[c,s]),Z=b.useCallback(async de=>{try{const pe=await c.createThread(de);return x(pe.threadId),await ke(),pe.threadId}catch(pe){return s==null||s(String(pe)),null}},[c,ke,s]),fe=b.useCallback(async de=>{try{await c.deleteThread(de),V.current===de&&(x(null),N([],{})),await ke()}catch(pe){s==null||s(String(pe))}},[c,ke,N,s]),Ie=b.useCallback(async(de,pe)=>{try{await c.updateThread(de,pe),await ke()}catch(me){s==null||s(String(me))}},[c,ke,s]),Ae=b.useCallback((de,pe,me)=>{const ze=pe.filter(De=>De.checkpointId).map(De=>({checkpointId:De.checkpointId,checkpointNs:De.checkpointNs??void 0,createdAt:De.createdAt??""}));console.log(`[ChatSessionProvider] Cached metadata for ${ze.length} checkpoints from ${me}`),_e(de,ze)},[_e]),Fe=b.useCallback(async(de,pe)=>{if(de){T(!0),E(null);try{const me=await c.getStateHistory({threadId:de,checkpointId:pe||void 0}),{checkpoints:ze}=$r(me);Ae(de,ze,`thread load (requested: ${pe})`);const De=ze.find(ot=>ot.messages&&ot.messages.length>0)??(pe?ze.find(ot=>ot.checkpointId===pe):null)??ze[0];N((De==null?void 0:De.messages)??[],{checkpointId:(De==null?void 0:De.checkpointId)??null,checkpointNs:(De==null?void 0:De.checkpointNs)??null}),J(ze),R(!!(De!=null&&De.nextCursor)),L((De==null?void 0:De.nextCursor)??null)}catch(me){const ze=String(me);E(ze),s==null||s(ze)}finally{T(!1)}}},[c,N,s,Ae]);b.useEffect(()=>{q.current=Fe},[Fe]);const Ze=b.useCallback(async(de,pe)=>{const me=V.current;if(me){he(!0);try{const ze=await c.getStateHistory({threadId:me,checkpointId:de,checkpointNs:pe??void 0}),{checkpoints:De}=$r(ze);Ae(me,De,"checkpoint navigation");const ot=De.find(Et=>Et.checkpointId===de&&(pe?Et.checkpointNs===pe:!0));if(!ot){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:de,checkpointNs:pe});return}J(De),N(ot.messages??[],{checkpointId:ot.checkpointId??null,checkpointNs:ot.checkpointNs??null})}catch(ze){s==null||s(String(ze))}finally{he(!1)}}},[c,N,s,Ae]),Ve=b.useCallback((de,pe)=>{N(j.messages,{checkpointId:de??null,checkpointNs:pe??null})},[N,j.messages]),Ke=b.useCallback(async()=>{V.current&&await Fe(V.current)},[Fe]),qe=b.useCallback(async()=>{if(!(!V.current||!B)){_(!0);try{const de=await c.getStateHistory({threadId:V.current,checkpointId:B}),{checkpoints:pe}=$r(de);if(pe.length>0){const me=pe[pe.length-1];A((me==null?void 0:me.messages)??[]),R(!!(me!=null&&me.nextCursor)),L((me==null?void 0:me.nextCursor)??null)}}catch(de){s==null||s(String(de))}finally{_(!1)}}},[c,B,A,s]),Xe=b.useCallback(async()=>{N([],{}),x(null),H(),J([]),R(!1),L(null)},[N,H]),Qe=b.useCallback(async(de,pe,me)=>{const ze=V.current;if(!ze)throw new Error("No active thread to handle interrupt");const De=pe?me??!0:!1;try{const ot={threadId:ze,checkpointId:j.lastCheckpointId??void 0,checkpointNs:j.lastCheckpointNs??void 0,command:{kind:"resume",value:De}};D(ot)}catch(ot){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${de}:`,ot),ot}},[j.lastCheckpointId,j.lastCheckpointNs,D]);b.useEffect(()=>{ke()},[ke]),b.useEffect(()=>{var de,pe;!o||!m||k||ee.current!==m&&(ee.current=m,n?(console.log("[ChatSessionProvider] Loading thread with checkpoint:",n),(de=q.current)==null||de.call(q,m,n)):(console.log("[ChatSessionProvider] Loading thread with latest checkpoint"),(pe=q.current)==null||pe.call(q,m)))},[o,m,k,n,r]),b.useEffect(()=>{a==null||a(m)},[m,a]);const et=b.useCallback(async(de,pe)=>{const me=V.current,ze=(de==null?void 0:de.text)??"";if(!me&&!ze)return;if(!me){await Z("New Chat");return}const{contentParts:De}=await Tg(c,(de==null?void 0:de.attachments)??[]),ot=[...De];ze!=null&&ze.trim()&&ot.push({type:"text",text:ze});const Et={id:`msg-${Date.now()}`,role:"user",content:ot,createdAt:new Date().toISOString()};O(Et);const st={threadId:me,payload:{messages:[Et]},checkpointId:(pe==null?void 0:pe.checkpointId)??j.lastCheckpointId??void 0,checkpointNs:(pe==null?void 0:pe.checkpointNs)??j.lastCheckpointNs??void 0};D(st)},[c,Z,O,j,D]),Nt=b.useMemo(()=>({threads:p,currentThreadId:m,setCurrentThreadId:x,isLoading:y,error:w,actions:{createThread:Z,deleteThread:fe,renameThread:Ie,refreshThreads:ke}}),[p,m,y,w,Z,fe,Ie,ke]),mt=b.useMemo(()=>({threadId:m,messages:j.messages,interrupt:null,checkpoint:{id:j.lastCheckpointId??null,namespace:j.lastCheckpointNs??null},checkpoints:M,metadata:null,isLoading:k,isHistoryLoading:z,isLoadingCheckpoint:X,error:C,hasMore:$,loadOlder:qe,clearState:Xe,navigateToCheckpoint:Ze,setCurrentCheckpointId:Ve,returnToLatest:Ke,loadThread:Fe,clearThread:Xe,respondToInterrupt:Qe}),[m,j,M,k,z,X,C,$,qe,Xe,Ze,Ve,Ke,Fe,Qe]),at=b.useMemo(()=>({isStreaming:te,error:se,connectionState:te?"connected":"idle",submit:et,send:et,stop:H,setAuthToken:ne}),[te,se,et,H,ne]);return u.jsx(uc.Provider,{value:Nt,children:u.jsx(dc.Provider,{value:mt,children:u.jsx(fc.Provider,{value:at,children:e})})})}function Oo(){const e=b.useContext(uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){const e=b.useContext(dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function pc(){const e=b.useContext(fc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Do({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c}){return u.jsx(Sg,{apiConfig:t,children:u.jsx(Zg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c,children:e})})}function Q(...e){return Yh.twMerge(Gh.clsx(e))}const Qg=xo.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),nt=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yn.Slot:"button";return u.jsx(i,{className:Q(Qg({variant:t,size:n,className:e})),ref:s,...o})});nt.displayName="Button";const hc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:Q("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));hc.displayName="Textarea";function mc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const m=i!==void 0,[x,y]=b.useState(e),g=(m?i:x)??"",[w,S]=b.useTransition(),k=b.useRef(null),T=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{m||(y(e??""),C.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const z=k.current;z&&(z.style.height="auto",z.style.height=`${z.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,g]);const j=b.useCallback((z,{fromUser:_})=>{m||y(z),_&&(a==null||a(z))},[m,a]),N=b.useCallback(async z=>{z&&z.preventDefault();const _=(g??"").trim();if(!_&&!h)return;const B=++T.current;C.current={id:B,shouldClear:!0},S(()=>{var L,M,J;try{const X=l(_);X&&typeof X.then=="function"?X.then(()=>{var he,Ne;((he=C.current)==null?void 0:he.id)===B&&C.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((Ne=C.current)==null?void 0:Ne.id)===B&&(C.current=null)}).catch(()=>{var he;((he=C.current)==null?void 0:he.id)===B&&(C.current=null)}):(((L=C.current)==null?void 0:L.id)===B&&C.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=C.current)==null?void 0:M.id)===B&&(C.current=null))}catch{((J=C.current)==null?void 0:J.id)===B&&(C.current=null)}})},[g,l,h,m,a]),A=b.useCallback(z=>{const _=z.target.value;j(_,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[j]),O=b.useCallback(z=>{z.key==="Enter"&&!z.shiftKey?(z.preventDefault(),N()):z.key==="Escape"&&t&&(z.preventDefault(),c==null||c())},[N,t,c]),R=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:z=>void N(z),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(hc,{ref:k,value:g,onChange:A,onKeyDown:O,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(nt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(oe.Square,{size:16})}):u.jsx(nt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||w,children:u.jsx(oe.Send,{size:16})})})]})})}const ex=b.memo(mc);function ue(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function gc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=gc(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():gc(e[o],null)}}}}function Ue(...e){return v.useCallback(yi(...e),e)}function tx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function In(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:p,children:h,...m}=f,x=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(x.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var x;const h=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,m=v.useContext(h);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,nx(o,...t)]}function nx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var _t=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},rx=v[" useInsertionEffect ".trim().toString()]||_t;function xr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ox({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=sx(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function ox({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return rx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function sx(e){return typeof e=="function"}var ix=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Re=ix.reduce((e,t)=>{const n=Yn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xc(e,t){e&&yo.flushSync(()=>e.dispatchEvent(t))}function vi(e){const t=e+"CollectionProvider",[n,r]=In(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:y,children:g}=x,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:w,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Yn.createSlot(a),c=b.forwardRef((x,y)=>{const{scope:g,children:w}=x,S=s(a,g),k=Ue(y,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Yn.createSlot(d),h=b.forwardRef((x,y)=>{const{scope:g,children:w,...S}=x,k=b.useRef(null),T=Ue(y,k),C=s(d,g);return b.useEffect(()=>(C.itemMap.set(k,{ref:k,...S}),()=>void C.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:T,children:w})});h.displayName=d;function m(x){const y=s(e+"CollectionConsumer",x);return b.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},m,r]}var ax=v.createContext(void 0);function Lo(e){const t=v.useContext(ax);return e||t||"ltr"}function Rt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function lx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var cx="DismissableLayer",wi="dismissableLayer.update",ux="dismissableLayer.pointerDownOutside",dx="dismissableLayer.focusOutside",yc,vc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Fo=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(vc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),m=Ue(t,E=>f(E)),x=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=x.indexOf(y),w=d?x.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=g,T=hx(E=>{const j=E.target,N=[...c.branches].some(A=>A.contains(j));!k||N||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),C=mx(E=>{const j=E.target;[...c.branches].some(A=>A.contains(j))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return lx(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(yc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=yc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wc())},[d,c]),v.useEffect(()=>{const E=()=>h({});return document.addEventListener(wi,E),()=>document.removeEventListener(wi,E)},[]),u.jsx(Re.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:ue(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ue(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ue(e.onPointerDownCapture,T.onPointerDownCapture)})});Fo.displayName=cx;var fx="DismissableLayerBranch",px=v.forwardRef((e,t)=>{const n=v.useContext(vc),r=v.useRef(null),o=Ue(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Re.div,{...e,ref:o})});px.displayName=fx;function hx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){bc(ux,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function mx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&bc(dx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function wc(){const e=new CustomEvent(wi);document.dispatchEvent(e)}function bc(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?xc(o,s):o.dispatchEvent(s)}var bi=0;function Si(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sc()),document.body.insertAdjacentElement("beforeend",e[1]??Sc()),bi++,()=>{bi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),bi--}},[])}function Sc(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Ci="focusScope.autoFocusOnMount",Ti="focusScope.autoFocusOnUnmount",Cc={bubbles:!1,cancelable:!0},gx="FocusScope",$o=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Rt(o),d=Rt(s),f=v.useRef(null),p=Ue(t,x=>l(x)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let x=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:On(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||On(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const T of S)T.removedNodes.length>0&&On(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",y);const w=new MutationObserver(g);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",y),w.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){Ec.add(h);const x=document.activeElement;if(!a.contains(x)){const g=new CustomEvent(Ci,Cc);a.addEventListener(Ci,c),a.dispatchEvent(g),g.defaultPrevented||(xx(Sx(Tc(a)),{select:!0}),document.activeElement===x&&On(a))}return()=>{a.removeEventListener(Ci,c),setTimeout(()=>{const g=new CustomEvent(Ti,Cc);a.addEventListener(Ti,d),a.dispatchEvent(g),g.defaultPrevented||On(x??document.body,{select:!0}),a.removeEventListener(Ti,d),Ec.remove(h)},0)}}},[a,c,d,h]);const m=v.useCallback(x=>{if(!n&&!r||h.paused)return;const y=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,g=document.activeElement;if(y&&g){const w=x.currentTarget,[S,k]=yx(w);S&&k?!x.shiftKey&&g===k?(x.preventDefault(),n&&On(S,{select:!0})):x.shiftKey&&g===S&&(x.preventDefault(),n&&On(k,{select:!0})):g===w&&x.preventDefault()}},[n,r,h.paused]);return u.jsx(Re.div,{tabIndex:-1,...i,ref:p,onKeyDown:m})});$o.displayName=gx;function xx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(On(r,{select:t}),document.activeElement!==n)return}function yx(e){const t=Tc(e),n=kc(t,e),r=kc(t.reverse(),e);return[n,r]}function Tc(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function kc(e,t){for(const n of e)if(!vx(n,{upTo:t}))return n}function vx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function wx(e){return e instanceof HTMLInputElement&&"select"in e}function On(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var Ec=bx();function bx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Ic(e,t),e.unshift(t)},remove(t){var n;e=Ic(e,t),(n=e[0])==null||n.resume()}}}function Ic(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Sx(e){return e.filter(t=>t.tagName!=="A")}var Cx=v[" useId ".trim().toString()]||(()=>{}),Tx=0;function Nn(e){const[t,n]=v.useState(Cx());return _t(()=>{n(r=>r??String(Tx++))},[e]),t?`radix-${t}`:""}const kx=["top","right","bottom","left"],Mn=Math.min,Gt=Math.max,zo=Math.round,Bo=Math.floor,xn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ix={start:"end",end:"start"};function ki(e,t,n){return Gt(e,Mn(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function jn(e){return e.split("-")[0]}function yr(e){return e.split("-")[1]}function Ei(e){return e==="x"?"y":"x"}function Ii(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function yn(e){return Nx.has(jn(e))?"y":"x"}function Ni(e){return Ei(yn(e))}function Ax(e,t,n){n===void 0&&(n=!1);const r=yr(e),o=Ni(e),s=Ii(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ho(i)),[i,Ho(i)]}function jx(e){const t=Ho(e);return[Ai(e),t,Ai(t)]}function Ai(e){return e.replace(/start|end/g,t=>Ix[t])}const Nc=["left","right"],Ac=["right","left"],_x=["top","bottom"],Rx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Ac:Nc:t?Nc:Ac;case"left":case"right":return t?_x:Rx;default:return[]}}function Ox(e,t,n,r){const o=yr(e);let s=Px(jn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ai)))),s}function Ho(e){return e.replace(/left|right|bottom|top/g,t=>Ex[t])}function Mx(e){return{top:0,right:0,bottom:0,left:0,...e}}function jc(e){return typeof e!="number"?Mx(e):{top:e,right:e,bottom:e,left:e}}function Uo(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function _c(e,t,n){let{reference:r,floating:o}=e;const s=yn(t),i=Ni(t),a=Ii(i),l=jn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(yr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Dx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=_c(c,r,l),p=r,h={},m=0;for(let x=0;x<a.length;x++){const{name:y,fn:g}=a[x],{x:w,y:S,data:k,reset:T}=await g({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,h={...h,[y]:{...h[y],...k}},T&&m<=50&&(m++,typeof T=="object"&&(T.placement&&(p=T.placement),T.rects&&(c=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=_c(c,p,l)),x=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Br(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=An(t,e),m=jc(h),y=a[p?f==="floating"?"reference":"floating":f],g=Uo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},T=Uo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(g.top-T.top+m.top)/k.y,bottom:(T.bottom-g.bottom+m.bottom)/k.y,left:(g.left-T.left+m.left)/k.x,right:(T.right-g.right+m.right)/k.x}}const Lx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const f=jc(d),p={x:n,y:r},h=Ni(o),m=Ii(h),x=await i.getDimensions(c),y=h==="y",g=y?"top":"left",w=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[h]-p[h]-s.floating[m],T=p[h]-s.reference[h],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[m]);const j=k/2-T/2,N=E/2-x[m]/2-1,A=Mn(f[g],N),O=Mn(f[w],N),F=A,$=E-x[m]-O,R=E/2-x[m]/2+j,z=ki(F,R,$),_=!l.arrow&&yr(o)!=null&&R!==z&&s.reference[m]/2-(R<F?A:O)-x[m]/2<0,B=_?R<F?R-F:R-$:0;return{[h]:p[h]+B,data:{[h]:z,centerOffset:R-z-B,..._&&{alignmentOffset:B}},reset:_}}}),Fx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:x=!0,...y}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=jn(o),w=yn(a),S=jn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),T=p||(S||!x?[Ho(a)]:jx(a)),C=m!=="none";!p&&C&&T.push(...Ox(a,x,m,k));const E=[a,...T],j=await Br(t,y),N=[];let A=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&N.push(j[g]),f){const R=Ax(o,i,k);N.push(j[R[0]],j[R[1]])}if(A=[...A,{placement:o,overflows:N}],!N.every(R=>R<=0)){var O,F;const R=(((O=s.flip)==null?void 0:O.index)||0)+1,z=E[R];if(z&&(!(f==="alignment"?w!==yn(z):!1)||A.every(L=>yn(L.placement)===w?L.overflows[0]>0:!0)))return{data:{index:R,overflows:A},reset:{placement:z}};let _=(F=A.filter(B=>B.overflows[0]<=0).sort((B,L)=>B.overflows[1]-L.overflows[1])[0])==null?void 0:F.placement;if(!_)switch(h){case"bestFit":{var $;const B=($=A.filter(L=>{if(C){const M=yn(L.placement);return M===w||M==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(M=>M>0).reduce((M,J)=>M+J,0)]).sort((L,M)=>L[1]-M[1])[0])==null?void 0:$[0];B&&(_=B);break}case"initialPlacement":_=a;break}if(o!==_)return{reset:{placement:_}}}return{}}}};function Rc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pc(e){return kx.some(t=>e[t]>=0)}const $x=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=An(e,t);switch(r){case"referenceHidden":{const s=await Br(t,{...o,elementContext:"reference"}),i=Rc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pc(i)}}}case"escaped":{const s=await Br(t,{...o,altBoundary:!0}),i=Rc(s,n.floating);return{data:{escapedOffsets:i,escaped:Pc(i)}}}default:return{}}}}},Oc=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=jn(n),a=yr(n),l=yn(n)==="y",c=Oc.has(i)?-1:1,d=s&&l?-1:1,f=An(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(h=a==="end"?m*-1:m),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Bx=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await zx(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:g,y:w}=y;return{x:g,y:w}}},...l}=An(e,t),c={x:n,y:r},d=await Br(t,l),f=yn(jn(o)),p=Ei(f);let h=c[p],m=c[f];if(s){const y=p==="y"?"top":"left",g=p==="y"?"bottom":"right",w=h+d[y],S=h-d[g];h=ki(w,h,S)}if(i){const y=f==="y"?"top":"left",g=f==="y"?"bottom":"right",w=m+d[y],S=m-d[g];m=ki(w,m,S)}const x=a.fn({...t,[p]:h,[f]:m});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[p]:s,[f]:i}}}}}},Ux=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=An(e,t),d={x:n,y:r},f=yn(o),p=Ei(f);let h=d[p],m=d[f];const x=An(a,t),y=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,T=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>T&&(h=T)}if(c){var g,w;const S=p==="y"?"width":"height",k=Oc.has(jn(o)),T=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:y.crossAxis),C=s.reference[f]+s.reference[S]+(k?0:((w=i.offset)==null?void 0:w[f])||0)-(k?y.crossAxis:0);m<T?m=T:m>C&&(m=C)}return{[p]:h,[f]:m}}}},Wx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=An(e,t),d=await Br(t,c),f=jn(o),p=yr(o),h=yn(o)==="y",{width:m,height:x}=s.floating;let y,g;f==="top"||f==="bottom"?(y=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,y=p==="end"?"top":"bottom");const w=x-d.top-d.bottom,S=m-d.left-d.right,k=Mn(x-d[y],w),T=Mn(m-d[g],S),C=!t.middlewareData.shift;let E=k,j=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(j=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),C&&!p){const A=Gt(d.left,0),O=Gt(d.right,0),F=Gt(d.top,0),$=Gt(d.bottom,0);h?j=m-2*(A!==0||O!==0?A+O:Gt(d.left,d.right)):E=x-2*(F!==0||$!==0?F+$:Gt(d.top,d.bottom))}await l({...t,availableWidth:j,availableHeight:E});const N=await i.getDimensions(a.floating);return m!==N.width||x!==N.height?{reset:{rects:!0}}:{}}}};function Wo(){return typeof window<"u"}function vr(e){return Mc(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function vn(e){var t;return(t=(Mc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Mc(e){return Wo()?e instanceof Node||e instanceof Yt(e).Node:!1}function un(e){return Wo()?e instanceof Element||e instanceof Yt(e).Element:!1}function wn(e){return Wo()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function Dc(e){return!Wo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const Vx=new Set(["inline","contents"]);function Hr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Vx.has(o)}const Kx=new Set(["table","td","th"]);function qx(e){return Kx.has(vr(e))}const Gx=[":popover-open",":modal"];function Vo(e){return Gx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Yx=["transform","translate","scale","rotate","perspective"],Xx=["transform","translate","scale","rotate","perspective","filter"],Jx=["paint","layout","strict","content"];function ji(e){const t=_i(),n=un(e)?dn(e):e;return Yx.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||Xx.some(r=>(n.willChange||"").includes(r))||Jx.some(r=>(n.contain||"").includes(r))}function Zx(e){let t=Dn(e);for(;wn(t)&&!wr(t);){if(ji(t))return t;if(Vo(t))return null;t=Dn(t)}return null}function _i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Qx=new Set(["html","body","#document"]);function wr(e){return Qx.has(vr(e))}function dn(e){return Yt(e).getComputedStyle(e)}function Ko(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Dn(e){if(vr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Dc(e)&&e.host||vn(e);return Dc(t)?t.host:t}function Lc(e){const t=Dn(e);return wr(t)?e.ownerDocument?e.ownerDocument.body:e.body:wn(t)&&Hr(t)?t:Lc(t)}function Ur(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Lc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Ri(i);return t.concat(i,i.visualViewport||[],Hr(o)?o:[],a&&n?Ur(a):[])}return t.concat(o,Ur(o,[],n))}function Ri(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Fc(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=wn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=zo(n)!==s||zo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Pi(e){return un(e)?e:e.contextElement}function br(e){const t=Pi(e);if(!wn(t))return xn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Fc(t);let i=(s?zo(n.width):n.width)/r,a=(s?zo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ey=xn(0);function $c(e){const t=Yt(e);return!_i()||!t.visualViewport?ey:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ty(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function Qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Pi(e);let i=xn(1);t&&(r?un(r)&&(i=br(r)):i=br(e));const a=ty(s,n,r)?$c(s):xn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Yt(s),h=r&&un(r)?Yt(r):r;let m=p,x=Ri(m);for(;x&&r&&h!==m;){const y=br(x),g=x.getBoundingClientRect(),w=dn(x),S=g.left+(x.clientLeft+parseFloat(w.paddingLeft))*y.x,k=g.top+(x.clientTop+parseFloat(w.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,m=Yt(x),x=Ri(m)}}return Uo({width:d,height:f,x:l,y:c})}function qo(e,t){const n=Ko(e).scrollLeft;return t?t.left+n:Qn(vn(e)).left+n}function zc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-qo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=vn(r),a=t?Vo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=xn(1);const d=xn(0),f=wn(r);if((f||!f&&!s)&&((vr(r)!=="body"||Hr(i))&&(l=Ko(r)),wn(r))){const h=Qn(r);c=br(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?zc(i,l):xn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function ry(e){return Array.from(e.getClientRects())}function oy(e){const t=vn(e),n=Ko(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+qo(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Bc=25;function sy(e,t){const n=Yt(e),r=vn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=_i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=qo(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-h);m<=Bc&&(s-=m)}else c<=Bc&&(s+=c);return{width:s,height:i,x:a,y:l}}const iy=new Set(["absolute","fixed"]);function ay(e,t){const n=Qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=wn(e)?br(e):xn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Hc(e,t,n){let r;if(t==="viewport")r=sy(e,n);else if(t==="document")r=oy(vn(e));else if(un(t))r=ay(t,n);else{const o=$c(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Uo(r)}function Uc(e,t){const n=Dn(e);return n===t||!un(n)||wr(n)?!1:dn(n).position==="fixed"||Uc(n,t)}function ly(e,t){const n=t.get(e);if(n)return n;let r=Ur(e,[],!1).filter(a=>un(a)&&vr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Dn(e):e;for(;un(i)&&!wr(i);){const a=dn(i),l=ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&iy.has(o.position)||Hr(i)&&!l&&Uc(e,i))?r=r.filter(d=>d!==i):o=a,i=Dn(i)}return t.set(e,r),r}function cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Vo(t)?[]:ly(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Hc(t,d,o);return c.top=Gt(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Gt(f.left,c.left),c},Hc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function uy(e){const{width:t,height:n}=Fc(e);return{width:t,height:n}}function dy(e,t,n){const r=wn(t),o=vn(t),s=n==="fixed",i=Qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=xn(0);function c(){l.x=qo(o)}if(r||!r&&!s)if((vr(t)!=="body"||Hr(o))&&(a=Ko(t)),r){const h=Qn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?zc(o,a):xn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function Oi(e){return dn(e).position==="static"}function Wc(e,t){if(!wn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return vn(e)===n&&(n=n.ownerDocument.body),n}function Vc(e,t){const n=Yt(e);if(Vo(e))return n;if(!wn(e)){let o=Dn(e);for(;o&&!wr(o);){if(un(o)&&!Oi(o))return o;o=Dn(o)}return n}let r=Wc(e,t);for(;r&&qx(r)&&Oi(r);)r=Wc(r,t);return r&&wr(r)&&Oi(r)&&!ji(r)?n:r||Zx(e)||n}const fy=async function(e){const t=this.getOffsetParent||Vc,n=this.getDimensions,r=await n(e.floating);return{reference:dy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function py(e){return dn(e).direction==="rtl"}const hy={convertOffsetParentRelativeRectToViewportRelativeRect:ny,getDocumentElement:vn,getClippingRect:cy,getOffsetParent:Vc,getElementRects:fy,getClientRects:ry,getDimensions:uy,getScale:br,isElement:un,isRTL:py};function Kc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function my(e,t){let n=null,r;const o=vn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const m=Bo(f),x=Bo(o.clientWidth-(d+p)),y=Bo(o.clientHeight-(f+h)),g=Bo(d),S={rootMargin:-m+"px "+-x+"px "+-y+"px "+-g+"px",threshold:Gt(0,Mn(1,l))||1};let k=!0;function T(C){const E=C[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Kc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(T,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,S)}n.observe(e)}return i(!0),s}function gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Pi(e),d=o||s?[...c?Ur(c):[],...Ur(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?my(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(g=>{let[w]=g;w&&w.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let m,x=l?Qn(e):null;l&&y();function y(){const g=Qn(e);x&&!Kc(x,g)&&n(),x=g,m=requestAnimationFrame(y)}return n(),()=>{var g;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(g=h)==null||g.disconnect(),h=null,l&&cancelAnimationFrame(m)}}const xy=Bx,yy=Hx,vy=Fx,wy=Wx,by=$x,qc=Lx,Sy=Ux,Cy=(e,t,n)=>{const r=new Map,o={platform:hy,...n},s={...o.platform,_c:r};return Dx(e,t,{...o,platform:s})};var Ty=typeof document<"u",ky=function(){},Go=Ty?b.useLayoutEffect:ky;function Yo(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Yo(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Yo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Gc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yc(e,t){const n=Gc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Go(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Yo(p,r)||h(r);const[m,x]=v.useState(null),[y,g]=v.useState(null),w=v.useCallback(L=>{L!==C.current&&(C.current=L,x(L))},[]),S=v.useCallback(L=>{L!==E.current&&(E.current=L,g(L))},[]),k=s||m,T=i||y,C=v.useRef(null),E=v.useRef(null),j=v.useRef(d),N=l!=null,A=Mi(l),O=Mi(o),F=Mi(c),$=v.useCallback(()=>{if(!C.current||!E.current)return;const L={placement:t,strategy:n,middleware:p};O.current&&(L.platform=O.current),Cy(C.current,E.current,L).then(M=>{const J={...M,isPositioned:F.current!==!1};R.current&&!Yo(j.current,J)&&(j.current=J,yo.flushSync(()=>{f(J)}))})},[p,t,n,O,F]);Go(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[c]);const R=v.useRef(!1);Go(()=>(R.current=!0,()=>{R.current=!1}),[]),Go(()=>{if(k&&(C.current=k),T&&(E.current=T),k&&T){if(A.current)return A.current(k,T,$);$()}},[k,T,$,A,N]);const z=v.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),_=v.useMemo(()=>({reference:k,floating:T}),[k,T]),B=v.useMemo(()=>{const L={position:n,left:0,top:0};if(!_.floating)return L;const M=Yc(_.floating,d.x),J=Yc(_.floating,d.y);return a?{...L,transform:"translate("+M+"px, "+J+"px)",...Gc(_.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:J}},[n,a,_.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:$,refs:z,elements:_,floatingStyles:B}),[d,$,z,_,B])}const Iy=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?qc({element:r.current,padding:o}).fn(n):{}:r?qc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...xy(e),options:[e,t]}),Ay=(e,t)=>({...yy(e),options:[e,t]}),jy=(e,t)=>({...Sy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),Ry=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...by(e),options:[e,t]}),Oy=(e,t)=>({...Iy(e),options:[e,t]});var My="Arrow",Xc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Re.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Xc.displayName=My;var Dy=Xc;function Jc(e){const[t,n]=v.useState(void 0);return _t(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Di="Popper",[Zc,Xo]=In(Di),[Ly,Qc]=Zc(Di),eu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(Ly,{scope:t,anchor:r,onAnchorChange:o,children:n})};eu.displayName=Di;var tu="PopperAnchor",nu=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Qc(tu,n),i=v.useRef(null),a=Ue(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Re.div,{...o,ref:a})});nu.displayName=tu;var Li="PopperContent",[Fy,$y]=Zc(Li),ru=v.forwardRef((e,t)=>{var q,D,H,te,se,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:m,...x}=e,y=Qc(Li,n),[g,w]=v.useState(null),S=Ue(t,ke=>w(ke)),[k,T]=v.useState(null),C=Jc(k),E=(C==null?void 0:C.width)??0,j=(C==null?void 0:C.height)??0,N=r+(s!=="center"?"-"+s:""),A=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},O=Array.isArray(c)?c:[c],F=O.length>0,$={padding:A,boundary:O.filter(By),altBoundary:F},{refs:R,floatingStyles:z,placement:_,isPositioned:B,middlewareData:L}=Ey({strategy:"fixed",placement:N,whileElementsMounted:(...ke)=>gy(...ke,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Ny({mainAxis:o+j,alignmentAxis:i}),l&&Ay({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...$}),l&&_y({...$}),Ry({...$,apply:({elements:ke,rects:Z,availableWidth:fe,availableHeight:Ie})=>{const{width:Ae,height:Fe}=Z.reference,Ze=ke.floating.style;Ze.setProperty("--radix-popper-available-width",`${fe}px`),Ze.setProperty("--radix-popper-available-height",`${Ie}px`),Ze.setProperty("--radix-popper-anchor-width",`${Ae}px`),Ze.setProperty("--radix-popper-anchor-height",`${Fe}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:E,arrowHeight:j}),p&&Py({strategy:"referenceHidden",...$})]}),[M,J]=iu(_),X=Rt(m);_t(()=>{B&&(X==null||X())},[B,X]);const he=(q=L.arrow)==null?void 0:q.x,Ne=(D=L.arrow)==null?void 0:D.y,_e=((H=L.arrow)==null?void 0:H.centerOffset)!==0,[V,ee]=v.useState();return _t(()=>{g&&ee(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:B?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:V,"--radix-popper-transform-origin":[(te=L.transformOrigin)==null?void 0:te.x,(se=L.transformOrigin)==null?void 0:se.y].join(" "),...((ne=L.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Fy,{scope:n,placedSide:M,onArrowChange:T,arrowX:he,arrowY:Ne,shouldHideArrow:_e,children:u.jsx(Re.div,{"data-side":M,"data-align":J,...x,ref:S,style:{...x.style,animation:B?void 0:"none"}})})})});ru.displayName=Li;var ou="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},su=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=$y(ou,r),i=zy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Dy,{...o,ref:n,style:{...o.style,display:"block"}})})});su.displayName=ou;function By(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var y,g,w;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=iu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,h=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",x="";return c==="bottom"?(m=i?f:`${p}px`,x=`${-l}px`):c==="top"?(m=i?f:`${p}px`,x=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,x=i?f:`${h}px`):c==="left"&&(m=`${r.floating.width+l}px`,x=i?f:`${h}px`),{data:{x:m,y:x}}}});function iu(e){const[t,n="center"]=e.split("-");return[t,n]}var au=eu,lu=nu,cu=ru,uu=su,Uy="Portal",Jo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);_t(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Js.createPortal(u.jsx(Re.div,{...r,ref:t}),i):null});Jo.displayName=Uy;function Wy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var tn=e=>{const{present:t,children:n}=e,r=Vy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Ue(r.ref,Ky(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};tn.displayName="Presence";function Vy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Zo(r.current);s.current=a==="mounted"?c:"none"},[a]),_t(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Zo(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),_t(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const x=Zo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&x&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Zo(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Zo(e){return(e==null?void 0:e.animationName)||"none"}function Ky(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Fi="rovingFocusGroup.onEntryFocus",qy={bubbles:!1,cancelable:!0},Wr="RovingFocusGroup",[$i,du,Gy]=vi(Wr),[Yy,fu]=In(Wr,[Gy]),[Xy,Jy]=Yy(Wr),pu=v.forwardRef((e,t)=>u.jsx($i.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx($i.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Zy,{...e,ref:t})})}));pu.displayName=Wr;var Zy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Ue(t,p),m=Lo(s),[x,y]=xr({prop:i,defaultProp:a??null,onChange:l,caller:Wr}),[g,w]=v.useState(!1),S=Rt(c),k=du(n),T=v.useRef(!1),[C,E]=v.useState(0);return v.useEffect(()=>{const j=p.current;if(j)return j.addEventListener(Fi,S),()=>j.removeEventListener(Fi,S)},[S]),u.jsx(Xy,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:x,onItemFocus:v.useCallback(j=>y(j),[y]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(j=>j+1),[]),onFocusableItemRemove:v.useCallback(()=>E(j=>j-1),[]),children:u.jsx(Re.div,{tabIndex:g||C===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:ue(e.onMouseDown,()=>{T.current=!0}),onFocus:ue(e.onFocus,j=>{const N=!T.current;if(j.target===j.currentTarget&&N&&!g){const A=new CustomEvent(Fi,qy);if(j.currentTarget.dispatchEvent(A),!A.defaultPrevented){const O=k().filter(_=>_.focusable),F=O.find(_=>_.active),$=O.find(_=>_.id===x),z=[F,$,...O].filter(Boolean).map(_=>_.ref.current);gu(z,d)}}T.current=!1}),onBlur:ue(e.onBlur,()=>w(!1))})})}),hu="RovingFocusGroupItem",mu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Nn(),c=s||l,d=Jy(hu,n),f=d.currentTabStopId===c,p=du(n),{onFocusableItemAdd:h,onFocusableItemRemove:m,currentTabStopId:x}=d;return v.useEffect(()=>{if(r)return h(),()=>m()},[r,h,m]),u.jsx($i.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Re.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ue(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:ue(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ue(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=tv(y,d.orientation,d.dir);if(g!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?nv(S,k+1):S.slice(k+1)}setTimeout(()=>gu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});mu.displayName=hu;var Qy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ev(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function tv(e,t,n){const r=ev(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Qy[r]}function gu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function nv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rv=pu,ov=mu,sv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Sr=new WeakMap,Qo=new WeakMap,es={},zi=0,xu=function(e){return e&&(e.host||xu(e.parentNode))},iv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=xu(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},av=function(e,t,n,r){var o=iv(t,Array.isArray(e)?e:[e]);es[n]||(es[n]=new WeakMap);var s=es[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),m=h!==null&&h!=="false",x=(Sr.get(p)||0)+1,y=(s.get(p)||0)+1;Sr.set(p,x),s.set(p,y),i.push(p),x===1&&m&&Qo.set(p,!0),y===1&&p.setAttribute(n,"true"),m||p.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",p,g)}})};return d(t),a.clear(),zi++,function(){i.forEach(function(f){var p=Sr.get(f)-1,h=s.get(f)-1;Sr.set(f,p),s.set(f,h),p||(Qo.has(f)||f.removeAttribute(r),Qo.delete(f)),h||f.removeAttribute(n)}),zi--,zi||(Sr=new WeakMap,Sr=new WeakMap,Qo=new WeakMap,es={})}},Bi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=sv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),av(r,o,n,"aria-hidden")):function(){return null}},bn=function(){return bn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},bn.apply(this,arguments)};function yu(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function lv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var ts="right-scroll-bar-position",ns="width-before-scroll-bar",cv="with-scroll-bars-hidden",uv="--removed-body-scroll-bar-size";function Hi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function dv(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var fv=typeof window<"u"?v.useLayoutEffect:v.useEffect,vu=new WeakMap;function pv(e,t){var n=dv(null,function(r){return e.forEach(function(o){return Hi(o,r)})});return fv(function(){var r=vu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Hi(a,null)}),s.forEach(function(a){o.has(a)||Hi(a,i)})}vu.set(n,e)},[e]),n}function hv(e){return e}function mv(e,t){t===void 0&&(t=hv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function gv(e){e===void 0&&(e={});var t=mv(null);return t.options=bn({async:!0,ssr:!1},e),t}var wu=function(e){var t=e.sideCar,n=yu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,bn({},n))};wu.isSideCarExport=!0;function xv(e,t){return e.useMedium(t),wu}var bu=gv(),Ui=function(){},rs=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Ui,onWheelCapture:Ui,onTouchMoveCapture:Ui}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,m=e.noIsolation,x=e.inert,y=e.allowPinchZoom,g=e.as,w=g===void 0?"div":g,S=e.gapMode,k=yu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=p,C=pv([n,t]),E=bn(bn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(T,{sideCar:bu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:m,inert:x,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),bn(bn({},E),{ref:C})):v.createElement(w,bn({},E,{className:l,ref:C}),a))});rs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},rs.classNames={fullWidth:ns,zeroRight:ts};var yv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function vv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function bv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Sv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=vv())&&(wv(t,n),bv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Cv=function(){var e=Sv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Su=function(){var e=Cv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Tv={left:0,top:0,right:0,gap:0},Wi=function(e){return parseInt(e||"",10)||0},kv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Wi(n),Wi(r),Wi(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Tv;var t=kv(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Iv=Su(),Cr="data-scroll-locked",Nv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
39
39
|
.`.concat(cv,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
package/package.json
CHANGED