teodor-new-chat-ui 4.3.416 → 4.3.417

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(z,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom","lucide-react"],b):(z=typeof globalThis<"u"?globalThis:z||self,b(z.NewChatUI={},z.React,z.reactSlot,z.classVarianceAuthority,z.clsx,z.tailwindMerge,z.ReactDOM,z.LucideReact))})(this,function(z,b,Vt,Dr,Yg,Xg,No,ue){"use strict";var RI=Object.defineProperty;var MI=(z,b,Vt)=>b in z?RI(z,b,{enumerable:!0,configurable:!0,writable:!0,value:Vt}):z[b]=Vt;var qg=(z,b,Vt)=>MI(z,typeof b!="symbol"?b+"":b,Vt);function Xl(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const h=Xl(b),Lr=Xl(No),Jl=120;function Jg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>Jl?`${n.slice(0,Jl-3)}…`:n:""}function ui(e){return Jg(e.content)||""}function Zg(e){var n;const t=new Map;for(const r of e){if(!r.checkpointId)continue;const o=(n=r.messages)==null?void 0:n.find(s=>s.role==="user");if(o){const s=ui(o);s&&t.set(r.checkpointId,s)}}return t}function Zl(e){const t=new Map,n=[],r=new Map,o=[];for(let c=0;c<e.length;c++){const d=e[c],p=d.checkpointId,m=p??`cp-${c}`,f=d.metadata??{},v=typeof f.step=="number"?f.step:null,g=typeof f.source=="string"?f.source:null;let x=null,y=null;const w=Array.isArray(d.messages)?d.messages:[];for(const T of w)T.role==="user"&&(y||(y=T),T.id&&(x=T.id));const S=d.next&&d.next.length>0?String(d.next[0]):null,k=d.parentConfig??null,C={id:m,step:v,source:g,createdAt:d.createdAt??null,namespace:d.checkpointNs??null,parentId:d.parentId??null,next:S,parentConfig:k,userMessageId:x};if(o.push(C),p&&t.set(p,C),p&&y){const T=ui(y);T&&r.set(p,T)}n.push({id:m,messageId:x,step:v,source:g,createdAt:d.createdAt??null,next:S,parentConfig:k})}const s=new Map;for(const c of o){if(!c.userMessageId)continue;const d=s.get(c.userMessageId)??[];d.push(c),s.set(c.userMessageId,d)}console.log("🔍 [CheckpointIndex] Built checkpoint metadata:"),console.log(` Total checkpoints: ${o.length}`),console.log(` User message groups: ${s.size}`);for(const[c,d]of s.entries())console.log(` 📌 User Message "${c}": ${d.length} checkpoint(s)`),d.forEach((p,m)=>{console.log(` [${m}] checkpoint="${p.id}", step=${p.step}, created=${p.createdAt}`)});for(const c of s.values()){if(!c.length)continue;c.sort((p,m)=>{const f=p.createdAt?Date.parse(p.createdAt):0;return(m.createdAt?Date.parse(m.createdAt):0)-f});const d=c.length;for(let p=0;p<c.length;p++){const m=c[p];m.attemptCount=d,m.attemptIndex=p,m.isLatestAttempt=p===0}}console.log("🔍 [CheckpointIndex] After attempt indexing:");for(const[c,d]of s.entries())console.log(` 📌 User Message "${c}": ${d.length} attempt(s)`),d.forEach(p=>{console.log(` - checkpoint="${p.id}", attemptCount=${p.attemptCount}, attemptIndex=${p.attemptIndex}, isLatest=${p.isLatestAttempt}`)});return{checkpoints:e,checkpointMetaByCheckpointId:t,timeline:n,messagePreviews:r,getLatest:()=>{const c=n[0];if(c)return t.get(c.id)},getCheckpoint:c=>t.get(c),getMessageAttempts:c=>{const d=[];for(const p of t.values())p.userMessageId===c&&d.push(p);return d.length?(d.sort((p,m)=>{const f=typeof p.attemptIndex=="number"?p.attemptIndex:Number.MAX_SAFE_INTEGER,v=typeof m.attemptIndex=="number"?m.attemptIndex:Number.MAX_SAFE_INTEGER;return f-v}),d):[]}}}function Ql(e,t){if(!e)return console.log("🔍 [getMessageAttemptInfo] No checkpointId provided, returning defaults"),{attemptCount:1,attemptIndex:0};const n=t.getCheckpoint(e);if(!n||!n.userMessageId)return console.log(`🔍 [getMessageAttemptInfo] No checkpoint meta or userMessageId for "${e}"`),{attemptCount:1,attemptIndex:0};const r=t.getMessageAttempts(n.userMessageId);if(!r.length)return console.log(`🔍 [getMessageAttemptInfo] No attempts found for userMessageId "${n.userMessageId}"`),{attemptCount:1,attemptIndex:0};const o=r.findIndex(s=>s.id===e);return console.log(`🔍 [getMessageAttemptInfo] checkpoint="${e}", userMsg="${n.userMessageId}", attemptCount=${r.length}, attemptIndex=${o}`),{attemptCount:r.length,attemptIndex:o>=0?o:0}}function Qg(e,t){return e?t.getCheckpoint(e)??null:null}function ec(e){return b.useMemo(()=>Zl(e),[e])}function cr(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Vn(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}}function tc(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function di(e){const t=cr(e);if(t)return cr(t.configurable)??t}function Nn(e){const r=[...(Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[]).map((s,i)=>ex(s,i)).filter(s=>!!s)].sort((s,i)=>nc(i.createdAt)-nc(s.createdAt)),o=r[0]??null;return{threadId:(e==null?void 0:e.threadId)??"",latest:o,checkpoints:r,interrupt:(o==null?void 0:o.interrupt)??null}}function ex(e,t){var S;if(!e)return null;const r=(Array.isArray((S=e.values)==null?void 0:S.messages)?e.values.messages:[]).filter(k=>!!(k&&typeof k=="object"&&typeof k.role=="string")),o=cr(e.metadata)??{},s=di(e.config),i=cr(e.parent_config??e.parentConfig),a=di(i),l=Vn(s,["checkpoint_id","checkpointId"]),c=Vn(s,["checkpoint_ns","checkpointNs"]),d=Vn(a,["checkpoint_id","checkpointId"]),p=Vn(a,["checkpoint_id","checkpointId"])??null,m=Vn(a,["checkpoint_ns","checkpointNs"])??null,f=cr(e.config),v=Array.isArray(e.tasks)?e.tasks.map(k=>({...k})):e.tasks??null,g=Array.isArray(e.next)?[...e.next]:e.next??null,x=typeof e.created_at=="string"&&e.created_at.trim()?e.created_at:typeof e.createdAt=="string"&&e.createdAt.trim()?e.createdAt:new Date(Date.now()-t).toISOString(),y={...o,step:tc(o,["step"])??0,source:Vn(o,["source"])??null},w=r.map(k=>({...k,checkpointId:l??null}));return console.log(`🔍 [normalizeSnapshot] Attaching checkpoint ID to ${w.length} messages:`,{checkpointId:l,messageIds:w.map(k=>k.id)}),{checkpointId:l??null,checkpointNs:c??null,createdAt:x,parentId:d??null,messages:w,nextCursor:p,nextCursorNs:m,interrupt:tx(r,t),metadata:y,config:f??null,parentConfig:i??null,next:g,tasks:v}}function tx(e,t){return nx(e,t)}function nx(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 nc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}var fi={exports:{}},$r={};/**
1
+ (function(z,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom","lucide-react"],b):(z=typeof globalThis<"u"?globalThis:z||self,b(z.NewChatUI={},z.React,z.reactSlot,z.classVarianceAuthority,z.clsx,z.tailwindMerge,z.ReactDOM,z.LucideReact))})(this,function(z,b,Vt,Dr,Yg,Xg,No,ue){"use strict";var RI=Object.defineProperty;var MI=(z,b,Vt)=>b in z?RI(z,b,{enumerable:!0,configurable:!0,writable:!0,value:Vt}):z[b]=Vt;var qg=(z,b,Vt)=>MI(z,typeof b!="symbol"?b+"":b,Vt);function Xl(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const h=Xl(b),Lr=Xl(No),Jl=120;function Jg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>Jl?`${n.slice(0,Jl-3)}…`:n:""}function ui(e){return Jg(e.content)||""}function Zg(e){var n;const t=new Map;for(const r of e){if(!r.checkpointId)continue;const o=(n=r.messages)==null?void 0:n.find(s=>s.role==="user");if(o){const s=ui(o);s&&t.set(r.checkpointId,s)}}return t}function Zl(e){const t=new Map,n=[],r=new Map,o=[];for(let c=0;c<e.length;c++){const d=e[c],p=d.checkpointId,m=p??`cp-${c}`,f=d.metadata??{},v=typeof f.step=="number"?f.step:null,g=typeof f.source=="string"?f.source:null;let x=null,y=null;const w=Array.isArray(d.messages)?d.messages:[];for(const T of w)T.role==="user"&&(y||(y=T),T.id&&(x=T.id));const S=d.next&&d.next.length>0?String(d.next[0]):null,k=d.parentConfig??null,C={id:m,step:v,source:g,createdAt:d.createdAt??null,namespace:d.checkpointNs??null,parentId:d.parentId??null,next:S,parentConfig:k,userMessageId:x};if(o.push(C),p&&t.set(p,C),p&&y){const T=ui(y);T&&r.set(p,T)}n.push({id:m,messageId:x,step:v,source:g,createdAt:d.createdAt??null,next:S,parentConfig:k})}const s=new Map;for(const c of o){if(!c.userMessageId)continue;const d=s.get(c.userMessageId)??[];d.push(c),s.set(c.userMessageId,d)}console.log("🔍 [CheckpointIndex] Built checkpoint metadata:"),console.log(` Total checkpoints: ${o.length}`),console.log(` User message groups: ${s.size}`);for(const[c,d]of s.entries())console.log(` 📌 User Message "${c}": ${d.length} checkpoint(s)`),d.forEach((p,m)=>{console.log(` [${m}] checkpoint="${p.id}", step=${p.step}, created=${p.createdAt}`)});console.log("🔍 [CheckpointIndex] AFTER computing checkpoint metadata:"),console.log(` checkpointMetaByCheckpointId size: ${t.size}`),console.log(" checkpointMetaByCheckpointId keys:",Array.from(t.keys()));for(const[c,d]of t.entries())console.log(` Checkpoint "${c}":`,{userMessageId:d.userMessageId,step:d.step,source:d.source,createdAt:d.createdAt});for(const c of s.values()){if(!c.length)continue;c.sort((p,m)=>{const f=p.createdAt?Date.parse(p.createdAt):0;return(m.createdAt?Date.parse(m.createdAt):0)-f});const d=c.length;for(let p=0;p<c.length;p++){const m=c[p];m.attemptCount=d,m.attemptIndex=p,m.isLatestAttempt=p===0}}console.log("🔍 [CheckpointIndex] After attempt indexing:");for(const[c,d]of s.entries())console.log(` 📌 User Message "${c}": ${d.length} attempt(s)`),d.forEach(p=>{console.log(` - checkpoint="${p.id}", attemptCount=${p.attemptCount}, attemptIndex=${p.attemptIndex}, isLatest=${p.isLatestAttempt}`)});return{checkpoints:e,checkpointMetaByCheckpointId:t,timeline:n,messagePreviews:r,getLatest:()=>{const c=n[0];if(c)return t.get(c.id)},getCheckpoint:c=>t.get(c),getMessageAttempts:c=>{const d=[];for(const p of t.values())p.userMessageId===c&&d.push(p);return d.length?(d.sort((p,m)=>{const f=typeof p.attemptIndex=="number"?p.attemptIndex:Number.MAX_SAFE_INTEGER,v=typeof m.attemptIndex=="number"?m.attemptIndex:Number.MAX_SAFE_INTEGER;return f-v}),d):[]}}}function Ql(e,t){if(!e)return console.log("🔍 [getMessageAttemptInfo] No checkpointId provided, returning defaults"),{attemptCount:1,attemptIndex:0};const n=t.getCheckpoint(e);if(!n||!n.userMessageId)return console.log(`🔍 [getMessageAttemptInfo] No checkpoint meta or userMessageId for "${e}"`),{attemptCount:1,attemptIndex:0};const r=t.getMessageAttempts(n.userMessageId);if(!r.length)return console.log(`🔍 [getMessageAttemptInfo] No attempts found for userMessageId "${n.userMessageId}"`),{attemptCount:1,attemptIndex:0};const o=r.findIndex(s=>s.id===e);return console.log(`🔍 [getMessageAttemptInfo] checkpoint="${e}", userMsg="${n.userMessageId}", attemptCount=${r.length}, attemptIndex=${o}`),{attemptCount:r.length,attemptIndex:o>=0?o:0}}function Qg(e,t){return e?t.getCheckpoint(e)??null:null}function ec(e){return b.useMemo(()=>Zl(e),[e])}function cr(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Vn(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}}function tc(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function di(e){const t=cr(e);if(t)return cr(t.configurable)??t}function Nn(e){const r=[...(Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[]).map((s,i)=>ex(s,i)).filter(s=>!!s)].sort((s,i)=>nc(i.createdAt)-nc(s.createdAt)),o=r[0]??null;return{threadId:(e==null?void 0:e.threadId)??"",latest:o,checkpoints:r,interrupt:(o==null?void 0:o.interrupt)??null}}function ex(e,t){var S;if(!e)return null;const r=(Array.isArray((S=e.values)==null?void 0:S.messages)?e.values.messages:[]).filter(k=>!!(k&&typeof k=="object"&&typeof k.role=="string")),o=cr(e.metadata)??{},s=di(e.config),i=cr(e.parent_config??e.parentConfig),a=di(i),l=Vn(s,["checkpoint_id","checkpointId"]),c=Vn(s,["checkpoint_ns","checkpointNs"]),d=Vn(a,["checkpoint_id","checkpointId"]),p=Vn(a,["checkpoint_id","checkpointId"])??null,m=Vn(a,["checkpoint_ns","checkpointNs"])??null,f=cr(e.config),v=Array.isArray(e.tasks)?e.tasks.map(k=>({...k})):e.tasks??null,g=Array.isArray(e.next)?[...e.next]:e.next??null,x=typeof e.created_at=="string"&&e.created_at.trim()?e.created_at:typeof e.createdAt=="string"&&e.createdAt.trim()?e.createdAt:new Date(Date.now()-t).toISOString(),y={...o,step:tc(o,["step"])??0,source:Vn(o,["source"])??null},w=r.map(k=>({...k,checkpointId:l??null}));return console.log(`🔍 [normalizeSnapshot] Attaching checkpoint ID to ${w.length} messages:`,{checkpointId:l,messageIds:w.map(k=>k.id)}),{checkpointId:l??null,checkpointNs:c??null,createdAt:x,parentId:d??null,messages:w,nextCursor:p,nextCursorNs:m,interrupt:tx(r,t),metadata:y,config:f??null,parentConfig:i??null,next:g,tasks:v}}function tx(e,t){return nx(e,t)}function nx(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 nc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}var fi={exports:{}},$r={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -126,5 +126,5 @@ ${t}</tr>
126
126
  `}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=ah(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o='<a href="'+t+'"';return n&&(o+=' title="'+n+'"'),o+=">"+r+"</a>",o}image(t,n,r){if(t=ah(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o=`<img src="${t}" alt="${r}"`;return n&&(o+=` title="${n}"`),o+=this.options.xhtml?"/>":">",o}text(t){return t}}class fh{strong(t){return t}em(t){return t}codespan(t){return t}del(t){return t}html(t){return t}text(t){return t}link(t,n,r){return""+r}image(t,n,r){return""+r}br(){return""}}class ph{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class zn{constructor(t){this.options=t||or,this.options.renderer=this.options.renderer||new el,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new fh,this.slugger=new ph}static parse(t,n){return new zn(n).parse(t)}static parseInline(t,n){return new zn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,p,m,f,v,g,x,y,w,S,k,C,T;const E=t.length;for(o=0;o<E;o++){if(f=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[f.type]&&(T=this.options.extensions.renderers[f.type].call({parser:this},f),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(f.type))){r+=T||"";continue}switch(f.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(f.tokens),f.depth,ih(this.parseInline(f.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(f.text,f.lang,f.escaped);continue}case"table":{for(p="",d="",a=f.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(f.header[s].tokens),{header:!0,align:f.align[s]});for(p+=this.renderer.tablerow(d),m="",a=f.rows.length,s=0;s<a;s++){for(c=f.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:f.align[i]});m+=this.renderer.tablerow(d)}r+=this.renderer.table(p,m);continue}case"blockquote":{m=this.parse(f.tokens),r+=this.renderer.blockquote(m);continue}case"list":{for(v=f.ordered,g=f.start,x=f.loose,a=f.items.length,m="",s=0;s<a;s++)w=f.items[s],S=w.checked,k=w.task,y="",w.task&&(C=this.renderer.checkbox(S),x?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=C+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=C+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:C}):y+=C),y+=this.parse(w.tokens,x),m+=this.renderer.listitem(y,k,S);r+=this.renderer.list(m,v,g);continue}case"html":{r+=this.renderer.html(f.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(f.tokens));continue}case"text":{for(m=f.tokens?this.parseInline(f.tokens):f.text;o+1<E&&t[o+1].type==="text";)f=t[++o],m+=`
127
127
  `+(f.tokens?this.parseInline(f.tokens):f.text);r+=n?this.renderer.paragraph(m):m;continue}default:{const j='Token with "'+f.type+'" type was not found.';if(this.options.silent){console.error(j);return}else throw new Error(j)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ws{constructor(t){this.options=t||or}preprocess(t){return t}postprocess(t){return t}}qg(Ws,"passThroughHooks",new Set(["preprocess","postprocess"]));function bT(e,t,n){return r=>{if(r.message+=`
128
128
  Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function hh(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...be.defaults,...s};const i=bT(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(xT(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(p){return i(p)}const c=function(p){let m;if(!p)try{r.walkTokens&&be.walkTokens(l,r.walkTokens),m=t(l,r),r.hooks&&(m=r.hooks.postprocess(m))}catch(f){p=f}return r.highlight=a,p?i(p):o(null,m)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;be.walkTokens(l,function(p){p.type==="code"&&(d++,setTimeout(()=>{a(p.text,p.lang,function(m,f){if(m)return c(m);f!=null&&f!==p.text&&(p.text=f,p.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(be.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&be.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function be(e,t,n){return hh(Bn.lex,zn.parse)(e,t,n)}be.options=be.setOptions=function(e){return be.defaults={...be.defaults,...e},oT(be.defaults),be},be.getDefaults=nh,be.defaults=or,be.use=function(...e){const t=be.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=be.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=be.defaults.renderer||new el;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=be.defaults.tokenizer||new Qa;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=be.defaults.hooks||new Ws;for(const s in n.hooks){const i=o[s];Ws.passThroughHooks.has(s)?o[s]=a=>{if(be.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=be.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}be.setOptions(r)})},be.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(be,r)),r.type){case"table":{for(const o of r.header)n=n.concat(be.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(be.walkTokens(s.tokens,t));break}case"list":{n=n.concat(be.walkTokens(r.items,t));break}default:be.defaults.extensions&&be.defaults.extensions.childTokens&&be.defaults.extensions.childTokens[r.type]?be.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(be.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(be.walkTokens(r.tokens,t)))}return n},be.parseInline=hh(Bn.lexInline,zn.parseInline),be.Parser=zn,be.parser=zn.parse,be.Renderer=el,be.TextRenderer=fh,be.Lexer=Bn,be.lexer=Bn.lex,be.Tokenizer=Qa,be.Slugger=ph,be.Hooks=Ws,be.parse=be,be.options,be.setOptions,be.use,be.walkTokens,be.parseInline,zn.parse,Bn.lex;function Ar({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof be.parse=="function"?be.parse(i):be(i)}return typeof be.parse=="function"?be.parse(e):be(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=b.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}function mh({preview:e,idx:t}){return u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}function gh({artifact:e}){const[t,n]=b.useState("bg-yellow-500/20 text-yellow-700 dark:text-yellow-300"),[r,o]=b.useState(u.jsx(ue.Clock,{className:"w-4 h-4"})),[s,i]=b.useState("Processing");return b.useEffect(()=>{switch(e.status||"processing"){case"completed":n("bg-green-500/20 text-green-700 dark:text-green-300"),o(u.jsx(ue.CheckCircle,{className:"w-4 h-4"})),i("Completed");break;case"failed":n("bg-red-500/20 text-red-700 dark:text-red-300"),o(u.jsx(ue.ExternalLink,{className:"w-4 h-4 rotate-45"})),i("Failed");break;case"pending":n("bg-blue-500/20 text-blue-700 dark:text-blue-300"),o(u.jsx(ue.Clock,{className:"w-4 h-4"})),i("Pending");break;default:n("bg-yellow-500/20 text-yellow-700 dark:text-yellow-300"),o(u.jsx(ue.Clock,{className:"w-4 h-4"})),i("Processing")}},[e.status]),u.jsxs("div",{className:"rounded-lg border border-blue-200 dark:border-blue-900/50 bg-blue-50 dark:bg-blue-950/20 p-4 space-y-3",children:[u.jsxs("div",{className:"flex items-start gap-3",children:[u.jsx("div",{className:"mt-1 flex-shrink-0",children:u.jsx(ue.Search,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100",children:"Research Task"}),u.jsxs("p",{className:"text-sm text-blue-700 dark:text-blue-300 mt-1",children:["Task ID: ",u.jsxs("code",{className:"font-mono text-xs bg-blue-100 dark:bg-blue-900/30 px-2 py-1 rounded",children:[e.task_id.slice(0,8),"..."]})]})]})]}),u.jsxs("div",{className:`inline-flex items-center gap-2 px-3 py-1 rounded-full text-sm font-medium ${t}`,children:[r,u.jsx("span",{children:s})]}),e.query&&u.jsxs("div",{className:"text-sm text-blue-800 dark:text-blue-200 bg-white dark:bg-blue-900/30 rounded px-3 py-2",children:[u.jsx("p",{className:"font-medium text-xs text-blue-600 dark:text-blue-400 mb-1",children:"Query:"}),u.jsx("p",{className:"line-clamp-2",children:e.query})]}),typeof e.results=="string"&&e.results.trim()&&u.jsxs("div",{className:"text-sm text-blue-900 dark:text-blue-100 bg-white dark:bg-blue-900/30 rounded px-3 py-2 space-y-2",children:[u.jsx("p",{className:"font-semibold text-xs text-blue-600 dark:text-blue-400",children:"Results:"}),u.jsx(Ar,{content:e.results,allowHtml:!1,className:"prose text-xs !prose-sm prose-blue dark:prose-invert"})]}),e.progress_url&&u.jsx("div",{className:"pt-2",children:u.jsxs("a",{href:e.progress_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white dark:bg-blue-700 dark:hover:bg-blue-600 rounded-md text-sm font-medium transition-colors",children:[u.jsx("span",{children:"Monitor Progress"}),u.jsx(ue.ExternalLink,{className:"w-3.5 h-3.5"})]})}),e.createdAt&&u.jsxs("p",{className:"text-xs text-blue-600 dark:text-blue-400",children:["Started: ",new Date(e.createdAt).toLocaleTimeString()]})]})}function xh({artifact:e,idx:t=0}){const n=b.useMemo(()=>e?(Array.isArray(e.plots)?e.plots:[]).map(o=>Uv(o)).filter(o=>o!==null):[],[e]);return(e==null?void 0:e.type)==="research_task_info"?u.jsx(gh,{artifact:{type:"research_task_info",task_id:e.task_id,progress_url:e.progress_url,query:e.query,status:e.status,createdAt:e.createdAt}}):n.length>0?u.jsx("div",{className:"space-y-2",children:n.map((r,o)=>u.jsx(mh,{preview:r,idx:o},`${t}-plot-${o}`))}):e&&typeof e=="object"?u.jsx("div",{className:"rounded-lg border border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/20 p-4",children:u.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["Unknown artifact type: ",u.jsx("code",{className:"font-mono",children:e.type||"unknown"})]})}):null}const tl=h.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));tl.displayName="Card";const nl=h.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));nl.displayName="CardHeader";const rl=h.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));rl.displayName="CardTitle";const ol=h.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));ol.displayName="CardDescription";const sl=h.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));sl.displayName="CardContent";const vh=h.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));vh.displayName="CardFooter";function wh({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=hr(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(tl,{className:te("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(nl,{className:"pb-3",children:[u.jsx(rl,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(ol,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(sl,{className:"pt-0 pb-3",children:a}),u.jsx(vh,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(it,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(it,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const yT="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function il({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:yT,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:hr(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:hr(e)})}function bh({message:e,isStreaming:t=!1}){const n=e.name??"tool",r=b.useMemo(()=>{const a=e.additionalKwargs??{};return Array.isArray(a.toolProgress)?[...a.toolProgress]:[]},[e]),s=r.some(a=>a.type==="tool.start"||a.type==="tool.call"||a.type==="message.start")?`Running ${n}…`:void 0;return t||r.length>0?u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[t&&u.jsx(ue.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:s??`Running ${n}…`})]}),r.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:r.map((a,l)=>{var c;return u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsxs("div",{className:"mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:((c=a.type)==null?void 0:c.replace(/\./g," "))??"progress"}),u.jsx("span",{children:a.idx??l+1})]}),a.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:a.content}),u.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof a.factsFound=="number"&&u.jsxs("span",{children:["Facts found: ",a.factsFound]}),typeof a.isSufficient=="boolean"&&u.jsxs("span",{children:["Research ",a.isSufficient?"sufficient":"needs more data"]})]})]},`tool-progress-${n}-${l}`)})})]}):null}function yh({message:e,viewMode:t,isStreaming:n=!1}){const o=Ai(e).name||"tool",s=l=>{if(l==null)return null;const c=typeof l=="string"?Ni(l)??l:l;if(c&&typeof c=="object")return u.jsx(il,{data:c});const d=typeof c=="string"?c:(()=>{try{return hr(c)}catch{return String(c??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:d})},i=l=>{if(l==null)return null;const{content:c,isMarkdown:d}=Dv(l);return d?u.jsx(Ar,{content:c,className:"text-current"}):s(l)},a=()=>{const l=e.content.find(p=>p.type!=="tool_call");if(!l)return u.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:u.jsxs("span",{children:["Running ",o,"…"]})});if(l.type==="text"){const m=(l.text??"").trim();if(!m)return null;const f=qr(m);return i(f)}const c=Kr(l),d=qr(c);return i(d)};return u.jsxs("div",{className:"space-y-2",children:[u.jsx(bh,{message:e,isStreaming:n}),t==="expanded"&&a()]})}function Sh({className:e}){const[t,n]=b.useState(0);return b.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function Ch({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(Ar,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(it,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(ue.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ue.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function Th({message:e,isToolMessage:t,showToolMessages:n,artifactToRender:r,toolViewMode:o,isToolStreaming:s,contentParts:i,textContent:a,imageParts:l,fileParts:c,interruptParts:d,isStreamingMessage:p,defaultMessage:m,handleFileClick:f,uploadingFiles:v,handleInterruptApprove:g,handleInterruptReject:x,disableInterruptActions:y,messageRole:w,truncateUserMessages:S,userMessagePreviewLength:k,isUserExpanded:C,setIsUserExpanded:T,isCompactLayout:E,activeInterruptId:j,activeInterruptValue:O,iconForeground:L}){const U=b.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ue.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),K=b.useCallback(({part:N,i:W})=>{if(N.type==="text"){const I=N.text??"",F=I.trim(),R=Ni(F);return R&&w!=="tool"?u.jsx(il,{data:R},W):w==="user"&&S&&F.length>k?u.jsx(Ch,{text:F,expanded:C,onExpandedChange:T,previewLength:k,isCompact:E},W):u.jsx(Ar,{content:I,allowHtml:!1},W)}if(N.type==="image_url"){const I=N;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:I.url,alt:I.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},W)}if(N.type==="file"){const I=N,F=I.name||"file";return u.jsxs("a",{href:I.url,onClick:R=>f(R.nativeEvent,I,W),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
129
- dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[v[W]?u.jsx(ue.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[F,v[W]?" (processing)":""]})]},W)}if(N.type==="interrupt"){const I=N,F=Wo((I==null?void 0:I.id)??(I==null?void 0:I.interrupt_id)),R=!!(j&&F&&F===j),_=R?O??(I==null?void 0:I.value):I==null?void 0:I.value,G=F?{...I,id:F,interrupt_id:F}:I;return u.jsx(wh,{interruptPart:G,onApprove:g,onReject:x,disabled:y,isActive:R,payload:_},W)}return null},[f,v,g,x,w,S,k,C,E,j,O,y]),V=a.trim().length>0||l.length>0||c.length>0||d.length>0;if(!t&&c.length>0&&!p)return U();if(!t&&!V&&!p)return null;if(t)return!n&&r?null:n?u.jsx(yh,{message:e,viewMode:o,isStreaming:s},e.id):null;if(!m){const N=u.jsx("div",{className:"space-y-2",children:i.map((W,I)=>u.jsx(K,{part:W,i:I},I))});return p?u.jsxs("div",{"aria-busy":"true",role:"status",children:[N,u.jsx(Sh,{className:L})]}):N}return null}function kh(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Za(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),p=b.useCallback(f=>{a(f),c(!0)},[]),m=b.useCallback(async(f,v,g)=>{var x,y;if(!t){f.preventDefault();return}if(o[g]){f.preventDefault();return}try{const w=String(v.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){f.preventDefault();const k=S[1],C=v.name||`file_${k}`,T=v.mimeType||"application/octet-stream";p({id:k,name:C,mimeType:T});return}if(w.startsWith("data:")){f.preventDefault(),s(C=>({...C,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await Zc(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(v.name??""))?!1:typeof v.size=="number"&&typeof E.size=="number"?E.size===v.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${v.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");p({id:T.id,name:v.name||T.filename||`file_${T.id}`,mimeType:v.mimeType||T.mime_type||"application/octet-stream"}),(x=k.update)==null||x.call(k,{id:k.id,title:"Success",description:`Opened ${v.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(y=k.update)==null||y.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[g]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[g]:!1}))}},[t,o,r,n,p]);return{uploadingFiles:o,handleFileClick:m,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function Eh(e,t){return b.useMemo(()=>{if(t)return{contentParts:[],textContent:"",toolMeta:{},imageParts:[],fileParts:[],interruptParts:[],toolRaw:"",isToolStreaming:!1};const n=e,r=Array.isArray(n.content)?n.content:[],o=n.additionalKwargs??{};return{contentParts:r,textContent:Lv(r),toolMeta:Ai(n),imageParts:r.filter(s=>s.type==="image_url"),fileParts:r.filter(s=>s.type==="file"),interruptParts:r.filter(s=>s.type==="interrupt"),toolRaw:$v(r),isToolStreaming:!!o.toolStreaming}},[e,t])}const Vs=b.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:p=!0,showArtifactPreviews:m=!0,customStyles:f={},onEdit:v,onRegenerate:g,onCopy:x,activeInterrupt:y,disableInterruptActions:w=!1,onInterruptActionStart:S,onInterruptActionEnd:k,attemptCount:C=1,attemptIndex:T=0,onSelectCheckpoint:E}){const[j,O]=b.useState(!1),[L,U]=b.useState("preview"),[K,V]=b.useState(!1),{currentThreadId:N}=pr(),{respondToInterrupt:W}=Yr(),I=l==="phone"||l==="half-screen",F=t.role,R=F==="tool",_=b.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),G=!!_,J=!(r&&F!=="user"),{uploadingFiles:P,handleFileClick:M,fileViewerOpen:q,currentFileInfo:Y,closeFileViewer:se}=kh({allowFileOpen:J,currentThreadId:N}),B=b.useMemo(()=>{switch(F){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[F]),D=Eh(t,_),{contentParts:X,imageParts:re,fileParts:ae,interruptParts:$,textContent:Z,toolMeta:de,toolRaw:ce,isToolStreaming:xe}=D,_e=(y==null?void 0:y.id)??(y==null?void 0:y.interrupt_id),Ve=Wo(_e),He=y==null?void 0:y.value,Ee=b.useMemo(()=>_||!m?null:t.artifact||null,[_,t,m]),Fe=b.useCallback(async()=>{const ye=R?ce:Z;async function tt(rt){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(rt);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const _t=new Blob([rt],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":_t})]);return}throw new Error("Clipboard API not supported in this context.")}try{await tt(ye),O(!0),setTimeout(()=>O(!1),2e3),x==null||x(ye)}catch(rt){console.error("Failed to copy:",rt)}},[R,ce,Z,x]),Ke=b.useCallback(()=>{if(!v||!t.id)return;const ye=(R?ce:Z)??"",tt="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};v(t.id,ye,tt)},[v,t.id,R,ce,Z,t]),Ue=b.useCallback(()=>{g==null||g(n)},[g,n]),Ye=b.useCallback(()=>{const tt=te(I?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",B);switch(F){case"user":return u.jsx(ue.User,{className:tt});case"assistant":return u.jsx(ue.Bot,{className:tt});case"tool":return u.jsx(ue.Wrench,{className:tt});default:return u.jsx(ue.Bot,{className:tt})}},[I,B,F]),nt=b.useCallback(()=>{const ye="group relative mb-4 flex w-full";switch(F){case"user":return te(ye,"justify-end");case"assistant":case"tool":case"system":return te(ye,"justify-start");default:return ye}},[F]),et=b.useCallback(()=>{const ye=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",I&&"px-3 py-2 text-sm");if(G)return te(ye,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(F){case"user":return te(ye,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(ye,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(ye,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(ye,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(ye,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[I,G,F]),Ze=b.useCallback(async ye=>{if(w)return;const tt=Wo((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id));if(!tt){console.warn("Interrupt part missing id",ye);return}try{S==null||S(),await W(tt,!0)}catch(rt){console.error("Failed to approve interrupt:",rt)}finally{k==null||k()}},[w,k,S,W]),vt=b.useCallback(async ye=>{if(w)return;const tt=Wo((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id));if(!tt){console.warn("Interrupt part missing id",ye);return}try{S==null||S(),await W(tt,!1)}catch(rt){console.error("Failed to reject interrupt:",rt)}finally{k==null||k()}},[w,k,S,W]),gt=b.useMemo(()=>_?"Assistant":Fv(t),[_,t]),ut=F==="user"&&(C??1)>1&&typeof E=="function";return R&&!p&&!Ee?null:G&&_?u.jsx("div",{className:te(nt(),f.container),children:u.jsxs("div",{className:te(et(),f.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ue.Bot,{className:te("h-4 w-4",B)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(Ar,{content:_.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(nt(),f.container),children:u.jsxs("div",{className:te(et(),f.content),children:[(i||a||R)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",I&&"mb-1 pb-1",B,f.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ye(),a&&gt&&u.jsx("span",{className:te("font-medium",I?"text-xs":"text-sm"),children:gt}),R&&u.jsxs(Op,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",B,"border border-current/40",I&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":L==="expanded",onClick:()=>U(ye=>ye==="expanded"?"preview":"expanded"),onKeyDown:ye=>{(ye.key==="Enter"||ye.key===" ")&&(ye.preventDefault(),U(tt=>tt==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:de.name??"Tool Output"}),de.toolCallId&&u.jsx("span",{className:"opacity-70",children:de.toolCallId.slice(0,8)}),L==="expanded"?u.jsx(ue.ChevronUp,{className:"h-3 w-3"}):u.jsx(ue.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[ut&&C>1&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",T<C-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{T>=C-1||!E||E(null)},"aria-label":"Older attempt (back in time)",disabled:T>=C-1,children:u.jsx(ue.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[C-T," / ",C]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",T>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{T<=0||!E||E(null)},"aria-label":"Newer attempt (forward in time)",disabled:T<=0,children:u.jsx(ue.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",B,I&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",f.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>Fe(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",B,I&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ue.Copy,{className:te(j?"text-success":B,I?"h-3 w-3":"h-4 w-4")})})}),F==="user"&&v&&u.jsx(it,{variant:"ghost",size:"sm",onClick:Ke,className:te("h-6 w-6 p-0 hover:bg-foreground/10",B,I&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ue.Edit,{className:te(B,I?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&g&&u.jsx(it,{variant:"ghost",size:"sm",onClick:Ue,className:te("h-6 w-6 p-0 hover:bg-foreground/10",B,I&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ue.RotateCcw,{className:te(B,I?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[u.jsx(Th,{message:t,isToolMessage:R,showToolMessages:p,artifactToRender:Ee,toolViewMode:L,isToolStreaming:xe,contentParts:X,textContent:Z,imageParts:re,fileParts:ae,interruptParts:$,isStreamingMessage:r,defaultMessage:_,handleFileClick:M,uploadingFiles:P,handleInterruptApprove:Ze,handleInterruptReject:vt,disableInterruptActions:w,messageRole:F,truncateUserMessages:c,userMessagePreviewLength:d,isUserExpanded:K,setIsUserExpanded:V,isCompactLayout:I,activeInterruptId:Ve,activeInterruptValue:He,iconForeground:B}),m&&Ee&&u.jsx("div",{className:"mt-3",children:u.jsx(xh,{artifact:Ee,idx:0})})]}),R&&L==="expanded"&&(de.toolCallId||de.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",I&&"text-xs"),children:[de.name&&u.jsxs("div",{children:["Function: ",de.name]}),de.toolCallId&&u.jsxs("div",{children:["Call ID: ",de.toolCallId]})]}),!(i||a||R)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",f.actions),children:[u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>Fe(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.Copy,{className:te(j?"text-success":"text-current",I?"h-3 w-3":"h-4 w-4")})}),F==="user"&&v&&u.jsx(it,{variant:"ghost",size:"sm",onClick:Ke,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.Edit,{className:te("text-current",I?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&g&&u.jsx(it,{variant:"ghost",size:"sm",onClick:Ue,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.RotateCcw,{className:te("text-current",I?"h-3 w-3":"h-4 w-4")})})]})]})}),Y&&u.jsx(th,{isOpen:q,onClose:se,fileId:Y.id,fileName:Y.name,mimeType:Y.mimeType})]})},(e,t)=>{var l,c,d,p,m,f,v,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&lu(e.message)===lu(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(x=>e[x]===t[x]),s=((l=e.customStyles)==null?void 0:l.container)===((c=t.customStyles)==null?void 0:c.container)&&((d=e.customStyles)==null?void 0:d.content)===((p=t.customStyles)==null?void 0:p.content)&&((m=e.customStyles)==null?void 0:m.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((v=e.customStyles)==null?void 0:v.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=cu(e.message),a=cu(t.message);return i.length===a.length});Vs.displayName="MessageComponent";const ST={checkpoints:[],checkpointMetaByCheckpointId:new Map,timeline:[],messagePreviews:new Map,getLatest:()=>{},getCheckpoint:()=>{},getMessageAttempts:()=>[]},al=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,ll=b.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:p,activeInterrupt:m,disableInterruptActions:f,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:x,showArtifactPreviews:y,checkpointIndex:w,onSelectCheckpoint:S}){const k=al(t,n),C="type"in t&&t.type==="default_message",E=!!t.__syntheticStreaming,j=w??ST,O=!C&&"checkpointId"in t?t.checkpointId??null:null,{attemptCount:L,attemptIndex:U}=Ql(O,j);return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":k,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Vs,{message:t,messageIndex:n,isStreamingMessage:E||r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:p,activeInterrupt:m,disableInterruptActions:f,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:x,showArtifactPreviews:y,attemptCount:L,attemptIndex:U,onSelectCheckpoint:S})})});ll.displayName="MessageRow";const cl=b.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:p,style:m,emptyMessage:f,followNewMessages:v=!0,isNavigatingCheckpoint:g=!1,onScrollAway:x,onAtBottom:y,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointIndex:j,activeCheckpointId:O,onSelectCheckpoint:L,createSyntheticThinkingMessage:U=!0},K)=>{const V=b.useRef(null),N=b.useRef(null),W=b.useRef(!1),I=b.useRef(!1),[F,R]=b.useState(!0),_=b.useMemo(()=>w?e.some($=>"type"in $&&$.type==="default_message"?!1:Array.isArray($==null?void 0:$.content)&&$.content.some(Z=>Z&&Z.type==="interrupt"&&(Z.id??Z.interrupt_id)===w.id)):!1,[w,e]),G=b.useMemo(()=>{if(!w||_)return null;const $=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let Z;const de=w.value;if(de&&typeof de=="object"&&!Array.isArray(de)){const ce=de.title;typeof ce=="string"&&ce.trim()&&(Z=ce.trim())}return{id:`interrupt-${$}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:$,value:de,title:Z}]}},[w,_]),J=b.useMemo(()=>G?[...e,G]:e,[e,G]),P=b.useMemo(()=>!U||!t?J:!J.some(Z=>Z.role==="assistant")&&J.length>0?[...J,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString(),__syntheticStreaming:!0}]:J,[J,t,U]),M=b.useMemo(()=>T?P:P.filter($=>($==null?void 0:$.role)!=="tool"),[P,T]),q=b.useCallback($=>{R($),x&&x(!$),y&&y($)},[x,y]),Y=b.useMemo(()=>{if(a)return async()=>{if(!W.current){W.current=!0;try{await a()}finally{W.current=!1}}}},[a]),se=b.useMemo(()=>!v||g?!1:F?"auto":!1,[F,v,g]),B=b.useMemo(()=>{if(typeof f!="string")return null;const $=f.trim();return $?{id:"default-message",role:"assistant",type:"default_message",content:$,createdAt:new Date().toISOString()}:null},[f]),D=["flex h-full flex-col md:flex-row",p].filter(Boolean).join(" "),X=()=>B?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Vs,{message:B,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:E})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:f??"No messages yet. Start a conversation!"}),re=M.length,ae=re>0;return b.useEffect(()=>{var $,Z;if(re===0){I.current=!1;return}if(!I.current)if(I.current=!0,V.current&&M.length>0){const de=M.length-1;(Z=($=V.current).scrollToIndex)==null||Z.call($,{index:de,align:"end",behavior:"auto"})}else N.current&&(N.current.scrollTop=N.current.scrollHeight)},[re,M.length]),b.useImperativeHandle(K,()=>({scrollToLatest:()=>{var $,Z;if(V.current&&M.length>0){const de=M.length-1;(Z=($=V.current).scrollToIndex)==null||Z.call($,{index:de,align:"end",behavior:"auto"})}else N.current&&(N.current.scrollTop=N.current.scrollHeight)},scrollToTop:()=>{var $,Z;V.current&&M.length>0?(Z=($=V.current).scrollToIndex)==null||Z.call($,{index:0,align:"start",behavior:"auto"}):N.current&&(N.current.scrollTop=0)}}),[M]),u.jsx("div",{className:D,style:m,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:ae?u.jsx(kC,{ref:$=>{V.current=$},scrollerRef:$=>{N.current=$ instanceof HTMLDivElement?$:null},data:M,followOutput:se,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{Y&&Y()},atBottomStateChange:q,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:($,Z)=>al(Z,$),itemContent:($,Z)=>u.jsx(ll,{message:Z,index:$,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:E,checkpointIndex:j,activeCheckpointId:O,onSelectCheckpoint:L})}):X()})})});cl.displayName="MessageList";const Ih={value:""};function So({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:p=!0,customStyles:m={},onMessageSent:f,onExcelUploadSuccess:v,onError:g}){const{api:x}=Vr(),{currentThreadId:y}=pr(),{threadId:w,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:j,checkpoints:O,interrupt:L,metadata:U,checkpointIndex:K}=Yr(),{isStreaming:V,error:N,connectionState:W,submit:I,stop:F}=Ri(),R=w??y??null,_=(j==null?void 0:j.id)??null,G=(j==null?void 0:j.namespace)??null,J=(U==null?void 0:U.assemblingMessageId)??null,P=L,[M,q]=b.useState(!1);b.useEffect(()=>{P||q(!1)},[P]);const Y=b.useCallback(()=>{q(!0)},[]),se=b.useCallback(()=>{q(!1)},[]),B=!!P||M,[D,X]=b.useState(null),[re,ae]=b.useState(""),[$,Z]=b.useState(null),[de,ce]=b.useState(null),[xe,_e]=b.useState([]),[Ve,He]=b.useState(0),[Ee,Fe]=b.useState(0),[Ke,Ue]=b.useState(!1),[Ye,nt]=b.useState(null),[et,Ze]=b.useState(null),[vt,gt]=b.useState(!1),[ut,ye]=b.useState(null),tt=b.useRef(!1),[rt,_t]=b.useState(()=>Ih.value),pn=b.useRef(rt),Le=b.useRef(null),qe=b.useCallback(le=>{Ih.value=le,_t(le)},[]),[Dt,Pt]=b.useState(!1),wt=b.useRef(null),kt=b.useRef(null),ne=b.useRef(null),Se=b.useCallback(()=>{kt.current&&(kt.current.value=""),ne.current&&(ne.current.value=""),He(le=>le+1),Fe(le=>le+1)},[]),ft=b.useCallback(le=>{qe(le)},[qe]),Ce=b.useRef(!1);b.useEffect(()=>{Ce.current&&!V&&(_e([]),Se()),Ce.current=V},[V,Se]);const[Me,We]=b.useState("desktop");b.useEffect(()=>{const le=()=>{const ge=window.innerWidth;We(ge<640?"phone":ge<1024?"tablet":"desktop")};return le(),window.addEventListener("resize",le),()=>window.removeEventListener("resize",le)},[]),b.useEffect(()=>{tt.current=!1},[R]),b.useEffect(()=>{pn.current=rt},[rt]),b.useEffect(()=>{if(!D){Le.current=null;return}Le.current===null&&(Le.current=pn.current),qe(re??"")},[re,D,qe]),b.useEffect(()=>{(async()=>{if(!x.baseUrl){ye(null);return}try{const pe=(await x.getAgent("default")).uiDefaultMessage||"";ye(pe||null)}catch(ge){console.warn("Failed to fetch default message:",ge),ye(null)}})()},[x.baseUrl]),b.useEffect(()=>{N&&!vt&&(g==null||g(N))},[N,vt,g]);const Ct=async le=>{const ge=le.trim();if(!(!ge&&xe.length===0))try{const pe=D?($==null?void 0:$.checkpointId)??_??void 0:_??void 0,Te=D?($==null?void 0:$.checkpointNs)??G??void 0:G??void 0;await I({text:ge||"",attachments:xe},{checkpointId:pe,checkpointNs:Te,edit:!!D,originalMessageId:D??void 0}),f==null||f(ge),qe(""),ce(null),_e([]),Se(),X(null),ae(""),Z(null)}catch(pe){const Te=(pe==null?void 0:pe.message)||"Failed to send message";ce(Te),g==null||g(Te)}},Be=b.useCallback((le,ge,pe)=>{c&&(Le.current=rt,X(le),ae(ge),qe(ge),ce(null),Z({checkpointId:(pe==null?void 0:pe.checkpointId)??null,checkpointNs:(pe==null?void 0:pe.checkpointNs)??null}))},[rt,c,qe]),dt=b.useCallback(()=>{X(null),ae(""),Z(null),ce(null),qe(Le.current??rt),Le.current=null},[rt,qe]),$e=b.useCallback((le,ge,pe)=>{Be(le,ge,pe)},[Be]),Qe=b.useCallback(le=>{let ge=null;for(let Xe=le-1;Xe>=0;Xe--)if(S[Xe].role==="user"){ge=S[Xe];break}if(!ge)return;const pe=Array.isArray(ge.content)?ge.content:[],bt=pe.filter(Xe=>(Xe==null?void 0:Xe.type)==="text").map(Xe=>Xe.text).join("")||(()=>{try{return JSON.stringify(pe,null,2)}catch{return String(pe)}})();bt&&I({text:bt},{checkpointId:_??void 0,checkpointNs:G??void 0,edit:!0,originalMessageId:ge.id})},[S,I,_,G]),Ut=le=>{const ge=Array.from(le.target.files||[]);_e(pe=>[...pe,...ge]),le.target.value=""},ql=le=>{_e(ge=>{const pe=ge.filter((Te,bt)=>le!==bt);return pe.length===0&&Se(),pe})},Gl=async le=>{const ge=(le.target.files||[])[0];if(ge){nt(null),Ze(null),Ue(!0);try{await I({attachments:[ge]},{checkpointId:_??void 0,checkpointNs:G??void 0});const pe=`Uploaded ${ge.name} - processing through chat stream`;Ze(pe)}catch(pe){const Te=pe instanceof Error?pe.message:"Failed to upload Excel file";console.error("Excel upload failed",pe),nt(Te),g==null||g(Te)}finally{Ue(!1),le.target.value="",Se()}}},ci=async le=>{if(y){Pt(!0);try{if(!le){await E(),requestAnimationFrame(()=>{var Te;(Te=wt.current)==null||Te.scrollToLatest()});return}const ge=O.find(Te=>Te.checkpointId===le),pe=(ge==null?void 0:ge.checkpointNs)??null;await T(le,pe),requestAnimationFrame(()=>{var Te;(Te=wt.current)==null||Te.scrollToTop()})}finally{Pt(!1)}}},A=b.useCallback(async(le,ge,pe)=>{await ci(pe?null:le)},[ci]),ee=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${m.container||""}`,fe=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${m.messagesArea||""}`,Ne=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${m.inputArea||""}`;return u.jsxs("div",{className:ee,children:[!!N&&!vt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:N}),u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>gt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ue.X,{size:16})})]}),u.jsxs("div",{className:`relative ${fe}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(cl,{ref:wt,className:"h-full",style:{height:"100%"},messages:S,isStreaming:V,streamingAssistantId:J,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Me,enableMessageEditing:c,editingMessageId:D,onEdit:$e,onRegenerate:Qe,onCancelEdit:dt,emptyMessage:ut??void 0,isNavigatingCheckpoint:Dt,activeInterrupt:P,disableInterruptActions:M,onInterruptActionStart:Y,onInterruptActionEnd:se,showToolMessages:d,showArtifactPreviews:p,checkpointIndex:K,activeCheckpointId:_,onSelectCheckpoint:A,createSyntheticThinkingMessage:!0}),(W==="reconnecting"||W==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(ue.Loader2,{className:"h-3 w-3 animate-spin"}),W==="reconnecting"?"Reconnecting…":"Connecting…"]})}),W==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||Dt)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:Ne,children:[D&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ue.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(it,{variant:"ghost",size:"sm",onClick:dt,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ue.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:kt,type:"file",multiple:!0,onChange:le=>Ut(le),className:"hidden"},Ve),xe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:xe.map((le,ge)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(ue.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:le.name}),u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>ql(ge),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${le.name}`,children:u.jsx(ue.X,{size:12})})]},ge))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:ne,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Gl,className:"hidden"},Ee),Ke&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),et&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:et}),Ye&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Ye})]})]}),de&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:de}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(vs,{children:[u.jsx(ws,{asChild:!0,children:u.jsx(it,{type:"button",size:"icon",variant:"outline",disabled:V||B,title:"More input actions",className:m.moreButton||"",children:u.jsx(ue.Plus,{size:16})})}),u.jsxs(ao,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(On,{onClick:()=>{var le;return(le=kt.current)==null?void 0:le.click()},className:"cursor-pointer",children:[u.jsx(ue.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(On,{onClick:()=>{var le;Ke||(le=ne.current)==null||le.click()},className:`cursor-pointer ${Ke?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ue.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(mS,{initialValue:re,editingMessageId:D,value:rt,onValueChange:ft,placeholder:D?"Edit your message...":t,isStreaming:V,disabled:B,onSend:Ct,onCancelEdit:dt,onStop:F,allowEmptySend:xe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${D?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${de?"border-red-400":""} ${m.textarea||""}`})})]})]})]})}var Nh=1,CT=.9,TT=.8,kT=.17,ul=.1,dl=.999,ET=.9999,IT=.99,NT=/[\\\/_+.#"@\[\(\{&]/,AT=/[\\\/_+.#"@\[\(\{&]/g,jT=/[\s-]/,Ah=/[\s-]/g;function fl(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?Nh:IT;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),c=n.indexOf(l,o),d=0,p,m,f,v;c>=0;)p=fl(e,t,n,r,c+1,s+1,i),p>d&&(c===o?p*=Nh:NT.test(e.charAt(c-1))?(p*=TT,f=e.slice(o,c-1).match(AT),f&&o>0&&(p*=Math.pow(dl,f.length))):jT.test(e.charAt(c-1))?(p*=CT,v=e.slice(o,c-1).match(Ah),v&&o>0&&(p*=Math.pow(dl,v.length))):(p*=kT,o>0&&(p*=Math.pow(dl,c-o))),e.charAt(c)!==t.charAt(s)&&(p*=ET)),(p<ul&&n.charAt(c-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(c-1)!==r.charAt(s))&&(m=fl(e,t,n,r,c+1,s+2,i),m*ul>p&&(p=m*ul)),p>d&&(d=p),c=n.indexOf(l,c+1);return i[a]=d,d}function jh(e){return e.toLowerCase().replace(Ah," ")}function _T(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,fl(e,t,jh(e),jh(t),0,0,{})}var Co='[cmdk-group=""]',pl='[cmdk-group-items=""]',PT='[cmdk-group-heading=""]',_h='[cmdk-item=""]',Ph=`${_h}:not([aria-disabled="true"])`,hl="cmdk-item-select",jr="data-value",RT=(e,t,n)=>_T(e,t,n),Rh=h.createContext(void 0),To=()=>h.useContext(Rh),Mh=h.createContext(void 0),ml=()=>h.useContext(Mh),Oh=h.createContext(void 0),Dh=h.forwardRef((e,t)=>{let n=_r(()=>{var P,M;return{search:"",value:(M=(P=e.value)!=null?P:e.defaultValue)!=null?M:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=_r(()=>new Set),o=_r(()=>new Map),s=_r(()=>new Map),i=_r(()=>new Set),a=Lh(e),{label:l,children:c,value:d,onValueChange:p,filter:m,shouldFilter:f,loop:v,disablePointerSelection:g=!1,vimBindings:x=!0,...y}=e,w=It(),S=It(),k=It(),C=h.useRef(null),T=WT();sr(()=>{if(d!==void 0){let P=d.trim();n.current.value=P,E.emit()}},[d]),sr(()=>{T(6,V)},[]);let E=h.useMemo(()=>({subscribe:P=>(i.current.add(P),()=>i.current.delete(P)),snapshot:()=>n.current,setState:(P,M,q)=>{var Y,se,B,D;if(!Object.is(n.current[P],M)){if(n.current[P]=M,P==="search")K(),L(),T(1,U);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let X=document.getElementById(k);X?X.focus():(Y=document.getElementById(w))==null||Y.focus()}if(T(7,()=>{var X;n.current.selectedItemId=(X=N())==null?void 0:X.id,E.emit()}),q||T(5,V),((se=a.current)==null?void 0:se.value)!==void 0){let X=M??"";(D=(B=a.current).onValueChange)==null||D.call(B,X);return}}E.emit()}},emit:()=>{i.current.forEach(P=>P())}}),[]),j=h.useMemo(()=>({value:(P,M,q)=>{var Y;M!==((Y=s.current.get(P))==null?void 0:Y.value)&&(s.current.set(P,{value:M,keywords:q}),n.current.filtered.items.set(P,O(M,q)),T(2,()=>{L(),E.emit()}))},item:(P,M)=>(r.current.add(P),M&&(o.current.has(M)?o.current.get(M).add(P):o.current.set(M,new Set([P]))),T(3,()=>{K(),L(),n.current.value||U(),E.emit()}),()=>{s.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let q=N();T(4,()=>{K(),(q==null?void 0:q.getAttribute("id"))===P&&U(),E.emit()})}),group:P=>(o.current.has(P)||o.current.set(P,new Set),()=>{s.current.delete(P),o.current.delete(P)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:w,inputId:k,labelId:S,listInnerRef:C}),[]);function O(P,M){var q,Y;let se=(Y=(q=a.current)==null?void 0:q.filter)!=null?Y:RT;return P?se(P,n.current.search,M):0}function L(){if(!n.current.search||a.current.shouldFilter===!1)return;let P=n.current.filtered.items,M=[];n.current.filtered.groups.forEach(Y=>{let se=o.current.get(Y),B=0;se.forEach(D=>{let X=P.get(D);B=Math.max(X,B)}),M.push([Y,B])});let q=C.current;W().sort((Y,se)=>{var B,D;let X=Y.getAttribute("id"),re=se.getAttribute("id");return((B=P.get(re))!=null?B:0)-((D=P.get(X))!=null?D:0)}).forEach(Y=>{let se=Y.closest(pl);se?se.appendChild(Y.parentElement===se?Y:Y.closest(`${pl} > *`)):q.appendChild(Y.parentElement===q?Y:Y.closest(`${pl} > *`))}),M.sort((Y,se)=>se[1]-Y[1]).forEach(Y=>{var se;let B=(se=C.current)==null?void 0:se.querySelector(`${Co}[${jr}="${encodeURIComponent(Y[0])}"]`);B==null||B.parentElement.appendChild(B)})}function U(){let P=W().find(q=>q.getAttribute("aria-disabled")!=="true"),M=P==null?void 0:P.getAttribute(jr);E.setState("value",M||void 0)}function K(){var P,M,q,Y;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let se=0;for(let B of r.current){let D=(M=(P=s.current.get(B))==null?void 0:P.value)!=null?M:"",X=(Y=(q=s.current.get(B))==null?void 0:q.keywords)!=null?Y:[],re=O(D,X);n.current.filtered.items.set(B,re),re>0&&se++}for(let[B,D]of o.current)for(let X of D)if(n.current.filtered.items.get(X)>0){n.current.filtered.groups.add(B);break}n.current.filtered.count=se}function V(){var P,M,q;let Y=N();Y&&(((P=Y.parentElement)==null?void 0:P.firstChild)===Y&&((q=(M=Y.closest(Co))==null?void 0:M.querySelector(PT))==null||q.scrollIntoView({block:"nearest"})),Y.scrollIntoView({block:"nearest"}))}function N(){var P;return(P=C.current)==null?void 0:P.querySelector(`${_h}[aria-selected="true"]`)}function W(){var P;return Array.from(((P=C.current)==null?void 0:P.querySelectorAll(Ph))||[])}function I(P){let M=W()[P];M&&E.setState("value",M.getAttribute(jr))}function F(P){var M;let q=N(),Y=W(),se=Y.findIndex(D=>D===q),B=Y[se+P];(M=a.current)!=null&&M.loop&&(B=se+P<0?Y[Y.length-1]:se+P===Y.length?Y[0]:Y[se+P]),B&&E.setState("value",B.getAttribute(jr))}function R(P){let M=N(),q=M==null?void 0:M.closest(Co),Y;for(;q&&!Y;)q=P>0?HT(q,Co):UT(q,Co),Y=q==null?void 0:q.querySelector(Ph);Y?E.setState("value",Y.getAttribute(jr)):F(P)}let _=()=>I(W().length-1),G=P=>{P.preventDefault(),P.metaKey?_():P.altKey?R(1):F(1)},J=P=>{P.preventDefault(),P.metaKey?I(0):P.altKey?R(-1):F(-1)};return h.createElement(ve.div,{ref:t,tabIndex:-1,...y,"cmdk-root":"",onKeyDown:P=>{var M;(M=y.onKeyDown)==null||M.call(y,P);let q=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||q))switch(P.key){case"n":case"j":{x&&P.ctrlKey&&G(P);break}case"ArrowDown":{G(P);break}case"p":case"k":{x&&P.ctrlKey&&J(P);break}case"ArrowUp":{J(P);break}case"Home":{P.preventDefault(),I(0);break}case"End":{P.preventDefault(),_();break}case"Enter":{P.preventDefault();let Y=N();if(Y){let se=new Event(hl);Y.dispatchEvent(se)}}}}},h.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:KT},l),Ks(e,P=>h.createElement(Mh.Provider,{value:E},h.createElement(Rh.Provider,{value:j},P))))}),MT=h.forwardRef((e,t)=>{var n,r;let o=It(),s=h.useRef(null),i=h.useContext(Oh),a=To(),l=Lh(e),c=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;sr(()=>{if(!c)return a.item(o,i==null?void 0:i.id)},[c]);let d=$h(o,s,[e.value,e.children,s],e.keywords),p=ml(),m=Hn(T=>T.value&&T.value===d.current),f=Hn(T=>c||a.filter()===!1?!0:T.search?T.filtered.items.get(o)>0:!0);h.useEffect(()=>{let T=s.current;if(!(!T||e.disabled))return T.addEventListener(hl,v),()=>T.removeEventListener(hl,v)},[f,e.onSelect,e.disabled]);function v(){var T,E;g(),(E=(T=l.current).onSelect)==null||E.call(T,d.current)}function g(){p.setState("value",d.current,!0)}if(!f)return null;let{disabled:x,value:y,onSelect:w,forceMount:S,keywords:k,...C}=e;return h.createElement(ve.div,{ref:jn(s,t),...C,id:o,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!m,"data-disabled":!!x,"data-selected":!!m,onPointerMove:x||a.getDisablePointerSelection()?void 0:g,onClick:x?void 0:v},e.children)}),OT=h.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=It(),a=h.useRef(null),l=h.useRef(null),c=It(),d=To(),p=Hn(f=>o||d.filter()===!1?!0:f.search?f.filtered.groups.has(i):!0);sr(()=>d.group(i),[]),$h(i,a,[e.value,e.heading,l]);let m=h.useMemo(()=>({id:i,forceMount:o}),[o]);return h.createElement(ve.div,{ref:jn(a,t),...s,"cmdk-group":"",role:"presentation",hidden:p?void 0:!0},n&&h.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),Ks(e,f=>h.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},h.createElement(Oh.Provider,{value:m},f))))}),DT=h.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=h.useRef(null),s=Hn(i=>!i.search);return!n&&!s?null:h.createElement(ve.div,{ref:jn(o,t),...r,"cmdk-separator":"",role:"separator"})}),LT=h.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=ml(),i=Hn(c=>c.search),a=Hn(c=>c.selectedItemId),l=To();return h.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),h.createElement(ve.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:c=>{o||s.setState("search",c.target.value),n==null||n(c.target.value)}})}),$T=h.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=h.useRef(null),i=h.useRef(null),a=Hn(c=>c.selectedItemId),l=To();return h.useEffect(()=>{if(i.current&&s.current){let c=i.current,d=s.current,p,m=new ResizeObserver(()=>{p=requestAnimationFrame(()=>{let f=c.offsetHeight;d.style.setProperty("--cmdk-list-height",f.toFixed(1)+"px")})});return m.observe(c),()=>{cancelAnimationFrame(p),m.unobserve(c)}}},[]),h.createElement(ve.div,{ref:jn(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Ks(e,c=>h.createElement("div",{ref:jn(i,l.listInnerRef),"cmdk-list-sizer":""},c)))}),FT=h.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return h.createElement(qa,{open:n,onOpenChange:r},h.createElement(Ga,{container:i},h.createElement(wo,{"cmdk-overlay":"",className:o}),h.createElement(bo,{"aria-label":e.label,"cmdk-dialog":"",className:s},h.createElement(Dh,{ref:t,...a}))))}),BT=h.forwardRef((e,t)=>Hn(n=>n.filtered.count===0)?h.createElement(ve.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),zT=h.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return h.createElement(ve.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},Ks(e,i=>h.createElement("div",{"aria-hidden":!0},i)))}),zt=Object.assign(Dh,{List:$T,Item:MT,Input:LT,Group:OT,Separator:DT,Dialog:FT,Empty:BT,Loading:zT});function HT(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function UT(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Lh(e){let t=h.useRef(e);return sr(()=>{t.current=e}),t}var sr=typeof window>"u"?h.useEffect:h.useLayoutEffect;function _r(e){let t=h.useRef();return t.current===void 0&&(t.current=e()),t}function Hn(e){let t=ml(),n=()=>e(t.snapshot());return h.useSyncExternalStore(t.subscribe,n,n)}function $h(e,t,n,r=[]){let o=h.useRef(),s=To();return sr(()=>{var i;let a=(()=>{var c;for(let d of n){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?(c=d.current.textContent)==null?void 0:c.trim():o.current}})(),l=r.map(c=>c.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(jr,a),o.current=a}),o}var WT=()=>{let[e,t]=h.useState(),n=_r(()=>new Map);return sr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function VT(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Ks({asChild:e,children:t},n){return e&&h.isValidElement(t)?h.cloneElement(VT(t),{ref:t.ref},n(t.props.children)):n(t)}var KT={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const gl=h.forwardRef(({className:e,...t},n)=>u.jsx(zt,{ref:n,className:te("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));gl.displayName=zt.displayName;const xl=h.forwardRef(({className:e,...t},n)=>u.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[u.jsx(ue.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),u.jsx(zt.Input,{ref:n,className:te("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));xl.displayName=zt.Input.displayName;const vl=h.forwardRef(({className:e,...t},n)=>u.jsx(zt.List,{ref:n,className:te("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));vl.displayName=zt.List.displayName;const wl=h.forwardRef((e,t)=>u.jsx(zt.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));wl.displayName=zt.Empty.displayName;const bl=h.forwardRef(({className:e,...t},n)=>u.jsx(zt.Group,{ref:n,className:te("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));bl.displayName=zt.Group.displayName;const qT=h.forwardRef(({className:e,...t},n)=>u.jsx(zt.Separator,{ref:n,className:te("-mx-1 h-px bg-border",e),...t}));qT.displayName=zt.Separator.displayName;const yl=h.forwardRef(({className:e,...t},n)=>u.jsx(zt.Item,{ref:n,className:te("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));yl.displayName=zt.Item.displayName;function Sl(e,[t,n]){return Math.min(n,Math.max(t,e))}function GT(e,t){return h.useReducer((n,r)=>t[n][r]??n,e)}var Cl="ScrollArea",[Fh,l1]=on(Cl),[YT,tn]=Fh(Cl),Bh=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=h.useState(null),[c,d]=h.useState(null),[p,m]=h.useState(null),[f,v]=h.useState(null),[g,x]=h.useState(null),[y,w]=h.useState(0),[S,k]=h.useState(0),[C,T]=h.useState(!1),[E,j]=h.useState(!1),O=Oe(t,U=>l(U)),L=Ko(o);return u.jsx(YT,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:p,onContentChange:m,scrollbarX:f,onScrollbarXChange:v,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:x,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:w,onCornerHeightChange:k,children:u.jsx(ve.div,{dir:L,...i,ref:O,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Bh.displayName=Cl;var zh="ScrollAreaViewport",Hh=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=tn(zh,n),a=h.useRef(null),l=Oe(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(ve.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Hh.displayName=zh;var Tn="ScrollAreaScrollbar",Tl=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Tn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return h.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(XT,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(JT,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Uh,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(kl,{...r,ref:t}):null});Tl.displayName=Tn;var XT=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Tn,e.__scopeScrollArea),[s,i]=h.useState(!1);return h.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Ft,{present:n||s,children:u.jsx(Uh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),JT=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Tn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Xs(()=>l("SCROLL_END"),100),[a,l]=GT("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return h.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),h.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let p=c[d];const m=()=>{const f=c[d];p!==f&&(l("SCROLL"),i()),p=f};return c.addEventListener("scroll",m),()=>c.removeEventListener("scroll",m)}},[o.viewport,s,l,i]),u.jsx(Ft,{present:n||a!=="hidden",children:u.jsx(kl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ie(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ie(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Uh=h.forwardRef((e,t)=>{const n=tn(Tn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=h.useState(!1),a=e.orientation==="horizontal",l=Xs(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Pr(n.viewport,l),Pr(n.content,l),u.jsx(Ft,{present:r||s,children:u.jsx(kl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),kl=h.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=tn(Tn,e.__scopeScrollArea),s=h.useRef(null),i=h.useRef(0),[a,l]=h.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Gh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:m=>s.current=m,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:m=>i.current=m};function p(m,f){return rk(m,i.current,a,f)}return n==="horizontal"?u.jsx(ZT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,f=Yh(m,a,o.dir);s.current.style.transform=`translate3d(${f}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=p(m,o.dir))}}):n==="vertical"?u.jsx(QT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,f=Yh(m,a);s.current.style.transform=`translate3d(0, ${f}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=p(m))}}):null}),ZT=h.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(Tn,e.__scopeScrollArea),[i,a]=h.useState(),l=h.useRef(null),c=Oe(t,l,s.onScrollbarXChange);return h.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Vh,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ys(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,p)=>{if(s.viewport){const m=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(m),Jh(m,p)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Gs(i.paddingLeft),paddingEnd:Gs(i.paddingRight)}})}})}),QT=h.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(Tn,e.__scopeScrollArea),[i,a]=h.useState(),l=h.useRef(null),c=Oe(t,l,s.onScrollbarYChange);return h.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Vh,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ys(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,p)=>{if(s.viewport){const m=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(m),Jh(m,p)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Gs(i.paddingTop),paddingEnd:Gs(i.paddingBottom)}})}})}),[ek,Wh]=Fh(Tn),Vh=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:p,...m}=e,f=tn(Tn,n),[v,g]=h.useState(null),x=Oe(t,O=>g(O)),y=h.useRef(null),w=h.useRef(""),S=f.viewport,k=r.content-r.viewport,C=ht(d),T=ht(l),E=Xs(p,10);function j(O){if(y.current){const L=O.clientX-y.current.left,U=O.clientY-y.current.top;c({x:L,y:U})}}return h.useEffect(()=>{const O=L=>{const U=L.target;(v==null?void 0:v.contains(U))&&C(L,k)};return document.addEventListener("wheel",O,{passive:!1}),()=>document.removeEventListener("wheel",O,{passive:!1})},[S,v,k,C]),h.useEffect(T,[r,T]),Pr(v,E),Pr(f.content,E),u.jsx(ek,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:ht(s),onThumbPointerUp:ht(i),onThumbPositionChange:T,onThumbPointerDown:ht(a),children:u.jsx(ve.div,{...m,ref:x,style:{position:"absolute",...m.style},onPointerDown:ie(e.onPointerDown,O=>{O.button===0&&(O.target.setPointerCapture(O.pointerId),y.current=v.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",f.viewport&&(f.viewport.style.scrollBehavior="auto"),j(O))}),onPointerMove:ie(e.onPointerMove,j),onPointerUp:ie(e.onPointerUp,O=>{const L=O.target;L.hasPointerCapture(O.pointerId)&&L.releasePointerCapture(O.pointerId),document.body.style.webkitUserSelect=w.current,f.viewport&&(f.viewport.style.scrollBehavior=""),y.current=null})})})}),qs="ScrollAreaThumb",Kh=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Wh(qs,e.__scopeScrollArea);return u.jsx(Ft,{present:n||o.hasThumb,children:u.jsx(tk,{ref:t,...r})})}),tk=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=tn(qs,n),i=Wh(qs,n),{onThumbPositionChange:a}=i,l=Oe(t,p=>i.onThumbChange(p)),c=h.useRef(void 0),d=Xs(()=>{c.current&&(c.current(),c.current=void 0)},100);return h.useEffect(()=>{const p=s.viewport;if(p){const m=()=>{if(d(),!c.current){const f=ok(p,a);c.current=f,a()}};return a(),p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)}},[s.viewport,d,a]),u.jsx(ve.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ie(e.onPointerDownCapture,p=>{const f=p.target.getBoundingClientRect(),v=p.clientX-f.left,g=p.clientY-f.top;i.onThumbPointerDown({x:v,y:g})}),onPointerUp:ie(e.onPointerUp,i.onThumbPointerUp)})});Kh.displayName=qs;var El="ScrollAreaCorner",qh=h.forwardRef((e,t)=>{const n=tn(El,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(nk,{...e,ref:t}):null});qh.displayName=El;var nk=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=tn(El,n),[s,i]=h.useState(0),[a,l]=h.useState(0),c=!!(s&&a);return Pr(o.scrollbarX,()=>{var p;const d=((p=o.scrollbarX)==null?void 0:p.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Pr(o.scrollbarY,()=>{var p;const d=((p=o.scrollbarY)==null?void 0:p.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(ve.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Gs(e){return e?parseInt(e,10):0}function Gh(e,t){const n=e/t;return isNaN(n)?0:n}function Ys(e){const t=Gh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function rk(e,t,n,r="ltr"){const o=Ys(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,p=r==="ltr"?[0,d]:[d*-1,0];return Xh([l,c],p)(e)}function Yh(e,t,n="ltr"){const r=Ys(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Sl(e,l);return Xh([0,i],[0,a])(c)}function Xh(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Jh(e,t){return e>0&&e<t}var ok=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Xs(e,t){const n=ht(e),r=h.useRef(0);return h.useEffect(()=>()=>window.clearTimeout(r.current),[]),h.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Pr(e,t){const n=ht(t);Tt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Zh=Bh,sk=Hh,ik=qh;const Il=h.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Zh,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(sk,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Qh,{}),u.jsx(ik,{})]}));Il.displayName=Zh.displayName;const Qh=h.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Tl,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Kh,{className:"relative flex-1 rounded-full bg-border"})}));Qh.displayName=Tl.displayName;const Nl=h.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Nl.displayName="Input";const ak="group relative p-3 rounded-lg cursor-pointer transition-colors border text-gray-900 dark:text-slate-100",lk="bg-slate-700 border-slate-600 hover:bg-slate-600",ck="bg-slate-600 border-slate-500";function em({thread:e,isActive:t,editingThreadId:n,editingTitle:r,onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:l,onShare:c,onDelete:d,showEditTitle:p,showDeleteButton:m,formatDate:f,getDisplayThreadTitle:v,secondaryLine:g,itemClassName:x,activeItemClassName:y}){const w=n===e.threadId,S=t?`${y??ck}`:`${x??lk}`,k=C=>{C.stopPropagation(),o(e.threadId)};return u.jsxs("div",{onClick:k,className:`${ak} ${S}`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:w?u.jsxs("div",{className:"flex items-center gap-2",onClick:C=>C.stopPropagation(),children:[u.jsx(Nl,{value:r,onChange:C=>i(C.target.value),onKeyDown:C=>{C.key==="Enter"?a(e.threadId):C.key==="Escape"&&l()},className:"h-6 text-sm",autoFocus:!0}),u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>a(e.threadId),className:"h-6 w-6 p-0",children:u.jsx(ue.Check,{size:12})}),u.jsx(it,{variant:"ghost",size:"sm",onClick:l,className:"h-6 w-6 p-0",children:u.jsx(ue.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:v(e)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ue.Calendar,{size:10}),u.jsx("span",{children:f(e.updatedAt||e.createdAt)})]}),g&&u.jsx("div",{className:"text-[11px] text-muted-foreground mt-1",children:g})]})}),u.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:u.jsxs(vs,{children:[u.jsx(ws,{asChild:!0,children:u.jsx(it,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:u.jsx(ue.MoreHorizontal,{size:12})})}),u.jsxs(ao,{align:"end",sideOffset:6,className:"w-44",children:[u.jsxs(On,{onClick:C=>{C.preventDefault(),c(e.threadId)},children:[u.jsx(ue.Share2,{className:"mr-2 h-4 w-4"}),"Share thread"]}),p&&n!==e.threadId&&u.jsxs(On,{onClick:C=>{C.preventDefault(),s(e,C)},children:[u.jsx(ue.Edit3,{className:"mr-2 h-4 w-4"}),"Rename"]}),m&&d&&u.jsxs(On,{className:"text-red-400 hover:text-red-300",onClick:C=>{C.preventDefault(),d(e.threadId,C)},children:[u.jsx(ue.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})})]}),t&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]})}const tm=25,nm="thread-manager-view",uk=e=>e==="default"||e==="shared",dk=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(nm);if(uk(e))return e}catch{}return null};function rm({defaultView:e}={}){const[t,n]=b.useState(()=>dk()??e??"default");b.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(nm,t)}catch{}},[t]);const r=b.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const fk=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function Al({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d,view:p,defaultView:m,onViewChange:f,viewOptions:v,viewState:g,showHeader:x=!0,shareTargets:y,isLoadingShareTargets:w,shareTargetFilter:S}){const{threads:k,sharedThreads:C,currentThreadId:T,setCurrentThreadId:E,isLoading:j,isLoadingSharedThreads:O,actions:L,shareInFlight:U,shareStatus:K,clearShareStatus:V}=pr(),{createThread:N,deleteThread:W,renameThread:I,shareThread:F}=L,{loadThread:R}=Yr(),_=i??T,[G,J]=b.useState(Array.isArray(k)?k:[]),P=b.useRef(G.length>0),M=b.useRef(null),q=b.useRef(0),[Y,se]=b.useState(null),[B,D]=b.useState(""),[X,re]=b.useState(!1),[ae,$]=b.useState(!1),[Z,de]=b.useState(null),[ce,xe]=b.useState(""),_e=v&&v.length>0?v:fk,Ve=rm({defaultView:m}),He=g??Ve,Ee=p??He.view,Fe=b.useCallback(ne=>{p||He.setView(ne),f==null||f(ne)},[p,f,He]),Ke=_e.find(ne=>ne.key===Ee)??_e[0],Ue=ne=>{de(ne),xe(""),$(!0)},Ye=()=>{$(!1),de(null),xe(""),V()},nt=b.useCallback(async ne=>{if(!(!Z||U)&&ne.id)try{await F(Z,ne.id),setTimeout(()=>Ye(),600)}catch(Se){console.error("Failed to share thread:",Se)}},[Ye,U,Z,F]),et=b.useMemo(()=>{const ne=y??[],Se=ce.trim().toLowerCase();return Se?S?ne.filter(ft=>S(ft,Se)):ne.filter(ft=>`${ft.label} ${ft.secondaryLabel??""}`.toLowerCase().includes(Se)):ne},[y,ce,S]),Ze=Ee==="shared",vt=Ze?C:G,gt=Ze?O:j,ut=Ze?"No shared conversations yet":"No conversations yet",ye=ne=>{const Se=ne.sharedAt?` • ${Pt(ne.sharedAt)}`:"";return`Shared by ${ne.sharedByUserId}${Se}`},tt=ne=>"sharedByUserId"in ne;b.useEffect(()=>{const ne=Array.isArray(k)?k:[];if(ne.length>0){P.current=!0,J(ne);return}j||(P.current=!1,J(ne))},[k,j]),b.useEffect(()=>{if(!M.current)return;const ne=M.current.querySelector("[data-radix-scroll-area-viewport]");if(!ne)return;let Se=null,ft=null;return Se=requestAnimationFrame(()=>{ft=requestAnimationFrame(()=>{ne.scrollTop=q.current})}),()=>{Se!==null&&cancelAnimationFrame(Se),ft!==null&&cancelAnimationFrame(ft)}},[G]);const rt=async ne=>{try{E(ne),await R(ne),a==null||a(ne),l==null||l(ne)}catch(Se){console.error("Failed to select thread:",Se)}},_t=async()=>{try{re(!0);const ne=await N();ne&&(c==null||c(ne),a==null||a(ne))}catch(ne){console.error("Failed to create thread:",ne)}finally{re(!1)}},pn=async(ne,Se)=>{if(Se.stopPropagation(),!!confirm("Delete this thread?")){if(M.current){const ft=M.current.querySelector("[data-radix-scroll-area-viewport]");ft&&(q.current=ft.scrollTop)}try{await W(ne),d==null||d(ne)}catch(ft){console.error("Failed to delete thread:",ft)}}},Le=(ne,Se)=>{Se.stopPropagation(),se(ne.threadId),D(ne.title||`Thread ${ne.threadId.slice(0,8)}`)},qe=async ne=>{if(B.trim())try{await I(ne,B.trim()),se(null),D("")}catch(Se){console.error("Failed to update title:",Se)}},Dt=()=>{se(null),D("")},Pt=ne=>{if(!ne)return"";try{const Se=new Date(ne),Ce=new Date().getTime()-Se.getTime(),Me=Math.floor(Ce/(1e3*60*60*24));return Me===0?Se.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Me===1?"Yesterday":Me<7?`${Me} days ago`:Se.toLocaleDateString()}catch{return""}},wt=ne=>ne.title||`Thread ${ne.threadId.slice(0,8)}`,kt=ne=>{const Se=wt(ne);return Se.length<=tm?Se:`${Se.slice(0,tm)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[x&&u.jsxs("div",{className:s.header||"flex flex-col gap-2 px-1 py-0 border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900 shadow-sm",children:[t&&u.jsx("div",{className:"flex justify-end",children:u.jsxs(it,{onClick:_t,disabled:X||j,className:s.createButton||"px-3 py-2 gap-1",size:"sm",variant:"ghost",title:X?"Creating...":"New Chat",children:[u.jsx(ue.Edit3,{size:16}),u.jsx("span",{children:"New chat"})]})}),u.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-slate-700 dark:text-slate-200 uppercase tracking-wide leading-tight",children:[u.jsx("span",{children:"Current View"}),u.jsxs(vs,{children:[u.jsx(ws,{asChild:!0,children:u.jsx(it,{variant:"outline",size:"sm",className:"text-[11px] text-slate-700 dark:text-slate-200 border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 px-2 py-0",children:Ke.label})}),u.jsx(ao,{align:"start",sideOffset:6,className:"w-40",children:_e.map(ne=>u.jsxs(On,{className:"justify-between text-[12px]",onClick:Se=>{Se.preventDefault(),Fe(ne.key)},children:[u.jsx("span",{children:ne.label}),Ee===ne.key&&u.jsx(ue.Check,{className:"h-3 w-3"})]},ne.key))})]})]})]}),u.jsx(Il,{ref:M,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:gt?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ue.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):vt.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(ue.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:ut})]}):vt.slice().sort((ne,Se)=>new Date(Se.updatedAt||Se.createdAt||"").getTime()-new Date(ne.updatedAt||ne.createdAt||"").getTime()).map(ne=>u.jsx(em,{thread:ne,isActive:_===ne.threadId,editingThreadId:Y,editingTitle:B,onSelect:rt,onStartEditing:Le,onEditingTitleChange:Se=>D(Se),onSaveEditing:qe,onCancelEditing:Dt,onShare:()=>Ue(ne.threadId),onDelete:pn,showEditTitle:r,showDeleteButton:n,formatDate:Pt,getDisplayThreadTitle:kt,secondaryLine:Ze&&tt(ne)?ye(ne):void 0,itemClassName:s.threadItem,activeItemClassName:s.activeThread},ne.threadId))})}),u.jsx(Ya,{open:ae,onOpenChange:ne=>!ne&&Ye(),children:u.jsxs(Ds,{className:"max-w-md p-0",children:[u.jsx(Ls,{children:u.jsx($s,{children:"Share thread"})}),u.jsxs(gl,{children:[u.jsx(xl,{autoFocus:!0,value:ce,onValueChange:ne=>xe(ne),placeholder:"Search for recipients..."}),u.jsxs(vl,{children:[K&&u.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[U&&u.jsx(ue.Loader2,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{className:K.startsWith("Failed")?"text-red-500":K.startsWith("Shared")?"text-emerald-500":"text-slate-600 dark:text-slate-400",children:K})]}),u.jsx(wl,{children:w?u.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading recipients…"]}):"No matching recipients found"}),et.length>0&&u.jsx(bl,{heading:"Recipients",children:et.map(ne=>u.jsx(yl,{onSelect:()=>nt(ne),children:u.jsxs("div",{className:"flex flex-col items-start text-sm",children:[u.jsx("span",{className:"font-medium",children:ne.label}),ne.secondaryLabel&&u.jsx("span",{className:"text-xs text-muted-foreground",children:ne.secondaryLabel})]})},ne.id))})]})]})]})})]})}function pk({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Xr,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(So,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Xr,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Al,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(So,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Xr,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Al,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(So,{onError:s.onError,enableFileUpload:!0})})]})})}function hk({apiConfig:e,className:t="",onError:n}){return u.jsx(Xr,{apiConfig:e,onError:n,children:u.jsx("div",{className:`h-full ${t}`,children:u.jsx(So,{})})})}var mk="Label",om=h.forwardRef((e,t)=>u.jsx(ve.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));om.displayName=mk;var sm=om;const gk=Dr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),im=h.forwardRef(({className:e,...t},n)=>u.jsx(sm,{ref:n,className:te(gk(),e),...t}));im.displayName=sm.displayName;function am(e){const t=h.useRef({value:e,previous:e});return h.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var lm=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),xk="VisuallyHidden",Js=h.forwardRef((e,t)=>u.jsx(ve.span,{...e,ref:t,style:{...lm,...e.style}}));Js.displayName=xk;var vk=Js,wk=[" ","Enter","ArrowUp","ArrowDown"],bk=[" ","Enter"],ir="Select",[Zs,Qs,yk]=Vo(ir),[Rr,c1]=on(ir,[yk,yr]),ei=yr(),[Sk,Un]=Rr(ir),[Ck,Tk]=Rr(ir),cm=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:p,disabled:m,required:f,form:v}=e,g=ei(t),[x,y]=h.useState(null),[w,S]=h.useState(null),[k,C]=h.useState(!1),T=Ko(c),[E,j]=_n({prop:r,defaultProp:o??!1,onChange:s,caller:ir}),[O,L]=_n({prop:i,defaultProp:a,onChange:l,caller:ir}),U=h.useRef(null),K=x?v||!!x.closest("form"):!0,[V,N]=h.useState(new Set),W=Array.from(V).map(I=>I.props.value).join(";");return u.jsx(ea,{...g,children:u.jsxs(Sk,{required:f,scope:t,trigger:x,onTriggerChange:y,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:It(),value:O,onValueChange:L,open:E,onOpenChange:j,dir:T,triggerPointerDownPosRef:U,disabled:m,children:[u.jsx(Zs.Provider,{scope:t,children:u.jsx(Ck,{scope:e.__scopeSelect,onNativeOptionAdd:h.useCallback(I=>{N(F=>new Set(F).add(I))},[]),onNativeOptionRemove:h.useCallback(I=>{N(F=>{const R=new Set(F);return R.delete(I),R})},[]),children:n})}),K?u.jsxs(Rm,{"aria-hidden":!0,required:f,tabIndex:-1,name:d,autoComplete:p,value:O,onChange:I=>L(I.target.value),disabled:m,form:v,children:[O===void 0?u.jsx("option",{value:""}):null,Array.from(V)]},W):null]})})};cm.displayName=ir;var um="SelectTrigger",dm=h.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ei(n),i=Un(um,n),a=i.disabled||r,l=Oe(t,i.onTriggerChange),c=Qs(n),d=h.useRef("touch"),[p,m,f]=Om(g=>{const x=c().filter(S=>!S.disabled),y=x.find(S=>S.value===i.value),w=Dm(x,g,y);w!==void 0&&i.onValueChange(w.value)}),v=g=>{a||(i.onOpenChange(!0),f()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ta,{asChild:!0,...s,children:u.jsx(ve.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":Mm(i.value)?"":void 0,...o,ref:l,onClick:ie(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&v(g)}),onPointerDown:ie(o.onPointerDown,g=>{d.current=g.pointerType;const x=g.target;x.hasPointerCapture(g.pointerId)&&x.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(v(g),g.preventDefault())}),onKeyDown:ie(o.onKeyDown,g=>{const x=p.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&m(g.key),!(x&&g.key===" ")&&wk.includes(g.key)&&(v(),g.preventDefault())})})})});dm.displayName=um;var fm="SelectValue",pm=h.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Un(fm,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,p=Oe(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(ve.span,{...a,ref:p,style:{pointerEvents:"none"},children:Mm(l.value)?u.jsx(u.Fragment,{children:i}):s})});pm.displayName=fm;var kk="SelectIcon",hm=h.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(ve.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});hm.displayName=kk;var Ek="SelectPortal",mm=e=>u.jsx(eo,{asChild:!0,...e});mm.displayName=Ek;var ar="SelectContent",gm=h.forwardRef((e,t)=>{const n=Un(ar,e.__scopeSelect),[r,o]=h.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Lr.createPortal(u.jsx(xm,{scope:e.__scopeSelect,children:u.jsx(Zs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(vm,{...e,ref:t})});gm.displayName=ar;var dn=10,[xm,Wn]=Rr(ar),Ik="SelectContentImpl",Nk=Vt.createSlot("SelectContent.RemoveScroll"),vm=h.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:p,collisionBoundary:m,collisionPadding:f,sticky:v,hideWhenDetached:g,avoidCollisions:x,...y}=e,w=Un(ar,n),[S,k]=h.useState(null),[C,T]=h.useState(null),E=Oe(t,B=>k(B)),[j,O]=h.useState(null),[L,U]=h.useState(null),K=Qs(n),[V,N]=h.useState(!1),W=h.useRef(!1);h.useEffect(()=>{if(S)return aa(S)},[S]),$i();const I=h.useCallback(B=>{const[D,...X]=K().map($=>$.ref.current),[re]=X.slice(-1),ae=document.activeElement;for(const $ of B)if($===ae||($==null||$.scrollIntoView({block:"nearest"}),$===D&&C&&(C.scrollTop=0),$===re&&C&&(C.scrollTop=C.scrollHeight),$==null||$.focus(),document.activeElement!==ae))return},[K,C]),F=h.useCallback(()=>I([j,S]),[I,j,S]);h.useEffect(()=>{V&&F()},[V,F]);const{onOpenChange:R,triggerPointerDownPosRef:_}=w;h.useEffect(()=>{if(S){let B={x:0,y:0};const D=re=>{var ae,$;B={x:Math.abs(Math.round(re.pageX)-(((ae=_.current)==null?void 0:ae.x)??0)),y:Math.abs(Math.round(re.pageY)-((($=_.current)==null?void 0:$.y)??0))}},X=re=>{B.x<=10&&B.y<=10?re.preventDefault():S.contains(re.target)||R(!1),document.removeEventListener("pointermove",D),_.current=null};return _.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",X,{capture:!0})}}},[S,R,_]),h.useEffect(()=>{const B=()=>R(!1);return window.addEventListener("blur",B),window.addEventListener("resize",B),()=>{window.removeEventListener("blur",B),window.removeEventListener("resize",B)}},[R]);const[G,J]=Om(B=>{const D=K().filter(ae=>!ae.disabled),X=D.find(ae=>ae.ref.current===document.activeElement),re=Dm(D,B,X);re&&setTimeout(()=>re.ref.current.focus())}),P=h.useCallback((B,D,X)=>{const re=!W.current&&!X;(w.value!==void 0&&w.value===D||re)&&(O(B),re&&(W.current=!0))},[w.value]),M=h.useCallback(()=>S==null?void 0:S.focus(),[S]),q=h.useCallback((B,D,X)=>{const re=!W.current&&!X;(w.value!==void 0&&w.value===D||re)&&U(B)},[w.value]),Y=r==="popper"?jl:wm,se=Y===jl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:p,collisionBoundary:m,collisionPadding:f,sticky:v,hideWhenDetached:g,avoidCollisions:x}:{};return u.jsx(xm,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:P,selectedItem:j,onItemLeave:M,itemTextRefCallback:q,focusSelectedItem:F,selectedItemText:L,position:r,isPositioned:V,searchRef:G,children:u.jsx(fs,{as:Nk,allowPinchZoom:!0,children:u.jsx(qo,{asChild:!0,trapped:w.open,onMountAutoFocus:B=>{B.preventDefault()},onUnmountAutoFocus:ie(o,B=>{var D;(D=w.trigger)==null||D.focus({preventScroll:!0}),B.preventDefault()}),children:u.jsx(gr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:B=>B.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:B=>B.preventDefault(),...y,...se,onPlaced:()=>N(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...y.style},onKeyDown:ie(y.onKeyDown,B=>{const D=B.ctrlKey||B.altKey||B.metaKey;if(B.key==="Tab"&&B.preventDefault(),!D&&B.key.length===1&&J(B.key),["ArrowUp","ArrowDown","Home","End"].includes(B.key)){let re=K().filter(ae=>!ae.disabled).map(ae=>ae.ref.current);if(["ArrowUp","End"].includes(B.key)&&(re=re.slice().reverse()),["ArrowUp","ArrowDown"].includes(B.key)){const ae=B.target,$=re.indexOf(ae);re=re.slice($+1)}setTimeout(()=>I(re)),B.preventDefault()}})})})})})})});vm.displayName=Ik;var Ak="SelectItemAlignedPosition",wm=h.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Un(ar,n),i=Wn(ar,n),[a,l]=h.useState(null),[c,d]=h.useState(null),p=Oe(t,E=>d(E)),m=Qs(n),f=h.useRef(!1),v=h.useRef(!0),{viewport:g,selectedItem:x,selectedItemText:y,focusSelectedItem:w}=i,S=h.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&x&&y){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),O=s.valueNode.getBoundingClientRect(),L=y.getBoundingClientRect();if(s.dir!=="rtl"){const ae=L.left-j.left,$=O.left-ae,Z=E.left-$,de=E.width+Z,ce=Math.max(de,j.width),xe=window.innerWidth-dn,_e=Sl($,[dn,Math.max(dn,xe-ce)]);a.style.minWidth=de+"px",a.style.left=_e+"px"}else{const ae=j.right-L.right,$=window.innerWidth-O.right-ae,Z=window.innerWidth-E.right-$,de=E.width+Z,ce=Math.max(de,j.width),xe=window.innerWidth-dn,_e=Sl($,[dn,Math.max(dn,xe-ce)]);a.style.minWidth=de+"px",a.style.right=_e+"px"}const U=m(),K=window.innerHeight-dn*2,V=g.scrollHeight,N=window.getComputedStyle(c),W=parseInt(N.borderTopWidth,10),I=parseInt(N.paddingTop,10),F=parseInt(N.borderBottomWidth,10),R=parseInt(N.paddingBottom,10),_=W+I+V+R+F,G=Math.min(x.offsetHeight*5,_),J=window.getComputedStyle(g),P=parseInt(J.paddingTop,10),M=parseInt(J.paddingBottom,10),q=E.top+E.height/2-dn,Y=K-q,se=x.offsetHeight/2,B=x.offsetTop+se,D=W+I+B,X=_-D;if(D<=q){const ae=U.length>0&&x===U[U.length-1].ref.current;a.style.bottom="0px";const $=c.clientHeight-g.offsetTop-g.offsetHeight,Z=Math.max(Y,se+(ae?M:0)+$+F),de=D+Z;a.style.height=de+"px"}else{const ae=U.length>0&&x===U[0].ref.current;a.style.top="0px";const Z=Math.max(q,W+g.offsetTop+(ae?P:0)+se)+X;a.style.height=Z+"px",g.scrollTop=D-q+g.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=G+"px",a.style.maxHeight=K+"px",r==null||r(),requestAnimationFrame(()=>f.current=!0)}},[m,s.trigger,s.valueNode,a,c,g,x,y,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=h.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=h.useCallback(E=>{E&&v.current===!0&&(S(),w==null||w(),v.current=!1)},[S,w]);return u.jsx(_k,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:f,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(ve.div,{...o,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});wm.displayName=Ak;var jk="SelectPopperPosition",jl=h.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=ei(n);return u.jsx(na,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});jl.displayName=jk;var[_k,_l]=Rr(ar,{}),Pl="SelectViewport",bm=h.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Wn(Pl,n),i=_l(Pl,n),a=Oe(t,s.onViewportChange),l=h.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Zs.Slot,{scope:n,children:u.jsx(ve.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ie(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:m}=i;if(m!=null&&m.current&&p){const f=Math.abs(l.current-d.scrollTop);if(f>0){const v=window.innerHeight-dn*2,g=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),y=Math.max(g,x);if(y<v){const w=y+f,S=Math.min(v,w),k=w-S;p.style.height=S+"px",p.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,p.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});bm.displayName=Pl;var ym="SelectGroup",[Pk,Rk]=Rr(ym),Mk=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=It();return u.jsx(Pk,{scope:n,id:o,children:u.jsx(ve.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Mk.displayName=ym;var Sm="SelectLabel",Cm=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Rk(Sm,n);return u.jsx(ve.div,{id:o.id,...r,ref:t})});Cm.displayName=Sm;var ti="SelectItem",[Ok,Tm]=Rr(ti),km=h.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Un(ti,n),l=Wn(ti,n),c=a.value===r,[d,p]=h.useState(s??""),[m,f]=h.useState(!1),v=Oe(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),g=It(),x=h.useRef("touch"),y=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(Ok,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:h.useCallback(w=>{p(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(Zs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(ve.div,{role:"option","aria-labelledby":g,"data-highlighted":m?"":void 0,"aria-selected":c&&m,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:ie(i.onFocus,()=>f(!0)),onBlur:ie(i.onBlur,()=>f(!1)),onClick:ie(i.onClick,()=>{x.current!=="mouse"&&y()}),onPointerUp:ie(i.onPointerUp,()=>{x.current==="mouse"&&y()}),onPointerDown:ie(i.onPointerDown,w=>{x.current=w.pointerType}),onPointerMove:ie(i.onPointerMove,w=>{var S;x.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):x.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ie(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ie(i.onKeyDown,w=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&w.key===" "||(bk.includes(w.key)&&y(),w.key===" "&&w.preventDefault())})})})})});km.displayName=ti;var ko="SelectItemText",Em=h.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Un(ko,n),a=Wn(ko,n),l=Tm(ko,n),c=Tk(ko,n),[d,p]=h.useState(null),m=Oe(t,y=>p(y),l.onItemTextChange,y=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,y,l.value,l.disabled)}),f=d==null?void 0:d.textContent,v=h.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:f},l.value),[l.disabled,l.value,f]),{onNativeOptionAdd:g,onNativeOptionRemove:x}=c;return Tt(()=>(g(v),()=>x(v)),[g,x,v]),u.jsxs(u.Fragment,{children:[u.jsx(ve.span,{id:l.textId,...s,ref:m}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Lr.createPortal(s.children,i.valueNode):null]})});Em.displayName=ko;var Im="SelectItemIndicator",Nm=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Tm(Im,n).isSelected?u.jsx(ve.span,{"aria-hidden":!0,...r,ref:t}):null});Nm.displayName=Im;var Rl="SelectScrollUpButton",Am=h.forwardRef((e,t)=>{const n=Wn(Rl,e.__scopeSelect),r=_l(Rl,e.__scopeSelect),[o,s]=h.useState(!1),i=Oe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(_m,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Am.displayName=Rl;var Ml="SelectScrollDownButton",jm=h.forwardRef((e,t)=>{const n=Wn(Ml,e.__scopeSelect),r=_l(Ml,e.__scopeSelect),[o,s]=h.useState(!1),i=Oe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(_m,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});jm.displayName=Ml;var _m=h.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Wn("SelectScrollButton",n),i=h.useRef(null),a=Qs(n),l=h.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return h.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(p=>p.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(ve.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ie(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ie(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ie(o.onPointerLeave,()=>{l()})})}),Dk="SelectSeparator",Pm=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(ve.div,{"aria-hidden":!0,...r,ref:t})});Pm.displayName=Dk;var Ol="SelectArrow",Lk=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ei(n),s=Un(Ol,n),i=Wn(Ol,n);return s.open&&i.position==="popper"?u.jsx(ra,{...o,...r,ref:t}):null});Lk.displayName=Ol;var $k="SelectBubbleInput",Rm=h.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=h.useRef(null),s=Oe(r,o),i=am(t);return h.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const p=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(p)}},[i,t]),u.jsx(ve.select,{...n,style:{...lm,...n.style},ref:s,defaultValue:t})});Rm.displayName=$k;function Mm(e){return e===""||e===void 0}function Om(e){const t=ht(e),n=h.useRef(""),r=h.useRef(0),o=h.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=h.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return h.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Dm(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Fk(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Fk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Bk=cm,Lm=dm,zk=pm,Hk=hm,Uk=mm,$m=gm,Wk=bm,Fm=Cm,Bm=km,Vk=Em,Kk=Nm,zm=Am,Hm=jm,Um=Pm;const qk=Bk,Gk=zk,Wm=h.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Lm,{ref:r,className:te("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(Hk,{asChild:!0,children:u.jsx(ue.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wm.displayName=Lm.displayName;const Vm=h.forwardRef(({className:e,...t},n)=>u.jsx(zm,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ue.ChevronUp,{className:"h-4 w-4"})}));Vm.displayName=zm.displayName;const Km=h.forwardRef(({className:e,...t},n)=>u.jsx(Hm,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ue.ChevronDown,{className:"h-4 w-4"})}));Km.displayName=Hm.displayName;const qm=h.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Uk,{children:u.jsxs($m,{ref:o,className:te("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Vm,{}),u.jsx(Wk,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Km,{})]})}));qm.displayName=$m.displayName;const Yk=h.forwardRef(({className:e,...t},n)=>u.jsx(Fm,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Yk.displayName=Fm.displayName;const Gm=h.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Bm,{ref:r,className:te("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Kk,{children:u.jsx(ue.Check,{className:"h-4 w-4"})})}),u.jsx(Vk,{children:t})]}));Gm.displayName=Bm.displayName;const Xk=h.forwardRef(({className:e,...t},n)=>u.jsx(Um,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));Xk.displayName=Um.displayName;var Jk="Separator",Ym="horizontal",Zk=["horizontal","vertical"],Xm=h.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ym,...o}=e,s=Qk(r)?r:Ym,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(ve.div,{"data-orientation":s,...a,...o,ref:t})});Xm.displayName=Jk;function Qk(e){return Zk.includes(e)}var Jm=Xm;const Zm=h.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Jm,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Zm.displayName=Jm.displayName;var ni="Switch",[eE,u1]=on(ni),[tE,nE]=eE(ni),Qm=h.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...p}=e,[m,f]=h.useState(null),v=Oe(t,S=>f(S)),g=h.useRef(!1),x=m?d||!!m.closest("form"):!0,[y,w]=_n({prop:o,defaultProp:s??!1,onChange:c,caller:ni});return u.jsxs(tE,{scope:n,checked:y,disabled:a,children:[u.jsx(ve.button,{type:"button",role:"switch","aria-checked":y,"aria-required":i,"data-state":rg(y),"data-disabled":a?"":void 0,disabled:a,value:l,...p,ref:v,onClick:ie(e.onClick,S=>{w(k=>!k),x&&(g.current=S.isPropagationStopped(),g.current||S.stopPropagation())})}),x&&u.jsx(ng,{control:m,bubbles:!g.current,name:r,value:l,checked:y,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Qm.displayName=ni;var eg="SwitchThumb",tg=h.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=nE(eg,n);return u.jsx(ve.span,{"data-state":rg(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});tg.displayName=eg;var rE="SwitchBubbleInput",ng=h.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=h.useRef(null),a=Oe(i,s),l=am(n),c=fd(t);return h.useEffect(()=>{const d=i.current;if(!d)return;const p=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(p,"checked").set;if(l!==n&&f){const v=new Event("click",{bubbles:r});f.call(d,n),d.dispatchEvent(v)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});ng.displayName=rE;function rg(e){return e?"checked":"unchecked"}var og=Qm,oE=tg;const sg=h.forwardRef(({className:e,...t},n)=>u.jsx(og,{className:te("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(oE,{className:te("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));sg.displayName=og.displayName;const sE=qa,iE=XC,aE=Ga,ig=h.forwardRef(({className:e,...t},n)=>u.jsx(wo,{className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));ig.displayName=wo.displayName;const lE=Dr.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),ag=h.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(aE,{children:[u.jsx(ig,{}),u.jsxs(bo,{ref:o,className:te(lE({side:e}),t),...r,children:[n,u.jsxs(Zp,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(ue.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ag.displayName=bo.displayName;const lg=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});lg.displayName="SheetHeader";const cg=h.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));cg.displayName=rr.displayName;const ug=h.forwardRef(({className:e,...t},n)=>u.jsx(Os,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));ug.displayName=Os.displayName;var[ri,d1]=on("Tooltip",[yr]),oi=yr(),dg="TooltipProvider",cE=700,Dl="tooltip.open",[uE,Ll]=ri(dg),fg=e=>{const{__scopeTooltip:t,delayDuration:n=cE,skipDelayDuration:r=300,disableHoverableContent:o=!1,children:s}=e,i=h.useRef(!0),a=h.useRef(!1),l=h.useRef(0);return h.useEffect(()=>{const c=l.current;return()=>window.clearTimeout(c)},[]),u.jsx(uE,{scope:t,isOpenDelayedRef:i,delayDuration:n,onOpen:h.useCallback(()=>{window.clearTimeout(l.current),i.current=!1},[]),onClose:h.useCallback(()=>{window.clearTimeout(l.current),l.current=window.setTimeout(()=>i.current=!0,r)},[r]),isPointerInTransitRef:a,onPointerInTransitChange:h.useCallback(c=>{a.current=c},[]),disableHoverableContent:o,children:s})};fg.displayName=dg;var Eo="Tooltip",[dE,si]=ri(Eo),pg=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:o,onOpenChange:s,disableHoverableContent:i,delayDuration:a}=e,l=Ll(Eo,e.__scopeTooltip),c=oi(t),[d,p]=h.useState(null),m=It(),f=h.useRef(0),v=i??l.disableHoverableContent,g=a??l.delayDuration,x=h.useRef(!1),[y,w]=_n({prop:r,defaultProp:o??!1,onChange:E=>{E?(l.onOpen(),document.dispatchEvent(new CustomEvent(Dl))):l.onClose(),s==null||s(E)},caller:Eo}),S=h.useMemo(()=>y?x.current?"delayed-open":"instant-open":"closed",[y]),k=h.useCallback(()=>{window.clearTimeout(f.current),f.current=0,x.current=!1,w(!0)},[w]),C=h.useCallback(()=>{window.clearTimeout(f.current),f.current=0,w(!1)},[w]),T=h.useCallback(()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>{x.current=!0,w(!0),f.current=0},g)},[g,w]);return h.useEffect(()=>()=>{f.current&&(window.clearTimeout(f.current),f.current=0)},[]),u.jsx(ea,{...c,children:u.jsx(dE,{scope:t,contentId:m,open:y,stateAttribute:S,trigger:d,onTriggerChange:p,onTriggerEnter:h.useCallback(()=>{l.isOpenDelayedRef.current?T():k()},[l.isOpenDelayedRef,T,k]),onTriggerLeave:h.useCallback(()=>{v?C():(window.clearTimeout(f.current),f.current=0)},[C,v]),onOpen:k,onClose:C,disableHoverableContent:v,children:n})})};pg.displayName=Eo;var $l="TooltipTrigger",hg=h.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,o=si($l,n),s=Ll($l,n),i=oi(n),a=h.useRef(null),l=Oe(t,a,o.onTriggerChange),c=h.useRef(!1),d=h.useRef(!1),p=h.useCallback(()=>c.current=!1,[]);return h.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),u.jsx(ta,{asChild:!0,...i,children:u.jsx(ve.button,{"aria-describedby":o.open?o.contentId:void 0,"data-state":o.stateAttribute,...r,ref:l,onPointerMove:ie(e.onPointerMove,m=>{m.pointerType!=="touch"&&!d.current&&!s.isPointerInTransitRef.current&&(o.onTriggerEnter(),d.current=!0)}),onPointerLeave:ie(e.onPointerLeave,()=>{o.onTriggerLeave(),d.current=!1}),onPointerDown:ie(e.onPointerDown,()=>{o.open&&o.onClose(),c.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:ie(e.onFocus,()=>{c.current||o.onOpen()}),onBlur:ie(e.onBlur,o.onClose),onClick:ie(e.onClick,o.onClose)})})});hg.displayName=$l;var fE="TooltipPortal",[f1,pE]=ri(fE,{forceMount:void 0}),Mr="TooltipContent",mg=h.forwardRef((e,t)=>{const n=pE(Mr,e.__scopeTooltip),{forceMount:r=n.forceMount,side:o="top",...s}=e,i=si(Mr,e.__scopeTooltip);return u.jsx(Ft,{present:r||i.open,children:i.disableHoverableContent?u.jsx(gg,{side:o,...s,ref:t}):u.jsx(hE,{side:o,...s,ref:t})})}),hE=h.forwardRef((e,t)=>{const n=si(Mr,e.__scopeTooltip),r=Ll(Mr,e.__scopeTooltip),o=h.useRef(null),s=Oe(t,o),[i,a]=h.useState(null),{trigger:l,onClose:c}=n,d=o.current,{onPointerInTransitChange:p}=r,m=h.useCallback(()=>{a(null),p(!1)},[p]),f=h.useCallback((v,g)=>{const x=v.currentTarget,y={x:v.clientX,y:v.clientY},w=wE(y,x.getBoundingClientRect()),S=bE(y,w),k=yE(g.getBoundingClientRect()),C=CE([...S,...k]);a(C),p(!0)},[p]);return h.useEffect(()=>()=>m(),[m]),h.useEffect(()=>{if(l&&d){const v=x=>f(x,d),g=x=>f(x,l);return l.addEventListener("pointerleave",v),d.addEventListener("pointerleave",g),()=>{l.removeEventListener("pointerleave",v),d.removeEventListener("pointerleave",g)}}},[l,d,f,m]),h.useEffect(()=>{if(i){const v=g=>{const x=g.target,y={x:g.clientX,y:g.clientY},w=(l==null?void 0:l.contains(x))||(d==null?void 0:d.contains(x)),S=!SE(y,i);w?m():S&&(m(),c())};return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[l,d,i,c,m]),u.jsx(gg,{...e,ref:s})}),[mE,gE]=ri(Eo,{isInside:!1}),xE=Vt.createSlottable("TooltipContent"),gg=h.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":o,onEscapeKeyDown:s,onPointerDownOutside:i,...a}=e,l=si(Mr,n),c=oi(n),{onClose:d}=l;return h.useEffect(()=>(document.addEventListener(Dl,d),()=>document.removeEventListener(Dl,d)),[d]),h.useEffect(()=>{if(l.trigger){const p=m=>{const f=m.target;f!=null&&f.contains(l.trigger)&&d()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[l.trigger,d]),u.jsx(gr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:p=>p.preventDefault(),onDismiss:d,children:u.jsxs(na,{"data-state":l.stateAttribute,...c,...a,ref:t,style:{...a.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[u.jsx(xE,{children:r}),u.jsx(mE,{scope:n,isInside:!0,children:u.jsx(vk,{id:l.contentId,role:"tooltip",children:o||r})})]})})});mg.displayName=Mr;var xg="TooltipArrow",vE=h.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,o=oi(n);return gE(xg,n).isInside?null:u.jsx(ra,{...o,...r,ref:t})});vE.displayName=xg;function wE(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),o=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,o,s)){case s:return"left";case o:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function bE(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function yE(e){const{top:t,right:n,bottom:r,left:o}=e;return[{x:o,y:t},{x:n,y:t},{x:n,y:r},{x:o,y:r}]}function SE(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,p=l.x,m=l.y;d>r!=m>r&&n<(p-c)*(r-d)/(m-d)+c&&(o=!o)}return o}function CE(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),TE(t)}function TE(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const o=e[r];for(;t.length>=2;){const s=t[t.length-1],i=t[t.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))t.pop();else break}t.push(o)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const o=e[r];for(;n.length>=2;){const s=n[n.length-1],i=n[n.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))n.pop();else break}n.push(o)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var kE=fg,EE=pg,IE=hg,vg=mg;const NE=kE,AE=EE,jE=IE,wg=h.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(vg,{ref:r,sideOffset:t,className:te("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n}));wg.displayName=vg.displayName;var Fl="ToastProvider",[Bl,_E,PE]=Vo("Toast"),[bg,p1]=on("Toast",[PE]),[RE,ii]=bg(Fl),yg=e=>{const{__scopeToast:t,label:n="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,l]=h.useState(null),[c,d]=h.useState(0),p=h.useRef(!1),m=h.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${Fl}\`. Expected non-empty \`string\`.`),u.jsx(Bl.Provider,{scope:t,children:u.jsx(RE,{scope:t,label:n,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:h.useCallback(()=>d(f=>f+1),[]),onToastRemove:h.useCallback(()=>d(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:p,isClosePausedRef:m,children:i})})};yg.displayName=Fl;var Sg="ToastViewport",ME=["F8"],zl="toast.viewportPause",Hl="toast.viewportResume",Cg=h.forwardRef((e,t)=>{const{__scopeToast:n,hotkey:r=ME,label:o="Notifications ({hotkey})",...s}=e,i=ii(Sg,n),a=_E(n),l=h.useRef(null),c=h.useRef(null),d=h.useRef(null),p=h.useRef(null),m=Oe(t,p,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=i.toastCount>0;h.useEffect(()=>{const x=y=>{var S;r.length!==0&&r.every(k=>y[k]||y.code===k)&&((S=p.current)==null||S.focus())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[r]),h.useEffect(()=>{const x=l.current,y=p.current;if(v&&x&&y){const w=()=>{if(!i.isClosePausedRef.current){const T=new CustomEvent(zl);y.dispatchEvent(T),i.isClosePausedRef.current=!0}},S=()=>{if(i.isClosePausedRef.current){const T=new CustomEvent(Hl);y.dispatchEvent(T),i.isClosePausedRef.current=!1}},k=T=>{!x.contains(T.relatedTarget)&&S()},C=()=>{x.contains(document.activeElement)||S()};return x.addEventListener("focusin",w),x.addEventListener("focusout",k),x.addEventListener("pointermove",w),x.addEventListener("pointerleave",C),window.addEventListener("blur",w),window.addEventListener("focus",S),()=>{x.removeEventListener("focusin",w),x.removeEventListener("focusout",k),x.removeEventListener("pointermove",w),x.removeEventListener("pointerleave",C),window.removeEventListener("blur",w),window.removeEventListener("focus",S)}}},[v,i.isClosePausedRef]);const g=h.useCallback(({tabbingDirection:x})=>{const w=a().map(S=>{const k=S.ref.current,C=[k,...qE(k)];return x==="forwards"?C:C.reverse()});return(x==="forwards"?w.reverse():w).flat()},[a]);return h.useEffect(()=>{const x=p.current;if(x){const y=w=>{var C,T,E;const S=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!S){const j=document.activeElement,O=w.shiftKey;if(w.target===x&&O){(C=c.current)==null||C.focus();return}const K=g({tabbingDirection:O?"backwards":"forwards"}),V=K.findIndex(N=>N===j);Vl(K.slice(V+1))?w.preventDefault():O?(T=c.current)==null||T.focus():(E=d.current)==null||E.focus()}};return x.addEventListener("keydown",y),()=>x.removeEventListener("keydown",y)}},[a,g]),u.jsxs(Tw,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:v?void 0:"none"},children:[v&&u.jsx(Ul,{ref:c,onFocusFromOutsideViewport:()=>{const x=g({tabbingDirection:"forwards"});Vl(x)}}),u.jsx(Bl.Slot,{scope:n,children:u.jsx(ve.ol,{tabIndex:-1,...s,ref:m})}),v&&u.jsx(Ul,{ref:d,onFocusFromOutsideViewport:()=>{const x=g({tabbingDirection:"backwards"});Vl(x)}})]})});Cg.displayName=Sg;var Tg="ToastFocusProxy",Ul=h.forwardRef((e,t)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=e,s=ii(Tg,n);return u.jsx(Js,{tabIndex:0,...o,ref:t,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=s.viewport)!=null&&c.contains(a))&&r()}})});Ul.displayName=Tg;var Io="Toast",OE="toast.swipeStart",DE="toast.swipeMove",LE="toast.swipeCancel",$E="toast.swipeEnd",kg=h.forwardRef((e,t)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a,l]=_n({prop:r,defaultProp:o??!0,onChange:s,caller:Io});return u.jsx(Ft,{present:n||a,children:u.jsx(zE,{open:a,...i,ref:t,onClose:()=>l(!1),onPause:ht(e.onPause),onResume:ht(e.onResume),onSwipeStart:ie(e.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:ie(e.onSwipeMove,c=>{const{x:d,y:p}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${p}px`)}),onSwipeCancel:ie(e.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:ie(e.onSwipeEnd,c=>{const{x:d,y:p}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${p}px`),l(!1)})})})});kg.displayName=Io;var[FE,BE]=bg(Io,{onClose(){}}),zE=h.forwardRef((e,t)=>{const{__scopeToast:n,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:d,onSwipeMove:p,onSwipeCancel:m,onSwipeEnd:f,...v}=e,g=ii(Io,n),[x,y]=h.useState(null),w=Oe(t,N=>y(N)),S=h.useRef(null),k=h.useRef(null),C=o||g.duration,T=h.useRef(0),E=h.useRef(C),j=h.useRef(0),{onToastAdd:O,onToastRemove:L}=g,U=ht(()=>{var W;(x==null?void 0:x.contains(document.activeElement))&&((W=g.viewport)==null||W.focus()),i()}),K=h.useCallback(N=>{!N||N===1/0||(window.clearTimeout(j.current),T.current=new Date().getTime(),j.current=window.setTimeout(U,N))},[U]);h.useEffect(()=>{const N=g.viewport;if(N){const W=()=>{K(E.current),c==null||c()},I=()=>{const F=new Date().getTime()-T.current;E.current=E.current-F,window.clearTimeout(j.current),l==null||l()};return N.addEventListener(zl,I),N.addEventListener(Hl,W),()=>{N.removeEventListener(zl,I),N.removeEventListener(Hl,W)}}},[g.viewport,C,l,c,K]),h.useEffect(()=>{s&&!g.isClosePausedRef.current&&K(C)},[s,C,g.isClosePausedRef,K]),h.useEffect(()=>(O(),()=>L()),[O,L]);const V=h.useMemo(()=>x?Pg(x):null,[x]);return g.viewport?u.jsxs(u.Fragment,{children:[V&&u.jsx(HE,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite",children:V}),u.jsx(FE,{scope:n,onClose:U,children:Lr.createPortal(u.jsx(Bl.ItemSlot,{scope:n,children:u.jsx(Cw,{asChild:!0,onEscapeKeyDown:ie(a,()=>{g.isFocusedToastEscapeKeyDownRef.current||U(),g.isFocusedToastEscapeKeyDownRef.current=!1}),children:u.jsx(ve.li,{tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":g.swipeDirection,...v,ref:w,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:ie(e.onKeyDown,N=>{N.key==="Escape"&&(a==null||a(N.nativeEvent),N.nativeEvent.defaultPrevented||(g.isFocusedToastEscapeKeyDownRef.current=!0,U()))}),onPointerDown:ie(e.onPointerDown,N=>{N.button===0&&(S.current={x:N.clientX,y:N.clientY})}),onPointerMove:ie(e.onPointerMove,N=>{if(!S.current)return;const W=N.clientX-S.current.x,I=N.clientY-S.current.y,F=!!k.current,R=["left","right"].includes(g.swipeDirection),_=["left","up"].includes(g.swipeDirection)?Math.min:Math.max,G=R?_(0,W):0,J=R?0:_(0,I),P=N.pointerType==="touch"?10:2,M={x:G,y:J},q={originalEvent:N,delta:M};F?(k.current=M,ai(DE,p,q,{discrete:!1})):Rg(M,g.swipeDirection,P)?(k.current=M,ai(OE,d,q,{discrete:!1}),N.target.setPointerCapture(N.pointerId)):(Math.abs(W)>P||Math.abs(I)>P)&&(S.current=null)}),onPointerUp:ie(e.onPointerUp,N=>{const W=k.current,I=N.target;if(I.hasPointerCapture(N.pointerId)&&I.releasePointerCapture(N.pointerId),k.current=null,S.current=null,W){const F=N.currentTarget,R={originalEvent:N,delta:W};Rg(W,g.swipeDirection,g.swipeThreshold)?ai($E,f,R,{discrete:!0}):ai(LE,m,R,{discrete:!0}),F.addEventListener("click",_=>_.preventDefault(),{once:!0})}})})})}),g.viewport)})]}):null}),HE=e=>{const{__scopeToast:t,children:n,...r}=e,o=ii(Io,t),[s,i]=h.useState(!1),[a,l]=h.useState(!1);return VE(()=>i(!0)),h.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:u.jsx(eo,{asChild:!0,children:u.jsx(Js,{...r,children:s&&u.jsxs(u.Fragment,{children:[o.label," ",n]})})})},UE="ToastTitle",Eg=h.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return u.jsx(ve.div,{...r,ref:t})});Eg.displayName=UE;var WE="ToastDescription",Ig=h.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return u.jsx(ve.div,{...r,ref:t})});Ig.displayName=WE;var Ng="ToastAction",Ag=h.forwardRef((e,t)=>{const{altText:n,...r}=e;return n.trim()?u.jsx(_g,{altText:n,asChild:!0,children:u.jsx(Wl,{...r,ref:t})}):(console.error(`Invalid prop \`altText\` supplied to \`${Ng}\`. Expected non-empty \`string\`.`),null)});Ag.displayName=Ng;var jg="ToastClose",Wl=h.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e,o=BE(jg,n);return u.jsx(_g,{asChild:!0,children:u.jsx(ve.button,{type:"button",...r,ref:t,onClick:ie(e.onClick,o.onClose)})})});Wl.displayName=jg;var _g=h.forwardRef((e,t)=>{const{__scopeToast:n,altText:r,...o}=e;return u.jsx(ve.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...o,ref:t})});function Pg(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),KE(r)){const o=r.ariaHidden||r.hidden||r.style.display==="none",s=r.dataset.radixToastAnnounceExclude==="";if(!o)if(s){const i=r.dataset.radixToastAnnounceAlt;i&&t.push(i)}else t.push(...Pg(r))}}),t}function ai(e,t,n,{discrete:r}){const o=n.originalEvent.currentTarget,s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Oi(o,s):o.dispatchEvent(s)}var Rg=(e,t,n=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),s=r>o;return t==="left"||t==="right"?s&&r>n:!s&&o>n};function VE(e=()=>{}){const t=ht(e);Tt(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[t])}function KE(e){return e.nodeType===e.ELEMENT_NODE}function qE(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 Vl(e){const t=document.activeElement;return e.some(n=>n===t?!0:(n.focus(),document.activeElement!==t))}var GE=yg,Mg=Cg,Og=kg,Dg=Eg,Lg=Ig,$g=Ag,Fg=Wl;const YE=GE,Bg=h.forwardRef(({className:e,...t},n)=>u.jsx(Mg,{ref:n,className:te("fixed bottom-0 right-0 z-[100] flex max-h-screen w-full flex-col p-4 md:max-w-[420px]",e),...t}));Bg.displayName=Mg.displayName;const XE=Dr.cva("group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",{variants:{variant:{default:"border bg-background text-foreground",destructive:"destructive group border-destructive bg-destructive text-destructive-foreground"}},defaultVariants:{variant:"default"}}),zg=h.forwardRef(({className:e,variant:t,...n},r)=>u.jsx(Og,{ref:r,className:te(XE({variant:t}),e),...n}));zg.displayName=Og.displayName;const JE=h.forwardRef(({className:e,...t},n)=>u.jsx($g,{ref:n,className:te("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",e),...t}));JE.displayName=$g.displayName;const Hg=h.forwardRef(({className:e,...t},n)=>u.jsx(Fg,{ref:n,className:te("absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",e),"toast-close":"",...t,children:u.jsx(ue.X,{className:"h-4 w-4"})}));Hg.displayName=Fg.displayName;const Ug=h.forwardRef(({className:e,...t},n)=>u.jsx(Dg,{ref:n,className:te("text-sm font-semibold",e),...t}));Ug.displayName=Dg.displayName;const Wg=h.forwardRef(({className:e,...t},n)=>u.jsx(Lg,{ref:n,className:te("text-sm opacity-90",e),...t}));Wg.displayName=Lg.displayName;function ZE(){const{toasts:e}=Za();return u.jsxs(YE,{children:[e.map(function({id:t,title:n,description:r,action:o,...s}){return u.jsxs(zg,{...s,children:[u.jsxs("div",{className:"grid gap-1",children:[n&&u.jsx(Ug,{children:n}),r&&u.jsx(Wg,{children:r})]}),o,u.jsx(Hg,{})]},t)}),u.jsx(Bg,{})]})}var QE=(e,t,n,r,o,s,i,a)=>{let l=document.documentElement,c=["light","dark"];function d(f){(Array.isArray(e)?e:[e]).forEach(v=>{let g=v==="class",x=g&&s?o.map(y=>s[y]||y):o;g?(l.classList.remove(...x),l.classList.add(s&&s[f]?s[f]:f)):l.setAttribute(v,f)}),p(f)}function p(f){a&&c.includes(f)&&(l.style.colorScheme=f)}function m(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(r)d(r);else try{let f=localStorage.getItem(t)||n,v=i&&f==="system"?m():f;d(v)}catch{}},eI=h.createContext(void 0),tI={setTheme:e=>{},themes:[]},nI=()=>{var e;return(e=h.useContext(eI))!=null?e:tI};h.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:o,defaultTheme:s,value:i,themes:a,nonce:l,scriptProps:c})=>{let d=JSON.stringify([n,t,s,e,a,i,r,o]).slice(1,-1);return h.createElement("script",{...c,suppressHydrationWarning:!0,nonce:typeof window>"u"?l:"",dangerouslySetInnerHTML:{__html:`(${QE.toString()})(${d})`}})});var rI=e=>{switch(e){case"success":return iI;case"info":return lI;case"warning":return aI;case"error":return cI;default:return null}},oI=Array(12).fill(0),sI=({visible:e,className:t})=>b.createElement("div",{className:["sonner-loading-wrapper",t].filter(Boolean).join(" "),"data-visible":e},b.createElement("div",{className:"sonner-spinner"},oI.map((n,r)=>b.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${r}`})))),iI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})),aI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",clipRule:"evenodd"})),lI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})),cI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})),uI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},b.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),b.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"})),dI=()=>{let[e,t]=b.useState(document.hidden);return b.useEffect(()=>{let n=()=>{t(document.hidden)};return document.addEventListener("visibilitychange",n),()=>window.removeEventListener("visibilitychange",n)},[]),e},Kl=1,fI=class{constructor(){this.subscribe=e=>(this.subscribers.push(e),()=>{let t=this.subscribers.indexOf(e);this.subscribers.splice(t,1)}),this.publish=e=>{this.subscribers.forEach(t=>t(e))},this.addToast=e=>{this.publish(e),this.toasts=[...this.toasts,e]},this.create=e=>{var t;let{message:n,...r}=e,o=typeof(e==null?void 0:e.id)=="number"||((t=e.id)==null?void 0:t.length)>0?e.id:Kl++,s=this.toasts.find(a=>a.id===o),i=e.dismissible===void 0?!0:e.dismissible;return this.dismissedToasts.has(o)&&this.dismissedToasts.delete(o),s?this.toasts=this.toasts.map(a=>a.id===o?(this.publish({...a,...e,id:o,title:n}),{...a,...e,id:o,dismissible:i,title:n}):a):this.addToast({title:n,...r,dismissible:i,id:o}),o},this.dismiss=e=>(this.dismissedToasts.add(e),e||this.toasts.forEach(t=>{this.subscribers.forEach(n=>n({id:t.id,dismiss:!0}))}),this.subscribers.forEach(t=>t({id:e,dismiss:!0})),e),this.message=(e,t)=>this.create({...t,message:e}),this.error=(e,t)=>this.create({...t,message:e,type:"error"}),this.success=(e,t)=>this.create({...t,type:"success",message:e}),this.info=(e,t)=>this.create({...t,type:"info",message:e}),this.warning=(e,t)=>this.create({...t,type:"warning",message:e}),this.loading=(e,t)=>this.create({...t,type:"loading",message:e}),this.promise=(e,t)=>{if(!t)return;let n;t.loading!==void 0&&(n=this.create({...t,promise:e,type:"loading",message:t.loading,description:typeof t.description!="function"?t.description:void 0}));let r=e instanceof Promise?e:e(),o=n!==void 0,s,i=r.then(async l=>{if(s=["resolve",l],b.isValidElement(l))o=!1,this.create({id:n,type:"default",message:l});else if(hI(l)&&!l.ok){o=!1;let c=typeof t.error=="function"?await t.error(`HTTP error! status: ${l.status}`):t.error,d=typeof t.description=="function"?await t.description(`HTTP error! status: ${l.status}`):t.description;this.create({id:n,type:"error",message:c,description:d})}else if(t.success!==void 0){o=!1;let c=typeof t.success=="function"?await t.success(l):t.success,d=typeof t.description=="function"?await t.description(l):t.description;this.create({id:n,type:"success",message:c,description:d})}}).catch(async l=>{if(s=["reject",l],t.error!==void 0){o=!1;let c=typeof t.error=="function"?await t.error(l):t.error,d=typeof t.description=="function"?await t.description(l):t.description;this.create({id:n,type:"error",message:c,description:d})}}).finally(()=>{var l;o&&(this.dismiss(n),n=void 0),(l=t.finally)==null||l.call(t)}),a=()=>new Promise((l,c)=>i.then(()=>s[0]==="reject"?c(s[1]):l(s[1])).catch(c));return typeof n!="string"&&typeof n!="number"?{unwrap:a}:Object.assign(n,{unwrap:a})},this.custom=(e,t)=>{let n=(t==null?void 0:t.id)||Kl++;return this.create({jsx:e(n),id:n,...t}),n},this.getActiveToasts=()=>this.toasts.filter(e=>!this.dismissedToasts.has(e.id)),this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},Ht=new fI,pI=(e,t)=>{let n=(t==null?void 0:t.id)||Kl++;return Ht.addToast({title:e,...t,id:n}),n},hI=e=>e&&typeof e=="object"&&"ok"in e&&typeof e.ok=="boolean"&&"status"in e&&typeof e.status=="number",mI=pI,gI=()=>Ht.toasts,xI=()=>Ht.getActiveToasts();Object.assign(mI,{success:Ht.success,info:Ht.info,warning:Ht.warning,error:Ht.error,custom:Ht.custom,message:Ht.message,promise:Ht.promise,dismiss:Ht.dismiss,loading:Ht.loading},{getHistory:gI,getToasts:xI});function vI(e,{insertAt:t}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",t==="top"&&n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}vI(`:where(html[dir="ltr"]),:where([data-sonner-toaster][dir="ltr"]){--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}:where(html[dir="rtl"]),:where([data-sonner-toaster][dir="rtl"]){--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}:where([data-sonner-toaster]){position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999;transition:transform .4s ease}:where([data-sonner-toaster][data-lifted="true"]){transform:translateY(-10px)}@media (hover: none) and (pointer: coarse){:where([data-sonner-toaster][data-lifted="true"]){transform:none}}:where([data-sonner-toaster][data-x-position="right"]){right:var(--offset-right)}:where([data-sonner-toaster][data-x-position="left"]){left:var(--offset-left)}:where([data-sonner-toaster][data-x-position="center"]){left:50%;transform:translate(-50%)}:where([data-sonner-toaster][data-y-position="top"]){top:var(--offset-top)}:where([data-sonner-toaster][data-y-position="bottom"]){bottom:var(--offset-bottom)}:where([data-sonner-toast]){--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}:where([data-sonner-toast][data-styled="true"]){padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}:where([data-sonner-toast]:focus-visible){box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast][data-y-position="top"]){top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}:where([data-sonner-toast][data-y-position="bottom"]){bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}:where([data-sonner-toast]) :where([data-description]){font-weight:400;line-height:1.4;color:inherit}:where([data-sonner-toast]) :where([data-title]){font-weight:500;line-height:1.5;color:inherit}:where([data-sonner-toast]) :where([data-icon]){display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}:where([data-sonner-toast][data-promise="true"]) :where([data-icon])>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}:where([data-sonner-toast]) :where([data-icon])>*{flex-shrink:0}:where([data-sonner-toast]) :where([data-icon]) svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}:where([data-sonner-toast]) :where([data-content]){display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}:where([data-sonner-toast]) :where([data-button]):focus-visible{box-shadow:0 0 0 2px #0006}:where([data-sonner-toast]) :where([data-button]):first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}:where([data-sonner-toast]) :where([data-cancel]){color:var(--normal-text);background:rgba(0,0,0,.08)}:where([data-sonner-toast][data-theme="dark"]) :where([data-cancel]){background:rgba(255,255,255,.3)}:where([data-sonner-toast]) :where([data-close-button]){position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-close-button]{background:var(--gray1)}:where([data-sonner-toast]) :where([data-close-button]):focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast]) :where([data-disabled="true"]){cursor:not-allowed}:where([data-sonner-toast]):hover :where([data-close-button]):hover{background:var(--gray2);border-color:var(--gray5)}:where([data-sonner-toast][data-swiping="true"]):before{content:"";position:absolute;left:-50%;right:-50%;height:100%;z-index:-1}:where([data-sonner-toast][data-y-position="top"][data-swiping="true"]):before{bottom:50%;transform:scaleY(3) translateY(50%)}:where([data-sonner-toast][data-y-position="bottom"][data-swiping="true"]):before{top:50%;transform:scaleY(3) translateY(-50%)}:where([data-sonner-toast][data-swiping="false"][data-removed="true"]):before{content:"";position:absolute;inset:0;transform:scaleY(2)}:where([data-sonner-toast]):after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}:where([data-sonner-toast][data-mounted="true"]){--y: translateY(0);opacity:1}:where([data-sonner-toast][data-expanded="false"][data-front="false"]){--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}:where([data-sonner-toast])>*{transition:opacity .4s}:where([data-sonner-toast][data-expanded="false"][data-front="false"][data-styled="true"])>*{opacity:0}:where([data-sonner-toast][data-visible="false"]){opacity:0;pointer-events:none}:where([data-sonner-toast][data-mounted="true"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}:where([data-sonner-toast][data-removed="true"][data-front="true"][data-swipe-out="false"]){--y: translateY(calc(var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="false"]){--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}:where([data-sonner-toast][data-removed="true"][data-front="false"]):before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y, 0px)) translate(var(--swipe-amount-x, 0px));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 91%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 91%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-bg-hover: hsl(0, 0%, 12%);--normal-border: hsl(0, 0%, 20%);--normal-border-hover: hsl(0, 0%, 25%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 100%, 12%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 12%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success],[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info],[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning],[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error],[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}
129
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[v[W]?u.jsx(ue.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[F,v[W]?" (processing)":""]})]},W)}if(N.type==="interrupt"){const I=N,F=Wo((I==null?void 0:I.id)??(I==null?void 0:I.interrupt_id)),R=!!(j&&F&&F===j),_=R?O??(I==null?void 0:I.value):I==null?void 0:I.value,G=F?{...I,id:F,interrupt_id:F}:I;return u.jsx(wh,{interruptPart:G,onApprove:g,onReject:x,disabled:y,isActive:R,payload:_},W)}return null},[f,v,g,x,w,S,k,C,E,j,O,y]),V=a.trim().length>0||l.length>0||c.length>0||d.length>0;if(!t&&c.length>0&&!p)return U();if(!t&&!V&&!p)return null;if(t)return!n&&r?null:n?u.jsx(yh,{message:e,viewMode:o,isStreaming:s},e.id):null;if(!m){const N=u.jsx("div",{className:"space-y-2",children:i.map((W,I)=>u.jsx(K,{part:W,i:I},I))});return p?u.jsxs("div",{"aria-busy":"true",role:"status",children:[N,u.jsx(Sh,{className:L})]}):N}return null}function kh(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Za(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),p=b.useCallback(f=>{a(f),c(!0)},[]),m=b.useCallback(async(f,v,g)=>{var x,y;if(!t){f.preventDefault();return}if(o[g]){f.preventDefault();return}try{const w=String(v.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){f.preventDefault();const k=S[1],C=v.name||`file_${k}`,T=v.mimeType||"application/octet-stream";p({id:k,name:C,mimeType:T});return}if(w.startsWith("data:")){f.preventDefault(),s(C=>({...C,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await Zc(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(v.name??""))?!1:typeof v.size=="number"&&typeof E.size=="number"?E.size===v.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${v.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");p({id:T.id,name:v.name||T.filename||`file_${T.id}`,mimeType:v.mimeType||T.mime_type||"application/octet-stream"}),(x=k.update)==null||x.call(k,{id:k.id,title:"Success",description:`Opened ${v.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(y=k.update)==null||y.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[g]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[g]:!1}))}},[t,o,r,n,p]);return{uploadingFiles:o,handleFileClick:m,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function Eh(e,t){return b.useMemo(()=>{if(t)return{contentParts:[],textContent:"",toolMeta:{},imageParts:[],fileParts:[],interruptParts:[],toolRaw:"",isToolStreaming:!1};const n=e,r=Array.isArray(n.content)?n.content:[],o=n.additionalKwargs??{};return{contentParts:r,textContent:Lv(r),toolMeta:Ai(n),imageParts:r.filter(s=>s.type==="image_url"),fileParts:r.filter(s=>s.type==="file"),interruptParts:r.filter(s=>s.type==="interrupt"),toolRaw:$v(r),isToolStreaming:!!o.toolStreaming}},[e,t])}const Vs=b.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:p=!0,showArtifactPreviews:m=!0,customStyles:f={},onEdit:v,onRegenerate:g,onCopy:x,activeInterrupt:y,disableInterruptActions:w=!1,onInterruptActionStart:S,onInterruptActionEnd:k,attemptCount:C=1,attemptIndex:T=0,onSelectCheckpoint:E}){const[j,O]=b.useState(!1),[L,U]=b.useState("preview"),[K,V]=b.useState(!1),{currentThreadId:N}=pr(),{respondToInterrupt:W}=Yr(),I=l==="phone"||l==="half-screen",F=t.role,R=F==="tool",_=b.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),G=!!_,J=!(r&&F!=="user"),{uploadingFiles:P,handleFileClick:M,fileViewerOpen:q,currentFileInfo:Y,closeFileViewer:se}=kh({allowFileOpen:J,currentThreadId:N}),B=b.useMemo(()=>{switch(F){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[F]),D=Eh(t,_),{contentParts:X,imageParts:re,fileParts:ae,interruptParts:$,textContent:Z,toolMeta:de,toolRaw:ce,isToolStreaming:xe}=D,_e=(y==null?void 0:y.id)??(y==null?void 0:y.interrupt_id),Ve=Wo(_e),He=y==null?void 0:y.value,Ee=b.useMemo(()=>_||!m?null:t.artifact||null,[_,t,m]),Fe=b.useCallback(async()=>{const ye=R?ce:Z;async function tt(rt){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(rt);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const _t=new Blob([rt],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":_t})]);return}throw new Error("Clipboard API not supported in this context.")}try{await tt(ye),O(!0),setTimeout(()=>O(!1),2e3),x==null||x(ye)}catch(rt){console.error("Failed to copy:",rt)}},[R,ce,Z,x]),Ke=b.useCallback(()=>{if(!v||!t.id)return;const ye=(R?ce:Z)??"",tt="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};v(t.id,ye,tt)},[v,t.id,R,ce,Z,t]),Ue=b.useCallback(()=>{g==null||g(n)},[g,n]),Ye=b.useCallback(()=>{const tt=te(I?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",B);switch(F){case"user":return u.jsx(ue.User,{className:tt});case"assistant":return u.jsx(ue.Bot,{className:tt});case"tool":return u.jsx(ue.Wrench,{className:tt});default:return u.jsx(ue.Bot,{className:tt})}},[I,B,F]),nt=b.useCallback(()=>{const ye="group relative mb-4 flex w-full";switch(F){case"user":return te(ye,"justify-end");case"assistant":case"tool":case"system":return te(ye,"justify-start");default:return ye}},[F]),et=b.useCallback(()=>{const ye=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",I&&"px-3 py-2 text-sm");if(G)return te(ye,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(F){case"user":return te(ye,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(ye,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(ye,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(ye,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(ye,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[I,G,F]),Ze=b.useCallback(async ye=>{if(w)return;const tt=Wo((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id));if(!tt){console.warn("Interrupt part missing id",ye);return}try{S==null||S(),await W(tt,!0)}catch(rt){console.error("Failed to approve interrupt:",rt)}finally{k==null||k()}},[w,k,S,W]),vt=b.useCallback(async ye=>{if(w)return;const tt=Wo((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id));if(!tt){console.warn("Interrupt part missing id",ye);return}try{S==null||S(),await W(tt,!1)}catch(rt){console.error("Failed to reject interrupt:",rt)}finally{k==null||k()}},[w,k,S,W]),gt=b.useMemo(()=>_?"Assistant":Fv(t),[_,t]),ut=F==="user"&&(C??1)>1&&typeof E=="function";return R&&!p&&!Ee?null:G&&_?u.jsx("div",{className:te(nt(),f.container),children:u.jsxs("div",{className:te(et(),f.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ue.Bot,{className:te("h-4 w-4",B)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(Ar,{content:_.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(nt(),f.container),children:u.jsxs("div",{className:te(et(),f.content),children:[(i||a||R)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",I&&"mb-1 pb-1",B,f.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ye(),a&&gt&&u.jsx("span",{className:te("font-medium",I?"text-xs":"text-sm"),children:gt}),R&&u.jsxs(Op,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",B,"border border-current/40",I&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":L==="expanded",onClick:()=>U(ye=>ye==="expanded"?"preview":"expanded"),onKeyDown:ye=>{(ye.key==="Enter"||ye.key===" ")&&(ye.preventDefault(),U(tt=>tt==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:de.name??"Tool Output"}),de.toolCallId&&u.jsx("span",{className:"opacity-70",children:de.toolCallId.slice(0,8)}),L==="expanded"?u.jsx(ue.ChevronUp,{className:"h-3 w-3"}):u.jsx(ue.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[ut&&C>1&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",T<C-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{T>=C-1||!E||E(null)},"aria-label":"Older attempt (back in time)",disabled:T>=C-1,children:u.jsx(ue.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[C-T," / ",C]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",T>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{T<=0||!E||E(null)},"aria-label":"Newer attempt (forward in time)",disabled:T<=0,children:u.jsx(ue.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",B,I&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",f.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>Fe(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",B,I&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ue.Copy,{className:te(j?"text-success":B,I?"h-3 w-3":"h-4 w-4")})})}),F==="user"&&v&&u.jsx(it,{variant:"ghost",size:"sm",onClick:Ke,className:te("h-6 w-6 p-0 hover:bg-foreground/10",B,I&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ue.Edit,{className:te(B,I?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&g&&u.jsx(it,{variant:"ghost",size:"sm",onClick:Ue,className:te("h-6 w-6 p-0 hover:bg-foreground/10",B,I&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ue.RotateCcw,{className:te(B,I?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[u.jsx(Th,{message:t,isToolMessage:R,showToolMessages:p,artifactToRender:Ee,toolViewMode:L,isToolStreaming:xe,contentParts:X,textContent:Z,imageParts:re,fileParts:ae,interruptParts:$,isStreamingMessage:r,defaultMessage:_,handleFileClick:M,uploadingFiles:P,handleInterruptApprove:Ze,handleInterruptReject:vt,disableInterruptActions:w,messageRole:F,truncateUserMessages:c,userMessagePreviewLength:d,isUserExpanded:K,setIsUserExpanded:V,isCompactLayout:I,activeInterruptId:Ve,activeInterruptValue:He,iconForeground:B}),m&&Ee&&u.jsx("div",{className:"mt-3",children:u.jsx(xh,{artifact:Ee,idx:0})})]}),R&&L==="expanded"&&(de.toolCallId||de.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",I&&"text-xs"),children:[de.name&&u.jsxs("div",{children:["Function: ",de.name]}),de.toolCallId&&u.jsxs("div",{children:["Call ID: ",de.toolCallId]})]}),!(i||a||R)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",f.actions),children:[u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>Fe(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.Copy,{className:te(j?"text-success":"text-current",I?"h-3 w-3":"h-4 w-4")})}),F==="user"&&v&&u.jsx(it,{variant:"ghost",size:"sm",onClick:Ke,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.Edit,{className:te("text-current",I?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&g&&u.jsx(it,{variant:"ghost",size:"sm",onClick:Ue,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.RotateCcw,{className:te("text-current",I?"h-3 w-3":"h-4 w-4")})})]})]})}),Y&&u.jsx(th,{isOpen:q,onClose:se,fileId:Y.id,fileName:Y.name,mimeType:Y.mimeType})]})},(e,t)=>{var l,c,d,p,m,f,v,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&lu(e.message)===lu(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(x=>e[x]===t[x]),s=((l=e.customStyles)==null?void 0:l.container)===((c=t.customStyles)==null?void 0:c.container)&&((d=e.customStyles)==null?void 0:d.content)===((p=t.customStyles)==null?void 0:p.content)&&((m=e.customStyles)==null?void 0:m.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((v=e.customStyles)==null?void 0:v.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=cu(e.message),a=cu(t.message);return i.length===a.length});Vs.displayName="MessageComponent";const ST={checkpoints:[],checkpointMetaByCheckpointId:new Map,timeline:[],messagePreviews:new Map,getLatest:()=>{},getCheckpoint:()=>{},getMessageAttempts:()=>[]},al=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,ll=b.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:p,activeInterrupt:m,disableInterruptActions:f,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:x,showArtifactPreviews:y,checkpointIndex:w,onSelectCheckpoint:S}){const k=al(t,n),C="type"in t&&t.type==="default_message",E=!!t.__syntheticStreaming,j=w??ST,O=!C&&"checkpointId"in t?t.checkpointId??null:null,{attemptCount:L,attemptIndex:U}=b.useMemo(()=>Ql(O,j),[O,j]);return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":k,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Vs,{message:t,messageIndex:n,isStreamingMessage:E||r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:p,activeInterrupt:m,disableInterruptActions:f,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:x,showArtifactPreviews:y,attemptCount:L,attemptIndex:U,onSelectCheckpoint:S})})});ll.displayName="MessageRow";const cl=b.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:p,style:m,emptyMessage:f,followNewMessages:v=!0,isNavigatingCheckpoint:g=!1,onScrollAway:x,onAtBottom:y,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointIndex:j,activeCheckpointId:O,onSelectCheckpoint:L,createSyntheticThinkingMessage:U=!0},K)=>{const V=b.useRef(null),N=b.useRef(null),W=b.useRef(!1),I=b.useRef(!1),[F,R]=b.useState(!0),_=b.useMemo(()=>w?e.some($=>"type"in $&&$.type==="default_message"?!1:Array.isArray($==null?void 0:$.content)&&$.content.some(Z=>Z&&Z.type==="interrupt"&&(Z.id??Z.interrupt_id)===w.id)):!1,[w,e]),G=b.useMemo(()=>{if(!w||_)return null;const $=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let Z;const de=w.value;if(de&&typeof de=="object"&&!Array.isArray(de)){const ce=de.title;typeof ce=="string"&&ce.trim()&&(Z=ce.trim())}return{id:`interrupt-${$}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:$,value:de,title:Z}]}},[w,_]),J=b.useMemo(()=>G?[...e,G]:e,[e,G]),P=b.useMemo(()=>!U||!t?J:!J.some(Z=>Z.role==="assistant")&&J.length>0?[...J,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString(),__syntheticStreaming:!0}]:J,[J,t,U]),M=b.useMemo(()=>T?P:P.filter($=>($==null?void 0:$.role)!=="tool"),[P,T]),q=b.useCallback($=>{R($),x&&x(!$),y&&y($)},[x,y]),Y=b.useMemo(()=>{if(a)return async()=>{if(!W.current){W.current=!0;try{await a()}finally{W.current=!1}}}},[a]),se=b.useMemo(()=>!v||g?!1:F?"auto":!1,[F,v,g]),B=b.useMemo(()=>{if(typeof f!="string")return null;const $=f.trim();return $?{id:"default-message",role:"assistant",type:"default_message",content:$,createdAt:new Date().toISOString()}:null},[f]),D=["flex h-full flex-col md:flex-row",p].filter(Boolean).join(" "),X=()=>B?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Vs,{message:B,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:E})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:f??"No messages yet. Start a conversation!"}),re=M.length,ae=re>0;return b.useEffect(()=>{var $,Z;if(re===0){I.current=!1;return}if(!I.current)if(I.current=!0,V.current&&M.length>0){const de=M.length-1;(Z=($=V.current).scrollToIndex)==null||Z.call($,{index:de,align:"end",behavior:"auto"})}else N.current&&(N.current.scrollTop=N.current.scrollHeight)},[re,M.length]),b.useImperativeHandle(K,()=>({scrollToLatest:()=>{var $,Z;if(V.current&&M.length>0){const de=M.length-1;(Z=($=V.current).scrollToIndex)==null||Z.call($,{index:de,align:"end",behavior:"auto"})}else N.current&&(N.current.scrollTop=N.current.scrollHeight)},scrollToTop:()=>{var $,Z;V.current&&M.length>0?(Z=($=V.current).scrollToIndex)==null||Z.call($,{index:0,align:"start",behavior:"auto"}):N.current&&(N.current.scrollTop=0)}}),[M]),u.jsx("div",{className:D,style:m,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:ae?u.jsx(kC,{ref:$=>{V.current=$},scrollerRef:$=>{N.current=$ instanceof HTMLDivElement?$:null},data:M,followOutput:se,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{Y&&Y()},atBottomStateChange:q,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:($,Z)=>al(Z,$),itemContent:($,Z)=>u.jsx(ll,{message:Z,index:$,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:E,checkpointIndex:j,activeCheckpointId:O,onSelectCheckpoint:L})}):X()})})});cl.displayName="MessageList";const Ih={value:""};function So({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:p=!0,customStyles:m={},onMessageSent:f,onExcelUploadSuccess:v,onError:g}){const{api:x}=Vr(),{currentThreadId:y}=pr(),{threadId:w,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:j,checkpoints:O,interrupt:L,metadata:U,checkpointIndex:K}=Yr(),{isStreaming:V,error:N,connectionState:W,submit:I,stop:F}=Ri(),R=w??y??null,_=(j==null?void 0:j.id)??null,G=(j==null?void 0:j.namespace)??null,J=(U==null?void 0:U.assemblingMessageId)??null,P=L,[M,q]=b.useState(!1);b.useEffect(()=>{P||q(!1)},[P]);const Y=b.useCallback(()=>{q(!0)},[]),se=b.useCallback(()=>{q(!1)},[]),B=!!P||M,[D,X]=b.useState(null),[re,ae]=b.useState(""),[$,Z]=b.useState(null),[de,ce]=b.useState(null),[xe,_e]=b.useState([]),[Ve,He]=b.useState(0),[Ee,Fe]=b.useState(0),[Ke,Ue]=b.useState(!1),[Ye,nt]=b.useState(null),[et,Ze]=b.useState(null),[vt,gt]=b.useState(!1),[ut,ye]=b.useState(null),tt=b.useRef(!1),[rt,_t]=b.useState(()=>Ih.value),pn=b.useRef(rt),Le=b.useRef(null),qe=b.useCallback(le=>{Ih.value=le,_t(le)},[]),[Dt,Pt]=b.useState(!1),wt=b.useRef(null),kt=b.useRef(null),ne=b.useRef(null),Se=b.useCallback(()=>{kt.current&&(kt.current.value=""),ne.current&&(ne.current.value=""),He(le=>le+1),Fe(le=>le+1)},[]),ft=b.useCallback(le=>{qe(le)},[qe]),Ce=b.useRef(!1);b.useEffect(()=>{Ce.current&&!V&&(_e([]),Se()),Ce.current=V},[V,Se]);const[Me,We]=b.useState("desktop");b.useEffect(()=>{const le=()=>{const ge=window.innerWidth;We(ge<640?"phone":ge<1024?"tablet":"desktop")};return le(),window.addEventListener("resize",le),()=>window.removeEventListener("resize",le)},[]),b.useEffect(()=>{tt.current=!1},[R]),b.useEffect(()=>{pn.current=rt},[rt]),b.useEffect(()=>{if(!D){Le.current=null;return}Le.current===null&&(Le.current=pn.current),qe(re??"")},[re,D,qe]),b.useEffect(()=>{(async()=>{if(!x.baseUrl){ye(null);return}try{const pe=(await x.getAgent("default")).uiDefaultMessage||"";ye(pe||null)}catch(ge){console.warn("Failed to fetch default message:",ge),ye(null)}})()},[x.baseUrl]),b.useEffect(()=>{N&&!vt&&(g==null||g(N))},[N,vt,g]);const Ct=async le=>{const ge=le.trim();if(!(!ge&&xe.length===0))try{const pe=D?($==null?void 0:$.checkpointId)??_??void 0:_??void 0,Te=D?($==null?void 0:$.checkpointNs)??G??void 0:G??void 0;await I({text:ge||"",attachments:xe},{checkpointId:pe,checkpointNs:Te,edit:!!D,originalMessageId:D??void 0}),f==null||f(ge),qe(""),ce(null),_e([]),Se(),X(null),ae(""),Z(null)}catch(pe){const Te=(pe==null?void 0:pe.message)||"Failed to send message";ce(Te),g==null||g(Te)}},Be=b.useCallback((le,ge,pe)=>{c&&(Le.current=rt,X(le),ae(ge),qe(ge),ce(null),Z({checkpointId:(pe==null?void 0:pe.checkpointId)??null,checkpointNs:(pe==null?void 0:pe.checkpointNs)??null}))},[rt,c,qe]),dt=b.useCallback(()=>{X(null),ae(""),Z(null),ce(null),qe(Le.current??rt),Le.current=null},[rt,qe]),$e=b.useCallback((le,ge,pe)=>{Be(le,ge,pe)},[Be]),Qe=b.useCallback(le=>{let ge=null;for(let Xe=le-1;Xe>=0;Xe--)if(S[Xe].role==="user"){ge=S[Xe];break}if(!ge)return;const pe=Array.isArray(ge.content)?ge.content:[],bt=pe.filter(Xe=>(Xe==null?void 0:Xe.type)==="text").map(Xe=>Xe.text).join("")||(()=>{try{return JSON.stringify(pe,null,2)}catch{return String(pe)}})();bt&&I({text:bt},{checkpointId:_??void 0,checkpointNs:G??void 0,edit:!0,originalMessageId:ge.id})},[S,I,_,G]),Ut=le=>{const ge=Array.from(le.target.files||[]);_e(pe=>[...pe,...ge]),le.target.value=""},ql=le=>{_e(ge=>{const pe=ge.filter((Te,bt)=>le!==bt);return pe.length===0&&Se(),pe})},Gl=async le=>{const ge=(le.target.files||[])[0];if(ge){nt(null),Ze(null),Ue(!0);try{await I({attachments:[ge]},{checkpointId:_??void 0,checkpointNs:G??void 0});const pe=`Uploaded ${ge.name} - processing through chat stream`;Ze(pe)}catch(pe){const Te=pe instanceof Error?pe.message:"Failed to upload Excel file";console.error("Excel upload failed",pe),nt(Te),g==null||g(Te)}finally{Ue(!1),le.target.value="",Se()}}},ci=async le=>{if(y){Pt(!0);try{if(!le){await E(),requestAnimationFrame(()=>{var Te;(Te=wt.current)==null||Te.scrollToLatest()});return}const ge=O.find(Te=>Te.checkpointId===le),pe=(ge==null?void 0:ge.checkpointNs)??null;await T(le,pe),requestAnimationFrame(()=>{var Te;(Te=wt.current)==null||Te.scrollToTop()})}finally{Pt(!1)}}},A=b.useCallback(async(le,ge,pe)=>{await ci(pe?null:le)},[ci]),ee=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${m.container||""}`,fe=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${m.messagesArea||""}`,Ne=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${m.inputArea||""}`;return u.jsxs("div",{className:ee,children:[!!N&&!vt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:N}),u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>gt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ue.X,{size:16})})]}),u.jsxs("div",{className:`relative ${fe}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(cl,{ref:wt,className:"h-full",style:{height:"100%"},messages:S,isStreaming:V,streamingAssistantId:J,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Me,enableMessageEditing:c,editingMessageId:D,onEdit:$e,onRegenerate:Qe,onCancelEdit:dt,emptyMessage:ut??void 0,isNavigatingCheckpoint:Dt,activeInterrupt:P,disableInterruptActions:M,onInterruptActionStart:Y,onInterruptActionEnd:se,showToolMessages:d,showArtifactPreviews:p,checkpointIndex:K,activeCheckpointId:_,onSelectCheckpoint:A,createSyntheticThinkingMessage:!0}),(W==="reconnecting"||W==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(ue.Loader2,{className:"h-3 w-3 animate-spin"}),W==="reconnecting"?"Reconnecting…":"Connecting…"]})}),W==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||Dt)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:Ne,children:[D&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ue.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(it,{variant:"ghost",size:"sm",onClick:dt,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ue.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:kt,type:"file",multiple:!0,onChange:le=>Ut(le),className:"hidden"},Ve),xe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:xe.map((le,ge)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(ue.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:le.name}),u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>ql(ge),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${le.name}`,children:u.jsx(ue.X,{size:12})})]},ge))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:ne,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Gl,className:"hidden"},Ee),Ke&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),et&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:et}),Ye&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Ye})]})]}),de&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:de}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(vs,{children:[u.jsx(ws,{asChild:!0,children:u.jsx(it,{type:"button",size:"icon",variant:"outline",disabled:V||B,title:"More input actions",className:m.moreButton||"",children:u.jsx(ue.Plus,{size:16})})}),u.jsxs(ao,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(On,{onClick:()=>{var le;return(le=kt.current)==null?void 0:le.click()},className:"cursor-pointer",children:[u.jsx(ue.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(On,{onClick:()=>{var le;Ke||(le=ne.current)==null||le.click()},className:`cursor-pointer ${Ke?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ue.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(mS,{initialValue:re,editingMessageId:D,value:rt,onValueChange:ft,placeholder:D?"Edit your message...":t,isStreaming:V,disabled:B,onSend:Ct,onCancelEdit:dt,onStop:F,allowEmptySend:xe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${D?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${de?"border-red-400":""} ${m.textarea||""}`})})]})]})]})}var Nh=1,CT=.9,TT=.8,kT=.17,ul=.1,dl=.999,ET=.9999,IT=.99,NT=/[\\\/_+.#"@\[\(\{&]/,AT=/[\\\/_+.#"@\[\(\{&]/g,jT=/[\s-]/,Ah=/[\s-]/g;function fl(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?Nh:IT;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),c=n.indexOf(l,o),d=0,p,m,f,v;c>=0;)p=fl(e,t,n,r,c+1,s+1,i),p>d&&(c===o?p*=Nh:NT.test(e.charAt(c-1))?(p*=TT,f=e.slice(o,c-1).match(AT),f&&o>0&&(p*=Math.pow(dl,f.length))):jT.test(e.charAt(c-1))?(p*=CT,v=e.slice(o,c-1).match(Ah),v&&o>0&&(p*=Math.pow(dl,v.length))):(p*=kT,o>0&&(p*=Math.pow(dl,c-o))),e.charAt(c)!==t.charAt(s)&&(p*=ET)),(p<ul&&n.charAt(c-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(c-1)!==r.charAt(s))&&(m=fl(e,t,n,r,c+1,s+2,i),m*ul>p&&(p=m*ul)),p>d&&(d=p),c=n.indexOf(l,c+1);return i[a]=d,d}function jh(e){return e.toLowerCase().replace(Ah," ")}function _T(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,fl(e,t,jh(e),jh(t),0,0,{})}var Co='[cmdk-group=""]',pl='[cmdk-group-items=""]',PT='[cmdk-group-heading=""]',_h='[cmdk-item=""]',Ph=`${_h}:not([aria-disabled="true"])`,hl="cmdk-item-select",jr="data-value",RT=(e,t,n)=>_T(e,t,n),Rh=h.createContext(void 0),To=()=>h.useContext(Rh),Mh=h.createContext(void 0),ml=()=>h.useContext(Mh),Oh=h.createContext(void 0),Dh=h.forwardRef((e,t)=>{let n=_r(()=>{var P,M;return{search:"",value:(M=(P=e.value)!=null?P:e.defaultValue)!=null?M:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=_r(()=>new Set),o=_r(()=>new Map),s=_r(()=>new Map),i=_r(()=>new Set),a=Lh(e),{label:l,children:c,value:d,onValueChange:p,filter:m,shouldFilter:f,loop:v,disablePointerSelection:g=!1,vimBindings:x=!0,...y}=e,w=It(),S=It(),k=It(),C=h.useRef(null),T=WT();sr(()=>{if(d!==void 0){let P=d.trim();n.current.value=P,E.emit()}},[d]),sr(()=>{T(6,V)},[]);let E=h.useMemo(()=>({subscribe:P=>(i.current.add(P),()=>i.current.delete(P)),snapshot:()=>n.current,setState:(P,M,q)=>{var Y,se,B,D;if(!Object.is(n.current[P],M)){if(n.current[P]=M,P==="search")K(),L(),T(1,U);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let X=document.getElementById(k);X?X.focus():(Y=document.getElementById(w))==null||Y.focus()}if(T(7,()=>{var X;n.current.selectedItemId=(X=N())==null?void 0:X.id,E.emit()}),q||T(5,V),((se=a.current)==null?void 0:se.value)!==void 0){let X=M??"";(D=(B=a.current).onValueChange)==null||D.call(B,X);return}}E.emit()}},emit:()=>{i.current.forEach(P=>P())}}),[]),j=h.useMemo(()=>({value:(P,M,q)=>{var Y;M!==((Y=s.current.get(P))==null?void 0:Y.value)&&(s.current.set(P,{value:M,keywords:q}),n.current.filtered.items.set(P,O(M,q)),T(2,()=>{L(),E.emit()}))},item:(P,M)=>(r.current.add(P),M&&(o.current.has(M)?o.current.get(M).add(P):o.current.set(M,new Set([P]))),T(3,()=>{K(),L(),n.current.value||U(),E.emit()}),()=>{s.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let q=N();T(4,()=>{K(),(q==null?void 0:q.getAttribute("id"))===P&&U(),E.emit()})}),group:P=>(o.current.has(P)||o.current.set(P,new Set),()=>{s.current.delete(P),o.current.delete(P)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:w,inputId:k,labelId:S,listInnerRef:C}),[]);function O(P,M){var q,Y;let se=(Y=(q=a.current)==null?void 0:q.filter)!=null?Y:RT;return P?se(P,n.current.search,M):0}function L(){if(!n.current.search||a.current.shouldFilter===!1)return;let P=n.current.filtered.items,M=[];n.current.filtered.groups.forEach(Y=>{let se=o.current.get(Y),B=0;se.forEach(D=>{let X=P.get(D);B=Math.max(X,B)}),M.push([Y,B])});let q=C.current;W().sort((Y,se)=>{var B,D;let X=Y.getAttribute("id"),re=se.getAttribute("id");return((B=P.get(re))!=null?B:0)-((D=P.get(X))!=null?D:0)}).forEach(Y=>{let se=Y.closest(pl);se?se.appendChild(Y.parentElement===se?Y:Y.closest(`${pl} > *`)):q.appendChild(Y.parentElement===q?Y:Y.closest(`${pl} > *`))}),M.sort((Y,se)=>se[1]-Y[1]).forEach(Y=>{var se;let B=(se=C.current)==null?void 0:se.querySelector(`${Co}[${jr}="${encodeURIComponent(Y[0])}"]`);B==null||B.parentElement.appendChild(B)})}function U(){let P=W().find(q=>q.getAttribute("aria-disabled")!=="true"),M=P==null?void 0:P.getAttribute(jr);E.setState("value",M||void 0)}function K(){var P,M,q,Y;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let se=0;for(let B of r.current){let D=(M=(P=s.current.get(B))==null?void 0:P.value)!=null?M:"",X=(Y=(q=s.current.get(B))==null?void 0:q.keywords)!=null?Y:[],re=O(D,X);n.current.filtered.items.set(B,re),re>0&&se++}for(let[B,D]of o.current)for(let X of D)if(n.current.filtered.items.get(X)>0){n.current.filtered.groups.add(B);break}n.current.filtered.count=se}function V(){var P,M,q;let Y=N();Y&&(((P=Y.parentElement)==null?void 0:P.firstChild)===Y&&((q=(M=Y.closest(Co))==null?void 0:M.querySelector(PT))==null||q.scrollIntoView({block:"nearest"})),Y.scrollIntoView({block:"nearest"}))}function N(){var P;return(P=C.current)==null?void 0:P.querySelector(`${_h}[aria-selected="true"]`)}function W(){var P;return Array.from(((P=C.current)==null?void 0:P.querySelectorAll(Ph))||[])}function I(P){let M=W()[P];M&&E.setState("value",M.getAttribute(jr))}function F(P){var M;let q=N(),Y=W(),se=Y.findIndex(D=>D===q),B=Y[se+P];(M=a.current)!=null&&M.loop&&(B=se+P<0?Y[Y.length-1]:se+P===Y.length?Y[0]:Y[se+P]),B&&E.setState("value",B.getAttribute(jr))}function R(P){let M=N(),q=M==null?void 0:M.closest(Co),Y;for(;q&&!Y;)q=P>0?HT(q,Co):UT(q,Co),Y=q==null?void 0:q.querySelector(Ph);Y?E.setState("value",Y.getAttribute(jr)):F(P)}let _=()=>I(W().length-1),G=P=>{P.preventDefault(),P.metaKey?_():P.altKey?R(1):F(1)},J=P=>{P.preventDefault(),P.metaKey?I(0):P.altKey?R(-1):F(-1)};return h.createElement(ve.div,{ref:t,tabIndex:-1,...y,"cmdk-root":"",onKeyDown:P=>{var M;(M=y.onKeyDown)==null||M.call(y,P);let q=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||q))switch(P.key){case"n":case"j":{x&&P.ctrlKey&&G(P);break}case"ArrowDown":{G(P);break}case"p":case"k":{x&&P.ctrlKey&&J(P);break}case"ArrowUp":{J(P);break}case"Home":{P.preventDefault(),I(0);break}case"End":{P.preventDefault(),_();break}case"Enter":{P.preventDefault();let Y=N();if(Y){let se=new Event(hl);Y.dispatchEvent(se)}}}}},h.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:KT},l),Ks(e,P=>h.createElement(Mh.Provider,{value:E},h.createElement(Rh.Provider,{value:j},P))))}),MT=h.forwardRef((e,t)=>{var n,r;let o=It(),s=h.useRef(null),i=h.useContext(Oh),a=To(),l=Lh(e),c=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;sr(()=>{if(!c)return a.item(o,i==null?void 0:i.id)},[c]);let d=$h(o,s,[e.value,e.children,s],e.keywords),p=ml(),m=Hn(T=>T.value&&T.value===d.current),f=Hn(T=>c||a.filter()===!1?!0:T.search?T.filtered.items.get(o)>0:!0);h.useEffect(()=>{let T=s.current;if(!(!T||e.disabled))return T.addEventListener(hl,v),()=>T.removeEventListener(hl,v)},[f,e.onSelect,e.disabled]);function v(){var T,E;g(),(E=(T=l.current).onSelect)==null||E.call(T,d.current)}function g(){p.setState("value",d.current,!0)}if(!f)return null;let{disabled:x,value:y,onSelect:w,forceMount:S,keywords:k,...C}=e;return h.createElement(ve.div,{ref:jn(s,t),...C,id:o,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!m,"data-disabled":!!x,"data-selected":!!m,onPointerMove:x||a.getDisablePointerSelection()?void 0:g,onClick:x?void 0:v},e.children)}),OT=h.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=It(),a=h.useRef(null),l=h.useRef(null),c=It(),d=To(),p=Hn(f=>o||d.filter()===!1?!0:f.search?f.filtered.groups.has(i):!0);sr(()=>d.group(i),[]),$h(i,a,[e.value,e.heading,l]);let m=h.useMemo(()=>({id:i,forceMount:o}),[o]);return h.createElement(ve.div,{ref:jn(a,t),...s,"cmdk-group":"",role:"presentation",hidden:p?void 0:!0},n&&h.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),Ks(e,f=>h.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},h.createElement(Oh.Provider,{value:m},f))))}),DT=h.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=h.useRef(null),s=Hn(i=>!i.search);return!n&&!s?null:h.createElement(ve.div,{ref:jn(o,t),...r,"cmdk-separator":"",role:"separator"})}),LT=h.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=ml(),i=Hn(c=>c.search),a=Hn(c=>c.selectedItemId),l=To();return h.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),h.createElement(ve.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:c=>{o||s.setState("search",c.target.value),n==null||n(c.target.value)}})}),$T=h.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=h.useRef(null),i=h.useRef(null),a=Hn(c=>c.selectedItemId),l=To();return h.useEffect(()=>{if(i.current&&s.current){let c=i.current,d=s.current,p,m=new ResizeObserver(()=>{p=requestAnimationFrame(()=>{let f=c.offsetHeight;d.style.setProperty("--cmdk-list-height",f.toFixed(1)+"px")})});return m.observe(c),()=>{cancelAnimationFrame(p),m.unobserve(c)}}},[]),h.createElement(ve.div,{ref:jn(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Ks(e,c=>h.createElement("div",{ref:jn(i,l.listInnerRef),"cmdk-list-sizer":""},c)))}),FT=h.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return h.createElement(qa,{open:n,onOpenChange:r},h.createElement(Ga,{container:i},h.createElement(wo,{"cmdk-overlay":"",className:o}),h.createElement(bo,{"aria-label":e.label,"cmdk-dialog":"",className:s},h.createElement(Dh,{ref:t,...a}))))}),BT=h.forwardRef((e,t)=>Hn(n=>n.filtered.count===0)?h.createElement(ve.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),zT=h.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return h.createElement(ve.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},Ks(e,i=>h.createElement("div",{"aria-hidden":!0},i)))}),zt=Object.assign(Dh,{List:$T,Item:MT,Input:LT,Group:OT,Separator:DT,Dialog:FT,Empty:BT,Loading:zT});function HT(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function UT(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Lh(e){let t=h.useRef(e);return sr(()=>{t.current=e}),t}var sr=typeof window>"u"?h.useEffect:h.useLayoutEffect;function _r(e){let t=h.useRef();return t.current===void 0&&(t.current=e()),t}function Hn(e){let t=ml(),n=()=>e(t.snapshot());return h.useSyncExternalStore(t.subscribe,n,n)}function $h(e,t,n,r=[]){let o=h.useRef(),s=To();return sr(()=>{var i;let a=(()=>{var c;for(let d of n){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?(c=d.current.textContent)==null?void 0:c.trim():o.current}})(),l=r.map(c=>c.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(jr,a),o.current=a}),o}var WT=()=>{let[e,t]=h.useState(),n=_r(()=>new Map);return sr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function VT(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Ks({asChild:e,children:t},n){return e&&h.isValidElement(t)?h.cloneElement(VT(t),{ref:t.ref},n(t.props.children)):n(t)}var KT={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const gl=h.forwardRef(({className:e,...t},n)=>u.jsx(zt,{ref:n,className:te("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));gl.displayName=zt.displayName;const xl=h.forwardRef(({className:e,...t},n)=>u.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[u.jsx(ue.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),u.jsx(zt.Input,{ref:n,className:te("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));xl.displayName=zt.Input.displayName;const vl=h.forwardRef(({className:e,...t},n)=>u.jsx(zt.List,{ref:n,className:te("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));vl.displayName=zt.List.displayName;const wl=h.forwardRef((e,t)=>u.jsx(zt.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));wl.displayName=zt.Empty.displayName;const bl=h.forwardRef(({className:e,...t},n)=>u.jsx(zt.Group,{ref:n,className:te("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));bl.displayName=zt.Group.displayName;const qT=h.forwardRef(({className:e,...t},n)=>u.jsx(zt.Separator,{ref:n,className:te("-mx-1 h-px bg-border",e),...t}));qT.displayName=zt.Separator.displayName;const yl=h.forwardRef(({className:e,...t},n)=>u.jsx(zt.Item,{ref:n,className:te("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));yl.displayName=zt.Item.displayName;function Sl(e,[t,n]){return Math.min(n,Math.max(t,e))}function GT(e,t){return h.useReducer((n,r)=>t[n][r]??n,e)}var Cl="ScrollArea",[Fh,l1]=on(Cl),[YT,tn]=Fh(Cl),Bh=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=h.useState(null),[c,d]=h.useState(null),[p,m]=h.useState(null),[f,v]=h.useState(null),[g,x]=h.useState(null),[y,w]=h.useState(0),[S,k]=h.useState(0),[C,T]=h.useState(!1),[E,j]=h.useState(!1),O=Oe(t,U=>l(U)),L=Ko(o);return u.jsx(YT,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:p,onContentChange:m,scrollbarX:f,onScrollbarXChange:v,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:x,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:w,onCornerHeightChange:k,children:u.jsx(ve.div,{dir:L,...i,ref:O,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Bh.displayName=Cl;var zh="ScrollAreaViewport",Hh=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=tn(zh,n),a=h.useRef(null),l=Oe(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(ve.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Hh.displayName=zh;var Tn="ScrollAreaScrollbar",Tl=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Tn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return h.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(XT,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(JT,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Uh,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(kl,{...r,ref:t}):null});Tl.displayName=Tn;var XT=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Tn,e.__scopeScrollArea),[s,i]=h.useState(!1);return h.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Ft,{present:n||s,children:u.jsx(Uh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),JT=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(Tn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Xs(()=>l("SCROLL_END"),100),[a,l]=GT("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return h.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),h.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let p=c[d];const m=()=>{const f=c[d];p!==f&&(l("SCROLL"),i()),p=f};return c.addEventListener("scroll",m),()=>c.removeEventListener("scroll",m)}},[o.viewport,s,l,i]),u.jsx(Ft,{present:n||a!=="hidden",children:u.jsx(kl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ie(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ie(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Uh=h.forwardRef((e,t)=>{const n=tn(Tn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=h.useState(!1),a=e.orientation==="horizontal",l=Xs(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Pr(n.viewport,l),Pr(n.content,l),u.jsx(Ft,{present:r||s,children:u.jsx(kl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),kl=h.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=tn(Tn,e.__scopeScrollArea),s=h.useRef(null),i=h.useRef(0),[a,l]=h.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Gh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:m=>s.current=m,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:m=>i.current=m};function p(m,f){return rk(m,i.current,a,f)}return n==="horizontal"?u.jsx(ZT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,f=Yh(m,a,o.dir);s.current.style.transform=`translate3d(${f}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=p(m,o.dir))}}):n==="vertical"?u.jsx(QT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,f=Yh(m,a);s.current.style.transform=`translate3d(0, ${f}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=p(m))}}):null}),ZT=h.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(Tn,e.__scopeScrollArea),[i,a]=h.useState(),l=h.useRef(null),c=Oe(t,l,s.onScrollbarXChange);return h.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Vh,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ys(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,p)=>{if(s.viewport){const m=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(m),Jh(m,p)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Gs(i.paddingLeft),paddingEnd:Gs(i.paddingRight)}})}})}),QT=h.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(Tn,e.__scopeScrollArea),[i,a]=h.useState(),l=h.useRef(null),c=Oe(t,l,s.onScrollbarYChange);return h.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Vh,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ys(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,p)=>{if(s.viewport){const m=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(m),Jh(m,p)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Gs(i.paddingTop),paddingEnd:Gs(i.paddingBottom)}})}})}),[ek,Wh]=Fh(Tn),Vh=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:p,...m}=e,f=tn(Tn,n),[v,g]=h.useState(null),x=Oe(t,O=>g(O)),y=h.useRef(null),w=h.useRef(""),S=f.viewport,k=r.content-r.viewport,C=ht(d),T=ht(l),E=Xs(p,10);function j(O){if(y.current){const L=O.clientX-y.current.left,U=O.clientY-y.current.top;c({x:L,y:U})}}return h.useEffect(()=>{const O=L=>{const U=L.target;(v==null?void 0:v.contains(U))&&C(L,k)};return document.addEventListener("wheel",O,{passive:!1}),()=>document.removeEventListener("wheel",O,{passive:!1})},[S,v,k,C]),h.useEffect(T,[r,T]),Pr(v,E),Pr(f.content,E),u.jsx(ek,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:ht(s),onThumbPointerUp:ht(i),onThumbPositionChange:T,onThumbPointerDown:ht(a),children:u.jsx(ve.div,{...m,ref:x,style:{position:"absolute",...m.style},onPointerDown:ie(e.onPointerDown,O=>{O.button===0&&(O.target.setPointerCapture(O.pointerId),y.current=v.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",f.viewport&&(f.viewport.style.scrollBehavior="auto"),j(O))}),onPointerMove:ie(e.onPointerMove,j),onPointerUp:ie(e.onPointerUp,O=>{const L=O.target;L.hasPointerCapture(O.pointerId)&&L.releasePointerCapture(O.pointerId),document.body.style.webkitUserSelect=w.current,f.viewport&&(f.viewport.style.scrollBehavior=""),y.current=null})})})}),qs="ScrollAreaThumb",Kh=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Wh(qs,e.__scopeScrollArea);return u.jsx(Ft,{present:n||o.hasThumb,children:u.jsx(tk,{ref:t,...r})})}),tk=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=tn(qs,n),i=Wh(qs,n),{onThumbPositionChange:a}=i,l=Oe(t,p=>i.onThumbChange(p)),c=h.useRef(void 0),d=Xs(()=>{c.current&&(c.current(),c.current=void 0)},100);return h.useEffect(()=>{const p=s.viewport;if(p){const m=()=>{if(d(),!c.current){const f=ok(p,a);c.current=f,a()}};return a(),p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)}},[s.viewport,d,a]),u.jsx(ve.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ie(e.onPointerDownCapture,p=>{const f=p.target.getBoundingClientRect(),v=p.clientX-f.left,g=p.clientY-f.top;i.onThumbPointerDown({x:v,y:g})}),onPointerUp:ie(e.onPointerUp,i.onThumbPointerUp)})});Kh.displayName=qs;var El="ScrollAreaCorner",qh=h.forwardRef((e,t)=>{const n=tn(El,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(nk,{...e,ref:t}):null});qh.displayName=El;var nk=h.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=tn(El,n),[s,i]=h.useState(0),[a,l]=h.useState(0),c=!!(s&&a);return Pr(o.scrollbarX,()=>{var p;const d=((p=o.scrollbarX)==null?void 0:p.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Pr(o.scrollbarY,()=>{var p;const d=((p=o.scrollbarY)==null?void 0:p.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(ve.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Gs(e){return e?parseInt(e,10):0}function Gh(e,t){const n=e/t;return isNaN(n)?0:n}function Ys(e){const t=Gh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function rk(e,t,n,r="ltr"){const o=Ys(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,p=r==="ltr"?[0,d]:[d*-1,0];return Xh([l,c],p)(e)}function Yh(e,t,n="ltr"){const r=Ys(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Sl(e,l);return Xh([0,i],[0,a])(c)}function Xh(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Jh(e,t){return e>0&&e<t}var ok=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Xs(e,t){const n=ht(e),r=h.useRef(0);return h.useEffect(()=>()=>window.clearTimeout(r.current),[]),h.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Pr(e,t){const n=ht(t);Tt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Zh=Bh,sk=Hh,ik=qh;const Il=h.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Zh,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(sk,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Qh,{}),u.jsx(ik,{})]}));Il.displayName=Zh.displayName;const Qh=h.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Tl,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Kh,{className:"relative flex-1 rounded-full bg-border"})}));Qh.displayName=Tl.displayName;const Nl=h.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Nl.displayName="Input";const ak="group relative p-3 rounded-lg cursor-pointer transition-colors border text-gray-900 dark:text-slate-100",lk="bg-slate-700 border-slate-600 hover:bg-slate-600",ck="bg-slate-600 border-slate-500";function em({thread:e,isActive:t,editingThreadId:n,editingTitle:r,onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:l,onShare:c,onDelete:d,showEditTitle:p,showDeleteButton:m,formatDate:f,getDisplayThreadTitle:v,secondaryLine:g,itemClassName:x,activeItemClassName:y}){const w=n===e.threadId,S=t?`${y??ck}`:`${x??lk}`,k=C=>{C.stopPropagation(),o(e.threadId)};return u.jsxs("div",{onClick:k,className:`${ak} ${S}`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:w?u.jsxs("div",{className:"flex items-center gap-2",onClick:C=>C.stopPropagation(),children:[u.jsx(Nl,{value:r,onChange:C=>i(C.target.value),onKeyDown:C=>{C.key==="Enter"?a(e.threadId):C.key==="Escape"&&l()},className:"h-6 text-sm",autoFocus:!0}),u.jsx(it,{variant:"ghost",size:"sm",onClick:()=>a(e.threadId),className:"h-6 w-6 p-0",children:u.jsx(ue.Check,{size:12})}),u.jsx(it,{variant:"ghost",size:"sm",onClick:l,className:"h-6 w-6 p-0",children:u.jsx(ue.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:v(e)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ue.Calendar,{size:10}),u.jsx("span",{children:f(e.updatedAt||e.createdAt)})]}),g&&u.jsx("div",{className:"text-[11px] text-muted-foreground mt-1",children:g})]})}),u.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:u.jsxs(vs,{children:[u.jsx(ws,{asChild:!0,children:u.jsx(it,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:u.jsx(ue.MoreHorizontal,{size:12})})}),u.jsxs(ao,{align:"end",sideOffset:6,className:"w-44",children:[u.jsxs(On,{onClick:C=>{C.preventDefault(),c(e.threadId)},children:[u.jsx(ue.Share2,{className:"mr-2 h-4 w-4"}),"Share thread"]}),p&&n!==e.threadId&&u.jsxs(On,{onClick:C=>{C.preventDefault(),s(e,C)},children:[u.jsx(ue.Edit3,{className:"mr-2 h-4 w-4"}),"Rename"]}),m&&d&&u.jsxs(On,{className:"text-red-400 hover:text-red-300",onClick:C=>{C.preventDefault(),d(e.threadId,C)},children:[u.jsx(ue.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})})]}),t&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]})}const tm=25,nm="thread-manager-view",uk=e=>e==="default"||e==="shared",dk=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(nm);if(uk(e))return e}catch{}return null};function rm({defaultView:e}={}){const[t,n]=b.useState(()=>dk()??e??"default");b.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(nm,t)}catch{}},[t]);const r=b.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const fk=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function Al({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d,view:p,defaultView:m,onViewChange:f,viewOptions:v,viewState:g,showHeader:x=!0,shareTargets:y,isLoadingShareTargets:w,shareTargetFilter:S}){const{threads:k,sharedThreads:C,currentThreadId:T,setCurrentThreadId:E,isLoading:j,isLoadingSharedThreads:O,actions:L,shareInFlight:U,shareStatus:K,clearShareStatus:V}=pr(),{createThread:N,deleteThread:W,renameThread:I,shareThread:F}=L,{loadThread:R}=Yr(),_=i??T,[G,J]=b.useState(Array.isArray(k)?k:[]),P=b.useRef(G.length>0),M=b.useRef(null),q=b.useRef(0),[Y,se]=b.useState(null),[B,D]=b.useState(""),[X,re]=b.useState(!1),[ae,$]=b.useState(!1),[Z,de]=b.useState(null),[ce,xe]=b.useState(""),_e=v&&v.length>0?v:fk,Ve=rm({defaultView:m}),He=g??Ve,Ee=p??He.view,Fe=b.useCallback(ne=>{p||He.setView(ne),f==null||f(ne)},[p,f,He]),Ke=_e.find(ne=>ne.key===Ee)??_e[0],Ue=ne=>{de(ne),xe(""),$(!0)},Ye=()=>{$(!1),de(null),xe(""),V()},nt=b.useCallback(async ne=>{if(!(!Z||U)&&ne.id)try{await F(Z,ne.id),setTimeout(()=>Ye(),600)}catch(Se){console.error("Failed to share thread:",Se)}},[Ye,U,Z,F]),et=b.useMemo(()=>{const ne=y??[],Se=ce.trim().toLowerCase();return Se?S?ne.filter(ft=>S(ft,Se)):ne.filter(ft=>`${ft.label} ${ft.secondaryLabel??""}`.toLowerCase().includes(Se)):ne},[y,ce,S]),Ze=Ee==="shared",vt=Ze?C:G,gt=Ze?O:j,ut=Ze?"No shared conversations yet":"No conversations yet",ye=ne=>{const Se=ne.sharedAt?` • ${Pt(ne.sharedAt)}`:"";return`Shared by ${ne.sharedByUserId}${Se}`},tt=ne=>"sharedByUserId"in ne;b.useEffect(()=>{const ne=Array.isArray(k)?k:[];if(ne.length>0){P.current=!0,J(ne);return}j||(P.current=!1,J(ne))},[k,j]),b.useEffect(()=>{if(!M.current)return;const ne=M.current.querySelector("[data-radix-scroll-area-viewport]");if(!ne)return;let Se=null,ft=null;return Se=requestAnimationFrame(()=>{ft=requestAnimationFrame(()=>{ne.scrollTop=q.current})}),()=>{Se!==null&&cancelAnimationFrame(Se),ft!==null&&cancelAnimationFrame(ft)}},[G]);const rt=async ne=>{try{E(ne),await R(ne),a==null||a(ne),l==null||l(ne)}catch(Se){console.error("Failed to select thread:",Se)}},_t=async()=>{try{re(!0);const ne=await N();ne&&(c==null||c(ne),a==null||a(ne))}catch(ne){console.error("Failed to create thread:",ne)}finally{re(!1)}},pn=async(ne,Se)=>{if(Se.stopPropagation(),!!confirm("Delete this thread?")){if(M.current){const ft=M.current.querySelector("[data-radix-scroll-area-viewport]");ft&&(q.current=ft.scrollTop)}try{await W(ne),d==null||d(ne)}catch(ft){console.error("Failed to delete thread:",ft)}}},Le=(ne,Se)=>{Se.stopPropagation(),se(ne.threadId),D(ne.title||`Thread ${ne.threadId.slice(0,8)}`)},qe=async ne=>{if(B.trim())try{await I(ne,B.trim()),se(null),D("")}catch(Se){console.error("Failed to update title:",Se)}},Dt=()=>{se(null),D("")},Pt=ne=>{if(!ne)return"";try{const Se=new Date(ne),Ce=new Date().getTime()-Se.getTime(),Me=Math.floor(Ce/(1e3*60*60*24));return Me===0?Se.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Me===1?"Yesterday":Me<7?`${Me} days ago`:Se.toLocaleDateString()}catch{return""}},wt=ne=>ne.title||`Thread ${ne.threadId.slice(0,8)}`,kt=ne=>{const Se=wt(ne);return Se.length<=tm?Se:`${Se.slice(0,tm)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[x&&u.jsxs("div",{className:s.header||"flex flex-col gap-2 px-1 py-0 border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900 shadow-sm",children:[t&&u.jsx("div",{className:"flex justify-end",children:u.jsxs(it,{onClick:_t,disabled:X||j,className:s.createButton||"px-3 py-2 gap-1",size:"sm",variant:"ghost",title:X?"Creating...":"New Chat",children:[u.jsx(ue.Edit3,{size:16}),u.jsx("span",{children:"New chat"})]})}),u.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-slate-700 dark:text-slate-200 uppercase tracking-wide leading-tight",children:[u.jsx("span",{children:"Current View"}),u.jsxs(vs,{children:[u.jsx(ws,{asChild:!0,children:u.jsx(it,{variant:"outline",size:"sm",className:"text-[11px] text-slate-700 dark:text-slate-200 border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 px-2 py-0",children:Ke.label})}),u.jsx(ao,{align:"start",sideOffset:6,className:"w-40",children:_e.map(ne=>u.jsxs(On,{className:"justify-between text-[12px]",onClick:Se=>{Se.preventDefault(),Fe(ne.key)},children:[u.jsx("span",{children:ne.label}),Ee===ne.key&&u.jsx(ue.Check,{className:"h-3 w-3"})]},ne.key))})]})]})]}),u.jsx(Il,{ref:M,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:gt?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ue.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):vt.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(ue.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:ut})]}):vt.slice().sort((ne,Se)=>new Date(Se.updatedAt||Se.createdAt||"").getTime()-new Date(ne.updatedAt||ne.createdAt||"").getTime()).map(ne=>u.jsx(em,{thread:ne,isActive:_===ne.threadId,editingThreadId:Y,editingTitle:B,onSelect:rt,onStartEditing:Le,onEditingTitleChange:Se=>D(Se),onSaveEditing:qe,onCancelEditing:Dt,onShare:()=>Ue(ne.threadId),onDelete:pn,showEditTitle:r,showDeleteButton:n,formatDate:Pt,getDisplayThreadTitle:kt,secondaryLine:Ze&&tt(ne)?ye(ne):void 0,itemClassName:s.threadItem,activeItemClassName:s.activeThread},ne.threadId))})}),u.jsx(Ya,{open:ae,onOpenChange:ne=>!ne&&Ye(),children:u.jsxs(Ds,{className:"max-w-md p-0",children:[u.jsx(Ls,{children:u.jsx($s,{children:"Share thread"})}),u.jsxs(gl,{children:[u.jsx(xl,{autoFocus:!0,value:ce,onValueChange:ne=>xe(ne),placeholder:"Search for recipients..."}),u.jsxs(vl,{children:[K&&u.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[U&&u.jsx(ue.Loader2,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{className:K.startsWith("Failed")?"text-red-500":K.startsWith("Shared")?"text-emerald-500":"text-slate-600 dark:text-slate-400",children:K})]}),u.jsx(wl,{children:w?u.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading recipients…"]}):"No matching recipients found"}),et.length>0&&u.jsx(bl,{heading:"Recipients",children:et.map(ne=>u.jsx(yl,{onSelect:()=>nt(ne),children:u.jsxs("div",{className:"flex flex-col items-start text-sm",children:[u.jsx("span",{className:"font-medium",children:ne.label}),ne.secondaryLabel&&u.jsx("span",{className:"text-xs text-muted-foreground",children:ne.secondaryLabel})]})},ne.id))})]})]})]})})]})}function pk({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Xr,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(So,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Xr,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Al,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(So,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Xr,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Al,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(So,{onError:s.onError,enableFileUpload:!0})})]})})}function hk({apiConfig:e,className:t="",onError:n}){return u.jsx(Xr,{apiConfig:e,onError:n,children:u.jsx("div",{className:`h-full ${t}`,children:u.jsx(So,{})})})}var mk="Label",om=h.forwardRef((e,t)=>u.jsx(ve.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));om.displayName=mk;var sm=om;const gk=Dr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),im=h.forwardRef(({className:e,...t},n)=>u.jsx(sm,{ref:n,className:te(gk(),e),...t}));im.displayName=sm.displayName;function am(e){const t=h.useRef({value:e,previous:e});return h.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var lm=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),xk="VisuallyHidden",Js=h.forwardRef((e,t)=>u.jsx(ve.span,{...e,ref:t,style:{...lm,...e.style}}));Js.displayName=xk;var vk=Js,wk=[" ","Enter","ArrowUp","ArrowDown"],bk=[" ","Enter"],ir="Select",[Zs,Qs,yk]=Vo(ir),[Rr,c1]=on(ir,[yk,yr]),ei=yr(),[Sk,Un]=Rr(ir),[Ck,Tk]=Rr(ir),cm=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:p,disabled:m,required:f,form:v}=e,g=ei(t),[x,y]=h.useState(null),[w,S]=h.useState(null),[k,C]=h.useState(!1),T=Ko(c),[E,j]=_n({prop:r,defaultProp:o??!1,onChange:s,caller:ir}),[O,L]=_n({prop:i,defaultProp:a,onChange:l,caller:ir}),U=h.useRef(null),K=x?v||!!x.closest("form"):!0,[V,N]=h.useState(new Set),W=Array.from(V).map(I=>I.props.value).join(";");return u.jsx(ea,{...g,children:u.jsxs(Sk,{required:f,scope:t,trigger:x,onTriggerChange:y,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:It(),value:O,onValueChange:L,open:E,onOpenChange:j,dir:T,triggerPointerDownPosRef:U,disabled:m,children:[u.jsx(Zs.Provider,{scope:t,children:u.jsx(Ck,{scope:e.__scopeSelect,onNativeOptionAdd:h.useCallback(I=>{N(F=>new Set(F).add(I))},[]),onNativeOptionRemove:h.useCallback(I=>{N(F=>{const R=new Set(F);return R.delete(I),R})},[]),children:n})}),K?u.jsxs(Rm,{"aria-hidden":!0,required:f,tabIndex:-1,name:d,autoComplete:p,value:O,onChange:I=>L(I.target.value),disabled:m,form:v,children:[O===void 0?u.jsx("option",{value:""}):null,Array.from(V)]},W):null]})})};cm.displayName=ir;var um="SelectTrigger",dm=h.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ei(n),i=Un(um,n),a=i.disabled||r,l=Oe(t,i.onTriggerChange),c=Qs(n),d=h.useRef("touch"),[p,m,f]=Om(g=>{const x=c().filter(S=>!S.disabled),y=x.find(S=>S.value===i.value),w=Dm(x,g,y);w!==void 0&&i.onValueChange(w.value)}),v=g=>{a||(i.onOpenChange(!0),f()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ta,{asChild:!0,...s,children:u.jsx(ve.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":Mm(i.value)?"":void 0,...o,ref:l,onClick:ie(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&v(g)}),onPointerDown:ie(o.onPointerDown,g=>{d.current=g.pointerType;const x=g.target;x.hasPointerCapture(g.pointerId)&&x.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(v(g),g.preventDefault())}),onKeyDown:ie(o.onKeyDown,g=>{const x=p.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&m(g.key),!(x&&g.key===" ")&&wk.includes(g.key)&&(v(),g.preventDefault())})})})});dm.displayName=um;var fm="SelectValue",pm=h.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Un(fm,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,p=Oe(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(ve.span,{...a,ref:p,style:{pointerEvents:"none"},children:Mm(l.value)?u.jsx(u.Fragment,{children:i}):s})});pm.displayName=fm;var kk="SelectIcon",hm=h.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(ve.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});hm.displayName=kk;var Ek="SelectPortal",mm=e=>u.jsx(eo,{asChild:!0,...e});mm.displayName=Ek;var ar="SelectContent",gm=h.forwardRef((e,t)=>{const n=Un(ar,e.__scopeSelect),[r,o]=h.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Lr.createPortal(u.jsx(xm,{scope:e.__scopeSelect,children:u.jsx(Zs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(vm,{...e,ref:t})});gm.displayName=ar;var dn=10,[xm,Wn]=Rr(ar),Ik="SelectContentImpl",Nk=Vt.createSlot("SelectContent.RemoveScroll"),vm=h.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:p,collisionBoundary:m,collisionPadding:f,sticky:v,hideWhenDetached:g,avoidCollisions:x,...y}=e,w=Un(ar,n),[S,k]=h.useState(null),[C,T]=h.useState(null),E=Oe(t,B=>k(B)),[j,O]=h.useState(null),[L,U]=h.useState(null),K=Qs(n),[V,N]=h.useState(!1),W=h.useRef(!1);h.useEffect(()=>{if(S)return aa(S)},[S]),$i();const I=h.useCallback(B=>{const[D,...X]=K().map($=>$.ref.current),[re]=X.slice(-1),ae=document.activeElement;for(const $ of B)if($===ae||($==null||$.scrollIntoView({block:"nearest"}),$===D&&C&&(C.scrollTop=0),$===re&&C&&(C.scrollTop=C.scrollHeight),$==null||$.focus(),document.activeElement!==ae))return},[K,C]),F=h.useCallback(()=>I([j,S]),[I,j,S]);h.useEffect(()=>{V&&F()},[V,F]);const{onOpenChange:R,triggerPointerDownPosRef:_}=w;h.useEffect(()=>{if(S){let B={x:0,y:0};const D=re=>{var ae,$;B={x:Math.abs(Math.round(re.pageX)-(((ae=_.current)==null?void 0:ae.x)??0)),y:Math.abs(Math.round(re.pageY)-((($=_.current)==null?void 0:$.y)??0))}},X=re=>{B.x<=10&&B.y<=10?re.preventDefault():S.contains(re.target)||R(!1),document.removeEventListener("pointermove",D),_.current=null};return _.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",X,{capture:!0})}}},[S,R,_]),h.useEffect(()=>{const B=()=>R(!1);return window.addEventListener("blur",B),window.addEventListener("resize",B),()=>{window.removeEventListener("blur",B),window.removeEventListener("resize",B)}},[R]);const[G,J]=Om(B=>{const D=K().filter(ae=>!ae.disabled),X=D.find(ae=>ae.ref.current===document.activeElement),re=Dm(D,B,X);re&&setTimeout(()=>re.ref.current.focus())}),P=h.useCallback((B,D,X)=>{const re=!W.current&&!X;(w.value!==void 0&&w.value===D||re)&&(O(B),re&&(W.current=!0))},[w.value]),M=h.useCallback(()=>S==null?void 0:S.focus(),[S]),q=h.useCallback((B,D,X)=>{const re=!W.current&&!X;(w.value!==void 0&&w.value===D||re)&&U(B)},[w.value]),Y=r==="popper"?jl:wm,se=Y===jl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:p,collisionBoundary:m,collisionPadding:f,sticky:v,hideWhenDetached:g,avoidCollisions:x}:{};return u.jsx(xm,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:P,selectedItem:j,onItemLeave:M,itemTextRefCallback:q,focusSelectedItem:F,selectedItemText:L,position:r,isPositioned:V,searchRef:G,children:u.jsx(fs,{as:Nk,allowPinchZoom:!0,children:u.jsx(qo,{asChild:!0,trapped:w.open,onMountAutoFocus:B=>{B.preventDefault()},onUnmountAutoFocus:ie(o,B=>{var D;(D=w.trigger)==null||D.focus({preventScroll:!0}),B.preventDefault()}),children:u.jsx(gr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:B=>B.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:B=>B.preventDefault(),...y,...se,onPlaced:()=>N(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...y.style},onKeyDown:ie(y.onKeyDown,B=>{const D=B.ctrlKey||B.altKey||B.metaKey;if(B.key==="Tab"&&B.preventDefault(),!D&&B.key.length===1&&J(B.key),["ArrowUp","ArrowDown","Home","End"].includes(B.key)){let re=K().filter(ae=>!ae.disabled).map(ae=>ae.ref.current);if(["ArrowUp","End"].includes(B.key)&&(re=re.slice().reverse()),["ArrowUp","ArrowDown"].includes(B.key)){const ae=B.target,$=re.indexOf(ae);re=re.slice($+1)}setTimeout(()=>I(re)),B.preventDefault()}})})})})})})});vm.displayName=Ik;var Ak="SelectItemAlignedPosition",wm=h.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Un(ar,n),i=Wn(ar,n),[a,l]=h.useState(null),[c,d]=h.useState(null),p=Oe(t,E=>d(E)),m=Qs(n),f=h.useRef(!1),v=h.useRef(!0),{viewport:g,selectedItem:x,selectedItemText:y,focusSelectedItem:w}=i,S=h.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&x&&y){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),O=s.valueNode.getBoundingClientRect(),L=y.getBoundingClientRect();if(s.dir!=="rtl"){const ae=L.left-j.left,$=O.left-ae,Z=E.left-$,de=E.width+Z,ce=Math.max(de,j.width),xe=window.innerWidth-dn,_e=Sl($,[dn,Math.max(dn,xe-ce)]);a.style.minWidth=de+"px",a.style.left=_e+"px"}else{const ae=j.right-L.right,$=window.innerWidth-O.right-ae,Z=window.innerWidth-E.right-$,de=E.width+Z,ce=Math.max(de,j.width),xe=window.innerWidth-dn,_e=Sl($,[dn,Math.max(dn,xe-ce)]);a.style.minWidth=de+"px",a.style.right=_e+"px"}const U=m(),K=window.innerHeight-dn*2,V=g.scrollHeight,N=window.getComputedStyle(c),W=parseInt(N.borderTopWidth,10),I=parseInt(N.paddingTop,10),F=parseInt(N.borderBottomWidth,10),R=parseInt(N.paddingBottom,10),_=W+I+V+R+F,G=Math.min(x.offsetHeight*5,_),J=window.getComputedStyle(g),P=parseInt(J.paddingTop,10),M=parseInt(J.paddingBottom,10),q=E.top+E.height/2-dn,Y=K-q,se=x.offsetHeight/2,B=x.offsetTop+se,D=W+I+B,X=_-D;if(D<=q){const ae=U.length>0&&x===U[U.length-1].ref.current;a.style.bottom="0px";const $=c.clientHeight-g.offsetTop-g.offsetHeight,Z=Math.max(Y,se+(ae?M:0)+$+F),de=D+Z;a.style.height=de+"px"}else{const ae=U.length>0&&x===U[0].ref.current;a.style.top="0px";const Z=Math.max(q,W+g.offsetTop+(ae?P:0)+se)+X;a.style.height=Z+"px",g.scrollTop=D-q+g.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=G+"px",a.style.maxHeight=K+"px",r==null||r(),requestAnimationFrame(()=>f.current=!0)}},[m,s.trigger,s.valueNode,a,c,g,x,y,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=h.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=h.useCallback(E=>{E&&v.current===!0&&(S(),w==null||w(),v.current=!1)},[S,w]);return u.jsx(_k,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:f,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(ve.div,{...o,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});wm.displayName=Ak;var jk="SelectPopperPosition",jl=h.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=ei(n);return u.jsx(na,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});jl.displayName=jk;var[_k,_l]=Rr(ar,{}),Pl="SelectViewport",bm=h.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Wn(Pl,n),i=_l(Pl,n),a=Oe(t,s.onViewportChange),l=h.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Zs.Slot,{scope:n,children:u.jsx(ve.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ie(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:m}=i;if(m!=null&&m.current&&p){const f=Math.abs(l.current-d.scrollTop);if(f>0){const v=window.innerHeight-dn*2,g=parseFloat(p.style.minHeight),x=parseFloat(p.style.height),y=Math.max(g,x);if(y<v){const w=y+f,S=Math.min(v,w),k=w-S;p.style.height=S+"px",p.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,p.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});bm.displayName=Pl;var ym="SelectGroup",[Pk,Rk]=Rr(ym),Mk=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=It();return u.jsx(Pk,{scope:n,id:o,children:u.jsx(ve.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Mk.displayName=ym;var Sm="SelectLabel",Cm=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Rk(Sm,n);return u.jsx(ve.div,{id:o.id,...r,ref:t})});Cm.displayName=Sm;var ti="SelectItem",[Ok,Tm]=Rr(ti),km=h.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Un(ti,n),l=Wn(ti,n),c=a.value===r,[d,p]=h.useState(s??""),[m,f]=h.useState(!1),v=Oe(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),g=It(),x=h.useRef("touch"),y=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(Ok,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:h.useCallback(w=>{p(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(Zs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(ve.div,{role:"option","aria-labelledby":g,"data-highlighted":m?"":void 0,"aria-selected":c&&m,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:ie(i.onFocus,()=>f(!0)),onBlur:ie(i.onBlur,()=>f(!1)),onClick:ie(i.onClick,()=>{x.current!=="mouse"&&y()}),onPointerUp:ie(i.onPointerUp,()=>{x.current==="mouse"&&y()}),onPointerDown:ie(i.onPointerDown,w=>{x.current=w.pointerType}),onPointerMove:ie(i.onPointerMove,w=>{var S;x.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):x.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ie(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ie(i.onKeyDown,w=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&w.key===" "||(bk.includes(w.key)&&y(),w.key===" "&&w.preventDefault())})})})})});km.displayName=ti;var ko="SelectItemText",Em=h.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Un(ko,n),a=Wn(ko,n),l=Tm(ko,n),c=Tk(ko,n),[d,p]=h.useState(null),m=Oe(t,y=>p(y),l.onItemTextChange,y=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,y,l.value,l.disabled)}),f=d==null?void 0:d.textContent,v=h.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:f},l.value),[l.disabled,l.value,f]),{onNativeOptionAdd:g,onNativeOptionRemove:x}=c;return Tt(()=>(g(v),()=>x(v)),[g,x,v]),u.jsxs(u.Fragment,{children:[u.jsx(ve.span,{id:l.textId,...s,ref:m}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Lr.createPortal(s.children,i.valueNode):null]})});Em.displayName=ko;var Im="SelectItemIndicator",Nm=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Tm(Im,n).isSelected?u.jsx(ve.span,{"aria-hidden":!0,...r,ref:t}):null});Nm.displayName=Im;var Rl="SelectScrollUpButton",Am=h.forwardRef((e,t)=>{const n=Wn(Rl,e.__scopeSelect),r=_l(Rl,e.__scopeSelect),[o,s]=h.useState(!1),i=Oe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(_m,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Am.displayName=Rl;var Ml="SelectScrollDownButton",jm=h.forwardRef((e,t)=>{const n=Wn(Ml,e.__scopeSelect),r=_l(Ml,e.__scopeSelect),[o,s]=h.useState(!1),i=Oe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(_m,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});jm.displayName=Ml;var _m=h.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Wn("SelectScrollButton",n),i=h.useRef(null),a=Qs(n),l=h.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return h.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(p=>p.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(ve.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ie(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ie(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ie(o.onPointerLeave,()=>{l()})})}),Dk="SelectSeparator",Pm=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(ve.div,{"aria-hidden":!0,...r,ref:t})});Pm.displayName=Dk;var Ol="SelectArrow",Lk=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ei(n),s=Un(Ol,n),i=Wn(Ol,n);return s.open&&i.position==="popper"?u.jsx(ra,{...o,...r,ref:t}):null});Lk.displayName=Ol;var $k="SelectBubbleInput",Rm=h.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=h.useRef(null),s=Oe(r,o),i=am(t);return h.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const p=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(p)}},[i,t]),u.jsx(ve.select,{...n,style:{...lm,...n.style},ref:s,defaultValue:t})});Rm.displayName=$k;function Mm(e){return e===""||e===void 0}function Om(e){const t=ht(e),n=h.useRef(""),r=h.useRef(0),o=h.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=h.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return h.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Dm(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Fk(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Fk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Bk=cm,Lm=dm,zk=pm,Hk=hm,Uk=mm,$m=gm,Wk=bm,Fm=Cm,Bm=km,Vk=Em,Kk=Nm,zm=Am,Hm=jm,Um=Pm;const qk=Bk,Gk=zk,Wm=h.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Lm,{ref:r,className:te("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(Hk,{asChild:!0,children:u.jsx(ue.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wm.displayName=Lm.displayName;const Vm=h.forwardRef(({className:e,...t},n)=>u.jsx(zm,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ue.ChevronUp,{className:"h-4 w-4"})}));Vm.displayName=zm.displayName;const Km=h.forwardRef(({className:e,...t},n)=>u.jsx(Hm,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ue.ChevronDown,{className:"h-4 w-4"})}));Km.displayName=Hm.displayName;const qm=h.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Uk,{children:u.jsxs($m,{ref:o,className:te("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Vm,{}),u.jsx(Wk,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Km,{})]})}));qm.displayName=$m.displayName;const Yk=h.forwardRef(({className:e,...t},n)=>u.jsx(Fm,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Yk.displayName=Fm.displayName;const Gm=h.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Bm,{ref:r,className:te("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Kk,{children:u.jsx(ue.Check,{className:"h-4 w-4"})})}),u.jsx(Vk,{children:t})]}));Gm.displayName=Bm.displayName;const Xk=h.forwardRef(({className:e,...t},n)=>u.jsx(Um,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));Xk.displayName=Um.displayName;var Jk="Separator",Ym="horizontal",Zk=["horizontal","vertical"],Xm=h.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ym,...o}=e,s=Qk(r)?r:Ym,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(ve.div,{"data-orientation":s,...a,...o,ref:t})});Xm.displayName=Jk;function Qk(e){return Zk.includes(e)}var Jm=Xm;const Zm=h.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Jm,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Zm.displayName=Jm.displayName;var ni="Switch",[eE,u1]=on(ni),[tE,nE]=eE(ni),Qm=h.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...p}=e,[m,f]=h.useState(null),v=Oe(t,S=>f(S)),g=h.useRef(!1),x=m?d||!!m.closest("form"):!0,[y,w]=_n({prop:o,defaultProp:s??!1,onChange:c,caller:ni});return u.jsxs(tE,{scope:n,checked:y,disabled:a,children:[u.jsx(ve.button,{type:"button",role:"switch","aria-checked":y,"aria-required":i,"data-state":rg(y),"data-disabled":a?"":void 0,disabled:a,value:l,...p,ref:v,onClick:ie(e.onClick,S=>{w(k=>!k),x&&(g.current=S.isPropagationStopped(),g.current||S.stopPropagation())})}),x&&u.jsx(ng,{control:m,bubbles:!g.current,name:r,value:l,checked:y,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Qm.displayName=ni;var eg="SwitchThumb",tg=h.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=nE(eg,n);return u.jsx(ve.span,{"data-state":rg(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});tg.displayName=eg;var rE="SwitchBubbleInput",ng=h.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=h.useRef(null),a=Oe(i,s),l=am(n),c=fd(t);return h.useEffect(()=>{const d=i.current;if(!d)return;const p=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(p,"checked").set;if(l!==n&&f){const v=new Event("click",{bubbles:r});f.call(d,n),d.dispatchEvent(v)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});ng.displayName=rE;function rg(e){return e?"checked":"unchecked"}var og=Qm,oE=tg;const sg=h.forwardRef(({className:e,...t},n)=>u.jsx(og,{className:te("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(oE,{className:te("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));sg.displayName=og.displayName;const sE=qa,iE=XC,aE=Ga,ig=h.forwardRef(({className:e,...t},n)=>u.jsx(wo,{className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));ig.displayName=wo.displayName;const lE=Dr.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),ag=h.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(aE,{children:[u.jsx(ig,{}),u.jsxs(bo,{ref:o,className:te(lE({side:e}),t),...r,children:[n,u.jsxs(Zp,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(ue.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ag.displayName=bo.displayName;const lg=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});lg.displayName="SheetHeader";const cg=h.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));cg.displayName=rr.displayName;const ug=h.forwardRef(({className:e,...t},n)=>u.jsx(Os,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));ug.displayName=Os.displayName;var[ri,d1]=on("Tooltip",[yr]),oi=yr(),dg="TooltipProvider",cE=700,Dl="tooltip.open",[uE,Ll]=ri(dg),fg=e=>{const{__scopeTooltip:t,delayDuration:n=cE,skipDelayDuration:r=300,disableHoverableContent:o=!1,children:s}=e,i=h.useRef(!0),a=h.useRef(!1),l=h.useRef(0);return h.useEffect(()=>{const c=l.current;return()=>window.clearTimeout(c)},[]),u.jsx(uE,{scope:t,isOpenDelayedRef:i,delayDuration:n,onOpen:h.useCallback(()=>{window.clearTimeout(l.current),i.current=!1},[]),onClose:h.useCallback(()=>{window.clearTimeout(l.current),l.current=window.setTimeout(()=>i.current=!0,r)},[r]),isPointerInTransitRef:a,onPointerInTransitChange:h.useCallback(c=>{a.current=c},[]),disableHoverableContent:o,children:s})};fg.displayName=dg;var Eo="Tooltip",[dE,si]=ri(Eo),pg=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:o,onOpenChange:s,disableHoverableContent:i,delayDuration:a}=e,l=Ll(Eo,e.__scopeTooltip),c=oi(t),[d,p]=h.useState(null),m=It(),f=h.useRef(0),v=i??l.disableHoverableContent,g=a??l.delayDuration,x=h.useRef(!1),[y,w]=_n({prop:r,defaultProp:o??!1,onChange:E=>{E?(l.onOpen(),document.dispatchEvent(new CustomEvent(Dl))):l.onClose(),s==null||s(E)},caller:Eo}),S=h.useMemo(()=>y?x.current?"delayed-open":"instant-open":"closed",[y]),k=h.useCallback(()=>{window.clearTimeout(f.current),f.current=0,x.current=!1,w(!0)},[w]),C=h.useCallback(()=>{window.clearTimeout(f.current),f.current=0,w(!1)},[w]),T=h.useCallback(()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>{x.current=!0,w(!0),f.current=0},g)},[g,w]);return h.useEffect(()=>()=>{f.current&&(window.clearTimeout(f.current),f.current=0)},[]),u.jsx(ea,{...c,children:u.jsx(dE,{scope:t,contentId:m,open:y,stateAttribute:S,trigger:d,onTriggerChange:p,onTriggerEnter:h.useCallback(()=>{l.isOpenDelayedRef.current?T():k()},[l.isOpenDelayedRef,T,k]),onTriggerLeave:h.useCallback(()=>{v?C():(window.clearTimeout(f.current),f.current=0)},[C,v]),onOpen:k,onClose:C,disableHoverableContent:v,children:n})})};pg.displayName=Eo;var $l="TooltipTrigger",hg=h.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,o=si($l,n),s=Ll($l,n),i=oi(n),a=h.useRef(null),l=Oe(t,a,o.onTriggerChange),c=h.useRef(!1),d=h.useRef(!1),p=h.useCallback(()=>c.current=!1,[]);return h.useEffect(()=>()=>document.removeEventListener("pointerup",p),[p]),u.jsx(ta,{asChild:!0,...i,children:u.jsx(ve.button,{"aria-describedby":o.open?o.contentId:void 0,"data-state":o.stateAttribute,...r,ref:l,onPointerMove:ie(e.onPointerMove,m=>{m.pointerType!=="touch"&&!d.current&&!s.isPointerInTransitRef.current&&(o.onTriggerEnter(),d.current=!0)}),onPointerLeave:ie(e.onPointerLeave,()=>{o.onTriggerLeave(),d.current=!1}),onPointerDown:ie(e.onPointerDown,()=>{o.open&&o.onClose(),c.current=!0,document.addEventListener("pointerup",p,{once:!0})}),onFocus:ie(e.onFocus,()=>{c.current||o.onOpen()}),onBlur:ie(e.onBlur,o.onClose),onClick:ie(e.onClick,o.onClose)})})});hg.displayName=$l;var fE="TooltipPortal",[f1,pE]=ri(fE,{forceMount:void 0}),Mr="TooltipContent",mg=h.forwardRef((e,t)=>{const n=pE(Mr,e.__scopeTooltip),{forceMount:r=n.forceMount,side:o="top",...s}=e,i=si(Mr,e.__scopeTooltip);return u.jsx(Ft,{present:r||i.open,children:i.disableHoverableContent?u.jsx(gg,{side:o,...s,ref:t}):u.jsx(hE,{side:o,...s,ref:t})})}),hE=h.forwardRef((e,t)=>{const n=si(Mr,e.__scopeTooltip),r=Ll(Mr,e.__scopeTooltip),o=h.useRef(null),s=Oe(t,o),[i,a]=h.useState(null),{trigger:l,onClose:c}=n,d=o.current,{onPointerInTransitChange:p}=r,m=h.useCallback(()=>{a(null),p(!1)},[p]),f=h.useCallback((v,g)=>{const x=v.currentTarget,y={x:v.clientX,y:v.clientY},w=wE(y,x.getBoundingClientRect()),S=bE(y,w),k=yE(g.getBoundingClientRect()),C=CE([...S,...k]);a(C),p(!0)},[p]);return h.useEffect(()=>()=>m(),[m]),h.useEffect(()=>{if(l&&d){const v=x=>f(x,d),g=x=>f(x,l);return l.addEventListener("pointerleave",v),d.addEventListener("pointerleave",g),()=>{l.removeEventListener("pointerleave",v),d.removeEventListener("pointerleave",g)}}},[l,d,f,m]),h.useEffect(()=>{if(i){const v=g=>{const x=g.target,y={x:g.clientX,y:g.clientY},w=(l==null?void 0:l.contains(x))||(d==null?void 0:d.contains(x)),S=!SE(y,i);w?m():S&&(m(),c())};return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[l,d,i,c,m]),u.jsx(gg,{...e,ref:s})}),[mE,gE]=ri(Eo,{isInside:!1}),xE=Vt.createSlottable("TooltipContent"),gg=h.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":o,onEscapeKeyDown:s,onPointerDownOutside:i,...a}=e,l=si(Mr,n),c=oi(n),{onClose:d}=l;return h.useEffect(()=>(document.addEventListener(Dl,d),()=>document.removeEventListener(Dl,d)),[d]),h.useEffect(()=>{if(l.trigger){const p=m=>{const f=m.target;f!=null&&f.contains(l.trigger)&&d()};return window.addEventListener("scroll",p,{capture:!0}),()=>window.removeEventListener("scroll",p,{capture:!0})}},[l.trigger,d]),u.jsx(gr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:p=>p.preventDefault(),onDismiss:d,children:u.jsxs(na,{"data-state":l.stateAttribute,...c,...a,ref:t,style:{...a.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[u.jsx(xE,{children:r}),u.jsx(mE,{scope:n,isInside:!0,children:u.jsx(vk,{id:l.contentId,role:"tooltip",children:o||r})})]})})});mg.displayName=Mr;var xg="TooltipArrow",vE=h.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,o=oi(n);return gE(xg,n).isInside?null:u.jsx(ra,{...o,...r,ref:t})});vE.displayName=xg;function wE(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),o=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,o,s)){case s:return"left";case o:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function bE(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function yE(e){const{top:t,right:n,bottom:r,left:o}=e;return[{x:o,y:t},{x:n,y:t},{x:n,y:r},{x:o,y:r}]}function SE(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,p=l.x,m=l.y;d>r!=m>r&&n<(p-c)*(r-d)/(m-d)+c&&(o=!o)}return o}function CE(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),TE(t)}function TE(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const o=e[r];for(;t.length>=2;){const s=t[t.length-1],i=t[t.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))t.pop();else break}t.push(o)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const o=e[r];for(;n.length>=2;){const s=n[n.length-1],i=n[n.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))n.pop();else break}n.push(o)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var kE=fg,EE=pg,IE=hg,vg=mg;const NE=kE,AE=EE,jE=IE,wg=h.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(vg,{ref:r,sideOffset:t,className:te("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n}));wg.displayName=vg.displayName;var Fl="ToastProvider",[Bl,_E,PE]=Vo("Toast"),[bg,p1]=on("Toast",[PE]),[RE,ii]=bg(Fl),yg=e=>{const{__scopeToast:t,label:n="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,l]=h.useState(null),[c,d]=h.useState(0),p=h.useRef(!1),m=h.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${Fl}\`. Expected non-empty \`string\`.`),u.jsx(Bl.Provider,{scope:t,children:u.jsx(RE,{scope:t,label:n,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:h.useCallback(()=>d(f=>f+1),[]),onToastRemove:h.useCallback(()=>d(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:p,isClosePausedRef:m,children:i})})};yg.displayName=Fl;var Sg="ToastViewport",ME=["F8"],zl="toast.viewportPause",Hl="toast.viewportResume",Cg=h.forwardRef((e,t)=>{const{__scopeToast:n,hotkey:r=ME,label:o="Notifications ({hotkey})",...s}=e,i=ii(Sg,n),a=_E(n),l=h.useRef(null),c=h.useRef(null),d=h.useRef(null),p=h.useRef(null),m=Oe(t,p,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=i.toastCount>0;h.useEffect(()=>{const x=y=>{var S;r.length!==0&&r.every(k=>y[k]||y.code===k)&&((S=p.current)==null||S.focus())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[r]),h.useEffect(()=>{const x=l.current,y=p.current;if(v&&x&&y){const w=()=>{if(!i.isClosePausedRef.current){const T=new CustomEvent(zl);y.dispatchEvent(T),i.isClosePausedRef.current=!0}},S=()=>{if(i.isClosePausedRef.current){const T=new CustomEvent(Hl);y.dispatchEvent(T),i.isClosePausedRef.current=!1}},k=T=>{!x.contains(T.relatedTarget)&&S()},C=()=>{x.contains(document.activeElement)||S()};return x.addEventListener("focusin",w),x.addEventListener("focusout",k),x.addEventListener("pointermove",w),x.addEventListener("pointerleave",C),window.addEventListener("blur",w),window.addEventListener("focus",S),()=>{x.removeEventListener("focusin",w),x.removeEventListener("focusout",k),x.removeEventListener("pointermove",w),x.removeEventListener("pointerleave",C),window.removeEventListener("blur",w),window.removeEventListener("focus",S)}}},[v,i.isClosePausedRef]);const g=h.useCallback(({tabbingDirection:x})=>{const w=a().map(S=>{const k=S.ref.current,C=[k,...qE(k)];return x==="forwards"?C:C.reverse()});return(x==="forwards"?w.reverse():w).flat()},[a]);return h.useEffect(()=>{const x=p.current;if(x){const y=w=>{var C,T,E;const S=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!S){const j=document.activeElement,O=w.shiftKey;if(w.target===x&&O){(C=c.current)==null||C.focus();return}const K=g({tabbingDirection:O?"backwards":"forwards"}),V=K.findIndex(N=>N===j);Vl(K.slice(V+1))?w.preventDefault():O?(T=c.current)==null||T.focus():(E=d.current)==null||E.focus()}};return x.addEventListener("keydown",y),()=>x.removeEventListener("keydown",y)}},[a,g]),u.jsxs(Tw,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:v?void 0:"none"},children:[v&&u.jsx(Ul,{ref:c,onFocusFromOutsideViewport:()=>{const x=g({tabbingDirection:"forwards"});Vl(x)}}),u.jsx(Bl.Slot,{scope:n,children:u.jsx(ve.ol,{tabIndex:-1,...s,ref:m})}),v&&u.jsx(Ul,{ref:d,onFocusFromOutsideViewport:()=>{const x=g({tabbingDirection:"backwards"});Vl(x)}})]})});Cg.displayName=Sg;var Tg="ToastFocusProxy",Ul=h.forwardRef((e,t)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=e,s=ii(Tg,n);return u.jsx(Js,{tabIndex:0,...o,ref:t,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=s.viewport)!=null&&c.contains(a))&&r()}})});Ul.displayName=Tg;var Io="Toast",OE="toast.swipeStart",DE="toast.swipeMove",LE="toast.swipeCancel",$E="toast.swipeEnd",kg=h.forwardRef((e,t)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a,l]=_n({prop:r,defaultProp:o??!0,onChange:s,caller:Io});return u.jsx(Ft,{present:n||a,children:u.jsx(zE,{open:a,...i,ref:t,onClose:()=>l(!1),onPause:ht(e.onPause),onResume:ht(e.onResume),onSwipeStart:ie(e.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:ie(e.onSwipeMove,c=>{const{x:d,y:p}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${p}px`)}),onSwipeCancel:ie(e.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:ie(e.onSwipeEnd,c=>{const{x:d,y:p}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${p}px`),l(!1)})})})});kg.displayName=Io;var[FE,BE]=bg(Io,{onClose(){}}),zE=h.forwardRef((e,t)=>{const{__scopeToast:n,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:d,onSwipeMove:p,onSwipeCancel:m,onSwipeEnd:f,...v}=e,g=ii(Io,n),[x,y]=h.useState(null),w=Oe(t,N=>y(N)),S=h.useRef(null),k=h.useRef(null),C=o||g.duration,T=h.useRef(0),E=h.useRef(C),j=h.useRef(0),{onToastAdd:O,onToastRemove:L}=g,U=ht(()=>{var W;(x==null?void 0:x.contains(document.activeElement))&&((W=g.viewport)==null||W.focus()),i()}),K=h.useCallback(N=>{!N||N===1/0||(window.clearTimeout(j.current),T.current=new Date().getTime(),j.current=window.setTimeout(U,N))},[U]);h.useEffect(()=>{const N=g.viewport;if(N){const W=()=>{K(E.current),c==null||c()},I=()=>{const F=new Date().getTime()-T.current;E.current=E.current-F,window.clearTimeout(j.current),l==null||l()};return N.addEventListener(zl,I),N.addEventListener(Hl,W),()=>{N.removeEventListener(zl,I),N.removeEventListener(Hl,W)}}},[g.viewport,C,l,c,K]),h.useEffect(()=>{s&&!g.isClosePausedRef.current&&K(C)},[s,C,g.isClosePausedRef,K]),h.useEffect(()=>(O(),()=>L()),[O,L]);const V=h.useMemo(()=>x?Pg(x):null,[x]);return g.viewport?u.jsxs(u.Fragment,{children:[V&&u.jsx(HE,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite",children:V}),u.jsx(FE,{scope:n,onClose:U,children:Lr.createPortal(u.jsx(Bl.ItemSlot,{scope:n,children:u.jsx(Cw,{asChild:!0,onEscapeKeyDown:ie(a,()=>{g.isFocusedToastEscapeKeyDownRef.current||U(),g.isFocusedToastEscapeKeyDownRef.current=!1}),children:u.jsx(ve.li,{tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":g.swipeDirection,...v,ref:w,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:ie(e.onKeyDown,N=>{N.key==="Escape"&&(a==null||a(N.nativeEvent),N.nativeEvent.defaultPrevented||(g.isFocusedToastEscapeKeyDownRef.current=!0,U()))}),onPointerDown:ie(e.onPointerDown,N=>{N.button===0&&(S.current={x:N.clientX,y:N.clientY})}),onPointerMove:ie(e.onPointerMove,N=>{if(!S.current)return;const W=N.clientX-S.current.x,I=N.clientY-S.current.y,F=!!k.current,R=["left","right"].includes(g.swipeDirection),_=["left","up"].includes(g.swipeDirection)?Math.min:Math.max,G=R?_(0,W):0,J=R?0:_(0,I),P=N.pointerType==="touch"?10:2,M={x:G,y:J},q={originalEvent:N,delta:M};F?(k.current=M,ai(DE,p,q,{discrete:!1})):Rg(M,g.swipeDirection,P)?(k.current=M,ai(OE,d,q,{discrete:!1}),N.target.setPointerCapture(N.pointerId)):(Math.abs(W)>P||Math.abs(I)>P)&&(S.current=null)}),onPointerUp:ie(e.onPointerUp,N=>{const W=k.current,I=N.target;if(I.hasPointerCapture(N.pointerId)&&I.releasePointerCapture(N.pointerId),k.current=null,S.current=null,W){const F=N.currentTarget,R={originalEvent:N,delta:W};Rg(W,g.swipeDirection,g.swipeThreshold)?ai($E,f,R,{discrete:!0}):ai(LE,m,R,{discrete:!0}),F.addEventListener("click",_=>_.preventDefault(),{once:!0})}})})})}),g.viewport)})]}):null}),HE=e=>{const{__scopeToast:t,children:n,...r}=e,o=ii(Io,t),[s,i]=h.useState(!1),[a,l]=h.useState(!1);return VE(()=>i(!0)),h.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:u.jsx(eo,{asChild:!0,children:u.jsx(Js,{...r,children:s&&u.jsxs(u.Fragment,{children:[o.label," ",n]})})})},UE="ToastTitle",Eg=h.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return u.jsx(ve.div,{...r,ref:t})});Eg.displayName=UE;var WE="ToastDescription",Ig=h.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return u.jsx(ve.div,{...r,ref:t})});Ig.displayName=WE;var Ng="ToastAction",Ag=h.forwardRef((e,t)=>{const{altText:n,...r}=e;return n.trim()?u.jsx(_g,{altText:n,asChild:!0,children:u.jsx(Wl,{...r,ref:t})}):(console.error(`Invalid prop \`altText\` supplied to \`${Ng}\`. Expected non-empty \`string\`.`),null)});Ag.displayName=Ng;var jg="ToastClose",Wl=h.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e,o=BE(jg,n);return u.jsx(_g,{asChild:!0,children:u.jsx(ve.button,{type:"button",...r,ref:t,onClick:ie(e.onClick,o.onClose)})})});Wl.displayName=jg;var _g=h.forwardRef((e,t)=>{const{__scopeToast:n,altText:r,...o}=e;return u.jsx(ve.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...o,ref:t})});function Pg(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),KE(r)){const o=r.ariaHidden||r.hidden||r.style.display==="none",s=r.dataset.radixToastAnnounceExclude==="";if(!o)if(s){const i=r.dataset.radixToastAnnounceAlt;i&&t.push(i)}else t.push(...Pg(r))}}),t}function ai(e,t,n,{discrete:r}){const o=n.originalEvent.currentTarget,s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Oi(o,s):o.dispatchEvent(s)}var Rg=(e,t,n=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),s=r>o;return t==="left"||t==="right"?s&&r>n:!s&&o>n};function VE(e=()=>{}){const t=ht(e);Tt(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[t])}function KE(e){return e.nodeType===e.ELEMENT_NODE}function qE(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 Vl(e){const t=document.activeElement;return e.some(n=>n===t?!0:(n.focus(),document.activeElement!==t))}var GE=yg,Mg=Cg,Og=kg,Dg=Eg,Lg=Ig,$g=Ag,Fg=Wl;const YE=GE,Bg=h.forwardRef(({className:e,...t},n)=>u.jsx(Mg,{ref:n,className:te("fixed bottom-0 right-0 z-[100] flex max-h-screen w-full flex-col p-4 md:max-w-[420px]",e),...t}));Bg.displayName=Mg.displayName;const XE=Dr.cva("group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",{variants:{variant:{default:"border bg-background text-foreground",destructive:"destructive group border-destructive bg-destructive text-destructive-foreground"}},defaultVariants:{variant:"default"}}),zg=h.forwardRef(({className:e,variant:t,...n},r)=>u.jsx(Og,{ref:r,className:te(XE({variant:t}),e),...n}));zg.displayName=Og.displayName;const JE=h.forwardRef(({className:e,...t},n)=>u.jsx($g,{ref:n,className:te("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",e),...t}));JE.displayName=$g.displayName;const Hg=h.forwardRef(({className:e,...t},n)=>u.jsx(Fg,{ref:n,className:te("absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",e),"toast-close":"",...t,children:u.jsx(ue.X,{className:"h-4 w-4"})}));Hg.displayName=Fg.displayName;const Ug=h.forwardRef(({className:e,...t},n)=>u.jsx(Dg,{ref:n,className:te("text-sm font-semibold",e),...t}));Ug.displayName=Dg.displayName;const Wg=h.forwardRef(({className:e,...t},n)=>u.jsx(Lg,{ref:n,className:te("text-sm opacity-90",e),...t}));Wg.displayName=Lg.displayName;function ZE(){const{toasts:e}=Za();return u.jsxs(YE,{children:[e.map(function({id:t,title:n,description:r,action:o,...s}){return u.jsxs(zg,{...s,children:[u.jsxs("div",{className:"grid gap-1",children:[n&&u.jsx(Ug,{children:n}),r&&u.jsx(Wg,{children:r})]}),o,u.jsx(Hg,{})]},t)}),u.jsx(Bg,{})]})}var QE=(e,t,n,r,o,s,i,a)=>{let l=document.documentElement,c=["light","dark"];function d(f){(Array.isArray(e)?e:[e]).forEach(v=>{let g=v==="class",x=g&&s?o.map(y=>s[y]||y):o;g?(l.classList.remove(...x),l.classList.add(s&&s[f]?s[f]:f)):l.setAttribute(v,f)}),p(f)}function p(f){a&&c.includes(f)&&(l.style.colorScheme=f)}function m(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(r)d(r);else try{let f=localStorage.getItem(t)||n,v=i&&f==="system"?m():f;d(v)}catch{}},eI=h.createContext(void 0),tI={setTheme:e=>{},themes:[]},nI=()=>{var e;return(e=h.useContext(eI))!=null?e:tI};h.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:o,defaultTheme:s,value:i,themes:a,nonce:l,scriptProps:c})=>{let d=JSON.stringify([n,t,s,e,a,i,r,o]).slice(1,-1);return h.createElement("script",{...c,suppressHydrationWarning:!0,nonce:typeof window>"u"?l:"",dangerouslySetInnerHTML:{__html:`(${QE.toString()})(${d})`}})});var rI=e=>{switch(e){case"success":return iI;case"info":return lI;case"warning":return aI;case"error":return cI;default:return null}},oI=Array(12).fill(0),sI=({visible:e,className:t})=>b.createElement("div",{className:["sonner-loading-wrapper",t].filter(Boolean).join(" "),"data-visible":e},b.createElement("div",{className:"sonner-spinner"},oI.map((n,r)=>b.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${r}`})))),iI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})),aI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",clipRule:"evenodd"})),lI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})),cI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})),uI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},b.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),b.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"})),dI=()=>{let[e,t]=b.useState(document.hidden);return b.useEffect(()=>{let n=()=>{t(document.hidden)};return document.addEventListener("visibilitychange",n),()=>window.removeEventListener("visibilitychange",n)},[]),e},Kl=1,fI=class{constructor(){this.subscribe=e=>(this.subscribers.push(e),()=>{let t=this.subscribers.indexOf(e);this.subscribers.splice(t,1)}),this.publish=e=>{this.subscribers.forEach(t=>t(e))},this.addToast=e=>{this.publish(e),this.toasts=[...this.toasts,e]},this.create=e=>{var t;let{message:n,...r}=e,o=typeof(e==null?void 0:e.id)=="number"||((t=e.id)==null?void 0:t.length)>0?e.id:Kl++,s=this.toasts.find(a=>a.id===o),i=e.dismissible===void 0?!0:e.dismissible;return this.dismissedToasts.has(o)&&this.dismissedToasts.delete(o),s?this.toasts=this.toasts.map(a=>a.id===o?(this.publish({...a,...e,id:o,title:n}),{...a,...e,id:o,dismissible:i,title:n}):a):this.addToast({title:n,...r,dismissible:i,id:o}),o},this.dismiss=e=>(this.dismissedToasts.add(e),e||this.toasts.forEach(t=>{this.subscribers.forEach(n=>n({id:t.id,dismiss:!0}))}),this.subscribers.forEach(t=>t({id:e,dismiss:!0})),e),this.message=(e,t)=>this.create({...t,message:e}),this.error=(e,t)=>this.create({...t,message:e,type:"error"}),this.success=(e,t)=>this.create({...t,type:"success",message:e}),this.info=(e,t)=>this.create({...t,type:"info",message:e}),this.warning=(e,t)=>this.create({...t,type:"warning",message:e}),this.loading=(e,t)=>this.create({...t,type:"loading",message:e}),this.promise=(e,t)=>{if(!t)return;let n;t.loading!==void 0&&(n=this.create({...t,promise:e,type:"loading",message:t.loading,description:typeof t.description!="function"?t.description:void 0}));let r=e instanceof Promise?e:e(),o=n!==void 0,s,i=r.then(async l=>{if(s=["resolve",l],b.isValidElement(l))o=!1,this.create({id:n,type:"default",message:l});else if(hI(l)&&!l.ok){o=!1;let c=typeof t.error=="function"?await t.error(`HTTP error! status: ${l.status}`):t.error,d=typeof t.description=="function"?await t.description(`HTTP error! status: ${l.status}`):t.description;this.create({id:n,type:"error",message:c,description:d})}else if(t.success!==void 0){o=!1;let c=typeof t.success=="function"?await t.success(l):t.success,d=typeof t.description=="function"?await t.description(l):t.description;this.create({id:n,type:"success",message:c,description:d})}}).catch(async l=>{if(s=["reject",l],t.error!==void 0){o=!1;let c=typeof t.error=="function"?await t.error(l):t.error,d=typeof t.description=="function"?await t.description(l):t.description;this.create({id:n,type:"error",message:c,description:d})}}).finally(()=>{var l;o&&(this.dismiss(n),n=void 0),(l=t.finally)==null||l.call(t)}),a=()=>new Promise((l,c)=>i.then(()=>s[0]==="reject"?c(s[1]):l(s[1])).catch(c));return typeof n!="string"&&typeof n!="number"?{unwrap:a}:Object.assign(n,{unwrap:a})},this.custom=(e,t)=>{let n=(t==null?void 0:t.id)||Kl++;return this.create({jsx:e(n),id:n,...t}),n},this.getActiveToasts=()=>this.toasts.filter(e=>!this.dismissedToasts.has(e.id)),this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},Ht=new fI,pI=(e,t)=>{let n=(t==null?void 0:t.id)||Kl++;return Ht.addToast({title:e,...t,id:n}),n},hI=e=>e&&typeof e=="object"&&"ok"in e&&typeof e.ok=="boolean"&&"status"in e&&typeof e.status=="number",mI=pI,gI=()=>Ht.toasts,xI=()=>Ht.getActiveToasts();Object.assign(mI,{success:Ht.success,info:Ht.info,warning:Ht.warning,error:Ht.error,custom:Ht.custom,message:Ht.message,promise:Ht.promise,dismiss:Ht.dismiss,loading:Ht.loading},{getHistory:gI,getToasts:xI});function vI(e,{insertAt:t}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",t==="top"&&n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}vI(`:where(html[dir="ltr"]),:where([data-sonner-toaster][dir="ltr"]){--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}:where(html[dir="rtl"]),:where([data-sonner-toaster][dir="rtl"]){--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}:where([data-sonner-toaster]){position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999;transition:transform .4s ease}:where([data-sonner-toaster][data-lifted="true"]){transform:translateY(-10px)}@media (hover: none) and (pointer: coarse){:where([data-sonner-toaster][data-lifted="true"]){transform:none}}:where([data-sonner-toaster][data-x-position="right"]){right:var(--offset-right)}:where([data-sonner-toaster][data-x-position="left"]){left:var(--offset-left)}:where([data-sonner-toaster][data-x-position="center"]){left:50%;transform:translate(-50%)}:where([data-sonner-toaster][data-y-position="top"]){top:var(--offset-top)}:where([data-sonner-toaster][data-y-position="bottom"]){bottom:var(--offset-bottom)}:where([data-sonner-toast]){--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}:where([data-sonner-toast][data-styled="true"]){padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}:where([data-sonner-toast]:focus-visible){box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast][data-y-position="top"]){top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}:where([data-sonner-toast][data-y-position="bottom"]){bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}:where([data-sonner-toast]) :where([data-description]){font-weight:400;line-height:1.4;color:inherit}:where([data-sonner-toast]) :where([data-title]){font-weight:500;line-height:1.5;color:inherit}:where([data-sonner-toast]) :where([data-icon]){display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}:where([data-sonner-toast][data-promise="true"]) :where([data-icon])>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}:where([data-sonner-toast]) :where([data-icon])>*{flex-shrink:0}:where([data-sonner-toast]) :where([data-icon]) svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}:where([data-sonner-toast]) :where([data-content]){display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}:where([data-sonner-toast]) :where([data-button]):focus-visible{box-shadow:0 0 0 2px #0006}:where([data-sonner-toast]) :where([data-button]):first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}:where([data-sonner-toast]) :where([data-cancel]){color:var(--normal-text);background:rgba(0,0,0,.08)}:where([data-sonner-toast][data-theme="dark"]) :where([data-cancel]){background:rgba(255,255,255,.3)}:where([data-sonner-toast]) :where([data-close-button]){position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-close-button]{background:var(--gray1)}:where([data-sonner-toast]) :where([data-close-button]):focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast]) :where([data-disabled="true"]){cursor:not-allowed}:where([data-sonner-toast]):hover :where([data-close-button]):hover{background:var(--gray2);border-color:var(--gray5)}:where([data-sonner-toast][data-swiping="true"]):before{content:"";position:absolute;left:-50%;right:-50%;height:100%;z-index:-1}:where([data-sonner-toast][data-y-position="top"][data-swiping="true"]):before{bottom:50%;transform:scaleY(3) translateY(50%)}:where([data-sonner-toast][data-y-position="bottom"][data-swiping="true"]):before{top:50%;transform:scaleY(3) translateY(-50%)}:where([data-sonner-toast][data-swiping="false"][data-removed="true"]):before{content:"";position:absolute;inset:0;transform:scaleY(2)}:where([data-sonner-toast]):after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}:where([data-sonner-toast][data-mounted="true"]){--y: translateY(0);opacity:1}:where([data-sonner-toast][data-expanded="false"][data-front="false"]){--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}:where([data-sonner-toast])>*{transition:opacity .4s}:where([data-sonner-toast][data-expanded="false"][data-front="false"][data-styled="true"])>*{opacity:0}:where([data-sonner-toast][data-visible="false"]){opacity:0;pointer-events:none}:where([data-sonner-toast][data-mounted="true"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}:where([data-sonner-toast][data-removed="true"][data-front="true"][data-swipe-out="false"]){--y: translateY(calc(var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="false"]){--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}:where([data-sonner-toast][data-removed="true"][data-front="false"]):before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y, 0px)) translate(var(--swipe-amount-x, 0px));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 91%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 91%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-bg-hover: hsl(0, 0%, 12%);--normal-border: hsl(0, 0%, 20%);--normal-border-hover: hsl(0, 0%, 25%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 100%, 12%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 12%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success],[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info],[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning],[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error],[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}
130
130
  `);function li(e){return e.label!==void 0}var wI=3,bI="32px",yI="16px",Vg=4e3,SI=356,CI=14,TI=20,kI=200;function fn(...e){return e.filter(Boolean).join(" ")}function EI(e){let[t,n]=e.split("-"),r=[];return t&&r.push(t),n&&r.push(n),r}var II=e=>{var t,n,r,o,s,i,a,l,c,d,p;let{invert:m,toast:f,unstyled:v,interacting:g,setHeights:x,visibleToasts:y,heights:w,index:S,toasts:k,expanded:C,removeToast:T,defaultRichColors:E,closeButton:j,style:O,cancelButtonStyle:L,actionButtonStyle:U,className:K="",descriptionClassName:V="",duration:N,position:W,gap:I,loadingIcon:F,expandByDefault:R,classNames:_,icons:G,closeButtonAriaLabel:J="Close toast",pauseWhenPageIsHidden:P}=e,[M,q]=b.useState(null),[Y,se]=b.useState(null),[B,D]=b.useState(!1),[X,re]=b.useState(!1),[ae,$]=b.useState(!1),[Z,de]=b.useState(!1),[ce,xe]=b.useState(!1),[_e,Ve]=b.useState(0),[He,Ee]=b.useState(0),Fe=b.useRef(f.duration||N||Vg),Ke=b.useRef(null),Ue=b.useRef(null),Ye=S===0,nt=S+1<=y,et=f.type,Ze=f.dismissible!==!1,vt=f.className||"",gt=f.descriptionClassName||"",ut=b.useMemo(()=>w.findIndex(Ce=>Ce.toastId===f.id)||0,[w,f.id]),ye=b.useMemo(()=>{var Ce;return(Ce=f.closeButton)!=null?Ce:j},[f.closeButton,j]),tt=b.useMemo(()=>f.duration||N||Vg,[f.duration,N]),rt=b.useRef(0),_t=b.useRef(0),pn=b.useRef(0),Le=b.useRef(null),[qe,Dt]=W.split("-"),Pt=b.useMemo(()=>w.reduce((Ce,Me,We)=>We>=ut?Ce:Ce+Me.height,0),[w,ut]),wt=dI(),kt=f.invert||m,ne=et==="loading";_t.current=b.useMemo(()=>ut*I+Pt,[ut,Pt]),b.useEffect(()=>{Fe.current=tt},[tt]),b.useEffect(()=>{D(!0)},[]),b.useEffect(()=>{let Ce=Ue.current;if(Ce){let Me=Ce.getBoundingClientRect().height;return Ee(Me),x(We=>[{toastId:f.id,height:Me,position:f.position},...We]),()=>x(We=>We.filter(Ct=>Ct.toastId!==f.id))}},[x,f.id]),b.useLayoutEffect(()=>{if(!B)return;let Ce=Ue.current,Me=Ce.style.height;Ce.style.height="auto";let We=Ce.getBoundingClientRect().height;Ce.style.height=Me,Ee(We),x(Ct=>Ct.find(Be=>Be.toastId===f.id)?Ct.map(Be=>Be.toastId===f.id?{...Be,height:We}:Be):[{toastId:f.id,height:We,position:f.position},...Ct])},[B,f.title,f.description,x,f.id]);let Se=b.useCallback(()=>{re(!0),Ve(_t.current),x(Ce=>Ce.filter(Me=>Me.toastId!==f.id)),setTimeout(()=>{T(f)},kI)},[f,T,x,_t]);b.useEffect(()=>{if(f.promise&&et==="loading"||f.duration===1/0||f.type==="loading")return;let Ce;return C||g||P&&wt?(()=>{if(pn.current<rt.current){let Me=new Date().getTime()-rt.current;Fe.current=Fe.current-Me}pn.current=new Date().getTime()})():Fe.current!==1/0&&(rt.current=new Date().getTime(),Ce=setTimeout(()=>{var Me;(Me=f.onAutoClose)==null||Me.call(f,f),Se()},Fe.current)),()=>clearTimeout(Ce)},[C,g,f,et,P,wt,Se]),b.useEffect(()=>{f.delete&&Se()},[Se,f.delete]);function ft(){var Ce,Me,We;return G!=null&&G.loading?b.createElement("div",{className:fn(_==null?void 0:_.loader,(Ce=f==null?void 0:f.classNames)==null?void 0:Ce.loader,"sonner-loader"),"data-visible":et==="loading"},G.loading):F?b.createElement("div",{className:fn(_==null?void 0:_.loader,(Me=f==null?void 0:f.classNames)==null?void 0:Me.loader,"sonner-loader"),"data-visible":et==="loading"},F):b.createElement(sI,{className:fn(_==null?void 0:_.loader,(We=f==null?void 0:f.classNames)==null?void 0:We.loader),visible:et==="loading"})}return b.createElement("li",{tabIndex:0,ref:Ue,className:fn(K,vt,_==null?void 0:_.toast,(t=f==null?void 0:f.classNames)==null?void 0:t.toast,_==null?void 0:_.default,_==null?void 0:_[et],(n=f==null?void 0:f.classNames)==null?void 0:n[et]),"data-sonner-toast":"","data-rich-colors":(r=f.richColors)!=null?r:E,"data-styled":!(f.jsx||f.unstyled||v),"data-mounted":B,"data-promise":!!f.promise,"data-swiped":ce,"data-removed":X,"data-visible":nt,"data-y-position":qe,"data-x-position":Dt,"data-index":S,"data-front":Ye,"data-swiping":ae,"data-dismissible":Ze,"data-type":et,"data-invert":kt,"data-swipe-out":Z,"data-swipe-direction":Y,"data-expanded":!!(C||R&&B),style:{"--index":S,"--toasts-before":S,"--z-index":k.length-S,"--offset":`${X?_e:_t.current}px`,"--initial-height":R?"auto":`${He}px`,...O,...f.style},onDragEnd:()=>{$(!1),q(null),Le.current=null},onPointerDown:Ce=>{ne||!Ze||(Ke.current=new Date,Ve(_t.current),Ce.target.setPointerCapture(Ce.pointerId),Ce.target.tagName!=="BUTTON"&&($(!0),Le.current={x:Ce.clientX,y:Ce.clientY}))},onPointerUp:()=>{var Ce,Me,We,Ct;if(Z||!Ze)return;Le.current=null;let Be=Number(((Ce=Ue.current)==null?void 0:Ce.style.getPropertyValue("--swipe-amount-x").replace("px",""))||0),dt=Number(((Me=Ue.current)==null?void 0:Me.style.getPropertyValue("--swipe-amount-y").replace("px",""))||0),$e=new Date().getTime()-((We=Ke.current)==null?void 0:We.getTime()),Qe=M==="x"?Be:dt,Ut=Math.abs(Qe)/$e;if(Math.abs(Qe)>=TI||Ut>.11){Ve(_t.current),(Ct=f.onDismiss)==null||Ct.call(f,f),se(M==="x"?Be>0?"right":"left":dt>0?"down":"up"),Se(),de(!0),xe(!1);return}$(!1),q(null)},onPointerMove:Ce=>{var Me,We,Ct,Be;if(!Le.current||!Ze||((Me=window.getSelection())==null?void 0:Me.toString().length)>0)return;let dt=Ce.clientY-Le.current.y,$e=Ce.clientX-Le.current.x,Qe=(We=e.swipeDirections)!=null?We:EI(W);!M&&(Math.abs($e)>1||Math.abs(dt)>1)&&q(Math.abs($e)>Math.abs(dt)?"x":"y");let Ut={x:0,y:0};M==="y"?(Qe.includes("top")||Qe.includes("bottom"))&&(Qe.includes("top")&&dt<0||Qe.includes("bottom")&&dt>0)&&(Ut.y=dt):M==="x"&&(Qe.includes("left")||Qe.includes("right"))&&(Qe.includes("left")&&$e<0||Qe.includes("right")&&$e>0)&&(Ut.x=$e),(Math.abs(Ut.x)>0||Math.abs(Ut.y)>0)&&xe(!0),(Ct=Ue.current)==null||Ct.style.setProperty("--swipe-amount-x",`${Ut.x}px`),(Be=Ue.current)==null||Be.style.setProperty("--swipe-amount-y",`${Ut.y}px`)}},ye&&!f.jsx?b.createElement("button",{"aria-label":J,"data-disabled":ne,"data-close-button":!0,onClick:ne||!Ze?()=>{}:()=>{var Ce;Se(),(Ce=f.onDismiss)==null||Ce.call(f,f)},className:fn(_==null?void 0:_.closeButton,(o=f==null?void 0:f.classNames)==null?void 0:o.closeButton)},(s=G==null?void 0:G.close)!=null?s:uI):null,f.jsx||b.isValidElement(f.title)?f.jsx?f.jsx:typeof f.title=="function"?f.title():f.title:b.createElement(b.Fragment,null,et||f.icon||f.promise?b.createElement("div",{"data-icon":"",className:fn(_==null?void 0:_.icon,(i=f==null?void 0:f.classNames)==null?void 0:i.icon)},f.promise||f.type==="loading"&&!f.icon?f.icon||ft():null,f.type!=="loading"?f.icon||(G==null?void 0:G[et])||rI(et):null):null,b.createElement("div",{"data-content":"",className:fn(_==null?void 0:_.content,(a=f==null?void 0:f.classNames)==null?void 0:a.content)},b.createElement("div",{"data-title":"",className:fn(_==null?void 0:_.title,(l=f==null?void 0:f.classNames)==null?void 0:l.title)},typeof f.title=="function"?f.title():f.title),f.description?b.createElement("div",{"data-description":"",className:fn(V,gt,_==null?void 0:_.description,(c=f==null?void 0:f.classNames)==null?void 0:c.description)},typeof f.description=="function"?f.description():f.description):null),b.isValidElement(f.cancel)?f.cancel:f.cancel&&li(f.cancel)?b.createElement("button",{"data-button":!0,"data-cancel":!0,style:f.cancelButtonStyle||L,onClick:Ce=>{var Me,We;li(f.cancel)&&Ze&&((We=(Me=f.cancel).onClick)==null||We.call(Me,Ce),Se())},className:fn(_==null?void 0:_.cancelButton,(d=f==null?void 0:f.classNames)==null?void 0:d.cancelButton)},f.cancel.label):null,b.isValidElement(f.action)?f.action:f.action&&li(f.action)?b.createElement("button",{"data-button":!0,"data-action":!0,style:f.actionButtonStyle||U,onClick:Ce=>{var Me,We;li(f.action)&&((We=(Me=f.action).onClick)==null||We.call(Me,Ce),!Ce.defaultPrevented&&Se())},className:fn(_==null?void 0:_.actionButton,(p=f==null?void 0:f.classNames)==null?void 0:p.actionButton)},f.action.label):null))};function Kg(){if(typeof window>"u"||typeof document>"u")return"ltr";let e=document.documentElement.getAttribute("dir");return e==="auto"||!e?window.getComputedStyle(document.documentElement).direction:e}function NI(e,t){let n={};return[e,t].forEach((r,o)=>{let s=o===1,i=s?"--mobile-offset":"--offset",a=s?yI:bI;function l(c){["top","right","bottom","left"].forEach(d=>{n[`${i}-${d}`]=typeof c=="number"?`${c}px`:c})}typeof r=="number"||typeof r=="string"?l(r):typeof r=="object"?["top","right","bottom","left"].forEach(c=>{r[c]===void 0?n[`${i}-${c}`]=a:n[`${i}-${c}`]=typeof r[c]=="number"?`${r[c]}px`:r[c]}):l(a)}),n}var AI=b.forwardRef(function(e,t){let{invert:n,position:r="bottom-right",hotkey:o=["altKey","KeyT"],expand:s,closeButton:i,className:a,offset:l,mobileOffset:c,theme:d="light",richColors:p,duration:m,style:f,visibleToasts:v=wI,toastOptions:g,dir:x=Kg(),gap:y=CI,loadingIcon:w,icons:S,containerAriaLabel:k="Notifications",pauseWhenPageIsHidden:C}=e,[T,E]=b.useState([]),j=b.useMemo(()=>Array.from(new Set([r].concat(T.filter(P=>P.position).map(P=>P.position)))),[T,r]),[O,L]=b.useState([]),[U,K]=b.useState(!1),[V,N]=b.useState(!1),[W,I]=b.useState(d!=="system"?d:typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),F=b.useRef(null),R=o.join("+").replace(/Key/g,"").replace(/Digit/g,""),_=b.useRef(null),G=b.useRef(!1),J=b.useCallback(P=>{E(M=>{var q;return(q=M.find(Y=>Y.id===P.id))!=null&&q.delete||Ht.dismiss(P.id),M.filter(({id:Y})=>Y!==P.id)})},[]);return b.useEffect(()=>Ht.subscribe(P=>{if(P.dismiss){E(M=>M.map(q=>q.id===P.id?{...q,delete:!0}:q));return}setTimeout(()=>{No.flushSync(()=>{E(M=>{let q=M.findIndex(Y=>Y.id===P.id);return q!==-1?[...M.slice(0,q),{...M[q],...P},...M.slice(q+1)]:[P,...M]})})})}),[]),b.useEffect(()=>{if(d!=="system"){I(d);return}if(d==="system"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?I("dark"):I("light")),typeof window>"u")return;let P=window.matchMedia("(prefers-color-scheme: dark)");try{P.addEventListener("change",({matches:M})=>{I(M?"dark":"light")})}catch{P.addListener(({matches:q})=>{try{I(q?"dark":"light")}catch(Y){console.error(Y)}})}},[d]),b.useEffect(()=>{T.length<=1&&K(!1)},[T]),b.useEffect(()=>{let P=M=>{var q,Y;o.every(se=>M[se]||M.code===se)&&(K(!0),(q=F.current)==null||q.focus()),M.code==="Escape"&&(document.activeElement===F.current||(Y=F.current)!=null&&Y.contains(document.activeElement))&&K(!1)};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[o]),b.useEffect(()=>{if(F.current)return()=>{_.current&&(_.current.focus({preventScroll:!0}),_.current=null,G.current=!1)}},[F.current]),b.createElement("section",{ref:t,"aria-label":`${k} ${R}`,tabIndex:-1,"aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",suppressHydrationWarning:!0},j.map((P,M)=>{var q;let[Y,se]=P.split("-");return T.length?b.createElement("ol",{key:P,dir:x==="auto"?Kg():x,tabIndex:-1,ref:F,className:a,"data-sonner-toaster":!0,"data-theme":W,"data-y-position":Y,"data-lifted":U&&T.length>1&&!s,"data-x-position":se,style:{"--front-toast-height":`${((q=O[0])==null?void 0:q.height)||0}px`,"--width":`${SI}px`,"--gap":`${y}px`,...f,...NI(l,c)},onBlur:B=>{G.current&&!B.currentTarget.contains(B.relatedTarget)&&(G.current=!1,_.current&&(_.current.focus({preventScroll:!0}),_.current=null))},onFocus:B=>{B.target instanceof HTMLElement&&B.target.dataset.dismissible==="false"||G.current||(G.current=!0,_.current=B.relatedTarget)},onMouseEnter:()=>K(!0),onMouseMove:()=>K(!0),onMouseLeave:()=>{V||K(!1)},onDragEnd:()=>K(!1),onPointerDown:B=>{B.target instanceof HTMLElement&&B.target.dataset.dismissible==="false"||N(!0)},onPointerUp:()=>N(!1)},T.filter(B=>!B.position&&M===0||B.position===P).map((B,D)=>{var X,re;return b.createElement(II,{key:B.id,icons:S,index:D,toast:B,defaultRichColors:p,duration:(X=g==null?void 0:g.duration)!=null?X:m,className:g==null?void 0:g.className,descriptionClassName:g==null?void 0:g.descriptionClassName,invert:n,visibleToasts:v,closeButton:(re=g==null?void 0:g.closeButton)!=null?re:i,interacting:V,position:P,style:g==null?void 0:g.style,unstyled:g==null?void 0:g.unstyled,classNames:g==null?void 0:g.classNames,cancelButtonStyle:g==null?void 0:g.cancelButtonStyle,actionButtonStyle:g==null?void 0:g.actionButtonStyle,removeToast:J,toasts:T.filter(ae=>ae.position==B.position),heights:O.filter(ae=>ae.position==B.position),setHeights:L,expandByDefault:s,gap:y,loadingIcon:w,expanded:U,pauseWhenPageIsHidden:C,swipeDirections:e.swipeDirections})})):null}))});const jI=({...e})=>{const{theme:t="system"}=nI();return u.jsx(AI,{theme:t,className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...e})};z.Api=Av,z.ApiClient=Nv,z.ApiProvider=eu,z.ArtifactRenderer=xh,z.Badge=Op,z.Button=it,z.Card=tl,z.CardContent=sl,z.CardDescription=ol,z.CardHeader=nl,z.CardTitle=rl,z.ChatApi=Ho,z.ChatApp=pk,z.ChatInput=Df,z.ChatInterface=So,z.ChatProviders=Xr,z.Command=gl,z.CommandEmpty=wl,z.CommandGroup=bl,z.CommandInput=xl,z.CommandItem=yl,z.CommandList=vl,z.DEFAULT_TIMEOUT_MS=Gc,z.Dialog=Ya,z.DialogContent=Ds,z.DialogHeader=Ls,z.DialogTitle=$s,z.DropdownMenu=vs,z.DropdownMenuContent=ao,z.DropdownMenuItem=On,z.DropdownMenuTrigger=ws,z.FileViewerModal=th,z.HISTORY_TIMEOUT_MS=Yc,z.Input=Nl,z.InterruptPartRenderer=wh,z.Label=im,z.MarkdownContent=Ar,z.MessageBody=Th,z.MessageComponent=Vs,z.MessageList=cl,z.MessageRow=ll,z.PlotArtifact=mh,z.ResearchTaskArtifact=gh,z.SETTINGS_STORAGE_KEY=Mi,z.ScrollArea=Il,z.Select=qk,z.SelectContent=qm,z.SelectItem=Gm,z.SelectTrigger=Wm,z.SelectValue=Gk,z.Separator=Zm,z.Sheet=sE,z.SheetContent=ag,z.SheetDescription=ug,z.SheetHeader=lg,z.SheetTitle=cg,z.SheetTrigger=iE,z.SimpleChat=hk,z.SimpleJsonView=il,z.Sonner=jI,z.StreamProgress=bh,z.Switch=sg,z.Textarea=ba,z.ThinkingIndicator=Sh,z.ThreadListItem=em,z.ThreadManager=Al,z.ThreadStateProvider=yu,z.ThreadsProvider=iu,z.TimelineColumn=sx,z.Toaster=ZE,z.ToolComponent=yh,z.Tooltip=AE,z.TooltipContent=wg,z.TooltipProvider=NE,z.TooltipTrigger=jE,z.UserTextContent=Ch,z.applySettings=aw,z.buildCheckpointIndex=Zl,z.buildCheckpointPreviewMap=Zg,z.chatApiClient=An,z.del=ki,z.downloadFileById=Jc,z.extractConfigFields=di,z.fileToBase64=tu,z.get=qt,z.getChatToken=Kc,z.getCheckpointForMessage=Qg,z.getCurrentSettings=iw,z.getDefaultApiConfig=Iu,z.getDefaultChatSettings=Nu,z.getFileContent=Ii,z.getFileInfo=_v,z.getMessageAttemptInfo=Ql,z.getMessageDomKey=al,z.getPreviewForMessage=ui,z.httpClient=Kt,z.hydrateHistorySnapshots=Nn,z.isEnvelope=ru,z.listFiles=Zc,z.loadStoredSettings=Au,z.onChatTokenChanged=qc,z.post=zo,z.processAttachments=nu,z.put=Xc,z.readNumber=tc,z.readString=Vn,z.resolveChatBaseUrl=mn,z.saveSettings=ju,z.setChatToken=Bo,z.toPlainObject=cr,z.unwrap=Rt,z.useApi=Vr,z.useCheckpointIndex=ec,z.useFilePreview=kh,z.useHasChatSession=ow,z.useParsedMessageContent=Eh,z.useStream=Ri,z.useStreamingHook=Ri,z.useThreadHistoryState=xu,z.useThreadManagerViewState=rm,z.useThreadState=Yr,z.useThreadStateUpdater=bu,z.useThreads=pr,z.useThreadsState=ou,z.viewFileById=jv,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})});