teodor-new-chat-ui 3.0.74 → 3.0.75

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.
@@ -8,7 +8,7 @@ export interface ChatInterfaceProps {
8
8
  placeholder?: string;
9
9
  autoFocus?: boolean;
10
10
  maxHeight?: string;
11
- /** debounce for mid-stream markdown rendering */
11
+ /** debounce for mid-stream markdown rendering (default: 300ms for smoother performance) */
12
12
  streamingDebounceMs?: number;
13
13
  enableFileUpload?: boolean;
14
14
  enableExcelUpload?: boolean;
package/dist/index.esm.js CHANGED
@@ -8438,7 +8438,7 @@ const Nw = K.memo(function({
8438
8438
  message: t,
8439
8439
  messageIndex: n,
8440
8440
  isStreamingMessage: r = !1,
8441
- streamingDebounceMs: o = 120,
8441
+ streamingDebounceMs: o = 300,
8442
8442
  isEditing: s = !1,
8443
8443
  showActions: i = !0,
8444
8444
  showTimestamp: a = !0,
@@ -8801,7 +8801,7 @@ const Nw = K.memo(function({
8801
8801
  }
8802
8802
  )
8803
8803
  ] });
8804
- }, (e, t) => e.message.id === t.message.id && e.message.content === t.message.content);
8804
+ }, (e, t) => t.isStreamingMessage ? !1 : e.message.id === t.message.id && e.message.content === t.message.content && e.isStreamingMessage === t.isStreamingMessage && e.isEditing === t.isEditing);
8805
8805
  function jw(e) {
8806
8806
  const t = e.filter((n) => n.type === "text").map((n) => n.text).join("");
8807
8807
  return t || JSON.stringify(e);
@@ -9100,8 +9100,8 @@ function Hw({
9100
9100
  },
9101
9101
  data: e,
9102
9102
  followOutput: "smooth",
9103
- overscan: 120,
9104
- increaseViewportBy: { top: 200, bottom: 200 },
9103
+ overscan: { main: 200, reverse: 200 },
9104
+ increaseViewportBy: { top: 400, bottom: 400 },
9105
9105
  startReached: () => {
9106
9106
  y && y();
9107
9107
  },
@@ -9119,31 +9119,43 @@ function Hw({
9119
9119
  style: {
9120
9120
  overflowAnchor: "none",
9121
9121
  willChange: "transform",
9122
+ contain: "layout style paint",
9122
9123
  ...(S == null ? void 0 : S.style) ?? {}
9123
9124
  }
9124
9125
  }
9125
9126
  ))
9126
9127
  },
9127
- itemContent: (S, C) => /* @__PURE__ */ l.jsx("div", { className: "mb-4 last:mb-0", children: /* @__PURE__ */ l.jsx(
9128
- Nw,
9128
+ itemContent: (S, C) => /* @__PURE__ */ l.jsx(
9129
+ "div",
9129
9130
  {
9130
- message: C,
9131
- messageIndex: S,
9132
- isStreamingMessage: t && n === C.id,
9133
- streamingDebounceMs: r,
9134
- isEditing: i === C.id,
9135
- showActions: s,
9136
- showTimestamp: !1,
9137
- showAgentName: !0,
9138
- layoutSize: o,
9139
- truncateToolMessages: !1,
9140
- toolMessagePreviewLength: 200,
9141
- onEdit: c,
9142
- onRegenerate: () => u(S),
9143
- onCancelEdit: d
9144
- },
9145
- C.id ?? `msg-${C.role}-${S}-${C.createdAt ?? ""}`
9146
- ) })
9131
+ className: "mb-4 last:mb-0",
9132
+ style: {
9133
+ contentVisibility: "auto",
9134
+ containIntrinsicSize: "auto 100px",
9135
+ transform: "translateZ(0)"
9136
+ },
9137
+ children: /* @__PURE__ */ l.jsx(
9138
+ Nw,
9139
+ {
9140
+ message: C,
9141
+ messageIndex: S,
9142
+ isStreamingMessage: t && n === C.id,
9143
+ streamingDebounceMs: r,
9144
+ isEditing: i === C.id,
9145
+ showActions: s,
9146
+ showTimestamp: !1,
9147
+ showAgentName: !0,
9148
+ layoutSize: o,
9149
+ truncateToolMessages: !1,
9150
+ toolMessagePreviewLength: 200,
9151
+ onEdit: c,
9152
+ onRegenerate: () => u(S),
9153
+ onCancelEdit: d
9154
+ },
9155
+ C.id ?? `msg-${C.role}-${S}-${C.createdAt ?? ""}`
9156
+ )
9157
+ }
9158
+ )
9147
9159
  }
9148
9160
  ) });
9149
9161
  }
@@ -11805,7 +11817,7 @@ function go({
11805
11817
  placeholder: t = "Type your message...",
11806
11818
  autoFocus: n = !0,
11807
11819
  maxHeight: r = void 0,
11808
- streamingDebounceMs: o = 120,
11820
+ streamingDebounceMs: o = 300,
11809
11821
  enableFileUpload: s = !0,
11810
11822
  enableExcelUpload: i = !1,
11811
11823
  enableMessageEditing: a = !0,
package/dist/index.umd.js CHANGED
@@ -74,8 +74,8 @@ Check the top-level render call using <`+ue+">.")}return J}}function Hu(A,J){{if
74
74
 
75
75
  If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
76
76
 
77
- For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return b.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},Jy="DialogDescriptionWarning",eI=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Vm(Jy).contentName}}.`;return b.useEffect(()=>{var i;const a=(i=t.current)==null?void 0:i.getAttribute("aria-describedby");e&&a&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},zm=xm,tI=wm,$m=Lm,Xa=Pm,Za=km,Gn=Fm,Ja=Gm,Wm=Hm;const nI=zm,rI=$m,Km=b.forwardRef(({className:t,...e},n)=>u.jsx(Xa,{ref:n,className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e}));Km.displayName=Xa.displayName;const Qm=b.forwardRef(({className:t,children:e,...n},r)=>{const a=b.useMemo(()=>{let i=!1;function o(s){b.Children.forEach(s,l=>{if(i||!b.isValidElement(l))return;const c=l.type;if(c===Gn||(c==null?void 0:c.displayName)===Gn.displayName||(c==null?void 0:c.name)==="DialogTitle"){i=!0;return}l.props&&l.props.children&&o(l.props.children)})}return o(e),i},[e]);return u.jsxs(rI,{children:[u.jsx(Km,{}),u.jsxs(Za,{ref:r,className:$("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...n,children:[!a&&u.jsx(Gn,{className:"sr-only",children:"Dialog"}),e,u.jsxs(Wm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(pe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Qm.displayName=Za.displayName;const jm=({className:t,...e})=>u.jsx("div",{className:$("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});jm.displayName="DialogHeader";const Xm=b.forwardRef(({className:t,...e},n)=>u.jsx(Gn,{ref:n,className:$("text-lg font-semibold leading-none tracking-tight",t),...e}));Xm.displayName=Gn.displayName;const aI=b.forwardRef(({className:t,...e},n)=>u.jsx(Ja,{ref:n,className:$("text-sm text-muted-foreground",t),...e}));aI.displayName=Ja.displayName;function iI({isOpen:t,onClose:e,fileId:n,fileName:r,mimeType:a}){const[i,o]=y.useState(!1),[s,l]=y.useState(null),[c,d]=y.useState(null),{toast:_}=Wo();y.useEffect(()=>{t&&n&&p()},[t,n]);const p=async()=>{if(n){o(!0),d(null),l(null);try{const S=await am(n);l(S)}catch(S){console.error("Failed to load file:",S),d(S instanceof Error?S.message:"Failed to load file")}finally{o(!1)}}},m=async()=>{if(n)try{await BO(n),_({title:"Download started",description:`Downloading ${r}`})}catch(S){console.error("Failed to download file:",S),_({title:"Download failed",description:String(S),variant:"destructive"})}},g=async()=>{if(n)try{const S=await am(n),T=new Blob([S],{type:a}),h=URL.createObjectURL(T);window.open(h,"_blank"),URL.revokeObjectURL(h)}catch(S){console.error("Failed to open file externally:",S),_({title:"Failed to open file",description:String(S),variant:"destructive"})}},f=()=>i?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(pe.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Ve,{onClick:p,variant:"outline",children:"Try Again"})]}):s?a.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${a};base64,${s}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):a==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${s}`,className:"w-full h-full",title:r})}):a.startsWith("text/")||a.includes("json")||a.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:s})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(pe.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[a," • ",s.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),E=()=>a.startsWith("image/")?u.jsx(pe.Image,{className:"h-5 w-5"}):u.jsx(pe.FileText,{className:"h-5 w-5"});return u.jsx(nI,{open:t,onOpenChange:e,children:u.jsxs(Qm,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(jm,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[E(),u.jsxs("div",{children:[u.jsx(Xm,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[a," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Ve,{variant:"outline",size:"sm",onClick:g,className:"flex items-center gap-2",children:[u.jsx(pe.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ve,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(pe.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:f()})]})})}const ei="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function oI({className:t}){const[e,n]=y.useState(0);return y.useEffect(()=>{const r=setInterval(()=>n(a=>(a+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:$("inline-block text-xs opacity-70 ml-1",t),children:["Is thinking",".".repeat(e)]})}const Zm=y.memo(function({message:e,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:a=120,isEditing:i=!1,showActions:o=!0,showTimestamp:s=!0,showAgentName:l=!0,layoutSize:c="desktop",truncateToolMessages:d=!0,toolMessagePreviewLength:_=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:g={},onEdit:f,onRegenerate:E,onCancelEdit:S,onCopy:T}){const[h,v]=y.useState(!1),[R,C]=y.useState(!1),[N,O]=y.useState(!1),[D,w]=y.useState(!1),{currentThreadId:L}=ba();Wo();const[H,z]=y.useState({}),[P,G]=y.useState(!1),[I,U]=y.useState(null),M=c==="phone"||c==="half-screen",k=e.role,Y=k==="tool",W=y.useMemo(()=>{switch(k){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[k]),re=y.useMemo(()=>sI(e.content),[e.content]),q=y.useMemo(()=>_I(e.content),[e.content]),X=y.useMemo(()=>e.content.filter(Se=>Se.type==="image_url"),[e.content]),ce=y.useMemo(()=>e.content.filter(Se=>Se.type==="file"),[e.content]),ge=mI(re,r?a:0),V=async()=>{try{const Se=Y?sr(e.content):re;await navigator.clipboard.writeText(Se),v(!0),setTimeout(()=>v(!1),2e3),T==null||T(Se)}catch(Se){console.error("Failed to copy:",Se)}},F=()=>{if(!f)return;const Se=Y?sr(e.content):re;f(e.id,Se)},K=()=>E==null?void 0:E(n),te=()=>{const Be=$(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",W);switch(k){case"user":return u.jsx(pe.User,{className:Be});case"assistant":return u.jsx(pe.Bot,{className:Be});case"tool":return u.jsx(pe.Wrench,{className:Be});default:return u.jsx(pe.Bot,{className:Be})}},le=()=>{const Se="group relative mb-4 flex w-full";switch(k){case"user":return $(Se,"justify-end");case"assistant":case"tool":case"system":return $(Se,"justify-start");default:return Se}},oe=()=>{const Se=$("rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");switch(k){case"user":return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return $(Se,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return $(Se,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},Ae=Se=>{if(!Se)return"";try{return new Date(Se).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},qe=()=>{if(e.model==="reflection"){const ee=re.trim(),Q=ls(ee);if(Q&&typeof Q=="object")return u.jsx(gI,{data:Q})}if(Y&&q.name==="get_issues"){const ee=e.content.find(be=>be.type==="tool_result"),Q=(ee==null?void 0:ee.output)??sr(e.content),ae=tg(Q);if(ae)return u.jsx(EI,{issues:ae})}if(Y&&!N){const ee=sr(e.content).slice(0,80).replace(/\s+/g," ");return u.jsx("div",{className:$("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",M&&"text-[10px]"),children:u.jsxs("span",{className:"truncate max-w-full text-current",children:[ee,ee.length>=80?"…":""]})})}if(Y&&d){const ee=sr(e.content),Q=ee.length>_;return u.jsx(Xp,{open:R,onOpenChange:C,children:u.jsxs("div",{className:"font-mono text-sm text-current",children:[u.jsx("pre",{className:$("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:Q&&!R?ee.substring(0,_)+"...":ee}),Q&&u.jsx(Zp,{asChild:!0,children:u.jsx(Ve,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:R?u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",ee.length-_," chars)"]})})})]})})}if(Y&&N&&!d){const ee=fI(e.content);if(ee&&lI(ee))return u.jsx(Br,{content:ee.trim()});const Q=sr(e.content);return u.jsx("div",{className:"font-mono text-sm text-current",children:u.jsx("pre",{className:$("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:Q})})}const Se=X.length>0&&k!=="tool",Be=ce.length>0&&k!=="tool"&&!1;return u.jsxs("div",{children:[r?u.jsxs("div",{className:"relative",children:[(()=>{const ee=ls(ge);return ee!==null?u.jsx(Jm,{data:ee}):u.jsx(Br,{content:dI(cI(ge))})})(),u.jsx(oI,{className:$(W,M?"text-xs":"text-sm")})]}):(()=>{const ee=ls(re.trim());if(ee!==null)return u.jsx(Jm,{data:ee});if(k==="user"&&p){const Q=re.trim();if(Q.length>m)return u.jsxs(Xp,{open:D,onOpenChange:w,children:[u.jsx("div",{className:$("text-sm text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:D?u.jsx(Br,{content:Q}):u.jsxs("pre",{className:$("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:[Q.substring(0,m),"..."]})}),u.jsx(Zp,{asChild:!0,children:u.jsx(Ve,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:D?u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",Q.length-m," chars)"]})})})]})}return u.jsx(Br,{content:re.trim()})})(),Se&&u.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:X.map((ee,Q)=>u.jsxs("div",{className:"relative border rounded overflow-hidden",children:[u.jsx("img",{src:ee.url,alt:ee.alt??"image",className:"w-full h-auto"}),u.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[u.jsx(pe.Image,{className:"h-3 w-3"}),u.jsx("span",{children:"image"})]})]},Q))}),Be]})},Me=y.useMemo(()=>pI(e),[e]);return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:$(le(),g.container),children:u.jsxs("div",{className:$(oe(),g.content),children:[(s||l||Y)&&u.jsxs("div",{className:$("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",W,g.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[te(),l&&Me&&u.jsx("span",{className:$("font-medium",M?"text-xs":"text-sm"),children:Me}),Y&&q.name&&u.jsxs(zp,{variant:"outline",className:$("text-xs flex items-center gap-1 cursor-pointer",W,"border border-current/40",M&&"text-xs h-4"),onClick:()=>O(Se=>!Se),children:[u.jsx("span",{children:q.name}),u.jsx("span",{className:"inline-flex items-center",children:N?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})})]}),Y&&!q.name&&u.jsx(Ve,{variant:"ghost",size:"sm",className:$("h-6 px-1",W,"hover:bg-foreground/10"),onClick:()=>O(Se=>!Se),children:u.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",N?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})]})})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[s&&u.jsx("span",{className:$("text-xs opacity-60",W,M&&"text-xs"),children:Ae(e.createdAt)}),o&&!i&&u.jsxs("div",{className:$("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",g.actions),children:[u.jsx(Ve,{variant:"ghost",size:"sm",onClick:V,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:$(h?"text-success":W,M?"h-3 w-3":"h-4 w-4")})}),k==="user"&&f&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:F,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:$(W,M?"h-3 w-3":"h-4 w-4")})}),k==="assistant"&&E&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:K,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:$(W,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:qe()}),Y&&N&&(q.toolCallId||q.name)&&u.jsxs("div",{className:$("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[q.name&&u.jsxs("div",{children:["Function: ",q.name]}),q.toolCallId&&u.jsxs("div",{children:["Call ID: ",q.toolCallId]})]}),!(s||l||Y)&&o&&!i&&u.jsxs("div",{className:$("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",g.actions),children:[u.jsx(Ve,{variant:"ghost",size:"sm",onClick:V,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:$(h?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),k==="user"&&f&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:F,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:$("text-current",M?"h-3 w-3":"h-4 w-4")})}),k==="assistant"&&E&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:K,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:$("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),I&&u.jsx(iI,{isOpen:P,onClose:()=>{G(!1),U(null)},fileId:I.id,fileName:I.name,mimeType:I.mimeType})]})},(t,e)=>t.message.id===e.message.id&&t.message.content===e.message.content);function sI(t){const e=t.filter(n=>n.type==="text").map(n=>n.text).join("");return e||JSON.stringify(t)}function lI(t){return t.includes(`
78
- `)||t.includes("```")||/[-*] /.test(t)||/#+\s/.test(t)}function cI(t){let e=t;try{(e.match(/```/g)||[]).length%2===1&&(e+="\n```"),(e.replace(/```[\s\S]*?```/g,"").match(new RegExp("(?<!`)`(?!`)","g"))||[]).length%2===1&&(e+="`")}catch{}return e}function dI(t){let e=t;try{const n=[],r=[],a="\0F",i="\0I";let o=e.replace(/```[\s\S]*?```/g,s=>(n.push(s),`${a}${n.length-1}\0`));o=o.replace(/`[^`]*`/g,s=>(r.push(s),`${i}${r.length-1}\0`)),o=o.replace(/\b([A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/\b([A-Za-z0-9_&\/-]+\s+[A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/([\.,;:!\?\-])\1+/g,"$1").replace(/([:;!\?\)])([A-Za-z])/g,"$1 $2").replace(/\s{3,}/g," "),o=o.replace(/\u0000F(\d+)\u0000/g,(s,l)=>n[Number(l)]??""),o=o.replace(/\u0000I(\d+)\u0000/g,(s,l)=>r[Number(l)]??""),e=o}catch{}return e}function ls(t){const e=t==null?void 0:t.trim();if(!e||!(e.startsWith("{")||e.startsWith("[")))return null;try{return JSON.parse(e)}catch{return null}}function Jm({data:t}){if(Array.isArray(t))return t.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:ei,children:u.jsx("ul",{className:"list-disc pl-5",children:t.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hr(t)});if(t&&typeof t=="object"){const e=Array.isArray(t.distilled_facts)?t.distilled_facts:null,n=Array.isArray(t.follow_up_queries)?t.follow_up_queries:null,r=typeof t.is_sufficient=="boolean"?t.is_sufficient:void 0;if(e||n||typeof r=="boolean")return u.jsxs("div",{className:ei,children:[typeof r=="boolean"&&u.jsxs("p",{children:[u.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Follow-up queries:"})}),u.jsx("ul",{className:"list-disc pl-5",children:n.map((i,o)=>u.jsx("li",{children:String(i)},o))})]}),e&&e.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Facts:"})}),u.jsx("ul",{className:"list-disc pl-5",children:e.map((i,o)=>u.jsx("li",{children:String(i)},o))})]})]});const a=Object.entries(t);return u.jsx("div",{className:ei,children:u.jsx("dl",{className:"mt-0",children:a.map(([i,o])=>u.jsxs("div",{className:"mb-1",children:[u.jsxs("dt",{className:"inline font-medium mr-1",children:[i,":"]}),u.jsx("dd",{className:"inline",children:uI(o)})]},i))})})}return u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hr(t)})}function uI(t){if(t==null)return String(t);const e=typeof t;if(e==="string"||e==="number"||e==="boolean")return String(t);if(Array.isArray(t)&&t.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return t.join(", ");try{return u.jsx("code",{className:"text-xs",children:JSON.stringify(ti(t))})}catch{return String(t)}}function eg(t){return!!(t&&typeof t=="object"&&(t.type==="file"||t.mimeType||t.filename||t.sourceType==="base64"))}function ti(t){if(typeof t=="string")return t.length>2e3?t.slice(0,2e3)+"... [truncated]":t;if(t&&typeof t=="object"){if(Array.isArray(t)){const n=t.map(ti).filter(r=>r!==void 0);return n.length?n:void 0}if(eg(t))return;const e={};for(const n of Object.keys(t)){const r=t[n];if(n==="data"&&typeof r=="string"&&r.length>100)e[n]=`[base64 ${r.length} chars omitted]`;else{const a=ti(r);a!==void 0&&(e[n]=a)}}return Object.keys(e).length?e:void 0}return t}function Hr(t){if(typeof t=="string")return t;if(eg(t))return"";try{const e=ti(t);return e===void 0?"":typeof e=="string"?e:JSON.stringify(e,null,2)}catch{return""}}function _I(t){const e=t.find(r=>r.type==="tool_call"),n=t.find(r=>r.type==="tool_result");return{name:e==null?void 0:e.name,toolCallId:(n==null?void 0:n.toolCallId)??(e==null?void 0:e.id)}}function pI(t){return t.name&&t.name.trim()?t.name:t.model&&t.model.includes("/")?t.model.split("/").pop()||null:t.model||null}function mI(t,e){const[n,r]=y.useState(t);return y.useEffect(()=>{if(!e){r(t);return}const a=setTimeout(()=>r(t),e);return()=>clearTimeout(a)},[t,e]),n}function gI({data:t}){return u.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(t).map(([e,n])=>u.jsxs("div",{className:"flex",children:[u.jsxs("dt",{className:"font-semibold mr-2",children:[e,":"]}),u.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,a)=>u.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},a)):String(n)})]},e))})}function tg(t){if(!t)return null;if(typeof t=="object"&&!Array.isArray(t)){if(t.desirability||t.feasibility||t.viability||t.other)return{desirability:Array.isArray(t.desirability)?t.desirability:[],feasibility:Array.isArray(t.feasibility)?t.feasibility:[],viability:Array.isArray(t.viability)?t.viability:[],other:Array.isArray(t.other)?t.other:[]};if(t.output&&typeof t.output!="object")t=t.output;else if(t.output&&typeof t.output=="object")return tg(t.output)}const e=String(t),n={desirability:[],feasibility:[],viability:[],other:[]};let r=e;const a=Math.min(...["desirability=","feasibility=","viability=","other="].map(o=>{const s=r.toLowerCase().indexOf(o);return s===-1?Number.MAX_SAFE_INTEGER:s}));a!==Number.MAX_SAFE_INTEGER&&(r=r.slice(a));for(const o of Object.keys(n)){const l=new RegExp(o+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const c=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let _=null;for(;(_=d.exec(c))!==null;){const p=_[1],m=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(p),g=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(p),f=m?m[2].trim():"",E=g?g[2].trim():"";n[o].push({title:f,description:E})}}return Object.values(n).some(o=>o.length>0)?n:null}function EI({issues:t}){const e=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return u.jsx("div",{className:ei,children:e.map(n=>{const r=t[n.key];return!r||!r.length?null:u.jsxs("div",{className:"mb-4",children:[u.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),u.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((a,i)=>u.jsxs("li",{children:[u.jsx("div",{className:"font-medium",children:a.title}),u.jsx("div",{className:"text-sm text-muted-foreground",children:a.description})]},i))})]},n.key)})})}function sr(t){const e=t.filter(n=>n.type==="tool_result");if(e.length)try{return e.length===1?Hr(e[0].output):Hr(e.map(n=>({toolCallId:n.toolCallId,output:n.output})))}catch{}return Hr(t)}function fI(t){const e=t.find(r=>r.type==="tool_result");if(!e)return null;const n=e.output;return typeof n=="string"?n:null}function ng({messages:t,isStreaming:e,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:a,enableMessageEditing:i,editingMessageId:o,onStartReached:s,onEdit:l,onRegenerate:c,onCancelEdit:d,className:_,style:p,emptyMessage:m}){const g=y.useRef(null),f=y.useRef(null),E=y.useRef(!1),S=y.useRef(!0),T=y.useRef(t.length);y.useEffect(()=>{const R=g.current;if(!R)return;const C=()=>{const N=R.scrollHeight-R.scrollTop-R.clientHeight;S.current=N<=32};return R.addEventListener("scroll",C,{passive:!0}),C(),()=>{R.removeEventListener("scroll",C)}},[t.length]),y.useEffect(()=>{t.length<T.current&&(S.current=!0),T.current=t.length},[t.length]),y.useEffect(()=>{var R;E.current||S.current&&S.current&&((R=f.current)==null||R.scrollToIndex({index:Math.max(0,t.length-1),behavior:"auto",align:"end"}),S.current=!0)},[t]);const h=y.useMemo(()=>{if(s)return async()=>{if(E.current)return;const R=g.current;if(!R){await(s==null?void 0:s());return}const C=R.scrollHeight,N=R.scrollTop;E.current=!0;try{await s()}finally{requestAnimationFrame(()=>{const O=g.current;if(!O){E.current=!1;return}const D=O.scrollHeight;O.scrollTop=N+(D-C);const w=D-O.scrollTop-O.clientHeight;S.current=w<=32,E.current=!1})}}},[s]),v=(R,C)=>{g.current=R,C&&(typeof C=="function"?C(R):C.current=R)};return t.length===0?u.jsx("div",{className:_,style:p,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:m||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:_,style:p,children:u.jsx(JN,{ref:R=>{f.current=R},data:t,followOutput:"smooth",overscan:120,increaseViewportBy:{top:200,bottom:200},startReached:()=>{h&&h()},atBottomStateChange:R=>{S.current=R},style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(R,C)=>C.id??`message-${R}`,components:{Scroller:y.forwardRef((R,C)=>u.jsx("div",{...R,ref:N=>v(N,C),style:{overflowAnchor:"none",willChange:"transform",...(R==null?void 0:R.style)??{}}}))},itemContent:(R,C)=>u.jsx("div",{className:"mb-4 last:mb-0",children:u.jsx(Zm,{message:C,messageIndex:R,isStreamingMessage:e&&n===C.id,streamingDebounceMs:r,isEditing:o===C.id,showActions:i,showTimestamp:!1,showAgentName:!0,layoutSize:a,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>c(R),onCancelEdit:d},C.id??`msg-${C.role}-${R}-${C.createdAt??""}`)})})})}const ni=1e4;function SI(t){if(typeof t!="string")return String(t);const e=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=t;for(const a of e)n=n.replace(a,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
77
+ For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return b.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},Jy="DialogDescriptionWarning",eI=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Vm(Jy).contentName}}.`;return b.useEffect(()=>{var i;const a=(i=t.current)==null?void 0:i.getAttribute("aria-describedby");e&&a&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},zm=xm,tI=wm,$m=Lm,Xa=Pm,Za=km,Gn=Fm,Ja=Gm,Wm=Hm;const nI=zm,rI=$m,Km=b.forwardRef(({className:t,...e},n)=>u.jsx(Xa,{ref:n,className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e}));Km.displayName=Xa.displayName;const Qm=b.forwardRef(({className:t,children:e,...n},r)=>{const a=b.useMemo(()=>{let i=!1;function o(s){b.Children.forEach(s,l=>{if(i||!b.isValidElement(l))return;const c=l.type;if(c===Gn||(c==null?void 0:c.displayName)===Gn.displayName||(c==null?void 0:c.name)==="DialogTitle"){i=!0;return}l.props&&l.props.children&&o(l.props.children)})}return o(e),i},[e]);return u.jsxs(rI,{children:[u.jsx(Km,{}),u.jsxs(Za,{ref:r,className:$("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...n,children:[!a&&u.jsx(Gn,{className:"sr-only",children:"Dialog"}),e,u.jsxs(Wm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(pe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Qm.displayName=Za.displayName;const jm=({className:t,...e})=>u.jsx("div",{className:$("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});jm.displayName="DialogHeader";const Xm=b.forwardRef(({className:t,...e},n)=>u.jsx(Gn,{ref:n,className:$("text-lg font-semibold leading-none tracking-tight",t),...e}));Xm.displayName=Gn.displayName;const aI=b.forwardRef(({className:t,...e},n)=>u.jsx(Ja,{ref:n,className:$("text-sm text-muted-foreground",t),...e}));aI.displayName=Ja.displayName;function iI({isOpen:t,onClose:e,fileId:n,fileName:r,mimeType:a}){const[i,o]=y.useState(!1),[s,l]=y.useState(null),[c,d]=y.useState(null),{toast:_}=Wo();y.useEffect(()=>{t&&n&&p()},[t,n]);const p=async()=>{if(n){o(!0),d(null),l(null);try{const S=await am(n);l(S)}catch(S){console.error("Failed to load file:",S),d(S instanceof Error?S.message:"Failed to load file")}finally{o(!1)}}},m=async()=>{if(n)try{await BO(n),_({title:"Download started",description:`Downloading ${r}`})}catch(S){console.error("Failed to download file:",S),_({title:"Download failed",description:String(S),variant:"destructive"})}},g=async()=>{if(n)try{const S=await am(n),T=new Blob([S],{type:a}),h=URL.createObjectURL(T);window.open(h,"_blank"),URL.revokeObjectURL(h)}catch(S){console.error("Failed to open file externally:",S),_({title:"Failed to open file",description:String(S),variant:"destructive"})}},f=()=>i?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(pe.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Ve,{onClick:p,variant:"outline",children:"Try Again"})]}):s?a.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${a};base64,${s}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):a==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${s}`,className:"w-full h-full",title:r})}):a.startsWith("text/")||a.includes("json")||a.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:s})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(pe.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[a," • ",s.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),E=()=>a.startsWith("image/")?u.jsx(pe.Image,{className:"h-5 w-5"}):u.jsx(pe.FileText,{className:"h-5 w-5"});return u.jsx(nI,{open:t,onOpenChange:e,children:u.jsxs(Qm,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(jm,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[E(),u.jsxs("div",{children:[u.jsx(Xm,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[a," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Ve,{variant:"outline",size:"sm",onClick:g,className:"flex items-center gap-2",children:[u.jsx(pe.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ve,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(pe.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:f()})]})})}const ei="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function oI({className:t}){const[e,n]=y.useState(0);return y.useEffect(()=>{const r=setInterval(()=>n(a=>(a+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:$("inline-block text-xs opacity-70 ml-1",t),children:["Is thinking",".".repeat(e)]})}const Zm=y.memo(function({message:e,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:a=300,isEditing:i=!1,showActions:o=!0,showTimestamp:s=!0,showAgentName:l=!0,layoutSize:c="desktop",truncateToolMessages:d=!0,toolMessagePreviewLength:_=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:g={},onEdit:f,onRegenerate:E,onCancelEdit:S,onCopy:T}){const[h,v]=y.useState(!1),[R,C]=y.useState(!1),[N,O]=y.useState(!1),[D,w]=y.useState(!1),{currentThreadId:L}=ba();Wo();const[H,z]=y.useState({}),[P,G]=y.useState(!1),[I,U]=y.useState(null),M=c==="phone"||c==="half-screen",k=e.role,Y=k==="tool",W=y.useMemo(()=>{switch(k){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[k]),re=y.useMemo(()=>sI(e.content),[e.content]),q=y.useMemo(()=>_I(e.content),[e.content]),X=y.useMemo(()=>e.content.filter(Se=>Se.type==="image_url"),[e.content]),ce=y.useMemo(()=>e.content.filter(Se=>Se.type==="file"),[e.content]),ge=mI(re,r?a:0),V=async()=>{try{const Se=Y?sr(e.content):re;await navigator.clipboard.writeText(Se),v(!0),setTimeout(()=>v(!1),2e3),T==null||T(Se)}catch(Se){console.error("Failed to copy:",Se)}},F=()=>{if(!f)return;const Se=Y?sr(e.content):re;f(e.id,Se)},K=()=>E==null?void 0:E(n),te=()=>{const Be=$(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",W);switch(k){case"user":return u.jsx(pe.User,{className:Be});case"assistant":return u.jsx(pe.Bot,{className:Be});case"tool":return u.jsx(pe.Wrench,{className:Be});default:return u.jsx(pe.Bot,{className:Be})}},le=()=>{const Se="group relative mb-4 flex w-full";switch(k){case"user":return $(Se,"justify-end");case"assistant":case"tool":case"system":return $(Se,"justify-start");default:return Se}},oe=()=>{const Se=$("rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");switch(k){case"user":return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return $(Se,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return $(Se,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},Ae=Se=>{if(!Se)return"";try{return new Date(Se).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},qe=()=>{if(e.model==="reflection"){const ee=re.trim(),Q=ls(ee);if(Q&&typeof Q=="object")return u.jsx(gI,{data:Q})}if(Y&&q.name==="get_issues"){const ee=e.content.find(be=>be.type==="tool_result"),Q=(ee==null?void 0:ee.output)??sr(e.content),ae=tg(Q);if(ae)return u.jsx(EI,{issues:ae})}if(Y&&!N){const ee=sr(e.content).slice(0,80).replace(/\s+/g," ");return u.jsx("div",{className:$("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",M&&"text-[10px]"),children:u.jsxs("span",{className:"truncate max-w-full text-current",children:[ee,ee.length>=80?"…":""]})})}if(Y&&d){const ee=sr(e.content),Q=ee.length>_;return u.jsx(Xp,{open:R,onOpenChange:C,children:u.jsxs("div",{className:"font-mono text-sm text-current",children:[u.jsx("pre",{className:$("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:Q&&!R?ee.substring(0,_)+"...":ee}),Q&&u.jsx(Zp,{asChild:!0,children:u.jsx(Ve,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:R?u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",ee.length-_," chars)"]})})})]})})}if(Y&&N&&!d){const ee=fI(e.content);if(ee&&lI(ee))return u.jsx(Br,{content:ee.trim()});const Q=sr(e.content);return u.jsx("div",{className:"font-mono text-sm text-current",children:u.jsx("pre",{className:$("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:Q})})}const Se=X.length>0&&k!=="tool",Be=ce.length>0&&k!=="tool"&&!1;return u.jsxs("div",{children:[r?u.jsxs("div",{className:"relative",children:[(()=>{const ee=ls(ge);return ee!==null?u.jsx(Jm,{data:ee}):u.jsx(Br,{content:dI(cI(ge))})})(),u.jsx(oI,{className:$(W,M?"text-xs":"text-sm")})]}):(()=>{const ee=ls(re.trim());if(ee!==null)return u.jsx(Jm,{data:ee});if(k==="user"&&p){const Q=re.trim();if(Q.length>m)return u.jsxs(Xp,{open:D,onOpenChange:w,children:[u.jsx("div",{className:$("text-sm text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:D?u.jsx(Br,{content:Q}):u.jsxs("pre",{className:$("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:[Q.substring(0,m),"..."]})}),u.jsx(Zp,{asChild:!0,children:u.jsx(Ve,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:D?u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",Q.length-m," chars)"]})})})]})}return u.jsx(Br,{content:re.trim()})})(),Se&&u.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:X.map((ee,Q)=>u.jsxs("div",{className:"relative border rounded overflow-hidden",children:[u.jsx("img",{src:ee.url,alt:ee.alt??"image",className:"w-full h-auto"}),u.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[u.jsx(pe.Image,{className:"h-3 w-3"}),u.jsx("span",{children:"image"})]})]},Q))}),Be]})},Me=y.useMemo(()=>pI(e),[e]);return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:$(le(),g.container),children:u.jsxs("div",{className:$(oe(),g.content),children:[(s||l||Y)&&u.jsxs("div",{className:$("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",W,g.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[te(),l&&Me&&u.jsx("span",{className:$("font-medium",M?"text-xs":"text-sm"),children:Me}),Y&&q.name&&u.jsxs(zp,{variant:"outline",className:$("text-xs flex items-center gap-1 cursor-pointer",W,"border border-current/40",M&&"text-xs h-4"),onClick:()=>O(Se=>!Se),children:[u.jsx("span",{children:q.name}),u.jsx("span",{className:"inline-flex items-center",children:N?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})})]}),Y&&!q.name&&u.jsx(Ve,{variant:"ghost",size:"sm",className:$("h-6 px-1",W,"hover:bg-foreground/10"),onClick:()=>O(Se=>!Se),children:u.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",N?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})]})})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[s&&u.jsx("span",{className:$("text-xs opacity-60",W,M&&"text-xs"),children:Ae(e.createdAt)}),o&&!i&&u.jsxs("div",{className:$("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",g.actions),children:[u.jsx(Ve,{variant:"ghost",size:"sm",onClick:V,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:$(h?"text-success":W,M?"h-3 w-3":"h-4 w-4")})}),k==="user"&&f&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:F,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:$(W,M?"h-3 w-3":"h-4 w-4")})}),k==="assistant"&&E&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:K,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:$(W,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:qe()}),Y&&N&&(q.toolCallId||q.name)&&u.jsxs("div",{className:$("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[q.name&&u.jsxs("div",{children:["Function: ",q.name]}),q.toolCallId&&u.jsxs("div",{children:["Call ID: ",q.toolCallId]})]}),!(s||l||Y)&&o&&!i&&u.jsxs("div",{className:$("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",g.actions),children:[u.jsx(Ve,{variant:"ghost",size:"sm",onClick:V,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:$(h?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),k==="user"&&f&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:F,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:$("text-current",M?"h-3 w-3":"h-4 w-4")})}),k==="assistant"&&E&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:K,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:$("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),I&&u.jsx(iI,{isOpen:P,onClose:()=>{G(!1),U(null)},fileId:I.id,fileName:I.name,mimeType:I.mimeType})]})},(t,e)=>e.isStreamingMessage?!1:t.message.id===e.message.id&&t.message.content===e.message.content&&t.isStreamingMessage===e.isStreamingMessage&&t.isEditing===e.isEditing);function sI(t){const e=t.filter(n=>n.type==="text").map(n=>n.text).join("");return e||JSON.stringify(t)}function lI(t){return t.includes(`
78
+ `)||t.includes("```")||/[-*] /.test(t)||/#+\s/.test(t)}function cI(t){let e=t;try{(e.match(/```/g)||[]).length%2===1&&(e+="\n```"),(e.replace(/```[\s\S]*?```/g,"").match(new RegExp("(?<!`)`(?!`)","g"))||[]).length%2===1&&(e+="`")}catch{}return e}function dI(t){let e=t;try{const n=[],r=[],a="\0F",i="\0I";let o=e.replace(/```[\s\S]*?```/g,s=>(n.push(s),`${a}${n.length-1}\0`));o=o.replace(/`[^`]*`/g,s=>(r.push(s),`${i}${r.length-1}\0`)),o=o.replace(/\b([A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/\b([A-Za-z0-9_&\/-]+\s+[A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/([\.,;:!\?\-])\1+/g,"$1").replace(/([:;!\?\)])([A-Za-z])/g,"$1 $2").replace(/\s{3,}/g," "),o=o.replace(/\u0000F(\d+)\u0000/g,(s,l)=>n[Number(l)]??""),o=o.replace(/\u0000I(\d+)\u0000/g,(s,l)=>r[Number(l)]??""),e=o}catch{}return e}function ls(t){const e=t==null?void 0:t.trim();if(!e||!(e.startsWith("{")||e.startsWith("[")))return null;try{return JSON.parse(e)}catch{return null}}function Jm({data:t}){if(Array.isArray(t))return t.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:ei,children:u.jsx("ul",{className:"list-disc pl-5",children:t.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hr(t)});if(t&&typeof t=="object"){const e=Array.isArray(t.distilled_facts)?t.distilled_facts:null,n=Array.isArray(t.follow_up_queries)?t.follow_up_queries:null,r=typeof t.is_sufficient=="boolean"?t.is_sufficient:void 0;if(e||n||typeof r=="boolean")return u.jsxs("div",{className:ei,children:[typeof r=="boolean"&&u.jsxs("p",{children:[u.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Follow-up queries:"})}),u.jsx("ul",{className:"list-disc pl-5",children:n.map((i,o)=>u.jsx("li",{children:String(i)},o))})]}),e&&e.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Facts:"})}),u.jsx("ul",{className:"list-disc pl-5",children:e.map((i,o)=>u.jsx("li",{children:String(i)},o))})]})]});const a=Object.entries(t);return u.jsx("div",{className:ei,children:u.jsx("dl",{className:"mt-0",children:a.map(([i,o])=>u.jsxs("div",{className:"mb-1",children:[u.jsxs("dt",{className:"inline font-medium mr-1",children:[i,":"]}),u.jsx("dd",{className:"inline",children:uI(o)})]},i))})})}return u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hr(t)})}function uI(t){if(t==null)return String(t);const e=typeof t;if(e==="string"||e==="number"||e==="boolean")return String(t);if(Array.isArray(t)&&t.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return t.join(", ");try{return u.jsx("code",{className:"text-xs",children:JSON.stringify(ti(t))})}catch{return String(t)}}function eg(t){return!!(t&&typeof t=="object"&&(t.type==="file"||t.mimeType||t.filename||t.sourceType==="base64"))}function ti(t){if(typeof t=="string")return t.length>2e3?t.slice(0,2e3)+"... [truncated]":t;if(t&&typeof t=="object"){if(Array.isArray(t)){const n=t.map(ti).filter(r=>r!==void 0);return n.length?n:void 0}if(eg(t))return;const e={};for(const n of Object.keys(t)){const r=t[n];if(n==="data"&&typeof r=="string"&&r.length>100)e[n]=`[base64 ${r.length} chars omitted]`;else{const a=ti(r);a!==void 0&&(e[n]=a)}}return Object.keys(e).length?e:void 0}return t}function Hr(t){if(typeof t=="string")return t;if(eg(t))return"";try{const e=ti(t);return e===void 0?"":typeof e=="string"?e:JSON.stringify(e,null,2)}catch{return""}}function _I(t){const e=t.find(r=>r.type==="tool_call"),n=t.find(r=>r.type==="tool_result");return{name:e==null?void 0:e.name,toolCallId:(n==null?void 0:n.toolCallId)??(e==null?void 0:e.id)}}function pI(t){return t.name&&t.name.trim()?t.name:t.model&&t.model.includes("/")?t.model.split("/").pop()||null:t.model||null}function mI(t,e){const[n,r]=y.useState(t);return y.useEffect(()=>{if(!e){r(t);return}const a=setTimeout(()=>r(t),e);return()=>clearTimeout(a)},[t,e]),n}function gI({data:t}){return u.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(t).map(([e,n])=>u.jsxs("div",{className:"flex",children:[u.jsxs("dt",{className:"font-semibold mr-2",children:[e,":"]}),u.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,a)=>u.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},a)):String(n)})]},e))})}function tg(t){if(!t)return null;if(typeof t=="object"&&!Array.isArray(t)){if(t.desirability||t.feasibility||t.viability||t.other)return{desirability:Array.isArray(t.desirability)?t.desirability:[],feasibility:Array.isArray(t.feasibility)?t.feasibility:[],viability:Array.isArray(t.viability)?t.viability:[],other:Array.isArray(t.other)?t.other:[]};if(t.output&&typeof t.output!="object")t=t.output;else if(t.output&&typeof t.output=="object")return tg(t.output)}const e=String(t),n={desirability:[],feasibility:[],viability:[],other:[]};let r=e;const a=Math.min(...["desirability=","feasibility=","viability=","other="].map(o=>{const s=r.toLowerCase().indexOf(o);return s===-1?Number.MAX_SAFE_INTEGER:s}));a!==Number.MAX_SAFE_INTEGER&&(r=r.slice(a));for(const o of Object.keys(n)){const l=new RegExp(o+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const c=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let _=null;for(;(_=d.exec(c))!==null;){const p=_[1],m=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(p),g=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(p),f=m?m[2].trim():"",E=g?g[2].trim():"";n[o].push({title:f,description:E})}}return Object.values(n).some(o=>o.length>0)?n:null}function EI({issues:t}){const e=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return u.jsx("div",{className:ei,children:e.map(n=>{const r=t[n.key];return!r||!r.length?null:u.jsxs("div",{className:"mb-4",children:[u.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),u.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((a,i)=>u.jsxs("li",{children:[u.jsx("div",{className:"font-medium",children:a.title}),u.jsx("div",{className:"text-sm text-muted-foreground",children:a.description})]},i))})]},n.key)})})}function sr(t){const e=t.filter(n=>n.type==="tool_result");if(e.length)try{return e.length===1?Hr(e[0].output):Hr(e.map(n=>({toolCallId:n.toolCallId,output:n.output})))}catch{}return Hr(t)}function fI(t){const e=t.find(r=>r.type==="tool_result");if(!e)return null;const n=e.output;return typeof n=="string"?n:null}function ng({messages:t,isStreaming:e,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:a,enableMessageEditing:i,editingMessageId:o,onStartReached:s,onEdit:l,onRegenerate:c,onCancelEdit:d,className:_,style:p,emptyMessage:m}){const g=y.useRef(null),f=y.useRef(null),E=y.useRef(!1),S=y.useRef(!0),T=y.useRef(t.length);y.useEffect(()=>{const R=g.current;if(!R)return;const C=()=>{const N=R.scrollHeight-R.scrollTop-R.clientHeight;S.current=N<=32};return R.addEventListener("scroll",C,{passive:!0}),C(),()=>{R.removeEventListener("scroll",C)}},[t.length]),y.useEffect(()=>{t.length<T.current&&(S.current=!0),T.current=t.length},[t.length]),y.useEffect(()=>{var R;E.current||S.current&&S.current&&((R=f.current)==null||R.scrollToIndex({index:Math.max(0,t.length-1),behavior:"auto",align:"end"}),S.current=!0)},[t]);const h=y.useMemo(()=>{if(s)return async()=>{if(E.current)return;const R=g.current;if(!R){await(s==null?void 0:s());return}const C=R.scrollHeight,N=R.scrollTop;E.current=!0;try{await s()}finally{requestAnimationFrame(()=>{const O=g.current;if(!O){E.current=!1;return}const D=O.scrollHeight;O.scrollTop=N+(D-C);const w=D-O.scrollTop-O.clientHeight;S.current=w<=32,E.current=!1})}}},[s]),v=(R,C)=>{g.current=R,C&&(typeof C=="function"?C(R):C.current=R)};return t.length===0?u.jsx("div",{className:_,style:p,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:m||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:_,style:p,children:u.jsx(JN,{ref:R=>{f.current=R},data:t,followOutput:"smooth",overscan:{main:200,reverse:200},increaseViewportBy:{top:400,bottom:400},startReached:()=>{h&&h()},atBottomStateChange:R=>{S.current=R},style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(R,C)=>C.id??`message-${R}`,components:{Scroller:y.forwardRef((R,C)=>u.jsx("div",{...R,ref:N=>v(N,C),style:{overflowAnchor:"none",willChange:"transform",contain:"layout style paint",...(R==null?void 0:R.style)??{}}}))},itemContent:(R,C)=>u.jsx("div",{className:"mb-4 last:mb-0",style:{contentVisibility:"auto",containIntrinsicSize:"auto 100px",transform:"translateZ(0)"},children:u.jsx(Zm,{message:C,messageIndex:R,isStreamingMessage:e&&n===C.id,streamingDebounceMs:r,isEditing:o===C.id,showActions:i,showTimestamp:!1,showAgentName:!0,layoutSize:a,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>c(R),onCancelEdit:d},C.id??`msg-${C.role}-${R}-${C.createdAt??""}`)})})})}const ni=1e4;function SI(t){if(typeof t!="string")return String(t);const e=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=t;for(const a of e)n=n.replace(a,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
79
79
  `).replace(/<p>(.*?)<\/p>/gi,`$1
80
80
 
81
81
  `).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(a,i,o)=>`${"#".repeat(parseInt(i))} ${o}
@@ -83,7 +83,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${e.do
83
83
  `).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
84
84
  `).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
85
85
  `).replace(/<li>(.*?)<\/li>/gi,`- $1
86
- `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function bI(t,e=ni){if(!t||typeof t!="string")throw new Error("Invalid content: must be a non-empty string");if(t.length>e)throw new Error(`Message exceeds maximum length of ${e} characters`);return t}function TI(t){let e;return typeof t=="string"?e=t:typeof t=="object"&&t!==null?e=JSON.stringify(t):e=String(t),bI(e),SI(e)}function cs(t){const e=t+"CollectionProvider",[n,r]=qt(e),[a,i]=n(e,{collectionRef:{current:null},itemMap:new Map}),o=f=>{const{scope:E,children:S}=f,T=y.useRef(null),h=y.useRef(new Map).current;return u.jsx(a,{scope:E,itemMap:h,collectionRef:T,children:S})};o.displayName=e;const s=t+"CollectionSlot",l=Nt.createSlot(s),c=y.forwardRef((f,E)=>{const{scope:S,children:T}=f,h=i(s,S),v=ke(E,h.collectionRef);return u.jsx(l,{ref:v,children:T})});c.displayName=s;const d=t+"CollectionItemSlot",_="data-radix-collection-item",p=Nt.createSlot(d),m=y.forwardRef((f,E)=>{const{scope:S,children:T,...h}=f,v=y.useRef(null),R=ke(E,v),C=i(d,S);return y.useEffect(()=>(C.itemMap.set(v,{ref:v,...h}),()=>void C.itemMap.delete(v))),u.jsx(p,{[_]:"",ref:R,children:T})});m.displayName=d;function g(f){const E=i(t+"CollectionConsumer",f);return y.useCallback(()=>{const T=E.collectionRef.current;if(!T)return[];const h=Array.from(T.querySelectorAll(`[${_}]`));return Array.from(E.itemMap.values()).sort((C,N)=>h.indexOf(C.ref.current)-h.indexOf(N.ref.current))},[E.collectionRef,E.itemMap])}return[{Provider:o,Slot:c,ItemSlot:m},g,r]}var hI=b.createContext(void 0);function ri(t){const e=b.useContext(hI);return t||e||"ltr"}const RI=["top","right","bottom","left"],Nn=Math.min,It=Math.max,ai=Math.round,ii=Math.floor,tn=t=>({x:t,y:t}),CI={left:"right",right:"left",bottom:"top",top:"bottom"},vI={start:"end",end:"start"};function ds(t,e,n){return It(t,Nn(e,n))}function un(t,e){return typeof t=="function"?t(e):t}function _n(t){return t.split("-")[0]}function lr(t){return t.split("-")[1]}function us(t){return t==="x"?"y":"x"}function _s(t){return t==="y"?"height":"width"}const NI=new Set(["top","bottom"]);function nn(t){return NI.has(_n(t))?"y":"x"}function ps(t){return us(nn(t))}function OI(t,e,n){n===void 0&&(n=!1);const r=lr(t),a=ps(t),i=_s(a);let o=a==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[i]>e.floating[i]&&(o=oi(o)),[o,oi(o)]}function yI(t){const e=oi(t);return[ms(t),e,ms(e)]}function ms(t){return t.replace(/start|end/g,e=>vI[e])}const rg=["left","right"],ag=["right","left"],II=["top","bottom"],AI=["bottom","top"];function xI(t,e,n){switch(t){case"top":case"bottom":return n?e?ag:rg:e?rg:ag;case"left":case"right":return e?II:AI;default:return[]}}function DI(t,e,n,r){const a=lr(t);let i=xI(_n(t),n==="start",r);return a&&(i=i.map(o=>o+"-"+a),e&&(i=i.concat(i.map(ms)))),i}function oi(t){return t.replace(/left|right|bottom|top/g,e=>CI[e])}function wI(t){return{top:0,right:0,bottom:0,left:0,...t}}function ig(t){return typeof t!="number"?wI(t):{top:t,right:t,bottom:t,left:t}}function si(t){const{x:e,y:n,width:r,height:a}=t;return{width:r,height:a,top:n,left:e,right:e+r,bottom:n+a,x:e,y:n}}function og(t,e,n){let{reference:r,floating:a}=t;const i=nn(e),o=ps(e),s=_s(o),l=_n(e),c=i==="y",d=r.x+r.width/2-a.width/2,_=r.y+r.height/2-a.height/2,p=r[s]/2-a[s]/2;let m;switch(l){case"top":m={x:d,y:r.y-a.height};break;case"bottom":m={x:d,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:_};break;case"left":m={x:r.x-a.width,y:_};break;default:m={x:r.x,y:r.y}}switch(lr(e)){case"start":m[o]-=p*(n&&c?-1:1);break;case"end":m[o]+=p*(n&&c?-1:1);break}return m}const MI=async(t,e,n)=>{const{placement:r="bottom",strategy:a="absolute",middleware:i=[],platform:o}=n,s=i.filter(Boolean),l=await(o.isRTL==null?void 0:o.isRTL(e));let c=await o.getElementRects({reference:t,floating:e,strategy:a}),{x:d,y:_}=og(c,r,l),p=r,m={},g=0;for(let f=0;f<s.length;f++){const{name:E,fn:S}=s[f],{x:T,y:h,data:v,reset:R}=await S({x:d,y:_,initialPlacement:r,placement:p,strategy:a,middlewareData:m,rects:c,platform:o,elements:{reference:t,floating:e}});d=T??d,_=h??_,m={...m,[E]:{...m[E],...v}},R&&g<=50&&(g++,typeof R=="object"&&(R.placement&&(p=R.placement),R.rects&&(c=R.rects===!0?await o.getElementRects({reference:t,floating:e,strategy:a}):R.rects),{x:d,y:_}=og(c,p,l)),f=-1)}return{x:d,y:_,placement:p,strategy:a,middlewareData:m}};async function qr(t,e){var n;e===void 0&&(e={});const{x:r,y:a,platform:i,rects:o,elements:s,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:_="floating",altBoundary:p=!1,padding:m=0}=un(e,t),g=ig(m),E=s[p?_==="floating"?"reference":"floating":_],S=si(await i.getClippingRect({element:(n=await(i.isElement==null?void 0:i.isElement(E)))==null||n?E:E.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(s.floating)),boundary:c,rootBoundary:d,strategy:l})),T=_==="floating"?{x:r,y:a,width:o.floating.width,height:o.floating.height}:o.reference,h=await(i.getOffsetParent==null?void 0:i.getOffsetParent(s.floating)),v=await(i.isElement==null?void 0:i.isElement(h))?await(i.getScale==null?void 0:i.getScale(h))||{x:1,y:1}:{x:1,y:1},R=si(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:s,rect:T,offsetParent:h,strategy:l}):T);return{top:(S.top-R.top+g.top)/v.y,bottom:(R.bottom-S.bottom+g.bottom)/v.y,left:(S.left-R.left+g.left)/v.x,right:(R.right-S.right+g.right)/v.x}}const LI=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:a,rects:i,platform:o,elements:s,middlewareData:l}=e,{element:c,padding:d=0}=un(t,e)||{};if(c==null)return{};const _=ig(d),p={x:n,y:r},m=ps(a),g=_s(m),f=await o.getDimensions(c),E=m==="y",S=E?"top":"left",T=E?"bottom":"right",h=E?"clientHeight":"clientWidth",v=i.reference[g]+i.reference[m]-p[m]-i.floating[g],R=p[m]-i.reference[m],C=await(o.getOffsetParent==null?void 0:o.getOffsetParent(c));let N=C?C[h]:0;(!N||!await(o.isElement==null?void 0:o.isElement(C)))&&(N=s.floating[h]||i.floating[g]);const O=v/2-R/2,D=N/2-f[g]/2-1,w=Nn(_[S],D),L=Nn(_[T],D),H=w,z=N-f[g]-L,P=N/2-f[g]/2+O,G=ds(H,P,z),I=!l.arrow&&lr(a)!=null&&P!==G&&i.reference[g]/2-(P<H?w:L)-f[g]/2<0,U=I?P<H?P-H:P-z:0;return{[m]:p[m]+U,data:{[m]:G,centerOffset:P-G-U,...I&&{alignmentOffset:U}},reset:I}}}),PI=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:a,middlewareData:i,rects:o,initialPlacement:s,platform:l,elements:c}=e,{mainAxis:d=!0,crossAxis:_=!0,fallbackPlacements:p,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:f=!0,...E}=un(t,e);if((n=i.arrow)!=null&&n.alignmentOffset)return{};const S=_n(a),T=nn(s),h=_n(s)===s,v=await(l.isRTL==null?void 0:l.isRTL(c.floating)),R=p||(h||!f?[oi(s)]:yI(s)),C=g!=="none";!p&&C&&R.push(...DI(s,f,g,v));const N=[s,...R],O=await qr(e,E),D=[];let w=((r=i.flip)==null?void 0:r.overflows)||[];if(d&&D.push(O[S]),_){const P=OI(a,o,v);D.push(O[P[0]],O[P[1]])}if(w=[...w,{placement:a,overflows:D}],!D.every(P=>P<=0)){var L,H;const P=(((L=i.flip)==null?void 0:L.index)||0)+1,G=N[P];if(G&&(!(_==="alignment"?T!==nn(G):!1)||w.every(M=>nn(M.placement)===T?M.overflows[0]>0:!0)))return{data:{index:P,overflows:w},reset:{placement:G}};let I=(H=w.filter(U=>U.overflows[0]<=0).sort((U,M)=>U.overflows[1]-M.overflows[1])[0])==null?void 0:H.placement;if(!I)switch(m){case"bestFit":{var z;const U=(z=w.filter(M=>{if(C){const k=nn(M.placement);return k===T||k==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(k=>k>0).reduce((k,Y)=>k+Y,0)]).sort((M,k)=>M[1]-k[1])[0])==null?void 0:z[0];U&&(I=U);break}case"initialPlacement":I=s;break}if(a!==I)return{reset:{placement:I}}}return{}}}};function sg(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function lg(t){return RI.some(e=>t[e]>=0)}const kI=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...a}=un(t,e);switch(r){case"referenceHidden":{const i=await qr(e,{...a,elementContext:"reference"}),o=sg(i,n.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:lg(o)}}}case"escaped":{const i=await qr(e,{...a,altBoundary:!0}),o=sg(i,n.floating);return{data:{escapedOffsets:o,escaped:lg(o)}}}default:return{}}}}},cg=new Set(["left","top"]);async function UI(t,e){const{placement:n,platform:r,elements:a}=t,i=await(r.isRTL==null?void 0:r.isRTL(a.floating)),o=_n(n),s=lr(n),l=nn(n)==="y",c=cg.has(o)?-1:1,d=i&&l?-1:1,_=un(e,t);let{mainAxis:p,crossAxis:m,alignmentAxis:g}=typeof _=="number"?{mainAxis:_,crossAxis:0,alignmentAxis:null}:{mainAxis:_.mainAxis||0,crossAxis:_.crossAxis||0,alignmentAxis:_.alignmentAxis};return s&&typeof g=="number"&&(m=s==="end"?g*-1:g),l?{x:m*d,y:p*c}:{x:p*c,y:m*d}}const FI=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:a,y:i,placement:o,middlewareData:s}=e,l=await UI(e,t);return o===((n=s.offset)==null?void 0:n.placement)&&(r=s.arrow)!=null&&r.alignmentOffset?{}:{x:a+l.x,y:i+l.y,data:{...l,placement:o}}}}},BI=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:a}=e,{mainAxis:i=!0,crossAxis:o=!1,limiter:s={fn:E=>{let{x:S,y:T}=E;return{x:S,y:T}}},...l}=un(t,e),c={x:n,y:r},d=await qr(e,l),_=nn(_n(a)),p=us(_);let m=c[p],g=c[_];if(i){const E=p==="y"?"top":"left",S=p==="y"?"bottom":"right",T=m+d[E],h=m-d[S];m=ds(T,m,h)}if(o){const E=_==="y"?"top":"left",S=_==="y"?"bottom":"right",T=g+d[E],h=g-d[S];g=ds(T,g,h)}const f=s.fn({...e,[p]:m,[_]:g});return{...f,data:{x:f.x-n,y:f.y-r,enabled:{[p]:i,[_]:o}}}}}},GI=function(t){return t===void 0&&(t={}),{options:t,fn(e){const{x:n,y:r,placement:a,rects:i,middlewareData:o}=e,{offset:s=0,mainAxis:l=!0,crossAxis:c=!0}=un(t,e),d={x:n,y:r},_=nn(a),p=us(_);let m=d[p],g=d[_];const f=un(s,e),E=typeof f=="number"?{mainAxis:f,crossAxis:0}:{mainAxis:0,crossAxis:0,...f};if(l){const h=p==="y"?"height":"width",v=i.reference[p]-i.floating[h]+E.mainAxis,R=i.reference[p]+i.reference[h]-E.mainAxis;m<v?m=v:m>R&&(m=R)}if(c){var S,T;const h=p==="y"?"width":"height",v=cg.has(_n(a)),R=i.reference[_]-i.floating[h]+(v&&((S=o.offset)==null?void 0:S[_])||0)+(v?0:E.crossAxis),C=i.reference[_]+i.reference[h]+(v?0:((T=o.offset)==null?void 0:T[_])||0)-(v?E.crossAxis:0);g<R?g=R:g>C&&(g=C)}return{[p]:m,[_]:g}}}},YI=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var n,r;const{placement:a,rects:i,platform:o,elements:s}=e,{apply:l=()=>{},...c}=un(t,e),d=await qr(e,c),_=_n(a),p=lr(a),m=nn(a)==="y",{width:g,height:f}=i.floating;let E,S;_==="top"||_==="bottom"?(E=_,S=p===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(S=_,E=p==="end"?"top":"bottom");const T=f-d.top-d.bottom,h=g-d.left-d.right,v=Nn(f-d[E],T),R=Nn(g-d[S],h),C=!e.middlewareData.shift;let N=v,O=R;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(O=h),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(N=T),C&&!p){const w=It(d.left,0),L=It(d.right,0),H=It(d.top,0),z=It(d.bottom,0);m?O=g-2*(w!==0||L!==0?w+L:It(d.left,d.right)):N=f-2*(H!==0||z!==0?H+z:It(d.top,d.bottom))}await l({...e,availableWidth:O,availableHeight:N});const D=await o.getDimensions(s.floating);return g!==D.width||f!==D.height?{reset:{rects:!0}}:{}}}};function li(){return typeof window<"u"}function cr(t){return dg(t)?(t.nodeName||"").toLowerCase():"#document"}function At(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function rn(t){var e;return(e=(dg(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function dg(t){return li()?t instanceof Node||t instanceof At(t).Node:!1}function $t(t){return li()?t instanceof Element||t instanceof At(t).Element:!1}function an(t){return li()?t instanceof HTMLElement||t instanceof At(t).HTMLElement:!1}function ug(t){return!li()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof At(t).ShadowRoot}const HI=new Set(["inline","contents"]);function Vr(t){const{overflow:e,overflowX:n,overflowY:r,display:a}=Wt(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!HI.has(a)}const qI=new Set(["table","td","th"]);function VI(t){return qI.has(cr(t))}const zI=[":popover-open",":modal"];function ci(t){return zI.some(e=>{try{return t.matches(e)}catch{return!1}})}const $I=["transform","translate","scale","rotate","perspective"],WI=["transform","translate","scale","rotate","perspective","filter"],KI=["paint","layout","strict","content"];function gs(t){const e=Es(),n=$t(t)?Wt(t):t;return $I.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||WI.some(r=>(n.willChange||"").includes(r))||KI.some(r=>(n.contain||"").includes(r))}function QI(t){let e=On(t);for(;an(e)&&!dr(e);){if(gs(e))return e;if(ci(e))return null;e=On(e)}return null}function Es(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const jI=new Set(["html","body","#document"]);function dr(t){return jI.has(cr(t))}function Wt(t){return At(t).getComputedStyle(t)}function di(t){return $t(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function On(t){if(cr(t)==="html")return t;const e=t.assignedSlot||t.parentNode||ug(t)&&t.host||rn(t);return ug(e)?e.host:e}function _g(t){const e=On(t);return dr(e)?t.ownerDocument?t.ownerDocument.body:t.body:an(e)&&Vr(e)?e:_g(e)}function zr(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const a=_g(t),i=a===((r=t.ownerDocument)==null?void 0:r.body),o=At(a);if(i){const s=fs(o);return e.concat(o,o.visualViewport||[],Vr(a)?a:[],s&&n?zr(s):[])}return e.concat(a,zr(a,[],n))}function fs(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function pg(t){const e=Wt(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const a=an(t),i=a?t.offsetWidth:n,o=a?t.offsetHeight:r,s=ai(n)!==i||ai(r)!==o;return s&&(n=i,r=o),{width:n,height:r,$:s}}function Ss(t){return $t(t)?t:t.contextElement}function ur(t){const e=Ss(t);if(!an(e))return tn(1);const n=e.getBoundingClientRect(),{width:r,height:a,$:i}=pg(e);let o=(i?ai(n.width):n.width)/r,s=(i?ai(n.height):n.height)/a;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}const XI=tn(0);function mg(t){const e=At(t);return!Es()||!e.visualViewport?XI:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ZI(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==At(t)?!1:e}function Yn(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const a=t.getBoundingClientRect(),i=Ss(t);let o=tn(1);e&&(r?$t(r)&&(o=ur(r)):o=ur(t));const s=ZI(i,n,r)?mg(i):tn(0);let l=(a.left+s.x)/o.x,c=(a.top+s.y)/o.y,d=a.width/o.x,_=a.height/o.y;if(i){const p=At(i),m=r&&$t(r)?At(r):r;let g=p,f=fs(g);for(;f&&r&&m!==g;){const E=ur(f),S=f.getBoundingClientRect(),T=Wt(f),h=S.left+(f.clientLeft+parseFloat(T.paddingLeft))*E.x,v=S.top+(f.clientTop+parseFloat(T.paddingTop))*E.y;l*=E.x,c*=E.y,d*=E.x,_*=E.y,l+=h,c+=v,g=At(f),f=fs(g)}}return si({width:d,height:_,x:l,y:c})}function ui(t,e){const n=di(t).scrollLeft;return e?e.left+n:Yn(rn(t)).left+n}function gg(t,e){const n=t.getBoundingClientRect(),r=n.left+e.scrollLeft-ui(t,n),a=n.top+e.scrollTop;return{x:r,y:a}}function JI(t){let{elements:e,rect:n,offsetParent:r,strategy:a}=t;const i=a==="fixed",o=rn(r),s=e?ci(e.floating):!1;if(r===o||s&&i)return n;let l={scrollLeft:0,scrollTop:0},c=tn(1);const d=tn(0),_=an(r);if((_||!_&&!i)&&((cr(r)!=="body"||Vr(o))&&(l=di(r)),an(r))){const m=Yn(r);c=ur(r),d.x=m.x+r.clientLeft,d.y=m.y+r.clientTop}const p=o&&!_&&!i?gg(o,l):tn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function eA(t){return Array.from(t.getClientRects())}function tA(t){const e=rn(t),n=di(t),r=t.ownerDocument.body,a=It(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),i=It(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+ui(t);const s=-n.scrollTop;return Wt(r).direction==="rtl"&&(o+=It(e.clientWidth,r.clientWidth)-a),{width:a,height:i,x:o,y:s}}const Eg=25;function nA(t,e){const n=At(t),r=rn(t),a=n.visualViewport;let i=r.clientWidth,o=r.clientHeight,s=0,l=0;if(a){i=a.width,o=a.height;const d=Es();(!d||d&&e==="fixed")&&(s=a.offsetLeft,l=a.offsetTop)}const c=ui(r);if(c<=0){const d=r.ownerDocument,_=d.body,p=getComputedStyle(_),m=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,g=Math.abs(r.clientWidth-_.clientWidth-m);g<=Eg&&(i-=g)}else c<=Eg&&(i+=c);return{width:i,height:o,x:s,y:l}}const rA=new Set(["absolute","fixed"]);function aA(t,e){const n=Yn(t,!0,e==="fixed"),r=n.top+t.clientTop,a=n.left+t.clientLeft,i=an(t)?ur(t):tn(1),o=t.clientWidth*i.x,s=t.clientHeight*i.y,l=a*i.x,c=r*i.y;return{width:o,height:s,x:l,y:c}}function fg(t,e,n){let r;if(e==="viewport")r=nA(t,n);else if(e==="document")r=tA(rn(t));else if($t(e))r=aA(e,n);else{const a=mg(t);r={x:e.x-a.x,y:e.y-a.y,width:e.width,height:e.height}}return si(r)}function Sg(t,e){const n=On(t);return n===e||!$t(n)||dr(n)?!1:Wt(n).position==="fixed"||Sg(n,e)}function iA(t,e){const n=e.get(t);if(n)return n;let r=zr(t,[],!1).filter(s=>$t(s)&&cr(s)!=="body"),a=null;const i=Wt(t).position==="fixed";let o=i?On(t):t;for(;$t(o)&&!dr(o);){const s=Wt(o),l=gs(o);!l&&s.position==="fixed"&&(a=null),(i?!l&&!a:!l&&s.position==="static"&&!!a&&rA.has(a.position)||Vr(o)&&!l&&Sg(t,o))?r=r.filter(d=>d!==o):a=s,o=On(o)}return e.set(t,r),r}function oA(t){let{element:e,boundary:n,rootBoundary:r,strategy:a}=t;const o=[...n==="clippingAncestors"?ci(e)?[]:iA(e,this._c):[].concat(n),r],s=o[0],l=o.reduce((c,d)=>{const _=fg(e,d,a);return c.top=It(_.top,c.top),c.right=Nn(_.right,c.right),c.bottom=Nn(_.bottom,c.bottom),c.left=It(_.left,c.left),c},fg(e,s,a));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function sA(t){const{width:e,height:n}=pg(t);return{width:e,height:n}}function lA(t,e,n){const r=an(e),a=rn(e),i=n==="fixed",o=Yn(t,!0,i,e);let s={scrollLeft:0,scrollTop:0};const l=tn(0);function c(){l.x=ui(a)}if(r||!r&&!i)if((cr(e)!=="body"||Vr(a))&&(s=di(e)),r){const m=Yn(e,!0,i,e);l.x=m.x+e.clientLeft,l.y=m.y+e.clientTop}else a&&c();i&&!r&&a&&c();const d=a&&!r&&!i?gg(a,s):tn(0),_=o.left+s.scrollLeft-l.x-d.x,p=o.top+s.scrollTop-l.y-d.y;return{x:_,y:p,width:o.width,height:o.height}}function bs(t){return Wt(t).position==="static"}function bg(t,e){if(!an(t)||Wt(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return rn(t)===n&&(n=n.ownerDocument.body),n}function Tg(t,e){const n=At(t);if(ci(t))return n;if(!an(t)){let a=On(t);for(;a&&!dr(a);){if($t(a)&&!bs(a))return a;a=On(a)}return n}let r=bg(t,e);for(;r&&VI(r)&&bs(r);)r=bg(r,e);return r&&dr(r)&&bs(r)&&!gs(r)?n:r||QI(t)||n}const cA=async function(t){const e=this.getOffsetParent||Tg,n=this.getDimensions,r=await n(t.floating);return{reference:lA(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function dA(t){return Wt(t).direction==="rtl"}const uA={convertOffsetParentRelativeRectToViewportRelativeRect:JI,getDocumentElement:rn,getClippingRect:oA,getOffsetParent:Tg,getElementRects:cA,getClientRects:eA,getDimensions:sA,getScale:ur,isElement:$t,isRTL:dA};function hg(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function _A(t,e){let n=null,r;const a=rn(t);function i(){var s;clearTimeout(r),(s=n)==null||s.disconnect(),n=null}function o(s,l){s===void 0&&(s=!1),l===void 0&&(l=1),i();const c=t.getBoundingClientRect(),{left:d,top:_,width:p,height:m}=c;if(s||e(),!p||!m)return;const g=ii(_),f=ii(a.clientWidth-(d+p)),E=ii(a.clientHeight-(_+m)),S=ii(d),h={rootMargin:-g+"px "+-f+"px "+-E+"px "+-S+"px",threshold:It(0,Nn(1,l))||1};let v=!0;function R(C){const N=C[0].intersectionRatio;if(N!==l){if(!v)return o();N?o(!1,N):r=setTimeout(()=>{o(!1,1e-7)},1e3)}N===1&&!hg(c,t.getBoundingClientRect())&&o(),v=!1}try{n=new IntersectionObserver(R,{...h,root:a.ownerDocument})}catch{n=new IntersectionObserver(R,h)}n.observe(t)}return o(!0),i}function pA(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:a=!0,ancestorResize:i=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:s=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Ss(t),d=a||i?[...c?zr(c):[],...zr(e)]:[];d.forEach(S=>{a&&S.addEventListener("scroll",n,{passive:!0}),i&&S.addEventListener("resize",n)});const _=c&&s?_A(c,n):null;let p=-1,m=null;o&&(m=new ResizeObserver(S=>{let[T]=S;T&&T.target===c&&m&&(m.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var h;(h=m)==null||h.observe(e)})),n()}),c&&!l&&m.observe(c),m.observe(e));let g,f=l?Yn(t):null;l&&E();function E(){const S=Yn(t);f&&!hg(f,S)&&n(),f=S,g=requestAnimationFrame(E)}return n(),()=>{var S;d.forEach(T=>{a&&T.removeEventListener("scroll",n),i&&T.removeEventListener("resize",n)}),_==null||_(),(S=m)==null||S.disconnect(),m=null,l&&cancelAnimationFrame(g)}}const mA=FI,gA=BI,EA=PI,fA=YI,SA=kI,Rg=LI,bA=GI,TA=(t,e,n)=>{const r=new Map,a={platform:uA,...n},i={...a.platform,_c:r};return MI(t,e,{...a,platform:i})};var hA=typeof document<"u",RA=function(){},_i=hA?y.useLayoutEffect:RA;function pi(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,a;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!pi(t[r],e[r]))return!1;return!0}if(a=Object.keys(t),n=a.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,a[r]))return!1;for(r=n;r--!==0;){const i=a[r];if(!(i==="_owner"&&t.$$typeof)&&!pi(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}function Cg(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function vg(t,e){const n=Cg(t);return Math.round(e*n)/n}function Ts(t){const e=b.useRef(t);return _i(()=>{e.current=t}),e}function CA(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:a,elements:{reference:i,floating:o}={},transform:s=!0,whileElementsMounted:l,open:c}=t,[d,_]=b.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[p,m]=b.useState(r);pi(p,r)||m(r);const[g,f]=b.useState(null),[E,S]=b.useState(null),T=b.useCallback(M=>{M!==C.current&&(C.current=M,f(M))},[]),h=b.useCallback(M=>{M!==N.current&&(N.current=M,S(M))},[]),v=i||g,R=o||E,C=b.useRef(null),N=b.useRef(null),O=b.useRef(d),D=l!=null,w=Ts(l),L=Ts(a),H=Ts(c),z=b.useCallback(()=>{if(!C.current||!N.current)return;const M={placement:e,strategy:n,middleware:p};L.current&&(M.platform=L.current),TA(C.current,N.current,M).then(k=>{const Y={...k,isPositioned:H.current!==!1};P.current&&!pi(O.current,Y)&&(O.current=Y,oa.flushSync(()=>{_(Y)}))})},[p,e,n,L,H]);_i(()=>{c===!1&&O.current.isPositioned&&(O.current.isPositioned=!1,_(M=>({...M,isPositioned:!1})))},[c]);const P=b.useRef(!1);_i(()=>(P.current=!0,()=>{P.current=!1}),[]),_i(()=>{if(v&&(C.current=v),R&&(N.current=R),v&&R){if(w.current)return w.current(v,R,z);z()}},[v,R,z,w,D]);const G=b.useMemo(()=>({reference:C,floating:N,setReference:T,setFloating:h}),[T,h]),I=b.useMemo(()=>({reference:v,floating:R}),[v,R]),U=b.useMemo(()=>{const M={position:n,left:0,top:0};if(!I.floating)return M;const k=vg(I.floating,d.x),Y=vg(I.floating,d.y);return s?{...M,transform:"translate("+k+"px, "+Y+"px)",...Cg(I.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:k,top:Y}},[n,s,I.floating,d.x,d.y]);return b.useMemo(()=>({...d,update:z,refs:G,elements:I,floatingStyles:U}),[d,z,G,I,U])}const vA=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:r,padding:a}=typeof t=="function"?t(n):t;return r&&e(r)?r.current!=null?Rg({element:r.current,padding:a}).fn(n):{}:r?Rg({element:r,padding:a}).fn(n):{}}}},NA=(t,e)=>({...mA(t),options:[t,e]}),OA=(t,e)=>({...gA(t),options:[t,e]}),yA=(t,e)=>({...bA(t),options:[t,e]}),IA=(t,e)=>({...EA(t),options:[t,e]}),AA=(t,e)=>({...fA(t),options:[t,e]}),xA=(t,e)=>({...SA(t),options:[t,e]}),DA=(t,e)=>({...vA(t),options:[t,e]});var wA="Arrow",Ng=b.forwardRef((t,e)=>{const{children:n,width:r=10,height:a=5,...i}=t;return u.jsx(ye.svg,{...i,ref:e,width:r,height:a,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Ng.displayName=wA;var MA=Ng;function Og(t){const[e,n]=b.useState(void 0);return _t(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const r=new ResizeObserver(a=>{if(!Array.isArray(a)||!a.length)return;const i=a[0];let o,s;if("borderBoxSize"in i){const l=i.borderBoxSize,c=Array.isArray(l)?l[0]:l;o=c.inlineSize,s=c.blockSize}else o=t.offsetWidth,s=t.offsetHeight;n({width:o,height:s})});return r.observe(t,{box:"border-box"}),()=>r.unobserve(t)}else n(void 0)},[t]),e}var hs="Popper",[yg,_r]=qt(hs),[LA,Ig]=yg(hs),Ag=t=>{const{__scopePopper:e,children:n}=t,[r,a]=b.useState(null);return u.jsx(LA,{scope:e,anchor:r,onAnchorChange:a,children:n})};Ag.displayName=hs;var xg="PopperAnchor",Dg=b.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...a}=t,i=Ig(xg,n),o=b.useRef(null),s=ke(e,o),l=b.useRef(null);return b.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||o.current,c!==l.current&&i.onAnchorChange(l.current)}),r?null:u.jsx(ye.div,{...a,ref:s})});Dg.displayName=xg;var Rs="PopperContent",[PA,kA]=yg(Rs),wg=b.forwardRef((t,e)=>{var V,F,K,te,le,oe;const{__scopePopper:n,side:r="bottom",sideOffset:a=0,align:i="center",alignOffset:o=0,arrowPadding:s=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:_="partial",hideWhenDetached:p=!1,updatePositionStrategy:m="optimized",onPlaced:g,...f}=t,E=Ig(Rs,n),[S,T]=b.useState(null),h=ke(e,Ae=>T(Ae)),[v,R]=b.useState(null),C=Og(v),N=(C==null?void 0:C.width)??0,O=(C==null?void 0:C.height)??0,D=r+(i!=="center"?"-"+i:""),w=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(c)?c:[c],H=L.length>0,z={padding:w,boundary:L.filter(FA),altBoundary:H},{refs:P,floatingStyles:G,placement:I,isPositioned:U,middlewareData:M}=CA({strategy:"fixed",placement:D,whileElementsMounted:(...Ae)=>pA(...Ae,{animationFrame:m==="always"}),elements:{reference:E.anchor},middleware:[NA({mainAxis:a+O,alignmentAxis:o}),l&&OA({mainAxis:!0,crossAxis:!1,limiter:_==="partial"?yA():void 0,...z}),l&&IA({...z}),AA({...z,apply:({elements:Ae,rects:qe,availableWidth:Me,availableHeight:Se})=>{const{width:Be,height:ee}=qe.reference,Q=Ae.floating.style;Q.setProperty("--radix-popper-available-width",`${Me}px`),Q.setProperty("--radix-popper-available-height",`${Se}px`),Q.setProperty("--radix-popper-anchor-width",`${Be}px`),Q.setProperty("--radix-popper-anchor-height",`${ee}px`)}}),v&&DA({element:v,padding:s}),BA({arrowWidth:N,arrowHeight:O}),p&&xA({strategy:"referenceHidden",...z})]}),[k,Y]=Pg(I),W=pt(g);_t(()=>{U&&(W==null||W())},[U,W]);const re=(V=M.arrow)==null?void 0:V.x,q=(F=M.arrow)==null?void 0:F.y,X=((K=M.arrow)==null?void 0:K.centerOffset)!==0,[ce,ge]=b.useState();return _t(()=>{S&&ge(window.getComputedStyle(S).zIndex)},[S]),u.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...G,transform:U?G.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ce,"--radix-popper-transform-origin":[(te=M.transformOrigin)==null?void 0:te.x,(le=M.transformOrigin)==null?void 0:le.y].join(" "),...((oe=M.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:u.jsx(PA,{scope:n,placedSide:k,onArrowChange:R,arrowX:re,arrowY:q,shouldHideArrow:X,children:u.jsx(ye.div,{"data-side":k,"data-align":Y,...f,ref:h,style:{...f.style,animation:U?void 0:"none"}})})})});wg.displayName=Rs;var Mg="PopperArrow",UA={top:"bottom",right:"left",bottom:"top",left:"right"},Lg=b.forwardRef(function(e,n){const{__scopePopper:r,...a}=e,i=kA(Mg,r),o=UA[i.placedSide];return u.jsx("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:u.jsx(MA,{...a,ref:n,style:{...a.style,display:"block"}})})});Lg.displayName=Mg;function FA(t){return t!==null}var BA=t=>({name:"transformOrigin",options:t,fn(e){var E,S,T;const{placement:n,rects:r,middlewareData:a}=e,o=((E=a.arrow)==null?void 0:E.centerOffset)!==0,s=o?0:t.arrowWidth,l=o?0:t.arrowHeight,[c,d]=Pg(n),_={start:"0%",center:"50%",end:"100%"}[d],p=(((S=a.arrow)==null?void 0:S.x)??0)+s/2,m=(((T=a.arrow)==null?void 0:T.y)??0)+l/2;let g="",f="";return c==="bottom"?(g=o?_:`${p}px`,f=`${-l}px`):c==="top"?(g=o?_:`${p}px`,f=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,f=o?_:`${m}px`):c==="left"&&(g=`${r.floating.width+l}px`,f=o?_:`${m}px`),{data:{x:g,y:f}}}});function Pg(t){const[e,n="center"]=t.split("-");return[e,n]}var Cs=Ag,vs=Dg,Ns=wg,Os=Lg,ys="rovingFocusGroup.onEntryFocus",GA={bubbles:!1,cancelable:!0},$r="RovingFocusGroup",[Is,kg,YA]=cs($r),[HA,Ug]=qt($r,[YA]),[qA,VA]=HA($r),Fg=b.forwardRef((t,e)=>u.jsx(Is.Provider,{scope:t.__scopeRovingFocusGroup,children:u.jsx(Is.Slot,{scope:t.__scopeRovingFocusGroup,children:u.jsx(zA,{...t,ref:e})})}));Fg.displayName=$r;var zA=b.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:a=!1,dir:i,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,..._}=t,p=b.useRef(null),m=ke(e,p),g=ri(i),[f,E]=Rn({prop:o,defaultProp:s??null,onChange:l,caller:$r}),[S,T]=b.useState(!1),h=pt(c),v=kg(n),R=b.useRef(!1),[C,N]=b.useState(0);return b.useEffect(()=>{const O=p.current;if(O)return O.addEventListener(ys,h),()=>O.removeEventListener(ys,h)},[h]),u.jsx(qA,{scope:n,orientation:r,dir:g,loop:a,currentTabStopId:f,onItemFocus:b.useCallback(O=>E(O),[E]),onItemShiftTab:b.useCallback(()=>T(!0),[]),onFocusableItemAdd:b.useCallback(()=>N(O=>O+1),[]),onFocusableItemRemove:b.useCallback(()=>N(O=>O-1),[]),children:u.jsx(ye.div,{tabIndex:S||C===0?-1:0,"data-orientation":r,..._,ref:m,style:{outline:"none",...t.style},onMouseDown:de(t.onMouseDown,()=>{R.current=!0}),onFocus:de(t.onFocus,O=>{const D=!R.current;if(O.target===O.currentTarget&&D&&!S){const w=new CustomEvent(ys,GA);if(O.currentTarget.dispatchEvent(w),!w.defaultPrevented){const L=v().filter(I=>I.focusable),H=L.find(I=>I.active),z=L.find(I=>I.id===f),G=[H,z,...L].filter(Boolean).map(I=>I.ref.current);Yg(G,d)}}R.current=!1}),onBlur:de(t.onBlur,()=>T(!1))})})}),Bg="RovingFocusGroupItem",Gg=b.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:a=!1,tabStopId:i,children:o,...s}=t,l=Vt(),c=i||l,d=VA(Bg,n),_=d.currentTabStopId===c,p=kg(n),{onFocusableItemAdd:m,onFocusableItemRemove:g,currentTabStopId:f}=d;return b.useEffect(()=>{if(r)return m(),()=>g()},[r,m,g]),u.jsx(Is.ItemSlot,{scope:n,id:c,focusable:r,active:a,children:u.jsx(ye.span,{tabIndex:_?0:-1,"data-orientation":d.orientation,...s,ref:e,onMouseDown:de(t.onMouseDown,E=>{r?d.onItemFocus(c):E.preventDefault()}),onFocus:de(t.onFocus,()=>d.onItemFocus(c)),onKeyDown:de(t.onKeyDown,E=>{if(E.key==="Tab"&&E.shiftKey){d.onItemShiftTab();return}if(E.target!==E.currentTarget)return;const S=KA(E,d.orientation,d.dir);if(S!==void 0){if(E.metaKey||E.ctrlKey||E.altKey||E.shiftKey)return;E.preventDefault();let h=p().filter(v=>v.focusable).map(v=>v.ref.current);if(S==="last")h.reverse();else if(S==="prev"||S==="next"){S==="prev"&&h.reverse();const v=h.indexOf(E.currentTarget);h=d.loop?QA(h,v+1):h.slice(v+1)}setTimeout(()=>Yg(h))}}),children:typeof o=="function"?o({isCurrentTabStop:_,hasTabStop:f!=null}):o})})});Gg.displayName=Bg;var $A={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function WA(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function KA(t,e,n){const r=WA(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return $A[r]}function Yg(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}function QA(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var jA=Fg,XA=Gg,As=["Enter"," "],ZA=["ArrowDown","PageUp","Home"],Hg=["ArrowUp","PageDown","End"],JA=[...ZA,...Hg],ex={ltr:[...As,"ArrowRight"],rtl:[...As,"ArrowLeft"]},tx={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Wr="Menu",[Kr,nx,rx]=cs(Wr),[Hn,qg]=qt(Wr,[rx,_r,Ug]),mi=_r(),Vg=Ug(),[ax,qn]=Hn(Wr),[ix,Qr]=Hn(Wr),zg=t=>{const{__scopeMenu:e,open:n=!1,children:r,dir:a,onOpenChange:i,modal:o=!0}=t,s=mi(e),[l,c]=b.useState(null),d=b.useRef(!1),_=pt(i),p=ri(a);return b.useEffect(()=>{const m=()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>d.current=!1;return document.addEventListener("keydown",m,{capture:!0}),()=>{document.removeEventListener("keydown",m,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.jsx(Cs,{...s,children:u.jsx(ax,{scope:e,open:n,onOpenChange:_,content:l,onContentChange:c,children:u.jsx(ix,{scope:e,onClose:b.useCallback(()=>_(!1),[_]),isUsingKeyboardRef:d,dir:p,modal:o,children:r})})})};zg.displayName=Wr;var ox="MenuAnchor",xs=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,a=mi(n);return u.jsx(vs,{...a,...r,ref:e})});xs.displayName=ox;var Ds="MenuPortal",[sx,$g]=Hn(Ds,{forceMount:void 0}),Wg=t=>{const{__scopeMenu:e,forceMount:n,children:r,container:a}=t,i=qn(Ds,e);return u.jsx(sx,{scope:e,forceMount:n,children:u.jsx(vt,{present:n||i.open,children:u.jsx(Ga,{asChild:!0,container:a,children:r})})})};Wg.displayName=Ds;var Ut="MenuContent",[lx,ws]=Hn(Ut),Kg=b.forwardRef((t,e)=>{const n=$g(Ut,t.__scopeMenu),{forceMount:r=n.forceMount,...a}=t,i=qn(Ut,t.__scopeMenu),o=Qr(Ut,t.__scopeMenu);return u.jsx(Kr.Provider,{scope:t.__scopeMenu,children:u.jsx(vt,{present:r||i.open,children:u.jsx(Kr.Slot,{scope:t.__scopeMenu,children:o.modal?u.jsx(cx,{...a,ref:e}):u.jsx(dx,{...a,ref:e})})})})}),cx=b.forwardRef((t,e)=>{const n=qn(Ut,t.__scopeMenu),r=b.useRef(null),a=ke(e,r);return b.useEffect(()=>{const i=r.current;if(i)return as(i)},[]),u.jsx(Ms,{...t,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(t.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),dx=b.forwardRef((t,e)=>{const n=qn(Ut,t.__scopeMenu);return u.jsx(Ms,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ux=Nt.createSlot("MenuContent.ScrollLock"),Ms=b.forwardRef((t,e)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:a,onOpenAutoFocus:i,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:_,onInteractOutside:p,onDismiss:m,disableOutsideScroll:g,...f}=t,E=qn(Ut,n),S=Qr(Ut,n),T=mi(n),h=Vg(n),v=nx(n),[R,C]=b.useState(null),N=b.useRef(null),O=ke(e,N,E.onContentChange),D=b.useRef(0),w=b.useRef(""),L=b.useRef(0),H=b.useRef(null),z=b.useRef("right"),P=b.useRef(0),G=g?$a:b.Fragment,I=g?{as:ux,allowPinchZoom:!0}:void 0,U=k=>{var V,F;const Y=w.current+k,W=v().filter(K=>!K.disabled),re=document.activeElement,q=(V=W.find(K=>K.ref.current===re))==null?void 0:V.textValue,X=W.map(K=>K.textValue),ce=Cx(X,Y,q),ge=(F=W.find(K=>K.textValue===ce))==null?void 0:F.ref.current;(function K(te){w.current=te,window.clearTimeout(D.current),te!==""&&(D.current=window.setTimeout(()=>K(""),1e3))})(Y),ge&&setTimeout(()=>ge.focus())};b.useEffect(()=>()=>window.clearTimeout(D.current),[]),Zo();const M=b.useCallback(k=>{var W,re;return z.current===((W=H.current)==null?void 0:W.side)&&Nx(k,(re=H.current)==null?void 0:re.area)},[]);return u.jsx(lx,{scope:n,searchRef:w,onItemEnter:b.useCallback(k=>{M(k)&&k.preventDefault()},[M]),onItemLeave:b.useCallback(k=>{var Y;M(k)||((Y=N.current)==null||Y.focus(),C(null))},[M]),onTriggerLeave:b.useCallback(k=>{M(k)&&k.preventDefault()},[M]),pointerGraceTimerRef:L,onPointerGraceIntentChange:b.useCallback(k=>{H.current=k},[]),children:u.jsx(G,{...I,children:u.jsx(Ba,{asChild:!0,trapped:a,onMountAutoFocus:de(i,k=>{var Y;k.preventDefault(),(Y=N.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:u.jsx(Yr,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:_,onInteractOutside:p,onDismiss:m,children:u.jsx(jA,{asChild:!0,...h,dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:R,onCurrentTabStopIdChange:C,onEntryFocus:de(l,k=>{S.isUsingKeyboardRef.current||k.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(Ns,{role:"menu","aria-orientation":"vertical","data-state":uE(E.open),"data-radix-menu-content":"",dir:S.dir,...T,...f,ref:O,style:{outline:"none",...f.style},onKeyDown:de(f.onKeyDown,k=>{const W=k.target.closest("[data-radix-menu-content]")===k.currentTarget,re=k.ctrlKey||k.altKey||k.metaKey,q=k.key.length===1;W&&(k.key==="Tab"&&k.preventDefault(),!re&&q&&U(k.key));const X=N.current;if(k.target!==X||!JA.includes(k.key))return;k.preventDefault();const ge=v().filter(V=>!V.disabled).map(V=>V.ref.current);Hg.includes(k.key)&&ge.reverse(),hx(ge)}),onBlur:de(t.onBlur,k=>{k.currentTarget.contains(k.target)||(window.clearTimeout(D.current),w.current="")}),onPointerMove:de(t.onPointerMove,Xr(k=>{const Y=k.target,W=P.current!==k.clientX;if(k.currentTarget.contains(Y)&&W){const re=k.clientX>P.current?"right":"left";z.current=re,P.current=k.clientX}}))})})})})})})});Kg.displayName=Ut;var _x="MenuGroup",Ls=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return u.jsx(ye.div,{role:"group",...r,ref:e})});Ls.displayName=_x;var px="MenuLabel",Qg=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return u.jsx(ye.div,{...r,ref:e})});Qg.displayName=px;var gi="MenuItem",jg="menu.itemSelect",Ei=b.forwardRef((t,e)=>{const{disabled:n=!1,onSelect:r,...a}=t,i=b.useRef(null),o=Qr(gi,t.__scopeMenu),s=ws(gi,t.__scopeMenu),l=ke(e,i),c=b.useRef(!1),d=()=>{const _=i.current;if(!n&&_){const p=new CustomEvent(jg,{bubbles:!0,cancelable:!0});_.addEventListener(jg,m=>r==null?void 0:r(m),{once:!0}),Wp(_,p),p.defaultPrevented?c.current=!1:o.onClose()}};return u.jsx(Xg,{...a,ref:l,disabled:n,onClick:de(t.onClick,d),onPointerDown:_=>{var p;(p=t.onPointerDown)==null||p.call(t,_),c.current=!0},onPointerUp:de(t.onPointerUp,_=>{var p;c.current||(p=_.currentTarget)==null||p.click()}),onKeyDown:de(t.onKeyDown,_=>{const p=s.searchRef.current!=="";n||p&&_.key===" "||As.includes(_.key)&&(_.currentTarget.click(),_.preventDefault())})})});Ei.displayName=gi;var Xg=b.forwardRef((t,e)=>{const{__scopeMenu:n,disabled:r=!1,textValue:a,...i}=t,o=ws(gi,n),s=Vg(n),l=b.useRef(null),c=ke(e,l),[d,_]=b.useState(!1),[p,m]=b.useState("");return b.useEffect(()=>{const g=l.current;g&&m((g.textContent??"").trim())},[i.children]),u.jsx(Kr.ItemSlot,{scope:n,disabled:r,textValue:a??p,children:u.jsx(XA,{asChild:!0,...s,focusable:!r,children:u.jsx(ye.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...i,ref:c,onPointerMove:de(t.onPointerMove,Xr(g=>{r?o.onItemLeave(g):(o.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(t.onPointerLeave,Xr(g=>o.onItemLeave(g))),onFocus:de(t.onFocus,()=>_(!0)),onBlur:de(t.onBlur,()=>_(!1))})})})}),mx="MenuCheckboxItem",Zg=b.forwardRef((t,e)=>{const{checked:n=!1,onCheckedChange:r,...a}=t;return u.jsx(rE,{scope:t.__scopeMenu,checked:n,children:u.jsx(Ei,{role:"menuitemcheckbox","aria-checked":fi(n)?"mixed":n,...a,ref:e,"data-state":ks(n),onSelect:de(a.onSelect,()=>r==null?void 0:r(fi(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Zg.displayName=mx;var Jg="MenuRadioGroup",[gx,Ex]=Hn(Jg,{value:void 0,onValueChange:()=>{}}),eE=b.forwardRef((t,e)=>{const{value:n,onValueChange:r,...a}=t,i=pt(r);return u.jsx(gx,{scope:t.__scopeMenu,value:n,onValueChange:i,children:u.jsx(Ls,{...a,ref:e})})});eE.displayName=Jg;var tE="MenuRadioItem",nE=b.forwardRef((t,e)=>{const{value:n,...r}=t,a=Ex(tE,t.__scopeMenu),i=n===a.value;return u.jsx(rE,{scope:t.__scopeMenu,checked:i,children:u.jsx(Ei,{role:"menuitemradio","aria-checked":i,...r,ref:e,"data-state":ks(i),onSelect:de(r.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,n)},{checkForDefaultPrevented:!1})})})});nE.displayName=tE;var Ps="MenuItemIndicator",[rE,fx]=Hn(Ps,{checked:!1}),aE=b.forwardRef((t,e)=>{const{__scopeMenu:n,forceMount:r,...a}=t,i=fx(Ps,n);return u.jsx(vt,{present:r||fi(i.checked)||i.checked===!0,children:u.jsx(ye.span,{...a,ref:e,"data-state":ks(i.checked)})})});aE.displayName=Ps;var Sx="MenuSeparator",iE=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return u.jsx(ye.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});iE.displayName=Sx;var bx="MenuArrow",oE=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,a=mi(n);return u.jsx(Os,{...a,...r,ref:e})});oE.displayName=bx;var Tx="MenuSub",[Z0,sE]=Hn(Tx),jr="MenuSubTrigger",lE=b.forwardRef((t,e)=>{const n=qn(jr,t.__scopeMenu),r=Qr(jr,t.__scopeMenu),a=sE(jr,t.__scopeMenu),i=ws(jr,t.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:s,onPointerGraceIntentChange:l}=i,c={__scopeMenu:t.__scopeMenu},d=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>d,[d]),b.useEffect(()=>{const _=s.current;return()=>{window.clearTimeout(_),l(null)}},[s,l]),u.jsx(xs,{asChild:!0,...c,children:u.jsx(Xg,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":a.contentId,"data-state":uE(n.open),...t,ref:ko(e,a.onTriggerChange),onClick:_=>{var p;(p=t.onClick)==null||p.call(t,_),!(t.disabled||_.defaultPrevented)&&(_.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:de(t.onPointerMove,Xr(_=>{i.onItemEnter(_),!_.defaultPrevented&&!t.disabled&&!n.open&&!o.current&&(i.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:de(t.onPointerLeave,Xr(_=>{var m,g;d();const p=(m=n.content)==null?void 0:m.getBoundingClientRect();if(p){const f=(g=n.content)==null?void 0:g.dataset.side,E=f==="right",S=E?-5:5,T=p[E?"left":"right"],h=p[E?"right":"left"];i.onPointerGraceIntentChange({area:[{x:_.clientX+S,y:_.clientY},{x:T,y:p.top},{x:h,y:p.top},{x:h,y:p.bottom},{x:T,y:p.bottom}],side:f}),window.clearTimeout(s.current),s.current=window.setTimeout(()=>i.onPointerGraceIntentChange(null),300)}else{if(i.onTriggerLeave(_),_.defaultPrevented)return;i.onPointerGraceIntentChange(null)}})),onKeyDown:de(t.onKeyDown,_=>{var m;const p=i.searchRef.current!=="";t.disabled||p&&_.key===" "||ex[r.dir].includes(_.key)&&(n.onOpenChange(!0),(m=n.content)==null||m.focus(),_.preventDefault())})})})});lE.displayName=jr;var cE="MenuSubContent",dE=b.forwardRef((t,e)=>{const n=$g(Ut,t.__scopeMenu),{forceMount:r=n.forceMount,...a}=t,i=qn(Ut,t.__scopeMenu),o=Qr(Ut,t.__scopeMenu),s=sE(cE,t.__scopeMenu),l=b.useRef(null),c=ke(e,l);return u.jsx(Kr.Provider,{scope:t.__scopeMenu,children:u.jsx(vt,{present:r||i.open,children:u.jsx(Kr.Slot,{scope:t.__scopeMenu,children:u.jsx(Ms,{id:s.contentId,"aria-labelledby":s.triggerId,...a,ref:c,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var _;o.isUsingKeyboardRef.current&&((_=l.current)==null||_.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:de(t.onFocusOutside,d=>{d.target!==s.trigger&&i.onOpenChange(!1)}),onEscapeKeyDown:de(t.onEscapeKeyDown,d=>{o.onClose(),d.preventDefault()}),onKeyDown:de(t.onKeyDown,d=>{var m;const _=d.currentTarget.contains(d.target),p=tx[o.dir].includes(d.key);_&&p&&(i.onOpenChange(!1),(m=s.trigger)==null||m.focus(),d.preventDefault())})})})})})});dE.displayName=cE;function uE(t){return t?"open":"closed"}function fi(t){return t==="indeterminate"}function ks(t){return fi(t)?"indeterminate":t?"checked":"unchecked"}function hx(t){const e=document.activeElement;for(const n of t)if(n===e||(n.focus(),document.activeElement!==e))return}function Rx(t,e){return t.map((n,r)=>t[(e+r)%t.length])}function Cx(t,e,n){const a=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,i=n?t.indexOf(n):-1;let o=Rx(t,Math.max(i,0));a.length===1&&(o=o.filter(c=>c!==n));const l=o.find(c=>c.toLowerCase().startsWith(a.toLowerCase()));return l!==n?l:void 0}function vx(t,e){const{x:n,y:r}=t;let a=!1;for(let i=0,o=e.length-1;i<e.length;o=i++){const s=e[i],l=e[o],c=s.x,d=s.y,_=l.x,p=l.y;d>r!=p>r&&n<(_-c)*(r-d)/(p-d)+c&&(a=!a)}return a}function Nx(t,e){if(!e)return!1;const n={x:t.clientX,y:t.clientY};return vx(n,e)}function Xr(t){return e=>e.pointerType==="mouse"?t(e):void 0}var Ox=zg,yx=xs,Ix=Wg,Ax=Kg,xx=Ls,Dx=Qg,wx=Ei,Mx=Zg,Lx=eE,Px=nE,kx=aE,Ux=iE,Fx=oE,Bx=lE,Gx=dE,Si="DropdownMenu",[Yx,J0]=qt(Si,[qg]),Tt=qg(),[Hx,_E]=Yx(Si),pE=t=>{const{__scopeDropdownMenu:e,children:n,dir:r,open:a,defaultOpen:i,onOpenChange:o,modal:s=!0}=t,l=Tt(e),c=b.useRef(null),[d,_]=Rn({prop:a,defaultProp:i??!1,onChange:o,caller:Si});return u.jsx(Hx,{scope:e,triggerId:Vt(),triggerRef:c,contentId:Vt(),open:d,onOpenChange:_,onOpenToggle:b.useCallback(()=>_(p=>!p),[_]),modal:s,children:u.jsx(Ox,{...l,open:d,onOpenChange:_,dir:r,modal:s,children:n})})};pE.displayName=Si;var mE="DropdownMenuTrigger",gE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...a}=t,i=_E(mE,n),o=Tt(n);return u.jsx(yx,{asChild:!0,...o,children:u.jsx(ye.button,{type:"button",id:i.triggerId,"aria-haspopup":"menu","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":i.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...a,ref:ko(e,i.triggerRef),onPointerDown:de(t.onPointerDown,s=>{!r&&s.button===0&&s.ctrlKey===!1&&(i.onOpenToggle(),i.open||s.preventDefault())}),onKeyDown:de(t.onKeyDown,s=>{r||(["Enter"," "].includes(s.key)&&i.onOpenToggle(),s.key==="ArrowDown"&&i.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(s.key)&&s.preventDefault())})})})});gE.displayName=mE;var qx="DropdownMenuPortal",EE=t=>{const{__scopeDropdownMenu:e,...n}=t,r=Tt(e);return u.jsx(Ix,{...r,...n})};EE.displayName=qx;var fE="DropdownMenuContent",SE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=_E(fE,n),i=Tt(n),o=b.useRef(!1);return u.jsx(Ax,{id:a.contentId,"aria-labelledby":a.triggerId,...i,...r,ref:e,onCloseAutoFocus:de(t.onCloseAutoFocus,s=>{var l;o.current||(l=a.triggerRef.current)==null||l.focus(),o.current=!1,s.preventDefault()}),onInteractOutside:de(t.onInteractOutside,s=>{const l=s.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!a.modal||d)&&(o.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});SE.displayName=fE;var Vx="DropdownMenuGroup",zx=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(xx,{...a,...r,ref:e})});zx.displayName=Vx;var $x="DropdownMenuLabel",bE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Dx,{...a,...r,ref:e})});bE.displayName=$x;var Wx="DropdownMenuItem",TE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(wx,{...a,...r,ref:e})});TE.displayName=Wx;var Kx="DropdownMenuCheckboxItem",hE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Mx,{...a,...r,ref:e})});hE.displayName=Kx;var Qx="DropdownMenuRadioGroup",jx=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Lx,{...a,...r,ref:e})});jx.displayName=Qx;var Xx="DropdownMenuRadioItem",RE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Px,{...a,...r,ref:e})});RE.displayName=Xx;var Zx="DropdownMenuItemIndicator",CE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(kx,{...a,...r,ref:e})});CE.displayName=Zx;var Jx="DropdownMenuSeparator",vE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Ux,{...a,...r,ref:e})});vE.displayName=Jx;var eD="DropdownMenuArrow",tD=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Fx,{...a,...r,ref:e})});tD.displayName=eD;var nD="DropdownMenuSubTrigger",NE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Bx,{...a,...r,ref:e})});NE.displayName=nD;var rD="DropdownMenuSubContent",OE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Gx,{...a,...r,ref:e,style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});OE.displayName=rD;var aD=pE,iD=gE,oD=EE,yE=SE,IE=bE,AE=TE,xE=hE,DE=RE,wE=CE,ME=vE,LE=NE,PE=OE;const sD=aD,lD=iD,cD=b.forwardRef(({className:t,inset:e,children:n,...r},a)=>u.jsxs(LE,{ref:a,className:$("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",e&&"pl-8",t),...r,children:[n,u.jsx(pe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));cD.displayName=LE.displayName;const dD=b.forwardRef(({className:t,...e},n)=>u.jsx(PE,{ref:n,className:$("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...e}));dD.displayName=PE.displayName;const kE=b.forwardRef(({className:t,sideOffset:e=4,...n},r)=>u.jsx(oD,{children:u.jsx(yE,{ref:r,sideOffset:e,className:$("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...n})}));kE.displayName=yE.displayName;const Us=b.forwardRef(({className:t,inset:e,...n},r)=>u.jsx(AE,{ref:r,className:$("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e&&"pl-8",t),...n}));Us.displayName=AE.displayName;const uD=b.forwardRef(({className:t,children:e,checked:n,...r},a)=>u.jsxs(xE,{ref:a,className:$("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wE,{children:u.jsx(pe.Check,{className:"h-4 w-4"})})}),e]}));uD.displayName=xE.displayName;const _D=b.forwardRef(({className:t,children:e,...n},r)=>u.jsxs(DE,{ref:r,className:$("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wE,{children:u.jsx(pe.Circle,{className:"h-2 w-2 fill-current"})})}),e]}));_D.displayName=DE.displayName;const pD=b.forwardRef(({className:t,inset:e,...n},r)=>u.jsx(IE,{ref:r,className:$("px-2 py-1.5 text-sm font-semibold",e&&"pl-8",t),...n}));pD.displayName=IE.displayName;const mD=b.forwardRef(({className:t,...e},n)=>u.jsx(ME,{ref:n,className:$("-mx-1 my-1 h-px bg-muted",t),...e}));mD.displayName=ME.displayName;function Zr({className:t="",placeholder:e="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:a=120,enableFileUpload:i=!0,enableExcelUpload:o=!1,enableMessageEditing:s=!0,customStyles:l={},onMessageSent:c,onExcelUploadSuccess:d,onError:_}){const{currentThreadId:p,messages:m,isStreaming:g,streamingAssistantId:f,error:E,send:S,stop:T,lastCheckpointId:h,listCheckpoints:v,navigateToCheckpoint:R,returnToLatest:C,hasMoreHistory:N,isLoadingHistory:O,loadOlderMessages:D,api:w}=ba(),[L,H]=y.useState(null),[z,P]=y.useState(""),[G,I]=y.useState(null),[U,M]=y.useState([]),[k,Y]=y.useState(!1),[W,re]=y.useState(null),[q,X]=y.useState(null),[ce,ge]=y.useState(!1),[V,F]=y.useState(null),[K,te]=y.useState([]),[le,oe]=y.useState(null),Ae=y.useRef(null),qe=y.useRef(null),Me=y.useRef(null),[Se,Be]=y.useState("desktop");y.useEffect(()=>{const ie=()=>{const Te=window.innerWidth;Be(Te<640?"phone":Te<1024?"tablet":"desktop")};return ie(),window.addEventListener("resize",ie),()=>window.removeEventListener("resize",ie)},[]),y.useEffect(()=>{let ie=!1;if(!p){te([]),oe(null),Me.current=null;return}const Te={threadId:p,checkpointId:h??null},ze=Me.current;if(!(ze&&ze.threadId===Te.threadId&&ze.checkpointId===Te.checkpointId))return v(p).then(it=>{if(ie)return;const gn=((it==null?void 0:it.checkpoints)??[]).slice().sort((En,Pe)=>new Date(Pe.createdAt).getTime()-new Date(En.createdAt).getTime());te(gn),oe(En=>{var Pe;return En??((Pe=gn[0])==null?void 0:Pe.checkpointId)??null}),Me.current=Te}).catch(it=>{console.error("ChatInterface - listCheckpoints error:",it),ie||(te([]),Me.current=null)}),()=>{ie=!0}},[p,h,v]),y.useEffect(()=>{h&&oe(h)},[h]);const ee=y.useCallback(async()=>{if(!(!N||O))try{await D()}catch(ie){console.warn("loadOlderMessages failed",ie)}},[N,O,D]);y.useEffect(()=>{(async()=>{try{const Te=await w.getAgent("default");F(Te.uiDefaultMessage||null)}catch(Te){console.warn("Failed to fetch default message:",Te),F(null)}})()},[w]),y.useEffect(()=>{E&&!ce&&(_==null||_(E))},[E,ce,_]);const Q=ie=>{if(ie.length>ni)return`Message too long (${ie.length}/${ni} characters)`;try{return TI(ie),null}catch(Te){return(Te==null?void 0:Te.message)||"Invalid message"}},ae=ie=>{const Te=ie.content||[],ze=Te.filter(it=>it.type==="text").map(it=>it.text).join("");if(ze)return ze;try{return JSON.stringify(Te,null,2)}catch{return String(Te)}},be=async ie=>{const Te=ie.trim();if(!(!Te&&U.length===0)){if(Te){const ze=Q(Te);if(ze){I(ze);return}}try{await S(Te,{checkpointId:le||h||void 0,payloadExtras:L?{edit:!0,originalMessageId:L}:void 0,attachments:U}),c==null||c(Te),I(null),M([]),H(null),P("")}catch(ze){const it=(ze==null?void 0:ze.message)||"Failed to send message";I(it),_==null||_(it)}}},Je=y.useCallback((ie,Te)=>{s&&(H(ie),P(Te),I(null))},[s]),Qe=y.useCallback(()=>{H(null),P(""),I(null)},[]),at=y.useCallback((ie,Te)=>{Je(ie,Te)},[Je]),Ke=y.useCallback(ie=>{for(let Te=ie-1;Te>=0;Te--)if(m[Te].role==="user"){const ze=ae(m[Te]);ze&&S(ze,{checkpointId:le||h||void 0});break}},[m,S,le,h,ae]),Z=ie=>{const Te=Array.from(ie.target.files||[]);M(ze=>[...ze,...Te])},se=ie=>M(Te=>Te.filter((ze,it)=>ie!==it)),Ee=async ie=>{const Te=(ie.target.files||[])[0];if(Te){re(null),X(null),Y(!0);try{await S("",{checkpointId:le||h||void 0,attachments:[Te]});const ze=`Uploaded ${Te.name} - processing through chat stream`;X(ze)}catch(ze){const it=ze instanceof Error?ze.message:"Failed to upload Excel file";console.error("Excel upload failed",ze),re(it),_==null||_(it)}finally{Y(!1),ie.target.value=""}}},he=ie=>{if(!ie)return"Unknown";const Te=Date.parse(ie);return Number.isNaN(Te)?ie:new Date(Te).toLocaleString()},Ue=async ie=>{if(p){if(!ie){await C(),oe(null);return}await R(ie),oe(ie)}},rt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${t} ${l.container||""}`,xt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-y-auto overflow-x-auto overscroll-contain break-words break-anywhere p-4 bg-transparent ${l.messagesArea||""}`,Qt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${l.inputArea||""}`;return u.jsxs("div",{className:rt,children:[!!E&&!ce&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:E}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>ge(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(pe.X,{size:16})})]}),p&&K.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:le??"",onChange:ie=>{const Te=ie.target.value||null;Ue(Te)},children:[u.jsx("option",{value:"",children:"Latest"}),K.map(ie=>u.jsxs("option",{value:ie.checkpointId,children:[he(ie.createdAt),ie.preview?` — ${ie.preview.slice(0,40)}`:""]},ie.checkpointId))]})]}),u.jsx(ng,{className:xt,style:r?{maxHeight:r}:void 0,messages:m,isStreaming:g,streamingAssistantId:f,streamingDebounceMs:a,layoutSize:Se,enableMessageEditing:s,editingMessageId:L,onStartReached:()=>{ee()},onEdit:at,onRegenerate:Ke,onCancelEdit:Qe,emptyMessage:V??void 0}),u.jsxs("div",{className:Qt,children:[L&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(pe.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:Qe,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(pe.X,{size:16})})]})}),(i||o)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[i&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Ae,type:"file",multiple:!0,onChange:ie=>Z(ie),className:"hidden"}),U.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:U.map((ie,Te)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(pe.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:ie.name}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>se(Te),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${ie.name}`,children:u.jsx(pe.X,{size:12})})]},Te))})]}),o&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:qe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Ee,className:"hidden"}),k&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(pe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),q&&!k&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:q}),W&&!k&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:W})]})]}),G&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:G}),u.jsxs("div",{className:"flex items-end gap-2",children:[(i||o)&&u.jsxs(sD,{children:[u.jsx(lD,{asChild:!0,children:u.jsx(Ve,{type:"button",size:"icon",variant:"outline",disabled:g,title:"More input actions",className:l.moreButton||"",children:u.jsx(pe.Plus,{size:16})})}),u.jsxs(kE,{align:"start",sideOffset:6,className:"w-52",children:[i&&u.jsxs(Us,{onClick:()=>{var ie;return(ie=Ae.current)==null?void 0:ie.click()},className:"cursor-pointer",children:[u.jsx(pe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),o&&u.jsxs(Us,{onClick:()=>{var ie;k||(ie=qe.current)==null||ie.click()},className:`cursor-pointer ${k?"opacity-60 pointer-events-none":""}`,children:[u.jsx(pe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(qv,{initialValue:z,editingMessageId:L,placeholder:L?"Edit your message...":e,isStreaming:g,disabled:!1,maxLength:ni,onSend:be,onCancelEdit:Qe,onStop:T,allowEmptySend:U.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${L?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${G?"border-red-400":""} ${l.textarea||""}`})})]})]})]})}const Jr=b.forwardRef(({className:t,type:e,...n},r)=>u.jsx("input",{type:e,className:$("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",t),ref:r,...n}));Jr.displayName="Input";function Fs(t,[e,n]){return Math.min(n,Math.max(e,t))}function gD(t,e){return b.useReducer((n,r)=>e[n][r]??n,t)}var Bs="ScrollArea",[UE,eF]=qt(Bs),[ED,Ft]=UE(Bs),FE=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,type:r="hover",dir:a,scrollHideDelay:i=600,...o}=t,[s,l]=b.useState(null),[c,d]=b.useState(null),[_,p]=b.useState(null),[m,g]=b.useState(null),[f,E]=b.useState(null),[S,T]=b.useState(0),[h,v]=b.useState(0),[R,C]=b.useState(!1),[N,O]=b.useState(!1),D=ke(e,L=>l(L)),w=ri(a);return u.jsx(ED,{scope:n,type:r,dir:w,scrollHideDelay:i,scrollArea:s,viewport:c,onViewportChange:d,content:_,onContentChange:p,scrollbarX:m,onScrollbarXChange:g,scrollbarXEnabled:R,onScrollbarXEnabledChange:C,scrollbarY:f,onScrollbarYChange:E,scrollbarYEnabled:N,onScrollbarYEnabledChange:O,onCornerWidthChange:T,onCornerHeightChange:v,children:u.jsx(ye.div,{dir:w,...o,ref:D,style:{position:"relative","--radix-scroll-area-corner-width":S+"px","--radix-scroll-area-corner-height":h+"px",...t.style}})})});FE.displayName=Bs;var BE="ScrollAreaViewport",GE=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,children:r,nonce:a,...i}=t,o=Ft(BE,n),s=b.useRef(null),l=ke(e,s,o.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:a}),u.jsx(ye.div,{"data-radix-scroll-area-viewport":"",...i,ref:l,style:{overflowX:o.scrollbarXEnabled?"scroll":"hidden",overflowY:o.scrollbarYEnabled?"scroll":"hidden",...t.style},children:u.jsx("div",{ref:o.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});GE.displayName=BE;var on="ScrollAreaScrollbar",Gs=b.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=Ft(on,t.__scopeScrollArea),{onScrollbarXEnabledChange:i,onScrollbarYEnabledChange:o}=a,s=t.orientation==="horizontal";return b.useEffect(()=>(s?i(!0):o(!0),()=>{s?i(!1):o(!1)}),[s,i,o]),a.type==="hover"?u.jsx(fD,{...r,ref:e,forceMount:n}):a.type==="scroll"?u.jsx(SD,{...r,ref:e,forceMount:n}):a.type==="auto"?u.jsx(YE,{...r,ref:e,forceMount:n}):a.type==="always"?u.jsx(Ys,{...r,ref:e}):null});Gs.displayName=on;var fD=b.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=Ft(on,t.__scopeScrollArea),[i,o]=b.useState(!1);return b.useEffect(()=>{const s=a.scrollArea;let l=0;if(s){const c=()=>{window.clearTimeout(l),o(!0)},d=()=>{l=window.setTimeout(()=>o(!1),a.scrollHideDelay)};return s.addEventListener("pointerenter",c),s.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),s.removeEventListener("pointerenter",c),s.removeEventListener("pointerleave",d)}}},[a.scrollArea,a.scrollHideDelay]),u.jsx(vt,{present:n||i,children:u.jsx(YE,{"data-state":i?"visible":"hidden",...r,ref:e})})}),SD=b.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=Ft(on,t.__scopeScrollArea),i=t.orientation==="horizontal",o=Ri(()=>l("SCROLL_END"),100),[s,l]=gD("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 b.useEffect(()=>{if(s==="idle"){const c=window.setTimeout(()=>l("HIDE"),a.scrollHideDelay);return()=>window.clearTimeout(c)}},[s,a.scrollHideDelay,l]),b.useEffect(()=>{const c=a.viewport,d=i?"scrollLeft":"scrollTop";if(c){let _=c[d];const p=()=>{const m=c[d];_!==m&&(l("SCROLL"),o()),_=m};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[a.viewport,i,l,o]),u.jsx(vt,{present:n||s!=="hidden",children:u.jsx(Ys,{"data-state":s==="hidden"?"hidden":"visible",...r,ref:e,onPointerEnter:de(t.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(t.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),YE=b.forwardRef((t,e)=>{const n=Ft(on,t.__scopeScrollArea),{forceMount:r,...a}=t,[i,o]=b.useState(!1),s=t.orientation==="horizontal",l=Ri(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;o(s?c:d)}},10);return pr(n.viewport,l),pr(n.content,l),u.jsx(vt,{present:r||i,children:u.jsx(Ys,{"data-state":i?"visible":"hidden",...a,ref:e})})}),Ys=b.forwardRef((t,e)=>{const{orientation:n="vertical",...r}=t,a=Ft(on,t.__scopeScrollArea),i=b.useRef(null),o=b.useRef(0),[s,l]=b.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=$E(s.viewport,s.content),d={...r,sizes:s,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>i.current=p,onThumbPointerUp:()=>o.current=0,onThumbPointerDown:p=>o.current=p};function _(p,m){return vD(p,o.current,s,m)}return n==="horizontal"?u.jsx(bD,{...d,ref:e,onThumbPositionChange:()=>{if(a.viewport&&i.current){const p=a.viewport.scrollLeft,m=WE(p,s,a.dir);i.current.style.transform=`translate3d(${m}px, 0, 0)`}},onWheelScroll:p=>{a.viewport&&(a.viewport.scrollLeft=p)},onDragScroll:p=>{a.viewport&&(a.viewport.scrollLeft=_(p,a.dir))}}):n==="vertical"?u.jsx(TD,{...d,ref:e,onThumbPositionChange:()=>{if(a.viewport&&i.current){const p=a.viewport.scrollTop,m=WE(p,s);i.current.style.transform=`translate3d(0, ${m}px, 0)`}},onWheelScroll:p=>{a.viewport&&(a.viewport.scrollTop=p)},onDragScroll:p=>{a.viewport&&(a.viewport.scrollTop=_(p))}}):null}),bD=b.forwardRef((t,e)=>{const{sizes:n,onSizesChange:r,...a}=t,i=Ft(on,t.__scopeScrollArea),[o,s]=b.useState(),l=b.useRef(null),c=ke(e,l,i.onScrollbarXChange);return b.useEffect(()=>{l.current&&s(getComputedStyle(l.current))},[l]),u.jsx(qE,{"data-orientation":"horizontal",...a,ref:c,sizes:n,style:{bottom:0,left:i.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:i.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":hi(n)+"px",...t.style},onThumbPointerDown:d=>t.onThumbPointerDown(d.x),onDragScroll:d=>t.onDragScroll(d.x),onWheelScroll:(d,_)=>{if(i.viewport){const p=i.viewport.scrollLeft+d.deltaX;t.onWheelScroll(p),QE(p,_)&&d.preventDefault()}},onResize:()=>{l.current&&i.viewport&&o&&r({content:i.viewport.scrollWidth,viewport:i.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ti(o.paddingLeft),paddingEnd:Ti(o.paddingRight)}})}})}),TD=b.forwardRef((t,e)=>{const{sizes:n,onSizesChange:r,...a}=t,i=Ft(on,t.__scopeScrollArea),[o,s]=b.useState(),l=b.useRef(null),c=ke(e,l,i.onScrollbarYChange);return b.useEffect(()=>{l.current&&s(getComputedStyle(l.current))},[l]),u.jsx(qE,{"data-orientation":"vertical",...a,ref:c,sizes:n,style:{top:0,right:i.dir==="ltr"?0:void 0,left:i.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":hi(n)+"px",...t.style},onThumbPointerDown:d=>t.onThumbPointerDown(d.y),onDragScroll:d=>t.onDragScroll(d.y),onWheelScroll:(d,_)=>{if(i.viewport){const p=i.viewport.scrollTop+d.deltaY;t.onWheelScroll(p),QE(p,_)&&d.preventDefault()}},onResize:()=>{l.current&&i.viewport&&o&&r({content:i.viewport.scrollHeight,viewport:i.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ti(o.paddingTop),paddingEnd:Ti(o.paddingBottom)}})}})}),[hD,HE]=UE(on),qE=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:a,onThumbChange:i,onThumbPointerUp:o,onThumbPointerDown:s,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:_,...p}=t,m=Ft(on,n),[g,f]=b.useState(null),E=ke(e,D=>f(D)),S=b.useRef(null),T=b.useRef(""),h=m.viewport,v=r.content-r.viewport,R=pt(d),C=pt(l),N=Ri(_,10);function O(D){if(S.current){const w=D.clientX-S.current.left,L=D.clientY-S.current.top;c({x:w,y:L})}}return b.useEffect(()=>{const D=w=>{const L=w.target;(g==null?void 0:g.contains(L))&&R(w,v)};return document.addEventListener("wheel",D,{passive:!1}),()=>document.removeEventListener("wheel",D,{passive:!1})},[h,g,v,R]),b.useEffect(C,[r,C]),pr(g,N),pr(m.content,N),u.jsx(hD,{scope:n,scrollbar:g,hasThumb:a,onThumbChange:pt(i),onThumbPointerUp:pt(o),onThumbPositionChange:C,onThumbPointerDown:pt(s),children:u.jsx(ye.div,{...p,ref:E,style:{position:"absolute",...p.style},onPointerDown:de(t.onPointerDown,D=>{D.button===0&&(D.target.setPointerCapture(D.pointerId),S.current=g.getBoundingClientRect(),T.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",m.viewport&&(m.viewport.style.scrollBehavior="auto"),O(D))}),onPointerMove:de(t.onPointerMove,O),onPointerUp:de(t.onPointerUp,D=>{const w=D.target;w.hasPointerCapture(D.pointerId)&&w.releasePointerCapture(D.pointerId),document.body.style.webkitUserSelect=T.current,m.viewport&&(m.viewport.style.scrollBehavior=""),S.current=null})})})}),bi="ScrollAreaThumb",VE=b.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=HE(bi,t.__scopeScrollArea);return u.jsx(vt,{present:n||a.hasThumb,children:u.jsx(RD,{ref:e,...r})})}),RD=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,style:r,...a}=t,i=Ft(bi,n),o=HE(bi,n),{onThumbPositionChange:s}=o,l=ke(e,_=>o.onThumbChange(_)),c=b.useRef(void 0),d=Ri(()=>{c.current&&(c.current(),c.current=void 0)},100);return b.useEffect(()=>{const _=i.viewport;if(_){const p=()=>{if(d(),!c.current){const m=ND(_,s);c.current=m,s()}};return s(),_.addEventListener("scroll",p),()=>_.removeEventListener("scroll",p)}},[i.viewport,d,s]),u.jsx(ye.div,{"data-state":o.hasThumb?"visible":"hidden",...a,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:de(t.onPointerDownCapture,_=>{const m=_.target.getBoundingClientRect(),g=_.clientX-m.left,f=_.clientY-m.top;o.onThumbPointerDown({x:g,y:f})}),onPointerUp:de(t.onPointerUp,o.onThumbPointerUp)})});VE.displayName=bi;var Hs="ScrollAreaCorner",zE=b.forwardRef((t,e)=>{const n=Ft(Hs,t.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(CD,{...t,ref:e}):null});zE.displayName=Hs;var CD=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,...r}=t,a=Ft(Hs,n),[i,o]=b.useState(0),[s,l]=b.useState(0),c=!!(i&&s);return pr(a.scrollbarX,()=>{var _;const d=((_=a.scrollbarX)==null?void 0:_.offsetHeight)||0;a.onCornerHeightChange(d),l(d)}),pr(a.scrollbarY,()=>{var _;const d=((_=a.scrollbarY)==null?void 0:_.offsetWidth)||0;a.onCornerWidthChange(d),o(d)}),c?u.jsx(ye.div,{...r,ref:e,style:{width:i,height:s,position:"absolute",right:a.dir==="ltr"?0:void 0,left:a.dir==="rtl"?0:void 0,bottom:0,...t.style}}):null});function Ti(t){return t?parseInt(t,10):0}function $E(t,e){const n=t/e;return isNaN(n)?0:n}function hi(t){const e=$E(t.viewport,t.content),n=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,r=(t.scrollbar.size-n)*e;return Math.max(r,18)}function vD(t,e,n,r="ltr"){const a=hi(n),i=a/2,o=e||i,s=a-o,l=n.scrollbar.paddingStart+o,c=n.scrollbar.size-n.scrollbar.paddingEnd-s,d=n.content-n.viewport,_=r==="ltr"?[0,d]:[d*-1,0];return KE([l,c],_)(t)}function WE(t,e,n="ltr"){const r=hi(e),a=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,i=e.scrollbar.size-a,o=e.content-e.viewport,s=i-r,l=n==="ltr"?[0,o]:[o*-1,0],c=Fs(t,l);return KE([0,o],[0,s])(c)}function KE(t,e){return n=>{if(t[0]===t[1]||e[0]===e[1])return e[0];const r=(e[1]-e[0])/(t[1]-t[0]);return e[0]+r*(n-t[0])}}function QE(t,e){return t>0&&t<e}var ND=(t,e=()=>{})=>{let n={left:t.scrollLeft,top:t.scrollTop},r=0;return function a(){const i={left:t.scrollLeft,top:t.scrollTop},o=n.left!==i.left,s=n.top!==i.top;(o||s)&&e(),n=i,r=window.requestAnimationFrame(a)}(),()=>window.cancelAnimationFrame(r)};function Ri(t,e){const n=pt(t),r=b.useRef(0);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),b.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,e)},[n,e])}function pr(t,e){const n=pt(e);_t(()=>{let r=0;if(t){const a=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return a.observe(t),()=>{window.cancelAnimationFrame(r),a.unobserve(t)}}},[t,n])}var jE=FE,OD=GE,yD=zE;const XE=b.forwardRef(({className:t,children:e,...n},r)=>u.jsxs(jE,{ref:r,className:$("relative overflow-hidden",t),...n,children:[u.jsx(OD,{className:"h-full w-full rounded-[inherit] overflow-auto",children:e}),u.jsx(ZE,{}),u.jsx(yD,{})]}));XE.displayName=jE.displayName;const ZE=b.forwardRef(({className:t,orientation:e="vertical",...n},r)=>u.jsx(Gs,{ref:r,orientation:e,className:$("flex touch-none select-none transition-colors",e==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",e==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",t),...n,children:u.jsx(VE,{className:"relative flex-1 rounded-full bg-border"})}));ZE.displayName=Gs.displayName;function Ci({className:t="",showCreateButton:e=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:a="400px",customStyles:i={},currentThreadId:o=null,navigateToThread:s,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{loadThread:_,threads:p,refreshThreads:m,currentThreadId:g,createThread:f,deleteThread:E,renameThread:S}=ba(),[T,h]=y.useState(p??[]),[v,R]=y.useState(!1),[C,N]=y.useState(null),[O,D]=y.useState(null),[w,L]=y.useState(""),[H,z]=y.useState(!1);y.useEffect(()=>{h(p??[])},[p]);const P=async q=>{try{await _(q),s==null||s(q),l==null||l(q)}catch(X){console.error("Failed to select thread:",X)}},G=async()=>{try{z(!0);const q=await f();c==null||c(q),s==null||s(q)}catch(q){console.error("Failed to create thread:",q)}finally{z(!1)}},I=async(q,X)=>{if(X.stopPropagation(),!!confirm("Delete this thread?"))try{await E(q),d==null||d(q)}catch(ce){console.error("Failed to delete thread:",ce)}},U=(q,X)=>{X.stopPropagation(),D(q.threadId),L(q.title||`Thread ${q.threadId.slice(0,8)}`)},M=async q=>{if(w.trim())try{await S(q,w.trim()),D(null),L("")}catch(X){console.error("Failed to update title:",X)}},k=()=>{D(null),L("")},Y=(q,X)=>{q.key==="Enter"?M(X):q.key==="Escape"&&k()},W=q=>{if(!q)return"";try{const X=new Date(q),ge=new Date().getTime()-X.getTime(),V=Math.floor(ge/(1e3*60*60*24));return V===0?X.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):V===1?"Yesterday":V<7?`${V} days ago`:X.toLocaleDateString()}catch{return""}},re=q=>q.title||`Thread ${q.threadId.slice(0,8)}`;return u.jsxs("div",{className:`flex flex-col h-full ${t} ${i.container||""}`,children:[e&&u.jsx("div",{className:i.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Ve,{onClick:G,disabled:H||v,className:i.createButton||"p-2",size:"sm",variant:"ghost",title:H?"Creating...":"New Chat",children:u.jsx(pe.MessageSquarePlus,{size:20})})}),u.jsx(XE,{className:`flex-1 min-h-0 ${i.threadList||""}`,style:a?{maxHeight:a}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:v?u.jsx("div",{className:"text-center py-8 text-slate-400",children:"Loading…"}):T.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(pe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):T.slice().sort((q,X)=>new Date(X.updatedAt||X.createdAt||"").getTime()-new Date(q.updatedAt||q.createdAt||"").getTime()).map(q=>u.jsxs("div",{onClick:()=>P(q.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(o??g)===q.threadId?`${i.activeThread||"bg-slate-600 border-slate-500"} `:`${i.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${i.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:O===q.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:X=>X.stopPropagation(),children:[u.jsx(Jr,{value:w,onChange:X=>L(X.target.value),onKeyDown:X=>Y(X,q.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>M(q.threadId),className:"h-6 w-6 p-0",children:u.jsx(pe.Check,{size:12})}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:k,className:"h-6 w-6 p-0",children:u.jsx(pe.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:re(q)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(pe.Calendar,{size:10}),u.jsx("span",{children:W(q.updatedAt||q.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&O!==q.threadId&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:X=>U(q,X),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(pe.Edit3,{size:12})}),n&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:X=>I(q.threadId,X),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(pe.Trash2,{size:12})})]})]}),o===q.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},q.threadId))})})]})}const JE=y.createContext(null);function ID({children:t,basePath:e="/chat"}){const n=y.useMemo(()=>e?e==="/"?"":e.endsWith("/")?e.slice(0,-1):e:"/chat",[e]),r={basePath:n,buildThreadPath:a=>`${n}/${a}`,buildBasePath:()=>n};return u.jsx(JE.Provider,{value:r,children:t})}function AD(){const t=y.useContext(JE);return t||{basePath:"/chat",buildThreadPath:e=>`/chat/${e}`,buildBasePath:()=>"/chat"}}function mr(t){if(!(typeof globalThis>"u"))return globalThis[t]}function xD(t){if(typeof t!="string")return;const e=t.trim();if(e)return e.replace(/\/+$/g,"")}function ef(){const t=[mr("__API_BASE_URL__"),mr("__CHAT_API_BASE_URL__"),mr("__CHAT_API_URL__")];for(const e of t){const n=xD(e);if(n)return n}}function tf(){const t=[mr("__API_AUTH_TOKEN__"),mr("__CHAT_API_KEY__"),mr("__CHAT_AUTH_TOKEN__")];for(const e of t)if(typeof e=="string"&&e.trim())return e.trim()}function nf(){const t={},e=ef(),n=tf();return e&&(t.baseUrl=e),n&&(t.apiKey=n),t}function rf(){const t=nf(),e=cn.getAuthToken(),n=ef();return{apiBaseUrl:t.baseUrl||cn.baseUrl||n||"http://localhost:8000",apiKey:e||t.apiKey||tf()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const af="chat-settings";function DD(){try{const t=localStorage.getItem(af);return t?JSON.parse(t):{}}catch(t){return console.error("Failed to parse stored settings:",t),{}}}function wD(t){try{localStorage.setItem(af,JSON.stringify(t)),t.apiKey&&cn.setAuthToken(t.apiKey)}catch(e){console.error("Failed to save settings:",e)}}function MD(){const t=rf(),e=DD(),n=cn.getAuthToken();return{...t,...e,apiKey:n||e.apiKey||t.apiKey,apiBaseUrl:cn.baseUrl||e.apiBaseUrl||t.apiBaseUrl}}function LD(t){t.apiKey&&cn.setAuthToken(t.apiKey),wD(t)}const qs=768;function PD(){const[t,e]=b.useState(void 0);return b.useEffect(()=>{const n=window.matchMedia(`(max-width: ${qs-1}px)`),r=()=>{e(window.innerWidth<qs)};return n.addEventListener("change",r),e(window.innerWidth<qs),()=>n.removeEventListener("change",r)},[]),!!t}var kD="Separator",of="horizontal",UD=["horizontal","vertical"],sf=b.forwardRef((t,e)=>{const{decorative:n,orientation:r=of,...a}=t,i=FD(r)?r:of,s=n?{role:"none"}:{"aria-orientation":i==="vertical"?i:void 0,role:"separator"};return u.jsx(ye.div,{"data-orientation":i,...s,...a,ref:e})});sf.displayName=kD;function FD(t){return UD.includes(t)}var lf=sf;const Vs=b.forwardRef(({className:t,orientation:e="horizontal",decorative:n=!0,...r},a)=>u.jsx(lf,{ref:a,decorative:n,orientation:e,className:$("shrink-0 bg-border",e==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...r}));Vs.displayName=lf.displayName;const cf=zm,BD=tI,GD=$m,df=b.forwardRef(({className:t,...e},n)=>u.jsx(Xa,{className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e,ref:n}));df.displayName=Xa.displayName;const YD=br.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),zs=b.forwardRef(({side:t="right",className:e,children:n,...r},a)=>u.jsxs(GD,{children:[u.jsx(df,{}),u.jsxs(Za,{ref:a,className:$(YD({side:t}),e),...r,children:[n,u.jsxs(Wm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(pe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));zs.displayName=Za.displayName;const uf=({className:t,...e})=>u.jsx("div",{className:$("flex flex-col space-y-2 text-center sm:text-left",t),...e});uf.displayName="SheetHeader";const _f=b.forwardRef(({className:t,...e},n)=>u.jsx(Gn,{ref:n,className:$("text-lg font-semibold text-foreground",t),...e}));_f.displayName=Gn.displayName;const pf=b.forwardRef(({className:t,...e},n)=>u.jsx(Ja,{ref:n,className:$("text-sm text-muted-foreground",t),...e}));pf.displayName=Ja.displayName;function mf({className:t,...e}){return u.jsx("div",{className:$("animate-pulse rounded-md bg-muted",t),...e})}var gf=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"}),HD="VisuallyHidden",Ef=b.forwardRef((t,e)=>u.jsx(ye.span,{...t,ref:e,style:{...gf,...t.style}}));Ef.displayName=HD;var qD=Ef,[vi,tF]=qt("Tooltip",[_r]),Ni=_r(),ff="TooltipProvider",VD=700,$s="tooltip.open",[zD,Ws]=vi(ff),Sf=t=>{const{__scopeTooltip:e,delayDuration:n=VD,skipDelayDuration:r=300,disableHoverableContent:a=!1,children:i}=t,o=b.useRef(!0),s=b.useRef(!1),l=b.useRef(0);return b.useEffect(()=>{const c=l.current;return()=>window.clearTimeout(c)},[]),u.jsx(zD,{scope:e,isOpenDelayedRef:o,delayDuration:n,onOpen:b.useCallback(()=>{window.clearTimeout(l.current),o.current=!1},[]),onClose:b.useCallback(()=>{window.clearTimeout(l.current),l.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:b.useCallback(c=>{s.current=c},[]),disableHoverableContent:a,children:i})};Sf.displayName=ff;var ea="Tooltip",[$D,Oi]=vi(ea),bf=t=>{const{__scopeTooltip:e,children:n,open:r,defaultOpen:a,onOpenChange:i,disableHoverableContent:o,delayDuration:s}=t,l=Ws(ea,t.__scopeTooltip),c=Ni(e),[d,_]=b.useState(null),p=Vt(),m=b.useRef(0),g=o??l.disableHoverableContent,f=s??l.delayDuration,E=b.useRef(!1),[S,T]=Rn({prop:r,defaultProp:a??!1,onChange:N=>{N?(l.onOpen(),document.dispatchEvent(new CustomEvent($s))):l.onClose(),i==null||i(N)},caller:ea}),h=b.useMemo(()=>S?E.current?"delayed-open":"instant-open":"closed",[S]),v=b.useCallback(()=>{window.clearTimeout(m.current),m.current=0,E.current=!1,T(!0)},[T]),R=b.useCallback(()=>{window.clearTimeout(m.current),m.current=0,T(!1)},[T]),C=b.useCallback(()=>{window.clearTimeout(m.current),m.current=window.setTimeout(()=>{E.current=!0,T(!0),m.current=0},f)},[f,T]);return b.useEffect(()=>()=>{m.current&&(window.clearTimeout(m.current),m.current=0)},[]),u.jsx(Cs,{...c,children:u.jsx($D,{scope:e,contentId:p,open:S,stateAttribute:h,trigger:d,onTriggerChange:_,onTriggerEnter:b.useCallback(()=>{l.isOpenDelayedRef.current?C():v()},[l.isOpenDelayedRef,C,v]),onTriggerLeave:b.useCallback(()=>{g?R():(window.clearTimeout(m.current),m.current=0)},[R,g]),onOpen:v,onClose:R,disableHoverableContent:g,children:n})})};bf.displayName=ea;var Ks="TooltipTrigger",Tf=b.forwardRef((t,e)=>{const{__scopeTooltip:n,...r}=t,a=Oi(Ks,n),i=Ws(Ks,n),o=Ni(n),s=b.useRef(null),l=ke(e,s,a.onTriggerChange),c=b.useRef(!1),d=b.useRef(!1),_=b.useCallback(()=>c.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",_),[_]),u.jsx(vs,{asChild:!0,...o,children:u.jsx(ye.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...r,ref:l,onPointerMove:de(t.onPointerMove,p=>{p.pointerType!=="touch"&&!d.current&&!i.isPointerInTransitRef.current&&(a.onTriggerEnter(),d.current=!0)}),onPointerLeave:de(t.onPointerLeave,()=>{a.onTriggerLeave(),d.current=!1}),onPointerDown:de(t.onPointerDown,()=>{a.open&&a.onClose(),c.current=!0,document.addEventListener("pointerup",_,{once:!0})}),onFocus:de(t.onFocus,()=>{c.current||a.onOpen()}),onBlur:de(t.onBlur,a.onClose),onClick:de(t.onClick,a.onClose)})})});Tf.displayName=Ks;var WD="TooltipPortal",[nF,KD]=vi(WD,{forceMount:void 0}),gr="TooltipContent",hf=b.forwardRef((t,e)=>{const n=KD(gr,t.__scopeTooltip),{forceMount:r=n.forceMount,side:a="top",...i}=t,o=Oi(gr,t.__scopeTooltip);return u.jsx(vt,{present:r||o.open,children:o.disableHoverableContent?u.jsx(Rf,{side:a,...i,ref:e}):u.jsx(QD,{side:a,...i,ref:e})})}),QD=b.forwardRef((t,e)=>{const n=Oi(gr,t.__scopeTooltip),r=Ws(gr,t.__scopeTooltip),a=b.useRef(null),i=ke(e,a),[o,s]=b.useState(null),{trigger:l,onClose:c}=n,d=a.current,{onPointerInTransitChange:_}=r,p=b.useCallback(()=>{s(null),_(!1)},[_]),m=b.useCallback((g,f)=>{const E=g.currentTarget,S={x:g.clientX,y:g.clientY},T=ew(S,E.getBoundingClientRect()),h=tw(S,T),v=nw(f.getBoundingClientRect()),R=aw([...h,...v]);s(R),_(!0)},[_]);return b.useEffect(()=>()=>p(),[p]),b.useEffect(()=>{if(l&&d){const g=E=>m(E,d),f=E=>m(E,l);return l.addEventListener("pointerleave",g),d.addEventListener("pointerleave",f),()=>{l.removeEventListener("pointerleave",g),d.removeEventListener("pointerleave",f)}}},[l,d,m,p]),b.useEffect(()=>{if(o){const g=f=>{const E=f.target,S={x:f.clientX,y:f.clientY},T=(l==null?void 0:l.contains(E))||(d==null?void 0:d.contains(E)),h=!rw(S,o);T?p():h&&(p(),c())};return document.addEventListener("pointermove",g),()=>document.removeEventListener("pointermove",g)}},[l,d,o,c,p]),u.jsx(Rf,{...t,ref:i})}),[jD,XD]=vi(ea,{isInside:!1}),ZD=Nt.createSlottable("TooltipContent"),Rf=b.forwardRef((t,e)=>{const{__scopeTooltip:n,children:r,"aria-label":a,onEscapeKeyDown:i,onPointerDownOutside:o,...s}=t,l=Oi(gr,n),c=Ni(n),{onClose:d}=l;return b.useEffect(()=>(document.addEventListener($s,d),()=>document.removeEventListener($s,d)),[d]),b.useEffect(()=>{if(l.trigger){const _=p=>{const m=p.target;m!=null&&m.contains(l.trigger)&&d()};return window.addEventListener("scroll",_,{capture:!0}),()=>window.removeEventListener("scroll",_,{capture:!0})}},[l.trigger,d]),u.jsx(Yr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:i,onPointerDownOutside:o,onFocusOutside:_=>_.preventDefault(),onDismiss:d,children:u.jsxs(Ns,{"data-state":l.stateAttribute,...c,...s,ref:e,style:{...s.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[u.jsx(ZD,{children:r}),u.jsx(jD,{scope:n,isInside:!0,children:u.jsx(qD,{id:l.contentId,role:"tooltip",children:a||r})})]})})});hf.displayName=gr;var Cf="TooltipArrow",JD=b.forwardRef((t,e)=>{const{__scopeTooltip:n,...r}=t,a=Ni(n);return XD(Cf,n).isInside?null:u.jsx(Os,{...a,...r,ref:e})});JD.displayName=Cf;function ew(t,e){const n=Math.abs(e.top-t.y),r=Math.abs(e.bottom-t.y),a=Math.abs(e.right-t.x),i=Math.abs(e.left-t.x);switch(Math.min(n,r,a,i)){case i:return"left";case a:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function tw(t,e,n=5){const r=[];switch(e){case"top":r.push({x:t.x-n,y:t.y+n},{x:t.x+n,y:t.y+n});break;case"bottom":r.push({x:t.x-n,y:t.y-n},{x:t.x+n,y:t.y-n});break;case"left":r.push({x:t.x+n,y:t.y-n},{x:t.x+n,y:t.y+n});break;case"right":r.push({x:t.x-n,y:t.y-n},{x:t.x-n,y:t.y+n});break}return r}function nw(t){const{top:e,right:n,bottom:r,left:a}=t;return[{x:a,y:e},{x:n,y:e},{x:n,y:r},{x:a,y:r}]}function rw(t,e){const{x:n,y:r}=t;let a=!1;for(let i=0,o=e.length-1;i<e.length;o=i++){const s=e[i],l=e[o],c=s.x,d=s.y,_=l.x,p=l.y;d>r!=p>r&&n<(_-c)*(r-d)/(p-d)+c&&(a=!a)}return a}function aw(t){const e=t.slice();return e.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),iw(e)}function iw(t){if(t.length<=1)return t.slice();const e=[];for(let r=0;r<t.length;r++){const a=t[r];for(;e.length>=2;){const i=e[e.length-1],o=e[e.length-2];if((i.x-o.x)*(a.y-o.y)>=(i.y-o.y)*(a.x-o.x))e.pop();else break}e.push(a)}e.pop();const n=[];for(let r=t.length-1;r>=0;r--){const a=t[r];for(;n.length>=2;){const i=n[n.length-1],o=n[n.length-2];if((i.x-o.x)*(a.y-o.y)>=(i.y-o.y)*(a.x-o.x))n.pop();else break}n.push(a)}return n.pop(),e.length===1&&n.length===1&&e[0].x===n[0].x&&e[0].y===n[0].y?e:e.concat(n)}var ow=Sf,sw=bf,lw=Tf,vf=hf;const cw=ow,dw=sw,uw=lw,Nf=b.forwardRef(({className:t,sideOffset:e=4,...n},r)=>u.jsx(vf,{ref:r,sideOffset:e,className:$("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",t),...n}));Nf.displayName=vf.displayName;const _w="sidebar:state",pw=60*60*24*7,mw="16rem",gw="18rem",Ew="3rem",fw="b",Of=b.createContext(null);function yi(){const t=b.useContext(Of);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}const yf=b.forwardRef(({defaultOpen:t=!0,open:e,onOpenChange:n,className:r,style:a,children:i,...o},s)=>{const l=PD(),[c,d]=b.useState(!1),[_,p]=b.useState(t),m=e??_,g=b.useCallback(T=>{const h=typeof T=="function"?T(m):T;n?n(h):p(h),document.cookie=`${_w}=${h}; path=/; max-age=${pw}`},[n,m]),f=b.useCallback(()=>l?d(T=>!T):g(T=>!T),[l,g,d]);b.useEffect(()=>{const T=h=>{h.key===fw&&(h.metaKey||h.ctrlKey)&&(h.preventDefault(),f())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[f]);const E=m?"expanded":"collapsed",S=b.useMemo(()=>({state:E,open:m,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:d,toggleSidebar:f}),[E,m,g,l,c,d,f]);return u.jsx(Of.Provider,{value:S,children:u.jsx(cw,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":mw,"--sidebar-width-icon":Ew,...a},className:$("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",r),ref:s,...o,children:i})})})});yf.displayName="SidebarProvider";const If=b.forwardRef(({side:t="left",variant:e="sidebar",collapsible:n="offcanvas",className:r,children:a,...i},o)=>{const{isMobile:s,state:l,openMobile:c,setOpenMobile:d}=yi();return n==="none"?u.jsx("div",{className:$("flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",r),ref:o,...i,children:a}):s?u.jsx(cf,{open:c,onOpenChange:d,...i,children:u.jsx(zs,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":gw},side:t,children:u.jsx("div",{className:"flex h-full w-full flex-col",children:a})})}):u.jsxs("div",{ref:o,className:"group peer hidden md:block text-sidebar-foreground","data-state":l,"data-collapsible":l==="collapsed"?n:"","data-variant":e,"data-side":t,children:[u.jsx("div",{className:$("duration-200 relative h-svh w-[--sidebar-width] bg-transparent transition-[width] ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",e==="floating"||e==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),u.jsx("div",{className:$("duration-200 fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] ease-linear md:flex",t==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",e==="floating"||e==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...i,children:u.jsx("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow",children:a})})]})});If.displayName="Sidebar";const Af=b.forwardRef(({className:t,onClick:e,...n},r)=>{const{toggleSidebar:a}=yi();return u.jsxs(Ve,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:$("h-7 w-7",t),onClick:i=>{e==null||e(i),a()},...n,children:[u.jsx(pe.PanelLeft,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});Af.displayName="SidebarTrigger";const Sw=b.forwardRef(({className:t,...e},n)=>{const{toggleSidebar:r}=yi();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:$("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",t),...e})});Sw.displayName="SidebarRail";const xf=b.forwardRef(({className:t,...e},n)=>u.jsx("main",{ref:n,className:$("relative flex min-h-svh flex-1 flex-col bg-background","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",t),...e}));xf.displayName="SidebarInset";const bw=b.forwardRef(({className:t,...e},n)=>u.jsx(Jr,{ref:n,"data-sidebar":"input",className:$("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",t),...e}));bw.displayName="SidebarInput";const Df=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:$("flex flex-col gap-2 p-2",t),...e}));Df.displayName="SidebarHeader";const Tw=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:$("flex flex-col gap-2 p-2",t),...e}));Tw.displayName="SidebarFooter";const hw=b.forwardRef(({className:t,...e},n)=>u.jsx(Vs,{ref:n,"data-sidebar":"separator",className:$("mx-2 w-auto bg-sidebar-border",t),...e}));hw.displayName="SidebarSeparator";const wf=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:$("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",t),...e}));wf.displayName="SidebarContent";const Mf=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:$("relative flex w-full min-w-0 flex-col p-2",t),...e}));Mf.displayName="SidebarGroup";const Lf=b.forwardRef(({className:t,asChild:e=!1,...n},r)=>{const a=e?Nt.Slot:"div";return u.jsx(a,{ref:r,"data-sidebar":"group-label",className:$("duration-200 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opa] ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",t),...n})});Lf.displayName="SidebarGroupLabel";const Rw=b.forwardRef(({className:t,asChild:e=!1,...n},r)=>{const a=e?Nt.Slot:"button";return u.jsx(a,{ref:r,"data-sidebar":"group-action",className:$("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",t),...n})});Rw.displayName="SidebarGroupAction";const Pf=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:$("w-full text-sm",t),...e}));Pf.displayName="SidebarGroupContent";const kf=b.forwardRef(({className:t,...e},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:$("flex w-full min-w-0 flex-col gap-1",t),...e}));kf.displayName="SidebarMenu";const Uf=b.forwardRef(({className:t,...e},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:$("group/menu-item relative",t),...e}));Uf.displayName="SidebarMenuItem";const Cw=br.cva("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),Ff=b.forwardRef(({asChild:t=!1,isActive:e=!1,variant:n="default",size:r="default",tooltip:a,className:i,...o},s)=>{const l=t?Nt.Slot:"button",{isMobile:c,state:d}=yi(),_=u.jsx(l,{ref:s,"data-sidebar":"menu-button","data-size":r,"data-active":e,className:$(Cw({variant:n,size:r}),i),...o});return a?(typeof a=="string"&&(a={children:a}),u.jsxs(dw,{children:[u.jsx(uw,{asChild:!0,children:_}),u.jsx(Nf,{side:"right",align:"center",hidden:d!=="collapsed"||c,...a})]})):_});Ff.displayName="SidebarMenuButton";const vw=b.forwardRef(({className:t,asChild:e=!1,showOnHover:n=!1,...r},a)=>{const i=e?Nt.Slot:"button";return u.jsx(i,{ref:a,"data-sidebar":"menu-action",className:$("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",n&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",t),...r})});vw.displayName="SidebarMenuAction";const Nw=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:$("absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground select-none pointer-events-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",t),...e}));Nw.displayName="SidebarMenuBadge";const Ow=b.forwardRef(({className:t,showIcon:e=!1,...n},r)=>{const a=b.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:$("rounded-md h-8 flex gap-2 px-2 items-center",t),...n,children:[e&&u.jsx(mf,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(mf,{className:"h-4 flex-1 max-w-[--skeleton-width]","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":a}})]})});Ow.displayName="SidebarMenuSkeleton";const yw=b.forwardRef(({className:t,...e},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:$("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",t),...e}));yw.displayName="SidebarMenuSub";const Iw=b.forwardRef(({...t},e)=>u.jsx("li",{ref:e,...t}));Iw.displayName="SidebarMenuSubItem";const Aw=b.forwardRef(({asChild:t=!1,size:e="md",isActive:n,className:r,...a},i)=>{const o=t?Nt.Slot:"a";return u.jsx(o,{ref:i,"data-sidebar":"menu-sub-button","data-size":e,"data-active":n,className:$("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",e==="sm"&&"text-xs",e==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...a})});Aw.displayName="SidebarMenuSubButton";function xw({header:t,sidebarTitle:e="Threads",showThreads:n=!0,className:r="",sidebarClassName:a="",chatClassName:i="",...o}){return u.jsx(yr,{...o,children:u.jsxs(yf,{className:`w-full ${r}`,children:[u.jsxs(If,{className:`border-r ${a}`,children:[u.jsx(Df,{children:u.jsx(kf,{children:u.jsx(Uf,{children:u.jsx(Ff,{asChild:!0,size:"lg",children:u.jsx("span",{className:"font-semibold",children:e})})})})}),u.jsx(wf,{children:n&&u.jsxs(Mf,{children:[u.jsx(Lf,{children:"Conversations"}),u.jsx(Pf,{children:u.jsx("div",{className:"px-2 py-1",children:u.jsx(Ci,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-[calc(100vh-12rem)]"})})})]})})]}),u.jsxs(xf,{children:[u.jsxs("header",{className:"h-14 border-b bg-background/60 backdrop-blur flex items-center gap-2 px-4",children:[u.jsx(Af,{}),u.jsx("div",{className:"flex-1"}),t]}),u.jsx("main",{className:`flex-1 min-h-0 overflow-hidden ${i}`,children:u.jsx(Zr,{})})]})]})})}var Dw="Label",Bf=b.forwardRef((t,e)=>u.jsx(ye.label,{...t,ref:e,onMouseDown:n=>{var a;n.target.closest("button, input, select, textarea")||((a=t.onMouseDown)==null||a.call(t,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Bf.displayName=Dw;var Gf=Bf;const ww=br.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Bt=b.forwardRef(({className:t,...e},n)=>u.jsx(Gf,{ref:n,className:$(ww(),t),...e}));Bt.displayName=Gf.displayName;function Yf(t){const e=b.useRef({value:t,previous:t});return b.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}var Ii="Switch",[Mw,rF]=qt(Ii),[Lw,Pw]=Mw(Ii),Hf=b.forwardRef((t,e)=>{const{__scopeSwitch:n,name:r,checked:a,defaultChecked:i,required:o,disabled:s,value:l="on",onCheckedChange:c,form:d,..._}=t,[p,m]=b.useState(null),g=ke(e,h=>m(h)),f=b.useRef(!1),E=p?d||!!p.closest("form"):!0,[S,T]=Rn({prop:a,defaultProp:i??!1,onChange:c,caller:Ii});return u.jsxs(Lw,{scope:n,checked:S,disabled:s,children:[u.jsx(ye.button,{type:"button",role:"switch","aria-checked":S,"aria-required":o,"data-state":$f(S),"data-disabled":s?"":void 0,disabled:s,value:l,..._,ref:g,onClick:de(t.onClick,h=>{T(v=>!v),E&&(f.current=h.isPropagationStopped(),f.current||h.stopPropagation())})}),E&&u.jsx(zf,{control:p,bubbles:!f.current,name:r,value:l,checked:S,required:o,disabled:s,form:d,style:{transform:"translateX(-100%)"}})]})});Hf.displayName=Ii;var qf="SwitchThumb",Vf=b.forwardRef((t,e)=>{const{__scopeSwitch:n,...r}=t,a=Pw(qf,n);return u.jsx(ye.span,{"data-state":$f(a.checked),"data-disabled":a.disabled?"":void 0,...r,ref:e})});Vf.displayName=qf;var kw="SwitchBubbleInput",zf=b.forwardRef(({__scopeSwitch:t,control:e,checked:n,bubbles:r=!0,...a},i)=>{const o=b.useRef(null),s=ke(o,i),l=Yf(n),c=Og(e);return b.useEffect(()=>{const d=o.current;if(!d)return;const _=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(_,"checked").set;if(l!==n&&m){const g=new Event("click",{bubbles:r});m.call(d,n),d.dispatchEvent(g)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...a,tabIndex:-1,ref:s,style:{...a.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});zf.displayName=kw;function $f(t){return t?"checked":"unchecked"}var Wf=Hf,Uw=Vf;const yn=b.forwardRef(({className:t,...e},n)=>u.jsx(Wf,{className:$("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",t),...e,ref:n,children:u.jsx(Uw,{className:$("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));yn.displayName=Wf.displayName;var Fw=[" ","Enter","ArrowUp","ArrowDown"],Bw=[" ","Enter"],Vn="Select",[Ai,xi,Gw]=cs(Vn),[Er,aF]=qt(Vn,[Gw,_r]),Di=_r(),[Yw,In]=Er(Vn),[Hw,qw]=Er(Vn),Kf=t=>{const{__scopeSelect:e,children:n,open:r,defaultOpen:a,onOpenChange:i,value:o,defaultValue:s,onValueChange:l,dir:c,name:d,autoComplete:_,disabled:p,required:m,form:g}=t,f=Di(e),[E,S]=b.useState(null),[T,h]=b.useState(null),[v,R]=b.useState(!1),C=ri(c),[N,O]=Rn({prop:r,defaultProp:a??!1,onChange:i,caller:Vn}),[D,w]=Rn({prop:o,defaultProp:s,onChange:l,caller:Vn}),L=b.useRef(null),H=E?g||!!E.closest("form"):!0,[z,P]=b.useState(new Set),G=Array.from(z).map(I=>I.props.value).join(";");return u.jsx(Cs,{...f,children:u.jsxs(Yw,{required:m,scope:e,trigger:E,onTriggerChange:S,valueNode:T,onValueNodeChange:h,valueNodeHasChildren:v,onValueNodeHasChildrenChange:R,contentId:Vt(),value:D,onValueChange:w,open:N,onOpenChange:O,dir:C,triggerPointerDownPosRef:L,disabled:p,children:[u.jsx(Ai.Provider,{scope:e,children:u.jsx(Hw,{scope:t.__scopeSelect,onNativeOptionAdd:b.useCallback(I=>{P(U=>new Set(U).add(I))},[]),onNativeOptionRemove:b.useCallback(I=>{P(U=>{const M=new Set(U);return M.delete(I),M})},[]),children:n})}),H?u.jsxs(SS,{"aria-hidden":!0,required:m,tabIndex:-1,name:d,autoComplete:_,value:D,onChange:I=>w(I.target.value),disabled:p,form:g,children:[D===void 0?u.jsx("option",{value:""}):null,Array.from(z)]},G):null]})})};Kf.displayName=Vn;var Qf="SelectTrigger",jf=b.forwardRef((t,e)=>{const{__scopeSelect:n,disabled:r=!1,...a}=t,i=Di(n),o=In(Qf,n),s=o.disabled||r,l=ke(e,o.onTriggerChange),c=xi(n),d=b.useRef("touch"),[_,p,m]=TS(f=>{const E=c().filter(h=>!h.disabled),S=E.find(h=>h.value===o.value),T=hS(E,f,S);T!==void 0&&o.onValueChange(T.value)}),g=f=>{s||(o.onOpenChange(!0),m()),f&&(o.triggerPointerDownPosRef.current={x:Math.round(f.pageX),y:Math.round(f.pageY)})};return u.jsx(vs,{asChild:!0,...i,children:u.jsx(ye.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:s,"data-disabled":s?"":void 0,"data-placeholder":bS(o.value)?"":void 0,...a,ref:l,onClick:de(a.onClick,f=>{f.currentTarget.focus(),d.current!=="mouse"&&g(f)}),onPointerDown:de(a.onPointerDown,f=>{d.current=f.pointerType;const E=f.target;E.hasPointerCapture(f.pointerId)&&E.releasePointerCapture(f.pointerId),f.button===0&&f.ctrlKey===!1&&f.pointerType==="mouse"&&(g(f),f.preventDefault())}),onKeyDown:de(a.onKeyDown,f=>{const E=_.current!=="";!(f.ctrlKey||f.altKey||f.metaKey)&&f.key.length===1&&p(f.key),!(E&&f.key===" ")&&Fw.includes(f.key)&&(g(),f.preventDefault())})})})});jf.displayName=Qf;var Xf="SelectValue",Zf=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:a,children:i,placeholder:o="",...s}=t,l=In(Xf,n),{onValueNodeHasChildrenChange:c}=l,d=i!==void 0,_=ke(e,l.onValueNodeChange);return _t(()=>{c(d)},[c,d]),u.jsx(ye.span,{...s,ref:_,style:{pointerEvents:"none"},children:bS(l.value)?u.jsx(u.Fragment,{children:o}):i})});Zf.displayName=Xf;var Vw="SelectIcon",Jf=b.forwardRef((t,e)=>{const{__scopeSelect:n,children:r,...a}=t;return u.jsx(ye.span,{"aria-hidden":!0,...a,ref:e,children:r||"▼"})});Jf.displayName=Vw;var zw="SelectPortal",eS=t=>u.jsx(Ga,{asChild:!0,...t});eS.displayName=zw;var zn="SelectContent",tS=b.forwardRef((t,e)=>{const n=In(zn,t.__scopeSelect),[r,a]=b.useState();if(_t(()=>{a(new DocumentFragment)},[]),!n.open){const i=r;return i?oa.createPortal(u.jsx(nS,{scope:t.__scopeSelect,children:u.jsx(Ai.Slot,{scope:t.__scopeSelect,children:u.jsx("div",{children:t.children})})}),i):null}return u.jsx(rS,{...t,ref:e})});tS.displayName=zn;var Kt=10,[nS,An]=Er(zn),$w="SelectContentImpl",Ww=Nt.createSlot("SelectContent.RemoveScroll"),rS=b.forwardRef((t,e)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:a,onEscapeKeyDown:i,onPointerDownOutside:o,side:s,sideOffset:l,align:c,alignOffset:d,arrowPadding:_,collisionBoundary:p,collisionPadding:m,sticky:g,hideWhenDetached:f,avoidCollisions:E,...S}=t,T=In(zn,n),[h,v]=b.useState(null),[R,C]=b.useState(null),N=ke(e,V=>v(V)),[O,D]=b.useState(null),[w,L]=b.useState(null),H=xi(n),[z,P]=b.useState(!1),G=b.useRef(!1);b.useEffect(()=>{if(h)return as(h)},[h]),Zo();const I=b.useCallback(V=>{const[F,...K]=H().map(oe=>oe.ref.current),[te]=K.slice(-1),le=document.activeElement;for(const oe of V)if(oe===le||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===F&&R&&(R.scrollTop=0),oe===te&&R&&(R.scrollTop=R.scrollHeight),oe==null||oe.focus(),document.activeElement!==le))return},[H,R]),U=b.useCallback(()=>I([O,h]),[I,O,h]);b.useEffect(()=>{z&&U()},[z,U]);const{onOpenChange:M,triggerPointerDownPosRef:k}=T;b.useEffect(()=>{if(h){let V={x:0,y:0};const F=te=>{var le,oe;V={x:Math.abs(Math.round(te.pageX)-(((le=k.current)==null?void 0:le.x)??0)),y:Math.abs(Math.round(te.pageY)-(((oe=k.current)==null?void 0:oe.y)??0))}},K=te=>{V.x<=10&&V.y<=10?te.preventDefault():h.contains(te.target)||M(!1),document.removeEventListener("pointermove",F),k.current=null};return k.current!==null&&(document.addEventListener("pointermove",F),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",F),document.removeEventListener("pointerup",K,{capture:!0})}}},[h,M,k]),b.useEffect(()=>{const V=()=>M(!1);return window.addEventListener("blur",V),window.addEventListener("resize",V),()=>{window.removeEventListener("blur",V),window.removeEventListener("resize",V)}},[M]);const[Y,W]=TS(V=>{const F=H().filter(le=>!le.disabled),K=F.find(le=>le.ref.current===document.activeElement),te=hS(F,V,K);te&&setTimeout(()=>te.ref.current.focus())}),re=b.useCallback((V,F,K)=>{const te=!G.current&&!K;(T.value!==void 0&&T.value===F||te)&&(D(V),te&&(G.current=!0))},[T.value]),q=b.useCallback(()=>h==null?void 0:h.focus(),[h]),X=b.useCallback((V,F,K)=>{const te=!G.current&&!K;(T.value!==void 0&&T.value===F||te)&&L(V)},[T.value]),ce=r==="popper"?Qs:aS,ge=ce===Qs?{side:s,sideOffset:l,align:c,alignOffset:d,arrowPadding:_,collisionBoundary:p,collisionPadding:m,sticky:g,hideWhenDetached:f,avoidCollisions:E}:{};return u.jsx(nS,{scope:n,content:h,viewport:R,onViewportChange:C,itemRefCallback:re,selectedItem:O,onItemLeave:q,itemTextRefCallback:X,focusSelectedItem:U,selectedItemText:w,position:r,isPositioned:z,searchRef:Y,children:u.jsx($a,{as:Ww,allowPinchZoom:!0,children:u.jsx(Ba,{asChild:!0,trapped:T.open,onMountAutoFocus:V=>{V.preventDefault()},onUnmountAutoFocus:de(a,V=>{var F;(F=T.trigger)==null||F.focus({preventScroll:!0}),V.preventDefault()}),children:u.jsx(Yr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:i,onPointerDownOutside:o,onFocusOutside:V=>V.preventDefault(),onDismiss:()=>T.onOpenChange(!1),children:u.jsx(ce,{role:"listbox",id:T.contentId,"data-state":T.open?"open":"closed",dir:T.dir,onContextMenu:V=>V.preventDefault(),...S,...ge,onPlaced:()=>P(!0),ref:N,style:{display:"flex",flexDirection:"column",outline:"none",...S.style},onKeyDown:de(S.onKeyDown,V=>{const F=V.ctrlKey||V.altKey||V.metaKey;if(V.key==="Tab"&&V.preventDefault(),!F&&V.key.length===1&&W(V.key),["ArrowUp","ArrowDown","Home","End"].includes(V.key)){let te=H().filter(le=>!le.disabled).map(le=>le.ref.current);if(["ArrowUp","End"].includes(V.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(V.key)){const le=V.target,oe=te.indexOf(le);te=te.slice(oe+1)}setTimeout(()=>I(te)),V.preventDefault()}})})})})})})});rS.displayName=$w;var Kw="SelectItemAlignedPosition",aS=b.forwardRef((t,e)=>{const{__scopeSelect:n,onPlaced:r,...a}=t,i=In(zn,n),o=An(zn,n),[s,l]=b.useState(null),[c,d]=b.useState(null),_=ke(e,N=>d(N)),p=xi(n),m=b.useRef(!1),g=b.useRef(!0),{viewport:f,selectedItem:E,selectedItemText:S,focusSelectedItem:T}=o,h=b.useCallback(()=>{if(i.trigger&&i.valueNode&&s&&c&&f&&E&&S){const N=i.trigger.getBoundingClientRect(),O=c.getBoundingClientRect(),D=i.valueNode.getBoundingClientRect(),w=S.getBoundingClientRect();if(i.dir!=="rtl"){const le=w.left-O.left,oe=D.left-le,Ae=N.left-oe,qe=N.width+Ae,Me=Math.max(qe,O.width),Se=window.innerWidth-Kt,Be=Fs(oe,[Kt,Math.max(Kt,Se-Me)]);s.style.minWidth=qe+"px",s.style.left=Be+"px"}else{const le=O.right-w.right,oe=window.innerWidth-D.right-le,Ae=window.innerWidth-N.right-oe,qe=N.width+Ae,Me=Math.max(qe,O.width),Se=window.innerWidth-Kt,Be=Fs(oe,[Kt,Math.max(Kt,Se-Me)]);s.style.minWidth=qe+"px",s.style.right=Be+"px"}const L=p(),H=window.innerHeight-Kt*2,z=f.scrollHeight,P=window.getComputedStyle(c),G=parseInt(P.borderTopWidth,10),I=parseInt(P.paddingTop,10),U=parseInt(P.borderBottomWidth,10),M=parseInt(P.paddingBottom,10),k=G+I+z+M+U,Y=Math.min(E.offsetHeight*5,k),W=window.getComputedStyle(f),re=parseInt(W.paddingTop,10),q=parseInt(W.paddingBottom,10),X=N.top+N.height/2-Kt,ce=H-X,ge=E.offsetHeight/2,V=E.offsetTop+ge,F=G+I+V,K=k-F;if(F<=X){const le=L.length>0&&E===L[L.length-1].ref.current;s.style.bottom="0px";const oe=c.clientHeight-f.offsetTop-f.offsetHeight,Ae=Math.max(ce,ge+(le?q:0)+oe+U),qe=F+Ae;s.style.height=qe+"px"}else{const le=L.length>0&&E===L[0].ref.current;s.style.top="0px";const Ae=Math.max(X,G+f.offsetTop+(le?re:0)+ge)+K;s.style.height=Ae+"px",f.scrollTop=F-X+f.offsetTop}s.style.margin=`${Kt}px 0`,s.style.minHeight=Y+"px",s.style.maxHeight=H+"px",r==null||r(),requestAnimationFrame(()=>m.current=!0)}},[p,i.trigger,i.valueNode,s,c,f,E,S,i.dir,r]);_t(()=>h(),[h]);const[v,R]=b.useState();_t(()=>{c&&R(window.getComputedStyle(c).zIndex)},[c]);const C=b.useCallback(N=>{N&&g.current===!0&&(h(),T==null||T(),g.current=!1)},[h,T]);return u.jsx(jw,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:m,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:v},children:u.jsx(ye.div,{...a,ref:_,style:{boxSizing:"border-box",maxHeight:"100%",...a.style}})})})});aS.displayName=Kw;var Qw="SelectPopperPosition",Qs=b.forwardRef((t,e)=>{const{__scopeSelect:n,align:r="start",collisionPadding:a=Kt,...i}=t,o=Di(n);return u.jsx(Ns,{...o,...i,ref:e,align:r,collisionPadding:a,style:{boxSizing:"border-box",...i.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Qs.displayName=Qw;var[jw,js]=Er(zn,{}),Xs="SelectViewport",iS=b.forwardRef((t,e)=>{const{__scopeSelect:n,nonce:r,...a}=t,i=An(Xs,n),o=js(Xs,n),s=ke(e,i.onViewportChange),l=b.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Ai.Slot,{scope:n,children:u.jsx(ye.div,{"data-radix-select-viewport":"",role:"presentation",...a,ref:s,style:{position:"relative",flex:1,overflow:"hidden auto",...a.style},onScroll:de(a.onScroll,c=>{const d=c.currentTarget,{contentWrapper:_,shouldExpandOnScrollRef:p}=o;if(p!=null&&p.current&&_){const m=Math.abs(l.current-d.scrollTop);if(m>0){const g=window.innerHeight-Kt*2,f=parseFloat(_.style.minHeight),E=parseFloat(_.style.height),S=Math.max(f,E);if(S<g){const T=S+m,h=Math.min(g,T),v=T-h;_.style.height=h+"px",_.style.bottom==="0px"&&(d.scrollTop=v>0?v:0,_.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});iS.displayName=Xs;var oS="SelectGroup",[Xw,Zw]=Er(oS),Jw=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,a=Vt();return u.jsx(Xw,{scope:n,id:a,children:u.jsx(ye.div,{role:"group","aria-labelledby":a,...r,ref:e})})});Jw.displayName=oS;var sS="SelectLabel",lS=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,a=Zw(sS,n);return u.jsx(ye.div,{id:a.id,...r,ref:e})});lS.displayName=sS;var wi="SelectItem",[eM,cS]=Er(wi),dS=b.forwardRef((t,e)=>{const{__scopeSelect:n,value:r,disabled:a=!1,textValue:i,...o}=t,s=In(wi,n),l=An(wi,n),c=s.value===r,[d,_]=b.useState(i??""),[p,m]=b.useState(!1),g=ke(e,T=>{var h;return(h=l.itemRefCallback)==null?void 0:h.call(l,T,r,a)}),f=Vt(),E=b.useRef("touch"),S=()=>{a||(s.onValueChange(r),s.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(eM,{scope:n,value:r,disabled:a,textId:f,isSelected:c,onItemTextChange:b.useCallback(T=>{_(h=>h||((T==null?void 0:T.textContent)??"").trim())},[]),children:u.jsx(Ai.ItemSlot,{scope:n,value:r,disabled:a,textValue:d,children:u.jsx(ye.div,{role:"option","aria-labelledby":f,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":a||void 0,"data-disabled":a?"":void 0,tabIndex:a?void 0:-1,...o,ref:g,onFocus:de(o.onFocus,()=>m(!0)),onBlur:de(o.onBlur,()=>m(!1)),onClick:de(o.onClick,()=>{E.current!=="mouse"&&S()}),onPointerUp:de(o.onPointerUp,()=>{E.current==="mouse"&&S()}),onPointerDown:de(o.onPointerDown,T=>{E.current=T.pointerType}),onPointerMove:de(o.onPointerMove,T=>{var h;E.current=T.pointerType,a?(h=l.onItemLeave)==null||h.call(l):E.current==="mouse"&&T.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(o.onPointerLeave,T=>{var h;T.currentTarget===document.activeElement&&((h=l.onItemLeave)==null||h.call(l))}),onKeyDown:de(o.onKeyDown,T=>{var v;((v=l.searchRef)==null?void 0:v.current)!==""&&T.key===" "||(Bw.includes(T.key)&&S(),T.key===" "&&T.preventDefault())})})})})});dS.displayName=wi;var ta="SelectItemText",uS=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:a,...i}=t,o=In(ta,n),s=An(ta,n),l=cS(ta,n),c=qw(ta,n),[d,_]=b.useState(null),p=ke(e,S=>_(S),l.onItemTextChange,S=>{var T;return(T=s.itemTextRefCallback)==null?void 0:T.call(s,S,l.value,l.disabled)}),m=d==null?void 0:d.textContent,g=b.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:m},l.value),[l.disabled,l.value,m]),{onNativeOptionAdd:f,onNativeOptionRemove:E}=c;return _t(()=>(f(g),()=>E(g)),[f,E,g]),u.jsxs(u.Fragment,{children:[u.jsx(ye.span,{id:l.textId,...i,ref:p}),l.isSelected&&o.valueNode&&!o.valueNodeHasChildren?oa.createPortal(i.children,o.valueNode):null]})});uS.displayName=ta;var _S="SelectItemIndicator",pS=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return cS(_S,n).isSelected?u.jsx(ye.span,{"aria-hidden":!0,...r,ref:e}):null});pS.displayName=_S;var Zs="SelectScrollUpButton",mS=b.forwardRef((t,e)=>{const n=An(Zs,t.__scopeSelect),r=js(Zs,t.__scopeSelect),[a,i]=b.useState(!1),o=ke(e,r.onScrollButtonChange);return _t(()=>{if(n.viewport&&n.isPositioned){let s=function(){const c=l.scrollTop>0;i(c)};const l=n.viewport;return s(),l.addEventListener("scroll",s),()=>l.removeEventListener("scroll",s)}},[n.viewport,n.isPositioned]),a?u.jsx(ES,{...t,ref:o,onAutoScroll:()=>{const{viewport:s,selectedItem:l}=n;s&&l&&(s.scrollTop=s.scrollTop-l.offsetHeight)}}):null});mS.displayName=Zs;var Js="SelectScrollDownButton",gS=b.forwardRef((t,e)=>{const n=An(Js,t.__scopeSelect),r=js(Js,t.__scopeSelect),[a,i]=b.useState(!1),o=ke(e,r.onScrollButtonChange);return _t(()=>{if(n.viewport&&n.isPositioned){let s=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;i(d)};const l=n.viewport;return s(),l.addEventListener("scroll",s),()=>l.removeEventListener("scroll",s)}},[n.viewport,n.isPositioned]),a?u.jsx(ES,{...t,ref:o,onAutoScroll:()=>{const{viewport:s,selectedItem:l}=n;s&&l&&(s.scrollTop=s.scrollTop+l.offsetHeight)}}):null});gS.displayName=Js;var ES=b.forwardRef((t,e)=>{const{__scopeSelect:n,onAutoScroll:r,...a}=t,i=An("SelectScrollButton",n),o=b.useRef(null),s=xi(n),l=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>l(),[l]),_t(()=>{var d;const c=s().find(_=>_.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[s]),u.jsx(ye.div,{"aria-hidden":!0,...a,ref:e,style:{flexShrink:0,...a.style},onPointerDown:de(a.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:de(a.onPointerMove,()=>{var c;(c=i.onItemLeave)==null||c.call(i),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:de(a.onPointerLeave,()=>{l()})})}),tM="SelectSeparator",fS=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return u.jsx(ye.div,{"aria-hidden":!0,...r,ref:e})});fS.displayName=tM;var el="SelectArrow",nM=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,a=Di(n),i=In(el,n),o=An(el,n);return i.open&&o.position==="popper"?u.jsx(Os,{...a,...r,ref:e}):null});nM.displayName=el;var rM="SelectBubbleInput",SS=b.forwardRef(({__scopeSelect:t,value:e,...n},r)=>{const a=b.useRef(null),i=ke(r,a),o=Yf(e);return b.useEffect(()=>{const s=a.current;if(!s)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(o!==e&&d){const _=new Event("change",{bubbles:!0});d.call(s,e),s.dispatchEvent(_)}},[o,e]),u.jsx(ye.select,{...n,style:{...gf,...n.style},ref:i,defaultValue:e})});SS.displayName=rM;function bS(t){return t===""||t===void 0}function TS(t){const e=pt(t),n=b.useRef(""),r=b.useRef(0),a=b.useCallback(o=>{const s=n.current+o;e(s),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(s)},[e]),i=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,a,i]}function hS(t,e,n){const a=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,i=n?t.indexOf(n):-1;let o=aM(t,Math.max(i,0));a.length===1&&(o=o.filter(c=>c!==n));const l=o.find(c=>c.textValue.toLowerCase().startsWith(a.toLowerCase()));return l!==n?l:void 0}function aM(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var iM=Kf,RS=jf,oM=Zf,sM=Jf,lM=eS,CS=tS,cM=iS,vS=lS,NS=dS,dM=uS,uM=pS,OS=mS,yS=gS,IS=fS;const AS=iM,xS=oM,tl=b.forwardRef(({className:t,children:e,...n},r)=>u.jsxs(RS,{ref:r,className:$("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t),...n,children:[e,u.jsx(sM,{asChild:!0,children:u.jsx(pe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));tl.displayName=RS.displayName;const DS=b.forwardRef(({className:t,...e},n)=>u.jsx(OS,{ref:n,className:$("flex cursor-default items-center justify-center py-1",t),...e,children:u.jsx(pe.ChevronUp,{className:"h-4 w-4"})}));DS.displayName=OS.displayName;const wS=b.forwardRef(({className:t,...e},n)=>u.jsx(yS,{ref:n,className:$("flex cursor-default items-center justify-center py-1",t),...e,children:u.jsx(pe.ChevronDown,{className:"h-4 w-4"})}));wS.displayName=yS.displayName;const nl=b.forwardRef(({className:t,children:e,position:n="popper",...r},a)=>u.jsx(lM,{children:u.jsxs(CS,{ref:a,className:$("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,...r,children:[u.jsx(DS,{}),u.jsx(cM,{className:$("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:e}),u.jsx(wS,{})]})}));nl.displayName=CS.displayName;const _M=b.forwardRef(({className:t,...e},n)=>u.jsx(vS,{ref:n,className:$("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...e}));_M.displayName=vS.displayName;const $n=b.forwardRef(({className:t,children:e,...n},r)=>u.jsxs(NS,{ref:r,className:$("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(uM,{children:u.jsx(pe.Check,{className:"h-4 w-4"})})}),u.jsx(dM,{children:e})]}));$n.displayName=NS.displayName;const pM=b.forwardRef(({className:t,...e},n)=>u.jsx(IS,{ref:n,className:$("-mx-1 my-1 h-px bg-muted",t),...e}));pM.displayName=IS.displayName;const Mi=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,className:$("rounded-lg border bg-card text-card-foreground shadow-sm",t),...e}));Mi.displayName="Card";const Li=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,className:$("flex flex-col space-y-1.5 p-6",t),...e}));Li.displayName="CardHeader";const Pi=b.forwardRef(({className:t,...e},n)=>u.jsx("h3",{ref:n,className:$("text-2xl font-semibold leading-none tracking-tight",t),...e}));Pi.displayName="CardTitle";const mM=b.forwardRef(({className:t,...e},n)=>u.jsx("p",{ref:n,className:$("text-sm text-muted-foreground",t),...e}));mM.displayName="CardDescription";const ki=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,className:$("p-6 pt-0",t),...e}));ki.displayName="CardContent";const gM=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,className:$("flex items-center p-6 pt-0",t),...e}));gM.displayName="CardFooter";const EM={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function fM({settings:t,onSettingsChange:e,className:n=""}){const[r,a]=y.useState(!1),[i,o]=y.useState(!1),[s,l]=y.useState(t),[c,d]=y.useState(!1),{toast:_}=Wo();y.useEffect(()=>{const E=JSON.stringify(s)!==JSON.stringify(t);d(E)},[s,t]),y.useEffect(()=>{l(t)},[t]);const p=()=>{e(s),d(!1),_({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},m=()=>{l(EM),d(!0),_({title:"Settings reset",description:"Configuration has been reset to defaults."})},g=()=>{l(t),d(!1),a(!1)},f=async()=>{try{const S=await(await fetch(`${s.api.baseUrl}/health`)).json();_({title:"Connection successful",description:`API is ${S.status||"healthy"}`})}catch{_({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(cf,{open:r,onOpenChange:a,children:[u.jsx(BD,{asChild:!0,children:u.jsxs(Ve,{variant:"outline",size:"sm",className:n,children:[u.jsx(pe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(zp,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(zs,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(uf,{children:[u.jsx(_f,{children:"Chat Settings"}),u.jsx(pf,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Mi,{children:[u.jsx(Li,{className:"pb-3",children:u.jsxs(Pi,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(ki,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Bt,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Jr,{id:"api-url",value:s.api.baseUrl,onChange:E=>l(S=>({...S,api:{...S.api,baseUrl:E.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Ve,{variant:"outline",onClick:f,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Bt,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(yn,{id:"enable-auth",checked:s.api.enableAuth,onCheckedChange:E=>l(S=>({...S,api:{...S.api,enableAuth:E}}))})]}),s.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(Bt,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Jr,{id:"auth-token",type:i?"text":"password",value:s.api.authToken,onChange:E=>l(S=>({...S,api:{...S.api,authToken:E.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Ve,{variant:"outline",size:"icon",onClick:()=>o(!i),children:i?u.jsx(pe.EyeOff,{className:"h-4 w-4"}):u.jsx(pe.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(Mi,{children:[u.jsx(Li,{className:"pb-3",children:u.jsxs(Pi,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(ki,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Bt,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(AS,{value:s.ui.layout,onValueChange:E=>l(S=>({...S,ui:{...S.ui,layout:E}})),children:[u.jsx(tl,{children:u.jsx(xS,{})}),u.jsxs(nl,{children:[u.jsx($n,{value:"sidebar",children:"Sidebar Layout"}),u.jsx($n,{value:"fullscreen",children:"Fullscreen"}),u.jsx($n,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Bt,{htmlFor:"theme",children:"Theme"}),u.jsxs(AS,{value:s.ui.theme,onValueChange:E=>l(S=>({...S,ui:{...S.ui,theme:E}})),children:[u.jsx(tl,{children:u.jsx(xS,{})}),u.jsxs(nl,{children:[u.jsx($n,{value:"light",children:"Light"}),u.jsx($n,{value:"dark",children:"Dark"}),u.jsx($n,{value:"system",children:"System"})]})]})]}),u.jsx(Vs,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Bt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(yn,{id:"show-timestamps",checked:s.ui.showTimestamps,onCheckedChange:E=>l(S=>({...S,ui:{...S.ui,showTimestamps:E}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Bt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(yn,{id:"show-agent-names",checked:s.ui.showAgentNames,onCheckedChange:E=>l(S=>({...S,ui:{...S.ui,showAgentNames:E}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Bt,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(yn,{id:"compact-messages",checked:s.ui.compactMessages,onCheckedChange:E=>l(S=>({...S,ui:{...S.ui,compactMessages:E}}))})]})]})]})]}),u.jsxs(Mi,{children:[u.jsx(Li,{className:"pb-3",children:u.jsxs(Pi,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(ki,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Bt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(yn,{id:"auto-save",checked:s.behavior.autoSave,onCheckedChange:E=>l(S=>({...S,behavior:{...S.behavior,autoSave:E}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Bt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(yn,{id:"enable-streaming",checked:s.behavior.enableStreaming,onCheckedChange:E=>l(S=>({...S,behavior:{...S.behavior,enableStreaming:E}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Bt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(yn,{id:"typing-indicator",checked:s.behavior.showTypingIndicator,onCheckedChange:E=>l(S=>({...S,behavior:{...S.behavior,showTypingIndicator:E}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Ve,{variant:"outline",onClick:m,children:[u.jsx(pe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ve,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(Ve,{onClick:p,disabled:!c,children:[u.jsx(pe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function SM({layout:t="sidebar",layoutSize:e="desktop",showThreads:n=!0,className:r="",customStyles:a={},...i}){const o=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},s=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=y.useCallback(c=>{var d;(d=i.onThreadChange)==null||d.call(i,c)},[i.onThreadChange]);return t==="fullscreen"?u.jsx(yr,{...i,onThreadChange:l,children:u.jsx("div",{className:`${o(e)} flex flex-col overflow-hidden ${r} ${a.container||""}`,style:s(e),children:u.jsx(Zr,{className:"flex-1",onError:i.onError,enableFileUpload:!0})})}):t==="tabs"?u.jsx(yr,{...i,onThreadChange:l,children:u.jsx("div",{className:`${o(e)} flex flex-col overflow-hidden ${r} ${a.container||""}`,style:s(e),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${a.sidebar||""}`,children:u.jsx(Ci,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${a.chatArea||""}`,children:u.jsx(Zr,{onError:i.onError,enableFileUpload:!0})})]})})}):u.jsx(yr,{...i,onThreadChange:l,children:u.jsxs("div",{className:`${o(e)} flex overflow-hidden ${r} ${a.container||""}`,style:s(e),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${a.sidebar||""}`,children:u.jsx(Ci,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${a.chatArea||""}`,children:u.jsx(Zr,{onError:i.onError,enableFileUpload:!0})})]})})}function rl(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let xn=rl();function bM(t){xn=t}const MS=/[&<>"']/,TM=new RegExp(MS.source,"g"),LS=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,hM=new RegExp(LS.source,"g"),RM={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},PS=t=>RM[t];function ft(t,e){if(e){if(MS.test(t))return t.replace(TM,PS)}else if(LS.test(t))return t.replace(hM,PS);return t}const CM=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function kS(t){return t.replace(CM,(e,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const vM=/(^|[^\[])\^/g;function Ze(t,e){t=typeof t=="string"?t:t.source,e=e||"";const n={replace:(r,a)=>(a=a.source||a,a=a.replace(vM,"$1"),t=t.replace(r,a),n),getRegex:()=>new RegExp(t,e)};return n}const NM=/[^\w:]/g,OM=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function US(t,e,n){if(t){let r;try{r=decodeURIComponent(kS(n)).replace(NM,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}e&&!OM.test(n)&&(n=xM(e,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ui={},yM=/^[^:]+:\/*[^/]*$/,IM=/^([^:]+:)[\s\S]*$/,AM=/^([^:]+:\/*[^/]*)[\s\S]*$/;function xM(t,e){Ui[" "+t]||(yM.test(t)?Ui[" "+t]=t+"/":Ui[" "+t]=Bi(t,"/",!0)),t=Ui[" "+t];const n=t.indexOf(":")===-1;return e.substring(0,2)==="//"?n?e:t.replace(IM,"$1")+e:e.charAt(0)==="/"?n?e:t.replace(AM,"$1")+e:t+e}const Fi={exec:function(){}};function FS(t,e){const n=t.replace(/\|/g,(i,o,s)=>{let l=!1,c=o;for(;--c>=0&&s[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let a=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;a<r.length;a++)r[a]=r[a].trim().replace(/\\\|/g,"|");return r}function Bi(t,e,n){const r=t.length;if(r===0)return"";let a=0;for(;a<r;){const i=t.charAt(r-a-1);if(i===e&&!n)a++;else if(i!==e&&n)a++;else break}return t.slice(0,r-a)}function DM(t,e){if(t.indexOf(e[1])===-1)return-1;const n=t.length;let r=0,a=0;for(;a<n;a++)if(t[a]==="\\")a++;else if(t[a]===e[0])r++;else if(t[a]===e[1]&&(r--,r<0))return a;return-1}function wM(t){t&&t.sanitize&&!t.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function BS(t,e){if(e<1)return"";let n="";for(;e>1;)e&1&&(n+=t),e>>=1,t+=t;return n+t}function GS(t,e,n,r){const a=e.href,i=e.title?ft(e.title):null,o=t[1].replace(/\\([\[\]])/g,"$1");if(t[0].charAt(0)!=="!"){r.state.inLink=!0;const s={type:"link",raw:n,href:a,title:i,text:o,tokens:r.inlineTokens(o)};return r.state.inLink=!1,s}return{type:"image",raw:n,href:a,title:i,text:ft(o)}}function MM(t,e){const n=t.match(/^(\s+)(?:```)/);if(n===null)return e;const r=n[1];return e.split(`
86
+ `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function bI(t,e=ni){if(!t||typeof t!="string")throw new Error("Invalid content: must be a non-empty string");if(t.length>e)throw new Error(`Message exceeds maximum length of ${e} characters`);return t}function TI(t){let e;return typeof t=="string"?e=t:typeof t=="object"&&t!==null?e=JSON.stringify(t):e=String(t),bI(e),SI(e)}function cs(t){const e=t+"CollectionProvider",[n,r]=qt(e),[a,i]=n(e,{collectionRef:{current:null},itemMap:new Map}),o=f=>{const{scope:E,children:S}=f,T=y.useRef(null),h=y.useRef(new Map).current;return u.jsx(a,{scope:E,itemMap:h,collectionRef:T,children:S})};o.displayName=e;const s=t+"CollectionSlot",l=Nt.createSlot(s),c=y.forwardRef((f,E)=>{const{scope:S,children:T}=f,h=i(s,S),v=ke(E,h.collectionRef);return u.jsx(l,{ref:v,children:T})});c.displayName=s;const d=t+"CollectionItemSlot",_="data-radix-collection-item",p=Nt.createSlot(d),m=y.forwardRef((f,E)=>{const{scope:S,children:T,...h}=f,v=y.useRef(null),R=ke(E,v),C=i(d,S);return y.useEffect(()=>(C.itemMap.set(v,{ref:v,...h}),()=>void C.itemMap.delete(v))),u.jsx(p,{[_]:"",ref:R,children:T})});m.displayName=d;function g(f){const E=i(t+"CollectionConsumer",f);return y.useCallback(()=>{const T=E.collectionRef.current;if(!T)return[];const h=Array.from(T.querySelectorAll(`[${_}]`));return Array.from(E.itemMap.values()).sort((C,N)=>h.indexOf(C.ref.current)-h.indexOf(N.ref.current))},[E.collectionRef,E.itemMap])}return[{Provider:o,Slot:c,ItemSlot:m},g,r]}var hI=b.createContext(void 0);function ri(t){const e=b.useContext(hI);return t||e||"ltr"}const RI=["top","right","bottom","left"],Nn=Math.min,It=Math.max,ai=Math.round,ii=Math.floor,tn=t=>({x:t,y:t}),CI={left:"right",right:"left",bottom:"top",top:"bottom"},vI={start:"end",end:"start"};function ds(t,e,n){return It(t,Nn(e,n))}function un(t,e){return typeof t=="function"?t(e):t}function _n(t){return t.split("-")[0]}function lr(t){return t.split("-")[1]}function us(t){return t==="x"?"y":"x"}function _s(t){return t==="y"?"height":"width"}const NI=new Set(["top","bottom"]);function nn(t){return NI.has(_n(t))?"y":"x"}function ps(t){return us(nn(t))}function OI(t,e,n){n===void 0&&(n=!1);const r=lr(t),a=ps(t),i=_s(a);let o=a==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[i]>e.floating[i]&&(o=oi(o)),[o,oi(o)]}function yI(t){const e=oi(t);return[ms(t),e,ms(e)]}function ms(t){return t.replace(/start|end/g,e=>vI[e])}const rg=["left","right"],ag=["right","left"],II=["top","bottom"],AI=["bottom","top"];function xI(t,e,n){switch(t){case"top":case"bottom":return n?e?ag:rg:e?rg:ag;case"left":case"right":return e?II:AI;default:return[]}}function DI(t,e,n,r){const a=lr(t);let i=xI(_n(t),n==="start",r);return a&&(i=i.map(o=>o+"-"+a),e&&(i=i.concat(i.map(ms)))),i}function oi(t){return t.replace(/left|right|bottom|top/g,e=>CI[e])}function wI(t){return{top:0,right:0,bottom:0,left:0,...t}}function ig(t){return typeof t!="number"?wI(t):{top:t,right:t,bottom:t,left:t}}function si(t){const{x:e,y:n,width:r,height:a}=t;return{width:r,height:a,top:n,left:e,right:e+r,bottom:n+a,x:e,y:n}}function og(t,e,n){let{reference:r,floating:a}=t;const i=nn(e),o=ps(e),s=_s(o),l=_n(e),c=i==="y",d=r.x+r.width/2-a.width/2,_=r.y+r.height/2-a.height/2,p=r[s]/2-a[s]/2;let m;switch(l){case"top":m={x:d,y:r.y-a.height};break;case"bottom":m={x:d,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:_};break;case"left":m={x:r.x-a.width,y:_};break;default:m={x:r.x,y:r.y}}switch(lr(e)){case"start":m[o]-=p*(n&&c?-1:1);break;case"end":m[o]+=p*(n&&c?-1:1);break}return m}const MI=async(t,e,n)=>{const{placement:r="bottom",strategy:a="absolute",middleware:i=[],platform:o}=n,s=i.filter(Boolean),l=await(o.isRTL==null?void 0:o.isRTL(e));let c=await o.getElementRects({reference:t,floating:e,strategy:a}),{x:d,y:_}=og(c,r,l),p=r,m={},g=0;for(let f=0;f<s.length;f++){const{name:E,fn:S}=s[f],{x:T,y:h,data:v,reset:R}=await S({x:d,y:_,initialPlacement:r,placement:p,strategy:a,middlewareData:m,rects:c,platform:o,elements:{reference:t,floating:e}});d=T??d,_=h??_,m={...m,[E]:{...m[E],...v}},R&&g<=50&&(g++,typeof R=="object"&&(R.placement&&(p=R.placement),R.rects&&(c=R.rects===!0?await o.getElementRects({reference:t,floating:e,strategy:a}):R.rects),{x:d,y:_}=og(c,p,l)),f=-1)}return{x:d,y:_,placement:p,strategy:a,middlewareData:m}};async function qr(t,e){var n;e===void 0&&(e={});const{x:r,y:a,platform:i,rects:o,elements:s,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:_="floating",altBoundary:p=!1,padding:m=0}=un(e,t),g=ig(m),E=s[p?_==="floating"?"reference":"floating":_],S=si(await i.getClippingRect({element:(n=await(i.isElement==null?void 0:i.isElement(E)))==null||n?E:E.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(s.floating)),boundary:c,rootBoundary:d,strategy:l})),T=_==="floating"?{x:r,y:a,width:o.floating.width,height:o.floating.height}:o.reference,h=await(i.getOffsetParent==null?void 0:i.getOffsetParent(s.floating)),v=await(i.isElement==null?void 0:i.isElement(h))?await(i.getScale==null?void 0:i.getScale(h))||{x:1,y:1}:{x:1,y:1},R=si(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:s,rect:T,offsetParent:h,strategy:l}):T);return{top:(S.top-R.top+g.top)/v.y,bottom:(R.bottom-S.bottom+g.bottom)/v.y,left:(S.left-R.left+g.left)/v.x,right:(R.right-S.right+g.right)/v.x}}const LI=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:a,rects:i,platform:o,elements:s,middlewareData:l}=e,{element:c,padding:d=0}=un(t,e)||{};if(c==null)return{};const _=ig(d),p={x:n,y:r},m=ps(a),g=_s(m),f=await o.getDimensions(c),E=m==="y",S=E?"top":"left",T=E?"bottom":"right",h=E?"clientHeight":"clientWidth",v=i.reference[g]+i.reference[m]-p[m]-i.floating[g],R=p[m]-i.reference[m],C=await(o.getOffsetParent==null?void 0:o.getOffsetParent(c));let N=C?C[h]:0;(!N||!await(o.isElement==null?void 0:o.isElement(C)))&&(N=s.floating[h]||i.floating[g]);const O=v/2-R/2,D=N/2-f[g]/2-1,w=Nn(_[S],D),L=Nn(_[T],D),H=w,z=N-f[g]-L,P=N/2-f[g]/2+O,G=ds(H,P,z),I=!l.arrow&&lr(a)!=null&&P!==G&&i.reference[g]/2-(P<H?w:L)-f[g]/2<0,U=I?P<H?P-H:P-z:0;return{[m]:p[m]+U,data:{[m]:G,centerOffset:P-G-U,...I&&{alignmentOffset:U}},reset:I}}}),PI=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:a,middlewareData:i,rects:o,initialPlacement:s,platform:l,elements:c}=e,{mainAxis:d=!0,crossAxis:_=!0,fallbackPlacements:p,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:f=!0,...E}=un(t,e);if((n=i.arrow)!=null&&n.alignmentOffset)return{};const S=_n(a),T=nn(s),h=_n(s)===s,v=await(l.isRTL==null?void 0:l.isRTL(c.floating)),R=p||(h||!f?[oi(s)]:yI(s)),C=g!=="none";!p&&C&&R.push(...DI(s,f,g,v));const N=[s,...R],O=await qr(e,E),D=[];let w=((r=i.flip)==null?void 0:r.overflows)||[];if(d&&D.push(O[S]),_){const P=OI(a,o,v);D.push(O[P[0]],O[P[1]])}if(w=[...w,{placement:a,overflows:D}],!D.every(P=>P<=0)){var L,H;const P=(((L=i.flip)==null?void 0:L.index)||0)+1,G=N[P];if(G&&(!(_==="alignment"?T!==nn(G):!1)||w.every(M=>nn(M.placement)===T?M.overflows[0]>0:!0)))return{data:{index:P,overflows:w},reset:{placement:G}};let I=(H=w.filter(U=>U.overflows[0]<=0).sort((U,M)=>U.overflows[1]-M.overflows[1])[0])==null?void 0:H.placement;if(!I)switch(m){case"bestFit":{var z;const U=(z=w.filter(M=>{if(C){const k=nn(M.placement);return k===T||k==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(k=>k>0).reduce((k,Y)=>k+Y,0)]).sort((M,k)=>M[1]-k[1])[0])==null?void 0:z[0];U&&(I=U);break}case"initialPlacement":I=s;break}if(a!==I)return{reset:{placement:I}}}return{}}}};function sg(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function lg(t){return RI.some(e=>t[e]>=0)}const kI=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...a}=un(t,e);switch(r){case"referenceHidden":{const i=await qr(e,{...a,elementContext:"reference"}),o=sg(i,n.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:lg(o)}}}case"escaped":{const i=await qr(e,{...a,altBoundary:!0}),o=sg(i,n.floating);return{data:{escapedOffsets:o,escaped:lg(o)}}}default:return{}}}}},cg=new Set(["left","top"]);async function UI(t,e){const{placement:n,platform:r,elements:a}=t,i=await(r.isRTL==null?void 0:r.isRTL(a.floating)),o=_n(n),s=lr(n),l=nn(n)==="y",c=cg.has(o)?-1:1,d=i&&l?-1:1,_=un(e,t);let{mainAxis:p,crossAxis:m,alignmentAxis:g}=typeof _=="number"?{mainAxis:_,crossAxis:0,alignmentAxis:null}:{mainAxis:_.mainAxis||0,crossAxis:_.crossAxis||0,alignmentAxis:_.alignmentAxis};return s&&typeof g=="number"&&(m=s==="end"?g*-1:g),l?{x:m*d,y:p*c}:{x:p*c,y:m*d}}const FI=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:a,y:i,placement:o,middlewareData:s}=e,l=await UI(e,t);return o===((n=s.offset)==null?void 0:n.placement)&&(r=s.arrow)!=null&&r.alignmentOffset?{}:{x:a+l.x,y:i+l.y,data:{...l,placement:o}}}}},BI=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:a}=e,{mainAxis:i=!0,crossAxis:o=!1,limiter:s={fn:E=>{let{x:S,y:T}=E;return{x:S,y:T}}},...l}=un(t,e),c={x:n,y:r},d=await qr(e,l),_=nn(_n(a)),p=us(_);let m=c[p],g=c[_];if(i){const E=p==="y"?"top":"left",S=p==="y"?"bottom":"right",T=m+d[E],h=m-d[S];m=ds(T,m,h)}if(o){const E=_==="y"?"top":"left",S=_==="y"?"bottom":"right",T=g+d[E],h=g-d[S];g=ds(T,g,h)}const f=s.fn({...e,[p]:m,[_]:g});return{...f,data:{x:f.x-n,y:f.y-r,enabled:{[p]:i,[_]:o}}}}}},GI=function(t){return t===void 0&&(t={}),{options:t,fn(e){const{x:n,y:r,placement:a,rects:i,middlewareData:o}=e,{offset:s=0,mainAxis:l=!0,crossAxis:c=!0}=un(t,e),d={x:n,y:r},_=nn(a),p=us(_);let m=d[p],g=d[_];const f=un(s,e),E=typeof f=="number"?{mainAxis:f,crossAxis:0}:{mainAxis:0,crossAxis:0,...f};if(l){const h=p==="y"?"height":"width",v=i.reference[p]-i.floating[h]+E.mainAxis,R=i.reference[p]+i.reference[h]-E.mainAxis;m<v?m=v:m>R&&(m=R)}if(c){var S,T;const h=p==="y"?"width":"height",v=cg.has(_n(a)),R=i.reference[_]-i.floating[h]+(v&&((S=o.offset)==null?void 0:S[_])||0)+(v?0:E.crossAxis),C=i.reference[_]+i.reference[h]+(v?0:((T=o.offset)==null?void 0:T[_])||0)-(v?E.crossAxis:0);g<R?g=R:g>C&&(g=C)}return{[p]:m,[_]:g}}}},YI=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var n,r;const{placement:a,rects:i,platform:o,elements:s}=e,{apply:l=()=>{},...c}=un(t,e),d=await qr(e,c),_=_n(a),p=lr(a),m=nn(a)==="y",{width:g,height:f}=i.floating;let E,S;_==="top"||_==="bottom"?(E=_,S=p===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(S=_,E=p==="end"?"top":"bottom");const T=f-d.top-d.bottom,h=g-d.left-d.right,v=Nn(f-d[E],T),R=Nn(g-d[S],h),C=!e.middlewareData.shift;let N=v,O=R;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(O=h),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(N=T),C&&!p){const w=It(d.left,0),L=It(d.right,0),H=It(d.top,0),z=It(d.bottom,0);m?O=g-2*(w!==0||L!==0?w+L:It(d.left,d.right)):N=f-2*(H!==0||z!==0?H+z:It(d.top,d.bottom))}await l({...e,availableWidth:O,availableHeight:N});const D=await o.getDimensions(s.floating);return g!==D.width||f!==D.height?{reset:{rects:!0}}:{}}}};function li(){return typeof window<"u"}function cr(t){return dg(t)?(t.nodeName||"").toLowerCase():"#document"}function At(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function rn(t){var e;return(e=(dg(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function dg(t){return li()?t instanceof Node||t instanceof At(t).Node:!1}function $t(t){return li()?t instanceof Element||t instanceof At(t).Element:!1}function an(t){return li()?t instanceof HTMLElement||t instanceof At(t).HTMLElement:!1}function ug(t){return!li()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof At(t).ShadowRoot}const HI=new Set(["inline","contents"]);function Vr(t){const{overflow:e,overflowX:n,overflowY:r,display:a}=Wt(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!HI.has(a)}const qI=new Set(["table","td","th"]);function VI(t){return qI.has(cr(t))}const zI=[":popover-open",":modal"];function ci(t){return zI.some(e=>{try{return t.matches(e)}catch{return!1}})}const $I=["transform","translate","scale","rotate","perspective"],WI=["transform","translate","scale","rotate","perspective","filter"],KI=["paint","layout","strict","content"];function gs(t){const e=Es(),n=$t(t)?Wt(t):t;return $I.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||WI.some(r=>(n.willChange||"").includes(r))||KI.some(r=>(n.contain||"").includes(r))}function QI(t){let e=On(t);for(;an(e)&&!dr(e);){if(gs(e))return e;if(ci(e))return null;e=On(e)}return null}function Es(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const jI=new Set(["html","body","#document"]);function dr(t){return jI.has(cr(t))}function Wt(t){return At(t).getComputedStyle(t)}function di(t){return $t(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function On(t){if(cr(t)==="html")return t;const e=t.assignedSlot||t.parentNode||ug(t)&&t.host||rn(t);return ug(e)?e.host:e}function _g(t){const e=On(t);return dr(e)?t.ownerDocument?t.ownerDocument.body:t.body:an(e)&&Vr(e)?e:_g(e)}function zr(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const a=_g(t),i=a===((r=t.ownerDocument)==null?void 0:r.body),o=At(a);if(i){const s=fs(o);return e.concat(o,o.visualViewport||[],Vr(a)?a:[],s&&n?zr(s):[])}return e.concat(a,zr(a,[],n))}function fs(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function pg(t){const e=Wt(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const a=an(t),i=a?t.offsetWidth:n,o=a?t.offsetHeight:r,s=ai(n)!==i||ai(r)!==o;return s&&(n=i,r=o),{width:n,height:r,$:s}}function Ss(t){return $t(t)?t:t.contextElement}function ur(t){const e=Ss(t);if(!an(e))return tn(1);const n=e.getBoundingClientRect(),{width:r,height:a,$:i}=pg(e);let o=(i?ai(n.width):n.width)/r,s=(i?ai(n.height):n.height)/a;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}const XI=tn(0);function mg(t){const e=At(t);return!Es()||!e.visualViewport?XI:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ZI(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==At(t)?!1:e}function Yn(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const a=t.getBoundingClientRect(),i=Ss(t);let o=tn(1);e&&(r?$t(r)&&(o=ur(r)):o=ur(t));const s=ZI(i,n,r)?mg(i):tn(0);let l=(a.left+s.x)/o.x,c=(a.top+s.y)/o.y,d=a.width/o.x,_=a.height/o.y;if(i){const p=At(i),m=r&&$t(r)?At(r):r;let g=p,f=fs(g);for(;f&&r&&m!==g;){const E=ur(f),S=f.getBoundingClientRect(),T=Wt(f),h=S.left+(f.clientLeft+parseFloat(T.paddingLeft))*E.x,v=S.top+(f.clientTop+parseFloat(T.paddingTop))*E.y;l*=E.x,c*=E.y,d*=E.x,_*=E.y,l+=h,c+=v,g=At(f),f=fs(g)}}return si({width:d,height:_,x:l,y:c})}function ui(t,e){const n=di(t).scrollLeft;return e?e.left+n:Yn(rn(t)).left+n}function gg(t,e){const n=t.getBoundingClientRect(),r=n.left+e.scrollLeft-ui(t,n),a=n.top+e.scrollTop;return{x:r,y:a}}function JI(t){let{elements:e,rect:n,offsetParent:r,strategy:a}=t;const i=a==="fixed",o=rn(r),s=e?ci(e.floating):!1;if(r===o||s&&i)return n;let l={scrollLeft:0,scrollTop:0},c=tn(1);const d=tn(0),_=an(r);if((_||!_&&!i)&&((cr(r)!=="body"||Vr(o))&&(l=di(r)),an(r))){const m=Yn(r);c=ur(r),d.x=m.x+r.clientLeft,d.y=m.y+r.clientTop}const p=o&&!_&&!i?gg(o,l):tn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function eA(t){return Array.from(t.getClientRects())}function tA(t){const e=rn(t),n=di(t),r=t.ownerDocument.body,a=It(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),i=It(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+ui(t);const s=-n.scrollTop;return Wt(r).direction==="rtl"&&(o+=It(e.clientWidth,r.clientWidth)-a),{width:a,height:i,x:o,y:s}}const Eg=25;function nA(t,e){const n=At(t),r=rn(t),a=n.visualViewport;let i=r.clientWidth,o=r.clientHeight,s=0,l=0;if(a){i=a.width,o=a.height;const d=Es();(!d||d&&e==="fixed")&&(s=a.offsetLeft,l=a.offsetTop)}const c=ui(r);if(c<=0){const d=r.ownerDocument,_=d.body,p=getComputedStyle(_),m=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,g=Math.abs(r.clientWidth-_.clientWidth-m);g<=Eg&&(i-=g)}else c<=Eg&&(i+=c);return{width:i,height:o,x:s,y:l}}const rA=new Set(["absolute","fixed"]);function aA(t,e){const n=Yn(t,!0,e==="fixed"),r=n.top+t.clientTop,a=n.left+t.clientLeft,i=an(t)?ur(t):tn(1),o=t.clientWidth*i.x,s=t.clientHeight*i.y,l=a*i.x,c=r*i.y;return{width:o,height:s,x:l,y:c}}function fg(t,e,n){let r;if(e==="viewport")r=nA(t,n);else if(e==="document")r=tA(rn(t));else if($t(e))r=aA(e,n);else{const a=mg(t);r={x:e.x-a.x,y:e.y-a.y,width:e.width,height:e.height}}return si(r)}function Sg(t,e){const n=On(t);return n===e||!$t(n)||dr(n)?!1:Wt(n).position==="fixed"||Sg(n,e)}function iA(t,e){const n=e.get(t);if(n)return n;let r=zr(t,[],!1).filter(s=>$t(s)&&cr(s)!=="body"),a=null;const i=Wt(t).position==="fixed";let o=i?On(t):t;for(;$t(o)&&!dr(o);){const s=Wt(o),l=gs(o);!l&&s.position==="fixed"&&(a=null),(i?!l&&!a:!l&&s.position==="static"&&!!a&&rA.has(a.position)||Vr(o)&&!l&&Sg(t,o))?r=r.filter(d=>d!==o):a=s,o=On(o)}return e.set(t,r),r}function oA(t){let{element:e,boundary:n,rootBoundary:r,strategy:a}=t;const o=[...n==="clippingAncestors"?ci(e)?[]:iA(e,this._c):[].concat(n),r],s=o[0],l=o.reduce((c,d)=>{const _=fg(e,d,a);return c.top=It(_.top,c.top),c.right=Nn(_.right,c.right),c.bottom=Nn(_.bottom,c.bottom),c.left=It(_.left,c.left),c},fg(e,s,a));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function sA(t){const{width:e,height:n}=pg(t);return{width:e,height:n}}function lA(t,e,n){const r=an(e),a=rn(e),i=n==="fixed",o=Yn(t,!0,i,e);let s={scrollLeft:0,scrollTop:0};const l=tn(0);function c(){l.x=ui(a)}if(r||!r&&!i)if((cr(e)!=="body"||Vr(a))&&(s=di(e)),r){const m=Yn(e,!0,i,e);l.x=m.x+e.clientLeft,l.y=m.y+e.clientTop}else a&&c();i&&!r&&a&&c();const d=a&&!r&&!i?gg(a,s):tn(0),_=o.left+s.scrollLeft-l.x-d.x,p=o.top+s.scrollTop-l.y-d.y;return{x:_,y:p,width:o.width,height:o.height}}function bs(t){return Wt(t).position==="static"}function bg(t,e){if(!an(t)||Wt(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return rn(t)===n&&(n=n.ownerDocument.body),n}function Tg(t,e){const n=At(t);if(ci(t))return n;if(!an(t)){let a=On(t);for(;a&&!dr(a);){if($t(a)&&!bs(a))return a;a=On(a)}return n}let r=bg(t,e);for(;r&&VI(r)&&bs(r);)r=bg(r,e);return r&&dr(r)&&bs(r)&&!gs(r)?n:r||QI(t)||n}const cA=async function(t){const e=this.getOffsetParent||Tg,n=this.getDimensions,r=await n(t.floating);return{reference:lA(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function dA(t){return Wt(t).direction==="rtl"}const uA={convertOffsetParentRelativeRectToViewportRelativeRect:JI,getDocumentElement:rn,getClippingRect:oA,getOffsetParent:Tg,getElementRects:cA,getClientRects:eA,getDimensions:sA,getScale:ur,isElement:$t,isRTL:dA};function hg(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function _A(t,e){let n=null,r;const a=rn(t);function i(){var s;clearTimeout(r),(s=n)==null||s.disconnect(),n=null}function o(s,l){s===void 0&&(s=!1),l===void 0&&(l=1),i();const c=t.getBoundingClientRect(),{left:d,top:_,width:p,height:m}=c;if(s||e(),!p||!m)return;const g=ii(_),f=ii(a.clientWidth-(d+p)),E=ii(a.clientHeight-(_+m)),S=ii(d),h={rootMargin:-g+"px "+-f+"px "+-E+"px "+-S+"px",threshold:It(0,Nn(1,l))||1};let v=!0;function R(C){const N=C[0].intersectionRatio;if(N!==l){if(!v)return o();N?o(!1,N):r=setTimeout(()=>{o(!1,1e-7)},1e3)}N===1&&!hg(c,t.getBoundingClientRect())&&o(),v=!1}try{n=new IntersectionObserver(R,{...h,root:a.ownerDocument})}catch{n=new IntersectionObserver(R,h)}n.observe(t)}return o(!0),i}function pA(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:a=!0,ancestorResize:i=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:s=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Ss(t),d=a||i?[...c?zr(c):[],...zr(e)]:[];d.forEach(S=>{a&&S.addEventListener("scroll",n,{passive:!0}),i&&S.addEventListener("resize",n)});const _=c&&s?_A(c,n):null;let p=-1,m=null;o&&(m=new ResizeObserver(S=>{let[T]=S;T&&T.target===c&&m&&(m.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var h;(h=m)==null||h.observe(e)})),n()}),c&&!l&&m.observe(c),m.observe(e));let g,f=l?Yn(t):null;l&&E();function E(){const S=Yn(t);f&&!hg(f,S)&&n(),f=S,g=requestAnimationFrame(E)}return n(),()=>{var S;d.forEach(T=>{a&&T.removeEventListener("scroll",n),i&&T.removeEventListener("resize",n)}),_==null||_(),(S=m)==null||S.disconnect(),m=null,l&&cancelAnimationFrame(g)}}const mA=FI,gA=BI,EA=PI,fA=YI,SA=kI,Rg=LI,bA=GI,TA=(t,e,n)=>{const r=new Map,a={platform:uA,...n},i={...a.platform,_c:r};return MI(t,e,{...a,platform:i})};var hA=typeof document<"u",RA=function(){},_i=hA?y.useLayoutEffect:RA;function pi(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,a;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!pi(t[r],e[r]))return!1;return!0}if(a=Object.keys(t),n=a.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,a[r]))return!1;for(r=n;r--!==0;){const i=a[r];if(!(i==="_owner"&&t.$$typeof)&&!pi(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}function Cg(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function vg(t,e){const n=Cg(t);return Math.round(e*n)/n}function Ts(t){const e=b.useRef(t);return _i(()=>{e.current=t}),e}function CA(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:a,elements:{reference:i,floating:o}={},transform:s=!0,whileElementsMounted:l,open:c}=t,[d,_]=b.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[p,m]=b.useState(r);pi(p,r)||m(r);const[g,f]=b.useState(null),[E,S]=b.useState(null),T=b.useCallback(M=>{M!==C.current&&(C.current=M,f(M))},[]),h=b.useCallback(M=>{M!==N.current&&(N.current=M,S(M))},[]),v=i||g,R=o||E,C=b.useRef(null),N=b.useRef(null),O=b.useRef(d),D=l!=null,w=Ts(l),L=Ts(a),H=Ts(c),z=b.useCallback(()=>{if(!C.current||!N.current)return;const M={placement:e,strategy:n,middleware:p};L.current&&(M.platform=L.current),TA(C.current,N.current,M).then(k=>{const Y={...k,isPositioned:H.current!==!1};P.current&&!pi(O.current,Y)&&(O.current=Y,oa.flushSync(()=>{_(Y)}))})},[p,e,n,L,H]);_i(()=>{c===!1&&O.current.isPositioned&&(O.current.isPositioned=!1,_(M=>({...M,isPositioned:!1})))},[c]);const P=b.useRef(!1);_i(()=>(P.current=!0,()=>{P.current=!1}),[]),_i(()=>{if(v&&(C.current=v),R&&(N.current=R),v&&R){if(w.current)return w.current(v,R,z);z()}},[v,R,z,w,D]);const G=b.useMemo(()=>({reference:C,floating:N,setReference:T,setFloating:h}),[T,h]),I=b.useMemo(()=>({reference:v,floating:R}),[v,R]),U=b.useMemo(()=>{const M={position:n,left:0,top:0};if(!I.floating)return M;const k=vg(I.floating,d.x),Y=vg(I.floating,d.y);return s?{...M,transform:"translate("+k+"px, "+Y+"px)",...Cg(I.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:k,top:Y}},[n,s,I.floating,d.x,d.y]);return b.useMemo(()=>({...d,update:z,refs:G,elements:I,floatingStyles:U}),[d,z,G,I,U])}const vA=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:r,padding:a}=typeof t=="function"?t(n):t;return r&&e(r)?r.current!=null?Rg({element:r.current,padding:a}).fn(n):{}:r?Rg({element:r,padding:a}).fn(n):{}}}},NA=(t,e)=>({...mA(t),options:[t,e]}),OA=(t,e)=>({...gA(t),options:[t,e]}),yA=(t,e)=>({...bA(t),options:[t,e]}),IA=(t,e)=>({...EA(t),options:[t,e]}),AA=(t,e)=>({...fA(t),options:[t,e]}),xA=(t,e)=>({...SA(t),options:[t,e]}),DA=(t,e)=>({...vA(t),options:[t,e]});var wA="Arrow",Ng=b.forwardRef((t,e)=>{const{children:n,width:r=10,height:a=5,...i}=t;return u.jsx(ye.svg,{...i,ref:e,width:r,height:a,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Ng.displayName=wA;var MA=Ng;function Og(t){const[e,n]=b.useState(void 0);return _t(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const r=new ResizeObserver(a=>{if(!Array.isArray(a)||!a.length)return;const i=a[0];let o,s;if("borderBoxSize"in i){const l=i.borderBoxSize,c=Array.isArray(l)?l[0]:l;o=c.inlineSize,s=c.blockSize}else o=t.offsetWidth,s=t.offsetHeight;n({width:o,height:s})});return r.observe(t,{box:"border-box"}),()=>r.unobserve(t)}else n(void 0)},[t]),e}var hs="Popper",[yg,_r]=qt(hs),[LA,Ig]=yg(hs),Ag=t=>{const{__scopePopper:e,children:n}=t,[r,a]=b.useState(null);return u.jsx(LA,{scope:e,anchor:r,onAnchorChange:a,children:n})};Ag.displayName=hs;var xg="PopperAnchor",Dg=b.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...a}=t,i=Ig(xg,n),o=b.useRef(null),s=ke(e,o),l=b.useRef(null);return b.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||o.current,c!==l.current&&i.onAnchorChange(l.current)}),r?null:u.jsx(ye.div,{...a,ref:s})});Dg.displayName=xg;var Rs="PopperContent",[PA,kA]=yg(Rs),wg=b.forwardRef((t,e)=>{var V,F,K,te,le,oe;const{__scopePopper:n,side:r="bottom",sideOffset:a=0,align:i="center",alignOffset:o=0,arrowPadding:s=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:_="partial",hideWhenDetached:p=!1,updatePositionStrategy:m="optimized",onPlaced:g,...f}=t,E=Ig(Rs,n),[S,T]=b.useState(null),h=ke(e,Ae=>T(Ae)),[v,R]=b.useState(null),C=Og(v),N=(C==null?void 0:C.width)??0,O=(C==null?void 0:C.height)??0,D=r+(i!=="center"?"-"+i:""),w=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(c)?c:[c],H=L.length>0,z={padding:w,boundary:L.filter(FA),altBoundary:H},{refs:P,floatingStyles:G,placement:I,isPositioned:U,middlewareData:M}=CA({strategy:"fixed",placement:D,whileElementsMounted:(...Ae)=>pA(...Ae,{animationFrame:m==="always"}),elements:{reference:E.anchor},middleware:[NA({mainAxis:a+O,alignmentAxis:o}),l&&OA({mainAxis:!0,crossAxis:!1,limiter:_==="partial"?yA():void 0,...z}),l&&IA({...z}),AA({...z,apply:({elements:Ae,rects:qe,availableWidth:Me,availableHeight:Se})=>{const{width:Be,height:ee}=qe.reference,Q=Ae.floating.style;Q.setProperty("--radix-popper-available-width",`${Me}px`),Q.setProperty("--radix-popper-available-height",`${Se}px`),Q.setProperty("--radix-popper-anchor-width",`${Be}px`),Q.setProperty("--radix-popper-anchor-height",`${ee}px`)}}),v&&DA({element:v,padding:s}),BA({arrowWidth:N,arrowHeight:O}),p&&xA({strategy:"referenceHidden",...z})]}),[k,Y]=Pg(I),W=pt(g);_t(()=>{U&&(W==null||W())},[U,W]);const re=(V=M.arrow)==null?void 0:V.x,q=(F=M.arrow)==null?void 0:F.y,X=((K=M.arrow)==null?void 0:K.centerOffset)!==0,[ce,ge]=b.useState();return _t(()=>{S&&ge(window.getComputedStyle(S).zIndex)},[S]),u.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...G,transform:U?G.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ce,"--radix-popper-transform-origin":[(te=M.transformOrigin)==null?void 0:te.x,(le=M.transformOrigin)==null?void 0:le.y].join(" "),...((oe=M.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:u.jsx(PA,{scope:n,placedSide:k,onArrowChange:R,arrowX:re,arrowY:q,shouldHideArrow:X,children:u.jsx(ye.div,{"data-side":k,"data-align":Y,...f,ref:h,style:{...f.style,animation:U?void 0:"none"}})})})});wg.displayName=Rs;var Mg="PopperArrow",UA={top:"bottom",right:"left",bottom:"top",left:"right"},Lg=b.forwardRef(function(e,n){const{__scopePopper:r,...a}=e,i=kA(Mg,r),o=UA[i.placedSide];return u.jsx("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:u.jsx(MA,{...a,ref:n,style:{...a.style,display:"block"}})})});Lg.displayName=Mg;function FA(t){return t!==null}var BA=t=>({name:"transformOrigin",options:t,fn(e){var E,S,T;const{placement:n,rects:r,middlewareData:a}=e,o=((E=a.arrow)==null?void 0:E.centerOffset)!==0,s=o?0:t.arrowWidth,l=o?0:t.arrowHeight,[c,d]=Pg(n),_={start:"0%",center:"50%",end:"100%"}[d],p=(((S=a.arrow)==null?void 0:S.x)??0)+s/2,m=(((T=a.arrow)==null?void 0:T.y)??0)+l/2;let g="",f="";return c==="bottom"?(g=o?_:`${p}px`,f=`${-l}px`):c==="top"?(g=o?_:`${p}px`,f=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,f=o?_:`${m}px`):c==="left"&&(g=`${r.floating.width+l}px`,f=o?_:`${m}px`),{data:{x:g,y:f}}}});function Pg(t){const[e,n="center"]=t.split("-");return[e,n]}var Cs=Ag,vs=Dg,Ns=wg,Os=Lg,ys="rovingFocusGroup.onEntryFocus",GA={bubbles:!1,cancelable:!0},$r="RovingFocusGroup",[Is,kg,YA]=cs($r),[HA,Ug]=qt($r,[YA]),[qA,VA]=HA($r),Fg=b.forwardRef((t,e)=>u.jsx(Is.Provider,{scope:t.__scopeRovingFocusGroup,children:u.jsx(Is.Slot,{scope:t.__scopeRovingFocusGroup,children:u.jsx(zA,{...t,ref:e})})}));Fg.displayName=$r;var zA=b.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:a=!1,dir:i,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,..._}=t,p=b.useRef(null),m=ke(e,p),g=ri(i),[f,E]=Rn({prop:o,defaultProp:s??null,onChange:l,caller:$r}),[S,T]=b.useState(!1),h=pt(c),v=kg(n),R=b.useRef(!1),[C,N]=b.useState(0);return b.useEffect(()=>{const O=p.current;if(O)return O.addEventListener(ys,h),()=>O.removeEventListener(ys,h)},[h]),u.jsx(qA,{scope:n,orientation:r,dir:g,loop:a,currentTabStopId:f,onItemFocus:b.useCallback(O=>E(O),[E]),onItemShiftTab:b.useCallback(()=>T(!0),[]),onFocusableItemAdd:b.useCallback(()=>N(O=>O+1),[]),onFocusableItemRemove:b.useCallback(()=>N(O=>O-1),[]),children:u.jsx(ye.div,{tabIndex:S||C===0?-1:0,"data-orientation":r,..._,ref:m,style:{outline:"none",...t.style},onMouseDown:de(t.onMouseDown,()=>{R.current=!0}),onFocus:de(t.onFocus,O=>{const D=!R.current;if(O.target===O.currentTarget&&D&&!S){const w=new CustomEvent(ys,GA);if(O.currentTarget.dispatchEvent(w),!w.defaultPrevented){const L=v().filter(I=>I.focusable),H=L.find(I=>I.active),z=L.find(I=>I.id===f),G=[H,z,...L].filter(Boolean).map(I=>I.ref.current);Yg(G,d)}}R.current=!1}),onBlur:de(t.onBlur,()=>T(!1))})})}),Bg="RovingFocusGroupItem",Gg=b.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:a=!1,tabStopId:i,children:o,...s}=t,l=Vt(),c=i||l,d=VA(Bg,n),_=d.currentTabStopId===c,p=kg(n),{onFocusableItemAdd:m,onFocusableItemRemove:g,currentTabStopId:f}=d;return b.useEffect(()=>{if(r)return m(),()=>g()},[r,m,g]),u.jsx(Is.ItemSlot,{scope:n,id:c,focusable:r,active:a,children:u.jsx(ye.span,{tabIndex:_?0:-1,"data-orientation":d.orientation,...s,ref:e,onMouseDown:de(t.onMouseDown,E=>{r?d.onItemFocus(c):E.preventDefault()}),onFocus:de(t.onFocus,()=>d.onItemFocus(c)),onKeyDown:de(t.onKeyDown,E=>{if(E.key==="Tab"&&E.shiftKey){d.onItemShiftTab();return}if(E.target!==E.currentTarget)return;const S=KA(E,d.orientation,d.dir);if(S!==void 0){if(E.metaKey||E.ctrlKey||E.altKey||E.shiftKey)return;E.preventDefault();let h=p().filter(v=>v.focusable).map(v=>v.ref.current);if(S==="last")h.reverse();else if(S==="prev"||S==="next"){S==="prev"&&h.reverse();const v=h.indexOf(E.currentTarget);h=d.loop?QA(h,v+1):h.slice(v+1)}setTimeout(()=>Yg(h))}}),children:typeof o=="function"?o({isCurrentTabStop:_,hasTabStop:f!=null}):o})})});Gg.displayName=Bg;var $A={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function WA(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function KA(t,e,n){const r=WA(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return $A[r]}function Yg(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}function QA(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var jA=Fg,XA=Gg,As=["Enter"," "],ZA=["ArrowDown","PageUp","Home"],Hg=["ArrowUp","PageDown","End"],JA=[...ZA,...Hg],ex={ltr:[...As,"ArrowRight"],rtl:[...As,"ArrowLeft"]},tx={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Wr="Menu",[Kr,nx,rx]=cs(Wr),[Hn,qg]=qt(Wr,[rx,_r,Ug]),mi=_r(),Vg=Ug(),[ax,qn]=Hn(Wr),[ix,Qr]=Hn(Wr),zg=t=>{const{__scopeMenu:e,open:n=!1,children:r,dir:a,onOpenChange:i,modal:o=!0}=t,s=mi(e),[l,c]=b.useState(null),d=b.useRef(!1),_=pt(i),p=ri(a);return b.useEffect(()=>{const m=()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>d.current=!1;return document.addEventListener("keydown",m,{capture:!0}),()=>{document.removeEventListener("keydown",m,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.jsx(Cs,{...s,children:u.jsx(ax,{scope:e,open:n,onOpenChange:_,content:l,onContentChange:c,children:u.jsx(ix,{scope:e,onClose:b.useCallback(()=>_(!1),[_]),isUsingKeyboardRef:d,dir:p,modal:o,children:r})})})};zg.displayName=Wr;var ox="MenuAnchor",xs=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,a=mi(n);return u.jsx(vs,{...a,...r,ref:e})});xs.displayName=ox;var Ds="MenuPortal",[sx,$g]=Hn(Ds,{forceMount:void 0}),Wg=t=>{const{__scopeMenu:e,forceMount:n,children:r,container:a}=t,i=qn(Ds,e);return u.jsx(sx,{scope:e,forceMount:n,children:u.jsx(vt,{present:n||i.open,children:u.jsx(Ga,{asChild:!0,container:a,children:r})})})};Wg.displayName=Ds;var Ut="MenuContent",[lx,ws]=Hn(Ut),Kg=b.forwardRef((t,e)=>{const n=$g(Ut,t.__scopeMenu),{forceMount:r=n.forceMount,...a}=t,i=qn(Ut,t.__scopeMenu),o=Qr(Ut,t.__scopeMenu);return u.jsx(Kr.Provider,{scope:t.__scopeMenu,children:u.jsx(vt,{present:r||i.open,children:u.jsx(Kr.Slot,{scope:t.__scopeMenu,children:o.modal?u.jsx(cx,{...a,ref:e}):u.jsx(dx,{...a,ref:e})})})})}),cx=b.forwardRef((t,e)=>{const n=qn(Ut,t.__scopeMenu),r=b.useRef(null),a=ke(e,r);return b.useEffect(()=>{const i=r.current;if(i)return as(i)},[]),u.jsx(Ms,{...t,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(t.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),dx=b.forwardRef((t,e)=>{const n=qn(Ut,t.__scopeMenu);return u.jsx(Ms,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ux=Nt.createSlot("MenuContent.ScrollLock"),Ms=b.forwardRef((t,e)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:a,onOpenAutoFocus:i,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:_,onInteractOutside:p,onDismiss:m,disableOutsideScroll:g,...f}=t,E=qn(Ut,n),S=Qr(Ut,n),T=mi(n),h=Vg(n),v=nx(n),[R,C]=b.useState(null),N=b.useRef(null),O=ke(e,N,E.onContentChange),D=b.useRef(0),w=b.useRef(""),L=b.useRef(0),H=b.useRef(null),z=b.useRef("right"),P=b.useRef(0),G=g?$a:b.Fragment,I=g?{as:ux,allowPinchZoom:!0}:void 0,U=k=>{var V,F;const Y=w.current+k,W=v().filter(K=>!K.disabled),re=document.activeElement,q=(V=W.find(K=>K.ref.current===re))==null?void 0:V.textValue,X=W.map(K=>K.textValue),ce=Cx(X,Y,q),ge=(F=W.find(K=>K.textValue===ce))==null?void 0:F.ref.current;(function K(te){w.current=te,window.clearTimeout(D.current),te!==""&&(D.current=window.setTimeout(()=>K(""),1e3))})(Y),ge&&setTimeout(()=>ge.focus())};b.useEffect(()=>()=>window.clearTimeout(D.current),[]),Zo();const M=b.useCallback(k=>{var W,re;return z.current===((W=H.current)==null?void 0:W.side)&&Nx(k,(re=H.current)==null?void 0:re.area)},[]);return u.jsx(lx,{scope:n,searchRef:w,onItemEnter:b.useCallback(k=>{M(k)&&k.preventDefault()},[M]),onItemLeave:b.useCallback(k=>{var Y;M(k)||((Y=N.current)==null||Y.focus(),C(null))},[M]),onTriggerLeave:b.useCallback(k=>{M(k)&&k.preventDefault()},[M]),pointerGraceTimerRef:L,onPointerGraceIntentChange:b.useCallback(k=>{H.current=k},[]),children:u.jsx(G,{...I,children:u.jsx(Ba,{asChild:!0,trapped:a,onMountAutoFocus:de(i,k=>{var Y;k.preventDefault(),(Y=N.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:u.jsx(Yr,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:_,onInteractOutside:p,onDismiss:m,children:u.jsx(jA,{asChild:!0,...h,dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:R,onCurrentTabStopIdChange:C,onEntryFocus:de(l,k=>{S.isUsingKeyboardRef.current||k.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(Ns,{role:"menu","aria-orientation":"vertical","data-state":uE(E.open),"data-radix-menu-content":"",dir:S.dir,...T,...f,ref:O,style:{outline:"none",...f.style},onKeyDown:de(f.onKeyDown,k=>{const W=k.target.closest("[data-radix-menu-content]")===k.currentTarget,re=k.ctrlKey||k.altKey||k.metaKey,q=k.key.length===1;W&&(k.key==="Tab"&&k.preventDefault(),!re&&q&&U(k.key));const X=N.current;if(k.target!==X||!JA.includes(k.key))return;k.preventDefault();const ge=v().filter(V=>!V.disabled).map(V=>V.ref.current);Hg.includes(k.key)&&ge.reverse(),hx(ge)}),onBlur:de(t.onBlur,k=>{k.currentTarget.contains(k.target)||(window.clearTimeout(D.current),w.current="")}),onPointerMove:de(t.onPointerMove,Xr(k=>{const Y=k.target,W=P.current!==k.clientX;if(k.currentTarget.contains(Y)&&W){const re=k.clientX>P.current?"right":"left";z.current=re,P.current=k.clientX}}))})})})})})})});Kg.displayName=Ut;var _x="MenuGroup",Ls=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return u.jsx(ye.div,{role:"group",...r,ref:e})});Ls.displayName=_x;var px="MenuLabel",Qg=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return u.jsx(ye.div,{...r,ref:e})});Qg.displayName=px;var gi="MenuItem",jg="menu.itemSelect",Ei=b.forwardRef((t,e)=>{const{disabled:n=!1,onSelect:r,...a}=t,i=b.useRef(null),o=Qr(gi,t.__scopeMenu),s=ws(gi,t.__scopeMenu),l=ke(e,i),c=b.useRef(!1),d=()=>{const _=i.current;if(!n&&_){const p=new CustomEvent(jg,{bubbles:!0,cancelable:!0});_.addEventListener(jg,m=>r==null?void 0:r(m),{once:!0}),Wp(_,p),p.defaultPrevented?c.current=!1:o.onClose()}};return u.jsx(Xg,{...a,ref:l,disabled:n,onClick:de(t.onClick,d),onPointerDown:_=>{var p;(p=t.onPointerDown)==null||p.call(t,_),c.current=!0},onPointerUp:de(t.onPointerUp,_=>{var p;c.current||(p=_.currentTarget)==null||p.click()}),onKeyDown:de(t.onKeyDown,_=>{const p=s.searchRef.current!=="";n||p&&_.key===" "||As.includes(_.key)&&(_.currentTarget.click(),_.preventDefault())})})});Ei.displayName=gi;var Xg=b.forwardRef((t,e)=>{const{__scopeMenu:n,disabled:r=!1,textValue:a,...i}=t,o=ws(gi,n),s=Vg(n),l=b.useRef(null),c=ke(e,l),[d,_]=b.useState(!1),[p,m]=b.useState("");return b.useEffect(()=>{const g=l.current;g&&m((g.textContent??"").trim())},[i.children]),u.jsx(Kr.ItemSlot,{scope:n,disabled:r,textValue:a??p,children:u.jsx(XA,{asChild:!0,...s,focusable:!r,children:u.jsx(ye.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...i,ref:c,onPointerMove:de(t.onPointerMove,Xr(g=>{r?o.onItemLeave(g):(o.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(t.onPointerLeave,Xr(g=>o.onItemLeave(g))),onFocus:de(t.onFocus,()=>_(!0)),onBlur:de(t.onBlur,()=>_(!1))})})})}),mx="MenuCheckboxItem",Zg=b.forwardRef((t,e)=>{const{checked:n=!1,onCheckedChange:r,...a}=t;return u.jsx(rE,{scope:t.__scopeMenu,checked:n,children:u.jsx(Ei,{role:"menuitemcheckbox","aria-checked":fi(n)?"mixed":n,...a,ref:e,"data-state":ks(n),onSelect:de(a.onSelect,()=>r==null?void 0:r(fi(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Zg.displayName=mx;var Jg="MenuRadioGroup",[gx,Ex]=Hn(Jg,{value:void 0,onValueChange:()=>{}}),eE=b.forwardRef((t,e)=>{const{value:n,onValueChange:r,...a}=t,i=pt(r);return u.jsx(gx,{scope:t.__scopeMenu,value:n,onValueChange:i,children:u.jsx(Ls,{...a,ref:e})})});eE.displayName=Jg;var tE="MenuRadioItem",nE=b.forwardRef((t,e)=>{const{value:n,...r}=t,a=Ex(tE,t.__scopeMenu),i=n===a.value;return u.jsx(rE,{scope:t.__scopeMenu,checked:i,children:u.jsx(Ei,{role:"menuitemradio","aria-checked":i,...r,ref:e,"data-state":ks(i),onSelect:de(r.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,n)},{checkForDefaultPrevented:!1})})})});nE.displayName=tE;var Ps="MenuItemIndicator",[rE,fx]=Hn(Ps,{checked:!1}),aE=b.forwardRef((t,e)=>{const{__scopeMenu:n,forceMount:r,...a}=t,i=fx(Ps,n);return u.jsx(vt,{present:r||fi(i.checked)||i.checked===!0,children:u.jsx(ye.span,{...a,ref:e,"data-state":ks(i.checked)})})});aE.displayName=Ps;var Sx="MenuSeparator",iE=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return u.jsx(ye.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});iE.displayName=Sx;var bx="MenuArrow",oE=b.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,a=mi(n);return u.jsx(Os,{...a,...r,ref:e})});oE.displayName=bx;var Tx="MenuSub",[Z0,sE]=Hn(Tx),jr="MenuSubTrigger",lE=b.forwardRef((t,e)=>{const n=qn(jr,t.__scopeMenu),r=Qr(jr,t.__scopeMenu),a=sE(jr,t.__scopeMenu),i=ws(jr,t.__scopeMenu),o=b.useRef(null),{pointerGraceTimerRef:s,onPointerGraceIntentChange:l}=i,c={__scopeMenu:t.__scopeMenu},d=b.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return b.useEffect(()=>d,[d]),b.useEffect(()=>{const _=s.current;return()=>{window.clearTimeout(_),l(null)}},[s,l]),u.jsx(xs,{asChild:!0,...c,children:u.jsx(Xg,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":a.contentId,"data-state":uE(n.open),...t,ref:ko(e,a.onTriggerChange),onClick:_=>{var p;(p=t.onClick)==null||p.call(t,_),!(t.disabled||_.defaultPrevented)&&(_.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:de(t.onPointerMove,Xr(_=>{i.onItemEnter(_),!_.defaultPrevented&&!t.disabled&&!n.open&&!o.current&&(i.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:de(t.onPointerLeave,Xr(_=>{var m,g;d();const p=(m=n.content)==null?void 0:m.getBoundingClientRect();if(p){const f=(g=n.content)==null?void 0:g.dataset.side,E=f==="right",S=E?-5:5,T=p[E?"left":"right"],h=p[E?"right":"left"];i.onPointerGraceIntentChange({area:[{x:_.clientX+S,y:_.clientY},{x:T,y:p.top},{x:h,y:p.top},{x:h,y:p.bottom},{x:T,y:p.bottom}],side:f}),window.clearTimeout(s.current),s.current=window.setTimeout(()=>i.onPointerGraceIntentChange(null),300)}else{if(i.onTriggerLeave(_),_.defaultPrevented)return;i.onPointerGraceIntentChange(null)}})),onKeyDown:de(t.onKeyDown,_=>{var m;const p=i.searchRef.current!=="";t.disabled||p&&_.key===" "||ex[r.dir].includes(_.key)&&(n.onOpenChange(!0),(m=n.content)==null||m.focus(),_.preventDefault())})})})});lE.displayName=jr;var cE="MenuSubContent",dE=b.forwardRef((t,e)=>{const n=$g(Ut,t.__scopeMenu),{forceMount:r=n.forceMount,...a}=t,i=qn(Ut,t.__scopeMenu),o=Qr(Ut,t.__scopeMenu),s=sE(cE,t.__scopeMenu),l=b.useRef(null),c=ke(e,l);return u.jsx(Kr.Provider,{scope:t.__scopeMenu,children:u.jsx(vt,{present:r||i.open,children:u.jsx(Kr.Slot,{scope:t.__scopeMenu,children:u.jsx(Ms,{id:s.contentId,"aria-labelledby":s.triggerId,...a,ref:c,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var _;o.isUsingKeyboardRef.current&&((_=l.current)==null||_.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:de(t.onFocusOutside,d=>{d.target!==s.trigger&&i.onOpenChange(!1)}),onEscapeKeyDown:de(t.onEscapeKeyDown,d=>{o.onClose(),d.preventDefault()}),onKeyDown:de(t.onKeyDown,d=>{var m;const _=d.currentTarget.contains(d.target),p=tx[o.dir].includes(d.key);_&&p&&(i.onOpenChange(!1),(m=s.trigger)==null||m.focus(),d.preventDefault())})})})})})});dE.displayName=cE;function uE(t){return t?"open":"closed"}function fi(t){return t==="indeterminate"}function ks(t){return fi(t)?"indeterminate":t?"checked":"unchecked"}function hx(t){const e=document.activeElement;for(const n of t)if(n===e||(n.focus(),document.activeElement!==e))return}function Rx(t,e){return t.map((n,r)=>t[(e+r)%t.length])}function Cx(t,e,n){const a=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,i=n?t.indexOf(n):-1;let o=Rx(t,Math.max(i,0));a.length===1&&(o=o.filter(c=>c!==n));const l=o.find(c=>c.toLowerCase().startsWith(a.toLowerCase()));return l!==n?l:void 0}function vx(t,e){const{x:n,y:r}=t;let a=!1;for(let i=0,o=e.length-1;i<e.length;o=i++){const s=e[i],l=e[o],c=s.x,d=s.y,_=l.x,p=l.y;d>r!=p>r&&n<(_-c)*(r-d)/(p-d)+c&&(a=!a)}return a}function Nx(t,e){if(!e)return!1;const n={x:t.clientX,y:t.clientY};return vx(n,e)}function Xr(t){return e=>e.pointerType==="mouse"?t(e):void 0}var Ox=zg,yx=xs,Ix=Wg,Ax=Kg,xx=Ls,Dx=Qg,wx=Ei,Mx=Zg,Lx=eE,Px=nE,kx=aE,Ux=iE,Fx=oE,Bx=lE,Gx=dE,Si="DropdownMenu",[Yx,J0]=qt(Si,[qg]),Tt=qg(),[Hx,_E]=Yx(Si),pE=t=>{const{__scopeDropdownMenu:e,children:n,dir:r,open:a,defaultOpen:i,onOpenChange:o,modal:s=!0}=t,l=Tt(e),c=b.useRef(null),[d,_]=Rn({prop:a,defaultProp:i??!1,onChange:o,caller:Si});return u.jsx(Hx,{scope:e,triggerId:Vt(),triggerRef:c,contentId:Vt(),open:d,onOpenChange:_,onOpenToggle:b.useCallback(()=>_(p=>!p),[_]),modal:s,children:u.jsx(Ox,{...l,open:d,onOpenChange:_,dir:r,modal:s,children:n})})};pE.displayName=Si;var mE="DropdownMenuTrigger",gE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...a}=t,i=_E(mE,n),o=Tt(n);return u.jsx(yx,{asChild:!0,...o,children:u.jsx(ye.button,{type:"button",id:i.triggerId,"aria-haspopup":"menu","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":i.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...a,ref:ko(e,i.triggerRef),onPointerDown:de(t.onPointerDown,s=>{!r&&s.button===0&&s.ctrlKey===!1&&(i.onOpenToggle(),i.open||s.preventDefault())}),onKeyDown:de(t.onKeyDown,s=>{r||(["Enter"," "].includes(s.key)&&i.onOpenToggle(),s.key==="ArrowDown"&&i.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(s.key)&&s.preventDefault())})})})});gE.displayName=mE;var qx="DropdownMenuPortal",EE=t=>{const{__scopeDropdownMenu:e,...n}=t,r=Tt(e);return u.jsx(Ix,{...r,...n})};EE.displayName=qx;var fE="DropdownMenuContent",SE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=_E(fE,n),i=Tt(n),o=b.useRef(!1);return u.jsx(Ax,{id:a.contentId,"aria-labelledby":a.triggerId,...i,...r,ref:e,onCloseAutoFocus:de(t.onCloseAutoFocus,s=>{var l;o.current||(l=a.triggerRef.current)==null||l.focus(),o.current=!1,s.preventDefault()}),onInteractOutside:de(t.onInteractOutside,s=>{const l=s.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!a.modal||d)&&(o.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});SE.displayName=fE;var Vx="DropdownMenuGroup",zx=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(xx,{...a,...r,ref:e})});zx.displayName=Vx;var $x="DropdownMenuLabel",bE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Dx,{...a,...r,ref:e})});bE.displayName=$x;var Wx="DropdownMenuItem",TE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(wx,{...a,...r,ref:e})});TE.displayName=Wx;var Kx="DropdownMenuCheckboxItem",hE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Mx,{...a,...r,ref:e})});hE.displayName=Kx;var Qx="DropdownMenuRadioGroup",jx=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Lx,{...a,...r,ref:e})});jx.displayName=Qx;var Xx="DropdownMenuRadioItem",RE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Px,{...a,...r,ref:e})});RE.displayName=Xx;var Zx="DropdownMenuItemIndicator",CE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(kx,{...a,...r,ref:e})});CE.displayName=Zx;var Jx="DropdownMenuSeparator",vE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Ux,{...a,...r,ref:e})});vE.displayName=Jx;var eD="DropdownMenuArrow",tD=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Fx,{...a,...r,ref:e})});tD.displayName=eD;var nD="DropdownMenuSubTrigger",NE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Bx,{...a,...r,ref:e})});NE.displayName=nD;var rD="DropdownMenuSubContent",OE=b.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,a=Tt(n);return u.jsx(Gx,{...a,...r,ref:e,style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});OE.displayName=rD;var aD=pE,iD=gE,oD=EE,yE=SE,IE=bE,AE=TE,xE=hE,DE=RE,wE=CE,ME=vE,LE=NE,PE=OE;const sD=aD,lD=iD,cD=b.forwardRef(({className:t,inset:e,children:n,...r},a)=>u.jsxs(LE,{ref:a,className:$("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",e&&"pl-8",t),...r,children:[n,u.jsx(pe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));cD.displayName=LE.displayName;const dD=b.forwardRef(({className:t,...e},n)=>u.jsx(PE,{ref:n,className:$("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...e}));dD.displayName=PE.displayName;const kE=b.forwardRef(({className:t,sideOffset:e=4,...n},r)=>u.jsx(oD,{children:u.jsx(yE,{ref:r,sideOffset:e,className:$("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...n})}));kE.displayName=yE.displayName;const Us=b.forwardRef(({className:t,inset:e,...n},r)=>u.jsx(AE,{ref:r,className:$("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e&&"pl-8",t),...n}));Us.displayName=AE.displayName;const uD=b.forwardRef(({className:t,children:e,checked:n,...r},a)=>u.jsxs(xE,{ref:a,className:$("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wE,{children:u.jsx(pe.Check,{className:"h-4 w-4"})})}),e]}));uD.displayName=xE.displayName;const _D=b.forwardRef(({className:t,children:e,...n},r)=>u.jsxs(DE,{ref:r,className:$("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(wE,{children:u.jsx(pe.Circle,{className:"h-2 w-2 fill-current"})})}),e]}));_D.displayName=DE.displayName;const pD=b.forwardRef(({className:t,inset:e,...n},r)=>u.jsx(IE,{ref:r,className:$("px-2 py-1.5 text-sm font-semibold",e&&"pl-8",t),...n}));pD.displayName=IE.displayName;const mD=b.forwardRef(({className:t,...e},n)=>u.jsx(ME,{ref:n,className:$("-mx-1 my-1 h-px bg-muted",t),...e}));mD.displayName=ME.displayName;function Zr({className:t="",placeholder:e="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:a=300,enableFileUpload:i=!0,enableExcelUpload:o=!1,enableMessageEditing:s=!0,customStyles:l={},onMessageSent:c,onExcelUploadSuccess:d,onError:_}){const{currentThreadId:p,messages:m,isStreaming:g,streamingAssistantId:f,error:E,send:S,stop:T,lastCheckpointId:h,listCheckpoints:v,navigateToCheckpoint:R,returnToLatest:C,hasMoreHistory:N,isLoadingHistory:O,loadOlderMessages:D,api:w}=ba(),[L,H]=y.useState(null),[z,P]=y.useState(""),[G,I]=y.useState(null),[U,M]=y.useState([]),[k,Y]=y.useState(!1),[W,re]=y.useState(null),[q,X]=y.useState(null),[ce,ge]=y.useState(!1),[V,F]=y.useState(null),[K,te]=y.useState([]),[le,oe]=y.useState(null),Ae=y.useRef(null),qe=y.useRef(null),Me=y.useRef(null),[Se,Be]=y.useState("desktop");y.useEffect(()=>{const ie=()=>{const Te=window.innerWidth;Be(Te<640?"phone":Te<1024?"tablet":"desktop")};return ie(),window.addEventListener("resize",ie),()=>window.removeEventListener("resize",ie)},[]),y.useEffect(()=>{let ie=!1;if(!p){te([]),oe(null),Me.current=null;return}const Te={threadId:p,checkpointId:h??null},ze=Me.current;if(!(ze&&ze.threadId===Te.threadId&&ze.checkpointId===Te.checkpointId))return v(p).then(it=>{if(ie)return;const gn=((it==null?void 0:it.checkpoints)??[]).slice().sort((En,Pe)=>new Date(Pe.createdAt).getTime()-new Date(En.createdAt).getTime());te(gn),oe(En=>{var Pe;return En??((Pe=gn[0])==null?void 0:Pe.checkpointId)??null}),Me.current=Te}).catch(it=>{console.error("ChatInterface - listCheckpoints error:",it),ie||(te([]),Me.current=null)}),()=>{ie=!0}},[p,h,v]),y.useEffect(()=>{h&&oe(h)},[h]);const ee=y.useCallback(async()=>{if(!(!N||O))try{await D()}catch(ie){console.warn("loadOlderMessages failed",ie)}},[N,O,D]);y.useEffect(()=>{(async()=>{try{const Te=await w.getAgent("default");F(Te.uiDefaultMessage||null)}catch(Te){console.warn("Failed to fetch default message:",Te),F(null)}})()},[w]),y.useEffect(()=>{E&&!ce&&(_==null||_(E))},[E,ce,_]);const Q=ie=>{if(ie.length>ni)return`Message too long (${ie.length}/${ni} characters)`;try{return TI(ie),null}catch(Te){return(Te==null?void 0:Te.message)||"Invalid message"}},ae=ie=>{const Te=ie.content||[],ze=Te.filter(it=>it.type==="text").map(it=>it.text).join("");if(ze)return ze;try{return JSON.stringify(Te,null,2)}catch{return String(Te)}},be=async ie=>{const Te=ie.trim();if(!(!Te&&U.length===0)){if(Te){const ze=Q(Te);if(ze){I(ze);return}}try{await S(Te,{checkpointId:le||h||void 0,payloadExtras:L?{edit:!0,originalMessageId:L}:void 0,attachments:U}),c==null||c(Te),I(null),M([]),H(null),P("")}catch(ze){const it=(ze==null?void 0:ze.message)||"Failed to send message";I(it),_==null||_(it)}}},Je=y.useCallback((ie,Te)=>{s&&(H(ie),P(Te),I(null))},[s]),Qe=y.useCallback(()=>{H(null),P(""),I(null)},[]),at=y.useCallback((ie,Te)=>{Je(ie,Te)},[Je]),Ke=y.useCallback(ie=>{for(let Te=ie-1;Te>=0;Te--)if(m[Te].role==="user"){const ze=ae(m[Te]);ze&&S(ze,{checkpointId:le||h||void 0});break}},[m,S,le,h,ae]),Z=ie=>{const Te=Array.from(ie.target.files||[]);M(ze=>[...ze,...Te])},se=ie=>M(Te=>Te.filter((ze,it)=>ie!==it)),Ee=async ie=>{const Te=(ie.target.files||[])[0];if(Te){re(null),X(null),Y(!0);try{await S("",{checkpointId:le||h||void 0,attachments:[Te]});const ze=`Uploaded ${Te.name} - processing through chat stream`;X(ze)}catch(ze){const it=ze instanceof Error?ze.message:"Failed to upload Excel file";console.error("Excel upload failed",ze),re(it),_==null||_(it)}finally{Y(!1),ie.target.value=""}}},he=ie=>{if(!ie)return"Unknown";const Te=Date.parse(ie);return Number.isNaN(Te)?ie:new Date(Te).toLocaleString()},Ue=async ie=>{if(p){if(!ie){await C(),oe(null);return}await R(ie),oe(ie)}},rt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${t} ${l.container||""}`,xt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-y-auto overflow-x-auto overscroll-contain break-words break-anywhere p-4 bg-transparent ${l.messagesArea||""}`,Qt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${l.inputArea||""}`;return u.jsxs("div",{className:rt,children:[!!E&&!ce&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:E}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>ge(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(pe.X,{size:16})})]}),p&&K.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:le??"",onChange:ie=>{const Te=ie.target.value||null;Ue(Te)},children:[u.jsx("option",{value:"",children:"Latest"}),K.map(ie=>u.jsxs("option",{value:ie.checkpointId,children:[he(ie.createdAt),ie.preview?` — ${ie.preview.slice(0,40)}`:""]},ie.checkpointId))]})]}),u.jsx(ng,{className:xt,style:r?{maxHeight:r}:void 0,messages:m,isStreaming:g,streamingAssistantId:f,streamingDebounceMs:a,layoutSize:Se,enableMessageEditing:s,editingMessageId:L,onStartReached:()=>{ee()},onEdit:at,onRegenerate:Ke,onCancelEdit:Qe,emptyMessage:V??void 0}),u.jsxs("div",{className:Qt,children:[L&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(pe.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:Qe,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(pe.X,{size:16})})]})}),(i||o)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[i&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Ae,type:"file",multiple:!0,onChange:ie=>Z(ie),className:"hidden"}),U.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:U.map((ie,Te)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(pe.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:ie.name}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>se(Te),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${ie.name}`,children:u.jsx(pe.X,{size:12})})]},Te))})]}),o&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:qe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Ee,className:"hidden"}),k&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(pe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),q&&!k&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:q}),W&&!k&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:W})]})]}),G&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:G}),u.jsxs("div",{className:"flex items-end gap-2",children:[(i||o)&&u.jsxs(sD,{children:[u.jsx(lD,{asChild:!0,children:u.jsx(Ve,{type:"button",size:"icon",variant:"outline",disabled:g,title:"More input actions",className:l.moreButton||"",children:u.jsx(pe.Plus,{size:16})})}),u.jsxs(kE,{align:"start",sideOffset:6,className:"w-52",children:[i&&u.jsxs(Us,{onClick:()=>{var ie;return(ie=Ae.current)==null?void 0:ie.click()},className:"cursor-pointer",children:[u.jsx(pe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),o&&u.jsxs(Us,{onClick:()=>{var ie;k||(ie=qe.current)==null||ie.click()},className:`cursor-pointer ${k?"opacity-60 pointer-events-none":""}`,children:[u.jsx(pe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(qv,{initialValue:z,editingMessageId:L,placeholder:L?"Edit your message...":e,isStreaming:g,disabled:!1,maxLength:ni,onSend:be,onCancelEdit:Qe,onStop:T,allowEmptySend:U.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${L?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${G?"border-red-400":""} ${l.textarea||""}`})})]})]})]})}const Jr=b.forwardRef(({className:t,type:e,...n},r)=>u.jsx("input",{type:e,className:$("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",t),ref:r,...n}));Jr.displayName="Input";function Fs(t,[e,n]){return Math.min(n,Math.max(e,t))}function gD(t,e){return b.useReducer((n,r)=>e[n][r]??n,t)}var Bs="ScrollArea",[UE,eF]=qt(Bs),[ED,Ft]=UE(Bs),FE=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,type:r="hover",dir:a,scrollHideDelay:i=600,...o}=t,[s,l]=b.useState(null),[c,d]=b.useState(null),[_,p]=b.useState(null),[m,g]=b.useState(null),[f,E]=b.useState(null),[S,T]=b.useState(0),[h,v]=b.useState(0),[R,C]=b.useState(!1),[N,O]=b.useState(!1),D=ke(e,L=>l(L)),w=ri(a);return u.jsx(ED,{scope:n,type:r,dir:w,scrollHideDelay:i,scrollArea:s,viewport:c,onViewportChange:d,content:_,onContentChange:p,scrollbarX:m,onScrollbarXChange:g,scrollbarXEnabled:R,onScrollbarXEnabledChange:C,scrollbarY:f,onScrollbarYChange:E,scrollbarYEnabled:N,onScrollbarYEnabledChange:O,onCornerWidthChange:T,onCornerHeightChange:v,children:u.jsx(ye.div,{dir:w,...o,ref:D,style:{position:"relative","--radix-scroll-area-corner-width":S+"px","--radix-scroll-area-corner-height":h+"px",...t.style}})})});FE.displayName=Bs;var BE="ScrollAreaViewport",GE=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,children:r,nonce:a,...i}=t,o=Ft(BE,n),s=b.useRef(null),l=ke(e,s,o.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:a}),u.jsx(ye.div,{"data-radix-scroll-area-viewport":"",...i,ref:l,style:{overflowX:o.scrollbarXEnabled?"scroll":"hidden",overflowY:o.scrollbarYEnabled?"scroll":"hidden",...t.style},children:u.jsx("div",{ref:o.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});GE.displayName=BE;var on="ScrollAreaScrollbar",Gs=b.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=Ft(on,t.__scopeScrollArea),{onScrollbarXEnabledChange:i,onScrollbarYEnabledChange:o}=a,s=t.orientation==="horizontal";return b.useEffect(()=>(s?i(!0):o(!0),()=>{s?i(!1):o(!1)}),[s,i,o]),a.type==="hover"?u.jsx(fD,{...r,ref:e,forceMount:n}):a.type==="scroll"?u.jsx(SD,{...r,ref:e,forceMount:n}):a.type==="auto"?u.jsx(YE,{...r,ref:e,forceMount:n}):a.type==="always"?u.jsx(Ys,{...r,ref:e}):null});Gs.displayName=on;var fD=b.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=Ft(on,t.__scopeScrollArea),[i,o]=b.useState(!1);return b.useEffect(()=>{const s=a.scrollArea;let l=0;if(s){const c=()=>{window.clearTimeout(l),o(!0)},d=()=>{l=window.setTimeout(()=>o(!1),a.scrollHideDelay)};return s.addEventListener("pointerenter",c),s.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),s.removeEventListener("pointerenter",c),s.removeEventListener("pointerleave",d)}}},[a.scrollArea,a.scrollHideDelay]),u.jsx(vt,{present:n||i,children:u.jsx(YE,{"data-state":i?"visible":"hidden",...r,ref:e})})}),SD=b.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=Ft(on,t.__scopeScrollArea),i=t.orientation==="horizontal",o=Ri(()=>l("SCROLL_END"),100),[s,l]=gD("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 b.useEffect(()=>{if(s==="idle"){const c=window.setTimeout(()=>l("HIDE"),a.scrollHideDelay);return()=>window.clearTimeout(c)}},[s,a.scrollHideDelay,l]),b.useEffect(()=>{const c=a.viewport,d=i?"scrollLeft":"scrollTop";if(c){let _=c[d];const p=()=>{const m=c[d];_!==m&&(l("SCROLL"),o()),_=m};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[a.viewport,i,l,o]),u.jsx(vt,{present:n||s!=="hidden",children:u.jsx(Ys,{"data-state":s==="hidden"?"hidden":"visible",...r,ref:e,onPointerEnter:de(t.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(t.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),YE=b.forwardRef((t,e)=>{const n=Ft(on,t.__scopeScrollArea),{forceMount:r,...a}=t,[i,o]=b.useState(!1),s=t.orientation==="horizontal",l=Ri(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;o(s?c:d)}},10);return pr(n.viewport,l),pr(n.content,l),u.jsx(vt,{present:r||i,children:u.jsx(Ys,{"data-state":i?"visible":"hidden",...a,ref:e})})}),Ys=b.forwardRef((t,e)=>{const{orientation:n="vertical",...r}=t,a=Ft(on,t.__scopeScrollArea),i=b.useRef(null),o=b.useRef(0),[s,l]=b.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=$E(s.viewport,s.content),d={...r,sizes:s,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>i.current=p,onThumbPointerUp:()=>o.current=0,onThumbPointerDown:p=>o.current=p};function _(p,m){return vD(p,o.current,s,m)}return n==="horizontal"?u.jsx(bD,{...d,ref:e,onThumbPositionChange:()=>{if(a.viewport&&i.current){const p=a.viewport.scrollLeft,m=WE(p,s,a.dir);i.current.style.transform=`translate3d(${m}px, 0, 0)`}},onWheelScroll:p=>{a.viewport&&(a.viewport.scrollLeft=p)},onDragScroll:p=>{a.viewport&&(a.viewport.scrollLeft=_(p,a.dir))}}):n==="vertical"?u.jsx(TD,{...d,ref:e,onThumbPositionChange:()=>{if(a.viewport&&i.current){const p=a.viewport.scrollTop,m=WE(p,s);i.current.style.transform=`translate3d(0, ${m}px, 0)`}},onWheelScroll:p=>{a.viewport&&(a.viewport.scrollTop=p)},onDragScroll:p=>{a.viewport&&(a.viewport.scrollTop=_(p))}}):null}),bD=b.forwardRef((t,e)=>{const{sizes:n,onSizesChange:r,...a}=t,i=Ft(on,t.__scopeScrollArea),[o,s]=b.useState(),l=b.useRef(null),c=ke(e,l,i.onScrollbarXChange);return b.useEffect(()=>{l.current&&s(getComputedStyle(l.current))},[l]),u.jsx(qE,{"data-orientation":"horizontal",...a,ref:c,sizes:n,style:{bottom:0,left:i.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:i.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":hi(n)+"px",...t.style},onThumbPointerDown:d=>t.onThumbPointerDown(d.x),onDragScroll:d=>t.onDragScroll(d.x),onWheelScroll:(d,_)=>{if(i.viewport){const p=i.viewport.scrollLeft+d.deltaX;t.onWheelScroll(p),QE(p,_)&&d.preventDefault()}},onResize:()=>{l.current&&i.viewport&&o&&r({content:i.viewport.scrollWidth,viewport:i.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ti(o.paddingLeft),paddingEnd:Ti(o.paddingRight)}})}})}),TD=b.forwardRef((t,e)=>{const{sizes:n,onSizesChange:r,...a}=t,i=Ft(on,t.__scopeScrollArea),[o,s]=b.useState(),l=b.useRef(null),c=ke(e,l,i.onScrollbarYChange);return b.useEffect(()=>{l.current&&s(getComputedStyle(l.current))},[l]),u.jsx(qE,{"data-orientation":"vertical",...a,ref:c,sizes:n,style:{top:0,right:i.dir==="ltr"?0:void 0,left:i.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":hi(n)+"px",...t.style},onThumbPointerDown:d=>t.onThumbPointerDown(d.y),onDragScroll:d=>t.onDragScroll(d.y),onWheelScroll:(d,_)=>{if(i.viewport){const p=i.viewport.scrollTop+d.deltaY;t.onWheelScroll(p),QE(p,_)&&d.preventDefault()}},onResize:()=>{l.current&&i.viewport&&o&&r({content:i.viewport.scrollHeight,viewport:i.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ti(o.paddingTop),paddingEnd:Ti(o.paddingBottom)}})}})}),[hD,HE]=UE(on),qE=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:a,onThumbChange:i,onThumbPointerUp:o,onThumbPointerDown:s,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:_,...p}=t,m=Ft(on,n),[g,f]=b.useState(null),E=ke(e,D=>f(D)),S=b.useRef(null),T=b.useRef(""),h=m.viewport,v=r.content-r.viewport,R=pt(d),C=pt(l),N=Ri(_,10);function O(D){if(S.current){const w=D.clientX-S.current.left,L=D.clientY-S.current.top;c({x:w,y:L})}}return b.useEffect(()=>{const D=w=>{const L=w.target;(g==null?void 0:g.contains(L))&&R(w,v)};return document.addEventListener("wheel",D,{passive:!1}),()=>document.removeEventListener("wheel",D,{passive:!1})},[h,g,v,R]),b.useEffect(C,[r,C]),pr(g,N),pr(m.content,N),u.jsx(hD,{scope:n,scrollbar:g,hasThumb:a,onThumbChange:pt(i),onThumbPointerUp:pt(o),onThumbPositionChange:C,onThumbPointerDown:pt(s),children:u.jsx(ye.div,{...p,ref:E,style:{position:"absolute",...p.style},onPointerDown:de(t.onPointerDown,D=>{D.button===0&&(D.target.setPointerCapture(D.pointerId),S.current=g.getBoundingClientRect(),T.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",m.viewport&&(m.viewport.style.scrollBehavior="auto"),O(D))}),onPointerMove:de(t.onPointerMove,O),onPointerUp:de(t.onPointerUp,D=>{const w=D.target;w.hasPointerCapture(D.pointerId)&&w.releasePointerCapture(D.pointerId),document.body.style.webkitUserSelect=T.current,m.viewport&&(m.viewport.style.scrollBehavior=""),S.current=null})})})}),bi="ScrollAreaThumb",VE=b.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=HE(bi,t.__scopeScrollArea);return u.jsx(vt,{present:n||a.hasThumb,children:u.jsx(RD,{ref:e,...r})})}),RD=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,style:r,...a}=t,i=Ft(bi,n),o=HE(bi,n),{onThumbPositionChange:s}=o,l=ke(e,_=>o.onThumbChange(_)),c=b.useRef(void 0),d=Ri(()=>{c.current&&(c.current(),c.current=void 0)},100);return b.useEffect(()=>{const _=i.viewport;if(_){const p=()=>{if(d(),!c.current){const m=ND(_,s);c.current=m,s()}};return s(),_.addEventListener("scroll",p),()=>_.removeEventListener("scroll",p)}},[i.viewport,d,s]),u.jsx(ye.div,{"data-state":o.hasThumb?"visible":"hidden",...a,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:de(t.onPointerDownCapture,_=>{const m=_.target.getBoundingClientRect(),g=_.clientX-m.left,f=_.clientY-m.top;o.onThumbPointerDown({x:g,y:f})}),onPointerUp:de(t.onPointerUp,o.onThumbPointerUp)})});VE.displayName=bi;var Hs="ScrollAreaCorner",zE=b.forwardRef((t,e)=>{const n=Ft(Hs,t.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(CD,{...t,ref:e}):null});zE.displayName=Hs;var CD=b.forwardRef((t,e)=>{const{__scopeScrollArea:n,...r}=t,a=Ft(Hs,n),[i,o]=b.useState(0),[s,l]=b.useState(0),c=!!(i&&s);return pr(a.scrollbarX,()=>{var _;const d=((_=a.scrollbarX)==null?void 0:_.offsetHeight)||0;a.onCornerHeightChange(d),l(d)}),pr(a.scrollbarY,()=>{var _;const d=((_=a.scrollbarY)==null?void 0:_.offsetWidth)||0;a.onCornerWidthChange(d),o(d)}),c?u.jsx(ye.div,{...r,ref:e,style:{width:i,height:s,position:"absolute",right:a.dir==="ltr"?0:void 0,left:a.dir==="rtl"?0:void 0,bottom:0,...t.style}}):null});function Ti(t){return t?parseInt(t,10):0}function $E(t,e){const n=t/e;return isNaN(n)?0:n}function hi(t){const e=$E(t.viewport,t.content),n=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,r=(t.scrollbar.size-n)*e;return Math.max(r,18)}function vD(t,e,n,r="ltr"){const a=hi(n),i=a/2,o=e||i,s=a-o,l=n.scrollbar.paddingStart+o,c=n.scrollbar.size-n.scrollbar.paddingEnd-s,d=n.content-n.viewport,_=r==="ltr"?[0,d]:[d*-1,0];return KE([l,c],_)(t)}function WE(t,e,n="ltr"){const r=hi(e),a=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,i=e.scrollbar.size-a,o=e.content-e.viewport,s=i-r,l=n==="ltr"?[0,o]:[o*-1,0],c=Fs(t,l);return KE([0,o],[0,s])(c)}function KE(t,e){return n=>{if(t[0]===t[1]||e[0]===e[1])return e[0];const r=(e[1]-e[0])/(t[1]-t[0]);return e[0]+r*(n-t[0])}}function QE(t,e){return t>0&&t<e}var ND=(t,e=()=>{})=>{let n={left:t.scrollLeft,top:t.scrollTop},r=0;return function a(){const i={left:t.scrollLeft,top:t.scrollTop},o=n.left!==i.left,s=n.top!==i.top;(o||s)&&e(),n=i,r=window.requestAnimationFrame(a)}(),()=>window.cancelAnimationFrame(r)};function Ri(t,e){const n=pt(t),r=b.useRef(0);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),b.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,e)},[n,e])}function pr(t,e){const n=pt(e);_t(()=>{let r=0;if(t){const a=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return a.observe(t),()=>{window.cancelAnimationFrame(r),a.unobserve(t)}}},[t,n])}var jE=FE,OD=GE,yD=zE;const XE=b.forwardRef(({className:t,children:e,...n},r)=>u.jsxs(jE,{ref:r,className:$("relative overflow-hidden",t),...n,children:[u.jsx(OD,{className:"h-full w-full rounded-[inherit] overflow-auto",children:e}),u.jsx(ZE,{}),u.jsx(yD,{})]}));XE.displayName=jE.displayName;const ZE=b.forwardRef(({className:t,orientation:e="vertical",...n},r)=>u.jsx(Gs,{ref:r,orientation:e,className:$("flex touch-none select-none transition-colors",e==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",e==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",t),...n,children:u.jsx(VE,{className:"relative flex-1 rounded-full bg-border"})}));ZE.displayName=Gs.displayName;function Ci({className:t="",showCreateButton:e=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:a="400px",customStyles:i={},currentThreadId:o=null,navigateToThread:s,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{loadThread:_,threads:p,refreshThreads:m,currentThreadId:g,createThread:f,deleteThread:E,renameThread:S}=ba(),[T,h]=y.useState(p??[]),[v,R]=y.useState(!1),[C,N]=y.useState(null),[O,D]=y.useState(null),[w,L]=y.useState(""),[H,z]=y.useState(!1);y.useEffect(()=>{h(p??[])},[p]);const P=async q=>{try{await _(q),s==null||s(q),l==null||l(q)}catch(X){console.error("Failed to select thread:",X)}},G=async()=>{try{z(!0);const q=await f();c==null||c(q),s==null||s(q)}catch(q){console.error("Failed to create thread:",q)}finally{z(!1)}},I=async(q,X)=>{if(X.stopPropagation(),!!confirm("Delete this thread?"))try{await E(q),d==null||d(q)}catch(ce){console.error("Failed to delete thread:",ce)}},U=(q,X)=>{X.stopPropagation(),D(q.threadId),L(q.title||`Thread ${q.threadId.slice(0,8)}`)},M=async q=>{if(w.trim())try{await S(q,w.trim()),D(null),L("")}catch(X){console.error("Failed to update title:",X)}},k=()=>{D(null),L("")},Y=(q,X)=>{q.key==="Enter"?M(X):q.key==="Escape"&&k()},W=q=>{if(!q)return"";try{const X=new Date(q),ge=new Date().getTime()-X.getTime(),V=Math.floor(ge/(1e3*60*60*24));return V===0?X.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):V===1?"Yesterday":V<7?`${V} days ago`:X.toLocaleDateString()}catch{return""}},re=q=>q.title||`Thread ${q.threadId.slice(0,8)}`;return u.jsxs("div",{className:`flex flex-col h-full ${t} ${i.container||""}`,children:[e&&u.jsx("div",{className:i.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Ve,{onClick:G,disabled:H||v,className:i.createButton||"p-2",size:"sm",variant:"ghost",title:H?"Creating...":"New Chat",children:u.jsx(pe.MessageSquarePlus,{size:20})})}),u.jsx(XE,{className:`flex-1 min-h-0 ${i.threadList||""}`,style:a?{maxHeight:a}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:v?u.jsx("div",{className:"text-center py-8 text-slate-400",children:"Loading…"}):T.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(pe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):T.slice().sort((q,X)=>new Date(X.updatedAt||X.createdAt||"").getTime()-new Date(q.updatedAt||q.createdAt||"").getTime()).map(q=>u.jsxs("div",{onClick:()=>P(q.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(o??g)===q.threadId?`${i.activeThread||"bg-slate-600 border-slate-500"} `:`${i.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${i.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:O===q.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:X=>X.stopPropagation(),children:[u.jsx(Jr,{value:w,onChange:X=>L(X.target.value),onKeyDown:X=>Y(X,q.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>M(q.threadId),className:"h-6 w-6 p-0",children:u.jsx(pe.Check,{size:12})}),u.jsx(Ve,{variant:"ghost",size:"sm",onClick:k,className:"h-6 w-6 p-0",children:u.jsx(pe.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:re(q)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(pe.Calendar,{size:10}),u.jsx("span",{children:W(q.updatedAt||q.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&O!==q.threadId&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:X=>U(q,X),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(pe.Edit3,{size:12})}),n&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:X=>I(q.threadId,X),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(pe.Trash2,{size:12})})]})]}),o===q.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},q.threadId))})})]})}const JE=y.createContext(null);function ID({children:t,basePath:e="/chat"}){const n=y.useMemo(()=>e?e==="/"?"":e.endsWith("/")?e.slice(0,-1):e:"/chat",[e]),r={basePath:n,buildThreadPath:a=>`${n}/${a}`,buildBasePath:()=>n};return u.jsx(JE.Provider,{value:r,children:t})}function AD(){const t=y.useContext(JE);return t||{basePath:"/chat",buildThreadPath:e=>`/chat/${e}`,buildBasePath:()=>"/chat"}}function mr(t){if(!(typeof globalThis>"u"))return globalThis[t]}function xD(t){if(typeof t!="string")return;const e=t.trim();if(e)return e.replace(/\/+$/g,"")}function ef(){const t=[mr("__API_BASE_URL__"),mr("__CHAT_API_BASE_URL__"),mr("__CHAT_API_URL__")];for(const e of t){const n=xD(e);if(n)return n}}function tf(){const t=[mr("__API_AUTH_TOKEN__"),mr("__CHAT_API_KEY__"),mr("__CHAT_AUTH_TOKEN__")];for(const e of t)if(typeof e=="string"&&e.trim())return e.trim()}function nf(){const t={},e=ef(),n=tf();return e&&(t.baseUrl=e),n&&(t.apiKey=n),t}function rf(){const t=nf(),e=cn.getAuthToken(),n=ef();return{apiBaseUrl:t.baseUrl||cn.baseUrl||n||"http://localhost:8000",apiKey:e||t.apiKey||tf()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const af="chat-settings";function DD(){try{const t=localStorage.getItem(af);return t?JSON.parse(t):{}}catch(t){return console.error("Failed to parse stored settings:",t),{}}}function wD(t){try{localStorage.setItem(af,JSON.stringify(t)),t.apiKey&&cn.setAuthToken(t.apiKey)}catch(e){console.error("Failed to save settings:",e)}}function MD(){const t=rf(),e=DD(),n=cn.getAuthToken();return{...t,...e,apiKey:n||e.apiKey||t.apiKey,apiBaseUrl:cn.baseUrl||e.apiBaseUrl||t.apiBaseUrl}}function LD(t){t.apiKey&&cn.setAuthToken(t.apiKey),wD(t)}const qs=768;function PD(){const[t,e]=b.useState(void 0);return b.useEffect(()=>{const n=window.matchMedia(`(max-width: ${qs-1}px)`),r=()=>{e(window.innerWidth<qs)};return n.addEventListener("change",r),e(window.innerWidth<qs),()=>n.removeEventListener("change",r)},[]),!!t}var kD="Separator",of="horizontal",UD=["horizontal","vertical"],sf=b.forwardRef((t,e)=>{const{decorative:n,orientation:r=of,...a}=t,i=FD(r)?r:of,s=n?{role:"none"}:{"aria-orientation":i==="vertical"?i:void 0,role:"separator"};return u.jsx(ye.div,{"data-orientation":i,...s,...a,ref:e})});sf.displayName=kD;function FD(t){return UD.includes(t)}var lf=sf;const Vs=b.forwardRef(({className:t,orientation:e="horizontal",decorative:n=!0,...r},a)=>u.jsx(lf,{ref:a,decorative:n,orientation:e,className:$("shrink-0 bg-border",e==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...r}));Vs.displayName=lf.displayName;const cf=zm,BD=tI,GD=$m,df=b.forwardRef(({className:t,...e},n)=>u.jsx(Xa,{className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e,ref:n}));df.displayName=Xa.displayName;const YD=br.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),zs=b.forwardRef(({side:t="right",className:e,children:n,...r},a)=>u.jsxs(GD,{children:[u.jsx(df,{}),u.jsxs(Za,{ref:a,className:$(YD({side:t}),e),...r,children:[n,u.jsxs(Wm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(pe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));zs.displayName=Za.displayName;const uf=({className:t,...e})=>u.jsx("div",{className:$("flex flex-col space-y-2 text-center sm:text-left",t),...e});uf.displayName="SheetHeader";const _f=b.forwardRef(({className:t,...e},n)=>u.jsx(Gn,{ref:n,className:$("text-lg font-semibold text-foreground",t),...e}));_f.displayName=Gn.displayName;const pf=b.forwardRef(({className:t,...e},n)=>u.jsx(Ja,{ref:n,className:$("text-sm text-muted-foreground",t),...e}));pf.displayName=Ja.displayName;function mf({className:t,...e}){return u.jsx("div",{className:$("animate-pulse rounded-md bg-muted",t),...e})}var gf=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"}),HD="VisuallyHidden",Ef=b.forwardRef((t,e)=>u.jsx(ye.span,{...t,ref:e,style:{...gf,...t.style}}));Ef.displayName=HD;var qD=Ef,[vi,tF]=qt("Tooltip",[_r]),Ni=_r(),ff="TooltipProvider",VD=700,$s="tooltip.open",[zD,Ws]=vi(ff),Sf=t=>{const{__scopeTooltip:e,delayDuration:n=VD,skipDelayDuration:r=300,disableHoverableContent:a=!1,children:i}=t,o=b.useRef(!0),s=b.useRef(!1),l=b.useRef(0);return b.useEffect(()=>{const c=l.current;return()=>window.clearTimeout(c)},[]),u.jsx(zD,{scope:e,isOpenDelayedRef:o,delayDuration:n,onOpen:b.useCallback(()=>{window.clearTimeout(l.current),o.current=!1},[]),onClose:b.useCallback(()=>{window.clearTimeout(l.current),l.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:b.useCallback(c=>{s.current=c},[]),disableHoverableContent:a,children:i})};Sf.displayName=ff;var ea="Tooltip",[$D,Oi]=vi(ea),bf=t=>{const{__scopeTooltip:e,children:n,open:r,defaultOpen:a,onOpenChange:i,disableHoverableContent:o,delayDuration:s}=t,l=Ws(ea,t.__scopeTooltip),c=Ni(e),[d,_]=b.useState(null),p=Vt(),m=b.useRef(0),g=o??l.disableHoverableContent,f=s??l.delayDuration,E=b.useRef(!1),[S,T]=Rn({prop:r,defaultProp:a??!1,onChange:N=>{N?(l.onOpen(),document.dispatchEvent(new CustomEvent($s))):l.onClose(),i==null||i(N)},caller:ea}),h=b.useMemo(()=>S?E.current?"delayed-open":"instant-open":"closed",[S]),v=b.useCallback(()=>{window.clearTimeout(m.current),m.current=0,E.current=!1,T(!0)},[T]),R=b.useCallback(()=>{window.clearTimeout(m.current),m.current=0,T(!1)},[T]),C=b.useCallback(()=>{window.clearTimeout(m.current),m.current=window.setTimeout(()=>{E.current=!0,T(!0),m.current=0},f)},[f,T]);return b.useEffect(()=>()=>{m.current&&(window.clearTimeout(m.current),m.current=0)},[]),u.jsx(Cs,{...c,children:u.jsx($D,{scope:e,contentId:p,open:S,stateAttribute:h,trigger:d,onTriggerChange:_,onTriggerEnter:b.useCallback(()=>{l.isOpenDelayedRef.current?C():v()},[l.isOpenDelayedRef,C,v]),onTriggerLeave:b.useCallback(()=>{g?R():(window.clearTimeout(m.current),m.current=0)},[R,g]),onOpen:v,onClose:R,disableHoverableContent:g,children:n})})};bf.displayName=ea;var Ks="TooltipTrigger",Tf=b.forwardRef((t,e)=>{const{__scopeTooltip:n,...r}=t,a=Oi(Ks,n),i=Ws(Ks,n),o=Ni(n),s=b.useRef(null),l=ke(e,s,a.onTriggerChange),c=b.useRef(!1),d=b.useRef(!1),_=b.useCallback(()=>c.current=!1,[]);return b.useEffect(()=>()=>document.removeEventListener("pointerup",_),[_]),u.jsx(vs,{asChild:!0,...o,children:u.jsx(ye.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...r,ref:l,onPointerMove:de(t.onPointerMove,p=>{p.pointerType!=="touch"&&!d.current&&!i.isPointerInTransitRef.current&&(a.onTriggerEnter(),d.current=!0)}),onPointerLeave:de(t.onPointerLeave,()=>{a.onTriggerLeave(),d.current=!1}),onPointerDown:de(t.onPointerDown,()=>{a.open&&a.onClose(),c.current=!0,document.addEventListener("pointerup",_,{once:!0})}),onFocus:de(t.onFocus,()=>{c.current||a.onOpen()}),onBlur:de(t.onBlur,a.onClose),onClick:de(t.onClick,a.onClose)})})});Tf.displayName=Ks;var WD="TooltipPortal",[nF,KD]=vi(WD,{forceMount:void 0}),gr="TooltipContent",hf=b.forwardRef((t,e)=>{const n=KD(gr,t.__scopeTooltip),{forceMount:r=n.forceMount,side:a="top",...i}=t,o=Oi(gr,t.__scopeTooltip);return u.jsx(vt,{present:r||o.open,children:o.disableHoverableContent?u.jsx(Rf,{side:a,...i,ref:e}):u.jsx(QD,{side:a,...i,ref:e})})}),QD=b.forwardRef((t,e)=>{const n=Oi(gr,t.__scopeTooltip),r=Ws(gr,t.__scopeTooltip),a=b.useRef(null),i=ke(e,a),[o,s]=b.useState(null),{trigger:l,onClose:c}=n,d=a.current,{onPointerInTransitChange:_}=r,p=b.useCallback(()=>{s(null),_(!1)},[_]),m=b.useCallback((g,f)=>{const E=g.currentTarget,S={x:g.clientX,y:g.clientY},T=ew(S,E.getBoundingClientRect()),h=tw(S,T),v=nw(f.getBoundingClientRect()),R=aw([...h,...v]);s(R),_(!0)},[_]);return b.useEffect(()=>()=>p(),[p]),b.useEffect(()=>{if(l&&d){const g=E=>m(E,d),f=E=>m(E,l);return l.addEventListener("pointerleave",g),d.addEventListener("pointerleave",f),()=>{l.removeEventListener("pointerleave",g),d.removeEventListener("pointerleave",f)}}},[l,d,m,p]),b.useEffect(()=>{if(o){const g=f=>{const E=f.target,S={x:f.clientX,y:f.clientY},T=(l==null?void 0:l.contains(E))||(d==null?void 0:d.contains(E)),h=!rw(S,o);T?p():h&&(p(),c())};return document.addEventListener("pointermove",g),()=>document.removeEventListener("pointermove",g)}},[l,d,o,c,p]),u.jsx(Rf,{...t,ref:i})}),[jD,XD]=vi(ea,{isInside:!1}),ZD=Nt.createSlottable("TooltipContent"),Rf=b.forwardRef((t,e)=>{const{__scopeTooltip:n,children:r,"aria-label":a,onEscapeKeyDown:i,onPointerDownOutside:o,...s}=t,l=Oi(gr,n),c=Ni(n),{onClose:d}=l;return b.useEffect(()=>(document.addEventListener($s,d),()=>document.removeEventListener($s,d)),[d]),b.useEffect(()=>{if(l.trigger){const _=p=>{const m=p.target;m!=null&&m.contains(l.trigger)&&d()};return window.addEventListener("scroll",_,{capture:!0}),()=>window.removeEventListener("scroll",_,{capture:!0})}},[l.trigger,d]),u.jsx(Yr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:i,onPointerDownOutside:o,onFocusOutside:_=>_.preventDefault(),onDismiss:d,children:u.jsxs(Ns,{"data-state":l.stateAttribute,...c,...s,ref:e,style:{...s.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[u.jsx(ZD,{children:r}),u.jsx(jD,{scope:n,isInside:!0,children:u.jsx(qD,{id:l.contentId,role:"tooltip",children:a||r})})]})})});hf.displayName=gr;var Cf="TooltipArrow",JD=b.forwardRef((t,e)=>{const{__scopeTooltip:n,...r}=t,a=Ni(n);return XD(Cf,n).isInside?null:u.jsx(Os,{...a,...r,ref:e})});JD.displayName=Cf;function ew(t,e){const n=Math.abs(e.top-t.y),r=Math.abs(e.bottom-t.y),a=Math.abs(e.right-t.x),i=Math.abs(e.left-t.x);switch(Math.min(n,r,a,i)){case i:return"left";case a:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function tw(t,e,n=5){const r=[];switch(e){case"top":r.push({x:t.x-n,y:t.y+n},{x:t.x+n,y:t.y+n});break;case"bottom":r.push({x:t.x-n,y:t.y-n},{x:t.x+n,y:t.y-n});break;case"left":r.push({x:t.x+n,y:t.y-n},{x:t.x+n,y:t.y+n});break;case"right":r.push({x:t.x-n,y:t.y-n},{x:t.x-n,y:t.y+n});break}return r}function nw(t){const{top:e,right:n,bottom:r,left:a}=t;return[{x:a,y:e},{x:n,y:e},{x:n,y:r},{x:a,y:r}]}function rw(t,e){const{x:n,y:r}=t;let a=!1;for(let i=0,o=e.length-1;i<e.length;o=i++){const s=e[i],l=e[o],c=s.x,d=s.y,_=l.x,p=l.y;d>r!=p>r&&n<(_-c)*(r-d)/(p-d)+c&&(a=!a)}return a}function aw(t){const e=t.slice();return e.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),iw(e)}function iw(t){if(t.length<=1)return t.slice();const e=[];for(let r=0;r<t.length;r++){const a=t[r];for(;e.length>=2;){const i=e[e.length-1],o=e[e.length-2];if((i.x-o.x)*(a.y-o.y)>=(i.y-o.y)*(a.x-o.x))e.pop();else break}e.push(a)}e.pop();const n=[];for(let r=t.length-1;r>=0;r--){const a=t[r];for(;n.length>=2;){const i=n[n.length-1],o=n[n.length-2];if((i.x-o.x)*(a.y-o.y)>=(i.y-o.y)*(a.x-o.x))n.pop();else break}n.push(a)}return n.pop(),e.length===1&&n.length===1&&e[0].x===n[0].x&&e[0].y===n[0].y?e:e.concat(n)}var ow=Sf,sw=bf,lw=Tf,vf=hf;const cw=ow,dw=sw,uw=lw,Nf=b.forwardRef(({className:t,sideOffset:e=4,...n},r)=>u.jsx(vf,{ref:r,sideOffset:e,className:$("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",t),...n}));Nf.displayName=vf.displayName;const _w="sidebar:state",pw=60*60*24*7,mw="16rem",gw="18rem",Ew="3rem",fw="b",Of=b.createContext(null);function yi(){const t=b.useContext(Of);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}const yf=b.forwardRef(({defaultOpen:t=!0,open:e,onOpenChange:n,className:r,style:a,children:i,...o},s)=>{const l=PD(),[c,d]=b.useState(!1),[_,p]=b.useState(t),m=e??_,g=b.useCallback(T=>{const h=typeof T=="function"?T(m):T;n?n(h):p(h),document.cookie=`${_w}=${h}; path=/; max-age=${pw}`},[n,m]),f=b.useCallback(()=>l?d(T=>!T):g(T=>!T),[l,g,d]);b.useEffect(()=>{const T=h=>{h.key===fw&&(h.metaKey||h.ctrlKey)&&(h.preventDefault(),f())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[f]);const E=m?"expanded":"collapsed",S=b.useMemo(()=>({state:E,open:m,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:d,toggleSidebar:f}),[E,m,g,l,c,d,f]);return u.jsx(Of.Provider,{value:S,children:u.jsx(cw,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":mw,"--sidebar-width-icon":Ew,...a},className:$("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",r),ref:s,...o,children:i})})})});yf.displayName="SidebarProvider";const If=b.forwardRef(({side:t="left",variant:e="sidebar",collapsible:n="offcanvas",className:r,children:a,...i},o)=>{const{isMobile:s,state:l,openMobile:c,setOpenMobile:d}=yi();return n==="none"?u.jsx("div",{className:$("flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",r),ref:o,...i,children:a}):s?u.jsx(cf,{open:c,onOpenChange:d,...i,children:u.jsx(zs,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":gw},side:t,children:u.jsx("div",{className:"flex h-full w-full flex-col",children:a})})}):u.jsxs("div",{ref:o,className:"group peer hidden md:block text-sidebar-foreground","data-state":l,"data-collapsible":l==="collapsed"?n:"","data-variant":e,"data-side":t,children:[u.jsx("div",{className:$("duration-200 relative h-svh w-[--sidebar-width] bg-transparent transition-[width] ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",e==="floating"||e==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),u.jsx("div",{className:$("duration-200 fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] ease-linear md:flex",t==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",e==="floating"||e==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...i,children:u.jsx("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow",children:a})})]})});If.displayName="Sidebar";const Af=b.forwardRef(({className:t,onClick:e,...n},r)=>{const{toggleSidebar:a}=yi();return u.jsxs(Ve,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:$("h-7 w-7",t),onClick:i=>{e==null||e(i),a()},...n,children:[u.jsx(pe.PanelLeft,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});Af.displayName="SidebarTrigger";const Sw=b.forwardRef(({className:t,...e},n)=>{const{toggleSidebar:r}=yi();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:$("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",t),...e})});Sw.displayName="SidebarRail";const xf=b.forwardRef(({className:t,...e},n)=>u.jsx("main",{ref:n,className:$("relative flex min-h-svh flex-1 flex-col bg-background","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",t),...e}));xf.displayName="SidebarInset";const bw=b.forwardRef(({className:t,...e},n)=>u.jsx(Jr,{ref:n,"data-sidebar":"input",className:$("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",t),...e}));bw.displayName="SidebarInput";const Df=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:$("flex flex-col gap-2 p-2",t),...e}));Df.displayName="SidebarHeader";const Tw=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:$("flex flex-col gap-2 p-2",t),...e}));Tw.displayName="SidebarFooter";const hw=b.forwardRef(({className:t,...e},n)=>u.jsx(Vs,{ref:n,"data-sidebar":"separator",className:$("mx-2 w-auto bg-sidebar-border",t),...e}));hw.displayName="SidebarSeparator";const wf=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:$("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",t),...e}));wf.displayName="SidebarContent";const Mf=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:$("relative flex w-full min-w-0 flex-col p-2",t),...e}));Mf.displayName="SidebarGroup";const Lf=b.forwardRef(({className:t,asChild:e=!1,...n},r)=>{const a=e?Nt.Slot:"div";return u.jsx(a,{ref:r,"data-sidebar":"group-label",className:$("duration-200 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opa] ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",t),...n})});Lf.displayName="SidebarGroupLabel";const Rw=b.forwardRef(({className:t,asChild:e=!1,...n},r)=>{const a=e?Nt.Slot:"button";return u.jsx(a,{ref:r,"data-sidebar":"group-action",className:$("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",t),...n})});Rw.displayName="SidebarGroupAction";const Pf=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:$("w-full text-sm",t),...e}));Pf.displayName="SidebarGroupContent";const kf=b.forwardRef(({className:t,...e},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:$("flex w-full min-w-0 flex-col gap-1",t),...e}));kf.displayName="SidebarMenu";const Uf=b.forwardRef(({className:t,...e},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:$("group/menu-item relative",t),...e}));Uf.displayName="SidebarMenuItem";const Cw=br.cva("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),Ff=b.forwardRef(({asChild:t=!1,isActive:e=!1,variant:n="default",size:r="default",tooltip:a,className:i,...o},s)=>{const l=t?Nt.Slot:"button",{isMobile:c,state:d}=yi(),_=u.jsx(l,{ref:s,"data-sidebar":"menu-button","data-size":r,"data-active":e,className:$(Cw({variant:n,size:r}),i),...o});return a?(typeof a=="string"&&(a={children:a}),u.jsxs(dw,{children:[u.jsx(uw,{asChild:!0,children:_}),u.jsx(Nf,{side:"right",align:"center",hidden:d!=="collapsed"||c,...a})]})):_});Ff.displayName="SidebarMenuButton";const vw=b.forwardRef(({className:t,asChild:e=!1,showOnHover:n=!1,...r},a)=>{const i=e?Nt.Slot:"button";return u.jsx(i,{ref:a,"data-sidebar":"menu-action",className:$("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",n&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",t),...r})});vw.displayName="SidebarMenuAction";const Nw=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:$("absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground select-none pointer-events-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",t),...e}));Nw.displayName="SidebarMenuBadge";const Ow=b.forwardRef(({className:t,showIcon:e=!1,...n},r)=>{const a=b.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:$("rounded-md h-8 flex gap-2 px-2 items-center",t),...n,children:[e&&u.jsx(mf,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(mf,{className:"h-4 flex-1 max-w-[--skeleton-width]","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":a}})]})});Ow.displayName="SidebarMenuSkeleton";const yw=b.forwardRef(({className:t,...e},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:$("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",t),...e}));yw.displayName="SidebarMenuSub";const Iw=b.forwardRef(({...t},e)=>u.jsx("li",{ref:e,...t}));Iw.displayName="SidebarMenuSubItem";const Aw=b.forwardRef(({asChild:t=!1,size:e="md",isActive:n,className:r,...a},i)=>{const o=t?Nt.Slot:"a";return u.jsx(o,{ref:i,"data-sidebar":"menu-sub-button","data-size":e,"data-active":n,className:$("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",e==="sm"&&"text-xs",e==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...a})});Aw.displayName="SidebarMenuSubButton";function xw({header:t,sidebarTitle:e="Threads",showThreads:n=!0,className:r="",sidebarClassName:a="",chatClassName:i="",...o}){return u.jsx(yr,{...o,children:u.jsxs(yf,{className:`w-full ${r}`,children:[u.jsxs(If,{className:`border-r ${a}`,children:[u.jsx(Df,{children:u.jsx(kf,{children:u.jsx(Uf,{children:u.jsx(Ff,{asChild:!0,size:"lg",children:u.jsx("span",{className:"font-semibold",children:e})})})})}),u.jsx(wf,{children:n&&u.jsxs(Mf,{children:[u.jsx(Lf,{children:"Conversations"}),u.jsx(Pf,{children:u.jsx("div",{className:"px-2 py-1",children:u.jsx(Ci,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-[calc(100vh-12rem)]"})})})]})})]}),u.jsxs(xf,{children:[u.jsxs("header",{className:"h-14 border-b bg-background/60 backdrop-blur flex items-center gap-2 px-4",children:[u.jsx(Af,{}),u.jsx("div",{className:"flex-1"}),t]}),u.jsx("main",{className:`flex-1 min-h-0 overflow-hidden ${i}`,children:u.jsx(Zr,{})})]})]})})}var Dw="Label",Bf=b.forwardRef((t,e)=>u.jsx(ye.label,{...t,ref:e,onMouseDown:n=>{var a;n.target.closest("button, input, select, textarea")||((a=t.onMouseDown)==null||a.call(t,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Bf.displayName=Dw;var Gf=Bf;const ww=br.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Bt=b.forwardRef(({className:t,...e},n)=>u.jsx(Gf,{ref:n,className:$(ww(),t),...e}));Bt.displayName=Gf.displayName;function Yf(t){const e=b.useRef({value:t,previous:t});return b.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}var Ii="Switch",[Mw,rF]=qt(Ii),[Lw,Pw]=Mw(Ii),Hf=b.forwardRef((t,e)=>{const{__scopeSwitch:n,name:r,checked:a,defaultChecked:i,required:o,disabled:s,value:l="on",onCheckedChange:c,form:d,..._}=t,[p,m]=b.useState(null),g=ke(e,h=>m(h)),f=b.useRef(!1),E=p?d||!!p.closest("form"):!0,[S,T]=Rn({prop:a,defaultProp:i??!1,onChange:c,caller:Ii});return u.jsxs(Lw,{scope:n,checked:S,disabled:s,children:[u.jsx(ye.button,{type:"button",role:"switch","aria-checked":S,"aria-required":o,"data-state":$f(S),"data-disabled":s?"":void 0,disabled:s,value:l,..._,ref:g,onClick:de(t.onClick,h=>{T(v=>!v),E&&(f.current=h.isPropagationStopped(),f.current||h.stopPropagation())})}),E&&u.jsx(zf,{control:p,bubbles:!f.current,name:r,value:l,checked:S,required:o,disabled:s,form:d,style:{transform:"translateX(-100%)"}})]})});Hf.displayName=Ii;var qf="SwitchThumb",Vf=b.forwardRef((t,e)=>{const{__scopeSwitch:n,...r}=t,a=Pw(qf,n);return u.jsx(ye.span,{"data-state":$f(a.checked),"data-disabled":a.disabled?"":void 0,...r,ref:e})});Vf.displayName=qf;var kw="SwitchBubbleInput",zf=b.forwardRef(({__scopeSwitch:t,control:e,checked:n,bubbles:r=!0,...a},i)=>{const o=b.useRef(null),s=ke(o,i),l=Yf(n),c=Og(e);return b.useEffect(()=>{const d=o.current;if(!d)return;const _=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(_,"checked").set;if(l!==n&&m){const g=new Event("click",{bubbles:r});m.call(d,n),d.dispatchEvent(g)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...a,tabIndex:-1,ref:s,style:{...a.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});zf.displayName=kw;function $f(t){return t?"checked":"unchecked"}var Wf=Hf,Uw=Vf;const yn=b.forwardRef(({className:t,...e},n)=>u.jsx(Wf,{className:$("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",t),...e,ref:n,children:u.jsx(Uw,{className:$("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));yn.displayName=Wf.displayName;var Fw=[" ","Enter","ArrowUp","ArrowDown"],Bw=[" ","Enter"],Vn="Select",[Ai,xi,Gw]=cs(Vn),[Er,aF]=qt(Vn,[Gw,_r]),Di=_r(),[Yw,In]=Er(Vn),[Hw,qw]=Er(Vn),Kf=t=>{const{__scopeSelect:e,children:n,open:r,defaultOpen:a,onOpenChange:i,value:o,defaultValue:s,onValueChange:l,dir:c,name:d,autoComplete:_,disabled:p,required:m,form:g}=t,f=Di(e),[E,S]=b.useState(null),[T,h]=b.useState(null),[v,R]=b.useState(!1),C=ri(c),[N,O]=Rn({prop:r,defaultProp:a??!1,onChange:i,caller:Vn}),[D,w]=Rn({prop:o,defaultProp:s,onChange:l,caller:Vn}),L=b.useRef(null),H=E?g||!!E.closest("form"):!0,[z,P]=b.useState(new Set),G=Array.from(z).map(I=>I.props.value).join(";");return u.jsx(Cs,{...f,children:u.jsxs(Yw,{required:m,scope:e,trigger:E,onTriggerChange:S,valueNode:T,onValueNodeChange:h,valueNodeHasChildren:v,onValueNodeHasChildrenChange:R,contentId:Vt(),value:D,onValueChange:w,open:N,onOpenChange:O,dir:C,triggerPointerDownPosRef:L,disabled:p,children:[u.jsx(Ai.Provider,{scope:e,children:u.jsx(Hw,{scope:t.__scopeSelect,onNativeOptionAdd:b.useCallback(I=>{P(U=>new Set(U).add(I))},[]),onNativeOptionRemove:b.useCallback(I=>{P(U=>{const M=new Set(U);return M.delete(I),M})},[]),children:n})}),H?u.jsxs(SS,{"aria-hidden":!0,required:m,tabIndex:-1,name:d,autoComplete:_,value:D,onChange:I=>w(I.target.value),disabled:p,form:g,children:[D===void 0?u.jsx("option",{value:""}):null,Array.from(z)]},G):null]})})};Kf.displayName=Vn;var Qf="SelectTrigger",jf=b.forwardRef((t,e)=>{const{__scopeSelect:n,disabled:r=!1,...a}=t,i=Di(n),o=In(Qf,n),s=o.disabled||r,l=ke(e,o.onTriggerChange),c=xi(n),d=b.useRef("touch"),[_,p,m]=TS(f=>{const E=c().filter(h=>!h.disabled),S=E.find(h=>h.value===o.value),T=hS(E,f,S);T!==void 0&&o.onValueChange(T.value)}),g=f=>{s||(o.onOpenChange(!0),m()),f&&(o.triggerPointerDownPosRef.current={x:Math.round(f.pageX),y:Math.round(f.pageY)})};return u.jsx(vs,{asChild:!0,...i,children:u.jsx(ye.button,{type:"button",role:"combobox","aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:s,"data-disabled":s?"":void 0,"data-placeholder":bS(o.value)?"":void 0,...a,ref:l,onClick:de(a.onClick,f=>{f.currentTarget.focus(),d.current!=="mouse"&&g(f)}),onPointerDown:de(a.onPointerDown,f=>{d.current=f.pointerType;const E=f.target;E.hasPointerCapture(f.pointerId)&&E.releasePointerCapture(f.pointerId),f.button===0&&f.ctrlKey===!1&&f.pointerType==="mouse"&&(g(f),f.preventDefault())}),onKeyDown:de(a.onKeyDown,f=>{const E=_.current!=="";!(f.ctrlKey||f.altKey||f.metaKey)&&f.key.length===1&&p(f.key),!(E&&f.key===" ")&&Fw.includes(f.key)&&(g(),f.preventDefault())})})})});jf.displayName=Qf;var Xf="SelectValue",Zf=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:a,children:i,placeholder:o="",...s}=t,l=In(Xf,n),{onValueNodeHasChildrenChange:c}=l,d=i!==void 0,_=ke(e,l.onValueNodeChange);return _t(()=>{c(d)},[c,d]),u.jsx(ye.span,{...s,ref:_,style:{pointerEvents:"none"},children:bS(l.value)?u.jsx(u.Fragment,{children:o}):i})});Zf.displayName=Xf;var Vw="SelectIcon",Jf=b.forwardRef((t,e)=>{const{__scopeSelect:n,children:r,...a}=t;return u.jsx(ye.span,{"aria-hidden":!0,...a,ref:e,children:r||"▼"})});Jf.displayName=Vw;var zw="SelectPortal",eS=t=>u.jsx(Ga,{asChild:!0,...t});eS.displayName=zw;var zn="SelectContent",tS=b.forwardRef((t,e)=>{const n=In(zn,t.__scopeSelect),[r,a]=b.useState();if(_t(()=>{a(new DocumentFragment)},[]),!n.open){const i=r;return i?oa.createPortal(u.jsx(nS,{scope:t.__scopeSelect,children:u.jsx(Ai.Slot,{scope:t.__scopeSelect,children:u.jsx("div",{children:t.children})})}),i):null}return u.jsx(rS,{...t,ref:e})});tS.displayName=zn;var Kt=10,[nS,An]=Er(zn),$w="SelectContentImpl",Ww=Nt.createSlot("SelectContent.RemoveScroll"),rS=b.forwardRef((t,e)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:a,onEscapeKeyDown:i,onPointerDownOutside:o,side:s,sideOffset:l,align:c,alignOffset:d,arrowPadding:_,collisionBoundary:p,collisionPadding:m,sticky:g,hideWhenDetached:f,avoidCollisions:E,...S}=t,T=In(zn,n),[h,v]=b.useState(null),[R,C]=b.useState(null),N=ke(e,V=>v(V)),[O,D]=b.useState(null),[w,L]=b.useState(null),H=xi(n),[z,P]=b.useState(!1),G=b.useRef(!1);b.useEffect(()=>{if(h)return as(h)},[h]),Zo();const I=b.useCallback(V=>{const[F,...K]=H().map(oe=>oe.ref.current),[te]=K.slice(-1),le=document.activeElement;for(const oe of V)if(oe===le||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===F&&R&&(R.scrollTop=0),oe===te&&R&&(R.scrollTop=R.scrollHeight),oe==null||oe.focus(),document.activeElement!==le))return},[H,R]),U=b.useCallback(()=>I([O,h]),[I,O,h]);b.useEffect(()=>{z&&U()},[z,U]);const{onOpenChange:M,triggerPointerDownPosRef:k}=T;b.useEffect(()=>{if(h){let V={x:0,y:0};const F=te=>{var le,oe;V={x:Math.abs(Math.round(te.pageX)-(((le=k.current)==null?void 0:le.x)??0)),y:Math.abs(Math.round(te.pageY)-(((oe=k.current)==null?void 0:oe.y)??0))}},K=te=>{V.x<=10&&V.y<=10?te.preventDefault():h.contains(te.target)||M(!1),document.removeEventListener("pointermove",F),k.current=null};return k.current!==null&&(document.addEventListener("pointermove",F),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",F),document.removeEventListener("pointerup",K,{capture:!0})}}},[h,M,k]),b.useEffect(()=>{const V=()=>M(!1);return window.addEventListener("blur",V),window.addEventListener("resize",V),()=>{window.removeEventListener("blur",V),window.removeEventListener("resize",V)}},[M]);const[Y,W]=TS(V=>{const F=H().filter(le=>!le.disabled),K=F.find(le=>le.ref.current===document.activeElement),te=hS(F,V,K);te&&setTimeout(()=>te.ref.current.focus())}),re=b.useCallback((V,F,K)=>{const te=!G.current&&!K;(T.value!==void 0&&T.value===F||te)&&(D(V),te&&(G.current=!0))},[T.value]),q=b.useCallback(()=>h==null?void 0:h.focus(),[h]),X=b.useCallback((V,F,K)=>{const te=!G.current&&!K;(T.value!==void 0&&T.value===F||te)&&L(V)},[T.value]),ce=r==="popper"?Qs:aS,ge=ce===Qs?{side:s,sideOffset:l,align:c,alignOffset:d,arrowPadding:_,collisionBoundary:p,collisionPadding:m,sticky:g,hideWhenDetached:f,avoidCollisions:E}:{};return u.jsx(nS,{scope:n,content:h,viewport:R,onViewportChange:C,itemRefCallback:re,selectedItem:O,onItemLeave:q,itemTextRefCallback:X,focusSelectedItem:U,selectedItemText:w,position:r,isPositioned:z,searchRef:Y,children:u.jsx($a,{as:Ww,allowPinchZoom:!0,children:u.jsx(Ba,{asChild:!0,trapped:T.open,onMountAutoFocus:V=>{V.preventDefault()},onUnmountAutoFocus:de(a,V=>{var F;(F=T.trigger)==null||F.focus({preventScroll:!0}),V.preventDefault()}),children:u.jsx(Yr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:i,onPointerDownOutside:o,onFocusOutside:V=>V.preventDefault(),onDismiss:()=>T.onOpenChange(!1),children:u.jsx(ce,{role:"listbox",id:T.contentId,"data-state":T.open?"open":"closed",dir:T.dir,onContextMenu:V=>V.preventDefault(),...S,...ge,onPlaced:()=>P(!0),ref:N,style:{display:"flex",flexDirection:"column",outline:"none",...S.style},onKeyDown:de(S.onKeyDown,V=>{const F=V.ctrlKey||V.altKey||V.metaKey;if(V.key==="Tab"&&V.preventDefault(),!F&&V.key.length===1&&W(V.key),["ArrowUp","ArrowDown","Home","End"].includes(V.key)){let te=H().filter(le=>!le.disabled).map(le=>le.ref.current);if(["ArrowUp","End"].includes(V.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(V.key)){const le=V.target,oe=te.indexOf(le);te=te.slice(oe+1)}setTimeout(()=>I(te)),V.preventDefault()}})})})})})})});rS.displayName=$w;var Kw="SelectItemAlignedPosition",aS=b.forwardRef((t,e)=>{const{__scopeSelect:n,onPlaced:r,...a}=t,i=In(zn,n),o=An(zn,n),[s,l]=b.useState(null),[c,d]=b.useState(null),_=ke(e,N=>d(N)),p=xi(n),m=b.useRef(!1),g=b.useRef(!0),{viewport:f,selectedItem:E,selectedItemText:S,focusSelectedItem:T}=o,h=b.useCallback(()=>{if(i.trigger&&i.valueNode&&s&&c&&f&&E&&S){const N=i.trigger.getBoundingClientRect(),O=c.getBoundingClientRect(),D=i.valueNode.getBoundingClientRect(),w=S.getBoundingClientRect();if(i.dir!=="rtl"){const le=w.left-O.left,oe=D.left-le,Ae=N.left-oe,qe=N.width+Ae,Me=Math.max(qe,O.width),Se=window.innerWidth-Kt,Be=Fs(oe,[Kt,Math.max(Kt,Se-Me)]);s.style.minWidth=qe+"px",s.style.left=Be+"px"}else{const le=O.right-w.right,oe=window.innerWidth-D.right-le,Ae=window.innerWidth-N.right-oe,qe=N.width+Ae,Me=Math.max(qe,O.width),Se=window.innerWidth-Kt,Be=Fs(oe,[Kt,Math.max(Kt,Se-Me)]);s.style.minWidth=qe+"px",s.style.right=Be+"px"}const L=p(),H=window.innerHeight-Kt*2,z=f.scrollHeight,P=window.getComputedStyle(c),G=parseInt(P.borderTopWidth,10),I=parseInt(P.paddingTop,10),U=parseInt(P.borderBottomWidth,10),M=parseInt(P.paddingBottom,10),k=G+I+z+M+U,Y=Math.min(E.offsetHeight*5,k),W=window.getComputedStyle(f),re=parseInt(W.paddingTop,10),q=parseInt(W.paddingBottom,10),X=N.top+N.height/2-Kt,ce=H-X,ge=E.offsetHeight/2,V=E.offsetTop+ge,F=G+I+V,K=k-F;if(F<=X){const le=L.length>0&&E===L[L.length-1].ref.current;s.style.bottom="0px";const oe=c.clientHeight-f.offsetTop-f.offsetHeight,Ae=Math.max(ce,ge+(le?q:0)+oe+U),qe=F+Ae;s.style.height=qe+"px"}else{const le=L.length>0&&E===L[0].ref.current;s.style.top="0px";const Ae=Math.max(X,G+f.offsetTop+(le?re:0)+ge)+K;s.style.height=Ae+"px",f.scrollTop=F-X+f.offsetTop}s.style.margin=`${Kt}px 0`,s.style.minHeight=Y+"px",s.style.maxHeight=H+"px",r==null||r(),requestAnimationFrame(()=>m.current=!0)}},[p,i.trigger,i.valueNode,s,c,f,E,S,i.dir,r]);_t(()=>h(),[h]);const[v,R]=b.useState();_t(()=>{c&&R(window.getComputedStyle(c).zIndex)},[c]);const C=b.useCallback(N=>{N&&g.current===!0&&(h(),T==null||T(),g.current=!1)},[h,T]);return u.jsx(jw,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:m,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:v},children:u.jsx(ye.div,{...a,ref:_,style:{boxSizing:"border-box",maxHeight:"100%",...a.style}})})})});aS.displayName=Kw;var Qw="SelectPopperPosition",Qs=b.forwardRef((t,e)=>{const{__scopeSelect:n,align:r="start",collisionPadding:a=Kt,...i}=t,o=Di(n);return u.jsx(Ns,{...o,...i,ref:e,align:r,collisionPadding:a,style:{boxSizing:"border-box",...i.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Qs.displayName=Qw;var[jw,js]=Er(zn,{}),Xs="SelectViewport",iS=b.forwardRef((t,e)=>{const{__scopeSelect:n,nonce:r,...a}=t,i=An(Xs,n),o=js(Xs,n),s=ke(e,i.onViewportChange),l=b.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Ai.Slot,{scope:n,children:u.jsx(ye.div,{"data-radix-select-viewport":"",role:"presentation",...a,ref:s,style:{position:"relative",flex:1,overflow:"hidden auto",...a.style},onScroll:de(a.onScroll,c=>{const d=c.currentTarget,{contentWrapper:_,shouldExpandOnScrollRef:p}=o;if(p!=null&&p.current&&_){const m=Math.abs(l.current-d.scrollTop);if(m>0){const g=window.innerHeight-Kt*2,f=parseFloat(_.style.minHeight),E=parseFloat(_.style.height),S=Math.max(f,E);if(S<g){const T=S+m,h=Math.min(g,T),v=T-h;_.style.height=h+"px",_.style.bottom==="0px"&&(d.scrollTop=v>0?v:0,_.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});iS.displayName=Xs;var oS="SelectGroup",[Xw,Zw]=Er(oS),Jw=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,a=Vt();return u.jsx(Xw,{scope:n,id:a,children:u.jsx(ye.div,{role:"group","aria-labelledby":a,...r,ref:e})})});Jw.displayName=oS;var sS="SelectLabel",lS=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,a=Zw(sS,n);return u.jsx(ye.div,{id:a.id,...r,ref:e})});lS.displayName=sS;var wi="SelectItem",[eM,cS]=Er(wi),dS=b.forwardRef((t,e)=>{const{__scopeSelect:n,value:r,disabled:a=!1,textValue:i,...o}=t,s=In(wi,n),l=An(wi,n),c=s.value===r,[d,_]=b.useState(i??""),[p,m]=b.useState(!1),g=ke(e,T=>{var h;return(h=l.itemRefCallback)==null?void 0:h.call(l,T,r,a)}),f=Vt(),E=b.useRef("touch"),S=()=>{a||(s.onValueChange(r),s.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(eM,{scope:n,value:r,disabled:a,textId:f,isSelected:c,onItemTextChange:b.useCallback(T=>{_(h=>h||((T==null?void 0:T.textContent)??"").trim())},[]),children:u.jsx(Ai.ItemSlot,{scope:n,value:r,disabled:a,textValue:d,children:u.jsx(ye.div,{role:"option","aria-labelledby":f,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":a||void 0,"data-disabled":a?"":void 0,tabIndex:a?void 0:-1,...o,ref:g,onFocus:de(o.onFocus,()=>m(!0)),onBlur:de(o.onBlur,()=>m(!1)),onClick:de(o.onClick,()=>{E.current!=="mouse"&&S()}),onPointerUp:de(o.onPointerUp,()=>{E.current==="mouse"&&S()}),onPointerDown:de(o.onPointerDown,T=>{E.current=T.pointerType}),onPointerMove:de(o.onPointerMove,T=>{var h;E.current=T.pointerType,a?(h=l.onItemLeave)==null||h.call(l):E.current==="mouse"&&T.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(o.onPointerLeave,T=>{var h;T.currentTarget===document.activeElement&&((h=l.onItemLeave)==null||h.call(l))}),onKeyDown:de(o.onKeyDown,T=>{var v;((v=l.searchRef)==null?void 0:v.current)!==""&&T.key===" "||(Bw.includes(T.key)&&S(),T.key===" "&&T.preventDefault())})})})})});dS.displayName=wi;var ta="SelectItemText",uS=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:a,...i}=t,o=In(ta,n),s=An(ta,n),l=cS(ta,n),c=qw(ta,n),[d,_]=b.useState(null),p=ke(e,S=>_(S),l.onItemTextChange,S=>{var T;return(T=s.itemTextRefCallback)==null?void 0:T.call(s,S,l.value,l.disabled)}),m=d==null?void 0:d.textContent,g=b.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:m},l.value),[l.disabled,l.value,m]),{onNativeOptionAdd:f,onNativeOptionRemove:E}=c;return _t(()=>(f(g),()=>E(g)),[f,E,g]),u.jsxs(u.Fragment,{children:[u.jsx(ye.span,{id:l.textId,...i,ref:p}),l.isSelected&&o.valueNode&&!o.valueNodeHasChildren?oa.createPortal(i.children,o.valueNode):null]})});uS.displayName=ta;var _S="SelectItemIndicator",pS=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return cS(_S,n).isSelected?u.jsx(ye.span,{"aria-hidden":!0,...r,ref:e}):null});pS.displayName=_S;var Zs="SelectScrollUpButton",mS=b.forwardRef((t,e)=>{const n=An(Zs,t.__scopeSelect),r=js(Zs,t.__scopeSelect),[a,i]=b.useState(!1),o=ke(e,r.onScrollButtonChange);return _t(()=>{if(n.viewport&&n.isPositioned){let s=function(){const c=l.scrollTop>0;i(c)};const l=n.viewport;return s(),l.addEventListener("scroll",s),()=>l.removeEventListener("scroll",s)}},[n.viewport,n.isPositioned]),a?u.jsx(ES,{...t,ref:o,onAutoScroll:()=>{const{viewport:s,selectedItem:l}=n;s&&l&&(s.scrollTop=s.scrollTop-l.offsetHeight)}}):null});mS.displayName=Zs;var Js="SelectScrollDownButton",gS=b.forwardRef((t,e)=>{const n=An(Js,t.__scopeSelect),r=js(Js,t.__scopeSelect),[a,i]=b.useState(!1),o=ke(e,r.onScrollButtonChange);return _t(()=>{if(n.viewport&&n.isPositioned){let s=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;i(d)};const l=n.viewport;return s(),l.addEventListener("scroll",s),()=>l.removeEventListener("scroll",s)}},[n.viewport,n.isPositioned]),a?u.jsx(ES,{...t,ref:o,onAutoScroll:()=>{const{viewport:s,selectedItem:l}=n;s&&l&&(s.scrollTop=s.scrollTop+l.offsetHeight)}}):null});gS.displayName=Js;var ES=b.forwardRef((t,e)=>{const{__scopeSelect:n,onAutoScroll:r,...a}=t,i=An("SelectScrollButton",n),o=b.useRef(null),s=xi(n),l=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>l(),[l]),_t(()=>{var d;const c=s().find(_=>_.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[s]),u.jsx(ye.div,{"aria-hidden":!0,...a,ref:e,style:{flexShrink:0,...a.style},onPointerDown:de(a.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:de(a.onPointerMove,()=>{var c;(c=i.onItemLeave)==null||c.call(i),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:de(a.onPointerLeave,()=>{l()})})}),tM="SelectSeparator",fS=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return u.jsx(ye.div,{"aria-hidden":!0,...r,ref:e})});fS.displayName=tM;var el="SelectArrow",nM=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,a=Di(n),i=In(el,n),o=An(el,n);return i.open&&o.position==="popper"?u.jsx(Os,{...a,...r,ref:e}):null});nM.displayName=el;var rM="SelectBubbleInput",SS=b.forwardRef(({__scopeSelect:t,value:e,...n},r)=>{const a=b.useRef(null),i=ke(r,a),o=Yf(e);return b.useEffect(()=>{const s=a.current;if(!s)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(o!==e&&d){const _=new Event("change",{bubbles:!0});d.call(s,e),s.dispatchEvent(_)}},[o,e]),u.jsx(ye.select,{...n,style:{...gf,...n.style},ref:i,defaultValue:e})});SS.displayName=rM;function bS(t){return t===""||t===void 0}function TS(t){const e=pt(t),n=b.useRef(""),r=b.useRef(0),a=b.useCallback(o=>{const s=n.current+o;e(s),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(s)},[e]),i=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,a,i]}function hS(t,e,n){const a=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,i=n?t.indexOf(n):-1;let o=aM(t,Math.max(i,0));a.length===1&&(o=o.filter(c=>c!==n));const l=o.find(c=>c.textValue.toLowerCase().startsWith(a.toLowerCase()));return l!==n?l:void 0}function aM(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var iM=Kf,RS=jf,oM=Zf,sM=Jf,lM=eS,CS=tS,cM=iS,vS=lS,NS=dS,dM=uS,uM=pS,OS=mS,yS=gS,IS=fS;const AS=iM,xS=oM,tl=b.forwardRef(({className:t,children:e,...n},r)=>u.jsxs(RS,{ref:r,className:$("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t),...n,children:[e,u.jsx(sM,{asChild:!0,children:u.jsx(pe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));tl.displayName=RS.displayName;const DS=b.forwardRef(({className:t,...e},n)=>u.jsx(OS,{ref:n,className:$("flex cursor-default items-center justify-center py-1",t),...e,children:u.jsx(pe.ChevronUp,{className:"h-4 w-4"})}));DS.displayName=OS.displayName;const wS=b.forwardRef(({className:t,...e},n)=>u.jsx(yS,{ref:n,className:$("flex cursor-default items-center justify-center py-1",t),...e,children:u.jsx(pe.ChevronDown,{className:"h-4 w-4"})}));wS.displayName=yS.displayName;const nl=b.forwardRef(({className:t,children:e,position:n="popper",...r},a)=>u.jsx(lM,{children:u.jsxs(CS,{ref:a,className:$("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,...r,children:[u.jsx(DS,{}),u.jsx(cM,{className:$("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:e}),u.jsx(wS,{})]})}));nl.displayName=CS.displayName;const _M=b.forwardRef(({className:t,...e},n)=>u.jsx(vS,{ref:n,className:$("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...e}));_M.displayName=vS.displayName;const $n=b.forwardRef(({className:t,children:e,...n},r)=>u.jsxs(NS,{ref:r,className:$("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(uM,{children:u.jsx(pe.Check,{className:"h-4 w-4"})})}),u.jsx(dM,{children:e})]}));$n.displayName=NS.displayName;const pM=b.forwardRef(({className:t,...e},n)=>u.jsx(IS,{ref:n,className:$("-mx-1 my-1 h-px bg-muted",t),...e}));pM.displayName=IS.displayName;const Mi=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,className:$("rounded-lg border bg-card text-card-foreground shadow-sm",t),...e}));Mi.displayName="Card";const Li=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,className:$("flex flex-col space-y-1.5 p-6",t),...e}));Li.displayName="CardHeader";const Pi=b.forwardRef(({className:t,...e},n)=>u.jsx("h3",{ref:n,className:$("text-2xl font-semibold leading-none tracking-tight",t),...e}));Pi.displayName="CardTitle";const mM=b.forwardRef(({className:t,...e},n)=>u.jsx("p",{ref:n,className:$("text-sm text-muted-foreground",t),...e}));mM.displayName="CardDescription";const ki=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,className:$("p-6 pt-0",t),...e}));ki.displayName="CardContent";const gM=b.forwardRef(({className:t,...e},n)=>u.jsx("div",{ref:n,className:$("flex items-center p-6 pt-0",t),...e}));gM.displayName="CardFooter";const EM={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function fM({settings:t,onSettingsChange:e,className:n=""}){const[r,a]=y.useState(!1),[i,o]=y.useState(!1),[s,l]=y.useState(t),[c,d]=y.useState(!1),{toast:_}=Wo();y.useEffect(()=>{const E=JSON.stringify(s)!==JSON.stringify(t);d(E)},[s,t]),y.useEffect(()=>{l(t)},[t]);const p=()=>{e(s),d(!1),_({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},m=()=>{l(EM),d(!0),_({title:"Settings reset",description:"Configuration has been reset to defaults."})},g=()=>{l(t),d(!1),a(!1)},f=async()=>{try{const S=await(await fetch(`${s.api.baseUrl}/health`)).json();_({title:"Connection successful",description:`API is ${S.status||"healthy"}`})}catch{_({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(cf,{open:r,onOpenChange:a,children:[u.jsx(BD,{asChild:!0,children:u.jsxs(Ve,{variant:"outline",size:"sm",className:n,children:[u.jsx(pe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(zp,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(zs,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(uf,{children:[u.jsx(_f,{children:"Chat Settings"}),u.jsx(pf,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Mi,{children:[u.jsx(Li,{className:"pb-3",children:u.jsxs(Pi,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(ki,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Bt,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Jr,{id:"api-url",value:s.api.baseUrl,onChange:E=>l(S=>({...S,api:{...S.api,baseUrl:E.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Ve,{variant:"outline",onClick:f,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Bt,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(yn,{id:"enable-auth",checked:s.api.enableAuth,onCheckedChange:E=>l(S=>({...S,api:{...S.api,enableAuth:E}}))})]}),s.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(Bt,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Jr,{id:"auth-token",type:i?"text":"password",value:s.api.authToken,onChange:E=>l(S=>({...S,api:{...S.api,authToken:E.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Ve,{variant:"outline",size:"icon",onClick:()=>o(!i),children:i?u.jsx(pe.EyeOff,{className:"h-4 w-4"}):u.jsx(pe.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(Mi,{children:[u.jsx(Li,{className:"pb-3",children:u.jsxs(Pi,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(ki,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Bt,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(AS,{value:s.ui.layout,onValueChange:E=>l(S=>({...S,ui:{...S.ui,layout:E}})),children:[u.jsx(tl,{children:u.jsx(xS,{})}),u.jsxs(nl,{children:[u.jsx($n,{value:"sidebar",children:"Sidebar Layout"}),u.jsx($n,{value:"fullscreen",children:"Fullscreen"}),u.jsx($n,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Bt,{htmlFor:"theme",children:"Theme"}),u.jsxs(AS,{value:s.ui.theme,onValueChange:E=>l(S=>({...S,ui:{...S.ui,theme:E}})),children:[u.jsx(tl,{children:u.jsx(xS,{})}),u.jsxs(nl,{children:[u.jsx($n,{value:"light",children:"Light"}),u.jsx($n,{value:"dark",children:"Dark"}),u.jsx($n,{value:"system",children:"System"})]})]})]}),u.jsx(Vs,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Bt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(yn,{id:"show-timestamps",checked:s.ui.showTimestamps,onCheckedChange:E=>l(S=>({...S,ui:{...S.ui,showTimestamps:E}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Bt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(yn,{id:"show-agent-names",checked:s.ui.showAgentNames,onCheckedChange:E=>l(S=>({...S,ui:{...S.ui,showAgentNames:E}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Bt,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(yn,{id:"compact-messages",checked:s.ui.compactMessages,onCheckedChange:E=>l(S=>({...S,ui:{...S.ui,compactMessages:E}}))})]})]})]})]}),u.jsxs(Mi,{children:[u.jsx(Li,{className:"pb-3",children:u.jsxs(Pi,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(ki,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Bt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(yn,{id:"auto-save",checked:s.behavior.autoSave,onCheckedChange:E=>l(S=>({...S,behavior:{...S.behavior,autoSave:E}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Bt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(yn,{id:"enable-streaming",checked:s.behavior.enableStreaming,onCheckedChange:E=>l(S=>({...S,behavior:{...S.behavior,enableStreaming:E}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Bt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(yn,{id:"typing-indicator",checked:s.behavior.showTypingIndicator,onCheckedChange:E=>l(S=>({...S,behavior:{...S.behavior,showTypingIndicator:E}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Ve,{variant:"outline",onClick:m,children:[u.jsx(pe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ve,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(Ve,{onClick:p,disabled:!c,children:[u.jsx(pe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function SM({layout:t="sidebar",layoutSize:e="desktop",showThreads:n=!0,className:r="",customStyles:a={},...i}){const o=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},s=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=y.useCallback(c=>{var d;(d=i.onThreadChange)==null||d.call(i,c)},[i.onThreadChange]);return t==="fullscreen"?u.jsx(yr,{...i,onThreadChange:l,children:u.jsx("div",{className:`${o(e)} flex flex-col overflow-hidden ${r} ${a.container||""}`,style:s(e),children:u.jsx(Zr,{className:"flex-1",onError:i.onError,enableFileUpload:!0})})}):t==="tabs"?u.jsx(yr,{...i,onThreadChange:l,children:u.jsx("div",{className:`${o(e)} flex flex-col overflow-hidden ${r} ${a.container||""}`,style:s(e),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${a.sidebar||""}`,children:u.jsx(Ci,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${a.chatArea||""}`,children:u.jsx(Zr,{onError:i.onError,enableFileUpload:!0})})]})})}):u.jsx(yr,{...i,onThreadChange:l,children:u.jsxs("div",{className:`${o(e)} flex overflow-hidden ${r} ${a.container||""}`,style:s(e),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${a.sidebar||""}`,children:u.jsx(Ci,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${a.chatArea||""}`,children:u.jsx(Zr,{onError:i.onError,enableFileUpload:!0})})]})})}function rl(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let xn=rl();function bM(t){xn=t}const MS=/[&<>"']/,TM=new RegExp(MS.source,"g"),LS=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,hM=new RegExp(LS.source,"g"),RM={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},PS=t=>RM[t];function ft(t,e){if(e){if(MS.test(t))return t.replace(TM,PS)}else if(LS.test(t))return t.replace(hM,PS);return t}const CM=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function kS(t){return t.replace(CM,(e,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const vM=/(^|[^\[])\^/g;function Ze(t,e){t=typeof t=="string"?t:t.source,e=e||"";const n={replace:(r,a)=>(a=a.source||a,a=a.replace(vM,"$1"),t=t.replace(r,a),n),getRegex:()=>new RegExp(t,e)};return n}const NM=/[^\w:]/g,OM=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function US(t,e,n){if(t){let r;try{r=decodeURIComponent(kS(n)).replace(NM,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}e&&!OM.test(n)&&(n=xM(e,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ui={},yM=/^[^:]+:\/*[^/]*$/,IM=/^([^:]+:)[\s\S]*$/,AM=/^([^:]+:\/*[^/]*)[\s\S]*$/;function xM(t,e){Ui[" "+t]||(yM.test(t)?Ui[" "+t]=t+"/":Ui[" "+t]=Bi(t,"/",!0)),t=Ui[" "+t];const n=t.indexOf(":")===-1;return e.substring(0,2)==="//"?n?e:t.replace(IM,"$1")+e:e.charAt(0)==="/"?n?e:t.replace(AM,"$1")+e:t+e}const Fi={exec:function(){}};function FS(t,e){const n=t.replace(/\|/g,(i,o,s)=>{let l=!1,c=o;for(;--c>=0&&s[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let a=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;a<r.length;a++)r[a]=r[a].trim().replace(/\\\|/g,"|");return r}function Bi(t,e,n){const r=t.length;if(r===0)return"";let a=0;for(;a<r;){const i=t.charAt(r-a-1);if(i===e&&!n)a++;else if(i!==e&&n)a++;else break}return t.slice(0,r-a)}function DM(t,e){if(t.indexOf(e[1])===-1)return-1;const n=t.length;let r=0,a=0;for(;a<n;a++)if(t[a]==="\\")a++;else if(t[a]===e[0])r++;else if(t[a]===e[1]&&(r--,r<0))return a;return-1}function wM(t){t&&t.sanitize&&!t.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function BS(t,e){if(e<1)return"";let n="";for(;e>1;)e&1&&(n+=t),e>>=1,t+=t;return n+t}function GS(t,e,n,r){const a=e.href,i=e.title?ft(e.title):null,o=t[1].replace(/\\([\[\]])/g,"$1");if(t[0].charAt(0)!=="!"){r.state.inLink=!0;const s={type:"link",raw:n,href:a,title:i,text:o,tokens:r.inlineTokens(o)};return r.state.inLink=!1,s}return{type:"image",raw:n,href:a,title:i,text:ft(o)}}function MM(t,e){const n=t.match(/^(\s+)(?:```)/);if(n===null)return e;const r=n[1];return e.split(`
87
87
  `).map(a=>{const i=a.match(/^\s+/);if(i===null)return a;const[o]=i;return o.length>=r.length?a.slice(r.length):a}).join(`
88
88
  `)}class Gi{constructor(e){this.options=e||xn}space(e){const n=this.rules.block.newline.exec(e);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(e){const n=this.rules.block.code.exec(e);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:Bi(r,`
89
89
  `)}}}fences(e){const n=this.rules.block.fences.exec(e);if(n){const r=n[0],a=MM(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:a}}}heading(e){const n=this.rules.block.heading.exec(e);if(n){let r=n[2].trim();if(/#$/.test(r)){const a=Bi(r,"#");(this.options.pedantic||!a||/ $/.test(a))&&(r=a.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(e){const n=this.rules.block.hr.exec(e);if(n)return{type:"hr",raw:n[0]}}blockquote(e){const n=this.rules.block.blockquote.exec(e);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),a=this.lexer.state.top;this.lexer.state.top=!0;const i=this.lexer.blockTokens(r);return this.lexer.state.top=a,{type:"blockquote",raw:n[0],tokens:i,text:r}}}list(e){let n=this.rules.block.list.exec(e);if(n){let r,a,i,o,s,l,c,d,_,p,m,g,f=n[1].trim();const E=f.length>1,S={type:"list",raw:"",ordered:E,start:E?+f.slice(0,-1):"",loose:!1,items:[]};f=E?`\\d{1,9}\\${f.slice(-1)}`:`\\${f}`,this.options.pedantic&&(f=E?f:"[*+-]");const T=new RegExp(`^( {0,3}${f})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;e&&(g=!1,!(!(n=T.exec(e))||this.rules.block.hr.test(e)));){if(r=n[0],e=e.substring(r.length),d=n[2].split(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teodor-new-chat-ui",
3
- "version": "3.0.74",
3
+ "version": "3.0.75",
4
4
  "description": "React chat UI components with streaming support, tool calls, and modern design",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",