teodor-new-chat-ui 1.2.0 → 1.2.2

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,8 +1,9 @@
1
- (function(O,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],a):(O=typeof globalThis<"u"?globalThis:O||self,a(O.NewChatUI={},O.jsxRuntime,O.React,O.LucideReact,O.reactSlot,O.classVarianceAuthority,O.clsx,O.tailwindMerge,O.ReactDOM))})(this,function(O,a,L,W,Ze,Tt,un,hn,pn){"use strict";function Nt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const u=Nt(L),Pt=Nt(pn),Qe=1e4,Re=200,At=/^[a-zA-Z0-9\-_]{1,50}$/;function gn(e){return typeof e!="string"?String(e):e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;").trim()}function ae(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let r=e;for(const n of t)r=r.replace(n,"");return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").trim()}function Ot(e,t=Qe){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function mn(e){if(!e||typeof e!="string")throw new Error("Invalid thread ID: must be a non-empty string");if(!At.test(e))throw new Error("Invalid thread ID: contains invalid characters");return e}function Se(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Ot(t),ae(t)}function vn(e){if(!e||typeof e!="string")throw new Error("Invalid title: must be a non-empty string");if(e.length>Re)throw new Error(`Title exceeds maximum length of ${Re} characters`);return ae(e)}function wn(e){try{const t=JSON.parse(e);if(typeof t=="object"&&t!==null){const r=["__proto__","constructor","prototype"];for(const n of r)if(n in t)throw new Error(`Dangerous property detected: ${n}`)}return t}catch(t){throw new Error(`Invalid JSON: ${t instanceof Error?t.message:"Unknown error"}`)}}function bn(e,t){return(...r)=>(typeof r[0]=="string"&&(r[0]=t(r[0])),e(...r))}const Lt=L.createContext(null),yn="http://localhost:8000/api/chat";function Le({children:e,apiBaseUrl:t=yn,enableUrlSync:r=!1,getAuthHeaders:n,authToken:o}){const[s,i]=L.useState({currentThreadId:null,messages:[],isLoading:!1,isLoadingHistory:!1,error:null,interrupt:null,threads:[],loadingThreads:!1,availableBranches:[],currentBranch:null}),l=L.useCallback(()=>r?new URLSearchParams(window.location.search).get("thread"):null,[r]),f=L.useCallback(x=>{if(!r)return;const b=new URL(window.location.href);x?b.searchParams.set("thread",x):b.searchParams.delete("thread"),window.history.pushState({},"",b.toString())},[r]);L.useEffect(()=>{if(r){const x=l();x&&i(b=>({...b,currentThreadId:x}))}},[r,l]),L.useEffect(()=>{if(!r)return;const x=()=>{const b=l();i(A=>({...A,currentThreadId:b}))};return window.addEventListener("popstate",x),()=>window.removeEventListener("popstate",x)},[r,l]);const c=L.useCallback((x={})=>{const b={"Content-Type":"application/json",...x};if(n)return{...b,...n()};if(o)return{...b,Authorization:`Bearer ${o}`};const A=localStorage.getItem("authToken");return A?{...b,Authorization:`Bearer ${A}`}:b},[n,o]),d=L.useCallback(async()=>{i(x=>({...x,loadingThreads:!0}));try{const x=await fetch(`${t}/threads`,{headers:c()});if(!x.ok)throw new Error("Failed to load threads");const b=await x.json();i(A=>({...A,threads:b,loadingThreads:!1}))}catch(x){i(b=>({...b,loadingThreads:!1,error:x instanceof Error?x.message:"Failed to load threads"}))}},[t,c]),h=x=>x.map(b=>({id:b.id,role:b.role==="human"?"human":b.role==="ai"?"ai":"tool",content:b.content,timestamp:b.timestamp,name:b.name,tool_call_id:b.tool_call_id,args:b.args,branch_id:b.branch_id,sequence_number:b.sequence_number})),p=L.useCallback(async x=>{i(b=>({...b,isLoadingHistory:!0}));try{const b=await fetch(`${t}/history/${x}`,{headers:c()});if(!b.ok)throw new Error("Failed to load history");const A=await b.json(),D=h(A);i(F=>({...F,messages:D,isLoadingHistory:!1}))}catch(b){i(A=>({...A,isLoadingHistory:!1,error:b instanceof Error?b.message:"Failed to load history"}))}},[t,c]),g=L.useCallback(async x=>{try{const b=await fetch(`${t}/threads/${x}/branches`,{headers:c()});if(!b.ok)return;const A=await b.json();i(D=>({...D,availableBranches:A.branches||[],currentBranch:A.current_branch}))}catch(b){console.warn("Failed to load branches:",b)}},[t,c]),v=L.useCallback(x=>{i(b=>({...b,currentThreadId:x,messages:[],availableBranches:[],currentBranch:null,error:null})),f(x),x&&Promise.all([p(x),g(x)]).catch(b=>{console.error("Failed to load thread data:",b)})},[f,p,g]),y=L.useCallback(async()=>{try{const x=await fetch(`${t}/threads`,{method:"POST",headers:c()});if(!x.ok)throw new Error("Failed to create thread");const A=(await x.json()).thread_id;return await d(),A}catch(x){throw i(b=>({...b,error:x instanceof Error?x.message:"Failed to create thread"})),x}},[t,c,d]),C=L.useCallback(async x=>{console.log("deleteThread called with threadId:",x),console.log("apiBaseUrl:",t);try{const b=`${t}/threads/${x}`;console.log("Making DELETE request to:",b);const A=await fetch(b,{method:"DELETE",headers:c()});if(console.log("Delete response status:",A.status),console.log("Delete response ok:",A.ok),!A.ok){const D=await A.text();throw console.log("Delete error response:",D),new Error(`Failed to delete thread: ${A.status} ${D}`)}console.log("Thread deleted successfully"),s.currentThreadId===x&&(console.log("Clearing current thread as it was deleted"),v(null)),console.log("Reloading threads list"),await d()}catch(b){console.error("Error deleting thread:",b),i(A=>({...A,error:b instanceof Error?b.message:"Failed to delete thread"}))}},[t,s.currentThreadId,v,d,c]),S=L.useCallback(async(x,b)=>{try{if(!(await fetch(`${t}/threads/${x}/title`,{method:"PATCH",headers:c(),body:JSON.stringify({title:b})})).ok)throw new Error("Failed to update thread title");await d()}catch(A){i(D=>({...D,error:A instanceof Error?A.message:"Failed to update thread title"}))}},[t,d,c]),E=L.useCallback(async x=>{if(s.currentThreadId)try{const b=Se(x),A={id:`temp-${Date.now()}`,role:"human",content:b,timestamp:new Date().toISOString()};i(D=>({...D,messages:[...D.messages,A],isLoading:!0,error:null}));try{const D=await fetch(`${t}/stream`,{method:"POST",headers:c(),body:JSON.stringify({thread_id:s.currentThreadId,messages:[...s.messages,{role:"human",content:b}],operation:"continue"})});if(!D.ok){const F=await D.text();throw new Error(`HTTP ${D.status}: ${F}`)}await P(D),await p(s.currentThreadId)}catch(D){i(F=>({...F,messages:F.messages.filter(N=>N.id!==A.id),isLoading:!1,error:D instanceof Error?D.message:"Failed to send message"}))}}catch(b){i(A=>({...A,error:b instanceof Error?b.message:"Invalid message content"}))}},[t,s.currentThreadId,s.messages,p,c]),P=async x=>{var F;const b=(F=x.body)==null?void 0:F.getReader();if(!b){i(N=>({...N,isLoading:!1}));return}const A=new TextDecoder;let D="";try{for(;;){const{done:N,value:H}=await b.read();if(N)break;D+=A.decode(H,{stream:!0});const M=D.split(`
2
- `);D=M.pop()||"";for(const B of M)if(B.trim()&&B.startsWith("data: "))try{const $=JSON.parse(B.slice(6));$.type==="text"?i(Y=>{const Ce=[...Y.messages],Ae=Ce[Ce.length-1];return Ae&&Ae.role==="ai"?Ae.content+=$.text:Ce.push({id:`ai-${Date.now()}`,role:"ai",content:$.text,timestamp:new Date().toISOString()}),{...Y,messages:Ce}}):$.type==="tool_call"?i(Y=>({...Y,messages:[...Y.messages,{id:`tool-${Date.now()}`,role:"tool",content:$.result||"",name:$.name||"unknown_function",tool_call_id:$.id,args:$.args,timestamp:new Date().toISOString()}]})):$.type==="complete"&&i(Y=>({...Y,isLoading:!1}))}catch($){console.warn("Failed to parse streaming data:",B,$)}}}catch(N){console.error("Streaming error:",N)}finally{i(N=>({...N,isLoading:!1}))}};L.useEffect(()=>{d()},[d]);const m=L.useCallback(async(x,b,A=!1)=>{if(!(!s.currentThreadId||!x.id)){i(D=>({...D,isLoading:!0,error:null}));try{const D=b?A?"edit_from_input":"edit_and_regenerate":"regenerate",F=await fetch(`${t}/stream`,{method:"POST",headers:c(),body:JSON.stringify({thread_id:s.currentThreadId,messages:s.messages,operation:D,from_message_id:x.id,edited_content:b,create_branch:!!b})});if(!F.ok){const N=await F.text();throw new Error(`HTTP ${F.status}: ${N}`)}await P(F),await Promise.all([p(s.currentThreadId),g(s.currentThreadId)])}catch(D){i(F=>({...F,isLoading:!1,error:D instanceof Error?D.message:"Failed to regenerate message"}))}}},[t,s.currentThreadId,s.messages,p,g,c]),w=L.useCallback(async(x,b,A=!1,D=!1)=>{if(!(!s.currentThreadId||!x.id)){if(A){await m(x,b,D);return}i(F=>({...F,messages:F.messages.map(N=>N.id===x.id?{...N,content:b}:N)}))}},[s.currentThreadId,m]),_=L.useCallback(async x=>{if(s.currentThreadId)try{if(!(await fetch(`${t}/threads/${s.currentThreadId}/branch`,{method:"PATCH",headers:c(),body:JSON.stringify({branch_id:x})})).ok)throw new Error("Failed to switch branch");i(A=>({...A,currentBranch:x})),await p(s.currentThreadId)}catch(b){i(A=>({...A,error:b instanceof Error?b.message:"Failed to switch branch"}))}},[t,s.currentThreadId,p,c]),T=L.useCallback(()=>{i(x=>({...x,isLoading:!1}))},[]),k=L.useCallback(()=>{i(x=>({...x,error:null}))},[]),I=L.useCallback(async()=>{await d(),s.currentThreadId&&await Promise.all([p(s.currentThreadId),g(s.currentThreadId)])},[d,p,g,s.currentThreadId]),z={...s,selectThread:v,createThread:y,deleteThread:C,updateThreadTitle:S,sendMessage:E,editMessage:w,regenerateFromMessage:m,stop:T,switchBranch:_,clearError:k,refresh:I};return a.jsx(Lt.Provider,{value:z,children:e})}function fe(){const e=L.useContext(Lt);if(!e)throw new Error("useChat must be used within a ChatProvider");return e}function X(...e){return hn.twMerge(un.clsx(e))}const xn=Tt.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),j=u.forwardRef(({className:e,variant:t,size:r,asChild:n=!1,...o},s)=>{const i=n?Ze.Slot:"button";return a.jsx(i,{className:X(xn({variant:t,size:r,className:e})),ref:s,...o})});j.displayName="Button";const _e=u.forwardRef(({className:e,...t},r)=>a.jsx("textarea",{className:X("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...t}));_e.displayName="Textarea";function et({message:e,onRegenerate:t,onEditMessage:r,showRegenerate:n=!1,showBranches:o=!1,branches:s=[],onSwitchBranch:i}){var P;const[l,f]=L.useState(!1),[c,d]=L.useState(!1),[h,p]=L.useState(typeof e.content=="string"?e.content:JSON.stringify(e.content)),g=()=>{t&&t(e)},v=()=>{try{const m=typeof e.content=="string"?e.content:JSON.stringify(e.content),w=Se(h);w.trim()&&w!==m&&r&&r(e,w.trim(),!0)}catch(m){console.error("Error validating edit content:",m)}d(!1)},y=()=>{const m=typeof e.content=="string"?e.content:JSON.stringify(e.content);p(m),d(!1)},C=()=>{switch(e.role){case"human":return a.jsx(W.User,{size:20,className:"text-blue-600"});case"ai":return a.jsx(W.Bot,{size:20,className:"text-green-600"});case"tool":return a.jsx(W.Wrench,{size:20,className:"text-orange-600"});default:return a.jsx(W.Bot,{size:20,className:"text-gray-600"})}},S=()=>{switch(e.role){case"human":return"You";case"ai":return"Assistant";case"tool":return e.name||"Tool";default:return"Message"}},E=()=>{try{return typeof e.content=="string"?ae(e.content):e.role==="tool"&&e.args?ae(JSON.stringify(e.args,null,2)):ae(JSON.stringify(e.content,null,2))}catch(m){return console.warn("Error formatting message content:",m),"[Content formatting error]"}};return console.log("Rendering message:",e),e.role==="human"?a.jsxs("div",{className:"flex gap-3 justify-end mb-4",children:[a.jsxs("div",{className:"max-w-[80%] rounded-lg p-4 relative group",style:{backgroundColor:"#2563eb",color:"white",border:"2px solid #1d4ed8",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)"},children:[e.id&&r&&a.jsx("div",{className:"absolute -top-1 -right-1 flex space-x-1 opacity-0 group-hover:opacity-100 transition-opacity",children:c?a.jsxs(a.Fragment,{children:[a.jsx(j,{size:"sm",variant:"ghost",onClick:v,className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Save changes and regenerate",children:a.jsx(W.Check,{className:"h-3 w-3"})}),a.jsx(j,{size:"sm",variant:"ghost",onClick:y,className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Cancel editing",children:a.jsx(W.X,{className:"h-3 w-3"})})]}):a.jsx(j,{size:"sm",variant:"ghost",onClick:()=>{const m=typeof e.content=="string"?e.content:JSON.stringify(e.content);r(e,m,!1,!0)},className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Edit message in input field and create branch",children:a.jsx(W.Edit2,{className:"h-3 w-3"})})}),a.jsx("div",{className:"whitespace-pre-wrap",style:{color:"white"},children:c?a.jsx(_e,{value:h,onChange:m=>p(m.target.value),className:"w-full min-h-[60px] bg-white/10 border-white/20 text-white placeholder-white/70",placeholder:"Edit your message...",autoFocus:!0}):a.jsx("span",{style:{color:"white"},children:ae(((P=e.content)==null?void 0:P.toString())||"[No content]")})}),e.timestamp&&!c&&a.jsx("div",{className:"text-xs opacity-70 mt-2",style:{color:"white"},children:new Date(e.timestamp).toLocaleTimeString()})]}),a.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center",children:C()})]}):a.jsxs("div",{className:"flex gap-3 justify-start mb-4",children:[a.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center",children:C()}),a.jsxs("div",{className:`
1
+ (function(O,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],a):(O=typeof globalThis<"u"?globalThis:O||self,a(O.NewChatUI={},O.jsxRuntime,O.React,O.LucideReact,O.reactSlot,O.classVarianceAuthority,O.clsx,O.tailwindMerge,O.ReactDOM))})(this,function(O,a,L,F,Re,Pt,mn,vn,wn){"use strict";function At(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const u=At(L),Ot=At(wn),et=1e4,tt=200,Lt=/^[a-zA-Z0-9\-_]{1,50}$/;function bn(e){return typeof e!="string"?String(e):e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;").trim()}function de(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let r=e;for(const n of t)r=r.replace(n,"");return r.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function _t(e,t=et){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function yn(e){if(!e||typeof e!="string")throw new Error("Invalid thread ID: must be a non-empty string");if(!Lt.test(e))throw new Error("Invalid thread ID: contains invalid characters");return e}function Te(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),_t(t),de(t)}function xn(e){if(!e||typeof e!="string")throw new Error("Invalid title: must be a non-empty string");if(e.length>tt)throw new Error(`Title exceeds maximum length of ${tt} characters`);return de(e)}function Cn(e){try{const t=JSON.parse(e);if(typeof t=="object"&&t!==null){const r=["__proto__","constructor","prototype"];for(const n of r)if(n in t)throw new Error(`Dangerous property detected: ${n}`)}return t}catch(t){throw new Error(`Invalid JSON: ${t instanceof Error?t.message:"Unknown error"}`)}}function Sn(e,t){return(...r)=>(typeof r[0]=="string"&&(r[0]=t(r[0])),e(...r))}function Dt(e,t={}){if(!e||typeof e!="string")return"";const{escapeHtml:r=!0,breaks:n=!0}=t;let o=e;return r&&(o=o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;")),n&&(o=o.replace(/\n/g,"<br>")),o=o.replace(/^### (.*$)/gm,"<h3>$1</h3>"),o=o.replace(/^## (.*$)/gm,"<h2>$1</h2>"),o=o.replace(/^# (.*$)/gm,"<h1>$1</h1>"),o=o.replace(/\*\*\*(.*?)\*\*\*/g,"<strong><em>$1</em></strong>"),o=o.replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>"),o=o.replace(/\*(.*?)\*/g,"<em>$1</em>"),o=o.replace(/```([\s\S]*?)```/g,"<pre><code>$1</code></pre>"),o=o.replace(/`(.*?)`/g,"<code>$1</code>"),o=o.replace(/^[\s]*\* (.*$)/gm,"<li>$1</li>"),o=o.replace(/^[\s]*- (.*$)/gm,"<li>$1</li>"),o=o.replace(/^[\s]*\+ (.*$)/gm,"<li>$1</li>"),o=o.replace(/(<li>[\s\S]*?<\/li>)/g,s=>s.includes("<ul>")?s:`<ul>${s}</ul>`),o=o.replace(/^[\s]*\d+\. (.*$)/gm,"<li>$1</li>"),o=o.replace(/(<li>[\s\S]*?<\/li>)/g,(s,i,l,f)=>{const c=f.substring(0,l);return/\d+\.\s/.test(c.split(`
2
+ `).pop()||"")&&!s.includes("<ol>")&&!s.includes("<ul>")?`<ol>${s}</ol>`:s}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),o=o.replace(/(https?:\/\/[^\s]+)/g,'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>'),o=o.replace(/^> (.*$)/gm,"<blockquote>$1</blockquote>"),o=o.replace(/<br>\s*<br>/g,"<br>"),o.trim()}function Mt(e){return!e||typeof e!="string"?!1:[/^#+\s/m,/\*\*.*?\*\*/,/\*.*?\*/,/```[\s\S]*?```/,/`.*?`/,/^\s*[-*+]\s/m,/^\s*\d+\.\s/m,/\[.*?\]\(.*?\)/,/^>\s/m].some(r=>r.test(e))}const kt=L.createContext(null),En="http://localhost:8000/api/chat";function _e({children:e,apiBaseUrl:t=En,enableUrlSync:r=!1,getAuthHeaders:n,authToken:o}){const[s,i]=L.useState({currentThreadId:null,messages:[],isLoading:!1,isLoadingHistory:!1,error:null,interrupt:null,threads:[],loadingThreads:!1,availableBranches:[],currentBranch:null}),l=L.useCallback(()=>r?new URLSearchParams(window.location.search).get("thread"):null,[r]),f=L.useCallback(x=>{if(!r)return;const w=new URL(window.location.href);x?w.searchParams.set("thread",x):w.searchParams.delete("thread"),window.history.pushState({},"",w.toString())},[r]);L.useEffect(()=>{if(r){const x=l();x&&i(w=>({...w,currentThreadId:x}))}},[r,l]),L.useEffect(()=>{if(!r)return;const x=()=>{const w=l();i(P=>({...P,currentThreadId:w}))};return window.addEventListener("popstate",x),()=>window.removeEventListener("popstate",x)},[r,l]);const c=L.useCallback((x={})=>{const w={"Content-Type":"application/json",...x};if(n)return{...w,...n()};if(o)return{...w,Authorization:`Bearer ${o}`};const P=localStorage.getItem("authToken");return P?{...w,Authorization:`Bearer ${P}`}:w},[n,o]),d=L.useCallback(async()=>{i(x=>({...x,loadingThreads:!0}));try{const x=await fetch(`${t}/threads`,{headers:c()});if(!x.ok)throw new Error("Failed to load threads");const w=await x.json();i(P=>({...P,threads:w,loadingThreads:!1}))}catch(x){i(w=>({...w,loadingThreads:!1,error:x instanceof Error?x.message:"Failed to load threads"}))}},[t,c]),h=x=>x.map(w=>{const D=w.role==="ai"&&typeof w.content=="string"&&Mt(w.content);return{id:w.id,role:w.role==="human"?"human":w.role==="ai"?"ai":"tool",content:D?Dt(w.content,{escapeHtml:!0,breaks:!0}):w.content,timestamp:w.timestamp,name:w.name,tool_call_id:w.tool_call_id,args:w.args,branch_id:w.branch_id,sequence_number:w.sequence_number,isMarkdown:D}}),p=(x,w)=>typeof x=="string"&&Mt(x)?{content:Dt(x,{escapeHtml:!0,breaks:!0}),isMarkdown:!0}:{content:typeof x=="string"?x:String(x),isMarkdown:!1},g=L.useCallback(async x=>{i(w=>({...w,isLoadingHistory:!0}));try{const w=await fetch(`${t}/history/${x}`,{headers:c()});if(!w.ok)throw new Error("Failed to load history");const P=await w.json(),D=h(P);i(T=>({...T,messages:D,isLoadingHistory:!1}))}catch(w){i(P=>({...P,isLoadingHistory:!1,error:w instanceof Error?w.message:"Failed to load history"}))}},[t,c]),m=L.useCallback(async x=>{try{const w=await fetch(`${t}/threads/${x}/branches`,{headers:c()});if(!w.ok)return;const P=await w.json();i(D=>({...D,availableBranches:P.branches||[],currentBranch:P.current_branch}))}catch(w){console.warn("Failed to load branches:",w)}},[t,c]),y=L.useCallback(x=>{i(w=>({...w,currentThreadId:x,messages:[],availableBranches:[],currentBranch:null,error:null})),f(x),x&&Promise.all([g(x),m(x)]).catch(w=>{console.error("Failed to load thread data:",w)})},[f,g,m]),C=L.useCallback(async()=>{try{const x=await fetch(`${t}/threads`,{method:"POST",headers:c()});if(!x.ok)throw new Error("Failed to create thread");const P=(await x.json()).thread_id;return await d(),P}catch(x){throw i(w=>({...w,error:x instanceof Error?x.message:"Failed to create thread"})),x}},[t,c,d]),S=L.useCallback(async x=>{console.log("deleteThread called with threadId:",x),console.log("apiBaseUrl:",t);try{const w=`${t}/threads/${x}`;console.log("Making DELETE request to:",w);const P=await fetch(w,{method:"DELETE",headers:c()});if(console.log("Delete response status:",P.status),console.log("Delete response ok:",P.ok),!P.ok){const D=await P.text();throw console.log("Delete error response:",D),new Error(`Failed to delete thread: ${P.status} ${D}`)}console.log("Thread deleted successfully"),s.currentThreadId===x&&(console.log("Clearing current thread as it was deleted"),y(null)),console.log("Reloading threads list"),await d()}catch(w){console.error("Error deleting thread:",w),i(P=>({...P,error:w instanceof Error?w.message:"Failed to delete thread"}))}},[t,s.currentThreadId,y,d,c]),E=L.useCallback(async(x,w)=>{try{if(!(await fetch(`${t}/threads/${x}/title`,{method:"PATCH",headers:c(),body:JSON.stringify({title:w})})).ok)throw new Error("Failed to update thread title");await d()}catch(P){i(D=>({...D,error:P instanceof Error?P.message:"Failed to update thread title"}))}},[t,d,c]),A=L.useCallback(async x=>{if(s.currentThreadId)try{const w=Te(x),P={id:`temp-${Date.now()}`,role:"human",content:w,timestamp:new Date().toISOString()};i(D=>({...D,messages:[...D.messages,P],isLoading:!0,error:null}));try{const D=await fetch(`${t}/stream`,{method:"POST",headers:c(),body:JSON.stringify({thread_id:s.currentThreadId,messages:[...s.messages,{role:"human",content:w}],operation:"continue"})});if(!D.ok){const T=await D.text();throw new Error(`HTTP ${D.status}: ${T}`)}await v(D),await g(s.currentThreadId)}catch(D){i(T=>({...T,messages:T.messages.filter(k=>k.id!==P.id),isLoading:!1,error:D instanceof Error?D.message:"Failed to send message"}))}}catch(w){i(P=>({...P,error:w instanceof Error?w.message:"Invalid message content"}))}},[t,s.currentThreadId,s.messages,g,c]),v=async x=>{var T;const w=(T=x.body)==null?void 0:T.getReader();if(!w){i(k=>({...k,isLoading:!1}));return}const P=new TextDecoder;let D="";try{for(;;){const{done:k,value:M}=await w.read();if(k)break;D+=P.decode(M,{stream:!0});const j=D.split(`
3
+ `);D=j.pop()||"";for(const H of j)if(H.trim()&&H.startsWith("data: "))try{const V=JSON.parse(H.slice(6));V.type==="text"?i(ie=>{const ae=[...ie.messages],Z=ae[ae.length-1];return Z&&Z.role==="ai"?Z.content+=V.text:ae.push({id:`ai-${Date.now()}`,role:"ai",content:V.text,timestamp:new Date().toISOString()}),{...ie,messages:ae}}):V.type==="tool_call"?i(ie=>({...ie,messages:[...ie.messages,{id:`tool-${Date.now()}`,role:"tool",content:V.result||"",name:V.name||"unknown_function",tool_call_id:V.id,args:V.args,timestamp:new Date().toISOString()}]})):V.type==="complete"&&i(ie=>{const ae=[...ie.messages],Z=ae[ae.length-1];if(Z&&Z.role==="ai"&&typeof Z.content=="string"){const Ze=p(Z.content,"ai");Z.content=Ze.content,Z.isMarkdown=Ze.isMarkdown}return{...ie,messages:ae,isLoading:!1}})}catch(V){console.warn("Failed to parse streaming data:",H,V)}}}catch(k){console.error("Streaming error:",k)}finally{i(k=>({...k,isLoading:!1}))}};L.useEffect(()=>{d()},[d]);const b=L.useCallback(async(x,w,P=!1)=>{if(!(!s.currentThreadId||!x.id)){i(D=>({...D,isLoading:!0,error:null}));try{const D=w?P?"edit_from_input":"edit_and_regenerate":"regenerate",T=await fetch(`${t}/stream`,{method:"POST",headers:c(),body:JSON.stringify({thread_id:s.currentThreadId,messages:s.messages,operation:D,from_message_id:x.id,edited_content:w,create_branch:!!w})});if(!T.ok){const k=await T.text();throw new Error(`HTTP ${T.status}: ${k}`)}await v(T),await Promise.all([g(s.currentThreadId),m(s.currentThreadId)])}catch(D){i(T=>({...T,isLoading:!1,error:D instanceof Error?D.message:"Failed to regenerate message"}))}}},[t,s.currentThreadId,s.messages,g,m,c]),_=L.useCallback(async(x,w,P=!1,D=!1)=>{if(!(!s.currentThreadId||!x.id)){if(P){await b(x,w,D);return}i(T=>({...T,messages:T.messages.map(k=>k.id===x.id?{...k,content:w}:k)}))}},[s.currentThreadId,b]),N=L.useCallback(async x=>{if(s.currentThreadId)try{if(!(await fetch(`${t}/threads/${s.currentThreadId}/branch`,{method:"PATCH",headers:c(),body:JSON.stringify({branch_id:x})})).ok)throw new Error("Failed to switch branch");i(P=>({...P,currentBranch:x})),await g(s.currentThreadId)}catch(w){i(P=>({...P,error:w instanceof Error?w.message:"Failed to switch branch"}))}},[t,s.currentThreadId,g,c]),I=L.useCallback(()=>{i(x=>({...x,isLoading:!1}))},[]),$=L.useCallback(()=>{i(x=>({...x,error:null}))},[]),z=L.useCallback(async()=>{await d(),s.currentThreadId&&await Promise.all([g(s.currentThreadId),m(s.currentThreadId)])},[d,g,m,s.currentThreadId]),W={...s,selectThread:y,createThread:C,deleteThread:S,updateThreadTitle:E,sendMessage:A,editMessage:_,regenerateFromMessage:b,stop:I,switchBranch:N,clearError:$,refresh:z};return a.jsx(kt.Provider,{value:W,children:e})}function pe(){const e=L.useContext(kt);if(!e)throw new Error("useChat must be used within a ChatProvider");return e}function Y(...e){return vn.twMerge(mn.clsx(e))}const Tn=Pt.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),B=u.forwardRef(({className:e,variant:t,size:r,asChild:n=!1,...o},s)=>{const i=n?Re.Slot:"button";return a.jsx(i,{className:Y(Tn({variant:t,size:r,className:e})),ref:s,...o})});B.displayName="Button";const De=u.forwardRef(({className:e,...t},r)=>a.jsx("textarea",{className:Y("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...t}));De.displayName="Textarea";function rt({message:e,onRegenerate:t,onEditMessage:r,showRegenerate:n=!1,showBranches:o=!1,branches:s=[],onSwitchBranch:i}){var A;const[l,f]=L.useState(!1),[c,d]=L.useState(!1),[h,p]=L.useState(typeof e.content=="string"?e.content:JSON.stringify(e.content)),g=()=>{t&&t(e)},m=()=>{try{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content),b=Te(h);b.trim()&&b!==v&&r&&r(e,b.trim(),!0)}catch(v){console.error("Error validating edit content:",v)}d(!1)},y=()=>{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content);p(v),d(!1)},C=()=>{switch(e.role){case"human":return a.jsx(F.User,{size:20,className:"text-blue-600"});case"ai":return a.jsx(F.Bot,{size:20,className:"text-green-600"});case"tool":return a.jsx(F.Wrench,{size:20,className:"text-orange-600"});default:return a.jsx(F.Bot,{size:20,className:"text-gray-600"})}},S=()=>{switch(e.role){case"human":return"You";case"ai":return"Assistant";case"tool":return e.name||"Tool";default:return"Message"}},E=()=>{try{return typeof e.content=="string"?de(e.content):e.role==="tool"&&e.args?de(JSON.stringify(e.args,null,2)):de(JSON.stringify(e.content,null,2))}catch(v){return console.warn("Error formatting message content:",v),"[Content formatting error]"}};return console.log("Rendering message:",e),e.role==="human"?a.jsxs("div",{className:"flex gap-3 justify-end mb-4",children:[a.jsxs("div",{className:"max-w-[80%] rounded-lg p-4 relative group",style:{backgroundColor:"#2563eb",color:"white",border:"2px solid #1d4ed8",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)"},children:[e.id&&r&&a.jsx("div",{className:"absolute -top-1 -right-1 flex space-x-1 opacity-0 group-hover:opacity-100 transition-opacity",children:c?a.jsxs(a.Fragment,{children:[a.jsx(B,{size:"sm",variant:"ghost",onClick:m,className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Save changes and regenerate",children:a.jsx(F.Check,{className:"h-3 w-3"})}),a.jsx(B,{size:"sm",variant:"ghost",onClick:y,className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Cancel editing",children:a.jsx(F.X,{className:"h-3 w-3"})})]}):a.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content);r(e,v,!1,!0)},className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Edit message in input field and create branch",children:a.jsx(F.Edit2,{className:"h-3 w-3"})})}),a.jsx("div",{className:"whitespace-pre-wrap",style:{color:"white"},children:c?a.jsx(De,{value:h,onChange:v=>p(v.target.value),className:"w-full min-h-[60px] bg-white/10 border-white/20 text-white placeholder-white/70",placeholder:"Edit your message...",autoFocus:!0}):a.jsx("span",{style:{color:"white"},children:de(((A=e.content)==null?void 0:A.toString())||"[No content]")})}),e.timestamp&&!c&&a.jsx("div",{className:"text-xs opacity-70 mt-2",style:{color:"white"},children:new Date(e.timestamp).toLocaleTimeString()})]}),a.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center",children:C()})]}):a.jsxs("div",{className:"flex gap-3 justify-start mb-4",children:[a.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center",children:C()}),a.jsxs("div",{className:`
3
4
  max-w-[80%] rounded-lg p-3 relative group
4
5
  ${e.role==="tool"?"bg-orange-50 border border-orange-200":"bg-gray-100 text-gray-900"}
5
- `,children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"font-medium text-sm",children:S()}),e.role==="tool"&&a.jsxs(j,{variant:"ghost",size:"sm",onClick:()=>f(!l),className:"h-6 px-2 text-xs",children:[l?a.jsx(W.ChevronDown,{size:12}):a.jsx(W.ChevronRight,{size:12}),l?"Hide":"Show"," Content"]})]}),n&&t&&a.jsxs(j,{variant:"ghost",size:"sm",onClick:g,className:"h-6 px-2 text-xs",children:[a.jsx(W.RotateCcw,{size:12,className:"mr-1"}),"Regenerate"]})]}),o&&s&&s.length>1&&e.role==="ai"&&a.jsxs("div",{className:"flex items-center gap-2 mb-3 p-2 bg-white/50 rounded border text-xs",children:[a.jsx(W.GitBranch,{size:12,className:"text-gray-500"}),a.jsx("span",{className:"text-gray-600",children:"Branch:"}),a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>{const m=s.findIndex(_=>_.is_current),w=m>0?m-1:s.length-1;i==null||i(s[w].branch_id)},className:"h-5 w-5 p-0",title:"Previous branch",children:a.jsx(W.ChevronLeft,{size:10})}),a.jsxs("span",{className:"mx-2 font-mono text-xs",children:[s.findIndex(m=>m.is_current)+1," / ",s.length]}),a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>{const m=s.findIndex(_=>_.is_current),w=m<s.length-1?m+1:0;i==null||i(s[w].branch_id)},className:"h-5 w-5 p-0",title:"Next branch",children:a.jsx(W.ChevronRight,{size:10})})]}),s.map((m,w)=>a.jsx(j,{variant:m.is_current?"default":"ghost",size:"sm",onClick:()=>i==null?void 0:i(m.branch_id),className:"h-5 px-2 text-xs",title:`Switch to branch ${w+1}: ${m.preview}`,children:w+1},m.branch_id))]}),(e.role!=="tool"||l)&&a.jsx("div",{className:`whitespace-pre-wrap ${e.role==="tool"?"font-mono text-sm":""}`,children:E()}),e.timestamp&&a.jsx("div",{className:"text-xs opacity-70 mt-2",children:new Date(e.timestamp).toLocaleTimeString()})]})]})}function he({className:e="",placeholder:t="Type your message...",autoFocus:r=!0,showBranches:n=!0,maxHeight:o="600px",enableInputFieldEditing:s=!1}){const{currentThreadId:i,messages:l,isLoading:f,isLoadingHistory:c,error:d,availableBranches:h,currentBranch:p,sendMessage:g,stop:v,switchBranch:y,regenerateFromMessage:C,editMessage:S,clearError:E}=fe(),[P,m]=L.useState(""),[w,_]=L.useState(null),[T,k]=L.useState(null),I=L.useRef(null),z=L.useRef(null);L.useEffect(()=>{var N;(N=I.current)==null||N.scrollIntoView({behavior:"smooth"})},[l]),L.useEffect(()=>{r&&z.current&&z.current.focus()},[r,i]);const x=async N=>{if(N.preventDefault(),!(!P.trim()||f||!i))try{const H=Se(P.trim());m(""),k(null),w&&s?(await b(w,H),_(null)):await g(H)}catch(H){k(H instanceof Error?H.message:"Invalid input")}},b=async(N,H)=>{try{const M=l.find($=>$.id===N);if(!M)return;const B=Se(H);await S(M,B,!0,!0)}catch(M){k(M instanceof Error?M.message:"Invalid edit content")}},A=N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),x(N)):N.key==="Escape"&&w&&(_(null),m(""),k(null))},D=async N=>{await C(N)},F=async(N,H,M=!1,B=!1)=>{B?(_(N.id),m(H),setTimeout(()=>{var $;return($=z.current)==null?void 0:$.focus()},0)):await S(N,H,M)};return i?a.jsxs("div",{className:`flex flex-col h-full ${e}`,children:[T&&a.jsx("div",{className:"bg-red-50 border-l-4 border-red-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("div",{className:"text-red-700 text-sm",children:T}),a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>k(null),className:"text-red-600 hover:text-red-700",children:"×"})]})}),d&&a.jsx("div",{className:"bg-red-50 border-l-4 border-red-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("div",{className:"text-red-700 text-sm",children:d}),a.jsx(j,{variant:"ghost",size:"sm",onClick:E,className:"text-red-600 hover:text-red-700",children:"×"})]})}),w&&s&&a.jsx("div",{className:"bg-blue-50 border-l-4 border-blue-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsxs("div",{className:"text-blue-700 text-sm flex items-center",children:[a.jsx(W.Edit3,{size:16,className:"mr-2"}),"Editing message - modify your text below and press Enter to create a new branch"]}),a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>{_(null),m(""),k(null)},className:"text-blue-600 hover:text-blue-700",children:a.jsx(W.X,{size:16})})]})}),n&&h.length>1&&a.jsxs("div",{className:"border-b p-3 bg-gray-50",children:[a.jsx("div",{className:"text-sm font-medium mb-2",children:"Branches:"}),a.jsx("div",{className:"flex gap-2 flex-wrap",children:h.map(N=>a.jsxs(j,{size:"sm",variant:p===N.branch_id?"default":"outline",onClick:()=>y(N.branch_id),className:"text-xs",children:[N.preview,a.jsxs("span",{className:"ml-1 text-gray-500",children:["(",N.message_count,")"]})]},N.branch_id))})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto p-4",style:{maxHeight:o},children:[c?a.jsxs("div",{className:"flex items-center justify-center py-8",children:[a.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),a.jsx("span",{className:"ml-2 text-gray-600",children:"Loading conversation..."})]}):l.length===0?a.jsxs("div",{className:"text-center text-gray-500 py-8",children:[a.jsx("div",{className:"text-lg font-medium mb-2",children:"Start a conversation"}),a.jsx("div",{className:"text-sm",children:"Type a message below to begin"})]}):a.jsx("div",{className:"space-y-4",children:l.map((N,H)=>{const M=h?h.filter($=>$.from_message_index===H):[],B=M.length>1;return M.find($=>$.branch_id===p),a.jsxs("div",{children:[B&&n&&a.jsxs("div",{className:"flex items-center gap-2 mb-2 p-2 bg-gray-50 rounded border text-xs",children:[a.jsx("span",{className:"text-gray-600",children:"Message versions:"}),a.jsx("div",{className:"flex items-center gap-1",children:M.map(($,Y)=>a.jsx(j,{variant:p===$.branch_id?"default":"outline",size:"sm",onClick:()=>y($.branch_id),className:"h-6 px-2 text-xs",title:`Version ${Y+1}: ${$.preview}`,children:Y+1},$.branch_id))}),a.jsxs("span",{className:"text-gray-500 ml-2",children:["(",M.findIndex($=>$.branch_id===p)+1," of ",M.length,")"]})]}),a.jsx(et,{message:N,onRegenerate:D,onEditMessage:F,showRegenerate:N.role==="ai"||N.role==="human",showBranches:!1,branches:M,onSwitchBranch:y})]},N.id||H)})}),a.jsx("div",{ref:I})]}),a.jsx("div",{className:"border-t p-4 bg-white",children:a.jsxs("form",{onSubmit:x,className:"flex gap-3",children:[a.jsx("div",{className:"flex-1",children:a.jsx(_e,{ref:z,value:P,onChange:N=>{m(N.target.value),k(null)},onKeyDown:A,placeholder:w?"Edit your message and press Enter to create a new branch...":t,className:`resize-none min-h-[44px] max-h-32 ${w?"border-blue-400 bg-blue-50":""} ${T?"border-red-400":""}`,disabled:f,maxLength:Qe})}),a.jsx("div",{className:"flex flex-col gap-2",children:f?a.jsx(j,{type:"button",onClick:v,size:"icon",variant:"outline",className:"shrink-0",children:a.jsx(W.Square,{size:16})}):a.jsx(j,{type:"submit",disabled:!P.trim()||!i,size:"icon",className:`shrink-0 ${w?"bg-blue-600 hover:bg-blue-700":""}`,title:w?"Send edited message and create branch":"Send message",children:w?a.jsx(W.Check,{size:16}):a.jsx(W.Send,{size:16})})})]})})]}):a.jsx("div",{className:`flex items-center justify-center h-full ${e}`,children:a.jsxs("div",{className:"text-center text-gray-500",children:[a.jsx("div",{className:"text-lg font-medium mb-2",children:"No thread selected"}),a.jsx("div",{className:"text-sm",children:"Select a thread or create a new one to start chatting"})]})})}var Cn=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],U=Cn.reduce((e,t)=>{const r=Ze.createSlot(`Primitive.${t}`),n=u.forwardRef((o,s)=>{const{asChild:i,...l}=o,f=i?r:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(f,{...l,ref:s})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function Sn(e,t){e&&Pt.flushSync(()=>e.dispatchEvent(t))}function _t(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function En(...e){return t=>{let r=!1;const n=e.map(o=>{const s=_t(o,t);return!r&&typeof s=="function"&&(r=!0),s});if(r)return()=>{for(let o=0;o<n.length;o++){const s=n[o];typeof s=="function"?s():_t(e[o],null)}}}}function q(...e){return u.useCallback(En(...e),e)}var le=globalThis!=null&&globalThis.document?u.useLayoutEffect:()=>{};function Tn(e,t){return u.useReducer((r,n)=>t[r][n]??r,e)}var pe=e=>{const{present:t,children:r}=e,n=Nn(t),o=typeof r=="function"?r({present:n.isPresent}):u.Children.only(r),s=q(n.ref,Pn(o));return typeof r=="function"||n.isPresent?u.cloneElement(o,{ref:s}):null};pe.displayName="Presence";function Nn(e){const[t,r]=u.useState(),n=u.useRef(null),o=u.useRef(e),s=u.useRef("none"),i=e?"mounted":"unmounted",[l,f]=Tn(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return u.useEffect(()=>{const c=De(n.current);s.current=l==="mounted"?c:"none"},[l]),le(()=>{const c=n.current,d=o.current;if(d!==e){const p=s.current,g=De(c);e?f("MOUNT"):g==="none"||(c==null?void 0:c.display)==="none"?f("UNMOUNT"):f(d&&p!==g?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,f]),le(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,h=g=>{const y=De(n.current).includes(g.animationName);if(g.target===t&&y&&(f("ANIMATION_END"),!o.current)){const C=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=C)})}},p=g=>{g.target===t&&(s.current=De(n.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:u.useCallback(c=>{n.current=c?getComputedStyle(c):null,r(c)},[])}}function De(e){return(e==null?void 0:e.animationName)||"none"}function Pn(e){var n,o;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}function tt(e,t=[]){let r=[];function n(s,i){const l=u.createContext(i),f=r.length;r=[...r,i];const c=h=>{var S;const{scope:p,children:g,...v}=h,y=((S=p==null?void 0:p[e])==null?void 0:S[f])||l,C=u.useMemo(()=>v,Object.values(v));return a.jsx(y.Provider,{value:C,children:g})};c.displayName=s+"Provider";function d(h,p){var y;const g=((y=p==null?void 0:p[e])==null?void 0:y[f])||l,v=u.useContext(g);if(v)return v;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=r.map(i=>u.createContext(i));return function(l){const f=(l==null?void 0:l[e])||s;return u.useMemo(()=>({[`__scope${e}`]:{...l,[e]:f}}),[l,f])}};return o.scopeName=e,[n,An(o,...t)]}function An(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=n.reduce((l,{useScope:f,scopeName:c})=>{const h=f(s)[`__scope${c}`];return{...l,...h}},{});return u.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return r.scopeName=t.scopeName,r}function Z(e){const t=u.useRef(e);return u.useEffect(()=>{t.current=e}),u.useMemo(()=>(...r)=>{var n;return(n=t.current)==null?void 0:n.call(t,...r)},[])}var On=u.createContext(void 0);function Ln(e){const t=u.useContext(On);return e||t||"ltr"}function _n(e,[t,r]){return Math.min(r,Math.max(t,e))}function V(e,t,{checkForDefaultPrevented:r=!0}={}){return function(o){if(e==null||e(o),r===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function Dn(e,t){return u.useReducer((r,n)=>t[r][n]??r,e)}var rt="ScrollArea",[Dt,Ti]=tt(rt),[Mn,K]=Dt(rt),Mt=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:n="hover",dir:o,scrollHideDelay:s=600,...i}=e,[l,f]=u.useState(null),[c,d]=u.useState(null),[h,p]=u.useState(null),[g,v]=u.useState(null),[y,C]=u.useState(null),[S,E]=u.useState(0),[P,m]=u.useState(0),[w,_]=u.useState(!1),[T,k]=u.useState(!1),I=q(t,x=>f(x)),z=Ln(o);return a.jsx(Mn,{scope:r,type:n,dir:z,scrollHideDelay:s,scrollArea:l,viewport:c,onViewportChange:d,content:h,onContentChange:p,scrollbarX:g,onScrollbarXChange:v,scrollbarXEnabled:w,onScrollbarXEnabledChange:_,scrollbarY:y,onScrollbarYChange:C,scrollbarYEnabled:T,onScrollbarYEnabledChange:k,onCornerWidthChange:E,onCornerHeightChange:m,children:a.jsx(U.div,{dir:z,...i,ref:I,style:{position:"relative","--radix-scroll-area-corner-width":S+"px","--radix-scroll-area-corner-height":P+"px",...e.style}})})});Mt.displayName=rt;var kt="ScrollAreaViewport",It=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:n,nonce:o,...s}=e,i=K(kt,r),l=u.useRef(null),f=q(t,l,i.onViewportChange);return a.jsxs(a.Fragment,{children:[a.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}),a.jsx(U.div,{"data-radix-scroll-area-viewport":"",...s,ref:f,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:a.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:n})})]})});It.displayName=kt;var ee="ScrollAreaScrollbar",nt=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(ee,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,l=e.orientation==="horizontal";return u.useEffect(()=>(l?s(!0):i(!0),()=>{l?s(!1):i(!1)}),[l,s,i]),o.type==="hover"?a.jsx(kn,{...n,ref:t,forceMount:r}):o.type==="scroll"?a.jsx(In,{...n,ref:t,forceMount:r}):o.type==="auto"?a.jsx(zt,{...n,ref:t,forceMount:r}):o.type==="always"?a.jsx(ot,{...n,ref:t}):null});nt.displayName=ee;var kn=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(ee,e.__scopeScrollArea),[s,i]=u.useState(!1);return u.useEffect(()=>{const l=o.scrollArea;let f=0;if(l){const c=()=>{window.clearTimeout(f),i(!0)},d=()=>{f=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return l.addEventListener("pointerenter",c),l.addEventListener("pointerleave",d),()=>{window.clearTimeout(f),l.removeEventListener("pointerenter",c),l.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),a.jsx(pe,{present:r||s,children:a.jsx(zt,{"data-state":s?"visible":"hidden",...n,ref:t})})}),In=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(ee,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ze(()=>f("SCROLL_END"),100),[l,f]=Dn("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 u.useEffect(()=>{if(l==="idle"){const c=window.setTimeout(()=>f("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[l,o.scrollHideDelay,f]),u.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let h=c[d];const p=()=>{const g=c[d];h!==g&&(f("SCROLL"),i()),h=g};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,f,i]),a.jsx(pe,{present:r||l!=="hidden",children:a.jsx(ot,{"data-state":l==="hidden"?"hidden":"visible",...n,ref:t,onPointerEnter:V(e.onPointerEnter,()=>f("POINTER_ENTER")),onPointerLeave:V(e.onPointerLeave,()=>f("POINTER_LEAVE"))})})}),zt=u.forwardRef((e,t)=>{const r=K(ee,e.__scopeScrollArea),{forceMount:n,...o}=e,[s,i]=u.useState(!1),l=e.orientation==="horizontal",f=ze(()=>{if(r.viewport){const c=r.viewport.offsetWidth<r.viewport.scrollWidth,d=r.viewport.offsetHeight<r.viewport.scrollHeight;i(l?c:d)}},10);return ge(r.viewport,f),ge(r.content,f),a.jsx(pe,{present:n||s,children:a.jsx(ot,{"data-state":s?"visible":"hidden",...o,ref:t})})}),ot=u.forwardRef((e,t)=>{const{orientation:r="vertical",...n}=e,o=K(ee,e.__scopeScrollArea),s=u.useRef(null),i=u.useRef(0),[l,f]=u.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Bt(l.viewport,l.content),d={...n,sizes:l,onSizesChange:f,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function h(p,g){return Bn(p,i.current,l,g)}return r==="horizontal"?a.jsx(zn,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,g=jt(p,l,o.dir);s.current.style.transform=`translate3d(${g}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=h(p,o.dir))}}):r==="vertical"?a.jsx($n,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,g=jt(p,l);s.current.style.transform=`translate3d(0, ${g}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=h(p))}}):null}),zn=u.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=K(ee,e.__scopeScrollArea),[i,l]=u.useState(),f=u.useRef(null),c=q(t,f,s.onScrollbarXChange);return u.useEffect(()=>{f.current&&l(getComputedStyle(f.current))},[f]),a.jsx(Ft,{"data-orientation":"horizontal",...o,ref:c,sizes:r,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":Ie(r)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,h)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Xt(p,h)&&d.preventDefault()}},onResize:()=>{f.current&&s.viewport&&i&&n({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:f.current.clientWidth,paddingStart:ke(i.paddingLeft),paddingEnd:ke(i.paddingRight)}})}})}),$n=u.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=K(ee,e.__scopeScrollArea),[i,l]=u.useState(),f=u.useRef(null),c=q(t,f,s.onScrollbarYChange);return u.useEffect(()=>{f.current&&l(getComputedStyle(f.current))},[f]),a.jsx(Ft,{"data-orientation":"vertical",...o,ref:c,sizes:r,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":Ie(r)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,h)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Xt(p,h)&&d.preventDefault()}},onResize:()=>{f.current&&s.viewport&&i&&n({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:f.current.clientHeight,paddingStart:ke(i.paddingTop),paddingEnd:ke(i.paddingBottom)}})}})}),[Fn,$t]=Dt(ee),Ft=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:n,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:l,onThumbPositionChange:f,onDragScroll:c,onWheelScroll:d,onResize:h,...p}=e,g=K(ee,r),[v,y]=u.useState(null),C=q(t,I=>y(I)),S=u.useRef(null),E=u.useRef(""),P=g.viewport,m=n.content-n.viewport,w=Z(d),_=Z(f),T=ze(h,10);function k(I){if(S.current){const z=I.clientX-S.current.left,x=I.clientY-S.current.top;c({x:z,y:x})}}return u.useEffect(()=>{const I=z=>{const x=z.target;(v==null?void 0:v.contains(x))&&w(z,m)};return document.addEventListener("wheel",I,{passive:!1}),()=>document.removeEventListener("wheel",I,{passive:!1})},[P,v,m,w]),u.useEffect(_,[n,_]),ge(v,T),ge(g.content,T),a.jsx(Fn,{scope:r,scrollbar:v,hasThumb:o,onThumbChange:Z(s),onThumbPointerUp:Z(i),onThumbPositionChange:_,onThumbPointerDown:Z(l),children:a.jsx(U.div,{...p,ref:C,style:{position:"absolute",...p.style},onPointerDown:V(e.onPointerDown,I=>{I.button===0&&(I.target.setPointerCapture(I.pointerId),S.current=v.getBoundingClientRect(),E.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",g.viewport&&(g.viewport.style.scrollBehavior="auto"),k(I))}),onPointerMove:V(e.onPointerMove,k),onPointerUp:V(e.onPointerUp,I=>{const z=I.target;z.hasPointerCapture(I.pointerId)&&z.releasePointerCapture(I.pointerId),document.body.style.webkitUserSelect=E.current,g.viewport&&(g.viewport.style.scrollBehavior=""),S.current=null})})})}),Me="ScrollAreaThumb",Ht=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=$t(Me,e.__scopeScrollArea);return a.jsx(pe,{present:r||o.hasThumb,children:a.jsx(Hn,{ref:t,...n})})}),Hn=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:n,...o}=e,s=K(Me,r),i=$t(Me,r),{onThumbPositionChange:l}=i,f=q(t,h=>i.onThumbChange(h)),c=u.useRef(void 0),d=ze(()=>{c.current&&(c.current(),c.current=void 0)},100);return u.useEffect(()=>{const h=s.viewport;if(h){const p=()=>{if(d(),!c.current){const g=jn(h,l);c.current=g,l()}};return l(),h.addEventListener("scroll",p),()=>h.removeEventListener("scroll",p)}},[s.viewport,d,l]),a.jsx(U.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:f,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...n},onPointerDownCapture:V(e.onPointerDownCapture,h=>{const g=h.target.getBoundingClientRect(),v=h.clientX-g.left,y=h.clientY-g.top;i.onThumbPointerDown({x:v,y})}),onPointerUp:V(e.onPointerUp,i.onThumbPointerUp)})});Ht.displayName=Me;var st="ScrollAreaCorner",Wt=u.forwardRef((e,t)=>{const r=K(st,e.__scopeScrollArea),n=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&n?a.jsx(Wn,{...e,ref:t}):null});Wt.displayName=st;var Wn=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,...n}=e,o=K(st,r),[s,i]=u.useState(0),[l,f]=u.useState(0),c=!!(s&&l);return ge(o.scrollbarX,()=>{var h;const d=((h=o.scrollbarX)==null?void 0:h.offsetHeight)||0;o.onCornerHeightChange(d),f(d)}),ge(o.scrollbarY,()=>{var h;const d=((h=o.scrollbarY)==null?void 0:h.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?a.jsx(U.div,{...n,ref:t,style:{width:s,height:l,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function ke(e){return e?parseInt(e,10):0}function Bt(e,t){const r=e/t;return isNaN(r)?0:r}function Ie(e){const t=Bt(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,n=(e.scrollbar.size-r)*t;return Math.max(n,18)}function Bn(e,t,r,n="ltr"){const o=Ie(r),s=o/2,i=t||s,l=o-i,f=r.scrollbar.paddingStart+i,c=r.scrollbar.size-r.scrollbar.paddingEnd-l,d=r.content-r.viewport,h=n==="ltr"?[0,d]:[d*-1,0];return Vt([f,c],h)(e)}function jt(e,t,r="ltr"){const n=Ie(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,l=s-n,f=r==="ltr"?[0,i]:[i*-1,0],c=_n(e,f);return Vt([0,i],[0,l])(c)}function Vt(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const n=(t[1]-t[0])/(e[1]-e[0]);return t[0]+n*(r-e[0])}}function Xt(e,t){return e>0&&e<t}var jn=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},n=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=r.left!==s.left,l=r.top!==s.top;(i||l)&&t(),r=s,n=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(n)};function ze(e,t){const r=Z(e),n=u.useRef(0);return u.useEffect(()=>()=>window.clearTimeout(n.current),[]),u.useCallback(()=>{window.clearTimeout(n.current),n.current=window.setTimeout(r,t)},[r,t])}function ge(e,t){const r=Z(t);le(()=>{let n=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(n),n=window.requestAnimationFrame(r)});return o.observe(e),()=>{window.cancelAnimationFrame(n),o.unobserve(e)}}},[e,r])}var Yt=Mt,Vn=It,Xn=Wt;const it=u.forwardRef(({className:e,children:t,...r},n)=>a.jsxs(Yt,{ref:n,className:X("relative overflow-hidden",e),...r,children:[a.jsx(Vn,{className:"h-full w-full rounded-[inherit]",children:t}),a.jsx(Ut,{}),a.jsx(Xn,{})]}));it.displayName=Yt.displayName;const Ut=u.forwardRef(({className:e,orientation:t="vertical",...r},n)=>a.jsx(nt,{ref:n,orientation:t,className:X("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...r,children:a.jsx(Ht,{className:"relative flex-1 rounded-full bg-border"})}));Ut.displayName=nt.displayName;function me({className:e="",showCreateButton:t=!0,onThreadSelect:r}){const{currentThreadId:n,threads:o,loadingThreads:s,selectThread:i,createThread:l,deleteThread:f,updateThreadTitle:c}=fe();console.log("ThreadManager rendered, deleteThread available:",typeof f);const[d,h]=L.useState(null),[p,g]=L.useState(""),v=async m=>{await i(m),r==null||r(m)},y=async()=>{const m=await l();await v(m)},C=async(m,w)=>{console.log("handleDeleteThread called with threadId:",w),m.stopPropagation();const _=confirm("Are you sure you want to delete this thread?");if(console.log("User confirmed deletion:",_),_){console.log("Calling deleteThread from ChatProvider...");try{await f(w),console.log("deleteThread completed successfully")}catch(T){console.error("Error in handleDeleteThread:",T)}}},S=(m,w)=>{m.stopPropagation(),h(w.id),g(w.title||`Thread ${w.id.slice(0,8)}`)},E=async m=>{await c(m,p),h(null)},P=()=>{h(null),g("")};return s?a.jsx("div",{className:`p-4 ${e}`,children:a.jsx("div",{className:"animate-pulse space-y-2",children:[...Array(3)].map((m,w)=>a.jsx("div",{className:"h-10 bg-gray-200 rounded"},w))})}):a.jsxs("div",{className:`p-4 ${e}`,children:[t&&a.jsxs(j,{onClick:y,className:"w-full mb-4 flex items-center gap-2",variant:"outline",children:[a.jsx(W.Plus,{size:16}),"New Thread"]}),a.jsx(it,{className:"h-[calc(100vh-12rem)]",children:a.jsxs("div",{className:"space-y-2 pr-4",children:[o.map(m=>a.jsx("div",{className:`
6
+ `,children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"font-medium text-sm",children:S()}),e.role==="tool"&&a.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>f(!l),className:"h-6 px-2 text-xs",children:[l?a.jsx(F.ChevronDown,{size:12}):a.jsx(F.ChevronRight,{size:12}),l?"Hide":"Show"," Content"]})]}),n&&t&&a.jsxs(B,{variant:"ghost",size:"sm",onClick:g,className:"h-6 px-2 text-xs",children:[a.jsx(F.RotateCcw,{size:12,className:"mr-1"}),"Regenerate"]})]}),o&&s&&s.length>1&&e.role==="ai"&&a.jsxs("div",{className:"flex items-center gap-2 mb-3 p-2 bg-white/50 rounded border text-xs",children:[a.jsx(F.GitBranch,{size:12,className:"text-gray-500"}),a.jsx("span",{className:"text-gray-600",children:"Branch:"}),a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{const v=s.findIndex(_=>_.is_current),b=v>0?v-1:s.length-1;i==null||i(s[b].branch_id)},className:"h-5 w-5 p-0",title:"Previous branch",children:a.jsx(F.ChevronLeft,{size:10})}),a.jsxs("span",{className:"mx-2 font-mono text-xs",children:[s.findIndex(v=>v.is_current)+1," / ",s.length]}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{const v=s.findIndex(_=>_.is_current),b=v<s.length-1?v+1:0;i==null||i(s[b].branch_id)},className:"h-5 w-5 p-0",title:"Next branch",children:a.jsx(F.ChevronRight,{size:10})})]}),s.map((v,b)=>a.jsx(B,{variant:v.is_current?"default":"ghost",size:"sm",onClick:()=>i==null?void 0:i(v.branch_id),className:"h-5 px-2 text-xs",title:`Switch to branch ${b+1}: ${v.preview}`,children:b+1},v.branch_id))]}),(e.role!=="tool"||l)&&a.jsx("div",{className:`whitespace-pre-wrap ${e.role==="tool"?"font-mono text-sm":""}`,children:E()}),e.timestamp&&a.jsx("div",{className:"text-xs opacity-70 mt-2",children:new Date(e.timestamp).toLocaleTimeString()})]})]})}function me({className:e="",placeholder:t="Type your message...",autoFocus:r=!0,showBranches:n=!0,maxHeight:o="600px",enableInputFieldEditing:s=!1}){const{currentThreadId:i,messages:l,isLoading:f,isLoadingHistory:c,error:d,availableBranches:h,currentBranch:p,sendMessage:g,stop:m,switchBranch:y,regenerateFromMessage:C,editMessage:S,clearError:E}=pe(),[A,v]=L.useState(""),[b,_]=L.useState(null),[N,I]=L.useState(null),$=L.useRef(null),z=L.useRef(null);L.useEffect(()=>{var T;(T=$.current)==null||T.scrollIntoView({behavior:"smooth"})},[l]),L.useEffect(()=>{r&&z.current&&z.current.focus()},[r,i]);const W=async T=>{if(T.preventDefault(),!(!A.trim()||f||!i))try{const k=Te(A.trim());v(""),I(null),b&&s?(await x(b,k),_(null)):await g(k)}catch(k){I(k instanceof Error?k.message:"Invalid input")}},x=async(T,k)=>{try{const M=l.find(H=>H.id===T);if(!M)return;const j=Te(k);await S(M,j,!0,!0)}catch(M){I(M instanceof Error?M.message:"Invalid edit content")}},w=T=>{T.key==="Enter"&&!T.shiftKey?(T.preventDefault(),W(T)):T.key==="Escape"&&b&&(_(null),v(""),I(null))},P=async T=>{await C(T)},D=async(T,k,M=!1,j=!1)=>{j?(_(T.id),v(k),setTimeout(()=>{var H;return(H=z.current)==null?void 0:H.focus()},0)):await S(T,k,M)};return i?a.jsxs("div",{className:`flex flex-col h-full ${e}`,children:[N&&a.jsx("div",{className:"bg-red-50 border-l-4 border-red-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("div",{className:"text-red-700 text-sm",children:N}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>I(null),className:"text-red-600 hover:text-red-700",children:"×"})]})}),d&&a.jsx("div",{className:"bg-red-50 border-l-4 border-red-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("div",{className:"text-red-700 text-sm",children:d}),a.jsx(B,{variant:"ghost",size:"sm",onClick:E,className:"text-red-600 hover:text-red-700",children:"×"})]})}),b&&s&&a.jsx("div",{className:"bg-blue-50 border-l-4 border-blue-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsxs("div",{className:"text-blue-700 text-sm flex items-center",children:[a.jsx(F.Edit3,{size:16,className:"mr-2"}),"Editing message - modify your text below and press Enter to create a new branch"]}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{_(null),v(""),I(null)},className:"text-blue-600 hover:text-blue-700",children:a.jsx(F.X,{size:16})})]})}),n&&h.length>1&&a.jsxs("div",{className:"border-b p-3 bg-gray-50",children:[a.jsx("div",{className:"text-sm font-medium mb-2",children:"Branches:"}),a.jsx("div",{className:"flex gap-2 flex-wrap",children:h.map(T=>a.jsxs(B,{size:"sm",variant:p===T.branch_id?"default":"outline",onClick:()=>y(T.branch_id),className:"text-xs",children:[T.preview,a.jsxs("span",{className:"ml-1 text-gray-500",children:["(",T.message_count,")"]})]},T.branch_id))})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto p-4",style:{maxHeight:o},children:[c?a.jsxs("div",{className:"flex items-center justify-center py-8",children:[a.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),a.jsx("span",{className:"ml-2 text-gray-600",children:"Loading conversation..."})]}):l.length===0?a.jsxs("div",{className:"text-center text-gray-500 py-8",children:[a.jsx("div",{className:"text-lg font-medium mb-2",children:"Start a conversation"}),a.jsx("div",{className:"text-sm",children:"Type a message below to begin"})]}):a.jsx("div",{className:"space-y-4",children:l.map((T,k)=>{const M=h?h.filter(H=>H.from_message_index===k):[],j=M.length>1;return M.find(H=>H.branch_id===p),a.jsxs("div",{children:[j&&n&&a.jsxs("div",{className:"flex items-center gap-2 mb-2 p-2 bg-gray-50 rounded border text-xs",children:[a.jsx("span",{className:"text-gray-600",children:"Message versions:"}),a.jsx("div",{className:"flex items-center gap-1",children:M.map((H,V)=>a.jsx(B,{variant:p===H.branch_id?"default":"outline",size:"sm",onClick:()=>y(H.branch_id),className:"h-6 px-2 text-xs",title:`Version ${V+1}: ${H.preview}`,children:V+1},H.branch_id))}),a.jsxs("span",{className:"text-gray-500 ml-2",children:["(",M.findIndex(H=>H.branch_id===p)+1," of ",M.length,")"]})]}),a.jsx(rt,{message:T,onRegenerate:P,onEditMessage:D,showRegenerate:T.role==="ai"||T.role==="human",showBranches:!1,branches:M,onSwitchBranch:y})]},T.id||k)})}),a.jsx("div",{ref:$})]}),a.jsx("div",{className:"border-t p-4 bg-white",children:a.jsxs("form",{onSubmit:W,className:"flex gap-3",children:[a.jsx("div",{className:"flex-1",children:a.jsx(De,{ref:z,value:A,onChange:T=>{v(T.target.value),I(null)},onKeyDown:w,placeholder:b?"Edit your message and press Enter to create a new branch...":t,className:`resize-none min-h-[44px] max-h-32 ${b?"border-blue-400 bg-blue-50":""} ${N?"border-red-400":""}`,disabled:f,maxLength:et})}),a.jsx("div",{className:"flex flex-col gap-2",children:f?a.jsx(B,{type:"button",onClick:m,size:"icon",variant:"outline",className:"shrink-0",children:a.jsx(F.Square,{size:16})}):a.jsx(B,{type:"submit",disabled:!A.trim()||!i,size:"icon",className:`shrink-0 ${b?"bg-blue-600 hover:bg-blue-700":""}`,title:b?"Send edited message and create branch":"Send message",children:b?a.jsx(F.Check,{size:16}):a.jsx(F.Send,{size:16})})})]})})]}):a.jsx("div",{className:`flex items-center justify-center h-full ${e}`,children:a.jsxs("div",{className:"text-center text-gray-500",children:[a.jsx("div",{className:"text-lg font-medium mb-2",children:"No thread selected"}),a.jsx("div",{className:"text-sm",children:"Select a thread or create a new one to start chatting"})]})})}var Nn=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],U=Nn.reduce((e,t)=>{const r=Re.createSlot(`Primitive.${t}`),n=u.forwardRef((o,s)=>{const{asChild:i,...l}=o,f=i?r:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(f,{...l,ref:s})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function Pn(e,t){e&&Ot.flushSync(()=>e.dispatchEvent(t))}function It(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function An(...e){return t=>{let r=!1;const n=e.map(o=>{const s=It(o,t);return!r&&typeof s=="function"&&(r=!0),s});if(r)return()=>{for(let o=0;o<n.length;o++){const s=n[o];typeof s=="function"?s():It(e[o],null)}}}}function q(...e){return u.useCallback(An(...e),e)}var fe=globalThis!=null&&globalThis.document?u.useLayoutEffect:()=>{};function On(e,t){return u.useReducer((r,n)=>t[r][n]??r,e)}var ve=e=>{const{present:t,children:r}=e,n=Ln(t),o=typeof r=="function"?r({present:n.isPresent}):u.Children.only(r),s=q(n.ref,_n(o));return typeof r=="function"||n.isPresent?u.cloneElement(o,{ref:s}):null};ve.displayName="Presence";function Ln(e){const[t,r]=u.useState(),n=u.useRef(null),o=u.useRef(e),s=u.useRef("none"),i=e?"mounted":"unmounted",[l,f]=On(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return u.useEffect(()=>{const c=Me(n.current);s.current=l==="mounted"?c:"none"},[l]),fe(()=>{const c=n.current,d=o.current;if(d!==e){const p=s.current,g=Me(c);e?f("MOUNT"):g==="none"||(c==null?void 0:c.display)==="none"?f("UNMOUNT"):f(d&&p!==g?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,f]),fe(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,h=g=>{const y=Me(n.current).includes(g.animationName);if(g.target===t&&y&&(f("ANIMATION_END"),!o.current)){const C=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=C)})}},p=g=>{g.target===t&&(s.current=Me(n.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:u.useCallback(c=>{n.current=c?getComputedStyle(c):null,r(c)},[])}}function Me(e){return(e==null?void 0:e.animationName)||"none"}function _n(e){var n,o;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}function nt(e,t=[]){let r=[];function n(s,i){const l=u.createContext(i),f=r.length;r=[...r,i];const c=h=>{var S;const{scope:p,children:g,...m}=h,y=((S=p==null?void 0:p[e])==null?void 0:S[f])||l,C=u.useMemo(()=>m,Object.values(m));return a.jsx(y.Provider,{value:C,children:g})};c.displayName=s+"Provider";function d(h,p){var y;const g=((y=p==null?void 0:p[e])==null?void 0:y[f])||l,m=u.useContext(g);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=r.map(i=>u.createContext(i));return function(l){const f=(l==null?void 0:l[e])||s;return u.useMemo(()=>({[`__scope${e}`]:{...l,[e]:f}}),[l,f])}};return o.scopeName=e,[n,Dn(o,...t)]}function Dn(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=n.reduce((l,{useScope:f,scopeName:c})=>{const h=f(s)[`__scope${c}`];return{...l,...h}},{});return u.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return r.scopeName=t.scopeName,r}function Q(e){const t=u.useRef(e);return u.useEffect(()=>{t.current=e}),u.useMemo(()=>(...r)=>{var n;return(n=t.current)==null?void 0:n.call(t,...r)},[])}var Mn=u.createContext(void 0);function kn(e){const t=u.useContext(Mn);return e||t||"ltr"}function In(e,[t,r]){return Math.min(r,Math.max(t,e))}function X(e,t,{checkForDefaultPrevented:r=!0}={}){return function(o){if(e==null||e(o),r===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function $n(e,t){return u.useReducer((r,n)=>t[r][n]??r,e)}var ot="ScrollArea",[$t,Pi]=nt(ot),[zn,K]=$t(ot),zt=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:n="hover",dir:o,scrollHideDelay:s=600,...i}=e,[l,f]=u.useState(null),[c,d]=u.useState(null),[h,p]=u.useState(null),[g,m]=u.useState(null),[y,C]=u.useState(null),[S,E]=u.useState(0),[A,v]=u.useState(0),[b,_]=u.useState(!1),[N,I]=u.useState(!1),$=q(t,W=>f(W)),z=kn(o);return a.jsx(zn,{scope:r,type:n,dir:z,scrollHideDelay:s,scrollArea:l,viewport:c,onViewportChange:d,content:h,onContentChange:p,scrollbarX:g,onScrollbarXChange:m,scrollbarXEnabled:b,onScrollbarXEnabledChange:_,scrollbarY:y,onScrollbarYChange:C,scrollbarYEnabled:N,onScrollbarYEnabledChange:I,onCornerWidthChange:E,onCornerHeightChange:v,children:a.jsx(U.div,{dir:z,...i,ref:$,style:{position:"relative","--radix-scroll-area-corner-width":S+"px","--radix-scroll-area-corner-height":A+"px",...e.style}})})});zt.displayName=ot;var Ht="ScrollAreaViewport",Ft=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:n,nonce:o,...s}=e,i=K(Ht,r),l=u.useRef(null),f=q(t,l,i.onViewportChange);return a.jsxs(a.Fragment,{children:[a.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}),a.jsx(U.div,{"data-radix-scroll-area-viewport":"",...s,ref:f,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:a.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:n})})]})});Ft.displayName=Ht;var te="ScrollAreaScrollbar",st=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,l=e.orientation==="horizontal";return u.useEffect(()=>(l?s(!0):i(!0),()=>{l?s(!1):i(!1)}),[l,s,i]),o.type==="hover"?a.jsx(Hn,{...n,ref:t,forceMount:r}):o.type==="scroll"?a.jsx(Fn,{...n,ref:t,forceMount:r}):o.type==="auto"?a.jsx(Wt,{...n,ref:t,forceMount:r}):o.type==="always"?a.jsx(it,{...n,ref:t}):null});st.displayName=te;var Hn=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),[s,i]=u.useState(!1);return u.useEffect(()=>{const l=o.scrollArea;let f=0;if(l){const c=()=>{window.clearTimeout(f),i(!0)},d=()=>{f=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return l.addEventListener("pointerenter",c),l.addEventListener("pointerleave",d),()=>{window.clearTimeout(f),l.removeEventListener("pointerenter",c),l.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),a.jsx(ve,{present:r||s,children:a.jsx(Wt,{"data-state":s?"visible":"hidden",...n,ref:t})})}),Fn=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ze(()=>f("SCROLL_END"),100),[l,f]=$n("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 u.useEffect(()=>{if(l==="idle"){const c=window.setTimeout(()=>f("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[l,o.scrollHideDelay,f]),u.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let h=c[d];const p=()=>{const g=c[d];h!==g&&(f("SCROLL"),i()),h=g};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,f,i]),a.jsx(ve,{present:r||l!=="hidden",children:a.jsx(it,{"data-state":l==="hidden"?"hidden":"visible",...n,ref:t,onPointerEnter:X(e.onPointerEnter,()=>f("POINTER_ENTER")),onPointerLeave:X(e.onPointerLeave,()=>f("POINTER_LEAVE"))})})}),Wt=u.forwardRef((e,t)=>{const r=K(te,e.__scopeScrollArea),{forceMount:n,...o}=e,[s,i]=u.useState(!1),l=e.orientation==="horizontal",f=ze(()=>{if(r.viewport){const c=r.viewport.offsetWidth<r.viewport.scrollWidth,d=r.viewport.offsetHeight<r.viewport.scrollHeight;i(l?c:d)}},10);return we(r.viewport,f),we(r.content,f),a.jsx(ve,{present:n||s,children:a.jsx(it,{"data-state":s?"visible":"hidden",...o,ref:t})})}),it=u.forwardRef((e,t)=>{const{orientation:r="vertical",...n}=e,o=K(te,e.__scopeScrollArea),s=u.useRef(null),i=u.useRef(0),[l,f]=u.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Yt(l.viewport,l.content),d={...n,sizes:l,onSizesChange:f,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function h(p,g){return Yn(p,i.current,l,g)}return r==="horizontal"?a.jsx(Wn,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,g=Ut(p,l,o.dir);s.current.style.transform=`translate3d(${g}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=h(p,o.dir))}}):r==="vertical"?a.jsx(Bn,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,g=Ut(p,l);s.current.style.transform=`translate3d(0, ${g}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=h(p))}}):null}),Wn=u.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=K(te,e.__scopeScrollArea),[i,l]=u.useState(),f=u.useRef(null),c=q(t,f,s.onScrollbarXChange);return u.useEffect(()=>{f.current&&l(getComputedStyle(f.current))},[f]),a.jsx(jt,{"data-orientation":"horizontal",...o,ref:c,sizes:r,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":$e(r)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,h)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Jt(p,h)&&d.preventDefault()}},onResize:()=>{f.current&&s.viewport&&i&&n({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:f.current.clientWidth,paddingStart:Ie(i.paddingLeft),paddingEnd:Ie(i.paddingRight)}})}})}),Bn=u.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=K(te,e.__scopeScrollArea),[i,l]=u.useState(),f=u.useRef(null),c=q(t,f,s.onScrollbarYChange);return u.useEffect(()=>{f.current&&l(getComputedStyle(f.current))},[f]),a.jsx(jt,{"data-orientation":"vertical",...o,ref:c,sizes:r,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":$e(r)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,h)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Jt(p,h)&&d.preventDefault()}},onResize:()=>{f.current&&s.viewport&&i&&n({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:f.current.clientHeight,paddingStart:Ie(i.paddingTop),paddingEnd:Ie(i.paddingBottom)}})}})}),[jn,Bt]=$t(te),jt=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:n,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:l,onThumbPositionChange:f,onDragScroll:c,onWheelScroll:d,onResize:h,...p}=e,g=K(te,r),[m,y]=u.useState(null),C=q(t,$=>y($)),S=u.useRef(null),E=u.useRef(""),A=g.viewport,v=n.content-n.viewport,b=Q(d),_=Q(f),N=ze(h,10);function I($){if(S.current){const z=$.clientX-S.current.left,W=$.clientY-S.current.top;c({x:z,y:W})}}return u.useEffect(()=>{const $=z=>{const W=z.target;(m==null?void 0:m.contains(W))&&b(z,v)};return document.addEventListener("wheel",$,{passive:!1}),()=>document.removeEventListener("wheel",$,{passive:!1})},[A,m,v,b]),u.useEffect(_,[n,_]),we(m,N),we(g.content,N),a.jsx(jn,{scope:r,scrollbar:m,hasThumb:o,onThumbChange:Q(s),onThumbPointerUp:Q(i),onThumbPositionChange:_,onThumbPointerDown:Q(l),children:a.jsx(U.div,{...p,ref:C,style:{position:"absolute",...p.style},onPointerDown:X(e.onPointerDown,$=>{$.button===0&&($.target.setPointerCapture($.pointerId),S.current=m.getBoundingClientRect(),E.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",g.viewport&&(g.viewport.style.scrollBehavior="auto"),I($))}),onPointerMove:X(e.onPointerMove,I),onPointerUp:X(e.onPointerUp,$=>{const z=$.target;z.hasPointerCapture($.pointerId)&&z.releasePointerCapture($.pointerId),document.body.style.webkitUserSelect=E.current,g.viewport&&(g.viewport.style.scrollBehavior=""),S.current=null})})})}),ke="ScrollAreaThumb",Vt=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Bt(ke,e.__scopeScrollArea);return a.jsx(ve,{present:r||o.hasThumb,children:a.jsx(Vn,{ref:t,...n})})}),Vn=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:n,...o}=e,s=K(ke,r),i=Bt(ke,r),{onThumbPositionChange:l}=i,f=q(t,h=>i.onThumbChange(h)),c=u.useRef(void 0),d=ze(()=>{c.current&&(c.current(),c.current=void 0)},100);return u.useEffect(()=>{const h=s.viewport;if(h){const p=()=>{if(d(),!c.current){const g=Un(h,l);c.current=g,l()}};return l(),h.addEventListener("scroll",p),()=>h.removeEventListener("scroll",p)}},[s.viewport,d,l]),a.jsx(U.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:f,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...n},onPointerDownCapture:X(e.onPointerDownCapture,h=>{const g=h.target.getBoundingClientRect(),m=h.clientX-g.left,y=h.clientY-g.top;i.onThumbPointerDown({x:m,y})}),onPointerUp:X(e.onPointerUp,i.onThumbPointerUp)})});Vt.displayName=ke;var at="ScrollAreaCorner",Xt=u.forwardRef((e,t)=>{const r=K(at,e.__scopeScrollArea),n=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&n?a.jsx(Xn,{...e,ref:t}):null});Xt.displayName=at;var Xn=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,...n}=e,o=K(at,r),[s,i]=u.useState(0),[l,f]=u.useState(0),c=!!(s&&l);return we(o.scrollbarX,()=>{var h;const d=((h=o.scrollbarX)==null?void 0:h.offsetHeight)||0;o.onCornerHeightChange(d),f(d)}),we(o.scrollbarY,()=>{var h;const d=((h=o.scrollbarY)==null?void 0:h.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?a.jsx(U.div,{...n,ref:t,style:{width:s,height:l,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Ie(e){return e?parseInt(e,10):0}function Yt(e,t){const r=e/t;return isNaN(r)?0:r}function $e(e){const t=Yt(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,n=(e.scrollbar.size-r)*t;return Math.max(n,18)}function Yn(e,t,r,n="ltr"){const o=$e(r),s=o/2,i=t||s,l=o-i,f=r.scrollbar.paddingStart+i,c=r.scrollbar.size-r.scrollbar.paddingEnd-l,d=r.content-r.viewport,h=n==="ltr"?[0,d]:[d*-1,0];return qt([f,c],h)(e)}function Ut(e,t,r="ltr"){const n=$e(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,l=s-n,f=r==="ltr"?[0,i]:[i*-1,0],c=In(e,f);return qt([0,i],[0,l])(c)}function qt(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const n=(t[1]-t[0])/(e[1]-e[0]);return t[0]+n*(r-e[0])}}function Jt(e,t){return e>0&&e<t}var Un=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},n=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=r.left!==s.left,l=r.top!==s.top;(i||l)&&t(),r=s,n=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(n)};function ze(e,t){const r=Q(e),n=u.useRef(0);return u.useEffect(()=>()=>window.clearTimeout(n.current),[]),u.useCallback(()=>{window.clearTimeout(n.current),n.current=window.setTimeout(r,t)},[r,t])}function we(e,t){const r=Q(t);fe(()=>{let n=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(n),n=window.requestAnimationFrame(r)});return o.observe(e),()=>{window.cancelAnimationFrame(n),o.unobserve(e)}}},[e,r])}var Gt=zt,qn=Ft,Jn=Xt;const lt=u.forwardRef(({className:e,children:t,...r},n)=>a.jsxs(Gt,{ref:n,className:Y("relative overflow-hidden",e),...r,children:[a.jsx(qn,{className:"h-full w-full rounded-[inherit]",children:t}),a.jsx(Kt,{}),a.jsx(Jn,{})]}));lt.displayName=Gt.displayName;const Kt=u.forwardRef(({className:e,orientation:t="vertical",...r},n)=>a.jsx(st,{ref:n,orientation:t,className:Y("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),...r,children:a.jsx(Vt,{className:"relative flex-1 rounded-full bg-border"})}));Kt.displayName=st.displayName;function be({className:e="",showCreateButton:t=!0,onThreadSelect:r}){const{currentThreadId:n,threads:o,loadingThreads:s,selectThread:i,createThread:l,deleteThread:f,updateThreadTitle:c}=pe();console.log("ThreadManager rendered, deleteThread available:",typeof f);const[d,h]=L.useState(null),[p,g]=L.useState(""),m=async v=>{await i(v),r==null||r(v)},y=async()=>{const v=await l();await m(v)},C=async(v,b)=>{console.log("handleDeleteThread called with threadId:",b),v.stopPropagation();const _=confirm("Are you sure you want to delete this thread?");if(console.log("User confirmed deletion:",_),_){console.log("Calling deleteThread from ChatProvider...");try{await f(b),console.log("deleteThread completed successfully")}catch(N){console.error("Error in handleDeleteThread:",N)}}},S=(v,b)=>{v.stopPropagation(),h(b.id),g(b.title||`Thread ${b.id.slice(0,8)}`)},E=async v=>{await c(v,p),h(null)},A=()=>{h(null),g("")};return s?a.jsx("div",{className:`p-4 ${e}`,children:a.jsx("div",{className:"animate-pulse space-y-2",children:[...Array(3)].map((v,b)=>a.jsx("div",{className:"h-10 bg-gray-200 rounded"},b))})}):a.jsxs("div",{className:`p-4 ${e}`,children:[t&&a.jsxs(B,{onClick:y,className:"w-full mb-4 flex items-center gap-2",variant:"outline",children:[a.jsx(F.Plus,{size:16}),"New Thread"]}),a.jsx(lt,{className:"h-[calc(100vh-12rem)]",children:a.jsxs("div",{className:"space-y-2 pr-4",children:[o.map(v=>a.jsx("div",{className:`
6
7
  group p-3 rounded-lg cursor-pointer transition-colors
7
- ${n===m.id?"bg-blue-100 border-blue-300 border":"bg-gray-50 hover:bg-gray-100 border border-transparent"}
8
- `,onClick:()=>v(m.id),children:a.jsx("div",{className:"flex items-center justify-between",children:d===m.id?a.jsxs("div",{className:"flex-1 flex gap-2",children:[a.jsx("input",{value:p,onChange:w=>g(w.target.value),onKeyDown:w=>{w.key==="Enter"&&E(m.id),w.key==="Escape"&&P()},className:"flex-1 px-2 py-1 text-sm border rounded",autoFocus:!0}),a.jsx(j,{size:"sm",onClick:w=>{w.stopPropagation(),E(m.id)},children:"Save"})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"font-medium text-sm truncate",children:m.title||`Thread ${m.id.slice(0,8)}`}),a.jsx("div",{className:"text-xs text-gray-500",children:new Date(m.updated_at).toLocaleDateString()})]}),a.jsxs("div",{className:"flex gap-1 opacity-100 transition-opacity",children:[a.jsx(j,{size:"sm",variant:"ghost",onClick:w=>S(w,m),className:"p-1 h-auto",children:a.jsx(W.Edit3,{size:12})}),a.jsx(j,{size:"sm",variant:"ghost",onClick:w=>{console.log("Delete button clicked!"),C(w,m.id)},className:"p-1 h-auto text-red-600 hover:text-red-700",style:{backgroundColor:"rgba(255, 0, 0, 0.1)"},children:a.jsx(W.Trash2,{size:12})})]})]})})},m.id)),o.length===0&&a.jsx("div",{className:"text-center text-gray-500 py-8",children:"No threads yet. Create your first thread to get started!"})]})})]})}function qt({apiBaseUrl:e,enableUrlSync:t=!0,layout:r="sidebar",className:n=""}){return a.jsx(Le,{apiBaseUrl:e,enableUrlSync:t,children:a.jsxs("div",{className:`h-full ${n}`,children:[r==="sidebar"&&a.jsx(Yn,{}),r==="tabs"&&a.jsx(Un,{}),r==="split"&&a.jsx(qn,{})]})})}function Yn(){return a.jsxs("div",{className:"flex h-full",children:[a.jsx("div",{className:"w-80 border-r bg-gray-50",children:a.jsx(me,{})}),a.jsx("div",{className:"flex-1",children:a.jsx(he,{})})]})}function Un(){const[e,t]=L.useState("chat");return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsx("div",{className:"border-b",children:a.jsxs("div",{className:"flex",children:[a.jsx("button",{onClick:()=>t("chat"),className:`px-4 py-2 font-medium ${e==="chat"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-700"}`,children:"Chat"}),a.jsx("button",{onClick:()=>t("threads"),className:`px-4 py-2 font-medium ${e==="threads"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-700"}`,children:"Threads"})]})}),a.jsxs("div",{className:"flex-1",children:[e==="chat"&&a.jsx(he,{}),e==="threads"&&a.jsx(me,{onThreadSelect:()=>t("chat")})]})]})}function qn(){return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsx("div",{className:"h-1/3 border-b",children:a.jsx(me,{})}),a.jsx("div",{className:"flex-1",children:a.jsx(he,{})})]})}function Jn({placeholder:e,showThreadHistory:t=!0}){const[r,n]=L.useState(!1);L.useEffect(()=>{const s=()=>n(i=>!i);return window.addEventListener("toggleChatThreads",s),()=>window.removeEventListener("toggleChatThreads",s)},[]);const o=()=>{n(!1)};return a.jsxs("div",{className:"flex flex-col h-full relative",children:[t&&r&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40 bg-black/20",onClick:()=>n(!1)}),a.jsxs("div",{className:"absolute top-0 left-0 right-0 z-50 bg-white rounded-lg shadow-xl border border-gray-200 max-h-72 overflow-hidden",children:[a.jsx("div",{className:"p-3 border-b border-gray-100 bg-gray-50",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h4",{className:"font-medium text-sm text-gray-700",children:"Conversation History"}),a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>n(!1),className:"h-6 w-6 p-0 text-gray-400 hover:text-gray-600",children:a.jsx(W.X,{size:12})})]})}),a.jsx("div",{className:"max-h-56 overflow-y-auto",children:a.jsx(me,{className:"p-2",onThreadSelect:o})})]})]}),a.jsx("div",{className:"flex-1 h-full",children:a.jsx(he,{placeholder:e||"Type your message...",className:"h-full flex flex-col"})})]})}const Gn={sm:"w-80 h-80",md:"w-96 h-96",lg:"w-[28rem] h-[32rem]"},Jt={"bottom-right":"bottom-6 right-6","bottom-left":"bottom-6 left-6","top-right":"top-6 right-6","top-left":"top-6 left-6"};function Kn({apiBaseUrl:e="http://localhost:8000/api/chat",title:t="AI Assistant",subtitle:r="How can I help you?",placeholder:n="Type your message...",getAuthHeaders:o,authToken:s,className:i="",position:l="bottom-right",size:f="md",theme:c="light",enableUrlSync:d=!0,defaultOpen:h=!1,showThreadHistory:p=!0,onMessageSent:g,onThreadChanged:v,onToggle:y}){const[C,S]=L.useState(h),[E,P]=L.useState(!1),m=T=>{S(T),y==null||y(T)};L.useEffect(()=>{d&&!C&&new URLSearchParams(window.location.search).get("thread")&&m(!0)},[d,C]),L.useEffect(()=>{if(d){const k=new URLSearchParams(window.location.search).get("thread");k&&v&&v(k)}},[d,v]);const w=c==="dark"?"bg-gray-900 text-white border-gray-700":"bg-white text-gray-900 border-gray-200",_=c==="dark"?"bg-gray-800 text-white":"bg-slate-800 text-white";return C?a.jsx(Le,{apiBaseUrl:e,enableUrlSync:d,getAuthHeaders:o,authToken:s,children:a.jsx("div",{className:`fixed ${Jt[l]} z-50 transition-all duration-300 ${E?"scale-75":"scale-100"}`,children:a.jsxs("div",{className:`${Gn[f]} ${w} rounded-xl shadow-2xl border overflow-hidden relative`,children:[a.jsx("div",{className:`${_} p-4 flex-shrink-0`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-8 h-8 bg-white/10 rounded-full flex items-center justify-center border border-slate-600",children:a.jsx(W.MessageCircle,{size:16,className:"text-white"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"font-semibold text-sm",children:t}),a.jsx("p",{className:"text-xs text-slate-300",children:r})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[p&&a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>{const T=new CustomEvent("toggleChatThreads");window.dispatchEvent(T)},className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Conversation History",children:a.jsx(W.History,{size:14})}),a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>P(!E),className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:E?"Maximize":"Minimize",children:E?a.jsx(W.Maximize2,{size:14}):a.jsx(W.Minimize2,{size:14})}),a.jsx(j,{variant:"ghost",size:"sm",onClick:()=>m(!1),className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Close",children:a.jsx(W.X,{size:14})})]})]})}),!E&&a.jsx("div",{className:"flex-1 h-full overflow-hidden",children:a.jsx(Jn,{placeholder:n,showThreadHistory:p})})]})})}):a.jsxs(j,{onClick:()=>m(!0),size:"lg",className:`fixed ${Jt[l]} h-14 w-14 rounded-full shadow-lg bg-slate-800 hover:bg-slate-700 z-50 transition-all duration-200 ${i}`,children:[a.jsx(W.MessageCircle,{size:24,className:"text-white"}),a.jsx("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-red-500 rounded-full animate-pulse"})]})}function Gt(){const e=fe();return{...L.useMemo(()=>({all:e.messages,human:e.messages.filter(r=>r.role==="human"),ai:e.messages.filter(r=>r.role==="ai"),tool:e.messages.filter(r=>r.role==="tool"),latest:e.messages[e.messages.length-1],latestHuman:[...e.messages].reverse().find(r=>r.role==="human"),latestAI:[...e.messages].reverse().find(r=>r.role==="ai"),latestTool:[...e.messages].reverse().find(r=>r.role==="tool")}),[e.messages]),isLoading:e.isLoading,error:e.error,refresh:e.refresh}}function Zn(){const{tool:e}=Gt(),t=L.useMemo(()=>e.map(i=>{let l="",f=null,c=!1;try{if(typeof i.content=="string"){l=i.content;try{f=JSON.parse(i.content),c=!0}catch{}}else f=i.content,l=JSON.stringify(i.content,null,2),c=!0}catch{l=String(i.content||"")}return{id:i.id||"",name:i.name||"",tool_call_id:i.tool_call_id||"",args:i.args,content:i.content,timestamp:i.timestamp,textContent:l,jsonContent:f,isJson:c}}),[e]),r=L.useMemo(()=>{const i={};return t.forEach(l=>{i[l.name]||(i[l.name]=[]),i[l.name].push(l)}),i},[t]),n=i=>{const l=r[i];return l==null?void 0:l[l.length-1]},o=i=>{var l;return((l=r[i])==null?void 0:l.map(f=>f.jsonContent||f.textContent))||[]},s=()=>t.map(i=>i.jsonContent||i.textContent);return{all:t,raw:e,byToolName:r,toolNames:Object.keys(r),getLatestByTool:n,getContentByTool:o,getAllContent:s,latest:t[t.length-1],count:t.length,hasToolMessages:t.length>0}}function Qn(){const e=fe();return{currentThread:e.currentThreadId,isLoading:e.isLoading,error:e.error,sendMessage:e.sendMessage,createThread:e.createThread,selectThread:e.selectThread,deleteThread:e.deleteThread,clearError:e.clearError,stop:e.stop,refresh:e.refresh}}function Kt(){const e=fe(),[t,r]=L.useState({isStreaming:!1,events:[],latestEvent:null,error:null}),n=L.useRef(0),o=L.useRef(0);L.useEffect(()=>{r(c=>({...c,isStreaming:e.isLoading,error:e.error}))},[e.isLoading,e.error]),L.useEffect(()=>{const c=e.messages.length;c>n.current&&(e.messages.slice(n.current).forEach(h=>{const p={type:h.role==="tool"?"tool":"message",data:h,timestamp:Date.now()};r(g=>({...g,events:[...g.events,p],latestEvent:p}))}),n.current=c)},[e.messages]),L.useEffect(()=>{if(!e.isLoading&&t.isStreaming){const c={type:"complete",data:{messageCount:e.messages.length},timestamp:Date.now()};r(d=>({...d,isStreaming:!1,events:[...d.events,c],latestEvent:c}))}},[e.isLoading,t.isStreaming,e.messages.length]),L.useEffect(()=>{r(c=>({...c,events:[],latestEvent:null})),n.current=0,o.current=0},[e.currentThreadId]);const s=c=>t.events.filter(d=>d.type===c),i=c=>{const d=s(c);return d[d.length-1]||null},l=()=>t.events.filter(c=>c.type==="tool").map(c=>({...c,data:c.data}));return{...t,getEventsByType:s,getLatestEventByType:i,getToolEvents:l,clearEvents:()=>{r(c=>({...c,events:[],latestEvent:null}))},messageEvents:s("message"),toolEvents:l(),latestToolEvent:i("tool"),hasNewEvents:t.events.length>0}}function $e(e,t){const{toolEvents:r,latestToolEvent:n}=Kt(),[o,s]=L.useState([]),[i,l]=L.useState(null);L.useEffect(()=>{const d=r.filter(h=>h.data.name===e).map(h=>{const p=h.data.jsonContent||h.data.textContent;return t?t(p):p});s(d),l(d[d.length-1]||null)},[r,e,t]);const f=(n==null?void 0:n.data.name)===e;return{data:o,latest:i,count:o.length,hasData:o.length>0,hasNewData:f}}const Rn=(e="search")=>$e(e,t=>Array.isArray(t)?t:t!=null&&t.results?t.results:t!=null&&t.data?t.data:t),eo=(e="read_file")=>$e(e,t=>typeof t=="string"?t:t!=null&&t.content?t.content:t!=null&&t.text?t.text:String(t)),to=(e="execute_code")=>$e(e,t=>({output:(t==null?void 0:t.output)||(t==null?void 0:t.stdout)||t,error:(t==null?void 0:t.error)||(t==null?void 0:t.stderr)||null,exitCode:(t==null?void 0:t.exit_code)||(t==null?void 0:t.exitCode)||0})),Zt=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:X("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Zt.displayName="Card";const Qt=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:X("flex flex-col space-y-1.5 p-6",e),...t}));Qt.displayName="CardHeader";const Rt=u.forwardRef(({className:e,...t},r)=>a.jsx("h3",{ref:r,className:X("text-2xl font-semibold leading-none tracking-tight",e),...t}));Rt.displayName="CardTitle";const er=u.forwardRef(({className:e,...t},r)=>a.jsx("p",{ref:r,className:X("text-sm text-muted-foreground",e),...t}));er.displayName="CardDescription";const tr=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:X("p-6 pt-0",e),...t}));tr.displayName="CardContent";const rr=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:X("flex items-center p-6 pt-0",e),...t}));rr.displayName="CardFooter";const nr=u.forwardRef(({className:e,type:t,...r},n)=>a.jsx("input",{type:t,className:X("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:n,...r}));nr.displayName="Input";var ro="Label",or=u.forwardRef((e,t)=>a.jsx(U.label,{...e,ref:t,onMouseDown:r=>{var o;r.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,r),!r.defaultPrevented&&r.detail>1&&r.preventDefault())}}));or.displayName=ro;var sr=or;const no=Tt.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),ir=u.forwardRef(({className:e,...t},r)=>a.jsx(sr,{ref:r,className:X(no(),e),...t}));ir.displayName=sr.displayName;var oo="Separator",ar="horizontal",so=["horizontal","vertical"],lr=u.forwardRef((e,t)=>{const{decorative:r,orientation:n=ar,...o}=e,s=io(n)?n:ar,l=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return a.jsx(U.div,{"data-orientation":s,...l,...o,ref:t})});lr.displayName=oo;function io(e){return so.includes(e)}var cr=lr;const dr=u.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},o)=>a.jsx(cr,{ref:o,decorative:r,orientation:t,className:X("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));dr.displayName=cr.displayName;function ao(e,t=globalThis==null?void 0:globalThis.document){const r=Z(e);u.useEffect(()=>{const n=o=>{o.key==="Escape"&&r(o)};return t.addEventListener("keydown",n,{capture:!0}),()=>t.removeEventListener("keydown",n,{capture:!0})},[r,t])}var lo="DismissableLayer",at="dismissableLayer.update",co="dismissableLayer.pointerDownOutside",fo="dismissableLayer.focusOutside",fr,ur=u.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),hr=u.forwardRef((e,t)=>{const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:n,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:l,...f}=e,c=u.useContext(ur),[d,h]=u.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,g]=u.useState({}),v=q(t,T=>h(T)),y=Array.from(c.layers),[C]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=y.indexOf(C),E=d?y.indexOf(d):-1,P=c.layersWithOutsidePointerEventsDisabled.size>0,m=E>=S,w=po(T=>{const k=T.target,I=[...c.branches].some(z=>z.contains(k));!m||I||(o==null||o(T),i==null||i(T),T.defaultPrevented||l==null||l())},p),_=go(T=>{const k=T.target;[...c.branches].some(z=>z.contains(k))||(s==null||s(T),i==null||i(T),T.defaultPrevented||l==null||l())},p);return ao(T=>{E===c.layers.size-1&&(n==null||n(T),!T.defaultPrevented&&l&&(T.preventDefault(),l()))},p),u.useEffect(()=>{if(d)return r&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(fr=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),pr(),()=>{r&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=fr)}},[d,p,r,c]),u.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),pr())},[d,c]),u.useEffect(()=>{const T=()=>g({});return document.addEventListener(at,T),()=>document.removeEventListener(at,T)},[]),a.jsx(U.div,{...f,ref:v,style:{pointerEvents:P?m?"auto":"none":void 0,...e.style},onFocusCapture:V(e.onFocusCapture,_.onFocusCapture),onBlurCapture:V(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:V(e.onPointerDownCapture,w.onPointerDownCapture)})});hr.displayName=lo;var uo="DismissableLayerBranch",ho=u.forwardRef((e,t)=>{const r=u.useContext(ur),n=u.useRef(null),o=q(t,n);return u.useEffect(()=>{const s=n.current;if(s)return r.branches.add(s),()=>{r.branches.delete(s)}},[r.branches]),a.jsx(U.div,{...e,ref:o})});ho.displayName=uo;function po(e,t=globalThis==null?void 0:globalThis.document){const r=Z(e),n=u.useRef(!1),o=u.useRef(()=>{});return u.useEffect(()=>{const s=l=>{if(l.target&&!n.current){let f=function(){gr(co,r,c,{discrete:!0})};const c={originalEvent:l};l.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=f,t.addEventListener("click",o.current,{once:!0})):f()}else t.removeEventListener("click",o.current);n.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,r]),{onPointerDownCapture:()=>n.current=!0}}function go(e,t=globalThis==null?void 0:globalThis.document){const r=Z(e),n=u.useRef(!1);return u.useEffect(()=>{const o=s=>{s.target&&!n.current&&gr(fo,r,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,r]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function pr(){const e=new CustomEvent(at);document.dispatchEvent(e)}function gr(e,t,r,{discrete:n}){const o=r.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:r});t&&o.addEventListener(e,t,{once:!0}),n?Sn(o,s):o.dispatchEvent(s)}var mo=u[" useId ".trim().toString()]||(()=>{}),vo=0;function wo(e){const[t,r]=u.useState(mo());return le(()=>{r(n=>n??String(vo++))},[e]),t?`radix-${t}`:""}const bo=["top","right","bottom","left"],ce=Math.min,J=Math.max,Fe=Math.round,He=Math.floor,te=e=>({x:e,y:e}),yo={left:"right",right:"left",bottom:"top",top:"bottom"},xo={start:"end",end:"start"};function lt(e,t,r){return J(e,ce(t,r))}function se(e,t){return typeof e=="function"?e(t):e}function ie(e){return e.split("-")[0]}function ve(e){return e.split("-")[1]}function ct(e){return e==="x"?"y":"x"}function dt(e){return e==="y"?"height":"width"}const Co=new Set(["top","bottom"]);function re(e){return Co.has(ie(e))?"y":"x"}function ft(e){return ct(re(e))}function So(e,t,r){r===void 0&&(r=!1);const n=ve(e),o=ft(e),s=dt(o);let i=o==="x"?n===(r?"end":"start")?"right":"left":n==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=We(i)),[i,We(i)]}function Eo(e){const t=We(e);return[ut(e),t,ut(t)]}function ut(e){return e.replace(/start|end/g,t=>xo[t])}const mr=["left","right"],vr=["right","left"],To=["top","bottom"],No=["bottom","top"];function Po(e,t,r){switch(e){case"top":case"bottom":return r?t?vr:mr:t?mr:vr;case"left":case"right":return t?To:No;default:return[]}}function Ao(e,t,r,n){const o=ve(e);let s=Po(ie(e),r==="start",n);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ut)))),s}function We(e){return e.replace(/left|right|bottom|top/g,t=>yo[t])}function Oo(e){return{top:0,right:0,bottom:0,left:0,...e}}function wr(e){return typeof e!="number"?Oo(e):{top:e,right:e,bottom:e,left:e}}function Be(e){const{x:t,y:r,width:n,height:o}=e;return{width:n,height:o,top:r,left:t,right:t+n,bottom:r+o,x:t,y:r}}function br(e,t,r){let{reference:n,floating:o}=e;const s=re(t),i=ft(t),l=dt(i),f=ie(t),c=s==="y",d=n.x+n.width/2-o.width/2,h=n.y+n.height/2-o.height/2,p=n[l]/2-o[l]/2;let g;switch(f){case"top":g={x:d,y:n.y-o.height};break;case"bottom":g={x:d,y:n.y+n.height};break;case"right":g={x:n.x+n.width,y:h};break;case"left":g={x:n.x-o.width,y:h};break;default:g={x:n.x,y:n.y}}switch(ve(t)){case"start":g[i]-=p*(r&&c?-1:1);break;case"end":g[i]+=p*(r&&c?-1:1);break}return g}const Lo=async(e,t,r)=>{const{placement:n="bottom",strategy:o="absolute",middleware:s=[],platform:i}=r,l=s.filter(Boolean),f=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:h}=br(c,n,f),p=n,g={},v=0;for(let y=0;y<l.length;y++){const{name:C,fn:S}=l[y],{x:E,y:P,data:m,reset:w}=await S({x:d,y:h,initialPlacement:n,placement:p,strategy:o,middlewareData:g,rects:c,platform:i,elements:{reference:e,floating:t}});d=E??d,h=P??h,g={...g,[C]:{...g[C],...m}},w&&v<=50&&(v++,typeof w=="object"&&(w.placement&&(p=w.placement),w.rects&&(c=w.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):w.rects),{x:d,y:h}=br(c,p,f)),y=-1)}return{x:d,y:h,placement:p,strategy:o,middlewareData:g}};async function Ee(e,t){var r;t===void 0&&(t={});const{x:n,y:o,platform:s,rects:i,elements:l,strategy:f}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:p=!1,padding:g=0}=se(t,e),v=wr(g),C=l[p?h==="floating"?"reference":"floating":h],S=Be(await s.getClippingRect({element:(r=await(s.isElement==null?void 0:s.isElement(C)))==null||r?C:C.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:c,rootBoundary:d,strategy:f})),E=h==="floating"?{x:n,y:o,width:i.floating.width,height:i.floating.height}:i.reference,P=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),m=await(s.isElement==null?void 0:s.isElement(P))?await(s.getScale==null?void 0:s.getScale(P))||{x:1,y:1}:{x:1,y:1},w=Be(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:E,offsetParent:P,strategy:f}):E);return{top:(S.top-w.top+v.top)/m.y,bottom:(w.bottom-S.bottom+v.bottom)/m.y,left:(S.left-w.left+v.left)/m.x,right:(w.right-S.right+v.right)/m.x}}const _o=e=>({name:"arrow",options:e,async fn(t){const{x:r,y:n,placement:o,rects:s,platform:i,elements:l,middlewareData:f}=t,{element:c,padding:d=0}=se(e,t)||{};if(c==null)return{};const h=wr(d),p={x:r,y:n},g=ft(o),v=dt(g),y=await i.getDimensions(c),C=g==="y",S=C?"top":"left",E=C?"bottom":"right",P=C?"clientHeight":"clientWidth",m=s.reference[v]+s.reference[g]-p[g]-s.floating[v],w=p[g]-s.reference[g],_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let T=_?_[P]:0;(!T||!await(i.isElement==null?void 0:i.isElement(_)))&&(T=l.floating[P]||s.floating[v]);const k=m/2-w/2,I=T/2-y[v]/2-1,z=ce(h[S],I),x=ce(h[E],I),b=z,A=T-y[v]-x,D=T/2-y[v]/2+k,F=lt(b,D,A),N=!f.arrow&&ve(o)!=null&&D!==F&&s.reference[v]/2-(D<b?z:x)-y[v]/2<0,H=N?D<b?D-b:D-A:0;return{[g]:p[g]+H,data:{[g]:F,centerOffset:D-F-H,...N&&{alignmentOffset:H}},reset:N}}}),Do=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var r,n;const{placement:o,middlewareData:s,rects:i,initialPlacement:l,platform:f,elements:c}=t,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:y=!0,...C}=se(e,t);if((r=s.arrow)!=null&&r.alignmentOffset)return{};const S=ie(o),E=re(l),P=ie(l)===l,m=await(f.isRTL==null?void 0:f.isRTL(c.floating)),w=p||(P||!y?[We(l)]:Eo(l)),_=v!=="none";!p&&_&&w.push(...Ao(l,y,v,m));const T=[l,...w],k=await Ee(t,C),I=[];let z=((n=s.flip)==null?void 0:n.overflows)||[];if(d&&I.push(k[S]),h){const D=So(o,i,m);I.push(k[D[0]],k[D[1]])}if(z=[...z,{placement:o,overflows:I}],!I.every(D=>D<=0)){var x,b;const D=(((x=s.flip)==null?void 0:x.index)||0)+1,F=T[D];if(F&&(!(h==="alignment"?E!==re(F):!1)||z.every(M=>M.overflows[0]>0&&re(M.placement)===E)))return{data:{index:D,overflows:z},reset:{placement:F}};let N=(b=z.filter(H=>H.overflows[0]<=0).sort((H,M)=>H.overflows[1]-M.overflows[1])[0])==null?void 0:b.placement;if(!N)switch(g){case"bestFit":{var A;const H=(A=z.filter(M=>{if(_){const B=re(M.placement);return B===E||B==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(B=>B>0).reduce((B,$)=>B+$,0)]).sort((M,B)=>M[1]-B[1])[0])==null?void 0:A[0];H&&(N=H);break}case"initialPlacement":N=l;break}if(o!==N)return{reset:{placement:N}}}return{}}}};function yr(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function xr(e){return bo.some(t=>e[t]>=0)}const Mo=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:r}=t,{strategy:n="referenceHidden",...o}=se(e,t);switch(n){case"referenceHidden":{const s=await Ee(t,{...o,elementContext:"reference"}),i=yr(s,r.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:xr(i)}}}case"escaped":{const s=await Ee(t,{...o,altBoundary:!0}),i=yr(s,r.floating);return{data:{escapedOffsets:i,escaped:xr(i)}}}default:return{}}}}},Cr=new Set(["left","top"]);async function ko(e,t){const{placement:r,platform:n,elements:o}=e,s=await(n.isRTL==null?void 0:n.isRTL(o.floating)),i=ie(r),l=ve(r),f=re(r)==="y",c=Cr.has(i)?-1:1,d=s&&f?-1:1,h=se(t,e);let{mainAxis:p,crossAxis:g,alignmentAxis:v}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return l&&typeof v=="number"&&(g=l==="end"?v*-1:v),f?{x:g*d,y:p*c}:{x:p*c,y:g*d}}const Io=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var r,n;const{x:o,y:s,placement:i,middlewareData:l}=t,f=await ko(t,e);return i===((r=l.offset)==null?void 0:r.placement)&&(n=l.arrow)!=null&&n.alignmentOffset?{}:{x:o+f.x,y:s+f.y,data:{...f,placement:i}}}}},zo=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:r,y:n,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:l={fn:C=>{let{x:S,y:E}=C;return{x:S,y:E}}},...f}=se(e,t),c={x:r,y:n},d=await Ee(t,f),h=re(ie(o)),p=ct(h);let g=c[p],v=c[h];if(s){const C=p==="y"?"top":"left",S=p==="y"?"bottom":"right",E=g+d[C],P=g-d[S];g=lt(E,g,P)}if(i){const C=h==="y"?"top":"left",S=h==="y"?"bottom":"right",E=v+d[C],P=v-d[S];v=lt(E,v,P)}const y=l.fn({...t,[p]:g,[h]:v});return{...y,data:{x:y.x-r,y:y.y-n,enabled:{[p]:s,[h]:i}}}}}},$o=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:r,y:n,placement:o,rects:s,middlewareData:i}=t,{offset:l=0,mainAxis:f=!0,crossAxis:c=!0}=se(e,t),d={x:r,y:n},h=re(o),p=ct(h);let g=d[p],v=d[h];const y=se(l,t),C=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(f){const P=p==="y"?"height":"width",m=s.reference[p]-s.floating[P]+C.mainAxis,w=s.reference[p]+s.reference[P]-C.mainAxis;g<m?g=m:g>w&&(g=w)}if(c){var S,E;const P=p==="y"?"width":"height",m=Cr.has(ie(o)),w=s.reference[h]-s.floating[P]+(m&&((S=i.offset)==null?void 0:S[h])||0)+(m?0:C.crossAxis),_=s.reference[h]+s.reference[P]+(m?0:((E=i.offset)==null?void 0:E[h])||0)-(m?C.crossAxis:0);v<w?v=w:v>_&&(v=_)}return{[p]:g,[h]:v}}}},Fo=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var r,n;const{placement:o,rects:s,platform:i,elements:l}=t,{apply:f=()=>{},...c}=se(e,t),d=await Ee(t,c),h=ie(o),p=ve(o),g=re(o)==="y",{width:v,height:y}=s.floating;let C,S;h==="top"||h==="bottom"?(C=h,S=p===(await(i.isRTL==null?void 0:i.isRTL(l.floating))?"start":"end")?"left":"right"):(S=h,C=p==="end"?"top":"bottom");const E=y-d.top-d.bottom,P=v-d.left-d.right,m=ce(y-d[C],E),w=ce(v-d[S],P),_=!t.middlewareData.shift;let T=m,k=w;if((r=t.middlewareData.shift)!=null&&r.enabled.x&&(k=P),(n=t.middlewareData.shift)!=null&&n.enabled.y&&(T=E),_&&!p){const z=J(d.left,0),x=J(d.right,0),b=J(d.top,0),A=J(d.bottom,0);g?k=v-2*(z!==0||x!==0?z+x:J(d.left,d.right)):T=y-2*(b!==0||A!==0?b+A:J(d.top,d.bottom))}await f({...t,availableWidth:k,availableHeight:T});const I=await i.getDimensions(l.floating);return v!==I.width||y!==I.height?{reset:{rects:!0}}:{}}}};function je(){return typeof window<"u"}function we(e){return Sr(e)?(e.nodeName||"").toLowerCase():"#document"}function G(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ne(e){var t;return(t=(Sr(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Sr(e){return je()?e instanceof Node||e instanceof G(e).Node:!1}function Q(e){return je()?e instanceof Element||e instanceof G(e).Element:!1}function oe(e){return je()?e instanceof HTMLElement||e instanceof G(e).HTMLElement:!1}function Er(e){return!je()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof G(e).ShadowRoot}const Ho=new Set(["inline","contents"]);function Te(e){const{overflow:t,overflowX:r,overflowY:n,display:o}=R(e);return/auto|scroll|overlay|hidden|clip/.test(t+n+r)&&!Ho.has(o)}const Wo=new Set(["table","td","th"]);function Bo(e){return Wo.has(we(e))}const jo=[":popover-open",":modal"];function Ve(e){return jo.some(t=>{try{return e.matches(t)}catch{return!1}})}const Vo=["transform","translate","scale","rotate","perspective"],Xo=["transform","translate","scale","rotate","perspective","filter"],Yo=["paint","layout","strict","content"];function ht(e){const t=pt(),r=Q(e)?R(e):e;return Vo.some(n=>r[n]?r[n]!=="none":!1)||(r.containerType?r.containerType!=="normal":!1)||!t&&(r.backdropFilter?r.backdropFilter!=="none":!1)||!t&&(r.filter?r.filter!=="none":!1)||Xo.some(n=>(r.willChange||"").includes(n))||Yo.some(n=>(r.contain||"").includes(n))}function Uo(e){let t=de(e);for(;oe(t)&&!be(t);){if(ht(t))return t;if(Ve(t))return null;t=de(t)}return null}function pt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const qo=new Set(["html","body","#document"]);function be(e){return qo.has(we(e))}function R(e){return G(e).getComputedStyle(e)}function Xe(e){return Q(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function de(e){if(we(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Er(e)&&e.host||ne(e);return Er(t)?t.host:t}function Tr(e){const t=de(e);return be(t)?e.ownerDocument?e.ownerDocument.body:e.body:oe(t)&&Te(t)?t:Tr(t)}function Ne(e,t,r){var n;t===void 0&&(t=[]),r===void 0&&(r=!0);const o=Tr(e),s=o===((n=e.ownerDocument)==null?void 0:n.body),i=G(o);if(s){const l=gt(i);return t.concat(i,i.visualViewport||[],Te(o)?o:[],l&&r?Ne(l):[])}return t.concat(o,Ne(o,[],r))}function gt(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Nr(e){const t=R(e);let r=parseFloat(t.width)||0,n=parseFloat(t.height)||0;const o=oe(e),s=o?e.offsetWidth:r,i=o?e.offsetHeight:n,l=Fe(r)!==s||Fe(n)!==i;return l&&(r=s,n=i),{width:r,height:n,$:l}}function mt(e){return Q(e)?e:e.contextElement}function ye(e){const t=mt(e);if(!oe(t))return te(1);const r=t.getBoundingClientRect(),{width:n,height:o,$:s}=Nr(t);let i=(s?Fe(r.width):r.width)/n,l=(s?Fe(r.height):r.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const Jo=te(0);function Pr(e){const t=G(e);return!pt()||!t.visualViewport?Jo:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Go(e,t,r){return t===void 0&&(t=!1),!r||t&&r!==G(e)?!1:t}function ue(e,t,r,n){t===void 0&&(t=!1),r===void 0&&(r=!1);const o=e.getBoundingClientRect(),s=mt(e);let i=te(1);t&&(n?Q(n)&&(i=ye(n)):i=ye(e));const l=Go(s,r,n)?Pr(s):te(0);let f=(o.left+l.x)/i.x,c=(o.top+l.y)/i.y,d=o.width/i.x,h=o.height/i.y;if(s){const p=G(s),g=n&&Q(n)?G(n):n;let v=p,y=gt(v);for(;y&&n&&g!==v;){const C=ye(y),S=y.getBoundingClientRect(),E=R(y),P=S.left+(y.clientLeft+parseFloat(E.paddingLeft))*C.x,m=S.top+(y.clientTop+parseFloat(E.paddingTop))*C.y;f*=C.x,c*=C.y,d*=C.x,h*=C.y,f+=P,c+=m,v=G(y),y=gt(v)}}return Be({width:d,height:h,x:f,y:c})}function vt(e,t){const r=Xe(e).scrollLeft;return t?t.left+r:ue(ne(e)).left+r}function Ar(e,t,r){r===void 0&&(r=!1);const n=e.getBoundingClientRect(),o=n.left+t.scrollLeft-(r?0:vt(e,n)),s=n.top+t.scrollTop;return{x:o,y:s}}function Ko(e){let{elements:t,rect:r,offsetParent:n,strategy:o}=e;const s=o==="fixed",i=ne(n),l=t?Ve(t.floating):!1;if(n===i||l&&s)return r;let f={scrollLeft:0,scrollTop:0},c=te(1);const d=te(0),h=oe(n);if((h||!h&&!s)&&((we(n)!=="body"||Te(i))&&(f=Xe(n)),oe(n))){const g=ue(n);c=ye(n),d.x=g.x+n.clientLeft,d.y=g.y+n.clientTop}const p=i&&!h&&!s?Ar(i,f,!0):te(0);return{width:r.width*c.x,height:r.height*c.y,x:r.x*c.x-f.scrollLeft*c.x+d.x+p.x,y:r.y*c.y-f.scrollTop*c.y+d.y+p.y}}function Zo(e){return Array.from(e.getClientRects())}function Qo(e){const t=ne(e),r=Xe(e),n=e.ownerDocument.body,o=J(t.scrollWidth,t.clientWidth,n.scrollWidth,n.clientWidth),s=J(t.scrollHeight,t.clientHeight,n.scrollHeight,n.clientHeight);let i=-r.scrollLeft+vt(e);const l=-r.scrollTop;return R(n).direction==="rtl"&&(i+=J(t.clientWidth,n.clientWidth)-o),{width:o,height:s,x:i,y:l}}function Ro(e,t){const r=G(e),n=ne(e),o=r.visualViewport;let s=n.clientWidth,i=n.clientHeight,l=0,f=0;if(o){s=o.width,i=o.height;const c=pt();(!c||c&&t==="fixed")&&(l=o.offsetLeft,f=o.offsetTop)}return{width:s,height:i,x:l,y:f}}const es=new Set(["absolute","fixed"]);function ts(e,t){const r=ue(e,!0,t==="fixed"),n=r.top+e.clientTop,o=r.left+e.clientLeft,s=oe(e)?ye(e):te(1),i=e.clientWidth*s.x,l=e.clientHeight*s.y,f=o*s.x,c=n*s.y;return{width:i,height:l,x:f,y:c}}function Or(e,t,r){let n;if(t==="viewport")n=Ro(e,r);else if(t==="document")n=Qo(ne(e));else if(Q(t))n=ts(t,r);else{const o=Pr(e);n={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Be(n)}function Lr(e,t){const r=de(e);return r===t||!Q(r)||be(r)?!1:R(r).position==="fixed"||Lr(r,t)}function rs(e,t){const r=t.get(e);if(r)return r;let n=Ne(e,[],!1).filter(l=>Q(l)&&we(l)!=="body"),o=null;const s=R(e).position==="fixed";let i=s?de(e):e;for(;Q(i)&&!be(i);){const l=R(i),f=ht(i);!f&&l.position==="fixed"&&(o=null),(s?!f&&!o:!f&&l.position==="static"&&!!o&&es.has(o.position)||Te(i)&&!f&&Lr(e,i))?n=n.filter(d=>d!==i):o=l,i=de(i)}return t.set(e,n),n}function ns(e){let{element:t,boundary:r,rootBoundary:n,strategy:o}=e;const i=[...r==="clippingAncestors"?Ve(t)?[]:rs(t,this._c):[].concat(r),n],l=i[0],f=i.reduce((c,d)=>{const h=Or(t,d,o);return c.top=J(h.top,c.top),c.right=ce(h.right,c.right),c.bottom=ce(h.bottom,c.bottom),c.left=J(h.left,c.left),c},Or(t,l,o));return{width:f.right-f.left,height:f.bottom-f.top,x:f.left,y:f.top}}function os(e){const{width:t,height:r}=Nr(e);return{width:t,height:r}}function ss(e,t,r){const n=oe(t),o=ne(t),s=r==="fixed",i=ue(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const f=te(0);function c(){f.x=vt(o)}if(n||!n&&!s)if((we(t)!=="body"||Te(o))&&(l=Xe(t)),n){const g=ue(t,!0,s,t);f.x=g.x+t.clientLeft,f.y=g.y+t.clientTop}else o&&c();s&&!n&&o&&c();const d=o&&!n&&!s?Ar(o,l):te(0),h=i.left+l.scrollLeft-f.x-d.x,p=i.top+l.scrollTop-f.y-d.y;return{x:h,y:p,width:i.width,height:i.height}}function wt(e){return R(e).position==="static"}function _r(e,t){if(!oe(e)||R(e).position==="fixed")return null;if(t)return t(e);let r=e.offsetParent;return ne(e)===r&&(r=r.ownerDocument.body),r}function Dr(e,t){const r=G(e);if(Ve(e))return r;if(!oe(e)){let o=de(e);for(;o&&!be(o);){if(Q(o)&&!wt(o))return o;o=de(o)}return r}let n=_r(e,t);for(;n&&Bo(n)&&wt(n);)n=_r(n,t);return n&&be(n)&&wt(n)&&!ht(n)?r:n||Uo(e)||r}const is=async function(e){const t=this.getOffsetParent||Dr,r=this.getDimensions,n=await r(e.floating);return{reference:ss(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function as(e){return R(e).direction==="rtl"}const ls={convertOffsetParentRelativeRectToViewportRelativeRect:Ko,getDocumentElement:ne,getClippingRect:ns,getOffsetParent:Dr,getElementRects:is,getClientRects:Zo,getDimensions:os,getScale:ye,isElement:Q,isRTL:as};function Mr(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function cs(e,t){let r=null,n;const o=ne(e);function s(){var l;clearTimeout(n),(l=r)==null||l.disconnect(),r=null}function i(l,f){l===void 0&&(l=!1),f===void 0&&(f=1),s();const c=e.getBoundingClientRect(),{left:d,top:h,width:p,height:g}=c;if(l||t(),!p||!g)return;const v=He(h),y=He(o.clientWidth-(d+p)),C=He(o.clientHeight-(h+g)),S=He(d),P={rootMargin:-v+"px "+-y+"px "+-C+"px "+-S+"px",threshold:J(0,ce(1,f))||1};let m=!0;function w(_){const T=_[0].intersectionRatio;if(T!==f){if(!m)return i();T?i(!1,T):n=setTimeout(()=>{i(!1,1e-7)},1e3)}T===1&&!Mr(c,e.getBoundingClientRect())&&i(),m=!1}try{r=new IntersectionObserver(w,{...P,root:o.ownerDocument})}catch{r=new IntersectionObserver(w,P)}r.observe(e)}return i(!0),s}function ds(e,t,r,n){n===void 0&&(n={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:f=!1}=n,c=mt(e),d=o||s?[...c?Ne(c):[],...Ne(t)]:[];d.forEach(S=>{o&&S.addEventListener("scroll",r,{passive:!0}),s&&S.addEventListener("resize",r)});const h=c&&l?cs(c,r):null;let p=-1,g=null;i&&(g=new ResizeObserver(S=>{let[E]=S;E&&E.target===c&&g&&(g.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var P;(P=g)==null||P.observe(t)})),r()}),c&&!f&&g.observe(c),g.observe(t));let v,y=f?ue(e):null;f&&C();function C(){const S=ue(e);y&&!Mr(y,S)&&r(),y=S,v=requestAnimationFrame(C)}return r(),()=>{var S;d.forEach(E=>{o&&E.removeEventListener("scroll",r),s&&E.removeEventListener("resize",r)}),h==null||h(),(S=g)==null||S.disconnect(),g=null,f&&cancelAnimationFrame(v)}}const fs=Io,us=zo,hs=Do,ps=Fo,gs=Mo,kr=_o,ms=$o,vs=(e,t,r)=>{const n=new Map,o={platform:ls,...r},s={...o.platform,_c:n};return Lo(e,t,{...o,platform:s})};var ws=typeof document<"u",bs=function(){},Ye=ws?L.useLayoutEffect:bs;function Ue(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let r,n,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(r=e.length,r!==t.length)return!1;for(n=r;n--!==0;)if(!Ue(e[n],t[n]))return!1;return!0}if(o=Object.keys(e),r=o.length,r!==Object.keys(t).length)return!1;for(n=r;n--!==0;)if(!{}.hasOwnProperty.call(t,o[n]))return!1;for(n=r;n--!==0;){const s=o[n];if(!(s==="_owner"&&e.$$typeof)&&!Ue(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Ir(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function zr(e,t){const r=Ir(e);return Math.round(t*r)/r}function bt(e){const t=u.useRef(e);return Ye(()=>{t.current=e}),t}function ys(e){e===void 0&&(e={});const{placement:t="bottom",strategy:r="absolute",middleware:n=[],platform:o,elements:{reference:s,floating:i}={},transform:l=!0,whileElementsMounted:f,open:c}=e,[d,h]=u.useState({x:0,y:0,strategy:r,placement:t,middlewareData:{},isPositioned:!1}),[p,g]=u.useState(n);Ue(p,n)||g(n);const[v,y]=u.useState(null),[C,S]=u.useState(null),E=u.useCallback(M=>{M!==_.current&&(_.current=M,y(M))},[]),P=u.useCallback(M=>{M!==T.current&&(T.current=M,S(M))},[]),m=s||v,w=i||C,_=u.useRef(null),T=u.useRef(null),k=u.useRef(d),I=f!=null,z=bt(f),x=bt(o),b=bt(c),A=u.useCallback(()=>{if(!_.current||!T.current)return;const M={placement:t,strategy:r,middleware:p};x.current&&(M.platform=x.current),vs(_.current,T.current,M).then(B=>{const $={...B,isPositioned:b.current!==!1};D.current&&!Ue(k.current,$)&&(k.current=$,Pt.flushSync(()=>{h($)}))})},[p,t,r,x,b]);Ye(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,h(M=>({...M,isPositioned:!1})))},[c]);const D=u.useRef(!1);Ye(()=>(D.current=!0,()=>{D.current=!1}),[]),Ye(()=>{if(m&&(_.current=m),w&&(T.current=w),m&&w){if(z.current)return z.current(m,w,A);A()}},[m,w,A,z,I]);const F=u.useMemo(()=>({reference:_,floating:T,setReference:E,setFloating:P}),[E,P]),N=u.useMemo(()=>({reference:m,floating:w}),[m,w]),H=u.useMemo(()=>{const M={position:r,left:0,top:0};if(!N.floating)return M;const B=zr(N.floating,d.x),$=zr(N.floating,d.y);return l?{...M,transform:"translate("+B+"px, "+$+"px)",...Ir(N.floating)>=1.5&&{willChange:"transform"}}:{position:r,left:B,top:$}},[r,l,N.floating,d.x,d.y]);return u.useMemo(()=>({...d,update:A,refs:F,elements:N,floatingStyles:H}),[d,A,F,N,H])}const xs=e=>{function t(r){return{}.hasOwnProperty.call(r,"current")}return{name:"arrow",options:e,fn(r){const{element:n,padding:o}=typeof e=="function"?e(r):e;return n&&t(n)?n.current!=null?kr({element:n.current,padding:o}).fn(r):{}:n?kr({element:n,padding:o}).fn(r):{}}}},Cs=(e,t)=>({...fs(e),options:[e,t]}),Ss=(e,t)=>({...us(e),options:[e,t]}),Es=(e,t)=>({...ms(e),options:[e,t]}),Ts=(e,t)=>({...hs(e),options:[e,t]}),Ns=(e,t)=>({...ps(e),options:[e,t]}),Ps=(e,t)=>({...gs(e),options:[e,t]}),As=(e,t)=>({...xs(e),options:[e,t]});var Os="Arrow",$r=u.forwardRef((e,t)=>{const{children:r,width:n=10,height:o=5,...s}=e;return a.jsx(U.svg,{...s,ref:t,width:n,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?r:a.jsx("polygon",{points:"0,0 30,0 15,10"})})});$r.displayName=Os;var Ls=$r;function _s(e){const[t,r]=u.useState(void 0);return le(()=>{if(e){r({width:e.offsetWidth,height:e.offsetHeight});const n=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,l;if("borderBoxSize"in s){const f=s.borderBoxSize,c=Array.isArray(f)?f[0]:f;i=c.inlineSize,l=c.blockSize}else i=e.offsetWidth,l=e.offsetHeight;r({width:i,height:l})});return n.observe(e,{box:"border-box"}),()=>n.unobserve(e)}else r(void 0)},[e]),t}var yt="Popper",[Fr,Hr]=tt(yt),[Ds,Wr]=Fr(yt),Br=e=>{const{__scopePopper:t,children:r}=e,[n,o]=u.useState(null);return a.jsx(Ds,{scope:t,anchor:n,onAnchorChange:o,children:r})};Br.displayName=yt;var jr="PopperAnchor",Vr=u.forwardRef((e,t)=>{const{__scopePopper:r,virtualRef:n,...o}=e,s=Wr(jr,r),i=u.useRef(null),l=q(t,i);return u.useEffect(()=>{s.onAnchorChange((n==null?void 0:n.current)||i.current)}),n?null:a.jsx(U.div,{...o,ref:l})});Vr.displayName=jr;var xt="PopperContent",[Ms,ks]=Fr(xt),Xr=u.forwardRef((e,t)=>{var on,sn,an,ln,cn,dn;const{__scopePopper:r,side:n="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:l=0,avoidCollisions:f=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:v,...y}=e,C=Wr(xt,r),[S,E]=u.useState(null),P=q(t,Oe=>E(Oe)),[m,w]=u.useState(null),_=_s(m),T=(_==null?void 0:_.width)??0,k=(_==null?void 0:_.height)??0,I=n+(s!=="center"?"-"+s:""),z=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},x=Array.isArray(c)?c:[c],b=x.length>0,A={padding:z,boundary:x.filter(zs),altBoundary:b},{refs:D,floatingStyles:F,placement:N,isPositioned:H,middlewareData:M}=ys({strategy:"fixed",placement:I,whileElementsMounted:(...Oe)=>ds(...Oe,{animationFrame:g==="always"}),elements:{reference:C.anchor},middleware:[Cs({mainAxis:o+k,alignmentAxis:i}),f&&Ss({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Es():void 0,...A}),f&&Ts({...A}),Ns({...A,apply:({elements:Oe,rects:fn,availableWidth:xi,availableHeight:Ci})=>{const{width:Si,height:Ei}=fn.reference,Ke=Oe.floating.style;Ke.setProperty("--radix-popper-available-width",`${xi}px`),Ke.setProperty("--radix-popper-available-height",`${Ci}px`),Ke.setProperty("--radix-popper-anchor-width",`${Si}px`),Ke.setProperty("--radix-popper-anchor-height",`${Ei}px`)}}),m&&As({element:m,padding:l}),$s({arrowWidth:T,arrowHeight:k}),p&&Ps({strategy:"referenceHidden",...A})]}),[B,$]=qr(N),Y=Z(v);le(()=>{H&&(Y==null||Y())},[H,Y]);const Ce=(on=M.arrow)==null?void 0:on.x,Ae=(sn=M.arrow)==null?void 0:sn.y,wi=((an=M.arrow)==null?void 0:an.centerOffset)!==0,[bi,yi]=u.useState();return le(()=>{S&&yi(window.getComputedStyle(S).zIndex)},[S]),a.jsx("div",{ref:D.setFloating,"data-radix-popper-content-wrapper":"",style:{...F,transform:H?F.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:bi,"--radix-popper-transform-origin":[(ln=M.transformOrigin)==null?void 0:ln.x,(cn=M.transformOrigin)==null?void 0:cn.y].join(" "),...((dn=M.hide)==null?void 0:dn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:a.jsx(Ms,{scope:r,placedSide:B,onArrowChange:w,arrowX:Ce,arrowY:Ae,shouldHideArrow:wi,children:a.jsx(U.div,{"data-side":B,"data-align":$,...y,ref:P,style:{...y.style,animation:H?void 0:"none"}})})})});Xr.displayName=xt;var Yr="PopperArrow",Is={top:"bottom",right:"left",bottom:"top",left:"right"},Ur=u.forwardRef(function(t,r){const{__scopePopper:n,...o}=t,s=ks(Yr,n),i=Is[s.placedSide];return a.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:a.jsx(Ls,{...o,ref:r,style:{...o.style,display:"block"}})})});Ur.displayName=Yr;function zs(e){return e!==null}var $s=e=>({name:"transformOrigin",options:e,fn(t){var C,S,E;const{placement:r,rects:n,middlewareData:o}=t,i=((C=o.arrow)==null?void 0:C.centerOffset)!==0,l=i?0:e.arrowWidth,f=i?0:e.arrowHeight,[c,d]=qr(r),h={start:"0%",center:"50%",end:"100%"}[d],p=(((S=o.arrow)==null?void 0:S.x)??0)+l/2,g=(((E=o.arrow)==null?void 0:E.y)??0)+f/2;let v="",y="";return c==="bottom"?(v=i?h:`${p}px`,y=`${-f}px`):c==="top"?(v=i?h:`${p}px`,y=`${n.floating.height+f}px`):c==="right"?(v=`${-f}px`,y=i?h:`${g}px`):c==="left"&&(v=`${n.floating.width+f}px`,y=i?h:`${g}px`),{data:{x:v,y}}}});function qr(e){const[t,r="center"]=e.split("-");return[t,r]}var Fs=Br,Hs=Vr,Ws=Xr,Bs=Ur,js=u[" useInsertionEffect ".trim().toString()]||le;function Vs({prop:e,defaultProp:t,onChange:r=()=>{},caller:n}){const[o,s,i]=Xs({defaultProp:t,onChange:r}),l=e!==void 0,f=l?e:o;{const d=u.useRef(e!==void 0);u.useEffect(()=>{const h=d.current;h!==l&&console.warn(`${n} is changing from ${h?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=l},[l,n])}const c=u.useCallback(d=>{var h;if(l){const p=Ys(d)?d(e):d;p!==e&&((h=i.current)==null||h.call(i,p))}else s(d)},[l,e,s,i]);return[f,c]}function Xs({defaultProp:e,onChange:t}){const[r,n]=u.useState(e),o=u.useRef(r),s=u.useRef(t);return js(()=>{s.current=t},[t]),u.useEffect(()=>{var i;o.current!==r&&((i=s.current)==null||i.call(s,r),o.current=r)},[r,o]),[r,n,s]}function Ys(e){return typeof e=="function"}var Us=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"}),qs="VisuallyHidden",Jr=u.forwardRef((e,t)=>a.jsx(U.span,{...e,ref:t,style:{...Us,...e.style}}));Jr.displayName=qs;var Js=Jr,[qe,Ni]=tt("Tooltip",[Hr]),Je=Hr(),Gr="TooltipProvider",Gs=700,Ct="tooltip.open",[Ks,St]=qe(Gr),Kr=e=>{const{__scopeTooltip:t,delayDuration:r=Gs,skipDelayDuration:n=300,disableHoverableContent:o=!1,children:s}=e,i=u.useRef(!0),l=u.useRef(!1),f=u.useRef(0);return u.useEffect(()=>{const c=f.current;return()=>window.clearTimeout(c)},[]),a.jsx(Ks,{scope:t,isOpenDelayedRef:i,delayDuration:r,onOpen:u.useCallback(()=>{window.clearTimeout(f.current),i.current=!1},[]),onClose:u.useCallback(()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>i.current=!0,n)},[n]),isPointerInTransitRef:l,onPointerInTransitChange:u.useCallback(c=>{l.current=c},[]),disableHoverableContent:o,children:s})};Kr.displayName=Gr;var Pe="Tooltip",[Zs,Ge]=qe(Pe),Zr=e=>{const{__scopeTooltip:t,children:r,open:n,defaultOpen:o,onOpenChange:s,disableHoverableContent:i,delayDuration:l}=e,f=St(Pe,e.__scopeTooltip),c=Je(t),[d,h]=u.useState(null),p=wo(),g=u.useRef(0),v=i??f.disableHoverableContent,y=l??f.delayDuration,C=u.useRef(!1),[S,E]=Vs({prop:n,defaultProp:o??!1,onChange:T=>{T?(f.onOpen(),document.dispatchEvent(new CustomEvent(Ct))):f.onClose(),s==null||s(T)},caller:Pe}),P=u.useMemo(()=>S?C.current?"delayed-open":"instant-open":"closed",[S]),m=u.useCallback(()=>{window.clearTimeout(g.current),g.current=0,C.current=!1,E(!0)},[E]),w=u.useCallback(()=>{window.clearTimeout(g.current),g.current=0,E(!1)},[E]),_=u.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{C.current=!0,E(!0),g.current=0},y)},[y,E]);return u.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),a.jsx(Fs,{...c,children:a.jsx(Zs,{scope:t,contentId:p,open:S,stateAttribute:P,trigger:d,onTriggerChange:h,onTriggerEnter:u.useCallback(()=>{f.isOpenDelayedRef.current?_():m()},[f.isOpenDelayedRef,_,m]),onTriggerLeave:u.useCallback(()=>{v?w():(window.clearTimeout(g.current),g.current=0)},[w,v]),onOpen:m,onClose:w,disableHoverableContent:v,children:r})})};Zr.displayName=Pe;var Et="TooltipTrigger",Qr=u.forwardRef((e,t)=>{const{__scopeTooltip:r,...n}=e,o=Ge(Et,r),s=St(Et,r),i=Je(r),l=u.useRef(null),f=q(t,l,o.onTriggerChange),c=u.useRef(!1),d=u.useRef(!1),h=u.useCallback(()=>c.current=!1,[]);return u.useEffect(()=>()=>document.removeEventListener("pointerup",h),[h]),a.jsx(Hs,{asChild:!0,...i,children:a.jsx(U.button,{"aria-describedby":o.open?o.contentId:void 0,"data-state":o.stateAttribute,...n,ref:f,onPointerMove:V(e.onPointerMove,p=>{p.pointerType!=="touch"&&!d.current&&!s.isPointerInTransitRef.current&&(o.onTriggerEnter(),d.current=!0)}),onPointerLeave:V(e.onPointerLeave,()=>{o.onTriggerLeave(),d.current=!1}),onPointerDown:V(e.onPointerDown,()=>{o.open&&o.onClose(),c.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:V(e.onFocus,()=>{c.current||o.onOpen()}),onBlur:V(e.onBlur,o.onClose),onClick:V(e.onClick,o.onClose)})})});Qr.displayName=Et;var Qs="TooltipPortal",[Pi,Rs]=qe(Qs,{forceMount:void 0}),xe="TooltipContent",Rr=u.forwardRef((e,t)=>{const r=Rs(xe,e.__scopeTooltip),{forceMount:n=r.forceMount,side:o="top",...s}=e,i=Ge(xe,e.__scopeTooltip);return a.jsx(pe,{present:n||i.open,children:i.disableHoverableContent?a.jsx(en,{side:o,...s,ref:t}):a.jsx(ei,{side:o,...s,ref:t})})}),ei=u.forwardRef((e,t)=>{const r=Ge(xe,e.__scopeTooltip),n=St(xe,e.__scopeTooltip),o=u.useRef(null),s=q(t,o),[i,l]=u.useState(null),{trigger:f,onClose:c}=r,d=o.current,{onPointerInTransitChange:h}=n,p=u.useCallback(()=>{l(null),h(!1)},[h]),g=u.useCallback((v,y)=>{const C=v.currentTarget,S={x:v.clientX,y:v.clientY},E=si(S,C.getBoundingClientRect()),P=ii(S,E),m=ai(y.getBoundingClientRect()),w=ci([...P,...m]);l(w),h(!0)},[h]);return u.useEffect(()=>()=>p(),[p]),u.useEffect(()=>{if(f&&d){const v=C=>g(C,d),y=C=>g(C,f);return f.addEventListener("pointerleave",v),d.addEventListener("pointerleave",y),()=>{f.removeEventListener("pointerleave",v),d.removeEventListener("pointerleave",y)}}},[f,d,g,p]),u.useEffect(()=>{if(i){const v=y=>{const C=y.target,S={x:y.clientX,y:y.clientY},E=(f==null?void 0:f.contains(C))||(d==null?void 0:d.contains(C)),P=!li(S,i);E?p():P&&(p(),c())};return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[f,d,i,c,p]),a.jsx(en,{...e,ref:s})}),[ti,ri]=qe(Pe,{isInside:!1}),ni=Ze.createSlottable("TooltipContent"),en=u.forwardRef((e,t)=>{const{__scopeTooltip:r,children:n,"aria-label":o,onEscapeKeyDown:s,onPointerDownOutside:i,...l}=e,f=Ge(xe,r),c=Je(r),{onClose:d}=f;return u.useEffect(()=>(document.addEventListener(Ct,d),()=>document.removeEventListener(Ct,d)),[d]),u.useEffect(()=>{if(f.trigger){const h=p=>{const g=p.target;g!=null&&g.contains(f.trigger)&&d()};return window.addEventListener("scroll",h,{capture:!0}),()=>window.removeEventListener("scroll",h,{capture:!0})}},[f.trigger,d]),a.jsx(hr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:h=>h.preventDefault(),onDismiss:d,children:a.jsxs(Ws,{"data-state":f.stateAttribute,...c,...l,ref:t,style:{...l.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:[a.jsx(ni,{children:n}),a.jsx(ti,{scope:r,isInside:!0,children:a.jsx(Js,{id:f.contentId,role:"tooltip",children:o||n})})]})})});Rr.displayName=xe;var tn="TooltipArrow",oi=u.forwardRef((e,t)=>{const{__scopeTooltip:r,...n}=e,o=Je(r);return ri(tn,r).isInside?null:a.jsx(Bs,{...o,...n,ref:t})});oi.displayName=tn;function si(e,t){const r=Math.abs(t.top-e.y),n=Math.abs(t.bottom-e.y),o=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(r,n,o,s)){case s:return"left";case o:return"right";case r:return"top";case n:return"bottom";default:throw new Error("unreachable")}}function ii(e,t,r=5){const n=[];switch(t){case"top":n.push({x:e.x-r,y:e.y+r},{x:e.x+r,y:e.y+r});break;case"bottom":n.push({x:e.x-r,y:e.y-r},{x:e.x+r,y:e.y-r});break;case"left":n.push({x:e.x+r,y:e.y-r},{x:e.x+r,y:e.y+r});break;case"right":n.push({x:e.x-r,y:e.y-r},{x:e.x-r,y:e.y+r});break}return n}function ai(e){const{top:t,right:r,bottom:n,left:o}=e;return[{x:o,y:t},{x:r,y:t},{x:r,y:n},{x:o,y:n}]}function li(e,t){const{x:r,y:n}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const l=t[s],f=t[i],c=l.x,d=l.y,h=f.x,p=f.y;d>n!=p>n&&r<(h-c)*(n-d)/(p-d)+c&&(o=!o)}return o}function ci(e){const t=e.slice();return t.sort((r,n)=>r.x<n.x?-1:r.x>n.x?1:r.y<n.y?-1:r.y>n.y?1:0),di(t)}function di(e){if(e.length<=1)return e.slice();const t=[];for(let n=0;n<e.length;n++){const o=e[n];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 r=[];for(let n=e.length-1;n>=0;n--){const o=e[n];for(;r.length>=2;){const s=r[r.length-1],i=r[r.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))r.pop();else break}r.push(o)}return r.pop(),t.length===1&&r.length===1&&t[0].x===r[0].x&&t[0].y===r[0].y?t:t.concat(r)}var fi=Kr,ui=Zr,hi=Qr,rn=Rr;const pi=fi,gi=ui,mi=hi,nn=u.forwardRef(({className:e,sideOffset:t=4,...r},n)=>a.jsx(rn,{ref:n,sideOffset:t,className:X("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),...r}));nn.displayName=rn.displayName;const vi={ChatProvider:Le,ChatInterface:he,MessageComponent:et,ThreadManager:me,ChatApp:qt,useChat:fe};O.Button=j,O.Card=Zt,O.CardContent=tr,O.CardDescription=er,O.CardFooter=rr,O.CardHeader=Qt,O.CardTitle=Rt,O.ChatApp=qt,O.ChatInterface=he,O.ChatProvider=Le,O.ChatWidget=Kn,O.Input=nr,O.Label=ir,O.MESSAGE_MAX_LENGTH=Qe,O.MessageComponent=et,O.ScrollArea=it,O.Separator=dr,O.THREAD_ID_PATTERN=At,O.TITLE_MAX_LENGTH=Re,O.Textarea=_e,O.ThreadManager=me,O.Tooltip=gi,O.TooltipContent=nn,O.TooltipProvider=pi,O.TooltipTrigger=mi,O.cn=X,O.default=vi,O.safeJsonParse=wn,O.sanitizeHtml=gn,O.sanitizeText=ae,O.useChat=fe,O.useChatActions=Qn,O.useChatMessages=Gt,O.useCodeExecution=to,O.useFileContents=eo,O.useSearchResults=Rn,O.useStreamMonitor=Kt,O.useToolExtractor=$e,O.useToolMessages=Zn,O.validateAndSanitizeMessage=Se,O.validateAndSanitizeTitle=vn,O.validateMessageLength=Ot,O.validateThreadId=mn,O.withInputValidation=bn,Object.defineProperties(O,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ ${n===v.id?"bg-blue-100 border-blue-300 border":"bg-gray-50 hover:bg-gray-100 border border-transparent"}
9
+ `,onClick:()=>m(v.id),children:a.jsx("div",{className:"flex items-center justify-between",children:d===v.id?a.jsxs("div",{className:"flex-1 flex gap-2",children:[a.jsx("input",{value:p,onChange:b=>g(b.target.value),onKeyDown:b=>{b.key==="Enter"&&E(v.id),b.key==="Escape"&&A()},className:"flex-1 px-2 py-1 text-sm border rounded",autoFocus:!0}),a.jsx(B,{size:"sm",onClick:b=>{b.stopPropagation(),E(v.id)},children:"Save"})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"font-medium text-sm truncate",children:v.title||`Thread ${v.id.slice(0,8)}`}),a.jsx("div",{className:"text-xs text-gray-500",children:new Date(v.updated_at).toLocaleDateString()})]}),a.jsxs("div",{className:"flex gap-1 opacity-100 transition-opacity",children:[a.jsx(B,{size:"sm",variant:"ghost",onClick:b=>S(b,v),className:"p-1 h-auto",children:a.jsx(F.Edit3,{size:12})}),a.jsx(B,{size:"sm",variant:"ghost",onClick:b=>{console.log("Delete button clicked!"),C(b,v.id)},className:"p-1 h-auto text-red-600 hover:text-red-700",style:{backgroundColor:"rgba(255, 0, 0, 0.1)"},children:a.jsx(F.Trash2,{size:12})})]})]})})},v.id)),o.length===0&&a.jsx("div",{className:"text-center text-gray-500 py-8",children:"No threads yet. Create your first thread to get started!"})]})})]})}function Zt({apiBaseUrl:e,enableUrlSync:t=!0,layout:r="sidebar",className:n=""}){return a.jsx(_e,{apiBaseUrl:e,enableUrlSync:t,children:a.jsxs("div",{className:`h-full ${n}`,children:[r==="sidebar"&&a.jsx(Gn,{}),r==="tabs"&&a.jsx(Kn,{}),r==="split"&&a.jsx(Zn,{})]})})}function Gn(){return a.jsxs("div",{className:"flex h-full",children:[a.jsx("div",{className:"w-80 border-r bg-gray-50",children:a.jsx(be,{})}),a.jsx("div",{className:"flex-1",children:a.jsx(me,{})})]})}function Kn(){const[e,t]=L.useState("chat");return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsx("div",{className:"border-b",children:a.jsxs("div",{className:"flex",children:[a.jsx("button",{onClick:()=>t("chat"),className:`px-4 py-2 font-medium ${e==="chat"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-700"}`,children:"Chat"}),a.jsx("button",{onClick:()=>t("threads"),className:`px-4 py-2 font-medium ${e==="threads"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-700"}`,children:"Threads"})]})}),a.jsxs("div",{className:"flex-1",children:[e==="chat"&&a.jsx(me,{}),e==="threads"&&a.jsx(be,{onThreadSelect:()=>t("chat")})]})]})}function Zn(){return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsx("div",{className:"h-1/3 border-b",children:a.jsx(be,{})}),a.jsx("div",{className:"flex-1",children:a.jsx(me,{})})]})}function Qn({placeholder:e,showThreadHistory:t=!0}){const[r,n]=L.useState(!1);L.useEffect(()=>{const s=()=>n(i=>!i);return window.addEventListener("toggleChatThreads",s),()=>window.removeEventListener("toggleChatThreads",s)},[]);const o=()=>{n(!1)};return a.jsxs("div",{className:"flex flex-col h-full relative",children:[t&&r&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40 bg-black/20",onClick:()=>n(!1)}),a.jsxs("div",{className:"absolute top-0 left-0 right-0 z-50 bg-white rounded-lg shadow-xl border border-gray-200 max-h-72 overflow-hidden",children:[a.jsx("div",{className:"p-3 border-b border-gray-100 bg-gray-50",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h4",{className:"font-medium text-sm text-gray-700",children:"Conversation History"}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>n(!1),className:"h-6 w-6 p-0 text-gray-400 hover:text-gray-600",children:a.jsx(F.X,{size:12})})]})}),a.jsx("div",{className:"max-h-56 overflow-y-auto",children:a.jsx(be,{className:"p-2",onThreadSelect:o})})]})]}),a.jsx("div",{className:"flex-1 h-full",children:a.jsx(me,{placeholder:e||"Type your message...",className:"h-full flex flex-col"})})]})}const Rn={sm:"w-80 h-80",md:"w-96 h-96",lg:"w-[28rem] h-[32rem]"},Qt={"bottom-right":"bottom-6 right-6","bottom-left":"bottom-6 left-6","top-right":"top-6 right-6","top-left":"top-6 left-6"};function eo({apiBaseUrl:e="http://localhost:8000/api/chat",title:t="AI Assistant",subtitle:r="How can I help you?",placeholder:n="Type your message...",getAuthHeaders:o,authToken:s,className:i="",position:l="bottom-right",size:f="md",theme:c="light",enableUrlSync:d=!0,defaultOpen:h=!1,showThreadHistory:p=!0,onMessageSent:g,onThreadChanged:m,onToggle:y}){const[C,S]=L.useState(h),[E,A]=L.useState(!1),v=N=>{S(N),y==null||y(N)};L.useEffect(()=>{d&&!C&&new URLSearchParams(window.location.search).get("thread")&&v(!0)},[d,C]),L.useEffect(()=>{if(d){const I=new URLSearchParams(window.location.search).get("thread");I&&m&&m(I)}},[d,m]);const b=c==="dark"?"bg-gray-900 text-white border-gray-700":"bg-white text-gray-900 border-gray-200",_=c==="dark"?"bg-gray-800 text-white":"bg-slate-800 text-white";return C?a.jsx(_e,{apiBaseUrl:e,enableUrlSync:d,getAuthHeaders:o,authToken:s,children:a.jsx("div",{className:`fixed ${Qt[l]} z-50 transition-all duration-300 ${E?"scale-75":"scale-100"}`,children:a.jsxs("div",{className:`${Rn[f]} ${b} rounded-xl shadow-2xl border overflow-hidden relative`,children:[a.jsx("div",{className:`${_} p-4 flex-shrink-0`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-8 h-8 bg-white/10 rounded-full flex items-center justify-center border border-slate-600",children:a.jsx(F.MessageCircle,{size:16,className:"text-white"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"font-semibold text-sm",children:t}),a.jsx("p",{className:"text-xs text-slate-300",children:r})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[p&&a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{const N=new CustomEvent("toggleChatThreads");window.dispatchEvent(N)},className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Conversation History",children:a.jsx(F.History,{size:14})}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>A(!E),className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:E?"Maximize":"Minimize",children:E?a.jsx(F.Maximize2,{size:14}):a.jsx(F.Minimize2,{size:14})}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>v(!1),className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Close",children:a.jsx(F.X,{size:14})})]})]})}),!E&&a.jsx("div",{className:"flex-1 h-full overflow-hidden",children:a.jsx(Qn,{placeholder:n,showThreadHistory:p})})]})})}):a.jsxs(B,{onClick:()=>v(!0),size:"lg",className:`fixed ${Qt[l]} h-14 w-14 rounded-full shadow-lg bg-slate-800 hover:bg-slate-700 z-50 transition-all duration-200 ${i}`,children:[a.jsx(F.MessageCircle,{size:24,className:"text-white"}),a.jsx("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-red-500 rounded-full animate-pulse"})]})}function Rt(){const e=pe();return{...L.useMemo(()=>({all:e.messages,human:e.messages.filter(r=>r.role==="human"),ai:e.messages.filter(r=>r.role==="ai"),tool:e.messages.filter(r=>r.role==="tool"),latest:e.messages[e.messages.length-1],latestHuman:[...e.messages].reverse().find(r=>r.role==="human"),latestAI:[...e.messages].reverse().find(r=>r.role==="ai"),latestTool:[...e.messages].reverse().find(r=>r.role==="tool")}),[e.messages]),isLoading:e.isLoading,error:e.error,refresh:e.refresh}}function to(){const{tool:e}=Rt(),t=L.useMemo(()=>e.map(i=>{let l="",f=null,c=!1;try{if(typeof i.content=="string"){l=i.content;try{f=JSON.parse(i.content),c=!0}catch{}}else f=i.content,l=JSON.stringify(i.content,null,2),c=!0}catch{l=String(i.content||"")}return{id:i.id||"",name:i.name||"",tool_call_id:i.tool_call_id||"",args:i.args,content:i.content,timestamp:i.timestamp,textContent:l,jsonContent:f,isJson:c}}),[e]),r=L.useMemo(()=>{const i={};return t.forEach(l=>{i[l.name]||(i[l.name]=[]),i[l.name].push(l)}),i},[t]),n=i=>{const l=r[i];return l==null?void 0:l[l.length-1]},o=i=>{var l;return((l=r[i])==null?void 0:l.map(f=>f.jsonContent||f.textContent))||[]},s=()=>t.map(i=>i.jsonContent||i.textContent);return{all:t,raw:e,byToolName:r,toolNames:Object.keys(r),getLatestByTool:n,getContentByTool:o,getAllContent:s,latest:t[t.length-1],count:t.length,hasToolMessages:t.length>0}}function ro(){const e=pe();return{currentThread:e.currentThreadId,isLoading:e.isLoading,error:e.error,sendMessage:e.sendMessage,createThread:e.createThread,selectThread:e.selectThread,deleteThread:e.deleteThread,clearError:e.clearError,stop:e.stop,refresh:e.refresh}}function er(){const e=pe(),[t,r]=L.useState({isStreaming:!1,events:[],latestEvent:null,error:null}),n=L.useRef(0),o=L.useRef(0);L.useEffect(()=>{r(c=>({...c,isStreaming:e.isLoading,error:e.error}))},[e.isLoading,e.error]),L.useEffect(()=>{const c=e.messages.length;c>n.current&&(e.messages.slice(n.current).forEach(h=>{const p={type:h.role==="tool"?"tool":"message",data:h,timestamp:Date.now()};r(g=>({...g,events:[...g.events,p],latestEvent:p}))}),n.current=c)},[e.messages]),L.useEffect(()=>{if(!e.isLoading&&t.isStreaming){const c={type:"complete",data:{messageCount:e.messages.length},timestamp:Date.now()};r(d=>({...d,isStreaming:!1,events:[...d.events,c],latestEvent:c}))}},[e.isLoading,t.isStreaming,e.messages.length]),L.useEffect(()=>{r(c=>({...c,events:[],latestEvent:null})),n.current=0,o.current=0},[e.currentThreadId]);const s=c=>t.events.filter(d=>d.type===c),i=c=>{const d=s(c);return d[d.length-1]||null},l=()=>t.events.filter(c=>c.type==="tool").map(c=>({...c,data:c.data}));return{...t,getEventsByType:s,getLatestEventByType:i,getToolEvents:l,clearEvents:()=>{r(c=>({...c,events:[],latestEvent:null}))},messageEvents:s("message"),toolEvents:l(),latestToolEvent:i("tool"),hasNewEvents:t.events.length>0}}function He(e,t){const{toolEvents:r,latestToolEvent:n}=er(),[o,s]=L.useState([]),[i,l]=L.useState(null);L.useEffect(()=>{const d=r.filter(h=>h.data.name===e).map(h=>{const p=h.data.jsonContent||h.data.textContent;return t?t(p):p});s(d),l(d[d.length-1]||null)},[r,e,t]);const f=(n==null?void 0:n.data.name)===e;return{data:o,latest:i,count:o.length,hasData:o.length>0,hasNewData:f}}const no=(e="search")=>He(e,t=>Array.isArray(t)?t:t!=null&&t.results?t.results:t!=null&&t.data?t.data:t),oo=(e="read_file")=>He(e,t=>typeof t=="string"?t:t!=null&&t.content?t.content:t!=null&&t.text?t.text:String(t)),so=(e="execute_code")=>He(e,t=>({output:(t==null?void 0:t.output)||(t==null?void 0:t.stdout)||t,error:(t==null?void 0:t.error)||(t==null?void 0:t.stderr)||null,exitCode:(t==null?void 0:t.exit_code)||(t==null?void 0:t.exitCode)||0})),tr=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:Y("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));tr.displayName="Card";const rr=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:Y("flex flex-col space-y-1.5 p-6",e),...t}));rr.displayName="CardHeader";const nr=u.forwardRef(({className:e,...t},r)=>a.jsx("h3",{ref:r,className:Y("text-2xl font-semibold leading-none tracking-tight",e),...t}));nr.displayName="CardTitle";const or=u.forwardRef(({className:e,...t},r)=>a.jsx("p",{ref:r,className:Y("text-sm text-muted-foreground",e),...t}));or.displayName="CardDescription";const sr=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:Y("p-6 pt-0",e),...t}));sr.displayName="CardContent";const ir=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:Y("flex items-center p-6 pt-0",e),...t}));ir.displayName="CardFooter";const ar=u.forwardRef(({className:e,type:t,...r},n)=>a.jsx("input",{type:t,className:Y("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:n,...r}));ar.displayName="Input";var io="Label",lr=u.forwardRef((e,t)=>a.jsx(U.label,{...e,ref:t,onMouseDown:r=>{var o;r.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,r),!r.defaultPrevented&&r.detail>1&&r.preventDefault())}}));lr.displayName=io;var cr=lr;const ao=Pt.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),dr=u.forwardRef(({className:e,...t},r)=>a.jsx(cr,{ref:r,className:Y(ao(),e),...t}));dr.displayName=cr.displayName;var lo="Separator",fr="horizontal",co=["horizontal","vertical"],ur=u.forwardRef((e,t)=>{const{decorative:r,orientation:n=fr,...o}=e,s=fo(n)?n:fr,l=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return a.jsx(U.div,{"data-orientation":s,...l,...o,ref:t})});ur.displayName=lo;function fo(e){return co.includes(e)}var hr=ur;const pr=u.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},o)=>a.jsx(hr,{ref:o,decorative:r,orientation:t,className:Y("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));pr.displayName=hr.displayName;function uo(e,t=globalThis==null?void 0:globalThis.document){const r=Q(e);u.useEffect(()=>{const n=o=>{o.key==="Escape"&&r(o)};return t.addEventListener("keydown",n,{capture:!0}),()=>t.removeEventListener("keydown",n,{capture:!0})},[r,t])}var ho="DismissableLayer",ct="dismissableLayer.update",po="dismissableLayer.pointerDownOutside",go="dismissableLayer.focusOutside",gr,mr=u.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),vr=u.forwardRef((e,t)=>{const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:n,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:l,...f}=e,c=u.useContext(mr),[d,h]=u.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,g]=u.useState({}),m=q(t,N=>h(N)),y=Array.from(c.layers),[C]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=y.indexOf(C),E=d?y.indexOf(d):-1,A=c.layersWithOutsidePointerEventsDisabled.size>0,v=E>=S,b=wo(N=>{const I=N.target,$=[...c.branches].some(z=>z.contains(I));!v||$||(o==null||o(N),i==null||i(N),N.defaultPrevented||l==null||l())},p),_=bo(N=>{const I=N.target;[...c.branches].some(z=>z.contains(I))||(s==null||s(N),i==null||i(N),N.defaultPrevented||l==null||l())},p);return uo(N=>{E===c.layers.size-1&&(n==null||n(N),!N.defaultPrevented&&l&&(N.preventDefault(),l()))},p),u.useEffect(()=>{if(d)return r&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(gr=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wr(),()=>{r&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=gr)}},[d,p,r,c]),u.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wr())},[d,c]),u.useEffect(()=>{const N=()=>g({});return document.addEventListener(ct,N),()=>document.removeEventListener(ct,N)},[]),a.jsx(U.div,{...f,ref:m,style:{pointerEvents:A?v?"auto":"none":void 0,...e.style},onFocusCapture:X(e.onFocusCapture,_.onFocusCapture),onBlurCapture:X(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:X(e.onPointerDownCapture,b.onPointerDownCapture)})});vr.displayName=ho;var mo="DismissableLayerBranch",vo=u.forwardRef((e,t)=>{const r=u.useContext(mr),n=u.useRef(null),o=q(t,n);return u.useEffect(()=>{const s=n.current;if(s)return r.branches.add(s),()=>{r.branches.delete(s)}},[r.branches]),a.jsx(U.div,{...e,ref:o})});vo.displayName=mo;function wo(e,t=globalThis==null?void 0:globalThis.document){const r=Q(e),n=u.useRef(!1),o=u.useRef(()=>{});return u.useEffect(()=>{const s=l=>{if(l.target&&!n.current){let f=function(){br(po,r,c,{discrete:!0})};const c={originalEvent:l};l.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=f,t.addEventListener("click",o.current,{once:!0})):f()}else t.removeEventListener("click",o.current);n.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,r]),{onPointerDownCapture:()=>n.current=!0}}function bo(e,t=globalThis==null?void 0:globalThis.document){const r=Q(e),n=u.useRef(!1);return u.useEffect(()=>{const o=s=>{s.target&&!n.current&&br(go,r,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,r]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function wr(){const e=new CustomEvent(ct);document.dispatchEvent(e)}function br(e,t,r,{discrete:n}){const o=r.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:r});t&&o.addEventListener(e,t,{once:!0}),n?Pn(o,s):o.dispatchEvent(s)}var yo=u[" useId ".trim().toString()]||(()=>{}),xo=0;function Co(e){const[t,r]=u.useState(yo());return fe(()=>{r(n=>n??String(xo++))},[e]),t?`radix-${t}`:""}const So=["top","right","bottom","left"],ue=Math.min,J=Math.max,Fe=Math.round,We=Math.floor,re=e=>({x:e,y:e}),Eo={left:"right",right:"left",bottom:"top",top:"bottom"},To={start:"end",end:"start"};function dt(e,t,r){return J(e,ue(t,r))}function le(e,t){return typeof e=="function"?e(t):e}function ce(e){return e.split("-")[0]}function ye(e){return e.split("-")[1]}function ft(e){return e==="x"?"y":"x"}function ut(e){return e==="y"?"height":"width"}const No=new Set(["top","bottom"]);function ne(e){return No.has(ce(e))?"y":"x"}function ht(e){return ft(ne(e))}function Po(e,t,r){r===void 0&&(r=!1);const n=ye(e),o=ht(e),s=ut(o);let i=o==="x"?n===(r?"end":"start")?"right":"left":n==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Be(i)),[i,Be(i)]}function Ao(e){const t=Be(e);return[pt(e),t,pt(t)]}function pt(e){return e.replace(/start|end/g,t=>To[t])}const yr=["left","right"],xr=["right","left"],Oo=["top","bottom"],Lo=["bottom","top"];function _o(e,t,r){switch(e){case"top":case"bottom":return r?t?xr:yr:t?yr:xr;case"left":case"right":return t?Oo:Lo;default:return[]}}function Do(e,t,r,n){const o=ye(e);let s=_o(ce(e),r==="start",n);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(pt)))),s}function Be(e){return e.replace(/left|right|bottom|top/g,t=>Eo[t])}function Mo(e){return{top:0,right:0,bottom:0,left:0,...e}}function Cr(e){return typeof e!="number"?Mo(e):{top:e,right:e,bottom:e,left:e}}function je(e){const{x:t,y:r,width:n,height:o}=e;return{width:n,height:o,top:r,left:t,right:t+n,bottom:r+o,x:t,y:r}}function Sr(e,t,r){let{reference:n,floating:o}=e;const s=ne(t),i=ht(t),l=ut(i),f=ce(t),c=s==="y",d=n.x+n.width/2-o.width/2,h=n.y+n.height/2-o.height/2,p=n[l]/2-o[l]/2;let g;switch(f){case"top":g={x:d,y:n.y-o.height};break;case"bottom":g={x:d,y:n.y+n.height};break;case"right":g={x:n.x+n.width,y:h};break;case"left":g={x:n.x-o.width,y:h};break;default:g={x:n.x,y:n.y}}switch(ye(t)){case"start":g[i]-=p*(r&&c?-1:1);break;case"end":g[i]+=p*(r&&c?-1:1);break}return g}const ko=async(e,t,r)=>{const{placement:n="bottom",strategy:o="absolute",middleware:s=[],platform:i}=r,l=s.filter(Boolean),f=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:h}=Sr(c,n,f),p=n,g={},m=0;for(let y=0;y<l.length;y++){const{name:C,fn:S}=l[y],{x:E,y:A,data:v,reset:b}=await S({x:d,y:h,initialPlacement:n,placement:p,strategy:o,middlewareData:g,rects:c,platform:i,elements:{reference:e,floating:t}});d=E??d,h=A??h,g={...g,[C]:{...g[C],...v}},b&&m<=50&&(m++,typeof b=="object"&&(b.placement&&(p=b.placement),b.rects&&(c=b.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):b.rects),{x:d,y:h}=Sr(c,p,f)),y=-1)}return{x:d,y:h,placement:p,strategy:o,middlewareData:g}};async function Ne(e,t){var r;t===void 0&&(t={});const{x:n,y:o,platform:s,rects:i,elements:l,strategy:f}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:p=!1,padding:g=0}=le(t,e),m=Cr(g),C=l[p?h==="floating"?"reference":"floating":h],S=je(await s.getClippingRect({element:(r=await(s.isElement==null?void 0:s.isElement(C)))==null||r?C:C.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:c,rootBoundary:d,strategy:f})),E=h==="floating"?{x:n,y:o,width:i.floating.width,height:i.floating.height}:i.reference,A=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),v=await(s.isElement==null?void 0:s.isElement(A))?await(s.getScale==null?void 0:s.getScale(A))||{x:1,y:1}:{x:1,y:1},b=je(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:E,offsetParent:A,strategy:f}):E);return{top:(S.top-b.top+m.top)/v.y,bottom:(b.bottom-S.bottom+m.bottom)/v.y,left:(S.left-b.left+m.left)/v.x,right:(b.right-S.right+m.right)/v.x}}const Io=e=>({name:"arrow",options:e,async fn(t){const{x:r,y:n,placement:o,rects:s,platform:i,elements:l,middlewareData:f}=t,{element:c,padding:d=0}=le(e,t)||{};if(c==null)return{};const h=Cr(d),p={x:r,y:n},g=ht(o),m=ut(g),y=await i.getDimensions(c),C=g==="y",S=C?"top":"left",E=C?"bottom":"right",A=C?"clientHeight":"clientWidth",v=s.reference[m]+s.reference[g]-p[g]-s.floating[m],b=p[g]-s.reference[g],_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let N=_?_[A]:0;(!N||!await(i.isElement==null?void 0:i.isElement(_)))&&(N=l.floating[A]||s.floating[m]);const I=v/2-b/2,$=N/2-y[m]/2-1,z=ue(h[S],$),W=ue(h[E],$),x=z,w=N-y[m]-W,P=N/2-y[m]/2+I,D=dt(x,P,w),T=!f.arrow&&ye(o)!=null&&P!==D&&s.reference[m]/2-(P<x?z:W)-y[m]/2<0,k=T?P<x?P-x:P-w:0;return{[g]:p[g]+k,data:{[g]:D,centerOffset:P-D-k,...T&&{alignmentOffset:k}},reset:T}}}),$o=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var r,n;const{placement:o,middlewareData:s,rects:i,initialPlacement:l,platform:f,elements:c}=t,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:y=!0,...C}=le(e,t);if((r=s.arrow)!=null&&r.alignmentOffset)return{};const S=ce(o),E=ne(l),A=ce(l)===l,v=await(f.isRTL==null?void 0:f.isRTL(c.floating)),b=p||(A||!y?[Be(l)]:Ao(l)),_=m!=="none";!p&&_&&b.push(...Do(l,y,m,v));const N=[l,...b],I=await Ne(t,C),$=[];let z=((n=s.flip)==null?void 0:n.overflows)||[];if(d&&$.push(I[S]),h){const P=Po(o,i,v);$.push(I[P[0]],I[P[1]])}if(z=[...z,{placement:o,overflows:$}],!$.every(P=>P<=0)){var W,x;const P=(((W=s.flip)==null?void 0:W.index)||0)+1,D=N[P];if(D&&(!(h==="alignment"?E!==ne(D):!1)||z.every(M=>M.overflows[0]>0&&ne(M.placement)===E)))return{data:{index:P,overflows:z},reset:{placement:D}};let T=(x=z.filter(k=>k.overflows[0]<=0).sort((k,M)=>k.overflows[1]-M.overflows[1])[0])==null?void 0:x.placement;if(!T)switch(g){case"bestFit":{var w;const k=(w=z.filter(M=>{if(_){const j=ne(M.placement);return j===E||j==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(j=>j>0).reduce((j,H)=>j+H,0)]).sort((M,j)=>M[1]-j[1])[0])==null?void 0:w[0];k&&(T=k);break}case"initialPlacement":T=l;break}if(o!==T)return{reset:{placement:T}}}return{}}}};function Er(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Tr(e){return So.some(t=>e[t]>=0)}const zo=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:r}=t,{strategy:n="referenceHidden",...o}=le(e,t);switch(n){case"referenceHidden":{const s=await Ne(t,{...o,elementContext:"reference"}),i=Er(s,r.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Tr(i)}}}case"escaped":{const s=await Ne(t,{...o,altBoundary:!0}),i=Er(s,r.floating);return{data:{escapedOffsets:i,escaped:Tr(i)}}}default:return{}}}}},Nr=new Set(["left","top"]);async function Ho(e,t){const{placement:r,platform:n,elements:o}=e,s=await(n.isRTL==null?void 0:n.isRTL(o.floating)),i=ce(r),l=ye(r),f=ne(r)==="y",c=Nr.has(i)?-1:1,d=s&&f?-1:1,h=le(t,e);let{mainAxis:p,crossAxis:g,alignmentAxis:m}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return l&&typeof m=="number"&&(g=l==="end"?m*-1:m),f?{x:g*d,y:p*c}:{x:p*c,y:g*d}}const Fo=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var r,n;const{x:o,y:s,placement:i,middlewareData:l}=t,f=await Ho(t,e);return i===((r=l.offset)==null?void 0:r.placement)&&(n=l.arrow)!=null&&n.alignmentOffset?{}:{x:o+f.x,y:s+f.y,data:{...f,placement:i}}}}},Wo=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:r,y:n,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:l={fn:C=>{let{x:S,y:E}=C;return{x:S,y:E}}},...f}=le(e,t),c={x:r,y:n},d=await Ne(t,f),h=ne(ce(o)),p=ft(h);let g=c[p],m=c[h];if(s){const C=p==="y"?"top":"left",S=p==="y"?"bottom":"right",E=g+d[C],A=g-d[S];g=dt(E,g,A)}if(i){const C=h==="y"?"top":"left",S=h==="y"?"bottom":"right",E=m+d[C],A=m-d[S];m=dt(E,m,A)}const y=l.fn({...t,[p]:g,[h]:m});return{...y,data:{x:y.x-r,y:y.y-n,enabled:{[p]:s,[h]:i}}}}}},Bo=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:r,y:n,placement:o,rects:s,middlewareData:i}=t,{offset:l=0,mainAxis:f=!0,crossAxis:c=!0}=le(e,t),d={x:r,y:n},h=ne(o),p=ft(h);let g=d[p],m=d[h];const y=le(l,t),C=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(f){const A=p==="y"?"height":"width",v=s.reference[p]-s.floating[A]+C.mainAxis,b=s.reference[p]+s.reference[A]-C.mainAxis;g<v?g=v:g>b&&(g=b)}if(c){var S,E;const A=p==="y"?"width":"height",v=Nr.has(ce(o)),b=s.reference[h]-s.floating[A]+(v&&((S=i.offset)==null?void 0:S[h])||0)+(v?0:C.crossAxis),_=s.reference[h]+s.reference[A]+(v?0:((E=i.offset)==null?void 0:E[h])||0)-(v?C.crossAxis:0);m<b?m=b:m>_&&(m=_)}return{[p]:g,[h]:m}}}},jo=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var r,n;const{placement:o,rects:s,platform:i,elements:l}=t,{apply:f=()=>{},...c}=le(e,t),d=await Ne(t,c),h=ce(o),p=ye(o),g=ne(o)==="y",{width:m,height:y}=s.floating;let C,S;h==="top"||h==="bottom"?(C=h,S=p===(await(i.isRTL==null?void 0:i.isRTL(l.floating))?"start":"end")?"left":"right"):(S=h,C=p==="end"?"top":"bottom");const E=y-d.top-d.bottom,A=m-d.left-d.right,v=ue(y-d[C],E),b=ue(m-d[S],A),_=!t.middlewareData.shift;let N=v,I=b;if((r=t.middlewareData.shift)!=null&&r.enabled.x&&(I=A),(n=t.middlewareData.shift)!=null&&n.enabled.y&&(N=E),_&&!p){const z=J(d.left,0),W=J(d.right,0),x=J(d.top,0),w=J(d.bottom,0);g?I=m-2*(z!==0||W!==0?z+W:J(d.left,d.right)):N=y-2*(x!==0||w!==0?x+w:J(d.top,d.bottom))}await f({...t,availableWidth:I,availableHeight:N});const $=await i.getDimensions(l.floating);return m!==$.width||y!==$.height?{reset:{rects:!0}}:{}}}};function Ve(){return typeof window<"u"}function xe(e){return Pr(e)?(e.nodeName||"").toLowerCase():"#document"}function G(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function oe(e){var t;return(t=(Pr(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Pr(e){return Ve()?e instanceof Node||e instanceof G(e).Node:!1}function R(e){return Ve()?e instanceof Element||e instanceof G(e).Element:!1}function se(e){return Ve()?e instanceof HTMLElement||e instanceof G(e).HTMLElement:!1}function Ar(e){return!Ve()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof G(e).ShadowRoot}const Vo=new Set(["inline","contents"]);function Pe(e){const{overflow:t,overflowX:r,overflowY:n,display:o}=ee(e);return/auto|scroll|overlay|hidden|clip/.test(t+n+r)&&!Vo.has(o)}const Xo=new Set(["table","td","th"]);function Yo(e){return Xo.has(xe(e))}const Uo=[":popover-open",":modal"];function Xe(e){return Uo.some(t=>{try{return e.matches(t)}catch{return!1}})}const qo=["transform","translate","scale","rotate","perspective"],Jo=["transform","translate","scale","rotate","perspective","filter"],Go=["paint","layout","strict","content"];function gt(e){const t=mt(),r=R(e)?ee(e):e;return qo.some(n=>r[n]?r[n]!=="none":!1)||(r.containerType?r.containerType!=="normal":!1)||!t&&(r.backdropFilter?r.backdropFilter!=="none":!1)||!t&&(r.filter?r.filter!=="none":!1)||Jo.some(n=>(r.willChange||"").includes(n))||Go.some(n=>(r.contain||"").includes(n))}function Ko(e){let t=he(e);for(;se(t)&&!Ce(t);){if(gt(t))return t;if(Xe(t))return null;t=he(t)}return null}function mt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Zo=new Set(["html","body","#document"]);function Ce(e){return Zo.has(xe(e))}function ee(e){return G(e).getComputedStyle(e)}function Ye(e){return R(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function he(e){if(xe(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Ar(e)&&e.host||oe(e);return Ar(t)?t.host:t}function Or(e){const t=he(e);return Ce(t)?e.ownerDocument?e.ownerDocument.body:e.body:se(t)&&Pe(t)?t:Or(t)}function Ae(e,t,r){var n;t===void 0&&(t=[]),r===void 0&&(r=!0);const o=Or(e),s=o===((n=e.ownerDocument)==null?void 0:n.body),i=G(o);if(s){const l=vt(i);return t.concat(i,i.visualViewport||[],Pe(o)?o:[],l&&r?Ae(l):[])}return t.concat(o,Ae(o,[],r))}function vt(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Lr(e){const t=ee(e);let r=parseFloat(t.width)||0,n=parseFloat(t.height)||0;const o=se(e),s=o?e.offsetWidth:r,i=o?e.offsetHeight:n,l=Fe(r)!==s||Fe(n)!==i;return l&&(r=s,n=i),{width:r,height:n,$:l}}function wt(e){return R(e)?e:e.contextElement}function Se(e){const t=wt(e);if(!se(t))return re(1);const r=t.getBoundingClientRect(),{width:n,height:o,$:s}=Lr(t);let i=(s?Fe(r.width):r.width)/n,l=(s?Fe(r.height):r.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const Qo=re(0);function _r(e){const t=G(e);return!mt()||!t.visualViewport?Qo:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ro(e,t,r){return t===void 0&&(t=!1),!r||t&&r!==G(e)?!1:t}function ge(e,t,r,n){t===void 0&&(t=!1),r===void 0&&(r=!1);const o=e.getBoundingClientRect(),s=wt(e);let i=re(1);t&&(n?R(n)&&(i=Se(n)):i=Se(e));const l=Ro(s,r,n)?_r(s):re(0);let f=(o.left+l.x)/i.x,c=(o.top+l.y)/i.y,d=o.width/i.x,h=o.height/i.y;if(s){const p=G(s),g=n&&R(n)?G(n):n;let m=p,y=vt(m);for(;y&&n&&g!==m;){const C=Se(y),S=y.getBoundingClientRect(),E=ee(y),A=S.left+(y.clientLeft+parseFloat(E.paddingLeft))*C.x,v=S.top+(y.clientTop+parseFloat(E.paddingTop))*C.y;f*=C.x,c*=C.y,d*=C.x,h*=C.y,f+=A,c+=v,m=G(y),y=vt(m)}}return je({width:d,height:h,x:f,y:c})}function bt(e,t){const r=Ye(e).scrollLeft;return t?t.left+r:ge(oe(e)).left+r}function Dr(e,t,r){r===void 0&&(r=!1);const n=e.getBoundingClientRect(),o=n.left+t.scrollLeft-(r?0:bt(e,n)),s=n.top+t.scrollTop;return{x:o,y:s}}function es(e){let{elements:t,rect:r,offsetParent:n,strategy:o}=e;const s=o==="fixed",i=oe(n),l=t?Xe(t.floating):!1;if(n===i||l&&s)return r;let f={scrollLeft:0,scrollTop:0},c=re(1);const d=re(0),h=se(n);if((h||!h&&!s)&&((xe(n)!=="body"||Pe(i))&&(f=Ye(n)),se(n))){const g=ge(n);c=Se(n),d.x=g.x+n.clientLeft,d.y=g.y+n.clientTop}const p=i&&!h&&!s?Dr(i,f,!0):re(0);return{width:r.width*c.x,height:r.height*c.y,x:r.x*c.x-f.scrollLeft*c.x+d.x+p.x,y:r.y*c.y-f.scrollTop*c.y+d.y+p.y}}function ts(e){return Array.from(e.getClientRects())}function rs(e){const t=oe(e),r=Ye(e),n=e.ownerDocument.body,o=J(t.scrollWidth,t.clientWidth,n.scrollWidth,n.clientWidth),s=J(t.scrollHeight,t.clientHeight,n.scrollHeight,n.clientHeight);let i=-r.scrollLeft+bt(e);const l=-r.scrollTop;return ee(n).direction==="rtl"&&(i+=J(t.clientWidth,n.clientWidth)-o),{width:o,height:s,x:i,y:l}}function ns(e,t){const r=G(e),n=oe(e),o=r.visualViewport;let s=n.clientWidth,i=n.clientHeight,l=0,f=0;if(o){s=o.width,i=o.height;const c=mt();(!c||c&&t==="fixed")&&(l=o.offsetLeft,f=o.offsetTop)}return{width:s,height:i,x:l,y:f}}const os=new Set(["absolute","fixed"]);function ss(e,t){const r=ge(e,!0,t==="fixed"),n=r.top+e.clientTop,o=r.left+e.clientLeft,s=se(e)?Se(e):re(1),i=e.clientWidth*s.x,l=e.clientHeight*s.y,f=o*s.x,c=n*s.y;return{width:i,height:l,x:f,y:c}}function Mr(e,t,r){let n;if(t==="viewport")n=ns(e,r);else if(t==="document")n=rs(oe(e));else if(R(t))n=ss(t,r);else{const o=_r(e);n={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return je(n)}function kr(e,t){const r=he(e);return r===t||!R(r)||Ce(r)?!1:ee(r).position==="fixed"||kr(r,t)}function is(e,t){const r=t.get(e);if(r)return r;let n=Ae(e,[],!1).filter(l=>R(l)&&xe(l)!=="body"),o=null;const s=ee(e).position==="fixed";let i=s?he(e):e;for(;R(i)&&!Ce(i);){const l=ee(i),f=gt(i);!f&&l.position==="fixed"&&(o=null),(s?!f&&!o:!f&&l.position==="static"&&!!o&&os.has(o.position)||Pe(i)&&!f&&kr(e,i))?n=n.filter(d=>d!==i):o=l,i=he(i)}return t.set(e,n),n}function as(e){let{element:t,boundary:r,rootBoundary:n,strategy:o}=e;const i=[...r==="clippingAncestors"?Xe(t)?[]:is(t,this._c):[].concat(r),n],l=i[0],f=i.reduce((c,d)=>{const h=Mr(t,d,o);return c.top=J(h.top,c.top),c.right=ue(h.right,c.right),c.bottom=ue(h.bottom,c.bottom),c.left=J(h.left,c.left),c},Mr(t,l,o));return{width:f.right-f.left,height:f.bottom-f.top,x:f.left,y:f.top}}function ls(e){const{width:t,height:r}=Lr(e);return{width:t,height:r}}function cs(e,t,r){const n=se(t),o=oe(t),s=r==="fixed",i=ge(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const f=re(0);function c(){f.x=bt(o)}if(n||!n&&!s)if((xe(t)!=="body"||Pe(o))&&(l=Ye(t)),n){const g=ge(t,!0,s,t);f.x=g.x+t.clientLeft,f.y=g.y+t.clientTop}else o&&c();s&&!n&&o&&c();const d=o&&!n&&!s?Dr(o,l):re(0),h=i.left+l.scrollLeft-f.x-d.x,p=i.top+l.scrollTop-f.y-d.y;return{x:h,y:p,width:i.width,height:i.height}}function yt(e){return ee(e).position==="static"}function Ir(e,t){if(!se(e)||ee(e).position==="fixed")return null;if(t)return t(e);let r=e.offsetParent;return oe(e)===r&&(r=r.ownerDocument.body),r}function $r(e,t){const r=G(e);if(Xe(e))return r;if(!se(e)){let o=he(e);for(;o&&!Ce(o);){if(R(o)&&!yt(o))return o;o=he(o)}return r}let n=Ir(e,t);for(;n&&Yo(n)&&yt(n);)n=Ir(n,t);return n&&Ce(n)&&yt(n)&&!gt(n)?r:n||Ko(e)||r}const ds=async function(e){const t=this.getOffsetParent||$r,r=this.getDimensions,n=await r(e.floating);return{reference:cs(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function fs(e){return ee(e).direction==="rtl"}const us={convertOffsetParentRelativeRectToViewportRelativeRect:es,getDocumentElement:oe,getClippingRect:as,getOffsetParent:$r,getElementRects:ds,getClientRects:ts,getDimensions:ls,getScale:Se,isElement:R,isRTL:fs};function zr(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function hs(e,t){let r=null,n;const o=oe(e);function s(){var l;clearTimeout(n),(l=r)==null||l.disconnect(),r=null}function i(l,f){l===void 0&&(l=!1),f===void 0&&(f=1),s();const c=e.getBoundingClientRect(),{left:d,top:h,width:p,height:g}=c;if(l||t(),!p||!g)return;const m=We(h),y=We(o.clientWidth-(d+p)),C=We(o.clientHeight-(h+g)),S=We(d),A={rootMargin:-m+"px "+-y+"px "+-C+"px "+-S+"px",threshold:J(0,ue(1,f))||1};let v=!0;function b(_){const N=_[0].intersectionRatio;if(N!==f){if(!v)return i();N?i(!1,N):n=setTimeout(()=>{i(!1,1e-7)},1e3)}N===1&&!zr(c,e.getBoundingClientRect())&&i(),v=!1}try{r=new IntersectionObserver(b,{...A,root:o.ownerDocument})}catch{r=new IntersectionObserver(b,A)}r.observe(e)}return i(!0),s}function ps(e,t,r,n){n===void 0&&(n={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:f=!1}=n,c=wt(e),d=o||s?[...c?Ae(c):[],...Ae(t)]:[];d.forEach(S=>{o&&S.addEventListener("scroll",r,{passive:!0}),s&&S.addEventListener("resize",r)});const h=c&&l?hs(c,r):null;let p=-1,g=null;i&&(g=new ResizeObserver(S=>{let[E]=S;E&&E.target===c&&g&&(g.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var A;(A=g)==null||A.observe(t)})),r()}),c&&!f&&g.observe(c),g.observe(t));let m,y=f?ge(e):null;f&&C();function C(){const S=ge(e);y&&!zr(y,S)&&r(),y=S,m=requestAnimationFrame(C)}return r(),()=>{var S;d.forEach(E=>{o&&E.removeEventListener("scroll",r),s&&E.removeEventListener("resize",r)}),h==null||h(),(S=g)==null||S.disconnect(),g=null,f&&cancelAnimationFrame(m)}}const gs=Fo,ms=Wo,vs=$o,ws=jo,bs=zo,Hr=Io,ys=Bo,xs=(e,t,r)=>{const n=new Map,o={platform:us,...r},s={...o.platform,_c:n};return ko(e,t,{...o,platform:s})};var Cs=typeof document<"u",Ss=function(){},Ue=Cs?L.useLayoutEffect:Ss;function qe(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let r,n,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(r=e.length,r!==t.length)return!1;for(n=r;n--!==0;)if(!qe(e[n],t[n]))return!1;return!0}if(o=Object.keys(e),r=o.length,r!==Object.keys(t).length)return!1;for(n=r;n--!==0;)if(!{}.hasOwnProperty.call(t,o[n]))return!1;for(n=r;n--!==0;){const s=o[n];if(!(s==="_owner"&&e.$$typeof)&&!qe(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Fr(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wr(e,t){const r=Fr(e);return Math.round(t*r)/r}function xt(e){const t=u.useRef(e);return Ue(()=>{t.current=e}),t}function Es(e){e===void 0&&(e={});const{placement:t="bottom",strategy:r="absolute",middleware:n=[],platform:o,elements:{reference:s,floating:i}={},transform:l=!0,whileElementsMounted:f,open:c}=e,[d,h]=u.useState({x:0,y:0,strategy:r,placement:t,middlewareData:{},isPositioned:!1}),[p,g]=u.useState(n);qe(p,n)||g(n);const[m,y]=u.useState(null),[C,S]=u.useState(null),E=u.useCallback(M=>{M!==_.current&&(_.current=M,y(M))},[]),A=u.useCallback(M=>{M!==N.current&&(N.current=M,S(M))},[]),v=s||m,b=i||C,_=u.useRef(null),N=u.useRef(null),I=u.useRef(d),$=f!=null,z=xt(f),W=xt(o),x=xt(c),w=u.useCallback(()=>{if(!_.current||!N.current)return;const M={placement:t,strategy:r,middleware:p};W.current&&(M.platform=W.current),xs(_.current,N.current,M).then(j=>{const H={...j,isPositioned:x.current!==!1};P.current&&!qe(I.current,H)&&(I.current=H,Ot.flushSync(()=>{h(H)}))})},[p,t,r,W,x]);Ue(()=>{c===!1&&I.current.isPositioned&&(I.current.isPositioned=!1,h(M=>({...M,isPositioned:!1})))},[c]);const P=u.useRef(!1);Ue(()=>(P.current=!0,()=>{P.current=!1}),[]),Ue(()=>{if(v&&(_.current=v),b&&(N.current=b),v&&b){if(z.current)return z.current(v,b,w);w()}},[v,b,w,z,$]);const D=u.useMemo(()=>({reference:_,floating:N,setReference:E,setFloating:A}),[E,A]),T=u.useMemo(()=>({reference:v,floating:b}),[v,b]),k=u.useMemo(()=>{const M={position:r,left:0,top:0};if(!T.floating)return M;const j=Wr(T.floating,d.x),H=Wr(T.floating,d.y);return l?{...M,transform:"translate("+j+"px, "+H+"px)",...Fr(T.floating)>=1.5&&{willChange:"transform"}}:{position:r,left:j,top:H}},[r,l,T.floating,d.x,d.y]);return u.useMemo(()=>({...d,update:w,refs:D,elements:T,floatingStyles:k}),[d,w,D,T,k])}const Ts=e=>{function t(r){return{}.hasOwnProperty.call(r,"current")}return{name:"arrow",options:e,fn(r){const{element:n,padding:o}=typeof e=="function"?e(r):e;return n&&t(n)?n.current!=null?Hr({element:n.current,padding:o}).fn(r):{}:n?Hr({element:n,padding:o}).fn(r):{}}}},Ns=(e,t)=>({...gs(e),options:[e,t]}),Ps=(e,t)=>({...ms(e),options:[e,t]}),As=(e,t)=>({...ys(e),options:[e,t]}),Os=(e,t)=>({...vs(e),options:[e,t]}),Ls=(e,t)=>({...ws(e),options:[e,t]}),_s=(e,t)=>({...bs(e),options:[e,t]}),Ds=(e,t)=>({...Ts(e),options:[e,t]});var Ms="Arrow",Br=u.forwardRef((e,t)=>{const{children:r,width:n=10,height:o=5,...s}=e;return a.jsx(U.svg,{...s,ref:t,width:n,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?r:a.jsx("polygon",{points:"0,0 30,0 15,10"})})});Br.displayName=Ms;var ks=Br;function Is(e){const[t,r]=u.useState(void 0);return fe(()=>{if(e){r({width:e.offsetWidth,height:e.offsetHeight});const n=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,l;if("borderBoxSize"in s){const f=s.borderBoxSize,c=Array.isArray(f)?f[0]:f;i=c.inlineSize,l=c.blockSize}else i=e.offsetWidth,l=e.offsetHeight;r({width:i,height:l})});return n.observe(e,{box:"border-box"}),()=>n.unobserve(e)}else r(void 0)},[e]),t}var Ct="Popper",[jr,Vr]=nt(Ct),[$s,Xr]=jr(Ct),Yr=e=>{const{__scopePopper:t,children:r}=e,[n,o]=u.useState(null);return a.jsx($s,{scope:t,anchor:n,onAnchorChange:o,children:r})};Yr.displayName=Ct;var Ur="PopperAnchor",qr=u.forwardRef((e,t)=>{const{__scopePopper:r,virtualRef:n,...o}=e,s=Xr(Ur,r),i=u.useRef(null),l=q(t,i);return u.useEffect(()=>{s.onAnchorChange((n==null?void 0:n.current)||i.current)}),n?null:a.jsx(U.div,{...o,ref:l})});qr.displayName=Ur;var St="PopperContent",[zs,Hs]=jr(St),Jr=u.forwardRef((e,t)=>{var cn,dn,fn,un,hn,pn;const{__scopePopper:r,side:n="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:l=0,avoidCollisions:f=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:m,...y}=e,C=Xr(St,r),[S,E]=u.useState(null),A=q(t,Le=>E(Le)),[v,b]=u.useState(null),_=Is(v),N=(_==null?void 0:_.width)??0,I=(_==null?void 0:_.height)??0,$=n+(s!=="center"?"-"+s:""),z=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},W=Array.isArray(c)?c:[c],x=W.length>0,w={padding:z,boundary:W.filter(Ws),altBoundary:x},{refs:P,floatingStyles:D,placement:T,isPositioned:k,middlewareData:M}=Es({strategy:"fixed",placement:$,whileElementsMounted:(...Le)=>ps(...Le,{animationFrame:g==="always"}),elements:{reference:C.anchor},middleware:[Ns({mainAxis:o+I,alignmentAxis:i}),f&&Ps({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?As():void 0,...w}),f&&Os({...w}),Ls({...w,apply:({elements:Le,rects:gn,availableWidth:Si,availableHeight:Ei})=>{const{width:Ti,height:Ni}=gn.reference,Qe=Le.floating.style;Qe.setProperty("--radix-popper-available-width",`${Si}px`),Qe.setProperty("--radix-popper-available-height",`${Ei}px`),Qe.setProperty("--radix-popper-anchor-width",`${Ti}px`),Qe.setProperty("--radix-popper-anchor-height",`${Ni}px`)}}),v&&Ds({element:v,padding:l}),Bs({arrowWidth:N,arrowHeight:I}),p&&_s({strategy:"referenceHidden",...w})]}),[j,H]=Zr(T),V=Q(m);fe(()=>{k&&(V==null||V())},[k,V]);const ie=(cn=M.arrow)==null?void 0:cn.x,ae=(dn=M.arrow)==null?void 0:dn.y,Z=((fn=M.arrow)==null?void 0:fn.centerOffset)!==0,[Ze,Ci]=u.useState();return fe(()=>{S&&Ci(window.getComputedStyle(S).zIndex)},[S]),a.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...D,transform:k?D.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ze,"--radix-popper-transform-origin":[(un=M.transformOrigin)==null?void 0:un.x,(hn=M.transformOrigin)==null?void 0:hn.y].join(" "),...((pn=M.hide)==null?void 0:pn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:a.jsx(zs,{scope:r,placedSide:j,onArrowChange:b,arrowX:ie,arrowY:ae,shouldHideArrow:Z,children:a.jsx(U.div,{"data-side":j,"data-align":H,...y,ref:A,style:{...y.style,animation:k?void 0:"none"}})})})});Jr.displayName=St;var Gr="PopperArrow",Fs={top:"bottom",right:"left",bottom:"top",left:"right"},Kr=u.forwardRef(function(t,r){const{__scopePopper:n,...o}=t,s=Hs(Gr,n),i=Fs[s.placedSide];return a.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:a.jsx(ks,{...o,ref:r,style:{...o.style,display:"block"}})})});Kr.displayName=Gr;function Ws(e){return e!==null}var Bs=e=>({name:"transformOrigin",options:e,fn(t){var C,S,E;const{placement:r,rects:n,middlewareData:o}=t,i=((C=o.arrow)==null?void 0:C.centerOffset)!==0,l=i?0:e.arrowWidth,f=i?0:e.arrowHeight,[c,d]=Zr(r),h={start:"0%",center:"50%",end:"100%"}[d],p=(((S=o.arrow)==null?void 0:S.x)??0)+l/2,g=(((E=o.arrow)==null?void 0:E.y)??0)+f/2;let m="",y="";return c==="bottom"?(m=i?h:`${p}px`,y=`${-f}px`):c==="top"?(m=i?h:`${p}px`,y=`${n.floating.height+f}px`):c==="right"?(m=`${-f}px`,y=i?h:`${g}px`):c==="left"&&(m=`${n.floating.width+f}px`,y=i?h:`${g}px`),{data:{x:m,y}}}});function Zr(e){const[t,r="center"]=e.split("-");return[t,r]}var js=Yr,Vs=qr,Xs=Jr,Ys=Kr,Us=u[" useInsertionEffect ".trim().toString()]||fe;function qs({prop:e,defaultProp:t,onChange:r=()=>{},caller:n}){const[o,s,i]=Js({defaultProp:t,onChange:r}),l=e!==void 0,f=l?e:o;{const d=u.useRef(e!==void 0);u.useEffect(()=>{const h=d.current;h!==l&&console.warn(`${n} is changing from ${h?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=l},[l,n])}const c=u.useCallback(d=>{var h;if(l){const p=Gs(d)?d(e):d;p!==e&&((h=i.current)==null||h.call(i,p))}else s(d)},[l,e,s,i]);return[f,c]}function Js({defaultProp:e,onChange:t}){const[r,n]=u.useState(e),o=u.useRef(r),s=u.useRef(t);return Us(()=>{s.current=t},[t]),u.useEffect(()=>{var i;o.current!==r&&((i=s.current)==null||i.call(s,r),o.current=r)},[r,o]),[r,n,s]}function Gs(e){return typeof e=="function"}var Ks=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"}),Zs="VisuallyHidden",Qr=u.forwardRef((e,t)=>a.jsx(U.span,{...e,ref:t,style:{...Ks,...e.style}}));Qr.displayName=Zs;var Qs=Qr,[Je,Ai]=nt("Tooltip",[Vr]),Ge=Vr(),Rr="TooltipProvider",Rs=700,Et="tooltip.open",[ei,Tt]=Je(Rr),en=e=>{const{__scopeTooltip:t,delayDuration:r=Rs,skipDelayDuration:n=300,disableHoverableContent:o=!1,children:s}=e,i=u.useRef(!0),l=u.useRef(!1),f=u.useRef(0);return u.useEffect(()=>{const c=f.current;return()=>window.clearTimeout(c)},[]),a.jsx(ei,{scope:t,isOpenDelayedRef:i,delayDuration:r,onOpen:u.useCallback(()=>{window.clearTimeout(f.current),i.current=!1},[]),onClose:u.useCallback(()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>i.current=!0,n)},[n]),isPointerInTransitRef:l,onPointerInTransitChange:u.useCallback(c=>{l.current=c},[]),disableHoverableContent:o,children:s})};en.displayName=Rr;var Oe="Tooltip",[ti,Ke]=Je(Oe),tn=e=>{const{__scopeTooltip:t,children:r,open:n,defaultOpen:o,onOpenChange:s,disableHoverableContent:i,delayDuration:l}=e,f=Tt(Oe,e.__scopeTooltip),c=Ge(t),[d,h]=u.useState(null),p=Co(),g=u.useRef(0),m=i??f.disableHoverableContent,y=l??f.delayDuration,C=u.useRef(!1),[S,E]=qs({prop:n,defaultProp:o??!1,onChange:N=>{N?(f.onOpen(),document.dispatchEvent(new CustomEvent(Et))):f.onClose(),s==null||s(N)},caller:Oe}),A=u.useMemo(()=>S?C.current?"delayed-open":"instant-open":"closed",[S]),v=u.useCallback(()=>{window.clearTimeout(g.current),g.current=0,C.current=!1,E(!0)},[E]),b=u.useCallback(()=>{window.clearTimeout(g.current),g.current=0,E(!1)},[E]),_=u.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{C.current=!0,E(!0),g.current=0},y)},[y,E]);return u.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),a.jsx(js,{...c,children:a.jsx(ti,{scope:t,contentId:p,open:S,stateAttribute:A,trigger:d,onTriggerChange:h,onTriggerEnter:u.useCallback(()=>{f.isOpenDelayedRef.current?_():v()},[f.isOpenDelayedRef,_,v]),onTriggerLeave:u.useCallback(()=>{m?b():(window.clearTimeout(g.current),g.current=0)},[b,m]),onOpen:v,onClose:b,disableHoverableContent:m,children:r})})};tn.displayName=Oe;var Nt="TooltipTrigger",rn=u.forwardRef((e,t)=>{const{__scopeTooltip:r,...n}=e,o=Ke(Nt,r),s=Tt(Nt,r),i=Ge(r),l=u.useRef(null),f=q(t,l,o.onTriggerChange),c=u.useRef(!1),d=u.useRef(!1),h=u.useCallback(()=>c.current=!1,[]);return u.useEffect(()=>()=>document.removeEventListener("pointerup",h),[h]),a.jsx(Vs,{asChild:!0,...i,children:a.jsx(U.button,{"aria-describedby":o.open?o.contentId:void 0,"data-state":o.stateAttribute,...n,ref:f,onPointerMove:X(e.onPointerMove,p=>{p.pointerType!=="touch"&&!d.current&&!s.isPointerInTransitRef.current&&(o.onTriggerEnter(),d.current=!0)}),onPointerLeave:X(e.onPointerLeave,()=>{o.onTriggerLeave(),d.current=!1}),onPointerDown:X(e.onPointerDown,()=>{o.open&&o.onClose(),c.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:X(e.onFocus,()=>{c.current||o.onOpen()}),onBlur:X(e.onBlur,o.onClose),onClick:X(e.onClick,o.onClose)})})});rn.displayName=Nt;var ri="TooltipPortal",[Oi,ni]=Je(ri,{forceMount:void 0}),Ee="TooltipContent",nn=u.forwardRef((e,t)=>{const r=ni(Ee,e.__scopeTooltip),{forceMount:n=r.forceMount,side:o="top",...s}=e,i=Ke(Ee,e.__scopeTooltip);return a.jsx(ve,{present:n||i.open,children:i.disableHoverableContent?a.jsx(on,{side:o,...s,ref:t}):a.jsx(oi,{side:o,...s,ref:t})})}),oi=u.forwardRef((e,t)=>{const r=Ke(Ee,e.__scopeTooltip),n=Tt(Ee,e.__scopeTooltip),o=u.useRef(null),s=q(t,o),[i,l]=u.useState(null),{trigger:f,onClose:c}=r,d=o.current,{onPointerInTransitChange:h}=n,p=u.useCallback(()=>{l(null),h(!1)},[h]),g=u.useCallback((m,y)=>{const C=m.currentTarget,S={x:m.clientX,y:m.clientY},E=ci(S,C.getBoundingClientRect()),A=di(S,E),v=fi(y.getBoundingClientRect()),b=hi([...A,...v]);l(b),h(!0)},[h]);return u.useEffect(()=>()=>p(),[p]),u.useEffect(()=>{if(f&&d){const m=C=>g(C,d),y=C=>g(C,f);return f.addEventListener("pointerleave",m),d.addEventListener("pointerleave",y),()=>{f.removeEventListener("pointerleave",m),d.removeEventListener("pointerleave",y)}}},[f,d,g,p]),u.useEffect(()=>{if(i){const m=y=>{const C=y.target,S={x:y.clientX,y:y.clientY},E=(f==null?void 0:f.contains(C))||(d==null?void 0:d.contains(C)),A=!ui(S,i);E?p():A&&(p(),c())};return document.addEventListener("pointermove",m),()=>document.removeEventListener("pointermove",m)}},[f,d,i,c,p]),a.jsx(on,{...e,ref:s})}),[si,ii]=Je(Oe,{isInside:!1}),ai=Re.createSlottable("TooltipContent"),on=u.forwardRef((e,t)=>{const{__scopeTooltip:r,children:n,"aria-label":o,onEscapeKeyDown:s,onPointerDownOutside:i,...l}=e,f=Ke(Ee,r),c=Ge(r),{onClose:d}=f;return u.useEffect(()=>(document.addEventListener(Et,d),()=>document.removeEventListener(Et,d)),[d]),u.useEffect(()=>{if(f.trigger){const h=p=>{const g=p.target;g!=null&&g.contains(f.trigger)&&d()};return window.addEventListener("scroll",h,{capture:!0}),()=>window.removeEventListener("scroll",h,{capture:!0})}},[f.trigger,d]),a.jsx(vr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:h=>h.preventDefault(),onDismiss:d,children:a.jsxs(Xs,{"data-state":f.stateAttribute,...c,...l,ref:t,style:{...l.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:[a.jsx(ai,{children:n}),a.jsx(si,{scope:r,isInside:!0,children:a.jsx(Qs,{id:f.contentId,role:"tooltip",children:o||n})})]})})});nn.displayName=Ee;var sn="TooltipArrow",li=u.forwardRef((e,t)=>{const{__scopeTooltip:r,...n}=e,o=Ge(r);return ii(sn,r).isInside?null:a.jsx(Ys,{...o,...n,ref:t})});li.displayName=sn;function ci(e,t){const r=Math.abs(t.top-e.y),n=Math.abs(t.bottom-e.y),o=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(r,n,o,s)){case s:return"left";case o:return"right";case r:return"top";case n:return"bottom";default:throw new Error("unreachable")}}function di(e,t,r=5){const n=[];switch(t){case"top":n.push({x:e.x-r,y:e.y+r},{x:e.x+r,y:e.y+r});break;case"bottom":n.push({x:e.x-r,y:e.y-r},{x:e.x+r,y:e.y-r});break;case"left":n.push({x:e.x+r,y:e.y-r},{x:e.x+r,y:e.y+r});break;case"right":n.push({x:e.x-r,y:e.y-r},{x:e.x-r,y:e.y+r});break}return n}function fi(e){const{top:t,right:r,bottom:n,left:o}=e;return[{x:o,y:t},{x:r,y:t},{x:r,y:n},{x:o,y:n}]}function ui(e,t){const{x:r,y:n}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const l=t[s],f=t[i],c=l.x,d=l.y,h=f.x,p=f.y;d>n!=p>n&&r<(h-c)*(n-d)/(p-d)+c&&(o=!o)}return o}function hi(e){const t=e.slice();return t.sort((r,n)=>r.x<n.x?-1:r.x>n.x?1:r.y<n.y?-1:r.y>n.y?1:0),pi(t)}function pi(e){if(e.length<=1)return e.slice();const t=[];for(let n=0;n<e.length;n++){const o=e[n];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 r=[];for(let n=e.length-1;n>=0;n--){const o=e[n];for(;r.length>=2;){const s=r[r.length-1],i=r[r.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))r.pop();else break}r.push(o)}return r.pop(),t.length===1&&r.length===1&&t[0].x===r[0].x&&t[0].y===r[0].y?t:t.concat(r)}var gi=en,mi=tn,vi=rn,an=nn;const wi=gi,bi=mi,yi=vi,ln=u.forwardRef(({className:e,sideOffset:t=4,...r},n)=>a.jsx(an,{ref:n,sideOffset:t,className:Y("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),...r}));ln.displayName=an.displayName;const xi={ChatProvider:_e,ChatInterface:me,MessageComponent:rt,ThreadManager:be,ChatApp:Zt,useChat:pe};O.Button=B,O.Card=tr,O.CardContent=sr,O.CardDescription=or,O.CardFooter=ir,O.CardHeader=rr,O.CardTitle=nr,O.ChatApp=Zt,O.ChatInterface=me,O.ChatProvider=_e,O.ChatWidget=eo,O.Input=ar,O.Label=dr,O.MESSAGE_MAX_LENGTH=et,O.MessageComponent=rt,O.ScrollArea=lt,O.Separator=pr,O.THREAD_ID_PATTERN=Lt,O.TITLE_MAX_LENGTH=tt,O.Textarea=De,O.ThreadManager=be,O.Tooltip=bi,O.TooltipContent=ln,O.TooltipProvider=wi,O.TooltipTrigger=yi,O.cn=Y,O.default=xi,O.safeJsonParse=Cn,O.sanitizeHtml=bn,O.sanitizeText=de,O.useChat=pe,O.useChatActions=ro,O.useChatMessages=Rt,O.useCodeExecution=so,O.useFileContents=oo,O.useSearchResults=no,O.useStreamMonitor=er,O.useToolExtractor=He,O.useToolMessages=to,O.validateAndSanitizeMessage=Te,O.validateAndSanitizeTitle=xn,O.validateMessageLength=_t,O.validateThreadId=yn,O.withInputValidation=Sn,Object.defineProperties(O,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Markdown rendering utilities for chat content
3
+ * Handles basic markdown formatting without external dependencies
4
+ */
5
+ interface MarkdownOptions {
6
+ escapeHtml?: boolean;
7
+ breaks?: boolean;
8
+ }
9
+ /**
10
+ * Simple markdown renderer for chat content
11
+ */
12
+ export declare function renderMarkdown(content: string, options?: MarkdownOptions): string;
13
+ /**
14
+ * Check if content looks like markdown
15
+ */
16
+ export declare function isMarkdownContent(content: string): boolean;
17
+ /**
18
+ * Sanitize HTML content
19
+ */
20
+ export declare function sanitizeHtml(html: string): string;
21
+ /**
22
+ * React hook for rendering markdown content safely
23
+ */
24
+ export declare function useMarkdownRenderer(): {
25
+ renderContent: (content: string, options?: MarkdownOptions) => string;
26
+ isMarkdownContent: typeof isMarkdownContent;
27
+ };
28
+ export {};