shraga 0.1.110 → 0.1.112

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.
@@ -1844,7 +1844,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),dn=ge,_t=je),rt===void
1844
1844
  `)},cM=function(){var e=parseInt(document.body.getAttribute(hu)||"0",10);return isFinite(e)?e:0},sne=function(){y.useEffect(function(){return document.body.setAttribute(hu,(cM()+1).toString()),function(){var e=cM()-1;e<=0?document.body.removeAttribute(hu):document.body.setAttribute(hu,e.toString())}},[])},lne=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;sne();var a=y.useMemo(function(){return ine(i)},[i]);return y.createElement(ane,{styles:one(a,!t,i,n?"":"!important")})},Pw=!1;if(typeof window<"u")try{var lm=Object.defineProperty({},"passive",{get:function(){return Pw=!0,!0}});window.addEventListener("test",lm,lm),window.removeEventListener("test",lm,lm)}catch{Pw=!1}var Fc=Pw?{passive:!1}:!1,cne=function(e){return e.tagName==="TEXTAREA"},Mz=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!cne(e)&&n[t]==="visible")},une=function(e){return Mz(e,"overflowY")},fne=function(e){return Mz(e,"overflowX")},uM=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=Iz(e,r);if(i){var a=Rz(e,r),s=a[1],c=a[2];if(s>c)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},dne=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},hne=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Iz=function(e,t){return e==="v"?une(t):fne(t)},Rz=function(e,t){return e==="v"?dne(t):hne(t)},pne=function(e,t){return e==="h"&&t==="rtl"?-1:1},mne=function(e,t,n,r,i){var a=pne(e,window.getComputedStyle(t).direction),s=a*r,c=n.target,u=t.contains(c),f=!1,p=s>0,h=0,m=0;do{if(!c)break;var v=Rz(e,c),x=v[0],b=v[1],S=v[2],_=b-S-a*x;(x||_)&&Iz(e,c)&&(h+=_,m+=x);var O=c.parentNode;c=O&&O.nodeType===Node.DOCUMENT_FRAGMENT_NODE?O.host:O}while(!u&&c!==document.body||u&&(t.contains(c)||t===c));return(p&&Math.abs(h)<1||!p&&Math.abs(m)<1)&&(f=!0),f},cm=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},fM=function(e){return[e.deltaX,e.deltaY]},dM=function(e){return e&&"current"in e?e.current:e},gne=function(e,t){return e[0]===t[0]&&e[1]===t[1]},vne=function(e){return`
1845
1845
  .block-interactivity-`.concat(e,` {pointer-events: none;}
1846
1846
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
1847
- `)},yne=0,Hc=[];function bne(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),i=y.useState(yne++)[0],a=y.useState(Nz)[0],s=y.useRef(e);y.useEffect(function(){s.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var b=qH([e.lockRef.current],(e.shards||[]).map(dM),!0).filter(Boolean);return b.forEach(function(S){return S.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),b.forEach(function(S){return S.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var c=y.useCallback(function(b,S){if("touches"in b&&b.touches.length===2||b.type==="wheel"&&b.ctrlKey)return!s.current.allowPinchZoom;var _=cm(b),O=n.current,k="deltaX"in b?b.deltaX:O[0]-_[0],T="deltaY"in b?b.deltaY:O[1]-_[1],C,N=b.target,P=Math.abs(k)>Math.abs(T)?"h":"v";if("touches"in b&&P==="h"&&N.type==="range")return!1;var D=window.getSelection(),j=D&&D.anchorNode,I=j?j===N||j.contains(N):!1;if(I)return!1;var F=uM(P,N);if(!F)return!0;if(F?C=P:(C=P==="v"?"h":"v",F=uM(P,N)),!F)return!1;if(!r.current&&"changedTouches"in b&&(k||T)&&(r.current=C),!C)return!0;var R=r.current||C;return mne(R,S,b,R==="h"?k:T)},[]),u=y.useCallback(function(b){var S=b;if(!(!Hc.length||Hc[Hc.length-1]!==a)){var _="deltaY"in S?fM(S):cm(S),O=t.current.filter(function(C){return C.name===S.type&&(C.target===S.target||S.target===C.shadowParent)&&gne(C.delta,_)})[0];if(O&&O.should){S.cancelable&&S.preventDefault();return}if(!O){var k=(s.current.shards||[]).map(dM).filter(Boolean).filter(function(C){return C.contains(S.target)}),T=k.length>0?c(S,k[0]):!s.current.noIsolation;T&&S.cancelable&&S.preventDefault()}}},[]),f=y.useCallback(function(b,S,_,O){var k={name:b,delta:S,target:_,should:O,shadowParent:xne(_)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(T){return T!==k})},1)},[]),p=y.useCallback(function(b){n.current=cm(b),r.current=void 0},[]),h=y.useCallback(function(b){f(b.type,fM(b),b.target,c(b,e.lockRef.current))},[]),m=y.useCallback(function(b){f(b.type,cm(b),b.target,c(b,e.lockRef.current))},[]);y.useEffect(function(){return Hc.push(a),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:m}),document.addEventListener("wheel",u,Fc),document.addEventListener("touchmove",u,Fc),document.addEventListener("touchstart",p,Fc),function(){Hc=Hc.filter(function(b){return b!==a}),document.removeEventListener("wheel",u,Fc),document.removeEventListener("touchmove",u,Fc),document.removeEventListener("touchstart",p,Fc)}},[]);var v=e.removeScrollBar,x=e.inert;return y.createElement(y.Fragment,null,x?y.createElement(a,{styles:vne(i)}):null,v?y.createElement(lne,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function xne(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const wne=Yte(Tz,bne);var GE=y.forwardRef(function(e,t){return y.createElement(Av,oa({},e,{ref:t,sideCar:wne}))});GE.classNames=Av.classNames;var Ene=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Kc=new WeakMap,um=new WeakMap,fm={},px=0,Pz=function(e){return e&&(e.host||Pz(e.parentNode))},Sne=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Pz(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},_ne=function(e,t,n,r){var i=Sne(t,Array.isArray(e)?e:[e]);fm[n]||(fm[n]=new WeakMap);var a=fm[n],s=[],c=new Set,u=new Set(i),f=function(h){!h||c.has(h)||(c.add(h),f(h.parentNode))};i.forEach(f);var p=function(h){!h||u.has(h)||Array.prototype.forEach.call(h.children,function(m){if(c.has(m))p(m);else try{var v=m.getAttribute(r),x=v!==null&&v!=="false",b=(Kc.get(m)||0)+1,S=(a.get(m)||0)+1;Kc.set(m,b),a.set(m,S),s.push(m),b===1&&x&&um.set(m,!0),S===1&&m.setAttribute(n,"true"),x||m.setAttribute(r,"true")}catch(_){console.error("aria-hidden: cannot operate on ",m,_)}})};return p(t),c.clear(),px++,function(){s.forEach(function(h){var m=Kc.get(h)-1,v=a.get(h)-1;Kc.set(h,m),a.set(h,v),m||(um.has(h)||h.removeAttribute(r),um.delete(h)),v||h.removeAttribute(n)}),px--,px||(Kc=new WeakMap,Kc=new WeakMap,um=new WeakMap,fm={})}},Dz=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=Ene(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),_ne(r,i,n,"aria-hidden")):function(){return null}},kv="Dialog",[jz]=Ij(kv),[Ane,Bi]=jz(kv),Lz=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,c=y.useRef(null),u=y.useRef(null),[f,p]=xte({prop:r,defaultProp:i??!1,onChange:a,caller:kv});return w.jsx(Ane,{scope:t,triggerRef:c,contentRef:u,contentId:lx(),titleId:lx(),descriptionId:lx(),open:f,onOpenChange:p,onOpenToggle:y.useCallback(()=>p(h=>!h),[p]),modal:s,children:n})};Lz.displayName=kv;var zz="DialogTrigger",$z=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(zz,n),a=ri(t,i.triggerRef);return w.jsx(Dr.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":ZE(i.open),...r,ref:a,onClick:gr(e.onClick,i.onOpenToggle)})});$z.displayName=zz;var VE="DialogPortal",[kne,Bz]=jz(VE,{forceMount:void 0}),Uz=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Bi(VE,t);return w.jsx(kne,{scope:t,forceMount:n,children:y.Children.map(r,s=>w.jsx(Ds,{present:n||a.open,children:w.jsx(Oz,{asChild:!0,container:i,children:s})}))})};Uz.displayName=VE;var mg="DialogOverlay",WE=y.forwardRef((e,t)=>{const n=Bz(mg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Bi(mg,e.__scopeDialog);return a.modal?w.jsx(Ds,{present:r||a.open,children:w.jsx(Cne,{...i,ref:t})}):null});WE.displayName=mg;var One=wE("DialogOverlay.RemoveScroll"),Cne=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(mg,n),a=Cte(),s=ri(t,a);return w.jsx(GE,{as:One,allowPinchZoom:!0,shards:[i.contentRef],children:w.jsx(Dr.div,{"data-state":ZE(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),_u="DialogContent",YE=y.forwardRef((e,t)=>{const n=Bz(_u,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Bi(_u,e.__scopeDialog);return w.jsx(Ds,{present:r||a.open,children:a.modal?w.jsx(Tne,{...i,ref:t}):w.jsx(Nne,{...i,ref:t})})});YE.displayName=_u;var Tne=y.forwardRef((e,t)=>{const n=Bi(_u,e.__scopeDialog),r=y.useRef(null),i=ri(t,n.contentRef,r);return y.useEffect(()=>{const a=r.current;if(a)return Dz(a)},[]),w.jsx(Fz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:gr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:gr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,c=s.button===0&&s.ctrlKey===!0;(s.button===2||c)&&a.preventDefault()}),onFocusOutside:gr(e.onFocusOutside,a=>a.preventDefault())})}),Nne=y.forwardRef((e,t)=>{const n=Bi(_u,e.__scopeDialog),r=y.useRef(!1),i=y.useRef(!1);return w.jsx(Fz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,c;(s=e.onCloseAutoFocus)==null||s.call(e,a),a.defaultPrevented||(r.current||(c=n.triggerRef.current)==null||c.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var u,f;(u=e.onInteractOutside)==null||u.call(e,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=a.target;((f=n.triggerRef.current)==null?void 0:f.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),Fz=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,c=Bi(_u,n);return Bte(),w.jsx(w.Fragment,{children:w.jsx(Az,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:w.jsx(Sz,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":ZE(c.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Hz="DialogTitle",XE=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(Hz,n);return w.jsx(Dr.h2,{id:i.titleId,...r,ref:t})});XE.displayName=Hz;var Kz="DialogDescription",Mne=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(Kz,n);return w.jsx(Dr.p,{id:i.descriptionId,...r,ref:t})});Mne.displayName=Kz;var qz="DialogClose",Gz=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(qz,n);return w.jsx(Dr.button,{type:"button",...r,ref:t,onClick:gr(e.onClick,()=>i.onOpenChange(!1))})});Gz.displayName=qz;function ZE(e){return e?"open":"closed"}const _s=Lz,uh=$z,Ine=Uz,Vz=y.forwardRef(({className:e,...t},n)=>w.jsx(WE,{ref:n,className:Ue("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Vz.displayName=WE.displayName;const ho=y.forwardRef(({className:e,children:t,...n},r)=>w.jsxs(Ine,{children:[w.jsx(Vz,{}),w.jsxs(YE,{ref:r,className:Ue("fixed left-[50%] top-[50%] z-50 flex flex-col w-[calc(100vw-2rem)] max-w-lg max-h-[85dvh] overflow-y-auto translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-4 sm: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 sm:rounded-lg",e),...n,children:[t,w.jsxs(Gz,{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:[w.jsx(jl,{className:"h-4 w-4"}),w.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ho.displayName=YE.displayName;function zl({className:e,...t}){return w.jsx("div",{className:Ue("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function Wz({className:e,...t}){return w.jsx("div",{"data-dialog-body":!0,className:Ue("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Yz({className:e,...t}){return w.jsx("div",{className:Ue("shrink-0 -mx-4 px-4 pt-3 border-t sm:-mx-6 sm:px-6","flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t})}const As=y.forwardRef(({className:e,...t},n)=>w.jsx(XE,{ref:n,className:Ue("text-lg font-semibold leading-none tracking-tight",e),...t}));As.displayName=XE.displayName;const Rne=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),Pne=new Set(["pdf","mp4","webm","mp3","ogg","wav"]);async function Dne(e,t){const n=await t();if(!n)return[];const r=await fetch(`/api/workspace/ls?path=${encodeURIComponent(e)}`,{headers:{Authorization:`Bearer ${n}`}});return r.ok?(await r.json()).entries??[]:[]}function jne({getToken:e,onRefresh:t,refreshKey:n}){const[r,i]=y.useState(new Map),[a,s]=y.useState(()=>new Set),[c,u]=y.useState(null),[f,p]=y.useState(!1),[h,m]=y.useState("fit"),[v,x]=y.useState(null),[b,S]=y.useState(null),_=y.useRef(null),[O,k]=y.useState(null),[T,C]=y.useState(!1),[N,P]=y.useState([]),D=y.useCallback(async U=>{const W=await Dne(U,e);i(H=>new Map(H).set(U,W))},[e]);y.useEffect(()=>{D(""),a.forEach(U=>D(U))},[D,n]);const j=r.get("")??[],I=y.useCallback(U=>{try{const W=U.contentDocument;if(!(W!=null&&W.body))return;const H=Math.max(W.body.offsetWidth,W.body.scrollWidth),Y=Math.max(W.body.offsetHeight,W.body.scrollHeight);H&&Y&&S({w:H,h:Y})}catch{}},[]),F=y.useCallback(()=>{const U=_.current,W=b;if(!U||!W)return;const H=16,Y=U.clientWidth-H,z=U.clientHeight-H,$=Math.min(Y/W.w,z/W.h,1);x({scale:$,w:W.w,h:W.h})},[b]);y.useEffect(()=>{if(!(c!=null&&c.html)||h!=="fit"){x(null);return}const U=_.current;if(!U)return;const W=new ResizeObserver(()=>requestAnimationFrame(F));return W.observe(U),()=>W.disconnect()},[c==null?void 0:c.html,f,h,F]),y.useEffect(()=>{T&&e().then(U=>{U&&fetch("/api/data-sync/log",{headers:{Authorization:`Bearer ${U}`}}).then(W=>W.json()).then(P).catch(()=>{})})},[T]);const R=U=>{s(W=>{const H=new Set(W);return H.has(U)?H.delete(U):(H.add(U),r.has(U)||D(U)),H})},G=(U,W)=>{const H=new URLSearchParams({path:U});return O&&H.set("token",O),W&&H.set("dl","1"),`/api/workspace/raw?${H}`},q=async U=>{var Y;const W=await e();if(!W)return;k(W);const H=((Y=U.split(".").pop())==null?void 0:Y.toLowerCase())??"";if(H==="html"||H==="htm"){u({path:U,content:"",binary:!1,html:!0});return}if(Rne.has(H)){u({path:U,content:"",binary:!1,image:!0});return}if(Pne.has(H)){u({path:U,content:"",binary:!1,html:!0});return}try{const z=await fetch(`/api/workspace/file?path=${encodeURIComponent(U)}`,{headers:{Authorization:`Bearer ${W}`}});if(!z.ok)return;const $=await z.json();u({path:U,content:$.content,binary:!!$.binary})}catch{}},K=(U,W)=>w.jsx(w.Fragment,{children:U.map(H=>{const Y=H.path.split("/").pop();return w.jsxs("div",{children:[H.type==="dir"?w.jsxs("button",{onClick:()=>R(H.path),className:"w-full flex items-center gap-1 px-2 py-1 rounded hover:bg-accent/50 text-left text-sm",style:{paddingLeft:8+W*12},children:[w.jsx(Ps,{className:Ue("w-3 h-3 shrink-0 transition-transform",a.has(H.path)&&"rotate-90")}),w.jsx(eG,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),w.jsx("span",{className:"truncate",children:Y})]}):w.jsxs("button",{onClick:()=>q(H.path),className:"w-full flex items-center gap-1 px-2 py-1 rounded hover:bg-accent/50 text-left text-sm",style:{paddingLeft:8+W*12+12},title:H.oneLiner||H.path,children:[w.jsx(gE,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),w.jsx("span",{className:"truncate",children:Y})]}),H.type==="dir"&&a.has(H.path)&&K(r.get(H.path)??[],W+1)]},H.path)})});return w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1 shrink-0",children:[w.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Workspace"}),w.jsxs("div",{className:"flex items-center gap-0.5",children:[w.jsx("button",{onClick:()=>C(!0),className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Activity log",children:w.jsx(nG,{className:"w-3 h-3"})}),w.jsx("button",{onClick:()=>{D(""),a.forEach(U=>D(U)),t==null||t()},className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Refresh",children:w.jsx(fG,{className:"w-3 h-3"})})]})]}),w.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:j.length===0?w.jsx("p",{className:"text-xs text-muted-foreground px-3 py-2",children:"Empty. Drop .md files into data/workspace/ or ask the agent to create some."}):K(j,0)}),w.jsx(_s,{open:!!c,onOpenChange:U=>{U||(u(null),p(!1),m("fit"),S(null))},children:w.jsxs(ho,{className:Ue(c!=null&&c.html?Ue("!flex !flex-col !p-0 !gap-0 overflow-hidden",f?"max-w-none w-[100vw] h-[100vh] rounded-none border-0":"max-w-[90vw] w-[90vw] h-[85vh]"):"max-w-3xl max-h-[80vh] !flex !flex-col overflow-hidden"),children:[w.jsxs("div",{className:"absolute right-12 top-4 flex items-center gap-1.5 z-10",children:[(c==null?void 0:c.html)&&w.jsxs(w.Fragment,{children:[w.jsx("button",{onClick:()=>m(U=>U==="fit"?"scroll":"fit"),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:h==="fit"?"Switch to scrollable (1:1)":"Switch to scale-to-fit",children:h==="fit"?w.jsx(sG,{className:"w-4 h-4"}):w.jsx(hG,{className:"w-4 h-4"})}),w.jsx("button",{onClick:()=>p(U=>!U),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:f?"Restore":"Maximize",children:f?w.jsx(yE,{className:"w-4 h-4"}):w.jsx(vE,{className:"w-4 h-4"})})]}),c&&w.jsx("a",{href:G(c.path,!0),download:!0,className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:"Download",children:w.jsx(Oj,{className:"w-4 h-4"})})]}),w.jsx(zl,{className:Ue((c==null?void 0:c.html)&&"px-4 py-3 shrink-0 border-b"),children:w.jsx(As,{className:"font-mono text-sm truncate pr-16",children:c==null?void 0:c.path})}),w.jsx("div",{ref:c!=null&&c.html?_:void 0,className:Ue(c!=null&&c.html?Ue("flex-1 min-h-0 bg-muted/10",h==="fit"?"overflow-hidden flex items-center justify-center":"overflow-auto"):"flex-1 min-h-0 overflow-y-auto"),children:c!=null&&c.html?h==="fit"?w.jsx("div",{style:v?{width:v.w*v.scale,height:v.h*v.scale}:{width:"100%",height:"100%"},children:w.jsx("iframe",{src:G(c.path),className:"border-0 bg-white origin-top-left",title:c.path,onLoad:U=>{I(U.currentTarget),F()},style:v?{width:v.w,height:v.h,transform:`scale(${v.scale})`}:{width:"100%",height:"100%"}})}):w.jsx("iframe",{src:G(c.path),className:"border-0 bg-white mx-auto block",title:c.path,onLoad:U=>I(U.currentTarget),style:{width:(b==null?void 0:b.w)||"100%",height:(b==null?void 0:b.h)||"100%"}}):c!=null&&c.image?w.jsx("div",{className:"flex items-center justify-center p-4",children:w.jsx("img",{src:G(c.path),alt:c.path,className:"max-w-full max-h-[70vh] object-contain"})}):c!=null&&c.binary?w.jsx("p",{className:"text-sm text-muted-foreground",children:"(binary file — preview unavailable)"}):c!=null&&c.path.toLowerCase().endsWith(".md")||c!=null&&c.path.toLowerCase().endsWith(".markdown")?w.jsx("div",{className:"text-sm",children:w.jsx(NL,{remarkPlugins:[ez],rehypePlugins:[Ez],className:"prose prose-sm max-w-none dark:prose-invert prose-pre:bg-muted prose-pre:border prose-code:before:content-none prose-code:after:content-none",children:c.content})}):w.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:c==null?void 0:c.content})})]})}),w.jsx(_s,{open:T,onOpenChange:C,children:w.jsxs(ho,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[w.jsx(zl,{children:w.jsx(As,{className:"text-sm",children:"Activity Log"})}),w.jsxs("div",{className:"overflow-y-auto flex-1 space-y-2",children:[N.map(U=>w.jsxs("div",{className:"border-b border-border/50 pb-2 last:border-0",children:[w.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[w.jsx("span",{className:"text-sm text-foreground",children:U.message}),w.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:Lne(U.date)})]}),U.files.length>0&&w.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:U.files.map(W=>w.jsx("span",{className:"inline-block mr-2 font-mono",children:W},W))})]},U.hash)),N.length===0&&w.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No activity yet"})]})]})})]})}function Lne(e){const t=new Date(e),r=new Date().getTime()-t.getTime(),i=Math.floor(r/6e4);if(i<60)return`${i}m ago`;const a=Math.floor(i/60);return a<24?`${a}h ago`:t.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Um(e,t=Date.now()){if(!e)return null;const n=new Date(e).getTime()-t;if(!Number.isFinite(n)||n<=0)return null;const r=Math.round(n/6e4);if(r<1)return"1m";if(r<60)return`${r}m`;const i=Math.floor(r/60),a=r%60;if(i<48)return a?`${i}h ${a}m`:`${i}h`;const s=Math.floor(i/24),c=i%24;return c?`${s}d ${c}h`:`${s}d`}const zne=/resets\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\s*\(UTC\)/i;function $ne(e,t=Date.now(),n=Date.now()){var h;const r=e.match(zne);if(!r)return e;let i=Number(r[1]);const a=r[2]?Number(r[2]):0,s=(h=r[3])==null?void 0:h.toLowerCase();if(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0),i>23||a>59)return e;const c=new Date(t),u=new Date(Date.UTC(c.getUTCFullYear(),c.getUTCMonth(),c.getUTCDate(),i,a));u.getTime()<=t&&u.setUTCDate(u.getUTCDate()+1);const f=u.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),p=Um(u.toISOString(),n);return e.replace(r[0],`resets ${f}${p?` (in ${p})`:""}`)}var Bne=Object.defineProperty,$u=(e,t)=>Bne(e,"name",{value:t,configurable:!0}),Xz=!!(typeof window<"u"&&window.document&&window.document.createElement);function xs(e,t,{checkForDefaultPrevented:n=!0}={}){return $u(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}$u(xs,"composeEventHandlers");function Une(e){var t;if(!Xz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}$u(Une,"getOwnerWindow");function Dw(e){if(!Xz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}$u(Dw,"getOwnerDocument");function Zz(e,t=!1){const{activeElement:n}=Dw(e);if(!(n!=null&&n.nodeName))return null;if(Qz(n)&&n.contentDocument)return Zz(n.contentDocument.body,t);if(t){const r=n.getAttribute("aria-activedescendant");if(r){const i=Dw(n).getElementById(r);if(i)return i}}return n}$u(Zz,"getActiveElement");function Qz(e){return e.tagName==="IFRAME"}$u(Qz,"isFrame");var Fne=Object.defineProperty,QE=(e,t)=>Fne(e,"name",{value:t,configurable:!0});function jw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}QE(jw,"setRef");function Jz(...e){return t=>{let n=!1;const r=e.map(i=>{const a=jw(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():jw(e[i],null)}}}}QE(Jz,"composeRefs");function Bu(...e){return y.useCallback(Jz(...e),e)}QE(Bu,"useComposedRefs");var Hne=Object.defineProperty,wi=(e,t)=>Hne(e,"name",{value:t,configurable:!0});function Kne(e,t){const n=y.createContext(t);n.displayName=e+"Context";const r=wi(a=>{const{children:s,...c}=a,u=y.useMemo(()=>c,Object.values(c));return w.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:c=!1}=s,u=y.useContext(n);if(u)return u;if(t!==void 0)return t;if(!c)throw new Error(`\`${a}\` must be used within \`${e}\``)}return wi(i,"useContext"),[r,i]}wi(Kne,"createContext");function e3(e,t=[]){let n=[];function r(a,s){const c=y.createContext(s);c.displayName=a+"Context";const u=n.length;n=[...n,s];const f=wi(h=>{var _;const{scope:m,children:v,...x}=h,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useMemo(()=>x,Object.values(x));return w.jsx(b.Provider,{value:S,children:v})},"Provider");f.displayName=a+"Provider";function p(h,m,v={}){var _;const{optional:x=!1}=v,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useContext(b);if(S)return S;if(s!==void 0)return s;if(!x)throw new Error(`\`${h}\` must be used within \`${a}\``)}return wi(p,"useContext"),[f,p]}wi(r,"createContext");const i=wi(()=>{const a=n.map(s=>y.createContext(s));return wi(function(c){const u=(c==null?void 0:c[e])||a;return y.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])},"useScope")},"createScope");return i.scopeName=e,[r,t3(i,...t)]}wi(e3,"createContextScope");function t3(...e){const t=e[0];if(e.length===1)return t;const n=wi(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return wi(function(a){const s=r.reduce((c,{useScope:u,scopeName:f})=>{const h=u(a)[`__scope${f}`];return{...c,...h}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}wi(t3,"composeContextScopes");var qne=Object.defineProperty,Ui=(e,t)=>qne(e,"name",{value:t,configurable:!0});function JE(e){const t=y.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,c=!1;const u=[];Lw(i)&&typeof dm=="function"&&(i=dm(i._payload)),y.Children.forEach(i,m=>{var v;if(a3(m)){c=!0;const x=m;let b="child"in x.props?x.props.child:x.props.children;Lw(b)&&typeof dm=="function"&&(b=dm(b._payload)),s=Vne(x,b),u.push((v=s==null?void 0:s.props)==null?void 0:v.children)}else u.push(m)}),s?s=y.cloneElement(s,void 0,u):!c&&y.Children.count(i)===1&&y.isValidElement(i)&&(s=i);const f=s?i3(s):void 0,p=Bu(r,f);if(!s){if(i||i===0)throw new Error(c?Xne(e):Yne(e));return i}const h=r3(a,s.props??{});return s.type!==y.Fragment&&(h.ref=r?p:f),y.cloneElement(s,h)});return t.displayName=`${e}.Slot`,t}Ui(JE,"createSlot");var n3=Symbol.for("radix.slottable");function Gne(e){const t=Ui(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=n3,t}Ui(Gne,"createSlottable");var Vne=Ui((e,t)=>{if("child"in e.props){const n=e.props.child;return y.isValidElement(n)?y.cloneElement(n,void 0,e.props.children(n.props.children)):null}return y.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function r3(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...c)=>{const u=a(...c);return i(...c),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}Ui(r3,"mergeProps");function i3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Ui(i3,"getElementRef");function a3(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===n3}Ui(a3,"isSlottable");var Wne=Symbol.for("react.lazy");function Lw(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Wne&&"_payload"in e&&o3(e._payload)}Ui(Lw,"isLazyComponent");function o3(e){return typeof e=="object"&&e!==null&&"then"in e}Ui(o3,"isPromiseLike");var Yne=Ui(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Xne=Ui(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),dm=Ea[" use ".trim().toString()],Zne=Object.defineProperty,Qne=(e,t)=>Zne(e,"name",{value:t,configurable:!0}),Jne=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ov=Jne.reduce((e,t)=>{const n=JE(`Primitive.${t}`),r=y.forwardRef((i,a)=>{const{asChild:s,...c}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),w.jsx(u,{...c,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function s3(e,t){e&&Sa.flushSync(()=>e.dispatchEvent(t))}Qne(s3,"dispatchDiscreteCustomEvent");var ere=Object.defineProperty,tre=(e,t)=>ere(e,"name",{value:t,configurable:!0});function Cv(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}tre(Cv,"useCallbackRef");var nre=Object.defineProperty,$n=(e,t)=>nre(e,"name",{value:t,configurable:!0}),zw="dismissableLayer.update",rre="dismissableLayer.pointerDownOutside",ire="dismissableLayer.focusOutside",hM,l3=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),are=y.forwardRef($n(function(t,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:s,onFocusOutside:c,onInteractOutside:u,onDismiss:f,...p}=t,h=y.useContext(l3),[m,v]=y.useState(null),x=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,b]=y.useState({}),S=Bu(n,v),_=Array.from(h.layers),[O]=[...h.layersWithOutsidePointerEventsDisabled].slice(-1),k=O?_.indexOf(O):-1,T=m?_.indexOf(m):-1,C=h.layersWithOutsidePointerEventsDisabled.size>0,N=T>=k,P=y.useRef(!1),D=c3(R=>{s==null||s(R),u==null||u(R),R.defaultPrevented||f==null||f()},{ownerDocument:x,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:P,dismissableSurfaces:h.dismissableSurfaces,shouldHandlePointerDownOutside:y.useCallback(R=>{if(!(R instanceof Node))return!1;const G=[...h.branches].some(q=>q.contains(R));return N&&!G},[h.branches,N])}),j=u3(R=>{if(i&&P.current)return;const G=R.target;[...h.branches].some(K=>K.contains(G))||(c==null||c(R),u==null||u(R),R.defaultPrevented||f==null||f())},x),I=m?T===_.length-1:!1,F=Cv(R=>{R.key==="Escape"&&(a==null||a(R),!R.defaultPrevented&&f&&(R.preventDefault(),f()))});return y.useEffect(()=>{if(I)return x.addEventListener("keydown",F,{capture:!0}),()=>x.removeEventListener("keydown",F,{capture:!0})},[x,I,F]),y.useEffect(()=>{if(m)return r&&(h.layersWithOutsidePointerEventsDisabled.size===0&&(hM=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),h.layersWithOutsidePointerEventsDisabled.add(m)),h.layers.add(m),$w(),()=>{r&&(h.layersWithOutsidePointerEventsDisabled.delete(m),h.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=hM))}},[m,x,r,h]),y.useEffect(()=>()=>{m&&(h.layers.delete(m),h.layersWithOutsidePointerEventsDisabled.delete(m),$w())},[m,h]),y.useEffect(()=>{const R=$n(()=>b({}),"handleUpdate");return document.addEventListener(zw,R),()=>document.removeEventListener(zw,R)},[]),w.jsx(Ov.div,{...p,ref:S,style:{pointerEvents:C?N?"auto":"none":void 0,...t.style},onFocusCapture:xs(t.onFocusCapture,j.onFocusCapture),onBlurCapture:xs(t.onBlurCapture,j.onBlurCapture),onPointerDownCapture:xs(t.onPointerDownCapture,D.onPointerDownCapture)})},"DismissableLayer"));function ore(){const e=y.useContext(l3),[t,n]=y.useState(null);return y.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}$n(ore,"useDismissableLayerSurface");var sre=$n(()=>!0,"IS_TRUE");function c3(e,t){const{ownerDocument:n=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:s=sre}=t,c=Cv(e),u=y.useRef(!1),f=y.useRef(!1),p=y.useRef(new Map),h=y.useRef(()=>{});return y.useEffect(()=>{function m(){f.current=!1,i.current=!1,p.current.clear()}$n(m,"resetOutsideInteraction");function v(){return Array.from(p.current.values()).some(Boolean)}$n(v,"isOutsideInteractionIntercepted");function x(k){if(!f.current)return;const T=k.target;T instanceof Node&&[...a].some(N=>N.contains(T))||p.current.set(k.type,!0),k.type==="click"&&window.setTimeout(()=>{f.current&&h.current()},0)}$n(x,"handleInteractionCapture");function b(k){f.current&&p.current.set(k.type,!1)}$n(b,"handleInteractionBubble");const S=$n(k=>{if(k.target&&!u.current){let T=function(){n.removeEventListener("click",h.current);const N=v();m(),N||eS(rre,c,C,{discrete:!0})};if($n(T,"handleAndDispatchPointerDownOutsideEvent"),!s(k.target)){n.removeEventListener("click",h.current),m(),u.current=!1;return}const C={originalEvent:k};f.current=!0,i.current=r&&k.button===0,p.current.clear(),!r||k.button!==0?T():(n.removeEventListener("click",h.current),h.current=T,n.addEventListener("click",h.current,{once:!0}))}else n.removeEventListener("click",h.current),m();u.current=!1},"handlePointerDown"),_=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const k of _)n.addEventListener(k,x,!0),n.addEventListener(k,b);const O=window.setTimeout(()=>{n.addEventListener("pointerdown",S)},0);return()=>{window.clearTimeout(O),n.removeEventListener("pointerdown",S),n.removeEventListener("click",h.current);for(const k of _)n.removeEventListener(k,x,!0),n.removeEventListener(k,b)}},[n,c,r,i,a,s]),{onPointerDownCapture:$n(()=>u.current=!0,"onPointerDownCapture")}}$n(c3,"usePointerDownOutside");function u3(e,t=globalThis==null?void 0:globalThis.document){const n=Cv(e),r=y.useRef(!1);return y.useEffect(()=>{const i=$n(a=>{a.target&&!r.current&&eS(ire,n,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,n]),{onFocusCapture:$n(()=>r.current=!0,"onFocusCapture"),onBlurCapture:$n(()=>r.current=!1,"onBlurCapture")}}$n(u3,"useFocusOutside");function $w(){const e=new CustomEvent(zw);document.dispatchEvent(e)}$n($w,"dispatchUpdate");function eS(e,t,n,{discrete:r}){const i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?s3(i,a):i.dispatchEvent(a)}$n(eS,"handleAndDispatchCustomEvent");var lre=Object.defineProperty,tS=(e,t)=>lre(e,"name",{value:t,configurable:!0}),hm=0,Zi=null;function cre(e){return nS(),e.children}tS(cre,"FocusGuards");function nS(){y.useEffect(()=>{Zi||(Zi={start:Bw(),end:Bw()});const{start:e,end:t}=Zi;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),hm++,()=>{hm===1&&(Zi==null||Zi.start.remove(),Zi==null||Zi.end.remove(),Zi=null),hm=Math.max(0,hm-1)}},[])}tS(nS,"useFocusGuards");function Bw(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}tS(Bw,"createFocusGuard");var ure=Object.defineProperty,fre=(e,t)=>ure(e,"name",{value:t,configurable:!0});function Uw(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}fre(Uw,"useCallbackRef");var dre=Object.defineProperty,pr=(e,t)=>dre(e,"name",{value:t,configurable:!0}),mx="focusScope.autoFocusOnMount",gx="focusScope.autoFocusOnUnmount",pM={bubbles:!1,cancelable:!0},hre=y.forwardRef(pr(function(t,n){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:s,...c}=t,[u,f]=y.useState(null),p=Uw(a),h=Uw(s),m=y.useRef(null),v=Bu(n,f),x=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(i){let S=function(T){if(x.paused||!u)return;const C=T.target;u.contains(C)?m.current=C:Xa(m.current,{select:!0})},_=function(T){if(x.paused||!u)return;const C=T.relatedTarget;C!==null&&(u.contains(C)||Xa(m.current,{select:!0}))},O=function(T){if(document.activeElement===document.body)for(const N of T)N.removedNodes.length>0&&Xa(u)};pr(S,"handleFocusIn"),pr(_,"handleFocusOut"),pr(O,"handleMutations"),document.addEventListener("focusin",S),document.addEventListener("focusout",_);const k=new MutationObserver(O);return u&&k.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",S),document.removeEventListener("focusout",_),k.disconnect()}}},[i,u,x.paused]),y.useEffect(()=>{if(u){mM.add(x);const S=document.activeElement;if(!u.contains(S)){const O=new CustomEvent(mx,pM);u.addEventListener(mx,p),u.dispatchEvent(O),O.defaultPrevented||(f3(g3(rS(u)),{select:!0}),document.activeElement===S&&Xa(u))}return()=>{u.removeEventListener(mx,p),setTimeout(()=>{const O=new CustomEvent(gx,pM);u.addEventListener(gx,h),u.dispatchEvent(O),O.defaultPrevented||Xa(S??document.body,{select:!0}),u.removeEventListener(gx,h),mM.remove(x)},0)}}},[u,p,h,x]);const b=y.useCallback(S=>{if(!r&&!i||x.paused)return;const _=S.key==="Tab"&&!S.altKey&&!S.ctrlKey&&!S.metaKey,O=document.activeElement;if(_&&O){const k=S.currentTarget,[T,C]=d3(k);T&&C?!S.shiftKey&&O===C?(S.preventDefault(),r&&Xa(T,{select:!0})):S.shiftKey&&O===T&&(S.preventDefault(),r&&Xa(C,{select:!0})):O===k&&S.preventDefault()}},[r,i,x.paused]);return w.jsx(Ov.div,{tabIndex:-1,...c,ref:v,onKeyDown:b})},"FocusScope"));function f3(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Xa(r,{select:t}),document.activeElement!==n)return}pr(f3,"focusFirst");function d3(e){const t=rS(e),n=Fw(t,e),r=Fw(t.reverse(),e);return[n,r]}pr(d3,"getTabbableEdges");function rS(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:pr(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;n.nextNode();)t.push(n.currentNode);return t}pr(rS,"getTabbableCandidates");function Fw(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):h3(r,{upTo:t})))return r}pr(Fw,"findVisible");function h3(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}pr(h3,"isHidden");function p3(e){return e instanceof HTMLInputElement&&"select"in e}pr(p3,"isSelectableInput");function Xa(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&p3(e)&&t&&e.select()}}pr(Xa,"focus");var mM=m3();function m3(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Hw(e,t),e.unshift(t)},remove(t){var n;e=Hw(e,t),(n=e[0])==null||n.resume()}}}pr(m3,"createFocusScopesStack");function Hw(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}pr(Hw,"arrayRemove");function g3(e){return e.filter(t=>t.tagName!=="A")}pr(g3,"removeLinks");var pre=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},mre=Object.defineProperty,gre=(e,t)=>mre(e,"name",{value:t,configurable:!0}),vre=Ea[" useId ".trim().toString()]||(()=>{}),yre=0;function v3(e){const[t,n]=y.useState(vre());return pre(()=>{e||n(r=>r??String(yre++))},[e]),e||(t?`radix-${t}`:"")}gre(v3,"useId");const bre=["top","right","bottom","left"],ks=Math.min,oo=Math.max,gg=Math.round,pm=Math.floor,so=e=>({x:e,y:e}),xre={left:"right",right:"left",bottom:"top",top:"bottom"};function y3(e,t,n){return oo(e,ks(t,n))}function po(e,t){return typeof e=="function"?e(t):e}function Os(e){return e.split("-")[0]}function Uu(e){return e.split("-")[1]}function iS(e){return e==="x"?"y":"x"}function aS(e){return e==="y"?"height":"width"}function sa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function oS(e){return iS(sa(e))}function wre(e,t,n){n===void 0&&(n=!1);const r=Uu(e),i=oS(e),a=aS(i);let s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=vg(s)),[s,vg(s)]}function Ere(e){const t=vg(e);return[Kw(e),t,Kw(t)]}function Kw(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const gM=["left","right"],vM=["right","left"],Sre=["top","bottom"],_re=["bottom","top"];function Are(e,t,n){switch(e){case"top":case"bottom":return n?t?vM:gM:t?gM:vM;case"left":case"right":return t?Sre:_re;default:return[]}}function kre(e,t,n,r){const i=Uu(e);let a=Are(Os(e),n==="start",r);return i&&(a=a.map(s=>s+"-"+i),t&&(a=a.concat(a.map(Kw)))),a}function vg(e){const t=Os(e);return xre[t]+e.slice(t.length)}function Ore(e){var t,n,r,i;return{top:(t=e.top)!=null?t:0,right:(n=e.right)!=null?n:0,bottom:(r=e.bottom)!=null?r:0,left:(i=e.left)!=null?i:0}}function b3(e){return typeof e!="number"?Ore(e):{top:e,right:e,bottom:e,left:e}}function yg(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function yM(e,t,n){let{reference:r,floating:i}=e;const a=sa(t),s=oS(t),c=aS(s),u=Os(t),f=a==="y",p=r.x+r.width/2-i.width/2,h=r.y+r.height/2-i.height/2,m=r[c]/2-i[c]/2;let v;switch(u){case"top":v={x:p,y:r.y-i.height};break;case"bottom":v={x:p,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:h};break;case"left":v={x:r.x-i.width,y:h};break;default:v={x:r.x,y:r.y}}const x=Uu(t);return x&&(v[s]+=m*(x==="end"?1:-1)*(n&&f?-1:1)),v}async function Cre(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:s,elements:c,strategy:u}=e,{boundary:f="clippingAncestors",rootBoundary:p="viewport",elementContext:h="floating",altBoundary:m=!1,padding:v=0}=po(t,e),x=b3(v),S=c[m?h==="floating"?"reference":"floating":h],_=yg(await a.getClippingRect({element:(n=await(a.isElement==null?void 0:a.isElement(S)))==null||n?S:S.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(c.floating)),boundary:f,rootBoundary:p,strategy:u})),O=h==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,k=await(a.getOffsetParent==null?void 0:a.getOffsetParent(c.floating)),T=await(a.isElement==null?void 0:a.isElement(k))&&await(a.getScale==null?void 0:a.getScale(k))||{x:1,y:1},C=yg(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:O,offsetParent:k,strategy:u}):O);return{top:(_.top-C.top+x.top)/T.y,bottom:(C.bottom-_.bottom+x.bottom)/T.y,left:(_.left-C.left+x.left)/T.x,right:(C.right-_.right+x.right)/T.x}}const Tre=50,Nre=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:s}=n,c=s.detectOverflow?s:{...s,detectOverflow:Cre},u=await(s.isRTL==null?void 0:s.isRTL(t));let f=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:p,y:h}=yM(f,r,u),m=r,v=0;const x={};for(let b=0;b<a.length;b++){const S=a[b];if(!S)continue;const{name:_,fn:O}=S,{x:k,y:T,data:C,reset:N}=await O({x:p,y:h,initialPlacement:r,placement:m,strategy:i,middlewareData:x,rects:f,platform:c,elements:{reference:e,floating:t}});p=k??p,h=T??h,x[_]={...x[_],...C},N&&v<Tre&&(v++,typeof N=="object"&&(N.placement&&(m=N.placement),N.rects&&(f=N.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:p,y:h}=yM(f,m,u)),b=-1)}return{x:p,y:h,placement:m,strategy:i,middlewareData:x}},Mre=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:a,platform:s,elements:c,middlewareData:u}=t,{element:f,padding:p=0}=po(e,t)||{};if(f==null)return{};const h=b3(p),m={x:n,y:r},v=oS(i),x=aS(v),b=await s.getDimensions(f),S=v==="y",_=S?"top":"left",O=S?"bottom":"right",k=S?"clientHeight":"clientWidth",T=a.reference[x]+a.reference[v]-m[v]-a.floating[x],C=m[v]-a.reference[v],N=await(s.getOffsetParent==null?void 0:s.getOffsetParent(f));let P=N?N[k]:0;(!P||!await(s.isElement==null?void 0:s.isElement(N)))&&(P=c.floating[k]||a.floating[x]);const D=T/2-C/2,j=P/2-b[x]/2-1,I=ks(h[_],j),F=ks(h[O],j),R=P-b[x]-F,G=P/2-b[x]/2+D,q=y3(I,G,R),K=!u.arrow&&Uu(i)!=null&&G!==q&&a.reference[x]/2-(G<I?I:F)-b[x]/2<0,U=K?G<I?G-I:G-R:0;return{[v]:m[v]+U,data:{[v]:q,centerOffset:G-q-U,...K&&{alignmentOffset:U}},reset:K}}}),Ire=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:a,rects:s,initialPlacement:c,platform:u,elements:f}=t,{mainAxis:p=!0,crossAxis:h=!0,fallbackPlacements:m,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:b=!0,...S}=po(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=Os(i),O=sa(c),k=Os(c)===c,T=await(u.isRTL==null?void 0:u.isRTL(f.floating)),C=m||(k||!b?[vg(c)]:Ere(c)),N=x!=="none";!m&&N&&C.push(...kre(c,b,x,T));const P=[c,...C],D=await u.detectOverflow(t,S),j=[];let I=((r=a.flip)==null?void 0:r.overflows)||[];if(p&&j.push(D[_]),h){const q=wre(i,s,T);j.push(D[q[0]],D[q[1]])}if(I=[...I,{placement:i,overflows:j}],!j.every(q=>q<=0)){var F,R;const q=(((F=a.flip)==null?void 0:F.index)||0)+1,K=P[q];if(K&&(!(h==="alignment"?O!==sa(K):!1)||I.every(H=>sa(H.placement)===O?H.overflows[0]>0:!0)))return{data:{index:q,overflows:I},reset:{placement:K}};let U=(R=I.filter(W=>W.overflows[0]<=0).sort((W,H)=>W.overflows[1]-H.overflows[1])[0])==null?void 0:R.placement;if(!U)switch(v){case"bestFit":{var G;const W=(G=I.filter(H=>{if(N){const Y=sa(H.placement);return Y===O||Y==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(Y=>Y>0).reduce((Y,z)=>Y+z,0)]).sort((H,Y)=>H[1]-Y[1])[0])==null?void 0:G[0];W&&(U=W);break}case"initialPlacement":U=c;break}if(i!==U)return{reset:{placement:U}}}return{}}}};function bM(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function xM(e){return bre.some(t=>e[t]>=0)}const Rre=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...a}=po(e,t);switch(i){case"referenceHidden":{const s=await r.detectOverflow(t,{...a,elementContext:"reference"}),c=bM(s,n.reference);return{data:{referenceHiddenOffsets:c,referenceHidden:xM(c)}}}case"escaped":{const s=await r.detectOverflow(t,{...a,altBoundary:!0}),c=bM(s,n.floating);return{data:{escapedOffsets:c,escaped:xM(c)}}}default:return{}}}}},x3=new Set(["left","top"]);async function Pre(e,t){const{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=Os(n),c=Uu(n),u=sa(n)==="y",f=x3.has(s)?-1:1,p=a&&u?-1:1,h=po(t,e);let{mainAxis:m,crossAxis:v,alignmentAxis:x}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return c&&typeof x=="number"&&(v=c==="end"?x*-1:x),u?{x:v*p,y:m*f}:{x:m*f,y:v*p}}const Dre=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:a,placement:s,middlewareData:c}=t,u=await Pre(t,e);return s===((n=c.offset)==null?void 0:n.placement)&&(r=c.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:a+u.y,data:{...u,placement:s}}}}},jre=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:a}=t,{mainAxis:s=!0,crossAxis:c=!1,limiter:u={fn:O=>{let{x:k,y:T}=O;return{x:k,y:T}}},...f}=po(e,t),p={x:n,y:r},h=await a.detectOverflow(t,f),m=sa(i),v=iS(m);let x=p[v],b=p[m];const S=(O,k)=>y3(k+h[O==="y"?"top":"left"],k,k-h[O==="y"?"bottom":"right"]);s&&(x=S(v,x)),c&&(b=S(m,b));const _=u.fn({...t,[v]:x,[m]:b});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[v]:s,[m]:c}}}}}},Lre=function(e){return e===void 0&&(e={}),{options:e,fn(t){var n,r;const{x:i,y:a,placement:s,rects:c,middlewareData:u}=t,{offset:f=0,mainAxis:p=!0,crossAxis:h=!0}=po(e,t),m={x:i,y:a},v=sa(s),x=iS(v);let b=m[x],S=m[v];const _=po(f,t),O=typeof _=="number"?{mainAxis:_,crossAxis:0}:{mainAxis:(n=_.mainAxis)!=null?n:0,crossAxis:(r=_.crossAxis)!=null?r:0};if(p){const C=x==="y"?"height":"width",N=c.reference[x]-c.floating[C]+O.mainAxis,P=c.reference[x]+c.reference[C]-O.mainAxis;b<N?b=N:b>P&&(b=P)}if(h){var k,T;const C=x==="y"?"width":"height",N=x3.has(Os(s)),P=c.reference[v]-c.floating[C]+(N&&((k=u.offset)==null?void 0:k[v])||0)+(N?0:O.crossAxis),D=c.reference[v]+c.reference[C]+(N?0:((T=u.offset)==null?void 0:T[v])||0)-(N?O.crossAxis:0);S<P?S=P:S>D&&(S=D)}return{[x]:b,[v]:S}}}},zre=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:n,rects:r,platform:i,elements:a}=t,{apply:s=()=>{},...c}=po(e,t),u=await i.detectOverflow(t,c),f=Os(n),p=Uu(n),h=sa(n)==="y",{width:m,height:v}=r.floating;let x,b;f==="top"||f==="bottom"?(x=f,b=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(b=f,x=p==="end"?"top":"bottom");const S=v-u.top-u.bottom,_=m-u.left-u.right,O=ks(v-u[x],S),k=ks(m-u[b],_),T=t.middlewareData.shift,C=!T;let N=O,P=k;T!=null&&T.enabled.x&&(P=_),T!=null&&T.enabled.y&&(N=S),C&&!p&&(h?P=m-2*oo(u.left,u.right):N=v-2*oo(u.top,u.bottom)),await s({...t,availableWidth:P,availableHeight:N});const D=await i.getDimensions(a.floating);return m!==D.width||v!==D.height?{reset:{rects:!0}}:{}}}};function Tv(){return typeof window<"u"}function Fu(e){return w3(e)?(e.nodeName||"").toLowerCase():"#document"}function Pr(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function wo(e){var t;return(t=(w3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function w3(e){return Tv()?e instanceof Node||e instanceof Pr(e).Node:!1}function ma(e){return Tv()?e instanceof Element||e instanceof Pr(e).Element:!1}function Ls(e){return Tv()?e instanceof HTMLElement||e instanceof Pr(e).HTMLElement:!1}function wM(e){return!Tv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Pr(e).ShadowRoot}function Nv(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=ga(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function $re(e){return/^(table|td|th)$/.test(Fu(e))}function Mv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Bre=/transform|translate|scale|rotate|perspective|filter/,Ure=/paint|layout|strict|content/,ul=e=>!!e&&e!=="none";let vx;function sS(e){const t=ma(e)?ga(e):e;return ul(t.transform)||ul(t.translate)||ul(t.scale)||ul(t.rotate)||ul(t.perspective)||!lS()&&(ul(t.backdropFilter)||ul(t.filter))||Bre.test(t.willChange||"")||Ure.test(t.contain||"")}function Fre(e){let t=$l(e);for(;Ls(t)&&!zd(t);){if(sS(t))return t;if(Mv(t))return null;t=$l(t)}return null}function lS(){return vx==null&&(vx=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),vx}function zd(e){return/^(html|body|#document)$/.test(Fu(e))}function ga(e){return Pr(e).getComputedStyle(e)}function Iv(e){return ma(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $l(e){if(Fu(e)==="html")return e;const t=e.assignedSlot||e.parentNode||wM(e)&&e.host||wo(e);return wM(t)?t.host:t}function E3(e){const t=$l(e);return zd(t)?(e.ownerDocument||e).body:Ls(t)&&Nv(t)?t:E3(t)}function $d(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=E3(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=Pr(i);if(a){const c=qw(s);return t.concat(s,s.visualViewport||[],Nv(i)?i:[],c&&n?$d(c):[])}else return t.concat(i,$d(i,[],n))}function qw(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function S3(e){const t=ga(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ls(e),a=i?e.offsetWidth:n,s=i?e.offsetHeight:r,c=gg(n)!==a||gg(r)!==s;return c&&(n=a,r=s),{width:n,height:r,$:c}}function cS(e){return ma(e)?e:e.contextElement}function pu(e){const t=cS(e);if(!Ls(t))return so(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=S3(t);let s=(a?gg(n.width):n.width)/r,c=(a?gg(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}const Hre=so(0);function _3(e){const t=Pr(e);return!lS()||!t.visualViewport?Hre:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Kre(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Pr(e)}function Bl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=cS(e);let s=so(1);t&&(r?ma(r)&&(s=pu(r)):s=pu(e));const c=Kre(a,n,r)?_3(a):so(0);let u=(i.left+c.x)/s.x,f=(i.top+c.y)/s.y,p=i.width/s.x,h=i.height/s.y;if(a&&r){const m=Pr(a),v=ma(r)?Pr(r):r;let x=m,b=qw(x);for(;b&&v!==x;){const S=pu(b),_=b.getBoundingClientRect(),O=ga(b),k=_.left+(b.clientLeft+parseFloat(O.paddingLeft))*S.x,T=_.top+(b.clientTop+parseFloat(O.paddingTop))*S.y;u*=S.x,f*=S.y,p*=S.x,h*=S.y,u+=k,f+=T,x=Pr(b),b=qw(x)}}return yg({width:p,height:h,x:u,y:f})}function Rv(e,t){const n=Iv(e).scrollLeft;return t?t.left+n:Bl(wo(e)).left+n}function A3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Rv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function qre(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const a=i==="fixed",s=wo(r),c=t?Mv(t.floating):!1;if(r===s||c&&a)return n;let u={scrollLeft:0,scrollTop:0},f=so(1);const p=so(0),h=Ls(r);if((h||!a)&&((Fu(r)!=="body"||Nv(s))&&(u=Iv(r)),h)){const v=Bl(r);f=pu(r),p.x=v.x+r.clientLeft,p.y=v.y+r.clientTop}const m=s&&!h&&!a?A3(s,u):so(0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-u.scrollLeft*f.x+p.x+m.x,y:n.y*f.y-u.scrollTop*f.y+p.y+m.y}}function Gre(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Vre(e){const t=Iv(e),n=e.ownerDocument.body,r=oo(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=oo(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+Rv(e);const s=-t.scrollTop;return ga(n).direction==="rtl"&&(a+=oo(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:s}}const Wre=25;function Yre(e,t,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",i=Pr(e),a=wo(e),s=i.visualViewport;let c=a.clientWidth,u=a.clientHeight,f=0,p=0;if(s){const m=!lS()||t==="fixed";r?m||(f=-s.offsetLeft,p=-s.offsetTop):(c=s.width,u=s.height,m&&(f=s.offsetLeft,p=s.offsetTop))}if(Rv(a)<=0){const m=a.ownerDocument,v=m.body,x=getComputedStyle(v),b=m.compatMode==="CSS1Compat"&&parseFloat(x.marginLeft)+parseFloat(x.marginRight)||0,S=Math.abs(a.clientWidth-v.clientWidth-b),_=getComputedStyle(a).scrollbarGutter==="stable both-edges"?S/2:S;_<=Wre&&(c-=_)}return{width:c,height:u,x:f,y:p}}function Xre(e,t){const n=Bl(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=pu(e),s=e.clientWidth*a.x,c=e.clientHeight*a.y,u=i*a.x,f=r*a.y;return{width:s,height:c,x:u,y:f}}function EM(e,t,n){let r;if(t==="viewport"||t==="layoutViewport")r=Yre(e,n,t);else if(t==="document")r=Vre(wo(e));else if(ma(t))r=Xre(t,n);else{const i=_3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return yg(r)}function Zre(e,t){const n=t.get(e);if(n)return n;let r=$d(e,[],!1).filter(c=>ma(c)&&Fu(c)!=="body"),i=null;const a=ga(e).position==="fixed";let s=a?$l(e):e;for(;ma(s)&&!zd(s);){const c=ga(s),u=sS(s),f=i?i.position:a?"fixed":"";!u&&(f==="fixed"||f==="absolute"&&c.position==="static")?r=r.filter(h=>h!==s):i=c,s=$l(s)}return t.set(e,r),r}function Qre(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const s=[...n==="clippingAncestors"?Mv(t)?[]:Zre(t,this._c):[].concat(n),r],c=EM(t,s[0],i);let u=c.top,f=c.right,p=c.bottom,h=c.left;for(let m=1;m<s.length;m++){const v=EM(t,s[m],i);u=oo(v.top,u),f=ks(v.right,f),p=ks(v.bottom,p),h=oo(v.left,h)}return{width:f-h,height:p-u,x:h,y:u}}function Jre(e){const{width:t,height:n}=S3(e);return{width:t,height:n}}function eie(e,t,n){const r=Ls(t),i=wo(t),a=n==="fixed",s=Bl(e,!0,a,t);let c={scrollLeft:0,scrollTop:0};const u=so(0);if((r||!a)&&((Fu(t)!=="body"||Nv(i))&&(c=Iv(t)),r)){const m=Bl(t,!0,a,t);u.x=m.x+t.clientLeft,u.y=m.y+t.clientTop}!r&&i&&(u.x=Rv(i));const f=i&&!r&&!a?A3(i,c):so(0),p=s.left+c.scrollLeft-u.x-f.x,h=s.top+c.scrollTop-u.y-f.y;return{x:p,y:h,width:s.width,height:s.height}}function yx(e){return ga(e).position==="static"}function SM(e,t){if(!Ls(e)||ga(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return wo(e)===n&&(n=n.ownerDocument.body),n}function k3(e,t){const n=Pr(e);if(Mv(e))return n;if(!Ls(e)){let i=$l(e);for(;i&&!zd(i);){if(ma(i)&&!yx(i))return i;i=$l(i)}return n}let r=SM(e,t);for(;r&&$re(r)&&yx(r);)r=SM(r,t);return r&&zd(r)&&yx(r)&&!sS(r)?n:r||Fre(e)||n}const tie=async function(e){const t=this.getOffsetParent||k3,n=this.getDimensions,r=await n(e.floating);return{reference:eie(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function nie(e){return ga(e).direction==="rtl"}const rie={convertOffsetParentRelativeRectToViewportRelativeRect:qre,getDocumentElement:wo,getClippingRect:Qre,getOffsetParent:k3,getElementRects:tie,getClientRects:Gre,getDimensions:Jre,getScale:pu,isElement:ma,isRTL:nie};function O3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function iie(e,t,n){let r=null,i;const a=wo(e);function s(){var p;clearTimeout(i),(p=r)==null||p.disconnect(),r=null}function c(p,h){p===void 0&&(p=!1),h===void 0&&(h=1),s();const m=e.getBoundingClientRect(),{left:v,top:x,width:b,height:S}=m;if(p||t(),!b||!S)return;const _=pm(x),O=pm(a.clientWidth-(v+b)),k=pm(a.clientHeight-(x+S)),T=pm(v),N={rootMargin:-_+"px "+-O+"px "+-k+"px "+-T+"px",threshold:oo(0,ks(1,h))||1};let P=!0;function D(j){const I=j[0].intersectionRatio;if(!O3(m,e.getBoundingClientRect()))return c();if(I!==h){if(!P)return c();I?c(!1,I):i=setTimeout(()=>{c(!1,1e-7)},1e3)}P=!1}try{r=new IntersectionObserver(D,{...N,root:a.ownerDocument})}catch{r=new IntersectionObserver(D,N)}r.observe(e)}const u=Pr(e),f=()=>c(n);return u.addEventListener("resize",f),c(!0),()=>{u.removeEventListener("resize",f),s()}}function aie(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,f=cS(e),p=i||a?[...f?$d(f):[],...t?$d(t):[]]:[];p.forEach(_=>{i&&_.addEventListener("scroll",n),a&&_.addEventListener("resize",n)});const h=f&&c?iie(f,n,a):null;let m=-1,v=null;s&&(v=new ResizeObserver(_=>{let[O]=_;O&&O.target===f&&v&&t&&(v.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var k;(k=v)==null||k.observe(t)})),n()}),f&&!u&&v.observe(f),t&&v.observe(t));let x,b=u?Bl(e):null;u&&S();function S(){const _=Bl(e);b&&!O3(b,_)&&n(),b=_,x=requestAnimationFrame(S)}return n(),()=>{var _;p.forEach(O=>{i&&O.removeEventListener("scroll",n),a&&O.removeEventListener("resize",n)}),h==null||h(),(_=v)==null||_.disconnect(),v=null,u&&cancelAnimationFrame(x)}}const oie=Dre,sie=jre,lie=Ire,cie=zre,uie=Rre,_M=Mre,fie=Lre,die=(e,t,n)=>{const r=new Map,i=n??{},a={...rie,...i.platform,_c:r};return Nre(e,t,{...i,platform:a})};var hie=typeof document<"u",pie=function(){},Fm=hie?y.useLayoutEffect:pie;function bg(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!bg(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const a=i[r];if(!(a==="_owner"&&e.$$typeof)&&!bg(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function C3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function AM(e,t){const n=C3(e);return Math.round(t*n)/n}function bx(e){const t=y.useRef(e);return Fm(()=>{t.current=e}),t}function mie(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:s}={},transform:c=!0,whileElementsMounted:u,open:f}=e,[p,h]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,v]=y.useState(r);bg(m,r)||v(r);const[x,b]=y.useState(null),[S,_]=y.useState(null),O=y.useCallback(H=>{H!==N.current&&(N.current=H,b(H))},[]),k=y.useCallback(H=>{H!==P.current&&(P.current=H,_(H))},[]),T=a||x,C=s||S,N=y.useRef(null),P=y.useRef(null),D=y.useRef(p),j=u!=null,I=bx(u),F=bx(i),R=bx(f),G=y.useCallback(()=>{if(!N.current||!P.current)return;const H={placement:t,strategy:n,middleware:m};F.current&&(H.platform=F.current),die(N.current,P.current,H).then(Y=>{const z={...Y,isPositioned:R.current!==!1};q.current&&!bg(D.current,z)&&(D.current=z,Sa.flushSync(()=>{h(z)}))})},[m,t,n,F,R]);Fm(()=>{f===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,h(H=>({...H,isPositioned:!1})))},[f]);const q=y.useRef(!1);Fm(()=>(q.current=!0,()=>{q.current=!1}),[]),Fm(()=>{if(T&&(N.current=T),C&&(P.current=C),T&&C){if(I.current)return I.current(T,C,G);G()}},[T,C,G,I,j]);const K=y.useMemo(()=>({reference:N,floating:P,setReference:O,setFloating:k}),[O,k]),U=y.useMemo(()=>({reference:T,floating:C}),[T,C]),W=y.useMemo(()=>{const H={position:n,left:0,top:0};if(!U.floating)return H;const Y=AM(U.floating,p.x),z=AM(U.floating,p.y);return c?{...H,transform:"translate("+Y+"px, "+z+"px)",...C3(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Y,top:z}},[n,c,U.floating,p.x,p.y]);return y.useMemo(()=>({...p,update:G,refs:K,elements:U,floatingStyles:W}),[p,G,K,U,W])}const gie=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?_M({element:r.current,padding:i}).fn(n):{}:r?_M({element:r,padding:i}).fn(n):{}}}},vie=(e,t)=>{const n=oie(e);return{name:n.name,fn:n.fn,options:[e,t]}},yie=(e,t)=>{const n=sie(e);return{name:n.name,fn:n.fn,options:[e,t]}},bie=(e,t)=>({fn:fie(e).fn,options:[e,t]}),xie=(e,t)=>{const n=lie(e);return{name:n.name,fn:n.fn,options:[e,t]}},wie=(e,t)=>{const n=cie(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eie=(e,t)=>{const n=uie(e);return{name:n.name,fn:n.fn,options:[e,t]}},Sie=(e,t)=>{const n=gie(e);return{name:n.name,fn:n.fn,options:[e,t]}};var _ie=Object.defineProperty,uS=(e,t)=>_ie(e,"name",{value:t,configurable:!0});function Gw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}uS(Gw,"setRef");function T3(...e){return t=>{let n=!1;const r=e.map(i=>{const a=Gw(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():Gw(e[i],null)}}}}uS(T3,"composeRefs");function Pv(...e){return y.useCallback(T3(...e),e)}uS(Pv,"useComposedRefs");var Aie=Object.defineProperty,Ei=(e,t)=>Aie(e,"name",{value:t,configurable:!0});function kie(e,t){const n=y.createContext(t);n.displayName=e+"Context";const r=Ei(a=>{const{children:s,...c}=a,u=y.useMemo(()=>c,Object.values(c));return w.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:c=!1}=s,u=y.useContext(n);if(u)return u;if(t!==void 0)return t;if(!c)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ei(i,"useContext"),[r,i]}Ei(kie,"createContext");function N3(e,t=[]){let n=[];function r(a,s){const c=y.createContext(s);c.displayName=a+"Context";const u=n.length;n=[...n,s];const f=Ei(h=>{var _;const{scope:m,children:v,...x}=h,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useMemo(()=>x,Object.values(x));return w.jsx(b.Provider,{value:S,children:v})},"Provider");f.displayName=a+"Provider";function p(h,m,v={}){var _;const{optional:x=!1}=v,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useContext(b);if(S)return S;if(s!==void 0)return s;if(!x)throw new Error(`\`${h}\` must be used within \`${a}\``)}return Ei(p,"useContext"),[f,p]}Ei(r,"createContext");const i=Ei(()=>{const a=n.map(s=>y.createContext(s));return Ei(function(c){const u=(c==null?void 0:c[e])||a;return y.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])},"useScope")},"createScope");return i.scopeName=e,[r,M3(i,...t)]}Ei(N3,"createContextScope");function M3(...e){const t=e[0];if(e.length===1)return t;const n=Ei(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ei(function(a){const s=r.reduce((c,{useScope:u,scopeName:f})=>{const h=u(a)[`__scope${f}`];return{...c,...h}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ei(M3,"composeContextScopes");var Oie=Object.defineProperty,Fi=(e,t)=>Oie(e,"name",{value:t,configurable:!0});function I3(e){const t=y.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,c=!1;const u=[];Vw(i)&&typeof mm=="function"&&(i=mm(i._payload)),y.Children.forEach(i,m=>{var v;if(j3(m)){c=!0;const x=m;let b="child"in x.props?x.props.child:x.props.children;Vw(b)&&typeof mm=="function"&&(b=mm(b._payload)),s=Tie(x,b),u.push((v=s==null?void 0:s.props)==null?void 0:v.children)}else u.push(m)}),s?s=y.cloneElement(s,void 0,u):!c&&y.Children.count(i)===1&&y.isValidElement(i)&&(s=i);const f=s?D3(s):void 0,p=Pv(r,f);if(!s){if(i||i===0)throw new Error(c?Iie(e):Mie(e));return i}const h=P3(a,s.props??{});return s.type!==y.Fragment&&(h.ref=r?p:f),y.cloneElement(s,h)});return t.displayName=`${e}.Slot`,t}Fi(I3,"createSlot");var R3=Symbol.for("radix.slottable");function Cie(e){const t=Fi(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=R3,t}Fi(Cie,"createSlottable");var Tie=Fi((e,t)=>{if("child"in e.props){const n=e.props.child;return y.isValidElement(n)?y.cloneElement(n,void 0,e.props.children(n.props.children)):null}return y.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function P3(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...c)=>{const u=a(...c);return i(...c),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}Fi(P3,"mergeProps");function D3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Fi(D3,"getElementRef");function j3(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===R3}Fi(j3,"isSlottable");var Nie=Symbol.for("react.lazy");function Vw(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Nie&&"_payload"in e&&L3(e._payload)}Fi(Vw,"isLazyComponent");function L3(e){return typeof e=="object"&&e!==null&&"then"in e}Fi(L3,"isPromiseLike");var Mie=Fi(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Iie=Fi(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),mm=Ea[" use ".trim().toString()],Rie=Object.defineProperty,Pie=(e,t)=>Rie(e,"name",{value:t,configurable:!0}),Die=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],z3=Die.reduce((e,t)=>{const n=I3(`Primitive.${t}`),r=y.forwardRef((i,a)=>{const{asChild:s,...c}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),w.jsx(u,{...c,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function jie(e,t){e&&Sa.flushSync(()=>e.dispatchEvent(t))}Pie(jie,"dispatchDiscreteCustomEvent");var Lie=Object.defineProperty,zie=(e,t)=>Lie(e,"name",{value:t,configurable:!0});function $3(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}zie($3,"useCallbackRef");var xx=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},$ie=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},Bie=Object.defineProperty,Uie=(e,t)=>Bie(e,"name",{value:t,configurable:!0});function B3(e){const[t,n]=y.useState(void 0);return $ie(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let s,c;if("borderBoxSize"in a){const u=a.borderBoxSize,f=Array.isArray(u)?u[0]:u;s=f.inlineSize,c=f.blockSize}else s=e.offsetWidth,c=e.offsetHeight;n({width:s,height:c})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}Uie(B3,"useSize");var Fie=Object.defineProperty,ws=(e,t)=>Fie(e,"name",{value:t,configurable:!0}),U3="Popper",[F3,H3]=N3(U3),[Hie,K3]=F3(U3),Kie=ws(e=>{const{__scopePopper:t,children:n}=e,[r,i]=y.useState(null),[a,s]=y.useState(void 0);return w.jsx(Hie,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:s,children:n})},"Popper"),qie="PopperAnchor",Gie=y.forwardRef(ws(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=K3(qie,r),c=y.useRef(null),u=s.onAnchorChange,f=y.useCallback(b=>{c.current=b,b&&u(b)},[u]),p=Pv(n,f),h=y.useRef(null);y.useEffect(()=>{if(!i)return;const b=h.current;h.current=i.current,b!==h.current&&u(h.current)});const m=s.placementState&&Dv(s.placementState),v=m==null?void 0:m[0],x=m==null?void 0:m[1];return i?null:w.jsx(z3.div,{"data-radix-popper-side":v,"data-radix-popper-align":x,...a,ref:p})},"PopperAnchor")),q3="PopperContent",[Vie,zOe]=F3(q3),Wie=y.forwardRef(ws(function(t,n){var he,ke,we,fe,pt,qe,Oe;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:s="center",alignOffset:c=0,arrowPadding:u=0,avoidCollisions:f=!0,collisionBoundary:p=[],collisionPadding:h=0,sticky:m="partial",hideWhenDetached:v=!1,updatePositionStrategy:x="optimized",onPlaced:b,...S}=t,_=K3(q3,r),[O,k]=y.useState(null),T=Pv(n,k),[C,N]=y.useState(null),P=B3(C),D=(P==null?void 0:P.width)??0,j=(P==null?void 0:P.height)??0,I=i+(s!=="center"?"-"+s:""),F=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},R=Array.isArray(p)?p:[p],G=R.length>0,q={padding:F,boundary:R.filter(G3),altBoundary:G},{refs:K,floatingStyles:U,placement:W,isPositioned:H,middlewareData:Y}=mie({strategy:"fixed",placement:I,whileElementsMounted:ws((...De)=>aie(...De,{animationFrame:x==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[vie({mainAxis:a+j,alignmentAxis:c}),f&&yie({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?bie():void 0,...q}),f&&xie({...q}),wie({...q,apply:ws(({elements:De,rects:Pt,availableWidth:mn,availableHeight:br})=>{const{width:Hn,height:zr}=Pt.reference,ii=De.floating.style;ii.setProperty("--radix-popper-available-width",`${mn}px`),ii.setProperty("--radix-popper-available-height",`${br}px`),ii.setProperty("--radix-popper-anchor-width",`${Hn}px`),ii.setProperty("--radix-popper-anchor-height",`${zr}px`)},"apply")}),C&&Sie({element:C,padding:u}),Yie({arrowWidth:D,arrowHeight:j}),v&&Eie({strategy:"referenceHidden",...q,boundary:G?q.boundary:void 0})]}),z=_.setPlacementState;xx(()=>(z(W),()=>{z(void 0)}),[W,z]);const[$,Z]=Dv(W),L=$3(b);xx(()=>{H&&(L==null||L())},[H,L]);const ae=(he=Y.arrow)==null?void 0:he.x,me=(ke=Y.arrow)==null?void 0:ke.y,de=((we=Y.arrow)==null?void 0:we.centerOffset)!==0,[Ee,Ge]=y.useState();return xx(()=>{O&&Ge(window.getComputedStyle(O).zIndex)},[O]),w.jsx("div",{ref:K.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:H?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ee,"--radix-popper-transform-origin":[(fe=Y.transformOrigin)==null?void 0:fe.x,(pt=Y.transformOrigin)==null?void 0:pt.y].join(" "),...((qe=Y.hide)==null?void 0:qe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:w.jsx(Vie,{scope:r,placedSide:$,placedAlign:Z,onArrowChange:N,arrowX:ae,arrowY:me,shouldHideArrow:de,children:w.jsx(z3.div,{"data-side":$,"data-align":Z,...S,ref:T,style:{...S.style,animation:H?(Oe=S.style)==null?void 0:Oe.animation:"none"}})})})},"PopperContent"));function G3(e){return e!==null}ws(G3,"isNotNull");var Yie=ws(e=>({name:"transformOrigin",options:e,fn(t){var S,_,O;const{placement:n,rects:r,middlewareData:i}=t,s=((S=i.arrow)==null?void 0:S.centerOffset)!==0,c=s?0:e.arrowWidth,u=s?0:e.arrowHeight,[f,p]=Dv(n),h={start:"0%",center:"50%",end:"100%"}[p],m=(((_=i.arrow)==null?void 0:_.x)??0)+c/2,v=(((O=i.arrow)==null?void 0:O.y)??0)+u/2;let x="",b="";return f==="bottom"?(x=s?h:`${m}px`,b=`${-u}px`):f==="top"?(x=s?h:`${m}px`,b=`${r.floating.height+u}px`):f==="right"?(x=`${-u}px`,b=s?h:`${v}px`):f==="left"&&(x=`${r.floating.width+u}px`,b=s?h:`${v}px`),{data:{x,y:b}}}}),"transformOrigin");function Dv(e){const[t,n="center"]=e.split("-");return[t,n]}ws(Dv,"getSideAndAlignFromPlacement");var Xie=Kie,Zie=Gie,Qie=Wie,Jie=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},eae=Object.defineProperty,tae=(e,t)=>eae(e,"name",{value:t,configurable:!0}),nae=y.forwardRef(tae(function(t,n){var u;const{container:r,...i}=t,[a,s]=y.useState(!1);Jie(()=>s(!0),[]);const c=r||a&&((u=globalThis==null?void 0:globalThis.document)==null?void 0:u.body);return c?Sa.createPortal(w.jsx(Ov.div,{...i,ref:n}),c):null},"Portal")),kM=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},rae=Object.defineProperty,mo=(e,t)=>rae(e,"name",{value:t,configurable:!0});function V3(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}mo(V3,"useStateMachine");var W3=mo(e=>{const{present:t,children:n}=e,r=Y3(t),i=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),a=X3(r.ref,Z3(i));return typeof n=="function"||r.isPresent?y.cloneElement(i,{ref:a}):null},"Presence");function Y3(e){const[t,n]=y.useState(),r=y.useRef(null),i=y.useRef(e),a=y.useRef("none"),s=y.useRef(void 0),c=e?"mounted":"unmounted",[u,f]=V3(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{u==="mounted"?(a.current=s.current??ru(r.current),s.current=void 0):a.current="none"},[u]),kM(()=>{const p=r.current,h=i.current;if(h!==e){const v=a.current,x=ru(p);e?(s.current=x,f("MOUNT")):x==="none"||(p==null?void 0:p.display)==="none"?f("UNMOUNT"):f(h&&v!==x?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,f]),kM(()=>{if(t){let p;const h=t.ownerDocument.defaultView??window,m=mo(x=>{const S=ru(r.current).includes(CSS.escape(x.animationName));if(x.target===t&&S&&(f("ANIMATION_END"),!i.current)){const _=t.style.animationFillMode;t.style.animationFillMode="forwards",p=h.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=_)})}},"handleAnimationEnd"),v=mo(x=>{x.target===t&&(a.current=ru(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",v),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{h.clearTimeout(p),t.removeEventListener("animationstart",v),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:y.useCallback(p=>{if(p){const h=getComputedStyle(p);r.current=h,s.current=ru(h)}else r.current=null;n(p)},[])}}mo(Y3,"usePresence");function Ww(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}mo(Ww,"setRef");function X3(...e){const t=y.useRef(e);return t.current=e,y.useCallback(n=>{const r=t.current;let i=!1;const a=r.map(s=>{const c=Ww(s,n);return!i&&typeof c=="function"&&(i=!0),c});if(i)return()=>{for(let s=0;s<a.length;s++){const c=a[s];typeof c=="function"?c():Ww(r[s],null)}}},[])}mo(X3,"useStableComposedRefs");function ru(e){return(e==null?void 0:e.animationName)||"none"}mo(ru,"getAnimationName");function Z3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}mo(Z3,"getElementRef");var Q3=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},iae=Object.defineProperty,aae=(e,t)=>iae(e,"name",{value:t,configurable:!0}),OM=Ea[" useEffectEvent ".trim().toString()],CM=Ea[" useInsertionEffect ".trim().toString()];function J3(e){if(typeof OM=="function")return OM(e);const t=y.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof CM=="function"?CM(()=>{t.current=e}):Q3(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}aae(J3,"useEffectEvent");var oae=Object.defineProperty,fh=(e,t)=>oae(e,"name",{value:t,configurable:!0}),sae=Ea[" useInsertionEffect ".trim().toString()]||Q3;function e$({prop:e,defaultProp:t,onChange:n=fh(()=>{},"onChange"),caller:r}){const[i,a,s]=t$({defaultProp:t,onChange:n}),c=e!==void 0,u=c?e:i,f=y.useCallback(p=>{var h;if(c){const m=n$(p)?p(e):p;m!==e&&((h=s.current)==null||h.call(s,m))}else a(p)},[c,e,a,s]);return[u,f]}fh(e$,"useControllableState");function t$({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),i=y.useRef(n),a=y.useRef(t);return sae(()=>{a.current=t},[t]),y.useEffect(()=>{var s;i.current!==n&&((s=a.current)==null||s.call(a,n),i.current=n)},[n,i]),[n,r,a]}fh(t$,"useUncontrolledState");function n$(e){return typeof e=="function"}fh(n$,"isFunction");var TM=Symbol("RADIX:SYNC_STATE");function lae(e,t,n,r){const{prop:i,defaultProp:a,onChange:s,caller:c}=t,u=i!==void 0,f=J3(s),p=[{...n,state:a}];r&&p.push(r);const[h,m]=y.useReducer((S,_)=>{if(_.type===TM)return{...S,state:_.state};const O=e(S,_);return u&&!Object.is(O.state,S.state)&&f(O.state),O},...p),v=h.state,x=y.useRef(v);y.useEffect(()=>{x.current!==v&&(x.current=v,u||f(v))},[v,x,u]);const b=y.useMemo(()=>i!==void 0?{...h,state:i}:h,[h,i]);return y.useEffect(()=>{u&&!Object.is(i,h.state)&&m({type:TM,state:i})},[i,h.state,u]),[b,m]}fh(lae,"useControllableStateReducer");var cae=Object.defineProperty,zs=(e,t)=>cae(e,"name",{value:t,configurable:!0}),fS="Popover",[r$,$Oe]=e3(fS,[H3]),dS=H3(),[uae,Hu]=r$(fS),fae=zs(e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!1}=e,c=dS(t),u=y.useRef(null),[f,p]=y.useState(!1),[h,m]=e$({prop:r,defaultProp:i??!1,onChange:a,caller:fS});return w.jsx(Xie,{...c,children:w.jsx(uae,{scope:t,contentId:v3(),triggerRef:u,open:h,onOpenChange:m,onOpenToggle:y.useCallback(()=>m(v=>!v),[m]),hasCustomAnchor:f,onCustomAnchorAdd:y.useCallback(()=>p(!0),[]),onCustomAnchorRemove:y.useCallback(()=>p(!1),[]),modal:s,children:n})})},"Popover"),dae="PopoverTrigger",hae=y.forwardRef(zs(function(t,n){const{__scopePopover:r,...i}=t,a=Hu(dae,r),s=dS(r),c=Bu(n,a.triggerRef),u=w.jsx(Ov.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":hS(a.open),...i,ref:c,onClick:xs(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:w.jsx(Zie,{asChild:!0,...s,children:u})},"PopoverTrigger")),i$="PopoverPortal",[pae,mae]=r$(i$,{forceMount:void 0}),gae=zs(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=Hu(i$,t);return w.jsx(pae,{scope:t,forceMount:n,children:w.jsx(W3,{present:n||a.open,children:w.jsx(nae,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),Bd="PopoverContent",vae=y.forwardRef(zs(function(t,n){const r=mae(Bd,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=Hu(Bd,t.__scopePopover);return w.jsx(W3,{present:i||s.open,children:s.modal?w.jsx(bae,{...a,ref:n}):w.jsx(xae,{...a,ref:n})})},"PopoverContent")),yae=JE("PopoverContent.RemoveScroll"),bae=y.forwardRef(zs(function(t,n){const r=Hu(Bd,t.__scopePopover),i=y.useRef(null),a=Bu(n,i),s=y.useRef(!1);return y.useEffect(()=>{const c=i.current;if(c)return Dz(c)},[]),w.jsx(GE,{as:yae,allowPinchZoom:!0,children:w.jsx(a$,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:xs(t.onCloseAutoFocus,c=>{var u;c.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:xs(t.onPointerDownOutside,c=>{const u=c.detail.originalEvent,f=u.button===0&&u.ctrlKey===!0,p=u.button===2||f;s.current=p},{checkForDefaultPrevented:!1}),onFocusOutside:xs(t.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),xae=y.forwardRef(zs(function(t,n){const r=Hu(Bd,t.__scopePopover),i=y.useRef(!1),a=y.useRef(!1);return w.jsx(a$,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var c,u;(c=t.onCloseAutoFocus)==null||c.call(t,s),s.defaultPrevented||(i.current||(u=r.triggerRef.current)==null||u.focus(),s.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:s=>{var f,p;(f=t.onInteractOutside)==null||f.call(t,s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const c=s.target;((p=r.triggerRef.current)==null?void 0:p.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&a.current&&s.preventDefault()}})},"PopoverContentNonModal")),a$=y.forwardRef(zs(function(t,n){const{__scopePopover:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:s,disableOutsidePointerEvents:c,onEscapeKeyDown:u,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:h,...m}=t,v=Hu(Bd,r),x=dS(r);return nS(),w.jsx(hre,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:s,children:w.jsx(are,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:h,onEscapeKeyDown:u,onPointerDownOutside:f,onFocusOutside:p,onDismiss:()=>v.onOpenChange(!1),deferPointerDownOutside:!0,children:w.jsx(Qie,{"data-state":hS(v.open),role:"dialog",id:v.contentId,...x,...m,ref:n,style:{...m.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})},"PopoverContentImpl"));function hS(e){return e?"open":"closed"}zs(hS,"getState");var wae=fae,Eae=hae,Sae=gae,o$=vae;const _ae=wae,Aae=Eae,s$=y.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>w.jsx(Sae,{children:w.jsx(o$,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:Ue("z-50 w-64 max-w-[calc(100vw-1rem)] rounded-md border bg-card p-3 text-card-foreground shadow-md outline-none","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...a})}));s$.displayName=o$.displayName;const l$=92,c$=96;function wx(e){if(!Number.isFinite(e)||e<0)return"?";const t=["B","KB","MB","GB","TB","PB"];let n=0;for(;e>=1024&&n<t.length-1;)e/=1024,n++;return`${e<10&&n>0?e.toFixed(1):Math.round(e)} ${t[n]}`}const NM=3e5;function kae({socket:e,getToken:t}){const[n,r]=y.useState([]);if(y.useEffect(()=>{t().then(a=>a?fetch("/api/stats",{headers:{Authorization:`Bearer ${a}`}}):null).then(a=>a==null?void 0:a.json()).then(a=>(a==null?void 0:a.samples)&&r(a.samples)).catch(a=>console.warn("[MachineStats] seed failed",a))},[t]),y.useEffect(()=>{if(!e)return;const a=e.on(s=>{s.type==="stats"&&r(c=>[...c,s.sample].slice(-120))});return()=>{a()}},[e]),!n.length)return null;const i=n[n.length-1];return w.jsxs("div",{className:"w-full flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground/60",children:[w.jsx(Hm,{label:"cpu",value:i.cpu,series:n.map(a=>a.cpu)}),w.jsx(Hm,{label:"mem",value:i.mem,series:n.map(a=>a.mem)}),i.disk>=0&&w.jsx(Hm,{label:"disk",value:i.disk,severity:Pae(i.disk),title:jae(i)}),w.jsx(Oae,{getToken:t})]})}function Oae({getToken:e}){const[t,n]=y.useState(null);return y.useEffect(()=>{let r=!0,i=0;const a=async()=>{var f;try{const p=await e();if(!p)return;i=Date.now();const h=await fetch("/api/claude-usage",{headers:{Authorization:`Bearer ${p}`}});if(!r)return;if(h.status===204){n(null);return}if(h.status!==200)return;const m=await h.json();if(!r||!((f=m==null?void 0:m.limits)!=null&&f.length))return;n(m)}catch(p){console.warn("[MachineStats] claude usage poll failed",p)}},s=()=>{document.visibilityState==="visible"&&a()},c=()=>{document.visibilityState==="visible"&&Date.now()-i>=NM&&a()};s();const u=setInterval(s,NM);return document.addEventListener("visibilitychange",c),()=>{r=!1,clearInterval(u),document.removeEventListener("visibilitychange",c)}},[e]),w.jsx(Cae,{usage:t})}function Cae({usage:e}){const t=e&&u$(e.limits),[n,r]=y.useState(Yw),i=y.useRef(null),a=()=>{i.current&&(clearTimeout(i.current),i.current=null)},s=y.useCallback((c,u=0)=>{if(a(),!u){r(f=>IM(f,c));return}i.current=setTimeout(()=>{i.current=null,r(f=>IM(f,c))},u)},[]);return y.useEffect(()=>a,[]),!e||!t?null:w.jsxs(_ae,{open:n.open,onOpenChange:c=>s(c?{type:"activate"}:{type:"dismiss"}),children:[w.jsx(Aae,{asChild:!0,children:w.jsx("button",{type:"button","aria-label":"claude usage breakdown",className:"cursor-default rounded-sm outline-none focus-visible:ring-1 focus-visible:ring-ring",onPointerEnter:c=>s({type:"pointerenter",pointerType:c.pointerType},Tae),onPointerLeave:c=>s({type:"pointerleave",pointerType:c.pointerType},MM),children:w.jsx(Hm,{label:"usage",value:t.percent,severity:t.severity})})}),w.jsx(s$,{onOpenAutoFocus:c=>c.preventDefault(),onPointerEnter:()=>a(),onPointerLeave:c=>s({type:"pointerleave",pointerType:c.pointerType},MM),children:w.jsx(Nae,{usage:e})})]})}const Tae=120,MM=80,Yw={open:!1,byHover:!1};function IM(e,t){switch(t.type){case"pointerenter":return RM(t.pointerType)?{open:!0,byHover:!0}:e;case"pointerleave":return RM(t.pointerType)&&e.byHover?Yw:e;case"activate":return{open:!0,byHover:!1};case"dismiss":return Yw}}const RM=e=>e==="mouse"||e==="";function Nae({usage:e}){const t=u$(e.limits);return w.jsxs("div",{className:"text-[11px] leading-tight",children:[w.jsxs("div",{className:"flex items-baseline justify-between gap-2 pb-2 text-muted-foreground",children:[w.jsx("span",{className:"uppercase tracking-wide",children:"claude usage"}),e.subscriptionType&&w.jsxs("span",{className:"tabular-nums",children:[e.subscriptionType," plan"]})]}),w.jsxs("div",{className:"-mt-1 flex items-baseline justify-between gap-2 pb-2 text-[10px] text-muted-foreground",children:[e.account&&w.jsx("span",{className:"truncate",title:e.account,children:e.account}),w.jsx("span",{className:Ue("shrink-0",e.stale&&"text-amber-500"),children:Iae(e)})]}),e.stale&&e.error&&w.jsxs("div",{"data-refresh-error":!0,className:"-mt-1 pb-2 text-[10px] text-amber-500 break-words",children:[e.error,Um(e.retryAt??null)&&` · retrying in ${Um(e.retryAt??null)}`]}),w.jsx("div",{className:"flex flex-col gap-3",children:e.limits.map((n,r)=>{const i=Um(n.resetsAt),a=n===t;return w.jsxs("div",{"data-headline":a||void 0,className:Ue("flex flex-col gap-1",!a&&"opacity-60"),children:[w.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[w.jsxs("span",{className:Ue("truncate",a&&"font-medium"),children:[a&&w.jsx("span",{className:"mr-1 text-muted-foreground","aria-hidden":!0,children:"▸"}),Mae(n)]}),w.jsxs("span",{className:Ue("tabular-nums shrink-0",Xw(n.percent,n.severity)),children:[n.percent,"%"]})]}),w.jsx(f$,{value:n.percent,className:Ue("w-full",Xw(n.percent,n.severity))}),w.jsx("span",{className:"text-[10px] text-muted-foreground",children:i?`resets in ${i}`:"no reset reported"})]},`${n.kind}-${r}`)})}),w.jsx("div",{className:"mt-3 border-t pt-2 text-[10px] text-muted-foreground",children:"▸ is the window the strip is showing"})]})}function Mae(e){return e.scopeLabel?`${e.scopeLabel} window`:e.kind==="session"?"current session":e.kind==="weekly_all"?"all models":e.kind.replace(/_/g," ")}function u$(e){return e.reduce((t,n)=>!t||n.percent>t.percent?n:t,null)}function Iae(e){const t=Rae(e.fetchedAt);return t?e.stale?`${t} old — refresh failed`:`updated ${t} ago`:e.stale?"last reading — refresh failed":"updated just now"}function Rae(e){if(!e)return null;const t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t))return null;const n=Math.round(Math.max(0,t)/6e4);if(n<1)return null;if(n<60)return`${n}m`;const r=Math.floor(n/60),i=n%60;return r<24?i?`${r}h ${i}m`:`${r}h`:`${Math.floor(r/24)}d`}function Pae(e){return e>=c$?"critical":e>=l$?"warning":"ok"}const Dae={critical:"text-red-500",exceeded:"text-red-500",warning:"text-amber-500",warn:"text-amber-500",ok:"text-emerald-500"};function Xw(e,t){const n=t?Dae[t]:void 0;return n||(e>=90?"text-red-500":e>=75?"text-amber-500":"text-emerald-500")}function jae(e){const t=`warn at ${l$}%, critical at ${c$}%`;if(e.diskUsedBytes==null||e.diskTotalBytes==null)return`disk ${e.disk}% used — ${t}`;const n=Math.max(0,e.diskTotalBytes-e.diskUsedBytes);return`disk ${e.disk}% used — ${wx(e.diskUsedBytes)} of ${wx(e.diskTotalBytes)}, ${wx(n)} free — ${t}`}function Hm({label:e,value:t,series:n,title:r,severity:i}){const a=Xw(t,i),s=r??(n?`${e} ${t}% — last ${n.length} samples`:void 0);return w.jsxs("span",{className:"flex items-center gap-1",title:s,children:[w.jsx("span",{className:"uppercase tracking-wide",children:e}),n?w.jsx(Lae,{series:n,className:a}):w.jsx(f$,{value:t,className:a}),w.jsxs("span",{className:Ue("tabular-nums",a),children:[t,"%"]})]})}function f$({value:e,className:t}){const i=Math.max(0,Math.min(100,e))/100*40;return w.jsxs("svg",{width:40,height:12,viewBox:"0 0 40 12",className:Ue("overflow-visible",t),preserveAspectRatio:"none",children:[w.jsx("rect",{x:0,y:12/2-2,width:40,height:4,rx:2,fill:"currentColor",opacity:.2}),i>0&&w.jsx("rect",{x:0,y:12/2-2,width:i,height:4,rx:2,fill:"currentColor"})]})}function Lae({series:e,className:t}){const i=e.length;if(i<2)return null;const a=e.map((s,c)=>{const u=i>1?c/(i-1)*40:0,f=12-Math.max(0,Math.min(100,s))/100*12;return`${u.toFixed(1)},${f.toFixed(1)}`}).join(" ");return w.jsx("svg",{width:40,height:12,viewBox:"0 0 40 12",className:Ue("overflow-visible",t),preserveAspectRatio:"none",children:w.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}const od=50;function zae({getToken:e,filter:t,refreshKey:n,hydrateIds:r}){const[i,a]=y.useState([]),[s,c]=y.useState(null),[u,f]=y.useState(!1),[p,h]=y.useState({}),m=y.useRef(new Set),v=y.useRef(null),x=y.useRef(null),b=y.useRef(t);b.current=t;const S=y.useRef(od),_=y.useRef(t);_.current!==t&&(_.current=t,S.current=od);const O=y.useCallback(async(P,D)=>{const j=await e();if(!j||D!=null&&D.aborted)return null;const I=await fetch(`/api/sessions?${new URLSearchParams(P)}`,{signal:D,headers:{Authorization:`Bearer ${j}`}});if(!I.ok)return null;const F=await I.json();return Array.isArray(F==null?void 0:F.sessions)?F:null},[e]),k=y.useCallback(async(P,D,j)=>{const I=[];let F,R=null;for(;I.length<P;){const G={filter:D,limit:String(Math.min(od,P-I.length))};F&&(G.before=F);const q=await O(G,j);if(!q)return null;if(I.push(...q.sessions),R=q.nextCursor,!R||!q.sessions.length)break;F=R}return{sessions:I,nextCursor:R}},[O]);y.useEffect(()=>{var D,j;(D=v.current)==null||D.abort(),(j=x.current)==null||j.abort();const P=new AbortController;return v.current=P,f(!0),m.current.clear(),h({}),k(S.current,t,P.signal).then(I=>{!I||P.signal.aborted||(a(I.sessions),c(I.nextCursor))}).catch(()=>{}).finally(()=>{P.signal.aborted||f(!1)}),()=>P.abort()},[k,t,n]);const T=y.useCallback(()=>{var j;if(!s||u)return;(j=x.current)==null||j.abort();const P=new AbortController;x.current=P;const D=b.current;f(!0),O({filter:D,limit:String(od),before:s},P.signal).then(I=>{!I||P.signal.aborted||D!==b.current||(a(F=>{const R=new Set(F.map(q=>q.sessionId)),G=[...F,...I.sessions.filter(q=>!R.has(q.sessionId))];return S.current=Math.max(od,G.length),G}),c(I.nextCursor))}).catch(()=>{}).finally(()=>{P.signal.aborted||f(!1)})},[s,u,O]),C=y.useMemo(()=>{const P=new Map;for(const D of Object.values(p))P.set(D.sessionId,D);for(const D of i)P.set(D.sessionId,D);return P},[i,p]),N=r.join(",");return y.useEffect(()=>{const P=r.filter(j=>!!j&&!C.has(j)&&!m.current.has(j)).slice(0,200);if(!P.length)return;for(const j of P)m.current.add(j);let D=!1;return O({ids:P.join(",")}).then(j=>{!j||D||h(I=>{const F={...I};for(const R of j.sessions)F[R.sessionId]=R;return F})}).catch(()=>{}),()=>{D=!0}},[N,C,O]),{sessions:i,cursor:s,loading:u,byId:C,loadMore:T}}const sd="0.1.110";function $ae(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);if(r<24)return`${r}h ago`;const i=Math.floor(r/24);return i<7?`${i}d ago`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}const ld="w-4 h-4 mt-0.5 shrink-0";function Bae(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?w.jsx(oG,{className:`${ld} text-purple-400`}):(t==null?void 0:t.type)==="mention"?w.jsx(Wq,{className:`${ld} text-blue-400`}):(t==null?void 0:t.type)==="channel"?w.jsx(tG,{className:`${ld} text-green-400`}):e.sessionId.startsWith("slack-")?w.jsx(xw,{className:`${ld} text-yellow-400`}):w.jsx(xw,{className:`${ld} text-muted-foreground`})}function Uae(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?`DM${t.userName?` · ${t.userName}`:""}`:(t==null?void 0:t.type)==="mention"?`@mention${t.channelName?` · #${t.channelName}`:""}`:(t==null?void 0:t.type)==="channel"?`#${t.channelName||"channel"}`:e.sessionId.startsWith("slack-")?"Slack":null}function Fae(e,t,n){return Object.keys(e).map(r=>t.get(r)).filter(r=>!!r&&(n==="all"||r.mine!==!1))}const PM="chats-filter",DM="chats-unread-filter";function Hae({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,unreads:c={},busySessions:u=new Set,socket:f}){var H;const p=_a(),[h,m]=y.useState(()=>localStorage.getItem(PM)||"mine"),[v,x]=y.useState(()=>localStorage.getItem(DM)==="true"),[b,S]=y.useState(""),_=y.useRef(null);function O(Y){m(Y),localStorage.setItem(PM,Y)}function k(){const Y=!v;x(Y),localStorage.setItem(DM,String(Y))}const T=y.useMemo(()=>[t,...Object.keys(c)].filter(Y=>!!Y),[t,c]),{sessions:C,cursor:N,loading:P,byId:D,loadMore:j}=zae({getToken:e,filter:h,refreshKey:i,hydrateIds:T}),I=y.useMemo(()=>Fae(c,D,h),[c,D,h]),F=I.length,R=y.useMemo(()=>v?[...I].sort((Y,z)=>z.lastModified-Y.lastModified):C,[v,I,C]),G=t&&!R.some(Y=>Y.sessionId===t)?D.get(t):void 0;y.useEffect(()=>{_.current&&_.current.scrollIntoView({block:"nearest"})},[t,R,G]);const q=y.useRef(null),K=y.useRef(j);K.current=j,y.useEffect(()=>{const Y=q.current;if(!Y||!N||v)return;const z=new IntersectionObserver($=>{$.some(Z=>Z.isIntersecting)&&K.current()},{rootMargin:"300px"});return z.observe(Y),()=>z.disconnect()},[N,P,v]),y.useEffect(()=>{e().then(Y=>Y?fetch("/api/version",{headers:{Authorization:`Bearer ${Y}`}}):null).then(Y=>Y==null?void 0:Y.json()).then(Y=>Y&&S(Y.version)).catch(()=>{})},[]);const U=!!b&&b!=="unknown"&&sd!=="dev"&&b!==sd;y.useEffect(()=>{U&&console.warn(`[shraga] stale client bundle: built from v${sd}, server runs v${b} — rebuild dist/client`)},[U,b]);function W(Y){const z=c[Y.sessionId],$=u.has(Y.sessionId)||Y.runStatus==="running"||Y.scheduleRunStatus==="running",Z=!$&&(!!Y.lastStopReason||Y.scheduleRunStatus==="error"||Y.scheduleRunStatus==="aborted"),L=$?"border-amber-500":Z?"border-red-500":z?"border-blue-500":"",ae=!!($||Z||z);return w.jsx("button",{ref:Y.sessionId===t?_:void 0,onClick:()=>n(Y.sessionId,Y.title),className:Ue("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",ae?`rounded-r-lg border-l-[3px] ${L}`:"rounded-lg",t===Y.sessionId&&"bg-accent"),children:w.jsxs("div",{className:"flex items-start gap-2",children:[Bae(Y),w.jsxs("div",{className:"min-w-0 flex-1",children:[w.jsx("span",{className:Ue("block truncate text-sm leading-snug",z&&"font-semibold"),children:Y.title||"New session"}),w.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[w.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:Uae(Y)||Y.userName}),w.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),w.jsx("span",{className:"text-[10px] text-muted-foreground",children:$ae(Y.lastModified)})]})]})]})},Y.sessionId)}return w.jsxs("div",{className:"flex flex-col h-full bg-muted/30",children:[w.jsx("div",{className:"p-3",children:w.jsxs(Ne,{variant:"outline",size:"sm",className:"w-full gap-2 justify-start",onClick:r,title:"New Chat (Ctrl+N)",children:[w.jsx(vv,{className:"w-4 h-4"})," New Chat",w.jsx("span",{className:"ml-auto flex items-center gap-0.5 text-[10px] text-muted-foreground/50 font-mono",children:"⌃N"})]})}),w.jsx("div",{className:"border-b shrink-0 flex flex-col max-h-[40vh]",children:w.jsx(jne,{getToken:e,onRefresh:s,refreshKey:a})}),w.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1",children:[w.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Chats"}),w.jsxs("div",{className:"flex gap-0.5",children:[["mine","all"].map(Y=>w.jsx("button",{onClick:()=>O(Y),className:Ue("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",h===Y?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:Y},Y)),w.jsxs("button",{onClick:k,className:Ue("text-[10px] px-1.5 rounded-full transition-colors leading-none",v?"text-blue-600 dark:text-blue-400 font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:["unread",F>0&&w.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),w.jsx(Gj,{className:"flex-1",children:w.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[R.length===0&&!G&&w.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:P?"Loading…":v?"No unread conversations":"No conversations yet"}),G&&W(G),R.map(W),!v&&N&&w.jsx("div",{ref:q,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:P?"Loading older…":"···"})]})}),w.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[w.jsx(kae,{socket:f??null,getToken:e}),(H=p.sidebarExtras)==null?void 0:H.call(p),b&&(U?w.jsxs("button",{onClick:()=>location.reload(),title:`This page was built from v${sd}, the server runs v${b} — reload to update`,className:"text-[10px] text-amber-400 hover:text-amber-300 text-center underline decoration-dotted",children:["⚠️ stale page (v",sd," → v",b,") · reload"]}):w.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",b]}))]})]})}function Yr(e,t){const n=e[e.length-1];if((n==null?void 0:n.role)==="assistant"){if(t.type==="text"||t.type==="thinking"){const r=[...n.blocks],i=r[r.length-1];return(i==null?void 0:i.type)===t.type?(r[r.length-1]={...i,text:i.text+t.text},[...e.slice(0,-1),{...n,blocks:r}]):[...e.slice(0,-1),{...n,blocks:[...r,t]}]}return[...e.slice(0,-1),{...n,blocks:[...n.blocks,t]}]}return[...e,{id:vs(),role:"assistant",blocks:[t]}]}function jM(e,t,n="text"){const r=e[e.length-1],i={type:n,text:t};return(r==null?void 0:r.role)==="assistant"?[...e.slice(0,-1),{...r,blocks:[...r.blocks,i]}]:[...e,{id:vs(),role:"assistant",blocks:[i]}]}function d$(e,t,n){for(let r=e.length-1;r>=0;r--){const i=e[r];if(i.role!=="assistant")continue;const a=i.blocks.findIndex(c=>c.type==="tool_use"&&c.toolUseId===t);if(a===-1)continue;const s=[...i.blocks];return s[a]={...s[a],input:n},[...e.slice(0,r),{...i,blocks:s},...e.slice(r+1)]}return e}function Kae(e,t){const[n,r]=y.useState([]),[i,a]=y.useState(!1),[s,c]=y.useState([]),u=y.useRef(t.initialSessionId),f=y.useRef(!1),p=y.useRef(s);p.current=s;const h=y.useRef(t.getToken);h.current=t.getToken;const m=y.useRef(t.onNewSession);m.current=t.onNewSession;const v=y.useRef(t.onDirectivesChanged);v.current=t.onDirectivesChanged;const x=y.useRef(t.onParticipantsChanged);x.current=t.onParticipantsChanged;const b=y.useRef(t.onEvent);b.current=t.onEvent;const S=y.useRef(e);S.current=e;const _=y.useCallback(R=>R!=null&&R===u.current,[]),O=y.useCallback(async()=>{var G;const R=u.current;if(R)try{const K=await(await wl(`/api/sessions/${R}/messages`,h.current)).json();r(Ej(K)),a(!!K.busy),(G=x.current)==null||G.call(x,Array.isArray(K.participants)&&K.participants.length>1)}catch{}},[]);y.useEffect(()=>{if(!e)return;const R=e.on(G=>{var K,U,W,H,Y,z;(K=b.current)==null||K.call(b,G);const q=G;if(q.type==="compact_marker")return _(q.sessionId)?r($=>[...$,{id:vs(),role:"assistant",blocks:[{type:"compact_marker",summary:q.summary??"",compactedCount:q.compactedCount??0}]}]):void 0;switch(G.type){case"thinking_delta":return _(G.sessionId)?r($=>Yr($,{type:"thinking",text:G.text})):void 0;case"text_delta":return _(G.sessionId)?r($=>Yr($,{type:"text",text:G.text})):void 0;case"tool_use":return _(G.sessionId)?r($=>Yr($,{type:"tool_use",tool:G.tool,toolUseId:G.toolUseId,input:G.input})):void 0;case"tool_use_input":return _(G.sessionId)?r($=>d$($,G.toolUseId,G.input)):void 0;case"tool_result":return _(G.sessionId)?r($=>Yr($,{type:"tool_result",toolUseId:G.toolUseId,output:G.output})):void 0;case"tool_result_image":return _(G.sessionId)?r($=>Yr($,{type:"image",src:G.dataUrl})):void 0;case"permission_request":return _(G.sessionId)?r($=>Yr($,{type:"permission_request",id:G.id,tool:G.tool,input:G.input})):void 0;case"question_request":return _(G.sessionId)?r($=>Yr($,{type:"question_request",id:G.id,questions:G.questions})):void 0;case"directives":return f.current?(U=v.current)==null?void 0:U.call(v,G.directives):void 0;case"session_id":return!f.current||u.current?void 0:(u.current=G.sessionId,(W=m.current)==null?void 0:W.call(m,G.sessionId));case"forked":return G.sourceSessionId!==u.current?void 0:(u.current=G.sessionId,(H=m.current)==null?void 0:H.call(m,G.sessionId));case"session_busy":G.sessionId===u.current&&a(G.busy);return;case"session_stream":return G.sessionId!==u.current?void 0:qae(r,G.event);case"session_messages_changed":G.sessionId===u.current&&O();return;case"done":{if(G.sessionId!==u.current)return;G.stopReason==="max_turns_reached"&&r(Z=>Yr(Z,{type:"text",text:`
1847
+ `)},yne=0,Hc=[];function bne(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),i=y.useState(yne++)[0],a=y.useState(Nz)[0],s=y.useRef(e);y.useEffect(function(){s.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var b=qH([e.lockRef.current],(e.shards||[]).map(dM),!0).filter(Boolean);return b.forEach(function(S){return S.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),b.forEach(function(S){return S.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var c=y.useCallback(function(b,S){if("touches"in b&&b.touches.length===2||b.type==="wheel"&&b.ctrlKey)return!s.current.allowPinchZoom;var _=cm(b),O=n.current,k="deltaX"in b?b.deltaX:O[0]-_[0],T="deltaY"in b?b.deltaY:O[1]-_[1],C,N=b.target,P=Math.abs(k)>Math.abs(T)?"h":"v";if("touches"in b&&P==="h"&&N.type==="range")return!1;var D=window.getSelection(),j=D&&D.anchorNode,I=j?j===N||j.contains(N):!1;if(I)return!1;var F=uM(P,N);if(!F)return!0;if(F?C=P:(C=P==="v"?"h":"v",F=uM(P,N)),!F)return!1;if(!r.current&&"changedTouches"in b&&(k||T)&&(r.current=C),!C)return!0;var R=r.current||C;return mne(R,S,b,R==="h"?k:T)},[]),u=y.useCallback(function(b){var S=b;if(!(!Hc.length||Hc[Hc.length-1]!==a)){var _="deltaY"in S?fM(S):cm(S),O=t.current.filter(function(C){return C.name===S.type&&(C.target===S.target||S.target===C.shadowParent)&&gne(C.delta,_)})[0];if(O&&O.should){S.cancelable&&S.preventDefault();return}if(!O){var k=(s.current.shards||[]).map(dM).filter(Boolean).filter(function(C){return C.contains(S.target)}),T=k.length>0?c(S,k[0]):!s.current.noIsolation;T&&S.cancelable&&S.preventDefault()}}},[]),f=y.useCallback(function(b,S,_,O){var k={name:b,delta:S,target:_,should:O,shadowParent:xne(_)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(T){return T!==k})},1)},[]),p=y.useCallback(function(b){n.current=cm(b),r.current=void 0},[]),h=y.useCallback(function(b){f(b.type,fM(b),b.target,c(b,e.lockRef.current))},[]),m=y.useCallback(function(b){f(b.type,cm(b),b.target,c(b,e.lockRef.current))},[]);y.useEffect(function(){return Hc.push(a),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:m}),document.addEventListener("wheel",u,Fc),document.addEventListener("touchmove",u,Fc),document.addEventListener("touchstart",p,Fc),function(){Hc=Hc.filter(function(b){return b!==a}),document.removeEventListener("wheel",u,Fc),document.removeEventListener("touchmove",u,Fc),document.removeEventListener("touchstart",p,Fc)}},[]);var v=e.removeScrollBar,x=e.inert;return y.createElement(y.Fragment,null,x?y.createElement(a,{styles:vne(i)}):null,v?y.createElement(lne,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function xne(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const wne=Yte(Tz,bne);var GE=y.forwardRef(function(e,t){return y.createElement(Av,oa({},e,{ref:t,sideCar:wne}))});GE.classNames=Av.classNames;var Ene=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Kc=new WeakMap,um=new WeakMap,fm={},px=0,Pz=function(e){return e&&(e.host||Pz(e.parentNode))},Sne=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Pz(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},_ne=function(e,t,n,r){var i=Sne(t,Array.isArray(e)?e:[e]);fm[n]||(fm[n]=new WeakMap);var a=fm[n],s=[],c=new Set,u=new Set(i),f=function(h){!h||c.has(h)||(c.add(h),f(h.parentNode))};i.forEach(f);var p=function(h){!h||u.has(h)||Array.prototype.forEach.call(h.children,function(m){if(c.has(m))p(m);else try{var v=m.getAttribute(r),x=v!==null&&v!=="false",b=(Kc.get(m)||0)+1,S=(a.get(m)||0)+1;Kc.set(m,b),a.set(m,S),s.push(m),b===1&&x&&um.set(m,!0),S===1&&m.setAttribute(n,"true"),x||m.setAttribute(r,"true")}catch(_){console.error("aria-hidden: cannot operate on ",m,_)}})};return p(t),c.clear(),px++,function(){s.forEach(function(h){var m=Kc.get(h)-1,v=a.get(h)-1;Kc.set(h,m),a.set(h,v),m||(um.has(h)||h.removeAttribute(r),um.delete(h)),v||h.removeAttribute(n)}),px--,px||(Kc=new WeakMap,Kc=new WeakMap,um=new WeakMap,fm={})}},Dz=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=Ene(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),_ne(r,i,n,"aria-hidden")):function(){return null}},kv="Dialog",[jz]=Ij(kv),[Ane,Bi]=jz(kv),Lz=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,c=y.useRef(null),u=y.useRef(null),[f,p]=xte({prop:r,defaultProp:i??!1,onChange:a,caller:kv});return w.jsx(Ane,{scope:t,triggerRef:c,contentRef:u,contentId:lx(),titleId:lx(),descriptionId:lx(),open:f,onOpenChange:p,onOpenToggle:y.useCallback(()=>p(h=>!h),[p]),modal:s,children:n})};Lz.displayName=kv;var zz="DialogTrigger",$z=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(zz,n),a=ri(t,i.triggerRef);return w.jsx(Dr.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":ZE(i.open),...r,ref:a,onClick:gr(e.onClick,i.onOpenToggle)})});$z.displayName=zz;var VE="DialogPortal",[kne,Bz]=jz(VE,{forceMount:void 0}),Uz=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Bi(VE,t);return w.jsx(kne,{scope:t,forceMount:n,children:y.Children.map(r,s=>w.jsx(Ds,{present:n||a.open,children:w.jsx(Oz,{asChild:!0,container:i,children:s})}))})};Uz.displayName=VE;var mg="DialogOverlay",WE=y.forwardRef((e,t)=>{const n=Bz(mg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Bi(mg,e.__scopeDialog);return a.modal?w.jsx(Ds,{present:r||a.open,children:w.jsx(Cne,{...i,ref:t})}):null});WE.displayName=mg;var One=wE("DialogOverlay.RemoveScroll"),Cne=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(mg,n),a=Cte(),s=ri(t,a);return w.jsx(GE,{as:One,allowPinchZoom:!0,shards:[i.contentRef],children:w.jsx(Dr.div,{"data-state":ZE(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),_u="DialogContent",YE=y.forwardRef((e,t)=>{const n=Bz(_u,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Bi(_u,e.__scopeDialog);return w.jsx(Ds,{present:r||a.open,children:a.modal?w.jsx(Tne,{...i,ref:t}):w.jsx(Nne,{...i,ref:t})})});YE.displayName=_u;var Tne=y.forwardRef((e,t)=>{const n=Bi(_u,e.__scopeDialog),r=y.useRef(null),i=ri(t,n.contentRef,r);return y.useEffect(()=>{const a=r.current;if(a)return Dz(a)},[]),w.jsx(Fz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:gr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:gr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,c=s.button===0&&s.ctrlKey===!0;(s.button===2||c)&&a.preventDefault()}),onFocusOutside:gr(e.onFocusOutside,a=>a.preventDefault())})}),Nne=y.forwardRef((e,t)=>{const n=Bi(_u,e.__scopeDialog),r=y.useRef(!1),i=y.useRef(!1);return w.jsx(Fz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,c;(s=e.onCloseAutoFocus)==null||s.call(e,a),a.defaultPrevented||(r.current||(c=n.triggerRef.current)==null||c.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var u,f;(u=e.onInteractOutside)==null||u.call(e,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=a.target;((f=n.triggerRef.current)==null?void 0:f.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),Fz=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,c=Bi(_u,n);return Bte(),w.jsx(w.Fragment,{children:w.jsx(Az,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:w.jsx(Sz,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":ZE(c.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Hz="DialogTitle",XE=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(Hz,n);return w.jsx(Dr.h2,{id:i.titleId,...r,ref:t})});XE.displayName=Hz;var Kz="DialogDescription",Mne=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(Kz,n);return w.jsx(Dr.p,{id:i.descriptionId,...r,ref:t})});Mne.displayName=Kz;var qz="DialogClose",Gz=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Bi(qz,n);return w.jsx(Dr.button,{type:"button",...r,ref:t,onClick:gr(e.onClick,()=>i.onOpenChange(!1))})});Gz.displayName=qz;function ZE(e){return e?"open":"closed"}const _s=Lz,uh=$z,Ine=Uz,Vz=y.forwardRef(({className:e,...t},n)=>w.jsx(WE,{ref:n,className:Ue("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Vz.displayName=WE.displayName;const ho=y.forwardRef(({className:e,children:t,...n},r)=>w.jsxs(Ine,{children:[w.jsx(Vz,{}),w.jsxs(YE,{ref:r,className:Ue("fixed left-[50%] top-[50%] z-50 flex flex-col w-[calc(100vw-2rem)] max-w-lg max-h-[85dvh] overflow-y-auto translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-4 sm: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 sm:rounded-lg",e),...n,children:[t,w.jsxs(Gz,{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:[w.jsx(jl,{className:"h-4 w-4"}),w.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ho.displayName=YE.displayName;function zl({className:e,...t}){return w.jsx("div",{className:Ue("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function Wz({className:e,...t}){return w.jsx("div",{"data-dialog-body":!0,className:Ue("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Yz({className:e,...t}){return w.jsx("div",{className:Ue("shrink-0 -mx-4 px-4 pt-3 border-t sm:-mx-6 sm:px-6","flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t})}const As=y.forwardRef(({className:e,...t},n)=>w.jsx(XE,{ref:n,className:Ue("text-lg font-semibold leading-none tracking-tight",e),...t}));As.displayName=XE.displayName;const Rne=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),Pne=new Set(["pdf","mp4","webm","mp3","ogg","wav"]);async function Dne(e,t){const n=await t();if(!n)return[];const r=await fetch(`/api/workspace/ls?path=${encodeURIComponent(e)}`,{headers:{Authorization:`Bearer ${n}`}});return r.ok?(await r.json()).entries??[]:[]}function jne({getToken:e,onRefresh:t,refreshKey:n}){const[r,i]=y.useState(new Map),[a,s]=y.useState(()=>new Set),[c,u]=y.useState(null),[f,p]=y.useState(!1),[h,m]=y.useState("fit"),[v,x]=y.useState(null),[b,S]=y.useState(null),_=y.useRef(null),[O,k]=y.useState(null),[T,C]=y.useState(!1),[N,P]=y.useState([]),D=y.useCallback(async U=>{const W=await Dne(U,e);i(H=>new Map(H).set(U,W))},[e]);y.useEffect(()=>{D(""),a.forEach(U=>D(U))},[D,n]);const j=r.get("")??[],I=y.useCallback(U=>{try{const W=U.contentDocument;if(!(W!=null&&W.body))return;const H=Math.max(W.body.offsetWidth,W.body.scrollWidth),Y=Math.max(W.body.offsetHeight,W.body.scrollHeight);H&&Y&&S({w:H,h:Y})}catch{}},[]),F=y.useCallback(()=>{const U=_.current,W=b;if(!U||!W)return;const H=16,Y=U.clientWidth-H,z=U.clientHeight-H,$=Math.min(Y/W.w,z/W.h,1);x({scale:$,w:W.w,h:W.h})},[b]);y.useEffect(()=>{if(!(c!=null&&c.html)||h!=="fit"){x(null);return}const U=_.current;if(!U)return;const W=new ResizeObserver(()=>requestAnimationFrame(F));return W.observe(U),()=>W.disconnect()},[c==null?void 0:c.html,f,h,F]),y.useEffect(()=>{T&&e().then(U=>{U&&fetch("/api/data-sync/log",{headers:{Authorization:`Bearer ${U}`}}).then(W=>W.json()).then(P).catch(()=>{})})},[T]);const R=U=>{s(W=>{const H=new Set(W);return H.has(U)?H.delete(U):(H.add(U),r.has(U)||D(U)),H})},G=(U,W)=>{const H=new URLSearchParams({path:U});return O&&H.set("token",O),W&&H.set("dl","1"),`/api/workspace/raw?${H}`},q=async U=>{var Y;const W=await e();if(!W)return;k(W);const H=((Y=U.split(".").pop())==null?void 0:Y.toLowerCase())??"";if(H==="html"||H==="htm"){u({path:U,content:"",binary:!1,html:!0});return}if(Rne.has(H)){u({path:U,content:"",binary:!1,image:!0});return}if(Pne.has(H)){u({path:U,content:"",binary:!1,html:!0});return}try{const z=await fetch(`/api/workspace/file?path=${encodeURIComponent(U)}`,{headers:{Authorization:`Bearer ${W}`}});if(!z.ok)return;const $=await z.json();u({path:U,content:$.content,binary:!!$.binary})}catch{}},K=(U,W)=>w.jsx(w.Fragment,{children:U.map(H=>{const Y=H.path.split("/").pop();return w.jsxs("div",{children:[H.type==="dir"?w.jsxs("button",{onClick:()=>R(H.path),className:"w-full flex items-center gap-1 px-2 py-1 rounded hover:bg-accent/50 text-left text-sm",style:{paddingLeft:8+W*12},children:[w.jsx(Ps,{className:Ue("w-3 h-3 shrink-0 transition-transform",a.has(H.path)&&"rotate-90")}),w.jsx(eG,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),w.jsx("span",{className:"truncate",children:Y})]}):w.jsxs("button",{onClick:()=>q(H.path),className:"w-full flex items-center gap-1 px-2 py-1 rounded hover:bg-accent/50 text-left text-sm",style:{paddingLeft:8+W*12+12},title:H.oneLiner||H.path,children:[w.jsx(gE,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),w.jsx("span",{className:"truncate",children:Y})]}),H.type==="dir"&&a.has(H.path)&&K(r.get(H.path)??[],W+1)]},H.path)})});return w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1 shrink-0",children:[w.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Workspace"}),w.jsxs("div",{className:"flex items-center gap-0.5",children:[w.jsx("button",{onClick:()=>C(!0),className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Activity log",children:w.jsx(nG,{className:"w-3 h-3"})}),w.jsx("button",{onClick:()=>{D(""),a.forEach(U=>D(U)),t==null||t()},className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Refresh",children:w.jsx(fG,{className:"w-3 h-3"})})]})]}),w.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:j.length===0?w.jsx("p",{className:"text-xs text-muted-foreground px-3 py-2",children:"Empty. Drop .md files into data/workspace/ or ask the agent to create some."}):K(j,0)}),w.jsx(_s,{open:!!c,onOpenChange:U=>{U||(u(null),p(!1),m("fit"),S(null))},children:w.jsxs(ho,{className:Ue(c!=null&&c.html?Ue("!flex !flex-col !p-0 !gap-0 overflow-hidden",f?"max-w-none w-[100vw] h-[100vh] rounded-none border-0":"max-w-[90vw] w-[90vw] h-[85vh]"):"max-w-3xl max-h-[80vh] !flex !flex-col overflow-hidden"),children:[w.jsxs("div",{className:"absolute right-12 top-4 flex items-center gap-1.5 z-10",children:[(c==null?void 0:c.html)&&w.jsxs(w.Fragment,{children:[w.jsx("button",{onClick:()=>m(U=>U==="fit"?"scroll":"fit"),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:h==="fit"?"Switch to scrollable (1:1)":"Switch to scale-to-fit",children:h==="fit"?w.jsx(sG,{className:"w-4 h-4"}):w.jsx(hG,{className:"w-4 h-4"})}),w.jsx("button",{onClick:()=>p(U=>!U),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:f?"Restore":"Maximize",children:f?w.jsx(yE,{className:"w-4 h-4"}):w.jsx(vE,{className:"w-4 h-4"})})]}),c&&w.jsx("a",{href:G(c.path,!0),download:!0,className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:"Download",children:w.jsx(Oj,{className:"w-4 h-4"})})]}),w.jsx(zl,{className:Ue((c==null?void 0:c.html)&&"px-4 py-3 shrink-0 border-b"),children:w.jsx(As,{className:"font-mono text-sm truncate pr-16",children:c==null?void 0:c.path})}),w.jsx("div",{ref:c!=null&&c.html?_:void 0,className:Ue(c!=null&&c.html?Ue("flex-1 min-h-0 bg-muted/10",h==="fit"?"overflow-hidden flex items-center justify-center":"overflow-auto"):"flex-1 min-h-0 overflow-y-auto"),children:c!=null&&c.html?h==="fit"?w.jsx("div",{style:v?{width:v.w*v.scale,height:v.h*v.scale}:{width:"100%",height:"100%"},children:w.jsx("iframe",{src:G(c.path),className:"border-0 bg-white origin-top-left",title:c.path,onLoad:U=>{I(U.currentTarget),F()},style:v?{width:v.w,height:v.h,transform:`scale(${v.scale})`}:{width:"100%",height:"100%"}})}):w.jsx("iframe",{src:G(c.path),className:"border-0 bg-white mx-auto block",title:c.path,onLoad:U=>I(U.currentTarget),style:{width:(b==null?void 0:b.w)||"100%",height:(b==null?void 0:b.h)||"100%"}}):c!=null&&c.image?w.jsx("div",{className:"flex items-center justify-center p-4",children:w.jsx("img",{src:G(c.path),alt:c.path,className:"max-w-full max-h-[70vh] object-contain"})}):c!=null&&c.binary?w.jsx("p",{className:"text-sm text-muted-foreground",children:"(binary file — preview unavailable)"}):c!=null&&c.path.toLowerCase().endsWith(".md")||c!=null&&c.path.toLowerCase().endsWith(".markdown")?w.jsx("div",{className:"text-sm",children:w.jsx(NL,{remarkPlugins:[ez],rehypePlugins:[Ez],className:"prose prose-sm max-w-none dark:prose-invert prose-pre:bg-muted prose-pre:border prose-code:before:content-none prose-code:after:content-none",children:c.content})}):w.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:c==null?void 0:c.content})})]})}),w.jsx(_s,{open:T,onOpenChange:C,children:w.jsxs(ho,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[w.jsx(zl,{children:w.jsx(As,{className:"text-sm",children:"Activity Log"})}),w.jsxs("div",{className:"overflow-y-auto flex-1 space-y-2",children:[N.map(U=>w.jsxs("div",{className:"border-b border-border/50 pb-2 last:border-0",children:[w.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[w.jsx("span",{className:"text-sm text-foreground",children:U.message}),w.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:Lne(U.date)})]}),U.files.length>0&&w.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:U.files.map(W=>w.jsx("span",{className:"inline-block mr-2 font-mono",children:W},W))})]},U.hash)),N.length===0&&w.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No activity yet"})]})]})})]})}function Lne(e){const t=new Date(e),r=new Date().getTime()-t.getTime(),i=Math.floor(r/6e4);if(i<60)return`${i}m ago`;const a=Math.floor(i/60);return a<24?`${a}h ago`:t.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Um(e,t=Date.now()){if(!e)return null;const n=new Date(e).getTime()-t;if(!Number.isFinite(n)||n<=0)return null;const r=Math.round(n/6e4);if(r<1)return"1m";if(r<60)return`${r}m`;const i=Math.floor(r/60),a=r%60;if(i<48)return a?`${i}h ${a}m`:`${i}h`;const s=Math.floor(i/24),c=i%24;return c?`${s}d ${c}h`:`${s}d`}const zne=/resets\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\s*\(UTC\)/i;function $ne(e,t=Date.now(),n=Date.now()){var h;const r=e.match(zne);if(!r)return e;let i=Number(r[1]);const a=r[2]?Number(r[2]):0,s=(h=r[3])==null?void 0:h.toLowerCase();if(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0),i>23||a>59)return e;const c=new Date(t),u=new Date(Date.UTC(c.getUTCFullYear(),c.getUTCMonth(),c.getUTCDate(),i,a));u.getTime()<=t&&u.setUTCDate(u.getUTCDate()+1);const f=u.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),p=Um(u.toISOString(),n);return e.replace(r[0],`resets ${f}${p?` (in ${p})`:""}`)}var Bne=Object.defineProperty,$u=(e,t)=>Bne(e,"name",{value:t,configurable:!0}),Xz=!!(typeof window<"u"&&window.document&&window.document.createElement);function xs(e,t,{checkForDefaultPrevented:n=!0}={}){return $u(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}$u(xs,"composeEventHandlers");function Une(e){var t;if(!Xz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}$u(Une,"getOwnerWindow");function Dw(e){if(!Xz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}$u(Dw,"getOwnerDocument");function Zz(e,t=!1){const{activeElement:n}=Dw(e);if(!(n!=null&&n.nodeName))return null;if(Qz(n)&&n.contentDocument)return Zz(n.contentDocument.body,t);if(t){const r=n.getAttribute("aria-activedescendant");if(r){const i=Dw(n).getElementById(r);if(i)return i}}return n}$u(Zz,"getActiveElement");function Qz(e){return e.tagName==="IFRAME"}$u(Qz,"isFrame");var Fne=Object.defineProperty,QE=(e,t)=>Fne(e,"name",{value:t,configurable:!0});function jw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}QE(jw,"setRef");function Jz(...e){return t=>{let n=!1;const r=e.map(i=>{const a=jw(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():jw(e[i],null)}}}}QE(Jz,"composeRefs");function Bu(...e){return y.useCallback(Jz(...e),e)}QE(Bu,"useComposedRefs");var Hne=Object.defineProperty,wi=(e,t)=>Hne(e,"name",{value:t,configurable:!0});function Kne(e,t){const n=y.createContext(t);n.displayName=e+"Context";const r=wi(a=>{const{children:s,...c}=a,u=y.useMemo(()=>c,Object.values(c));return w.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:c=!1}=s,u=y.useContext(n);if(u)return u;if(t!==void 0)return t;if(!c)throw new Error(`\`${a}\` must be used within \`${e}\``)}return wi(i,"useContext"),[r,i]}wi(Kne,"createContext");function e3(e,t=[]){let n=[];function r(a,s){const c=y.createContext(s);c.displayName=a+"Context";const u=n.length;n=[...n,s];const f=wi(h=>{var _;const{scope:m,children:v,...x}=h,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useMemo(()=>x,Object.values(x));return w.jsx(b.Provider,{value:S,children:v})},"Provider");f.displayName=a+"Provider";function p(h,m,v={}){var _;const{optional:x=!1}=v,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useContext(b);if(S)return S;if(s!==void 0)return s;if(!x)throw new Error(`\`${h}\` must be used within \`${a}\``)}return wi(p,"useContext"),[f,p]}wi(r,"createContext");const i=wi(()=>{const a=n.map(s=>y.createContext(s));return wi(function(c){const u=(c==null?void 0:c[e])||a;return y.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])},"useScope")},"createScope");return i.scopeName=e,[r,t3(i,...t)]}wi(e3,"createContextScope");function t3(...e){const t=e[0];if(e.length===1)return t;const n=wi(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return wi(function(a){const s=r.reduce((c,{useScope:u,scopeName:f})=>{const h=u(a)[`__scope${f}`];return{...c,...h}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}wi(t3,"composeContextScopes");var qne=Object.defineProperty,Ui=(e,t)=>qne(e,"name",{value:t,configurable:!0});function JE(e){const t=y.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,c=!1;const u=[];Lw(i)&&typeof dm=="function"&&(i=dm(i._payload)),y.Children.forEach(i,m=>{var v;if(a3(m)){c=!0;const x=m;let b="child"in x.props?x.props.child:x.props.children;Lw(b)&&typeof dm=="function"&&(b=dm(b._payload)),s=Vne(x,b),u.push((v=s==null?void 0:s.props)==null?void 0:v.children)}else u.push(m)}),s?s=y.cloneElement(s,void 0,u):!c&&y.Children.count(i)===1&&y.isValidElement(i)&&(s=i);const f=s?i3(s):void 0,p=Bu(r,f);if(!s){if(i||i===0)throw new Error(c?Xne(e):Yne(e));return i}const h=r3(a,s.props??{});return s.type!==y.Fragment&&(h.ref=r?p:f),y.cloneElement(s,h)});return t.displayName=`${e}.Slot`,t}Ui(JE,"createSlot");var n3=Symbol.for("radix.slottable");function Gne(e){const t=Ui(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=n3,t}Ui(Gne,"createSlottable");var Vne=Ui((e,t)=>{if("child"in e.props){const n=e.props.child;return y.isValidElement(n)?y.cloneElement(n,void 0,e.props.children(n.props.children)):null}return y.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function r3(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...c)=>{const u=a(...c);return i(...c),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}Ui(r3,"mergeProps");function i3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Ui(i3,"getElementRef");function a3(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===n3}Ui(a3,"isSlottable");var Wne=Symbol.for("react.lazy");function Lw(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Wne&&"_payload"in e&&o3(e._payload)}Ui(Lw,"isLazyComponent");function o3(e){return typeof e=="object"&&e!==null&&"then"in e}Ui(o3,"isPromiseLike");var Yne=Ui(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Xne=Ui(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),dm=Ea[" use ".trim().toString()],Zne=Object.defineProperty,Qne=(e,t)=>Zne(e,"name",{value:t,configurable:!0}),Jne=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ov=Jne.reduce((e,t)=>{const n=JE(`Primitive.${t}`),r=y.forwardRef((i,a)=>{const{asChild:s,...c}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),w.jsx(u,{...c,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function s3(e,t){e&&Sa.flushSync(()=>e.dispatchEvent(t))}Qne(s3,"dispatchDiscreteCustomEvent");var ere=Object.defineProperty,tre=(e,t)=>ere(e,"name",{value:t,configurable:!0});function Cv(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}tre(Cv,"useCallbackRef");var nre=Object.defineProperty,$n=(e,t)=>nre(e,"name",{value:t,configurable:!0}),zw="dismissableLayer.update",rre="dismissableLayer.pointerDownOutside",ire="dismissableLayer.focusOutside",hM,l3=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),are=y.forwardRef($n(function(t,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:s,onFocusOutside:c,onInteractOutside:u,onDismiss:f,...p}=t,h=y.useContext(l3),[m,v]=y.useState(null),x=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,b]=y.useState({}),S=Bu(n,v),_=Array.from(h.layers),[O]=[...h.layersWithOutsidePointerEventsDisabled].slice(-1),k=O?_.indexOf(O):-1,T=m?_.indexOf(m):-1,C=h.layersWithOutsidePointerEventsDisabled.size>0,N=T>=k,P=y.useRef(!1),D=c3(R=>{s==null||s(R),u==null||u(R),R.defaultPrevented||f==null||f()},{ownerDocument:x,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:P,dismissableSurfaces:h.dismissableSurfaces,shouldHandlePointerDownOutside:y.useCallback(R=>{if(!(R instanceof Node))return!1;const G=[...h.branches].some(q=>q.contains(R));return N&&!G},[h.branches,N])}),j=u3(R=>{if(i&&P.current)return;const G=R.target;[...h.branches].some(K=>K.contains(G))||(c==null||c(R),u==null||u(R),R.defaultPrevented||f==null||f())},x),I=m?T===_.length-1:!1,F=Cv(R=>{R.key==="Escape"&&(a==null||a(R),!R.defaultPrevented&&f&&(R.preventDefault(),f()))});return y.useEffect(()=>{if(I)return x.addEventListener("keydown",F,{capture:!0}),()=>x.removeEventListener("keydown",F,{capture:!0})},[x,I,F]),y.useEffect(()=>{if(m)return r&&(h.layersWithOutsidePointerEventsDisabled.size===0&&(hM=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),h.layersWithOutsidePointerEventsDisabled.add(m)),h.layers.add(m),$w(),()=>{r&&(h.layersWithOutsidePointerEventsDisabled.delete(m),h.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=hM))}},[m,x,r,h]),y.useEffect(()=>()=>{m&&(h.layers.delete(m),h.layersWithOutsidePointerEventsDisabled.delete(m),$w())},[m,h]),y.useEffect(()=>{const R=$n(()=>b({}),"handleUpdate");return document.addEventListener(zw,R),()=>document.removeEventListener(zw,R)},[]),w.jsx(Ov.div,{...p,ref:S,style:{pointerEvents:C?N?"auto":"none":void 0,...t.style},onFocusCapture:xs(t.onFocusCapture,j.onFocusCapture),onBlurCapture:xs(t.onBlurCapture,j.onBlurCapture),onPointerDownCapture:xs(t.onPointerDownCapture,D.onPointerDownCapture)})},"DismissableLayer"));function ore(){const e=y.useContext(l3),[t,n]=y.useState(null);return y.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}$n(ore,"useDismissableLayerSurface");var sre=$n(()=>!0,"IS_TRUE");function c3(e,t){const{ownerDocument:n=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:s=sre}=t,c=Cv(e),u=y.useRef(!1),f=y.useRef(!1),p=y.useRef(new Map),h=y.useRef(()=>{});return y.useEffect(()=>{function m(){f.current=!1,i.current=!1,p.current.clear()}$n(m,"resetOutsideInteraction");function v(){return Array.from(p.current.values()).some(Boolean)}$n(v,"isOutsideInteractionIntercepted");function x(k){if(!f.current)return;const T=k.target;T instanceof Node&&[...a].some(N=>N.contains(T))||p.current.set(k.type,!0),k.type==="click"&&window.setTimeout(()=>{f.current&&h.current()},0)}$n(x,"handleInteractionCapture");function b(k){f.current&&p.current.set(k.type,!1)}$n(b,"handleInteractionBubble");const S=$n(k=>{if(k.target&&!u.current){let T=function(){n.removeEventListener("click",h.current);const N=v();m(),N||eS(rre,c,C,{discrete:!0})};if($n(T,"handleAndDispatchPointerDownOutsideEvent"),!s(k.target)){n.removeEventListener("click",h.current),m(),u.current=!1;return}const C={originalEvent:k};f.current=!0,i.current=r&&k.button===0,p.current.clear(),!r||k.button!==0?T():(n.removeEventListener("click",h.current),h.current=T,n.addEventListener("click",h.current,{once:!0}))}else n.removeEventListener("click",h.current),m();u.current=!1},"handlePointerDown"),_=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const k of _)n.addEventListener(k,x,!0),n.addEventListener(k,b);const O=window.setTimeout(()=>{n.addEventListener("pointerdown",S)},0);return()=>{window.clearTimeout(O),n.removeEventListener("pointerdown",S),n.removeEventListener("click",h.current);for(const k of _)n.removeEventListener(k,x,!0),n.removeEventListener(k,b)}},[n,c,r,i,a,s]),{onPointerDownCapture:$n(()=>u.current=!0,"onPointerDownCapture")}}$n(c3,"usePointerDownOutside");function u3(e,t=globalThis==null?void 0:globalThis.document){const n=Cv(e),r=y.useRef(!1);return y.useEffect(()=>{const i=$n(a=>{a.target&&!r.current&&eS(ire,n,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,n]),{onFocusCapture:$n(()=>r.current=!0,"onFocusCapture"),onBlurCapture:$n(()=>r.current=!1,"onBlurCapture")}}$n(u3,"useFocusOutside");function $w(){const e=new CustomEvent(zw);document.dispatchEvent(e)}$n($w,"dispatchUpdate");function eS(e,t,n,{discrete:r}){const i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?s3(i,a):i.dispatchEvent(a)}$n(eS,"handleAndDispatchCustomEvent");var lre=Object.defineProperty,tS=(e,t)=>lre(e,"name",{value:t,configurable:!0}),hm=0,Zi=null;function cre(e){return nS(),e.children}tS(cre,"FocusGuards");function nS(){y.useEffect(()=>{Zi||(Zi={start:Bw(),end:Bw()});const{start:e,end:t}=Zi;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),hm++,()=>{hm===1&&(Zi==null||Zi.start.remove(),Zi==null||Zi.end.remove(),Zi=null),hm=Math.max(0,hm-1)}},[])}tS(nS,"useFocusGuards");function Bw(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}tS(Bw,"createFocusGuard");var ure=Object.defineProperty,fre=(e,t)=>ure(e,"name",{value:t,configurable:!0});function Uw(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}fre(Uw,"useCallbackRef");var dre=Object.defineProperty,pr=(e,t)=>dre(e,"name",{value:t,configurable:!0}),mx="focusScope.autoFocusOnMount",gx="focusScope.autoFocusOnUnmount",pM={bubbles:!1,cancelable:!0},hre=y.forwardRef(pr(function(t,n){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:s,...c}=t,[u,f]=y.useState(null),p=Uw(a),h=Uw(s),m=y.useRef(null),v=Bu(n,f),x=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(i){let S=function(T){if(x.paused||!u)return;const C=T.target;u.contains(C)?m.current=C:Xa(m.current,{select:!0})},_=function(T){if(x.paused||!u)return;const C=T.relatedTarget;C!==null&&(u.contains(C)||Xa(m.current,{select:!0}))},O=function(T){if(document.activeElement===document.body)for(const N of T)N.removedNodes.length>0&&Xa(u)};pr(S,"handleFocusIn"),pr(_,"handleFocusOut"),pr(O,"handleMutations"),document.addEventListener("focusin",S),document.addEventListener("focusout",_);const k=new MutationObserver(O);return u&&k.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",S),document.removeEventListener("focusout",_),k.disconnect()}}},[i,u,x.paused]),y.useEffect(()=>{if(u){mM.add(x);const S=document.activeElement;if(!u.contains(S)){const O=new CustomEvent(mx,pM);u.addEventListener(mx,p),u.dispatchEvent(O),O.defaultPrevented||(f3(g3(rS(u)),{select:!0}),document.activeElement===S&&Xa(u))}return()=>{u.removeEventListener(mx,p),setTimeout(()=>{const O=new CustomEvent(gx,pM);u.addEventListener(gx,h),u.dispatchEvent(O),O.defaultPrevented||Xa(S??document.body,{select:!0}),u.removeEventListener(gx,h),mM.remove(x)},0)}}},[u,p,h,x]);const b=y.useCallback(S=>{if(!r&&!i||x.paused)return;const _=S.key==="Tab"&&!S.altKey&&!S.ctrlKey&&!S.metaKey,O=document.activeElement;if(_&&O){const k=S.currentTarget,[T,C]=d3(k);T&&C?!S.shiftKey&&O===C?(S.preventDefault(),r&&Xa(T,{select:!0})):S.shiftKey&&O===T&&(S.preventDefault(),r&&Xa(C,{select:!0})):O===k&&S.preventDefault()}},[r,i,x.paused]);return w.jsx(Ov.div,{tabIndex:-1,...c,ref:v,onKeyDown:b})},"FocusScope"));function f3(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Xa(r,{select:t}),document.activeElement!==n)return}pr(f3,"focusFirst");function d3(e){const t=rS(e),n=Fw(t,e),r=Fw(t.reverse(),e);return[n,r]}pr(d3,"getTabbableEdges");function rS(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:pr(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;n.nextNode();)t.push(n.currentNode);return t}pr(rS,"getTabbableCandidates");function Fw(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):h3(r,{upTo:t})))return r}pr(Fw,"findVisible");function h3(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}pr(h3,"isHidden");function p3(e){return e instanceof HTMLInputElement&&"select"in e}pr(p3,"isSelectableInput");function Xa(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&p3(e)&&t&&e.select()}}pr(Xa,"focus");var mM=m3();function m3(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Hw(e,t),e.unshift(t)},remove(t){var n;e=Hw(e,t),(n=e[0])==null||n.resume()}}}pr(m3,"createFocusScopesStack");function Hw(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}pr(Hw,"arrayRemove");function g3(e){return e.filter(t=>t.tagName!=="A")}pr(g3,"removeLinks");var pre=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},mre=Object.defineProperty,gre=(e,t)=>mre(e,"name",{value:t,configurable:!0}),vre=Ea[" useId ".trim().toString()]||(()=>{}),yre=0;function v3(e){const[t,n]=y.useState(vre());return pre(()=>{e||n(r=>r??String(yre++))},[e]),e||(t?`radix-${t}`:"")}gre(v3,"useId");const bre=["top","right","bottom","left"],ks=Math.min,oo=Math.max,gg=Math.round,pm=Math.floor,so=e=>({x:e,y:e}),xre={left:"right",right:"left",bottom:"top",top:"bottom"};function y3(e,t,n){return oo(e,ks(t,n))}function po(e,t){return typeof e=="function"?e(t):e}function Os(e){return e.split("-")[0]}function Uu(e){return e.split("-")[1]}function iS(e){return e==="x"?"y":"x"}function aS(e){return e==="y"?"height":"width"}function sa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function oS(e){return iS(sa(e))}function wre(e,t,n){n===void 0&&(n=!1);const r=Uu(e),i=oS(e),a=aS(i);let s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=vg(s)),[s,vg(s)]}function Ere(e){const t=vg(e);return[Kw(e),t,Kw(t)]}function Kw(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const gM=["left","right"],vM=["right","left"],Sre=["top","bottom"],_re=["bottom","top"];function Are(e,t,n){switch(e){case"top":case"bottom":return n?t?vM:gM:t?gM:vM;case"left":case"right":return t?Sre:_re;default:return[]}}function kre(e,t,n,r){const i=Uu(e);let a=Are(Os(e),n==="start",r);return i&&(a=a.map(s=>s+"-"+i),t&&(a=a.concat(a.map(Kw)))),a}function vg(e){const t=Os(e);return xre[t]+e.slice(t.length)}function Ore(e){var t,n,r,i;return{top:(t=e.top)!=null?t:0,right:(n=e.right)!=null?n:0,bottom:(r=e.bottom)!=null?r:0,left:(i=e.left)!=null?i:0}}function b3(e){return typeof e!="number"?Ore(e):{top:e,right:e,bottom:e,left:e}}function yg(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function yM(e,t,n){let{reference:r,floating:i}=e;const a=sa(t),s=oS(t),c=aS(s),u=Os(t),f=a==="y",p=r.x+r.width/2-i.width/2,h=r.y+r.height/2-i.height/2,m=r[c]/2-i[c]/2;let v;switch(u){case"top":v={x:p,y:r.y-i.height};break;case"bottom":v={x:p,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:h};break;case"left":v={x:r.x-i.width,y:h};break;default:v={x:r.x,y:r.y}}const x=Uu(t);return x&&(v[s]+=m*(x==="end"?1:-1)*(n&&f?-1:1)),v}async function Cre(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:s,elements:c,strategy:u}=e,{boundary:f="clippingAncestors",rootBoundary:p="viewport",elementContext:h="floating",altBoundary:m=!1,padding:v=0}=po(t,e),x=b3(v),S=c[m?h==="floating"?"reference":"floating":h],_=yg(await a.getClippingRect({element:(n=await(a.isElement==null?void 0:a.isElement(S)))==null||n?S:S.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(c.floating)),boundary:f,rootBoundary:p,strategy:u})),O=h==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,k=await(a.getOffsetParent==null?void 0:a.getOffsetParent(c.floating)),T=await(a.isElement==null?void 0:a.isElement(k))&&await(a.getScale==null?void 0:a.getScale(k))||{x:1,y:1},C=yg(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:O,offsetParent:k,strategy:u}):O);return{top:(_.top-C.top+x.top)/T.y,bottom:(C.bottom-_.bottom+x.bottom)/T.y,left:(_.left-C.left+x.left)/T.x,right:(C.right-_.right+x.right)/T.x}}const Tre=50,Nre=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:s}=n,c=s.detectOverflow?s:{...s,detectOverflow:Cre},u=await(s.isRTL==null?void 0:s.isRTL(t));let f=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:p,y:h}=yM(f,r,u),m=r,v=0;const x={};for(let b=0;b<a.length;b++){const S=a[b];if(!S)continue;const{name:_,fn:O}=S,{x:k,y:T,data:C,reset:N}=await O({x:p,y:h,initialPlacement:r,placement:m,strategy:i,middlewareData:x,rects:f,platform:c,elements:{reference:e,floating:t}});p=k??p,h=T??h,x[_]={...x[_],...C},N&&v<Tre&&(v++,typeof N=="object"&&(N.placement&&(m=N.placement),N.rects&&(f=N.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:i}):N.rects),{x:p,y:h}=yM(f,m,u)),b=-1)}return{x:p,y:h,placement:m,strategy:i,middlewareData:x}},Mre=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:a,platform:s,elements:c,middlewareData:u}=t,{element:f,padding:p=0}=po(e,t)||{};if(f==null)return{};const h=b3(p),m={x:n,y:r},v=oS(i),x=aS(v),b=await s.getDimensions(f),S=v==="y",_=S?"top":"left",O=S?"bottom":"right",k=S?"clientHeight":"clientWidth",T=a.reference[x]+a.reference[v]-m[v]-a.floating[x],C=m[v]-a.reference[v],N=await(s.getOffsetParent==null?void 0:s.getOffsetParent(f));let P=N?N[k]:0;(!P||!await(s.isElement==null?void 0:s.isElement(N)))&&(P=c.floating[k]||a.floating[x]);const D=T/2-C/2,j=P/2-b[x]/2-1,I=ks(h[_],j),F=ks(h[O],j),R=P-b[x]-F,G=P/2-b[x]/2+D,q=y3(I,G,R),K=!u.arrow&&Uu(i)!=null&&G!==q&&a.reference[x]/2-(G<I?I:F)-b[x]/2<0,U=K?G<I?G-I:G-R:0;return{[v]:m[v]+U,data:{[v]:q,centerOffset:G-q-U,...K&&{alignmentOffset:U}},reset:K}}}),Ire=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:a,rects:s,initialPlacement:c,platform:u,elements:f}=t,{mainAxis:p=!0,crossAxis:h=!0,fallbackPlacements:m,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:b=!0,...S}=po(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=Os(i),O=sa(c),k=Os(c)===c,T=await(u.isRTL==null?void 0:u.isRTL(f.floating)),C=m||(k||!b?[vg(c)]:Ere(c)),N=x!=="none";!m&&N&&C.push(...kre(c,b,x,T));const P=[c,...C],D=await u.detectOverflow(t,S),j=[];let I=((r=a.flip)==null?void 0:r.overflows)||[];if(p&&j.push(D[_]),h){const q=wre(i,s,T);j.push(D[q[0]],D[q[1]])}if(I=[...I,{placement:i,overflows:j}],!j.every(q=>q<=0)){var F,R;const q=(((F=a.flip)==null?void 0:F.index)||0)+1,K=P[q];if(K&&(!(h==="alignment"?O!==sa(K):!1)||I.every(H=>sa(H.placement)===O?H.overflows[0]>0:!0)))return{data:{index:q,overflows:I},reset:{placement:K}};let U=(R=I.filter(W=>W.overflows[0]<=0).sort((W,H)=>W.overflows[1]-H.overflows[1])[0])==null?void 0:R.placement;if(!U)switch(v){case"bestFit":{var G;const W=(G=I.filter(H=>{if(N){const Y=sa(H.placement);return Y===O||Y==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(Y=>Y>0).reduce((Y,z)=>Y+z,0)]).sort((H,Y)=>H[1]-Y[1])[0])==null?void 0:G[0];W&&(U=W);break}case"initialPlacement":U=c;break}if(i!==U)return{reset:{placement:U}}}return{}}}};function bM(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function xM(e){return bre.some(t=>e[t]>=0)}const Rre=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...a}=po(e,t);switch(i){case"referenceHidden":{const s=await r.detectOverflow(t,{...a,elementContext:"reference"}),c=bM(s,n.reference);return{data:{referenceHiddenOffsets:c,referenceHidden:xM(c)}}}case"escaped":{const s=await r.detectOverflow(t,{...a,altBoundary:!0}),c=bM(s,n.floating);return{data:{escapedOffsets:c,escaped:xM(c)}}}default:return{}}}}},x3=new Set(["left","top"]);async function Pre(e,t){const{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=Os(n),c=Uu(n),u=sa(n)==="y",f=x3.has(s)?-1:1,p=a&&u?-1:1,h=po(t,e);let{mainAxis:m,crossAxis:v,alignmentAxis:x}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return c&&typeof x=="number"&&(v=c==="end"?x*-1:x),u?{x:v*p,y:m*f}:{x:m*f,y:v*p}}const Dre=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:a,placement:s,middlewareData:c}=t,u=await Pre(t,e);return s===((n=c.offset)==null?void 0:n.placement)&&(r=c.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:a+u.y,data:{...u,placement:s}}}}},jre=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:a}=t,{mainAxis:s=!0,crossAxis:c=!1,limiter:u={fn:O=>{let{x:k,y:T}=O;return{x:k,y:T}}},...f}=po(e,t),p={x:n,y:r},h=await a.detectOverflow(t,f),m=sa(i),v=iS(m);let x=p[v],b=p[m];const S=(O,k)=>y3(k+h[O==="y"?"top":"left"],k,k-h[O==="y"?"bottom":"right"]);s&&(x=S(v,x)),c&&(b=S(m,b));const _=u.fn({...t,[v]:x,[m]:b});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[v]:s,[m]:c}}}}}},Lre=function(e){return e===void 0&&(e={}),{options:e,fn(t){var n,r;const{x:i,y:a,placement:s,rects:c,middlewareData:u}=t,{offset:f=0,mainAxis:p=!0,crossAxis:h=!0}=po(e,t),m={x:i,y:a},v=sa(s),x=iS(v);let b=m[x],S=m[v];const _=po(f,t),O=typeof _=="number"?{mainAxis:_,crossAxis:0}:{mainAxis:(n=_.mainAxis)!=null?n:0,crossAxis:(r=_.crossAxis)!=null?r:0};if(p){const C=x==="y"?"height":"width",N=c.reference[x]-c.floating[C]+O.mainAxis,P=c.reference[x]+c.reference[C]-O.mainAxis;b<N?b=N:b>P&&(b=P)}if(h){var k,T;const C=x==="y"?"width":"height",N=x3.has(Os(s)),P=c.reference[v]-c.floating[C]+(N&&((k=u.offset)==null?void 0:k[v])||0)+(N?0:O.crossAxis),D=c.reference[v]+c.reference[C]+(N?0:((T=u.offset)==null?void 0:T[v])||0)-(N?O.crossAxis:0);S<P?S=P:S>D&&(S=D)}return{[x]:b,[v]:S}}}},zre=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:n,rects:r,platform:i,elements:a}=t,{apply:s=()=>{},...c}=po(e,t),u=await i.detectOverflow(t,c),f=Os(n),p=Uu(n),h=sa(n)==="y",{width:m,height:v}=r.floating;let x,b;f==="top"||f==="bottom"?(x=f,b=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(b=f,x=p==="end"?"top":"bottom");const S=v-u.top-u.bottom,_=m-u.left-u.right,O=ks(v-u[x],S),k=ks(m-u[b],_),T=t.middlewareData.shift,C=!T;let N=O,P=k;T!=null&&T.enabled.x&&(P=_),T!=null&&T.enabled.y&&(N=S),C&&!p&&(h?P=m-2*oo(u.left,u.right):N=v-2*oo(u.top,u.bottom)),await s({...t,availableWidth:P,availableHeight:N});const D=await i.getDimensions(a.floating);return m!==D.width||v!==D.height?{reset:{rects:!0}}:{}}}};function Tv(){return typeof window<"u"}function Fu(e){return w3(e)?(e.nodeName||"").toLowerCase():"#document"}function Pr(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function wo(e){var t;return(t=(w3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function w3(e){return Tv()?e instanceof Node||e instanceof Pr(e).Node:!1}function ma(e){return Tv()?e instanceof Element||e instanceof Pr(e).Element:!1}function Ls(e){return Tv()?e instanceof HTMLElement||e instanceof Pr(e).HTMLElement:!1}function wM(e){return!Tv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Pr(e).ShadowRoot}function Nv(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=ga(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function $re(e){return/^(table|td|th)$/.test(Fu(e))}function Mv(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Bre=/transform|translate|scale|rotate|perspective|filter/,Ure=/paint|layout|strict|content/,ul=e=>!!e&&e!=="none";let vx;function sS(e){const t=ma(e)?ga(e):e;return ul(t.transform)||ul(t.translate)||ul(t.scale)||ul(t.rotate)||ul(t.perspective)||!lS()&&(ul(t.backdropFilter)||ul(t.filter))||Bre.test(t.willChange||"")||Ure.test(t.contain||"")}function Fre(e){let t=$l(e);for(;Ls(t)&&!zd(t);){if(sS(t))return t;if(Mv(t))return null;t=$l(t)}return null}function lS(){return vx==null&&(vx=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),vx}function zd(e){return/^(html|body|#document)$/.test(Fu(e))}function ga(e){return Pr(e).getComputedStyle(e)}function Iv(e){return ma(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $l(e){if(Fu(e)==="html")return e;const t=e.assignedSlot||e.parentNode||wM(e)&&e.host||wo(e);return wM(t)?t.host:t}function E3(e){const t=$l(e);return zd(t)?(e.ownerDocument||e).body:Ls(t)&&Nv(t)?t:E3(t)}function $d(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=E3(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=Pr(i);if(a){const c=qw(s);return t.concat(s,s.visualViewport||[],Nv(i)?i:[],c&&n?$d(c):[])}else return t.concat(i,$d(i,[],n))}function qw(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function S3(e){const t=ga(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ls(e),a=i?e.offsetWidth:n,s=i?e.offsetHeight:r,c=gg(n)!==a||gg(r)!==s;return c&&(n=a,r=s),{width:n,height:r,$:c}}function cS(e){return ma(e)?e:e.contextElement}function pu(e){const t=cS(e);if(!Ls(t))return so(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=S3(t);let s=(a?gg(n.width):n.width)/r,c=(a?gg(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}const Hre=so(0);function _3(e){const t=Pr(e);return!lS()||!t.visualViewport?Hre:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Kre(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Pr(e)}function Bl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=cS(e);let s=so(1);t&&(r?ma(r)&&(s=pu(r)):s=pu(e));const c=Kre(a,n,r)?_3(a):so(0);let u=(i.left+c.x)/s.x,f=(i.top+c.y)/s.y,p=i.width/s.x,h=i.height/s.y;if(a&&r){const m=Pr(a),v=ma(r)?Pr(r):r;let x=m,b=qw(x);for(;b&&v!==x;){const S=pu(b),_=b.getBoundingClientRect(),O=ga(b),k=_.left+(b.clientLeft+parseFloat(O.paddingLeft))*S.x,T=_.top+(b.clientTop+parseFloat(O.paddingTop))*S.y;u*=S.x,f*=S.y,p*=S.x,h*=S.y,u+=k,f+=T,x=Pr(b),b=qw(x)}}return yg({width:p,height:h,x:u,y:f})}function Rv(e,t){const n=Iv(e).scrollLeft;return t?t.left+n:Bl(wo(e)).left+n}function A3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Rv(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function qre(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const a=i==="fixed",s=wo(r),c=t?Mv(t.floating):!1;if(r===s||c&&a)return n;let u={scrollLeft:0,scrollTop:0},f=so(1);const p=so(0),h=Ls(r);if((h||!a)&&((Fu(r)!=="body"||Nv(s))&&(u=Iv(r)),h)){const v=Bl(r);f=pu(r),p.x=v.x+r.clientLeft,p.y=v.y+r.clientTop}const m=s&&!h&&!a?A3(s,u):so(0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-u.scrollLeft*f.x+p.x+m.x,y:n.y*f.y-u.scrollTop*f.y+p.y+m.y}}function Gre(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Vre(e){const t=Iv(e),n=e.ownerDocument.body,r=oo(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=oo(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+Rv(e);const s=-t.scrollTop;return ga(n).direction==="rtl"&&(a+=oo(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:s}}const Wre=25;function Yre(e,t,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",i=Pr(e),a=wo(e),s=i.visualViewport;let c=a.clientWidth,u=a.clientHeight,f=0,p=0;if(s){const m=!lS()||t==="fixed";r?m||(f=-s.offsetLeft,p=-s.offsetTop):(c=s.width,u=s.height,m&&(f=s.offsetLeft,p=s.offsetTop))}if(Rv(a)<=0){const m=a.ownerDocument,v=m.body,x=getComputedStyle(v),b=m.compatMode==="CSS1Compat"&&parseFloat(x.marginLeft)+parseFloat(x.marginRight)||0,S=Math.abs(a.clientWidth-v.clientWidth-b),_=getComputedStyle(a).scrollbarGutter==="stable both-edges"?S/2:S;_<=Wre&&(c-=_)}return{width:c,height:u,x:f,y:p}}function Xre(e,t){const n=Bl(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=pu(e),s=e.clientWidth*a.x,c=e.clientHeight*a.y,u=i*a.x,f=r*a.y;return{width:s,height:c,x:u,y:f}}function EM(e,t,n){let r;if(t==="viewport"||t==="layoutViewport")r=Yre(e,n,t);else if(t==="document")r=Vre(wo(e));else if(ma(t))r=Xre(t,n);else{const i=_3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return yg(r)}function Zre(e,t){const n=t.get(e);if(n)return n;let r=$d(e,[],!1).filter(c=>ma(c)&&Fu(c)!=="body"),i=null;const a=ga(e).position==="fixed";let s=a?$l(e):e;for(;ma(s)&&!zd(s);){const c=ga(s),u=sS(s),f=i?i.position:a?"fixed":"";!u&&(f==="fixed"||f==="absolute"&&c.position==="static")?r=r.filter(h=>h!==s):i=c,s=$l(s)}return t.set(e,r),r}function Qre(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const s=[...n==="clippingAncestors"?Mv(t)?[]:Zre(t,this._c):[].concat(n),r],c=EM(t,s[0],i);let u=c.top,f=c.right,p=c.bottom,h=c.left;for(let m=1;m<s.length;m++){const v=EM(t,s[m],i);u=oo(v.top,u),f=ks(v.right,f),p=ks(v.bottom,p),h=oo(v.left,h)}return{width:f-h,height:p-u,x:h,y:u}}function Jre(e){const{width:t,height:n}=S3(e);return{width:t,height:n}}function eie(e,t,n){const r=Ls(t),i=wo(t),a=n==="fixed",s=Bl(e,!0,a,t);let c={scrollLeft:0,scrollTop:0};const u=so(0);if((r||!a)&&((Fu(t)!=="body"||Nv(i))&&(c=Iv(t)),r)){const m=Bl(t,!0,a,t);u.x=m.x+t.clientLeft,u.y=m.y+t.clientTop}!r&&i&&(u.x=Rv(i));const f=i&&!r&&!a?A3(i,c):so(0),p=s.left+c.scrollLeft-u.x-f.x,h=s.top+c.scrollTop-u.y-f.y;return{x:p,y:h,width:s.width,height:s.height}}function yx(e){return ga(e).position==="static"}function SM(e,t){if(!Ls(e)||ga(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return wo(e)===n&&(n=n.ownerDocument.body),n}function k3(e,t){const n=Pr(e);if(Mv(e))return n;if(!Ls(e)){let i=$l(e);for(;i&&!zd(i);){if(ma(i)&&!yx(i))return i;i=$l(i)}return n}let r=SM(e,t);for(;r&&$re(r)&&yx(r);)r=SM(r,t);return r&&zd(r)&&yx(r)&&!sS(r)?n:r||Fre(e)||n}const tie=async function(e){const t=this.getOffsetParent||k3,n=this.getDimensions,r=await n(e.floating);return{reference:eie(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function nie(e){return ga(e).direction==="rtl"}const rie={convertOffsetParentRelativeRectToViewportRelativeRect:qre,getDocumentElement:wo,getClippingRect:Qre,getOffsetParent:k3,getElementRects:tie,getClientRects:Gre,getDimensions:Jre,getScale:pu,isElement:ma,isRTL:nie};function O3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function iie(e,t,n){let r=null,i;const a=wo(e);function s(){var p;clearTimeout(i),(p=r)==null||p.disconnect(),r=null}function c(p,h){p===void 0&&(p=!1),h===void 0&&(h=1),s();const m=e.getBoundingClientRect(),{left:v,top:x,width:b,height:S}=m;if(p||t(),!b||!S)return;const _=pm(x),O=pm(a.clientWidth-(v+b)),k=pm(a.clientHeight-(x+S)),T=pm(v),N={rootMargin:-_+"px "+-O+"px "+-k+"px "+-T+"px",threshold:oo(0,ks(1,h))||1};let P=!0;function D(j){const I=j[0].intersectionRatio;if(!O3(m,e.getBoundingClientRect()))return c();if(I!==h){if(!P)return c();I?c(!1,I):i=setTimeout(()=>{c(!1,1e-7)},1e3)}P=!1}try{r=new IntersectionObserver(D,{...N,root:a.ownerDocument})}catch{r=new IntersectionObserver(D,N)}r.observe(e)}const u=Pr(e),f=()=>c(n);return u.addEventListener("resize",f),c(!0),()=>{u.removeEventListener("resize",f),s()}}function aie(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,f=cS(e),p=i||a?[...f?$d(f):[],...t?$d(t):[]]:[];p.forEach(_=>{i&&_.addEventListener("scroll",n),a&&_.addEventListener("resize",n)});const h=f&&c?iie(f,n,a):null;let m=-1,v=null;s&&(v=new ResizeObserver(_=>{let[O]=_;O&&O.target===f&&v&&t&&(v.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var k;(k=v)==null||k.observe(t)})),n()}),f&&!u&&v.observe(f),t&&v.observe(t));let x,b=u?Bl(e):null;u&&S();function S(){const _=Bl(e);b&&!O3(b,_)&&n(),b=_,x=requestAnimationFrame(S)}return n(),()=>{var _;p.forEach(O=>{i&&O.removeEventListener("scroll",n),a&&O.removeEventListener("resize",n)}),h==null||h(),(_=v)==null||_.disconnect(),v=null,u&&cancelAnimationFrame(x)}}const oie=Dre,sie=jre,lie=Ire,cie=zre,uie=Rre,_M=Mre,fie=Lre,die=(e,t,n)=>{const r=new Map,i=n??{},a={...rie,...i.platform,_c:r};return Nre(e,t,{...i,platform:a})};var hie=typeof document<"u",pie=function(){},Fm=hie?y.useLayoutEffect:pie;function bg(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!bg(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const a=i[r];if(!(a==="_owner"&&e.$$typeof)&&!bg(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function C3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function AM(e,t){const n=C3(e);return Math.round(t*n)/n}function bx(e){const t=y.useRef(e);return Fm(()=>{t.current=e}),t}function mie(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:s}={},transform:c=!0,whileElementsMounted:u,open:f}=e,[p,h]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,v]=y.useState(r);bg(m,r)||v(r);const[x,b]=y.useState(null),[S,_]=y.useState(null),O=y.useCallback(H=>{H!==N.current&&(N.current=H,b(H))},[]),k=y.useCallback(H=>{H!==P.current&&(P.current=H,_(H))},[]),T=a||x,C=s||S,N=y.useRef(null),P=y.useRef(null),D=y.useRef(p),j=u!=null,I=bx(u),F=bx(i),R=bx(f),G=y.useCallback(()=>{if(!N.current||!P.current)return;const H={placement:t,strategy:n,middleware:m};F.current&&(H.platform=F.current),die(N.current,P.current,H).then(Y=>{const z={...Y,isPositioned:R.current!==!1};q.current&&!bg(D.current,z)&&(D.current=z,Sa.flushSync(()=>{h(z)}))})},[m,t,n,F,R]);Fm(()=>{f===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,h(H=>({...H,isPositioned:!1})))},[f]);const q=y.useRef(!1);Fm(()=>(q.current=!0,()=>{q.current=!1}),[]),Fm(()=>{if(T&&(N.current=T),C&&(P.current=C),T&&C){if(I.current)return I.current(T,C,G);G()}},[T,C,G,I,j]);const K=y.useMemo(()=>({reference:N,floating:P,setReference:O,setFloating:k}),[O,k]),U=y.useMemo(()=>({reference:T,floating:C}),[T,C]),W=y.useMemo(()=>{const H={position:n,left:0,top:0};if(!U.floating)return H;const Y=AM(U.floating,p.x),z=AM(U.floating,p.y);return c?{...H,transform:"translate("+Y+"px, "+z+"px)",...C3(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Y,top:z}},[n,c,U.floating,p.x,p.y]);return y.useMemo(()=>({...p,update:G,refs:K,elements:U,floatingStyles:W}),[p,G,K,U,W])}const gie=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?_M({element:r.current,padding:i}).fn(n):{}:r?_M({element:r,padding:i}).fn(n):{}}}},vie=(e,t)=>{const n=oie(e);return{name:n.name,fn:n.fn,options:[e,t]}},yie=(e,t)=>{const n=sie(e);return{name:n.name,fn:n.fn,options:[e,t]}},bie=(e,t)=>({fn:fie(e).fn,options:[e,t]}),xie=(e,t)=>{const n=lie(e);return{name:n.name,fn:n.fn,options:[e,t]}},wie=(e,t)=>{const n=cie(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eie=(e,t)=>{const n=uie(e);return{name:n.name,fn:n.fn,options:[e,t]}},Sie=(e,t)=>{const n=gie(e);return{name:n.name,fn:n.fn,options:[e,t]}};var _ie=Object.defineProperty,uS=(e,t)=>_ie(e,"name",{value:t,configurable:!0});function Gw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}uS(Gw,"setRef");function T3(...e){return t=>{let n=!1;const r=e.map(i=>{const a=Gw(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():Gw(e[i],null)}}}}uS(T3,"composeRefs");function Pv(...e){return y.useCallback(T3(...e),e)}uS(Pv,"useComposedRefs");var Aie=Object.defineProperty,Ei=(e,t)=>Aie(e,"name",{value:t,configurable:!0});function kie(e,t){const n=y.createContext(t);n.displayName=e+"Context";const r=Ei(a=>{const{children:s,...c}=a,u=y.useMemo(()=>c,Object.values(c));return w.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:c=!1}=s,u=y.useContext(n);if(u)return u;if(t!==void 0)return t;if(!c)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ei(i,"useContext"),[r,i]}Ei(kie,"createContext");function N3(e,t=[]){let n=[];function r(a,s){const c=y.createContext(s);c.displayName=a+"Context";const u=n.length;n=[...n,s];const f=Ei(h=>{var _;const{scope:m,children:v,...x}=h,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useMemo(()=>x,Object.values(x));return w.jsx(b.Provider,{value:S,children:v})},"Provider");f.displayName=a+"Provider";function p(h,m,v={}){var _;const{optional:x=!1}=v,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useContext(b);if(S)return S;if(s!==void 0)return s;if(!x)throw new Error(`\`${h}\` must be used within \`${a}\``)}return Ei(p,"useContext"),[f,p]}Ei(r,"createContext");const i=Ei(()=>{const a=n.map(s=>y.createContext(s));return Ei(function(c){const u=(c==null?void 0:c[e])||a;return y.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])},"useScope")},"createScope");return i.scopeName=e,[r,M3(i,...t)]}Ei(N3,"createContextScope");function M3(...e){const t=e[0];if(e.length===1)return t;const n=Ei(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ei(function(a){const s=r.reduce((c,{useScope:u,scopeName:f})=>{const h=u(a)[`__scope${f}`];return{...c,...h}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ei(M3,"composeContextScopes");var Oie=Object.defineProperty,Fi=(e,t)=>Oie(e,"name",{value:t,configurable:!0});function I3(e){const t=y.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,c=!1;const u=[];Vw(i)&&typeof mm=="function"&&(i=mm(i._payload)),y.Children.forEach(i,m=>{var v;if(j3(m)){c=!0;const x=m;let b="child"in x.props?x.props.child:x.props.children;Vw(b)&&typeof mm=="function"&&(b=mm(b._payload)),s=Tie(x,b),u.push((v=s==null?void 0:s.props)==null?void 0:v.children)}else u.push(m)}),s?s=y.cloneElement(s,void 0,u):!c&&y.Children.count(i)===1&&y.isValidElement(i)&&(s=i);const f=s?D3(s):void 0,p=Pv(r,f);if(!s){if(i||i===0)throw new Error(c?Iie(e):Mie(e));return i}const h=P3(a,s.props??{});return s.type!==y.Fragment&&(h.ref=r?p:f),y.cloneElement(s,h)});return t.displayName=`${e}.Slot`,t}Fi(I3,"createSlot");var R3=Symbol.for("radix.slottable");function Cie(e){const t=Fi(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=R3,t}Fi(Cie,"createSlottable");var Tie=Fi((e,t)=>{if("child"in e.props){const n=e.props.child;return y.isValidElement(n)?y.cloneElement(n,void 0,e.props.children(n.props.children)):null}return y.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function P3(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...c)=>{const u=a(...c);return i(...c),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}Fi(P3,"mergeProps");function D3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Fi(D3,"getElementRef");function j3(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===R3}Fi(j3,"isSlottable");var Nie=Symbol.for("react.lazy");function Vw(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Nie&&"_payload"in e&&L3(e._payload)}Fi(Vw,"isLazyComponent");function L3(e){return typeof e=="object"&&e!==null&&"then"in e}Fi(L3,"isPromiseLike");var Mie=Fi(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Iie=Fi(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),mm=Ea[" use ".trim().toString()],Rie=Object.defineProperty,Pie=(e,t)=>Rie(e,"name",{value:t,configurable:!0}),Die=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],z3=Die.reduce((e,t)=>{const n=I3(`Primitive.${t}`),r=y.forwardRef((i,a)=>{const{asChild:s,...c}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),w.jsx(u,{...c,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function jie(e,t){e&&Sa.flushSync(()=>e.dispatchEvent(t))}Pie(jie,"dispatchDiscreteCustomEvent");var Lie=Object.defineProperty,zie=(e,t)=>Lie(e,"name",{value:t,configurable:!0});function $3(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}zie($3,"useCallbackRef");var xx=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},$ie=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},Bie=Object.defineProperty,Uie=(e,t)=>Bie(e,"name",{value:t,configurable:!0});function B3(e){const[t,n]=y.useState(void 0);return $ie(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let s,c;if("borderBoxSize"in a){const u=a.borderBoxSize,f=Array.isArray(u)?u[0]:u;s=f.inlineSize,c=f.blockSize}else s=e.offsetWidth,c=e.offsetHeight;n({width:s,height:c})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}Uie(B3,"useSize");var Fie=Object.defineProperty,ws=(e,t)=>Fie(e,"name",{value:t,configurable:!0}),U3="Popper",[F3,H3]=N3(U3),[Hie,K3]=F3(U3),Kie=ws(e=>{const{__scopePopper:t,children:n}=e,[r,i]=y.useState(null),[a,s]=y.useState(void 0);return w.jsx(Hie,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:s,children:n})},"Popper"),qie="PopperAnchor",Gie=y.forwardRef(ws(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=K3(qie,r),c=y.useRef(null),u=s.onAnchorChange,f=y.useCallback(b=>{c.current=b,b&&u(b)},[u]),p=Pv(n,f),h=y.useRef(null);y.useEffect(()=>{if(!i)return;const b=h.current;h.current=i.current,b!==h.current&&u(h.current)});const m=s.placementState&&Dv(s.placementState),v=m==null?void 0:m[0],x=m==null?void 0:m[1];return i?null:w.jsx(z3.div,{"data-radix-popper-side":v,"data-radix-popper-align":x,...a,ref:p})},"PopperAnchor")),q3="PopperContent",[Vie,zOe]=F3(q3),Wie=y.forwardRef(ws(function(t,n){var he,ke,we,fe,pt,qe,Oe;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:s="center",alignOffset:c=0,arrowPadding:u=0,avoidCollisions:f=!0,collisionBoundary:p=[],collisionPadding:h=0,sticky:m="partial",hideWhenDetached:v=!1,updatePositionStrategy:x="optimized",onPlaced:b,...S}=t,_=K3(q3,r),[O,k]=y.useState(null),T=Pv(n,k),[C,N]=y.useState(null),P=B3(C),D=(P==null?void 0:P.width)??0,j=(P==null?void 0:P.height)??0,I=i+(s!=="center"?"-"+s:""),F=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},R=Array.isArray(p)?p:[p],G=R.length>0,q={padding:F,boundary:R.filter(G3),altBoundary:G},{refs:K,floatingStyles:U,placement:W,isPositioned:H,middlewareData:Y}=mie({strategy:"fixed",placement:I,whileElementsMounted:ws((...De)=>aie(...De,{animationFrame:x==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[vie({mainAxis:a+j,alignmentAxis:c}),f&&yie({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?bie():void 0,...q}),f&&xie({...q}),wie({...q,apply:ws(({elements:De,rects:Pt,availableWidth:mn,availableHeight:br})=>{const{width:Hn,height:zr}=Pt.reference,ii=De.floating.style;ii.setProperty("--radix-popper-available-width",`${mn}px`),ii.setProperty("--radix-popper-available-height",`${br}px`),ii.setProperty("--radix-popper-anchor-width",`${Hn}px`),ii.setProperty("--radix-popper-anchor-height",`${zr}px`)},"apply")}),C&&Sie({element:C,padding:u}),Yie({arrowWidth:D,arrowHeight:j}),v&&Eie({strategy:"referenceHidden",...q,boundary:G?q.boundary:void 0})]}),z=_.setPlacementState;xx(()=>(z(W),()=>{z(void 0)}),[W,z]);const[$,Z]=Dv(W),L=$3(b);xx(()=>{H&&(L==null||L())},[H,L]);const ae=(he=Y.arrow)==null?void 0:he.x,me=(ke=Y.arrow)==null?void 0:ke.y,de=((we=Y.arrow)==null?void 0:we.centerOffset)!==0,[Ee,Ge]=y.useState();return xx(()=>{O&&Ge(window.getComputedStyle(O).zIndex)},[O]),w.jsx("div",{ref:K.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:H?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ee,"--radix-popper-transform-origin":[(fe=Y.transformOrigin)==null?void 0:fe.x,(pt=Y.transformOrigin)==null?void 0:pt.y].join(" "),...((qe=Y.hide)==null?void 0:qe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:w.jsx(Vie,{scope:r,placedSide:$,placedAlign:Z,onArrowChange:N,arrowX:ae,arrowY:me,shouldHideArrow:de,children:w.jsx(z3.div,{"data-side":$,"data-align":Z,...S,ref:T,style:{...S.style,animation:H?(Oe=S.style)==null?void 0:Oe.animation:"none"}})})})},"PopperContent"));function G3(e){return e!==null}ws(G3,"isNotNull");var Yie=ws(e=>({name:"transformOrigin",options:e,fn(t){var S,_,O;const{placement:n,rects:r,middlewareData:i}=t,s=((S=i.arrow)==null?void 0:S.centerOffset)!==0,c=s?0:e.arrowWidth,u=s?0:e.arrowHeight,[f,p]=Dv(n),h={start:"0%",center:"50%",end:"100%"}[p],m=(((_=i.arrow)==null?void 0:_.x)??0)+c/2,v=(((O=i.arrow)==null?void 0:O.y)??0)+u/2;let x="",b="";return f==="bottom"?(x=s?h:`${m}px`,b=`${-u}px`):f==="top"?(x=s?h:`${m}px`,b=`${r.floating.height+u}px`):f==="right"?(x=`${-u}px`,b=s?h:`${v}px`):f==="left"&&(x=`${r.floating.width+u}px`,b=s?h:`${v}px`),{data:{x,y:b}}}}),"transformOrigin");function Dv(e){const[t,n="center"]=e.split("-");return[t,n]}ws(Dv,"getSideAndAlignFromPlacement");var Xie=Kie,Zie=Gie,Qie=Wie,Jie=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},eae=Object.defineProperty,tae=(e,t)=>eae(e,"name",{value:t,configurable:!0}),nae=y.forwardRef(tae(function(t,n){var u;const{container:r,...i}=t,[a,s]=y.useState(!1);Jie(()=>s(!0),[]);const c=r||a&&((u=globalThis==null?void 0:globalThis.document)==null?void 0:u.body);return c?Sa.createPortal(w.jsx(Ov.div,{...i,ref:n}),c):null},"Portal")),kM=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},rae=Object.defineProperty,mo=(e,t)=>rae(e,"name",{value:t,configurable:!0});function V3(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}mo(V3,"useStateMachine");var W3=mo(e=>{const{present:t,children:n}=e,r=Y3(t),i=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),a=X3(r.ref,Z3(i));return typeof n=="function"||r.isPresent?y.cloneElement(i,{ref:a}):null},"Presence");function Y3(e){const[t,n]=y.useState(),r=y.useRef(null),i=y.useRef(e),a=y.useRef("none"),s=y.useRef(void 0),c=e?"mounted":"unmounted",[u,f]=V3(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{u==="mounted"?(a.current=s.current??ru(r.current),s.current=void 0):a.current="none"},[u]),kM(()=>{const p=r.current,h=i.current;if(h!==e){const v=a.current,x=ru(p);e?(s.current=x,f("MOUNT")):x==="none"||(p==null?void 0:p.display)==="none"?f("UNMOUNT"):f(h&&v!==x?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,f]),kM(()=>{if(t){let p;const h=t.ownerDocument.defaultView??window,m=mo(x=>{const S=ru(r.current).includes(CSS.escape(x.animationName));if(x.target===t&&S&&(f("ANIMATION_END"),!i.current)){const _=t.style.animationFillMode;t.style.animationFillMode="forwards",p=h.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=_)})}},"handleAnimationEnd"),v=mo(x=>{x.target===t&&(a.current=ru(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",v),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{h.clearTimeout(p),t.removeEventListener("animationstart",v),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:y.useCallback(p=>{if(p){const h=getComputedStyle(p);r.current=h,s.current=ru(h)}else r.current=null;n(p)},[])}}mo(Y3,"usePresence");function Ww(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}mo(Ww,"setRef");function X3(...e){const t=y.useRef(e);return t.current=e,y.useCallback(n=>{const r=t.current;let i=!1;const a=r.map(s=>{const c=Ww(s,n);return!i&&typeof c=="function"&&(i=!0),c});if(i)return()=>{for(let s=0;s<a.length;s++){const c=a[s];typeof c=="function"?c():Ww(r[s],null)}}},[])}mo(X3,"useStableComposedRefs");function ru(e){return(e==null?void 0:e.animationName)||"none"}mo(ru,"getAnimationName");function Z3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}mo(Z3,"getElementRef");var Q3=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},iae=Object.defineProperty,aae=(e,t)=>iae(e,"name",{value:t,configurable:!0}),OM=Ea[" useEffectEvent ".trim().toString()],CM=Ea[" useInsertionEffect ".trim().toString()];function J3(e){if(typeof OM=="function")return OM(e);const t=y.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof CM=="function"?CM(()=>{t.current=e}):Q3(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}aae(J3,"useEffectEvent");var oae=Object.defineProperty,fh=(e,t)=>oae(e,"name",{value:t,configurable:!0}),sae=Ea[" useInsertionEffect ".trim().toString()]||Q3;function e$({prop:e,defaultProp:t,onChange:n=fh(()=>{},"onChange"),caller:r}){const[i,a,s]=t$({defaultProp:t,onChange:n}),c=e!==void 0,u=c?e:i,f=y.useCallback(p=>{var h;if(c){const m=n$(p)?p(e):p;m!==e&&((h=s.current)==null||h.call(s,m))}else a(p)},[c,e,a,s]);return[u,f]}fh(e$,"useControllableState");function t$({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),i=y.useRef(n),a=y.useRef(t);return sae(()=>{a.current=t},[t]),y.useEffect(()=>{var s;i.current!==n&&((s=a.current)==null||s.call(a,n),i.current=n)},[n,i]),[n,r,a]}fh(t$,"useUncontrolledState");function n$(e){return typeof e=="function"}fh(n$,"isFunction");var TM=Symbol("RADIX:SYNC_STATE");function lae(e,t,n,r){const{prop:i,defaultProp:a,onChange:s,caller:c}=t,u=i!==void 0,f=J3(s),p=[{...n,state:a}];r&&p.push(r);const[h,m]=y.useReducer((S,_)=>{if(_.type===TM)return{...S,state:_.state};const O=e(S,_);return u&&!Object.is(O.state,S.state)&&f(O.state),O},...p),v=h.state,x=y.useRef(v);y.useEffect(()=>{x.current!==v&&(x.current=v,u||f(v))},[v,x,u]);const b=y.useMemo(()=>i!==void 0?{...h,state:i}:h,[h,i]);return y.useEffect(()=>{u&&!Object.is(i,h.state)&&m({type:TM,state:i})},[i,h.state,u]),[b,m]}fh(lae,"useControllableStateReducer");var cae=Object.defineProperty,zs=(e,t)=>cae(e,"name",{value:t,configurable:!0}),fS="Popover",[r$,$Oe]=e3(fS,[H3]),dS=H3(),[uae,Hu]=r$(fS),fae=zs(e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!1}=e,c=dS(t),u=y.useRef(null),[f,p]=y.useState(!1),[h,m]=e$({prop:r,defaultProp:i??!1,onChange:a,caller:fS});return w.jsx(Xie,{...c,children:w.jsx(uae,{scope:t,contentId:v3(),triggerRef:u,open:h,onOpenChange:m,onOpenToggle:y.useCallback(()=>m(v=>!v),[m]),hasCustomAnchor:f,onCustomAnchorAdd:y.useCallback(()=>p(!0),[]),onCustomAnchorRemove:y.useCallback(()=>p(!1),[]),modal:s,children:n})})},"Popover"),dae="PopoverTrigger",hae=y.forwardRef(zs(function(t,n){const{__scopePopover:r,...i}=t,a=Hu(dae,r),s=dS(r),c=Bu(n,a.triggerRef),u=w.jsx(Ov.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":hS(a.open),...i,ref:c,onClick:xs(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:w.jsx(Zie,{asChild:!0,...s,children:u})},"PopoverTrigger")),i$="PopoverPortal",[pae,mae]=r$(i$,{forceMount:void 0}),gae=zs(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=Hu(i$,t);return w.jsx(pae,{scope:t,forceMount:n,children:w.jsx(W3,{present:n||a.open,children:w.jsx(nae,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),Bd="PopoverContent",vae=y.forwardRef(zs(function(t,n){const r=mae(Bd,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=Hu(Bd,t.__scopePopover);return w.jsx(W3,{present:i||s.open,children:s.modal?w.jsx(bae,{...a,ref:n}):w.jsx(xae,{...a,ref:n})})},"PopoverContent")),yae=JE("PopoverContent.RemoveScroll"),bae=y.forwardRef(zs(function(t,n){const r=Hu(Bd,t.__scopePopover),i=y.useRef(null),a=Bu(n,i),s=y.useRef(!1);return y.useEffect(()=>{const c=i.current;if(c)return Dz(c)},[]),w.jsx(GE,{as:yae,allowPinchZoom:!0,children:w.jsx(a$,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:xs(t.onCloseAutoFocus,c=>{var u;c.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:xs(t.onPointerDownOutside,c=>{const u=c.detail.originalEvent,f=u.button===0&&u.ctrlKey===!0,p=u.button===2||f;s.current=p},{checkForDefaultPrevented:!1}),onFocusOutside:xs(t.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),xae=y.forwardRef(zs(function(t,n){const r=Hu(Bd,t.__scopePopover),i=y.useRef(!1),a=y.useRef(!1);return w.jsx(a$,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var c,u;(c=t.onCloseAutoFocus)==null||c.call(t,s),s.defaultPrevented||(i.current||(u=r.triggerRef.current)==null||u.focus(),s.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:s=>{var f,p;(f=t.onInteractOutside)==null||f.call(t,s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const c=s.target;((p=r.triggerRef.current)==null?void 0:p.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&a.current&&s.preventDefault()}})},"PopoverContentNonModal")),a$=y.forwardRef(zs(function(t,n){const{__scopePopover:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:s,disableOutsidePointerEvents:c,onEscapeKeyDown:u,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:h,...m}=t,v=Hu(Bd,r),x=dS(r);return nS(),w.jsx(hre,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:s,children:w.jsx(are,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:h,onEscapeKeyDown:u,onPointerDownOutside:f,onFocusOutside:p,onDismiss:()=>v.onOpenChange(!1),deferPointerDownOutside:!0,children:w.jsx(Qie,{"data-state":hS(v.open),role:"dialog",id:v.contentId,...x,...m,ref:n,style:{...m.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})},"PopoverContentImpl"));function hS(e){return e?"open":"closed"}zs(hS,"getState");var wae=fae,Eae=hae,Sae=gae,o$=vae;const _ae=wae,Aae=Eae,s$=y.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>w.jsx(Sae,{children:w.jsx(o$,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:Ue("z-50 w-64 max-w-[calc(100vw-1rem)] rounded-md border bg-card p-3 text-card-foreground shadow-md outline-none","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...a})}));s$.displayName=o$.displayName;const l$=92,c$=96;function wx(e){if(!Number.isFinite(e)||e<0)return"?";const t=["B","KB","MB","GB","TB","PB"];let n=0;for(;e>=1024&&n<t.length-1;)e/=1024,n++;return`${e<10&&n>0?e.toFixed(1):Math.round(e)} ${t[n]}`}const NM=3e5;function kae({socket:e,getToken:t}){const[n,r]=y.useState([]);if(y.useEffect(()=>{t().then(a=>a?fetch("/api/stats",{headers:{Authorization:`Bearer ${a}`}}):null).then(a=>a==null?void 0:a.json()).then(a=>(a==null?void 0:a.samples)&&r(a.samples)).catch(a=>console.warn("[MachineStats] seed failed",a))},[t]),y.useEffect(()=>{if(!e)return;const a=e.on(s=>{s.type==="stats"&&r(c=>[...c,s.sample].slice(-120))});return()=>{a()}},[e]),!n.length)return null;const i=n[n.length-1];return w.jsxs("div",{className:"w-full flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground/60",children:[w.jsx(Hm,{label:"cpu",value:i.cpu,series:n.map(a=>a.cpu)}),w.jsx(Hm,{label:"mem",value:i.mem,series:n.map(a=>a.mem)}),i.disk>=0&&w.jsx(Hm,{label:"disk",value:i.disk,severity:Pae(i.disk),title:jae(i)}),w.jsx(Oae,{getToken:t})]})}function Oae({getToken:e}){const[t,n]=y.useState(null);return y.useEffect(()=>{let r=!0,i=0;const a=async()=>{var f;try{const p=await e();if(!p)return;i=Date.now();const h=await fetch("/api/claude-usage",{headers:{Authorization:`Bearer ${p}`}});if(!r)return;if(h.status===204){n(null);return}if(h.status!==200)return;const m=await h.json();if(!r||!((f=m==null?void 0:m.limits)!=null&&f.length))return;n(m)}catch(p){console.warn("[MachineStats] claude usage poll failed",p)}},s=()=>{document.visibilityState==="visible"&&a()},c=()=>{document.visibilityState==="visible"&&Date.now()-i>=NM&&a()};s();const u=setInterval(s,NM);return document.addEventListener("visibilitychange",c),()=>{r=!1,clearInterval(u),document.removeEventListener("visibilitychange",c)}},[e]),w.jsx(Cae,{usage:t})}function Cae({usage:e}){const t=e&&u$(e.limits),[n,r]=y.useState(Yw),i=y.useRef(null),a=()=>{i.current&&(clearTimeout(i.current),i.current=null)},s=y.useCallback((c,u=0)=>{if(a(),!u){r(f=>IM(f,c));return}i.current=setTimeout(()=>{i.current=null,r(f=>IM(f,c))},u)},[]);return y.useEffect(()=>a,[]),!e||!t?null:w.jsxs(_ae,{open:n.open,onOpenChange:c=>s(c?{type:"activate"}:{type:"dismiss"}),children:[w.jsx(Aae,{asChild:!0,children:w.jsx("button",{type:"button","aria-label":"claude usage breakdown",className:"cursor-default rounded-sm outline-none focus-visible:ring-1 focus-visible:ring-ring",onPointerEnter:c=>s({type:"pointerenter",pointerType:c.pointerType},Tae),onPointerLeave:c=>s({type:"pointerleave",pointerType:c.pointerType},MM),children:w.jsx(Hm,{label:"usage",value:t.percent,severity:t.severity})})}),w.jsx(s$,{onOpenAutoFocus:c=>c.preventDefault(),onPointerEnter:()=>a(),onPointerLeave:c=>s({type:"pointerleave",pointerType:c.pointerType},MM),children:w.jsx(Nae,{usage:e})})]})}const Tae=120,MM=80,Yw={open:!1,byHover:!1};function IM(e,t){switch(t.type){case"pointerenter":return RM(t.pointerType)?{open:!0,byHover:!0}:e;case"pointerleave":return RM(t.pointerType)&&e.byHover?Yw:e;case"activate":return{open:!0,byHover:!1};case"dismiss":return Yw}}const RM=e=>e==="mouse"||e==="";function Nae({usage:e}){const t=u$(e.limits);return w.jsxs("div",{className:"text-[11px] leading-tight",children:[w.jsxs("div",{className:"flex items-baseline justify-between gap-2 pb-2 text-muted-foreground",children:[w.jsx("span",{className:"uppercase tracking-wide",children:"claude usage"}),e.subscriptionType&&w.jsxs("span",{className:"tabular-nums",children:[e.subscriptionType," plan"]})]}),w.jsxs("div",{className:"-mt-1 flex items-baseline justify-between gap-2 pb-2 text-[10px] text-muted-foreground",children:[e.account&&w.jsx("span",{className:"truncate",title:e.account,children:e.account}),w.jsx("span",{className:Ue("shrink-0",e.stale&&"text-amber-500"),children:Iae(e)})]}),e.stale&&e.error&&w.jsxs("div",{"data-refresh-error":!0,className:"-mt-1 pb-2 text-[10px] text-amber-500 break-words",children:[e.error,Um(e.retryAt??null)&&` · retrying in ${Um(e.retryAt??null)}`]}),w.jsx("div",{className:"flex flex-col gap-3",children:e.limits.map((n,r)=>{const i=Um(n.resetsAt),a=n===t;return w.jsxs("div",{"data-headline":a||void 0,className:Ue("flex flex-col gap-1",!a&&"opacity-60"),children:[w.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[w.jsxs("span",{className:Ue("truncate",a&&"font-medium"),children:[a&&w.jsx("span",{className:"mr-1 text-muted-foreground","aria-hidden":!0,children:"▸"}),Mae(n)]}),w.jsxs("span",{className:Ue("tabular-nums shrink-0",Xw(n.percent,n.severity)),children:[n.percent,"%"]})]}),w.jsx(f$,{value:n.percent,className:Ue("w-full",Xw(n.percent,n.severity))}),w.jsx("span",{className:"text-[10px] text-muted-foreground",children:i?`resets in ${i}`:"no reset reported"})]},`${n.kind}-${r}`)})}),w.jsx("div",{className:"mt-3 border-t pt-2 text-[10px] text-muted-foreground",children:"▸ is the window the strip is showing"})]})}function Mae(e){return e.scopeLabel?`${e.scopeLabel} window`:e.kind==="session"?"current session":e.kind==="weekly_all"?"all models":e.kind.replace(/_/g," ")}function u$(e){return e.reduce((t,n)=>!t||n.percent>t.percent?n:t,null)}function Iae(e){const t=Rae(e.fetchedAt);return t?e.stale?`${t} old — refresh failed`:`updated ${t} ago`:e.stale?"last reading — refresh failed":"updated just now"}function Rae(e){if(!e)return null;const t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t))return null;const n=Math.round(Math.max(0,t)/6e4);if(n<1)return null;if(n<60)return`${n}m`;const r=Math.floor(n/60),i=n%60;return r<24?i?`${r}h ${i}m`:`${r}h`:`${Math.floor(r/24)}d`}function Pae(e){return e>=c$?"critical":e>=l$?"warning":"ok"}const Dae={critical:"text-red-500",exceeded:"text-red-500",warning:"text-amber-500",warn:"text-amber-500",ok:"text-emerald-500"};function Xw(e,t){const n=t?Dae[t]:void 0;return n||(e>=90?"text-red-500":e>=75?"text-amber-500":"text-emerald-500")}function jae(e){const t=`warn at ${l$}%, critical at ${c$}%`;if(e.diskUsedBytes==null||e.diskTotalBytes==null)return`disk ${e.disk}% used — ${t}`;const n=Math.max(0,e.diskTotalBytes-e.diskUsedBytes);return`disk ${e.disk}% used — ${wx(e.diskUsedBytes)} of ${wx(e.diskTotalBytes)}, ${wx(n)} free — ${t}`}function Hm({label:e,value:t,series:n,title:r,severity:i}){const a=Xw(t,i),s=r??(n?`${e} ${t}% — last ${n.length} samples`:void 0);return w.jsxs("span",{className:"flex items-center gap-1",title:s,children:[w.jsx("span",{className:"uppercase tracking-wide",children:e}),n?w.jsx(Lae,{series:n,className:a}):w.jsx(f$,{value:t,className:a}),w.jsxs("span",{className:Ue("tabular-nums",a),children:[t,"%"]})]})}function f$({value:e,className:t}){const i=Math.max(0,Math.min(100,e))/100*40;return w.jsxs("svg",{width:40,height:12,viewBox:"0 0 40 12",className:Ue("overflow-visible",t),preserveAspectRatio:"none",children:[w.jsx("rect",{x:0,y:12/2-2,width:40,height:4,rx:2,fill:"currentColor",opacity:.2}),i>0&&w.jsx("rect",{x:0,y:12/2-2,width:i,height:4,rx:2,fill:"currentColor"})]})}function Lae({series:e,className:t}){const i=e.length;if(i<2)return null;const a=e.map((s,c)=>{const u=i>1?c/(i-1)*40:0,f=12-Math.max(0,Math.min(100,s))/100*12;return`${u.toFixed(1)},${f.toFixed(1)}`}).join(" ");return w.jsx("svg",{width:40,height:12,viewBox:"0 0 40 12",className:Ue("overflow-visible",t),preserveAspectRatio:"none",children:w.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}const od=50;function zae({getToken:e,filter:t,refreshKey:n,hydrateIds:r}){const[i,a]=y.useState([]),[s,c]=y.useState(null),[u,f]=y.useState(!1),[p,h]=y.useState({}),m=y.useRef(new Set),v=y.useRef(null),x=y.useRef(null),b=y.useRef(t);b.current=t;const S=y.useRef(od),_=y.useRef(t);_.current!==t&&(_.current=t,S.current=od);const O=y.useCallback(async(P,D)=>{const j=await e();if(!j||D!=null&&D.aborted)return null;const I=await fetch(`/api/sessions?${new URLSearchParams(P)}`,{signal:D,headers:{Authorization:`Bearer ${j}`}});if(!I.ok)return null;const F=await I.json();return Array.isArray(F==null?void 0:F.sessions)?F:null},[e]),k=y.useCallback(async(P,D,j)=>{const I=[];let F,R=null;for(;I.length<P;){const G={filter:D,limit:String(Math.min(od,P-I.length))};F&&(G.before=F);const q=await O(G,j);if(!q)return null;if(I.push(...q.sessions),R=q.nextCursor,!R||!q.sessions.length)break;F=R}return{sessions:I,nextCursor:R}},[O]);y.useEffect(()=>{var D,j;(D=v.current)==null||D.abort(),(j=x.current)==null||j.abort();const P=new AbortController;return v.current=P,f(!0),m.current.clear(),h({}),k(S.current,t,P.signal).then(I=>{!I||P.signal.aborted||(a(I.sessions),c(I.nextCursor))}).catch(()=>{}).finally(()=>{P.signal.aborted||f(!1)}),()=>P.abort()},[k,t,n]);const T=y.useCallback(()=>{var j;if(!s||u)return;(j=x.current)==null||j.abort();const P=new AbortController;x.current=P;const D=b.current;f(!0),O({filter:D,limit:String(od),before:s},P.signal).then(I=>{!I||P.signal.aborted||D!==b.current||(a(F=>{const R=new Set(F.map(q=>q.sessionId)),G=[...F,...I.sessions.filter(q=>!R.has(q.sessionId))];return S.current=Math.max(od,G.length),G}),c(I.nextCursor))}).catch(()=>{}).finally(()=>{P.signal.aborted||f(!1)})},[s,u,O]),C=y.useMemo(()=>{const P=new Map;for(const D of Object.values(p))P.set(D.sessionId,D);for(const D of i)P.set(D.sessionId,D);return P},[i,p]),N=r.join(",");return y.useEffect(()=>{const P=r.filter(j=>!!j&&!C.has(j)&&!m.current.has(j)).slice(0,200);if(!P.length)return;for(const j of P)m.current.add(j);let D=!1;return O({ids:P.join(",")}).then(j=>{!j||D||h(I=>{const F={...I};for(const R of j.sessions)F[R.sessionId]=R;return F})}).catch(()=>{}),()=>{D=!0}},[N,C,O]),{sessions:i,cursor:s,loading:u,byId:C,loadMore:T}}const sd="0.1.112";function $ae(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);if(r<24)return`${r}h ago`;const i=Math.floor(r/24);return i<7?`${i}d ago`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}const ld="w-4 h-4 mt-0.5 shrink-0";function Bae(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?w.jsx(oG,{className:`${ld} text-purple-400`}):(t==null?void 0:t.type)==="mention"?w.jsx(Wq,{className:`${ld} text-blue-400`}):(t==null?void 0:t.type)==="channel"?w.jsx(tG,{className:`${ld} text-green-400`}):e.sessionId.startsWith("slack-")?w.jsx(xw,{className:`${ld} text-yellow-400`}):w.jsx(xw,{className:`${ld} text-muted-foreground`})}function Uae(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?`DM${t.userName?` · ${t.userName}`:""}`:(t==null?void 0:t.type)==="mention"?`@mention${t.channelName?` · #${t.channelName}`:""}`:(t==null?void 0:t.type)==="channel"?`#${t.channelName||"channel"}`:e.sessionId.startsWith("slack-")?"Slack":null}function Fae(e,t,n){return Object.keys(e).map(r=>t.get(r)).filter(r=>!!r&&(n==="all"||r.mine!==!1))}const PM="chats-filter",DM="chats-unread-filter";function Hae({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,unreads:c={},busySessions:u=new Set,socket:f}){var H;const p=_a(),[h,m]=y.useState(()=>localStorage.getItem(PM)||"mine"),[v,x]=y.useState(()=>localStorage.getItem(DM)==="true"),[b,S]=y.useState(""),_=y.useRef(null);function O(Y){m(Y),localStorage.setItem(PM,Y)}function k(){const Y=!v;x(Y),localStorage.setItem(DM,String(Y))}const T=y.useMemo(()=>[t,...Object.keys(c)].filter(Y=>!!Y),[t,c]),{sessions:C,cursor:N,loading:P,byId:D,loadMore:j}=zae({getToken:e,filter:h,refreshKey:i,hydrateIds:T}),I=y.useMemo(()=>Fae(c,D,h),[c,D,h]),F=I.length,R=y.useMemo(()=>v?[...I].sort((Y,z)=>z.lastModified-Y.lastModified):C,[v,I,C]),G=t&&!R.some(Y=>Y.sessionId===t)?D.get(t):void 0;y.useEffect(()=>{_.current&&_.current.scrollIntoView({block:"nearest"})},[t,R,G]);const q=y.useRef(null),K=y.useRef(j);K.current=j,y.useEffect(()=>{const Y=q.current;if(!Y||!N||v)return;const z=new IntersectionObserver($=>{$.some(Z=>Z.isIntersecting)&&K.current()},{rootMargin:"300px"});return z.observe(Y),()=>z.disconnect()},[N,P,v]),y.useEffect(()=>{e().then(Y=>Y?fetch("/api/version",{headers:{Authorization:`Bearer ${Y}`}}):null).then(Y=>Y==null?void 0:Y.json()).then(Y=>Y&&S(Y.version)).catch(()=>{})},[]);const U=!!b&&b!=="unknown"&&sd!=="dev"&&b!==sd;y.useEffect(()=>{U&&console.warn(`[shraga] stale client bundle: built from v${sd}, server runs v${b} — rebuild dist/client`)},[U,b]);function W(Y){const z=c[Y.sessionId],$=u.has(Y.sessionId)||Y.runStatus==="running"||Y.scheduleRunStatus==="running",Z=!$&&(!!Y.lastStopReason||Y.scheduleRunStatus==="error"||Y.scheduleRunStatus==="aborted"),L=$?"border-amber-500":Z?"border-red-500":z?"border-blue-500":"",ae=!!($||Z||z);return w.jsx("button",{ref:Y.sessionId===t?_:void 0,onClick:()=>n(Y.sessionId,Y.title),className:Ue("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",ae?`rounded-r-lg border-l-[3px] ${L}`:"rounded-lg",t===Y.sessionId&&"bg-accent"),children:w.jsxs("div",{className:"flex items-start gap-2",children:[Bae(Y),w.jsxs("div",{className:"min-w-0 flex-1",children:[w.jsx("span",{className:Ue("block truncate text-sm leading-snug",z&&"font-semibold"),children:Y.title||"New session"}),w.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[w.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:Uae(Y)||Y.userName}),w.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),w.jsx("span",{className:"text-[10px] text-muted-foreground",children:$ae(Y.lastModified)})]})]})]})},Y.sessionId)}return w.jsxs("div",{className:"flex flex-col h-full bg-muted/30",children:[w.jsx("div",{className:"p-3",children:w.jsxs(Ne,{variant:"outline",size:"sm",className:"w-full gap-2 justify-start",onClick:r,title:"New Chat (Ctrl+N)",children:[w.jsx(vv,{className:"w-4 h-4"})," New Chat",w.jsx("span",{className:"ml-auto flex items-center gap-0.5 text-[10px] text-muted-foreground/50 font-mono",children:"⌃N"})]})}),w.jsx("div",{className:"border-b shrink-0 flex flex-col max-h-[40vh]",children:w.jsx(jne,{getToken:e,onRefresh:s,refreshKey:a})}),w.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1",children:[w.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Chats"}),w.jsxs("div",{className:"flex gap-0.5",children:[["mine","all"].map(Y=>w.jsx("button",{onClick:()=>O(Y),className:Ue("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",h===Y?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:Y},Y)),w.jsxs("button",{onClick:k,className:Ue("text-[10px] px-1.5 rounded-full transition-colors leading-none",v?"text-blue-600 dark:text-blue-400 font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:["unread",F>0&&w.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),w.jsx(Gj,{className:"flex-1",children:w.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[R.length===0&&!G&&w.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:P?"Loading…":v?"No unread conversations":"No conversations yet"}),G&&W(G),R.map(W),!v&&N&&w.jsx("div",{ref:q,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:P?"Loading older…":"···"})]})}),w.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[w.jsx(kae,{socket:f??null,getToken:e}),(H=p.sidebarExtras)==null?void 0:H.call(p),b&&(U?w.jsxs("button",{onClick:()=>location.reload(),title:`This page was built from v${sd}, the server runs v${b} — reload to update`,className:"text-[10px] text-amber-400 hover:text-amber-300 text-center underline decoration-dotted",children:["⚠️ stale page (v",sd," → v",b,") · reload"]}):w.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",b]}))]})]})}function Yr(e,t){const n=e[e.length-1];if((n==null?void 0:n.role)==="assistant"){if(t.type==="text"||t.type==="thinking"){const r=[...n.blocks],i=r[r.length-1];return(i==null?void 0:i.type)===t.type?(r[r.length-1]={...i,text:i.text+t.text},[...e.slice(0,-1),{...n,blocks:r}]):[...e.slice(0,-1),{...n,blocks:[...r,t]}]}return[...e.slice(0,-1),{...n,blocks:[...n.blocks,t]}]}return[...e,{id:vs(),role:"assistant",blocks:[t]}]}function jM(e,t,n="text"){const r=e[e.length-1],i={type:n,text:t};return(r==null?void 0:r.role)==="assistant"?[...e.slice(0,-1),{...r,blocks:[...r.blocks,i]}]:[...e,{id:vs(),role:"assistant",blocks:[i]}]}function d$(e,t,n){for(let r=e.length-1;r>=0;r--){const i=e[r];if(i.role!=="assistant")continue;const a=i.blocks.findIndex(c=>c.type==="tool_use"&&c.toolUseId===t);if(a===-1)continue;const s=[...i.blocks];return s[a]={...s[a],input:n},[...e.slice(0,r),{...i,blocks:s},...e.slice(r+1)]}return e}function Kae(e,t){const[n,r]=y.useState([]),[i,a]=y.useState(!1),[s,c]=y.useState([]),u=y.useRef(t.initialSessionId),f=y.useRef(!1),p=y.useRef(s);p.current=s;const h=y.useRef(t.getToken);h.current=t.getToken;const m=y.useRef(t.onNewSession);m.current=t.onNewSession;const v=y.useRef(t.onDirectivesChanged);v.current=t.onDirectivesChanged;const x=y.useRef(t.onParticipantsChanged);x.current=t.onParticipantsChanged;const b=y.useRef(t.onEvent);b.current=t.onEvent;const S=y.useRef(e);S.current=e;const _=y.useCallback(R=>R!=null&&R===u.current,[]),O=y.useCallback(async()=>{var G;const R=u.current;if(R)try{const K=await(await wl(`/api/sessions/${R}/messages`,h.current)).json();r(Ej(K)),a(!!K.busy),(G=x.current)==null||G.call(x,Array.isArray(K.participants)&&K.participants.length>1)}catch{}},[]);y.useEffect(()=>{if(!e)return;const R=e.on(G=>{var K,U,W,H,Y,z;(K=b.current)==null||K.call(b,G);const q=G;if(q.type==="compact_marker")return _(q.sessionId)?r($=>[...$,{id:vs(),role:"assistant",blocks:[{type:"compact_marker",summary:q.summary??"",compactedCount:q.compactedCount??0}]}]):void 0;switch(G.type){case"thinking_delta":return _(G.sessionId)?r($=>Yr($,{type:"thinking",text:G.text})):void 0;case"text_delta":return _(G.sessionId)?r($=>Yr($,{type:"text",text:G.text})):void 0;case"tool_use":return _(G.sessionId)?r($=>Yr($,{type:"tool_use",tool:G.tool,toolUseId:G.toolUseId,input:G.input})):void 0;case"tool_use_input":return _(G.sessionId)?r($=>d$($,G.toolUseId,G.input)):void 0;case"tool_result":return _(G.sessionId)?r($=>Yr($,{type:"tool_result",toolUseId:G.toolUseId,output:G.output})):void 0;case"tool_result_image":return _(G.sessionId)?r($=>Yr($,{type:"image",src:G.dataUrl})):void 0;case"permission_request":return _(G.sessionId)?r($=>Yr($,{type:"permission_request",id:G.id,tool:G.tool,input:G.input})):void 0;case"question_request":return _(G.sessionId)?r($=>Yr($,{type:"question_request",id:G.id,questions:G.questions})):void 0;case"directives":return f.current?(U=v.current)==null?void 0:U.call(v,G.directives):void 0;case"session_id":return!f.current||u.current?void 0:(u.current=G.sessionId,(W=m.current)==null?void 0:W.call(m,G.sessionId));case"forked":return G.sourceSessionId!==u.current?void 0:(u.current=G.sessionId,(H=m.current)==null?void 0:H.call(m,G.sessionId));case"session_busy":G.sessionId===u.current&&a(G.busy);return;case"session_stream":return G.sessionId!==u.current?void 0:qae(r,G.event);case"session_messages_changed":G.sessionId===u.current&&O();return;case"done":{if(G.sessionId!==u.current)return;G.stopReason==="max_turns_reached"&&r(Z=>Yr(Z,{type:"text",text:`
1848
1848
 
1849
1849
  ---
1850
1850
  ⚠️ Reached the maximum number of steps for this turn. Send "continue" to pick up where I left off.`})),(Y=m.current)==null||Y.call(m,G.sessionId);const $=p.current;if($.length>0){const Z=$.join(`
@@ -1942,7 +1942,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1942
1942
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function AAe(e,t){if(e){if(typeof e=="string")return Y2(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Y2(e,t):void 0}}function Y2(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function kAe(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,i,a,s,c=[],u=!0,f=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(u=(r=a.call(n)).done)&&(c.push(r.value),c.length!==t);u=!0);}catch(p){f=!0,i=p}finally{try{if(!u&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(f)throw i}}return c}}function OAe(e){if(Array.isArray(e))return e}var CAe=()=>(Ebe(),null);function dv(e){if(typeof e=="number")return e;if(typeof e=="string"){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var TAe=y.forwardRef((e,t)=>{var n,r,i=y.useRef(null),a=y.useState({containerWidth:dv((n=e.style)===null||n===void 0?void 0:n.width),containerHeight:dv((r=e.style)===null||r===void 0?void 0:r.height)}),s=fv(a,2),c=s[0],u=s[1],f=y.useCallback((h,m)=>{u(v=>{var x=Math.round(h),b=Math.round(m);return v.containerWidth===x&&v.containerHeight===b?v:{containerWidth:x,containerHeight:b}})},[]),p=y.useCallback(h=>{if(typeof t=="function"&&t(h),i.current!=null&&(i.current.disconnect(),i.current=null),h!=null&&typeof ResizeObserver<"u"){var m=h.getBoundingClientRect(),v=m.width,x=m.height;f(v,x);var b=_=>{var O=_[0];if(O!=null){var k=O.contentRect,T=k.width,C=k.height;f(T,C)}},S=new ResizeObserver(b);S.observe(h),i.current=S}},[t,f]);return y.useEffect(()=>()=>{var h=i.current;h!=null&&h.disconnect()},[f]),y.createElement(y.Fragment,null,y.createElement(vh,{width:c.containerWidth,height:c.containerHeight}),y.createElement("div",Ss({ref:p},e)))}),NAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height,i=y.useState({containerWidth:dv(n),containerHeight:dv(r)}),a=fv(i,2),s=a[0],c=a[1],u=y.useCallback((p,h)=>{c(m=>{var v=Math.round(p),x=Math.round(h);return m.containerWidth===v&&m.containerHeight===x?m:{containerWidth:v,containerHeight:x}})},[]),f=y.useCallback(p=>{if(typeof t=="function"&&t(p),p!=null){var h=p.getBoundingClientRect(),m=h.width,v=h.height;u(m,v)}},[t,u]);return y.createElement(y.Fragment,null,y.createElement(vh,{width:s.containerWidth,height:s.containerHeight}),y.createElement("div",Ss({ref:f},e)))}),MAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height;return y.createElement(y.Fragment,null,y.createElement(vh,{width:n,height:r}),y.createElement("div",Ss({ref:t},e)))}),IAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height;return typeof n=="string"||typeof r=="string"?y.createElement(NAe,Ss({},e,{ref:t})):typeof n=="number"&&typeof r=="number"?y.createElement(MAe,Ss({},e,{width:n,height:r,ref:t})):y.createElement(y.Fragment,null,y.createElement(vh,{width:n,height:r}),y.createElement("div",Ss({ref:t},e)))});function RAe(e){return e?TAe:IAe}var PAe=y.forwardRef((e,t)=>{var n=e.children,r=e.className,i=e.height,a=e.onClick,s=e.onContextMenu,c=e.onDoubleClick,u=e.onMouseDown,f=e.onMouseEnter,p=e.onMouseLeave,h=e.onMouseMove,m=e.onMouseUp,v=e.onTouchEnd,x=e.onTouchMove,b=e.onTouchStart,S=e.style,_=e.width,O=e.responsive,k=e.dispatchTouchEvents,T=k===void 0?!0:k,C=y.useRef(null),N=Rt(),P=y.useState(null),D=fv(P,2),j=D[0],I=D[1],F=y.useState(null),R=fv(F,2),G=R[0],q=R[1],K=bAe(),U=MS(),W=(U==null?void 0:U.width)>0?U.width:_,H=(U==null?void 0:U.height)>0?U.height:i,Y=y.useCallback(Oe=>{K(Oe),typeof t=="function"&&t(Oe),I(Oe),q(Oe),Oe!=null&&(C.current=Oe)},[K,t,I,q]),z=y.useCallback(Oe=>{N(p6(Oe)),N(vi({handler:a,reactEvent:Oe}))},[N,a]),$=y.useCallback(Oe=>{N(q1(Oe)),N(vi({handler:f,reactEvent:Oe}))},[N,f]),Z=y.useCallback(Oe=>{N(q4()),N(vi({handler:p,reactEvent:Oe}))},[N,p]),L=y.useCallback(Oe=>{N(q1(Oe)),N(vi({handler:h,reactEvent:Oe}))},[N,h]),ae=y.useCallback(()=>{N(x6())},[N]),me=y.useCallback(()=>{N(w6())},[N]),de=y.useCallback(Oe=>{N(b6(Oe.key))},[N]),Ee=y.useCallback(Oe=>{N(vi({handler:s,reactEvent:Oe}))},[N,s]),Ge=y.useCallback(Oe=>{N(vi({handler:c,reactEvent:Oe}))},[N,c]),he=y.useCallback(Oe=>{N(vi({handler:u,reactEvent:Oe}))},[N,u]),ke=y.useCallback(Oe=>{N(vi({handler:m,reactEvent:Oe}))},[N,m]),we=y.useCallback(Oe=>{N(vi({handler:b,reactEvent:Oe}))},[N,b]),fe=y.useCallback(Oe=>{T&&N(_6(Oe)),N(vi({handler:x,reactEvent:Oe}))},[N,T,x]),pt=y.useCallback(Oe=>{N(vi({handler:v,reactEvent:Oe}))},[N,v]),qe=RAe(O);return y.createElement(hU.Provider,{value:j},y.createElement(m$.Provider,{value:G},y.createElement(qe,{width:W??(S==null?void 0:S.width),height:H??(S==null?void 0:S.height),className:gt("recharts-wrapper",r),style:xAe({position:"relative",cursor:"default",width:W,height:H},S),onClick:z,onContextMenu:Ee,onDoubleClick:Ge,onFocus:ae,onBlur:me,onKeyDown:de,onMouseDown:he,onMouseEnter:$,onMouseLeave:Z,onMouseMove:L,onMouseUp:ke,onTouchEnd:pt,onTouchMove:fe,onTouchStart:we,ref:Y},y.createElement(CAe,null),n)))}),DAe=["width","height","responsive","children","className","style","compact","title","desc"];function jAe(e,t){if(e==null)return{};var n,r,i=LAe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function LAe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var M6=y.forwardRef((e,t)=>{var n=e.width,r=e.height,i=e.responsive,a=e.children,s=e.className,c=e.style,u=e.compact,f=e.title,p=e.desc,h=jAe(e,DAe),m=ei(h);return u?y.createElement(y.Fragment,null,y.createElement(vh,{width:n,height:r}),y.createElement(G2,{otherAttributes:m,title:f,desc:p},a)):y.createElement(PAe,{className:s,style:c,width:n,height:r,responsive:i??!1,onClick:e.onClick,onMouseLeave:e.onMouseLeave,onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseDown:e.onMouseDown,onMouseUp:e.onMouseUp,onContextMenu:e.onContextMenu,onDoubleClick:e.onDoubleClick,onTouchStart:e.onTouchStart,onTouchMove:e.onTouchMove,onTouchEnd:e.onTouchEnd},y.createElement(G2,{otherAttributes:m,title:f,desc:p,ref:t},y.createElement(N1e,null,a)))});function G1(){return G1=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},G1.apply(null,arguments)}function X2(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function zAe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?X2(Object(n),!0).forEach(function(r){$Ae(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):X2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function $Ae(e,t,n){return(t=BAe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function BAe(e){var t=UAe(e,"string");return typeof t=="symbol"?t:t+""}function UAe(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var FAe={top:5,right:5,bottom:5,left:5},HAe=zAe({accessibilityLayer:!0,barCategoryGap:"10%",barGap:4,layout:"horizontal",margin:FAe,responsive:!1,reverseStackOrder:!1,stackOffset:"none",syncMethod:"index"},EA),I6=y.forwardRef(function(t,n){var r,i=Rn(t.categoricalChartProps,HAe),a=t.chartName,s=t.defaultTooltipEventType,c=t.validateTooltipEventTypes,u=t.tooltipPayloadSearcher,f=t.categoricalChartProps,p={chartName:a,defaultTooltipEventType:s,validateTooltipEventTypes:c,tooltipPayloadSearcher:u,eventEmitter:void 0};return y.createElement(O6,{preloadedState:{options:p},reduxStoreName:(r=f.id)!==null&&r!==void 0?r:a},y.createElement(GU,{chartData:f.data}),y.createElement(C6,{layout:i.layout,margin:i.margin}),y.createElement(N6,{throttleDelay:i.throttleDelay,throttledEvents:i.throttledEvents}),y.createElement(T6,{baseValue:i.baseValue,accessibilityLayer:i.accessibilityLayer,barCategoryGap:i.barCategoryGap,maxBarSize:i.maxBarSize,stackOffset:i.stackOffset,barGap:i.barGap,barSize:i.barSize,syncId:i.syncId,syncMethod:i.syncMethod,className:i.className,reverseStackOrder:i.reverseStackOrder}),y.createElement(M6,G1({},i,{ref:n})))}),KAe=["axis"],qAe=y.forwardRef((e,t)=>y.createElement(I6,{chartName:"LineChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:KAe,tooltipPayloadSearcher:V_,categoricalChartProps:e,ref:t})),GAe=["axis","item"],VAe=y.forwardRef((e,t)=>y.createElement(I6,{chartName:"BarChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:GAe,tooltipPayloadSearcher:V_,categoricalChartProps:e,ref:t}));function WAe(e){var t=Rt();return y.useEffect(()=>{t(Q_e(e))},[t,e]),null}var YAe=["layout"];function V1(){return V1=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},V1.apply(null,arguments)}function XAe(e,t){if(e==null)return{};var n,r,i=ZAe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function ZAe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Z2(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function QAe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Z2(Object(n),!0).forEach(function(r){JAe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Z2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function JAe(e,t,n){return(t=eke(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function eke(e){var t=tke(e,"string");return typeof t=="symbol"?t:t+""}function tke(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var nke={top:5,right:5,bottom:5,left:5},R6=QAe({accessibilityLayer:!0,stackOffset:"none",barCategoryGap:"10%",barGap:4,margin:nke,reverseStackOrder:!1,syncMethod:"index",layout:"radial",responsive:!1,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"},EA),rke=y.forwardRef(function(t,n){var r,i=Rn(t.categoricalChartProps,R6),a=i.layout,s=XAe(i,YAe),c=t.chartName,u=t.defaultTooltipEventType,f=t.validateTooltipEventTypes,p=t.tooltipPayloadSearcher,h={chartName:c,defaultTooltipEventType:u,validateTooltipEventTypes:f,tooltipPayloadSearcher:p,eventEmitter:void 0};return y.createElement(O6,{preloadedState:{options:h},reduxStoreName:(r=i.id)!==null&&r!==void 0?r:c},y.createElement(GU,{chartData:i.data}),y.createElement(C6,{layout:a,margin:i.margin}),y.createElement(N6,{throttleDelay:i.throttleDelay,throttledEvents:i.throttledEvents}),y.createElement(T6,{baseValue:void 0,accessibilityLayer:i.accessibilityLayer,barCategoryGap:i.barCategoryGap,maxBarSize:i.maxBarSize,stackOffset:i.stackOffset,barGap:i.barGap,barSize:i.barSize,syncId:i.syncId,syncMethod:i.syncMethod,className:i.className,reverseStackOrder:i.reverseStackOrder}),y.createElement(WAe,{cx:i.cx,cy:i.cy,startAngle:i.startAngle,endAngle:i.endAngle,innerRadius:i.innerRadius,outerRadius:i.outerRadius}),y.createElement(M6,V1({},s,{ref:n})))});function Q2(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function J2(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Q2(Object(n),!0).forEach(function(r){ike(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Q2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function ike(e,t,n){return(t=ake(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ake(e){var t=oke(e,"string");return typeof t=="symbol"?t:t+""}function oke(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var ske=["item"],lke=J2(J2({},R6),{},{layout:"centric",startAngle:0,endAngle:360}),cke=y.forwardRef((e,t)=>{var n=Rn(e,lke);return y.createElement(rke,{chartName:"PieChart",defaultTooltipEventType:"item",validateTooltipEventTypes:ske,tooltipPayloadSearcher:V_,categoricalChartProps:n,ref:t})});const Qc=["#6366f1","#f59e0b","#10b981","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function uke(e){const t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return null;try{return JSON.parse(t)}catch{return null}}function fke(e){var s;const t=((s=e.data)==null?void 0:s.values)??e.values??e.series;if(!t||typeof t!="object")return null;const n=t,r=Object.keys(n);if(r.length===0)return null;const i=n[r[0]];return!i||typeof i!="object"?null:Object.keys(i).map(c=>{var f;const u={label:c};for(const p of r)u[p]=((f=n[p])==null?void 0:f[c])??0;return u})}function dke(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return"file"in t&&"sizeBytes"in t}function hke(e){if(dke(e))return null;if(Array.isArray(e))return e.length===0?null:typeof e[0]=="object"&&e[0]!==null?e:null;if(typeof e=="object"&&e!==null){const t=fke(e);if(t)return t}return null}function pke(e,t,n){return n.length===0?"table":n.length===1&&e.length<=8?"pie":e.map(a=>String(a[t]??"")).some(a=>/^\d{4}-\d{2}/.test(a))||e.length>20?"line":"bar"}function mke(e){const t=[...new Set(e.flatMap(Object.keys))],n=[];let r="";for(const i of t){const a=e.map(c=>c[i]).filter(c=>c!=null);a.filter(c=>typeof c=="number").length>a.length*.5?n.push(i):r||(r=i)}return r||(r=t[0]??"label"),{labelKey:r,numericKeys:n}}function gke({data:e}){const{rows:t,labelKey:n,numericKeys:r,chartType:i}=y.useMemo(()=>{const a=hke(e);if(!a||a.length===0)return{rows:null,labelKey:"",numericKeys:[],chartType:"table"};const{labelKey:s,numericKeys:c}=mke(a),u=pke(a,s,c);return{rows:a,labelKey:s,numericKeys:c,chartType:u}},[e]);return t?i==="table"?w.jsx(eD,{rows:t}):w.jsxs("div",{className:"space-y-2",children:[w.jsx("div",{className:"h-64 w-full",children:w.jsx(Oue,{width:"100%",height:"100%",children:i==="pie"?w.jsxs(cke,{children:[w.jsx(HU,{data:t,dataKey:r[0],nameKey:n,cx:"50%",cy:"50%",outerRadius:80,label:!0,children:t.map((a,s)=>w.jsx(Rh,{fill:Qc[s%Qc.length]},s))}),w.jsx(Zx,{}),w.jsx(Wm,{})]}):i==="line"?w.jsxs(qAe,{data:t,children:[w.jsx(j1,{strokeDasharray:"3 3",className:"opacity-30"}),w.jsx(U1,{dataKey:n,tick:{fontSize:11}}),w.jsx(K1,{tick:{fontSize:11}}),w.jsx(Zx,{}),r.length>1&&w.jsx(Wm,{}),r.map((a,s)=>w.jsx(s6,{type:"monotone",dataKey:a,stroke:Qc[s%Qc.length],strokeWidth:2,dot:!1},a))]}):w.jsxs(VAe,{data:t,children:[w.jsx(j1,{strokeDasharray:"3 3",className:"opacity-30"}),w.jsx(U1,{dataKey:n,tick:{fontSize:11}}),w.jsx(K1,{tick:{fontSize:11}}),w.jsx(Zx,{}),r.length>1&&w.jsx(Wm,{}),r.map((a,s)=>w.jsx(d6,{dataKey:a,fill:Qc[s%Qc.length],radius:[3,3,0,0]},a))]})})}),w.jsx(eD,{rows:t})]}):w.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:JSON.stringify(e,null,2)})}function eD({rows:e}){const t=[...new Set(e.flatMap(Object.keys))];return w.jsx("div",{className:"overflow-auto max-h-96 rounded border text-xs",children:w.jsxs("table",{className:"w-full text-left",children:[w.jsx("thead",{className:"bg-muted sticky top-0",children:w.jsx("tr",{children:t.map(n=>w.jsx("th",{className:"px-2 py-1 font-medium",children:n},n))})}),w.jsx("tbody",{children:e.map((n,r)=>w.jsx("tr",{className:"border-t",children:t.map(i=>{const a=n[i],s=a==null?"":typeof a=="object"?JSON.stringify(a,null,2):String(a);return w.jsx("td",{className:"px-2 py-1 max-w-[400px] whitespace-pre-wrap break-words align-top",title:s,children:s},i)})},r))})]})})}const W1=/^\/uploads\//;function SA({src:e,alt:t,className:n,onClick:r}){const{getToken:i}=hE(),[a,s]=y.useState(W1.test(e)?null:e);return y.useEffect(()=>{if(!W1.test(e)){s(e);return}let c=null,u=!1;return s(null),(async()=>{try{const f=await i(),p=await fetch(e,{headers:f?{Authorization:`Bearer ${f}`}:{}});if(!p.ok)throw new Error(`${p.status} ${p.statusText}`);c=URL.createObjectURL(await p.blob()),u?URL.revokeObjectURL(c):s(c)}catch(f){console.error("[authed-image] load failed:",e,f)}})(),()=>{u=!0,c&&URL.revokeObjectURL(c)}},[e,i]),a?w.jsx("img",{src:a,alt:t??"",className:n,onClick:()=>r==null?void 0:r(a)}):w.jsx("div",{className:n,"aria-busy":"true"})}function vke({src:e,name:t,className:n}){const{getToken:r}=hE(),i=async a=>{if(W1.test(e)){a.preventDefault();try{const s=await r(),c=await fetch(e,{headers:s?{Authorization:`Bearer ${s}`}:{}});if(!c.ok)throw new Error(`${c.status} ${c.statusText}`);const u=URL.createObjectURL(await c.blob()),f=document.createElement("a");f.href=u,f.download=t,f.click(),setTimeout(()=>URL.revokeObjectURL(u),1e4)}catch(s){console.error("[authed-file] open failed:",e,s)}}};return w.jsxs("a",{href:e,onClick:i,target:"_blank",rel:"noopener noreferrer",className:n,children:[w.jsx(gE,{className:"w-4 h-4 shrink-0"}),w.jsx("span",{className:"truncate max-w-[200px]",children:t})]})}const Y1=1,P6=10,bd={scale:1,tx:0,ty:0},tD=e=>Math.min(P6,Math.max(Y1,e));function yke({src:e,alt:t=""}){const n=y.useRef(null),r=y.useRef(null),[i,a]=y.useState(bd),[s,c]=y.useState(!1),u=(_,O)=>{var T;const k=(T=n.current)==null?void 0:T.getBoundingClientRect();return k?{cx:_-k.left-k.width/2,cy:O-k.top-k.height/2}:{cx:0,cy:0}},f=y.useCallback((_,O,k)=>{a(T=>{const C=tD(_);if(C===T.scale)return T;if(C<=Y1)return bd;const N=C/T.scale;return{scale:C,tx:O-N*(O-T.tx),ty:k-N*(k-T.ty)}})},[]),p=_=>{_.preventDefault();const{cx:O,cy:k}=u(_.clientX,_.clientY),T=_.deltaY<0?1.15:1/1.15;a(C=>{const N=tD(C.scale*T);if(N===C.scale)return C;if(N<=Y1)return bd;const P=N/C.scale;return{scale:N,tx:O-P*(O-C.tx),ty:k-P*(k-C.ty)}})},h=_=>{i.scale<=1||(_.currentTarget.setPointerCapture(_.pointerId),r.current={x:_.clientX,y:_.clientY,tx:i.tx,ty:i.ty},c(!0))},m=_=>{const O=r.current;O&&a(k=>({...k,tx:O.tx+(_.clientX-O.x),ty:O.ty+(_.clientY-O.y)}))},v=()=>{r.current=null,c(!1)},x=_=>{const{cx:O,cy:k}=u(_.clientX,_.clientY);i.scale>1?a(bd):f(2.5,O,k)},b=_=>f(i.scale*_,0,0),S=i.scale>1;return w.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[w.jsx("div",{ref:n,className:"w-full h-full overflow-hidden flex items-center justify-center",onWheel:p,onPointerDown:h,onPointerMove:m,onPointerUp:v,onPointerCancel:v,onDoubleClick:x,style:{cursor:S?s?"grabbing":"grab":"zoom-in",touchAction:"none"},children:w.jsx("img",{src:e,alt:t,draggable:!1,className:"max-w-full max-h-[85vh] object-contain rounded-lg select-none",style:{transform:`translate(${i.tx}px, ${i.ty}px) scale(${i.scale})`,transition:s?"none":"transform 0.08s ease-out",transformOrigin:"center center"}})}),w.jsxs("div",{className:"absolute bottom-3 left-1/2 -translate-x-1/2 flex items-center gap-1 rounded-full bg-background/90 border shadow-sm px-1.5 py-1 backdrop-blur",children:[w.jsx("button",{type:"button",onClick:()=>b(1/1.4),title:"Zoom out",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:!S,children:w.jsx(xG,{className:"w-4 h-4"})}),w.jsxs("span",{className:"text-xs tabular-nums w-11 text-center text-muted-foreground select-none",children:[Math.round(i.scale*100),"%"]}),w.jsx("button",{type:"button",onClick:()=>b(1.4),title:"Zoom in",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:i.scale>=P6,children:w.jsx(bG,{className:"w-4 h-4"})}),w.jsx("button",{type:"button",onClick:()=>a(bd),title:"Reset",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:!S,children:w.jsx(vE,{className:"w-4 h-4"})})]})]})}const bke=new Set(["p","li","h1","h2","h3","h4","h5","h6","blockquote","td","th"]),xke=()=>e=>{const t=n=>{for(const r of n.children??[])r.type==="element"&&(bke.has(r.tagName)&&(r.properties??(r.properties={}),r.properties.dir="auto"),t(r))};t(e)};var wD,ED;const wke=typeof window<"u"&&!!((ED=(wD=window.webkit)==null?void 0:wD.messageHandlers)!=null&&ED.appwrap);function Eke({text:e,onImageClick:t}){const n=e.replace(/\[Image #\d+\]\s*/g,"").trim();return wke?w.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert break-words min-w-0 whitespace-pre-wrap",children:n}):w.jsx(NL,{remarkPlugins:[ez],rehypePlugins:[Ez,xke],className:"prose prose-sm max-w-none dark:prose-invert prose-pre:bg-muted prose-pre:border prose-code:before:content-none prose-code:after:content-none break-words min-w-0",components:{pre:({children:r,...i})=>w.jsx(Lke,{...i,children:r}),a:({href:r,children:i})=>w.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",children:i}),img:({src:r,alt:i})=>w.jsx(SA,{src:r??"",alt:i??"",className:"max-h-[80vh] max-w-full rounded-xl border object-contain cursor-pointer hover:opacity-80 transition-opacity",onClick:a=>t==null?void 0:t(a)})},children:n})}function nD(e){const t=new Date(e),n=new Date,r=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(t.toDateString()===n.toDateString())return r;const i=t.getFullYear()===n.getFullYear();return`${t.toLocaleDateString([],{month:"short",day:"numeric",...!i&&{year:"numeric"}})}, ${r}`}const rD="shraga:showDetails",iD=150;function Ske({messages:e,busy:t,connectionStatus:n,onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c,multiParticipant:u,statusItems:f}){var Z;const p=_a(),h=y.useRef(null),m=y.useRef(null),v=y.useRef(!0),[x,b]=y.useState(()=>localStorage.getItem(rD)==="true"),[S,_]=y.useState(null),O=y.useRef({onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c});O.current={onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c};const k=y.useCallback((L,ae,me)=>{var de,Ee;return(Ee=(de=O.current).onPermissionRespond)==null?void 0:Ee.call(de,L,ae,me)},[]),T=y.useCallback((L,ae)=>{var me,de;return(de=(me=O.current).onQuestionRespond)==null?void 0:de.call(me,L,ae)},[]),C=y.useCallback((L,ae,me)=>{var de,Ee;return(Ee=(de=O.current).onReplay)==null?void 0:Ee.call(de,L,ae,me)},[]),N=y.useCallback((L,ae,me)=>{var de,Ee;return(Ee=(de=O.current).onEdit)==null?void 0:Ee.call(de,L,ae,me)},[]),P=y.useCallback(L=>{var ae,me;return(me=(ae=O.current).onFork)==null?void 0:me.call(ae,L)},[]),D=()=>{const L=m.current;L&&(v.current=L.scrollHeight-L.scrollTop-L.clientHeight<80)},j=y.useRef(new Map),I=y.useRef(new WeakSet),F=y.useRef(0),R=y.useMemo(()=>(Nke(j.current,I.current,e)&&F.current++,F.current),[e]),G=j.current,[q,K]=y.useState(iD),U=Math.max(0,e.length-q),W=U>0?e.slice(U):e,H=y.useCallback(()=>K(L=>L+iD),[]),Y=y.useRef(null),z=y.useRef(null);if(y.useEffect(()=>{const L=z.current;if(!L||U===0)return;const ae=new IntersectionObserver(me=>{if(!me.some(Ge=>Ge.isIntersecting)||v.current)return;const de=m.current,Ee=(de==null?void 0:de.scrollHeight)??0;Y.current={box:de,before:Ee},H()},{rootMargin:"400px"});return ae.observe(L),()=>ae.disconnect()},[U,q,H]),y.useEffect(()=>{const L=Y.current;L!=null&&L.box&&(Y.current=null,L.box.scrollTop+=L.box.scrollHeight-L.before)},[q]),y.useEffect(()=>{var L;v.current&&((L=h.current)==null||L.scrollIntoView({behavior:t?"auto":"smooth"}))},[e,t]),e.length===0&&!t)return w.jsx("div",{className:"flex-1 flex items-center justify-center",children:w.jsxs("div",{className:"text-center space-y-3 max-w-md px-4",children:[w.jsx("div",{className:"mx-auto w-12 h-12 rounded-full bg-muted flex items-center justify-center",children:w.jsx(du,{className:"w-6 h-6 text-muted-foreground"})}),w.jsx("h2",{className:"text-lg font-medium",children:"How can I help?"}),w.jsx("p",{className:"text-sm text-muted-foreground",children:"I can read files, edit code, run commands, search the web, and use any configured MCP tools on the remote machine."})]})});const $=()=>{b(L=>(localStorage.setItem(rD,String(!L)),!L))};return w.jsxs("div",{ref:m,onScroll:D,className:"flex-1 overflow-y-auto overflow-x-hidden",children:[w.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-4 sm:py-6 space-y-1",children:[w.jsx("div",{className:"flex justify-end mb-2",children:w.jsxs("button",{onClick:$,className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-xs text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:x?"Hide tool details":"Show tool details",children:[x?w.jsx(Jq,{className:"w-3.5 h-3.5"}):w.jsx(Qq,{className:"w-3.5 h-3.5"}),"Details"]})}),U>0&&w.jsxs("div",{ref:z,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:[U," earlier message",U===1?"":"s"," · scroll up to load"]}),W.map((L,ae)=>{const me=U+ae;return w.jsx(_ke,{message:L,messageIndex:me,isLast:me===e.length-1,showDetails:x,onPermissionRespond:k,onQuestionRespond:T,onReplay:C,onEdit:N,onFork:P,onImageClick:_,busy:t&&me===e.length-1,screenMap:G,screenVersion:R,multiParticipant:u},L.id)}),t&&((Z=e[e.length-1])==null?void 0:Z.role)!=="assistant"&&w.jsxs("div",{className:"flex gap-3 py-4",children:[w.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:w.jsx(du,{className:"w-4 h-4 text-muted-foreground"})}),w.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:w.jsxs("span",{className:"inline-flex gap-1",children:[w.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce",style:{animationDelay:"0ms"}}),w.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce",style:{animationDelay:"150ms"}}),w.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce",style:{animationDelay:"300ms"}})]})})]}),!!(f!=null&&f.length)&&p.statusChips&&w.jsxs("div",{className:"flex gap-3 py-2",children:[w.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:w.jsx(du,{className:"w-4 h-4 text-muted-foreground"})}),w.jsx("div",{className:"flex-1 min-w-0 pt-1",children:p.statusChips(f)})]}),n&&n!=="update_available"&&w.jsx("div",{className:Ue("text-center text-xs py-1.5 rounded-md transition-opacity",n==="reconnected"?"text-green-600 dark:text-green-400":"text-amber-600 dark:text-amber-400"),children:n==="server_restarting"?"Server updating — reconnecting automatically…":n==="disconnected"?"Connection lost — reconnecting...":"Reconnected."}),w.jsx("div",{ref:h})]}),w.jsx(_s,{open:!!S,onOpenChange:L=>{L||_(null)},children:w.jsx(ho,{className:"max-w-[90vw] max-h-[90vh] w-[90vw] h-[90vh] p-2 flex items-center justify-center bg-background/95",children:S&&w.jsx(yke,{src:S})})})]})}const _ke=y.memo(function({message:t,messageIndex:n,isLast:r,showDetails:i,onPermissionRespond:a,onQuestionRespond:s,onReplay:c,onEdit:u,onFork:f,onImageClick:p,busy:h,screenMap:m,multiParticipant:v}){var F;const x=t.blocks.find(R=>R.type==="compact_marker");if(x&&x.type==="compact_marker")return w.jsx(Ake,{summary:x.summary,compactedCount:x.compactedCount});const b=t.role==="user",S=b?((F=t.blocks.find(R=>R.type==="text"))==null?void 0:F.text)??"":"",_=b?t.blocks.filter(R=>R.type==="image"||R.type==="file").map(R=>R.type==="image"?{url:R.src,name:R.src.split("/").pop()??"image",mimeType:"image/png",path:R.src}:{url:R.src,name:R.name,mimeType:R.mimeType,path:R.src}):void 0,[O,k]=y.useState(!1),[T,C]=y.useState(""),[N,P]=y.useState(!1),D=y.useRef(null),j=()=>{C(S),k(!0),setTimeout(()=>{const R=D.current;R&&(R.style.height="auto",R.style.height=R.scrollHeight+"px",R.focus(),R.setSelectionRange(R.value.length,R.value.length))},0)},I=()=>{const R=T.trim();R&&(k(!1),u==null||u(t.id,R,_!=null&&_.length?_:void 0))};return w.jsxs("div",{className:Ue("flex gap-3 py-4 group/row",b&&"flex-row-reverse"),onTouchStart:R=>{R.target.closest("button")||P(G=>!G)},children:[!b&&w.jsx("div",{className:"w-7 h-7 rounded-full bg-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:w.jsx(du,{className:"w-4 h-4 text-primary"})}),b&&w.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:w.jsx(vG,{className:"w-4 h-4 text-muted-foreground"})}),w.jsxs("div",{className:Ue("min-w-0 max-w-[92%] sm:max-w-[85%] space-y-2"),children:[v&&b&&t.senderName&&w.jsx("div",{className:"text-[11px] font-medium text-muted-foreground text-right px-1",children:t.senderName}),O?w.jsxs("div",{className:"inline-block text-left w-full",children:[w.jsx("textarea",{ref:D,value:T,onChange:R=>{C(R.target.value),R.target.style.height="auto",R.target.style.height=R.target.scrollHeight+"px"},onKeyDown:R=>{R.key==="Enter"&&!R.shiftKey&&(R.preventDefault(),I()),R.key==="Escape"&&k(!1)},className:"w-full rounded-xl border bg-muted/50 px-4 py-2.5 text-sm resize-none outline-none focus:ring-1 focus:ring-primary min-h-[40px]"}),w.jsxs("div",{className:"flex gap-1 justify-end mt-1",children:[w.jsx("button",{onClick:()=>k(!1),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Cancel",children:w.jsx(jl,{className:"w-3.5 h-3.5"})}),w.jsx("button",{onClick:I,className:"p-1 rounded-md text-primary hover:bg-primary/10 transition-colors",title:"Send",children:w.jsx(og,{className:"w-3.5 h-3.5"})})]})]}):w.jsxs(w.Fragment,{children:[t.blocks.filter(R=>i?!0:R.type==="tool_use"&&R.tool==="AskUserQuestion"?t.blocks.some(G=>G.type==="tool_result"&&G.toolUseId===R.toolUseId):R.type!=="tool_use"&&R.type!=="tool_result"&&R.type!=="thinking").filter(R=>R.type!=="tool_result"?!0:!t.blocks.some(G=>G.type==="tool_use"&&G.toolUseId===R.toolUseId)).map((R,G,q)=>{const K=R.type==="tool_use"?t.blocks.find(U=>U.type==="tool_result"&&U.toolUseId===R.toolUseId):void 0;return w.jsx(kke,{block:R,isUser:b,ts:t.ts,onPermissionRespond:a,onQuestionRespond:s,pairedResult:K,onImageClick:p,busy:h,screenMap:m},G)}),b&&S&&w.jsxs("div",{className:Ue("flex gap-1 items-center justify-end transition-opacity",N?"opacity-100":"opacity-0 group-hover/row:opacity-100"),children:[t.ts&&w.jsx("span",{className:"text-[10px] text-muted-foreground/50 select-none mr-1",children:nD(t.ts)}),w.jsx("button",{onClick:()=>c==null?void 0:c(t.id,S,_!=null&&_.length?_:void 0),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Replay",children:w.jsx(dG,{className:"w-3.5 h-3.5"})}),w.jsx("button",{onClick:j,className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Edit & resend",children:w.jsx(bE,{className:"w-3.5 h-3.5"})})]}),!b&&!(h&&r)&&w.jsxs("div",{className:Ue("flex gap-1 items-center transition-opacity",N?"opacity-100":"opacity-0 group-hover/row:opacity-100"),children:[t.ts&&w.jsx("span",{className:"text-[10px] text-muted-foreground/40 select-none mr-1",children:nD(t.ts)}),w.jsx("button",{onClick:()=>f==null?void 0:f(n),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Fork from here",children:w.jsx(Cj,{className:"w-3.5 h-3.5"})})]})]})]})]})});function Ake({summary:e,compactedCount:t}){const[n,r]=y.useState(!1);return w.jsxs("div",{className:"py-3",children:[w.jsxs("div",{className:"flex items-center gap-3",children:[w.jsx("div",{className:"flex-1 border-t border-amber-500/30"}),w.jsxs("button",{onClick:()=>r(!n),className:"flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium bg-amber-500/10 text-amber-600 dark:text-amber-400 border border-amber-500/20 hover:bg-amber-500/20 transition-colors",children:[w.jsx(yE,{className:"w-3 h-3"}),"Compacted · ",t," messages",w.jsx(Ps,{className:Ue("w-3 h-3 transition-transform",n&&"rotate-90")})]}),w.jsx("div",{className:"flex-1 border-t border-amber-500/30"})]}),n&&w.jsx("div",{className:"mt-2 mx-auto max-w-2xl px-4 py-3 rounded-lg border border-amber-500/20 bg-amber-500/5 text-xs text-muted-foreground whitespace-pre-wrap",children:e})]})}function kke({block:e,isUser:t,ts:n,onPermissionRespond:r,onQuestionRespond:i,pairedResult:a,onImageClick:s,busy:c,screenMap:u}){var p;const f=_a();return e.type==="image"?w.jsx(SA,{src:e.src,className:"max-h-[80vh] max-w-full rounded-xl border object-contain cursor-pointer hover:opacity-80 transition-opacity",onClick:h=>s==null?void 0:s(h)}):e.type==="file"?w.jsx("div",{children:w.jsx(vke,{src:e.src,name:e.name,className:"inline-flex items-center gap-2 px-3 py-2 rounded-lg border bg-muted/50 text-sm text-muted-foreground hover:bg-muted transition-colors"})}):e.type==="context"?w.jsx(Cke,{label:e.label,text:e.text}):e.type==="thinking"?w.jsx(Tke,{text:e.text}):e.type==="error"?w.jsx(Oke,{text:e.text,ts:n}):e.type==="text"?t?w.jsx("div",{dir:"auto",className:"inline-block bg-primary text-primary-foreground rounded-2xl rounded-tr-sm px-4 py-2.5 text-sm break-words min-w-0 max-w-full whitespace-pre-wrap",children:e.text}):w.jsx("div",{className:"text-sm",dir:"auto",children:w.jsx(Eke,{text:e.text,onImageClick:s})}):e.type==="tool_use"?e.tool==="AskUserQuestion"&&(a!=null&&a.output)?w.jsx(Ike,{input:e.input,result:a.output}):w.jsx(Rke,{block:e,tool:e.tool,input:e.input,result:a==null?void 0:a.output,busy:c,screenMap:u}):e.type==="tool_result"?w.jsx(Pke,{output:e.output}):e.type==="permission_request"?w.jsx(Dke,{id:e.id,tool:e.tool,input:e.input,onRespond:r}):e.type==="question_request"?w.jsx(jke,{id:e.id,questions:e.questions,onRespond:i}):((p=f.extensionBlocks)==null?void 0:p.call(f,{block:e,onImageClick:s}))??null}function Oke({text:e,ts:t}){const n=$ne(e,t??Date.now());return w.jsxs("div",{dir:"auto",className:"border border-destructive/40 rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive break-words",children:[w.jsx("span",{className:"font-medium",children:"⚠️ Run failed"}),w.jsx("div",{className:"mt-1 text-xs opacity-90 whitespace-pre-wrap font-mono",children:n})]})}function Cke({label:e,text:t}){const[n,r]=y.useState(!1);return w.jsxs("div",{className:"border border-blue-500/20 rounded-lg overflow-hidden text-xs bg-blue-500/5",children:[w.jsxs("button",{onClick:()=>r(!n),className:"flex items-center gap-1.5 w-full px-3 py-2 hover:bg-blue-500/10 transition-colors text-left",children:[w.jsx(iG,{className:"w-3.5 h-3.5 text-blue-400 shrink-0"}),w.jsx("span",{className:"text-blue-300 font-medium",children:e}),w.jsx(Ps,{className:Ue("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",n&&"rotate-90")})]}),n&&w.jsx("div",{className:"px-3 py-2 border-t border-blue-500/20 text-muted-foreground whitespace-pre-wrap",children:t})]})}function Tke({text:e}){const[t,n]=y.useState(!1),r=e.slice(0,120).replace(/\n/g," ");return w.jsxs("div",{className:"border border-violet-500/20 rounded-lg overflow-hidden text-xs bg-violet-500/5",children:[w.jsxs("button",{onClick:()=>n(!t),className:"flex items-center gap-1.5 w-full px-3 py-2 hover:bg-violet-500/10 transition-colors text-left",children:[w.jsx(Yq,{className:"w-3.5 h-3.5 text-violet-400 shrink-0"}),w.jsx("span",{className:"text-violet-300 font-medium",children:"Thinking"}),w.jsx("span",{className:"text-muted-foreground truncate",children:r}),w.jsx(Ps,{className:Ue("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",t&&"rotate-90")})]}),t&&w.jsx("div",{className:"px-3 py-2 border-t border-violet-500/20 text-muted-foreground whitespace-pre-wrap",children:e})]})}function Nke(e,t,n){let r=!1;for(const i of n)for(const a of i.blocks)if(!(a.type!=="tool_result"||!a.output)&&!t.has(a)&&(t.add(a),!!a.output.includes('"screen"')))try{const s=JSON.parse(a.output);typeof(s==null?void 0:s.sessionId)=="string"&&Array.isArray(s==null?void 0:s.screen)&&(e.set(s.sessionId,s.screen),r=!0)}catch{}return r}function Mke(e){const t={},n=/"([^"]+)"="([^"]+)"/g;let r;for(;(r=n.exec(e))!==null;)t[r[1]]=r[2];return t}function Ike({input:e,result:t}){const n=e,r=(n==null?void 0:n.questions)??[],i=Mke(t);return!r.length||!Object.keys(i).length?null:w.jsxs("div",{className:"border rounded-lg overflow-hidden text-xs bg-blue-500/5 border-blue-500/20",children:[w.jsxs("div",{className:"flex items-center gap-1.5 px-2 sm:px-3 py-2 bg-blue-50 dark:bg-blue-950/40",children:[w.jsx(xE,{className:"w-3.5 h-3.5 text-blue-400 shrink-0"}),w.jsx("span",{className:"font-medium text-blue-300",children:"Questions answered"})]}),w.jsx("div",{className:"px-2 sm:px-3 py-2 space-y-2",children:r.map((a,s)=>{const c=i[a.question];return c?w.jsxs("div",{className:"space-y-0.5",children:[w.jsxs("div",{className:"text-muted-foreground",children:[a.header?`${a.header}: `:"",a.question]}),w.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-300 font-medium",children:[w.jsx(pa,{className:"w-2.5 h-2.5"}),c]})]},s):null})})]})}function Rke({block:e,tool:t,input:n,result:r,busy:i,screenMap:a}){var S;const s=_a(),[c,u]=y.useState(!1),f=typeof n=="string"?n:JSON.stringify(n,null,2),p=typeof n=="object"&&n!==null&&Object.keys(n).length===0,h=p?"":Yae(n),m=r!=null?D6(r.trim().replace(/\[Image #\d+\]\s*/g,"").trim()):void 0,v=r!=null,x=m?/^(Error|ERROR)|"status"\s*:\s*[45]\d\d|ENOENT|EACCES|Permission denied|command not found|No such file/i.test(m):!1,b=v?x?w.jsx(ag,{className:"w-3 h-3 text-red-400 shrink-0"}):w.jsx(pa,{className:"w-3 h-3 text-green-400 shrink-0"}):null;return w.jsxs("div",{className:"text-xs min-w-0 space-y-2",children:[w.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[w.jsxs("button",{onClick:()=>u(!c),className:"flex items-center gap-1.5 w-full px-2 sm:px-3 py-2 bg-muted/50 hover:bg-muted transition-colors text-left min-w-0",children:[w.jsx(yG,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"}),w.jsx("span",{className:"font-medium text-foreground shrink-0",children:t}),!p&&w.jsx("span",{className:"text-muted-foreground truncate min-w-0",children:h}),v?b:i?w.jsx(Pd,{className:"w-3 h-3 text-muted-foreground animate-spin shrink-0"}):w.jsx("span",{title:"Interrupted",children:w.jsx(ag,{className:"w-3 h-3 text-amber-400 shrink-0"})}),w.jsx(Ps,{className:Ue("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",c&&"rotate-90")})]}),c&&w.jsxs("div",{className:"border-t",children:[!p&&w.jsx("pre",{className:"p-3 overflow-auto max-h-64 text-xs bg-background whitespace-pre-wrap break-all",children:f}),m&&w.jsx("pre",{className:Ue("p-3 overflow-auto max-h-64 text-xs whitespace-pre-wrap break-words",!p&&"border-t",x?"bg-red-50 dark:bg-red-950/20 text-red-700 dark:text-red-300":"bg-muted/30 text-foreground/80"),children:m})]})]}),(S=s.toolRenderers)==null?void 0:S.call(s,{block:e,result:r,screens:a})]})}function D6(e){const t=e.split(`
1943
1943
  `);return t.length<2||!t.filter(r=>r.length>0).every(r=>/^\s*\d+\t/.test(r))?e:t.map(r=>r.replace(/^\s*\d+\t/,"")).join(`
1944
1944
  `)}function Pke({output:e}){const[t,n]=y.useState(!1),{trimmed:r,isError:i,chartData:a,isLong:s,preview:c}=y.useMemo(()=>{const m=e.trim().replace(/\[Image #\d+\]\s*/g,"").trim(),v=D6(m),x=/^(Error|ERROR)|"status"\s*:\s*[45]\d\d|ENOENT|EACCES|Permission denied|command not found|No such file/i.test(v);return{trimmed:v,isError:x,chartData:x?null:uke(v),isLong:v.length>200,preview:v.slice(0,120).replace(/\n/g," ")}},[e]);if(!r)return null;const u=i?ag:pa,f=i?"border-red-200 dark:border-red-900":"border-green-200 dark:border-green-900",p=i?"bg-red-50 dark:bg-red-950/30 hover:bg-red-100 dark:hover:bg-red-950/50":"bg-green-50 dark:bg-green-950/30 hover:bg-green-100 dark:hover:bg-green-950/50",h=i?"text-red-600 dark:text-red-400":"text-green-600 dark:text-green-400";return w.jsxs("div",{className:Ue("border rounded-lg overflow-hidden text-xs min-w-0",f),children:[w.jsxs("button",{onClick:()=>n(!t),className:Ue("flex items-center gap-1.5 w-full px-2 sm:px-3 py-2 transition-colors text-left min-w-0",p),children:[w.jsx(u,{className:Ue("w-3.5 h-3.5 shrink-0",h)}),w.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:s?c+"…":c}),w.jsx(Ps,{className:Ue("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0",t&&"rotate-90")})]}),t&&w.jsx("div",{className:"p-3 bg-background border-t",children:a?w.jsx(gke,{data:a}):w.jsx("pre",{className:"overflow-auto max-h-96 text-xs whitespace-pre-wrap break-words",children:r})})]})}function Dke({id:e,tool:t,input:n,onRespond:r}){const[i,a]=y.useState(!1),s=JSON.stringify(n,null,2),c=Object.keys(n).join(", ");return w.jsxs("div",{className:"border-2 rounded-lg overflow-hidden text-xs border-amber-300 dark:border-amber-700 animate-in fade-in slide-in-from-bottom-2 min-w-0",children:[w.jsxs("div",{className:"flex items-center gap-1.5 px-2 sm:px-3 py-2 bg-amber-50 dark:bg-amber-950/40 min-w-0",children:[w.jsx(xE,{className:"w-4 h-4 text-amber-600 dark:text-amber-400 shrink-0"}),w.jsx("span",{className:"font-medium text-foreground shrink-0",children:t}),w.jsxs("button",{onClick:()=>a(!i),className:"text-muted-foreground truncate min-w-0 text-left hover:text-foreground transition-colors",children:[c,w.jsx(Ps,{className:Ue("w-3.5 h-3.5 inline ml-1 transition-transform",i&&"rotate-90")})]})]}),i&&w.jsx("pre",{className:"p-3 overflow-auto max-h-48 text-xs bg-background border-t border-amber-200 dark:border-amber-800 whitespace-pre-wrap break-all",children:s}),w.jsxs("div",{className:"flex flex-wrap gap-2 px-2 sm:px-3 py-2 bg-amber-50/50 dark:bg-amber-950/20 border-t border-amber-200 dark:border-amber-800",children:[w.jsxs("button",{onClick:()=>r==null?void 0:r(e,!0),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium bg-green-600 text-white hover:bg-green-700 transition-colors",children:[w.jsx(HT,{className:"w-3.5 h-3.5"}),"Allow"]}),w.jsxs("button",{onClick:()=>r==null?void 0:r(e,!0,!0),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium border border-green-600 text-green-700 dark:text-green-400 hover:bg-green-50 dark:hover:bg-green-950/30 transition-colors",children:[w.jsx(HT,{className:"w-3.5 h-3.5"}),"Always Allow"]}),w.jsxs("button",{onClick:()=>r==null?void 0:r(e,!1),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium bg-red-600 text-white hover:bg-red-700 transition-colors",children:[w.jsx(ag,{className:"w-3.5 h-3.5"}),"Deny"]})]})]})}function jke({id:e,questions:t,onRespond:n}){const[r,i]=y.useState({}),[a,s]=y.useState({}),[c,u]=y.useState(!1),f=_a();y.useEffect(()=>{var b;return(b=f.onCardInteraction)==null?void 0:b.call(f,{id:e,questions:t,onAnswers:S=>{i(()=>{const _={};return t.forEach((O,k)=>{const T=S[O.question];T!=null&&(_[k]=new Set(Array.isArray(T)?T:[T]))}),_})}})},[e,t,f]);const p=(b,S,_)=>{i(O=>{const k=new Set(O[b]??[]);return _?k.has(S)?k.delete(S):k.add(S):(k.clear(),k.add(S)),{...O,[b]:k}})},h="__other__",m=t.filter((b,S)=>{var O;const _=r[S];return!(!_||_.size===0||_.has(h)&&!((O=a[S])!=null&&O.trim()))}).length,v=m===t.length,x=()=>{if(!v||c)return;const b={};t.forEach((S,_)=>{const O=[...r[_]??[]].map(k=>k===h?a[_].trim():k);b[S.question]=S.multiSelect?O:O[0]}),u(!0),n==null||n(e,b)};return w.jsxs("div",{className:"border-2 rounded-lg overflow-hidden text-xs border-blue-300 dark:border-blue-700 animate-in fade-in slide-in-from-bottom-2 min-w-0",children:[w.jsxs("div",{className:"flex items-center gap-1.5 px-2 sm:px-3 py-2 bg-blue-50 dark:bg-blue-950/40",children:[w.jsx(xE,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0"}),w.jsx("span",{className:"font-medium text-foreground",children:"Questions for you"})]}),w.jsx("div",{className:"px-2 sm:px-3 py-2 space-y-4 bg-background",children:t.map((b,S)=>{const _=!!b.multiSelect,O=r[S]??new Set;return w.jsxs("div",{className:"space-y-1.5",children:[w.jsx("div",{className:"font-medium text-foreground",children:b.question}),w.jsxs("div",{className:"space-y-1",children:[b.options.map(k=>w.jsxs("button",{disabled:c,onClick:()=>p(S,k.label,_),className:Ue("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md border transition-colors",O.has(k.label)?"border-blue-500 bg-blue-50 dark:bg-blue-950/40":"border-border hover:bg-muted/50"),children:[w.jsx("span",{className:Ue("mt-0.5 w-3.5 h-3.5 shrink-0 border flex items-center justify-center",_?"rounded-sm":"rounded-full",O.has(k.label)?"bg-blue-500 border-blue-500":"border-muted-foreground"),children:O.has(k.label)&&w.jsx(pa,{className:"w-2.5 h-2.5 text-white"})}),w.jsxs("span",{className:"min-w-0",children:[w.jsx("span",{className:"font-medium text-foreground",children:k.label}),k.description&&w.jsxs("span",{className:"text-muted-foreground",children:[" — ",k.description]})]})]},k.label)),w.jsxs("div",{className:Ue("flex items-center gap-2 px-2 py-1.5 rounded-md border",O.has(h)?"border-blue-500 bg-blue-50 dark:bg-blue-950/40":"border-border"),children:[w.jsx("button",{disabled:c,onClick:()=>p(S,h,_),className:Ue("w-3.5 h-3.5 shrink-0 border flex items-center justify-center",_?"rounded-sm":"rounded-full",O.has(h)?"bg-blue-500 border-blue-500":"border-muted-foreground"),children:O.has(h)&&w.jsx(pa,{className:"w-2.5 h-2.5 text-white"})}),w.jsx("input",{type:"text",disabled:c,value:a[S]??"",placeholder:"Other…",onChange:k=>{s(T=>({...T,[S]:k.target.value})),k.target.value&&!O.has(h)&&p(S,h,_)},className:"flex-1 bg-transparent outline-none text-foreground placeholder:text-muted-foreground"})]})]})]},S)})}),w.jsxs("div",{className:"flex items-center gap-2 px-2 sm:px-3 py-2 bg-blue-50/50 dark:bg-blue-950/20 border-t border-blue-200 dark:border-blue-800",children:[w.jsxs("button",{onClick:x,disabled:!v||c,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium bg-blue-600 text-white hover:bg-blue-700 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[w.jsx(og,{className:"w-3.5 h-3.5"}),c?"Sent":"Submit"]}),w.jsxs("span",{className:"text-muted-foreground",children:[m,"/",t.length," answered"]})]})]})}function Lke({children:e,...t}){const n=y.useRef(null);return w.jsxs("div",{className:"relative group",children:[w.jsx("pre",{ref:n,...t,className:"rounded-lg border bg-muted p-4 overflow-x-auto text-xs text-foreground",children:e}),w.jsx(zke,{getText:()=>{var r;return((r=n.current)==null?void 0:r.textContent)||""}})]})}function zke({getText:e}){const[t,n]=y.useState(!1);return w.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e()),n(!0),setTimeout(()=>n(!1),2e3)},className:"absolute top-2 right-2 p-1.5 rounded-md bg-background/80 border opacity-0 group-hover:opacity-100 transition-opacity",title:"Copy",children:t?w.jsx(pa,{className:"w-3 h-3"}):w.jsx(mE,{className:"w-3 h-3"})})}const j6=y.forwardRef(function({value:t,onChange:n,onKeyDown:r,onPaste:i,skills:a=[],workspaceFiles:s=[],placeholder:c,className:u,rows:f=1,disabled:p,autoResize:h=!0,maxHeight:m=200},v){const x=y.useRef(null),[b,S]=y.useState(null),[_,O]=y.useState(0);y.useImperativeHandle(v,()=>({focus:()=>{var D;return(D=x.current)==null?void 0:D.focus()},setValue:D=>{n(D),h&&T()}}));const k=b?[...a.filter(D=>D.toLowerCase().includes(b.query.toLowerCase())).map(D=>({kind:"skill",value:D})),...b.kind==="mention"?s.filter(D=>D.toLowerCase().includes(b.query.toLowerCase())).map(D=>({kind:"workspace",value:D})):[]]:[];function T(){setTimeout(()=>{const D=x.current;D&&(D.style.height="auto",D.style.height=Math.min(D.scrollHeight,m)+"px")},0)}const C=D=>{if(!b)return;const j=b.kind==="command"?"/":"@",I=t.slice(0,b.start),F=t.slice(b.start+b.query.length+1),R=`${I}${j}${D} ${F}`;n(R),S(null),setTimeout(()=>{const G=x.current;if(!G)return;h&&(G.style.height="auto",G.style.height=Math.min(G.scrollHeight,m)+"px");const q=I.length+D.length+2;G.setSelectionRange(q,q),G.focus()},0)},N=D=>{if(b&&k.length>0){if(D.key==="ArrowDown"){D.preventDefault(),O(j=>(j+1)%k.length);return}if(D.key==="ArrowUp"){D.preventDefault(),O(j=>(j-1+k.length)%k.length);return}if(D.key==="Enter"||D.key==="Tab"){D.preventDefault(),C(k[_].value);return}if(D.key==="Escape"){S(null);return}}r==null||r(D)},P=D=>{const j=D.target.value;n(j);const I=D.target;h&&(I.style.height="auto",I.style.height=Math.min(I.scrollHeight,m)+"px");const F=I.selectionStart??j.length,R=j.slice(0,F),G=R.match(/(?:^|\n)\/([\w-]*)$/),q=R.match(/@([\w\-./]*)$/);G?(S({query:G[1],start:G.index+(R[G.index]===`
1945
- `?1:0),kind:"command"}),O(0)):q?(S({query:q[1],start:q.index,kind:"mention"}),O(0)):S(null)};return y.useEffect(()=>{const D=()=>S(null);return b&&document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[b]),w.jsxs("div",{className:"relative flex-1 min-w-0",children:[b&&k.length>0&&w.jsx("div",{className:"absolute bottom-full mb-1 left-0 z-50 bg-background border rounded-lg shadow-lg overflow-hidden min-w-[220px] max-h-64 overflow-y-auto",children:k.map((D,j)=>w.jsxs("button",{onMouseDown:I=>{I.preventDefault(),C(D.value)},className:`w-full text-left px-3 py-1.5 text-sm hover:bg-accent transition-colors flex items-center gap-2 ${j===_?"bg-accent":""}`,children:[w.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground shrink-0 w-14",children:(b==null?void 0:b.kind)==="command"?"cmd":D.kind==="skill"?"skill":"file"}),w.jsxs("span",{className:"truncate",children:[w.jsx("span",{className:"text-muted-foreground",children:(b==null?void 0:b.kind)==="command"?"/":"@"}),D.value]})]},`${D.kind}:${D.value}`))}),w.jsx("textarea",{ref:x,value:t,onChange:P,onKeyDown:N,onPaste:i,placeholder:c,disabled:p,rows:f,dir:"auto",className:u})]})}),_A="shraga:draft:";function ow(e,t){const n=_A+(e??"new");t.trim()?localStorage.setItem(n,t):localStorage.removeItem(n)}function aD(e){return localStorage.getItem(_A+(e??"new"))??""}function oD(e){localStorage.removeItem(_A+(e??"new"))}const $ke=y.forwardRef(function({onSend:t,onSteer:n,onQueue:r,onRemoveQueued:i,queue:a,onUpload:s,onCancel:c,disabled:u,busy:f,skills:p=[],workspaceFiles:h=[],sessionId:m,inputCtx:v},x){var U,W;const b=_a(),[S,_]=y.useState(()=>aD(m)),[O,k]=y.useState([]),[T,C]=y.useState(!1),N=y.useRef(null),P=y.useRef(null),D=y.useRef(m);y.useEffect(()=>{var z;if(D.current===m)return;const H=D.current;if(D.current=m,!m){oD(H),ow(void 0,S);return}ow(H,S);const Y=aD(m);_(Y),(z=P.current)==null||z.setValue(Y)},[m]);const j=y.useCallback(H=>{_(H),ow(D.current,H)},[]);y.useImperativeHandle(x,()=>({prefill(H){var Y,z;j(H),(Y=P.current)==null||Y.setValue(H),(z=P.current)==null||z.focus()},setText(H){var Y;j(H),(Y=P.current)==null||Y.setValue(H)},focus(){var H;(H=P.current)==null||H.focus()}}));const I=(H="send")=>{var z;const Y=S.trim();!Y&&O.length===0||(H==="steer"?n(Y):H==="queue"?r(Y):t(Y,O.length>0?O:void 0),_(""),oD(D.current),k([]),(z=P.current)==null||z.setValue(""))},F=typeof window<"u"&&((U=window.matchMedia)==null?void 0:U.call(window,"(pointer: coarse)").matches),R=H=>{if(H.key==="Enter"&&!H.shiftKey&&(!F||H.metaKey||H.ctrlKey)){H.preventDefault(),I(f?"steer":"send");return}if(H.key==="Tab"&&f&&S.trim()){H.preventDefault(),I("queue");return}},G=y.useCallback(async H=>{C(!0);try{const Y=await s(H);Y&&k(z=>[...z,Y])}finally{C(!1)}},[s]),q=y.useCallback(H=>{const Y=Array.from(H.clipboardData.items);for(const z of Y)if(z.type.startsWith("image/")||z.type==="application/pdf"){const $=z.getAsFile();$&&G($)}},[G]),K=H=>{var z;const Y=(z=H.target.files)==null?void 0:z[0];Y&&(G(Y),H.target.value="")};return w.jsx("div",{className:"border-t bg-background",style:{paddingBottom:"env(safe-area-inset-bottom)"},children:w.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-3",children:[(O.length>0||T)&&w.jsxs("div",{className:"flex gap-2 mb-2 flex-wrap items-center",children:[O.map((H,Y)=>w.jsxs("div",{className:"relative group",children:[H.mimeType.startsWith("image/")?w.jsx(SA,{src:H.url,alt:H.name,className:"h-16 w-16 object-cover rounded-lg border"}):w.jsxs("div",{className:"h-16 px-3 flex items-center gap-2 rounded-lg border bg-muted/50 text-xs text-muted-foreground",children:[w.jsx(gE,{className:"w-4 h-4 shrink-0"}),w.jsx("span",{className:"truncate max-w-[120px]",children:H.name})]}),w.jsx("button",{onClick:()=>k(z=>z.filter(($,Z)=>Z!==Y)),className:"absolute -top-1.5 -right-1.5 bg-destructive text-destructive-foreground rounded-full w-5 h-5 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity shadow-sm",children:w.jsx(jl,{className:"w-3 h-3"})})]},Y)),T&&w.jsx("span",{className:"text-xs text-muted-foreground animate-pulse",children:"Uploading…"})]}),w.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-xl border px-3 py-2",children:[w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:()=>{var H;return(H=N.current)==null?void 0:H.click()},disabled:u,title:"Attach file or image",children:w.jsx(cG,{className:"w-4 h-4"})}),w.jsx("input",{ref:N,type:"file",className:"hidden",onChange:K}),w.jsx(j6,{ref:P,value:S,onChange:j,onKeyDown:R,onPaste:q,skills:p,workspaceFiles:h,placeholder:f?"Steer or queue…":"Message Claude…",disabled:u,rows:1,className:"w-full bg-transparent border-none outline-none resize-none text-sm py-1.5 placeholder:text-muted-foreground min-h-[28px] max-h-[200px]"}),(W=b.inputAdornments)==null?void 0:W.call(b,v),f?w.jsxs("div",{className:"flex items-center gap-2",children:[S.trim()&&w.jsx(Ne,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>I("steer"),title:"Steer (inject into current turn)",children:w.jsx(og,{className:"w-4 h-4"})}),w.jsx(Ne,{variant:"destructive",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>c(),title:"Stop generation",children:w.jsx(Mj,{className:"w-3.5 h-3.5"})})]}):w.jsx(Ne,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>I(),disabled:u||T||!S.trim()&&O.length===0,children:w.jsx(og,{className:"w-4 h-4"})})]}),a.length>0&&w.jsx("div",{className:"flex gap-1.5 flex-wrap mt-2",children:a.map((H,Y)=>w.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-50 dark:bg-blue-950/40 px-2.5 py-1 text-xs text-blue-700 dark:text-blue-300 ring-1 ring-inset ring-blue-600/20 dark:ring-blue-400/30",children:[w.jsx("span",{className:"truncate max-w-[200px]",children:H}),w.jsx("button",{onClick:()=>i(Y),className:"hover:text-blue-900 dark:hover:text-blue-100",children:w.jsx(jl,{className:"w-3 h-3"})})]},Y))}),w.jsx("p",{className:"text-[10px] text-muted-foreground text-center mt-2",children:f?"Enter to steer (redirect) · Tab to queue (after done) · Shift+Enter for newline":"Enter to send · Shift+Enter for newline · @ for skills · / for commands"})]})})}),Bke={"fb-feed":[1080,1080],"fb-story":[1080,1920],"fb-landscape":[1200,628],"ig-square":[1080,1080],"ig-story":[1080,1920],"ig-landscape":[1080,566],"banner-leaderboard":[728,90],"banner-medium":[300,250]};function Uke({artifacts:e,selectedId:t,sessionId:n,getToken:r,onSelect:i,onClose:a}){var P;const[s,c]=y.useState(!1),[u,f]=y.useState(!1),[p,h]=y.useState(!1),[m,v]=y.useState(1),x=y.useRef(null),b=e.find(D=>D.id===t),S=y.useCallback(()=>{if(!x.current||!b)return;const{clientWidth:D,clientHeight:j}=x.current,I=32,F=D-I,R=j-I,[G,q]=b.dimensions;v(Math.min(F/G,R/q,1))},[b]);y.useEffect(()=>{let D=!0;return r().then(j=>fetch("/api/features",{headers:j?{Authorization:`Bearer ${j}`}:{}})).then(j=>j.json()).then(j=>{D&&h(!!j.artifactPngExport)}).catch(j=>console.error("[artifact] features fetch failed:",j)),()=>{D=!1}},[r]),y.useEffect(()=>{S();const D=x.current;if(!D)return;const j=new ResizeObserver(S);return j.observe(D),()=>j.disconnect()},[S]);const _=async()=>{if(b){f(!0);try{const D=await r(),j=await fetch(`/api/artifacts/${n}/${b.id}/export`,{method:"POST",headers:{"Content-Type":"application/json",...D?{Authorization:`Bearer ${D}`}:{}},body:JSON.stringify({dimensions:b.dimensions})});if(!j.ok)throw new Error(await j.text());const I=await j.blob(),F=URL.createObjectURL(I),R=document.createElement("a");R.href=F,R.download=`${b.title.replace(/\s+/g,"-").toLowerCase()}.png`,R.click(),URL.revokeObjectURL(F)}catch(D){console.error("[artifact] export failed:",D)}finally{f(!1)}}},O=b?(P=Object.entries(Bke).find(([,D])=>D[0]===b.dimensions[0]&&D[1]===b.dimensions[1]))==null?void 0:P[0]:null,[k,T]=(b==null?void 0:b.dimensions)??[0,0],C=k*m,N=T*m;return w.jsxs("div",{className:Ue("flex flex-col border-l bg-background transition-all",s?"fixed inset-0 z-50":"fixed inset-0 z-50 sm:relative sm:inset-auto sm:z-auto sm:w-[480px] sm:shrink-0"),children:[w.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b bg-muted/30",children:[w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-7 w-7 sm:hidden shrink-0",onClick:a,title:"Back to chat",children:w.jsx(kj,{className:"w-4 h-4"})}),e.length>1&&w.jsx("select",{className:"text-xs bg-transparent border rounded px-1 py-0.5 max-w-[160px] truncate",value:t??"",onChange:D=>i(D.target.value),children:e.map(D=>w.jsx("option",{value:D.id,children:D.title},D.id))}),e.length<=1&&b&&w.jsx("span",{className:"text-xs font-medium truncate max-w-[160px]",children:b.title}),b&&w.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[O??`${k}×${T}`,m<1&&` · ${Math.round(m*100)}%`]}),w.jsx("div",{className:"flex-1"}),p&&w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:_,disabled:!b||u,title:"Export PNG",children:u?w.jsx("span",{className:"w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):w.jsx(rG,{className:"w-3.5 h-3.5"})}),w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:()=>c(!s),title:s?"Minimize":"Maximize",children:s?w.jsx(yE,{className:"w-3.5 h-3.5"}):w.jsx(vE,{className:"w-3.5 h-3.5"})}),w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:a,title:"Close",children:w.jsx(jl,{className:"w-3.5 h-3.5"})})]}),w.jsx("div",{ref:x,className:"flex-1 overflow-hidden flex items-center justify-center bg-muted/10",children:b?w.jsx("div",{style:{width:C,height:N},children:w.jsx("iframe",{src:`/api/artifacts/${n}/${b.id}`,sandbox:"allow-scripts",className:"border shadow-sm bg-white origin-top-left",style:{width:k,height:T,transform:`scale(${m})`},title:b.title})}):w.jsx("p",{className:"text-sm text-muted-foreground",children:"No artifact selected"})})]})}const _y=y.forwardRef(({className:e,...t},n)=>w.jsx("textarea",{className:Ue("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-none",e),ref:n,...t}));_y.displayName="Textarea";const X1={fable:"claude-fable-5-1","fable-5-1":"claude-fable-5-1","fable-5":"claude-fable-5",opus:"claude-opus-5","opus-5":"claude-opus-5","opus-4-8":"claude-opus-4-8","opus-4-7":"claude-opus-4-7","opus-4-6":"claude-opus-4-6",sonnet:"claude-sonnet-5","sonnet-5":"claude-sonnet-5","sonnet-4-6":"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"},Fke=/^\s*\[([^\]]*)\]\s*([\s\S]*)/,L6=["model","turns","thinking","think","effort","engine"],Z1=e=>/^[a-z0-9._-]+\/[a-z0-9./_-]+$/.test(e);let Rl=null;function Hke(e){Rl=e}function Q1(e){const t=e.trim().toLowerCase();return X1[t]?{model:X1[t]}:(Rl==null?void 0:Rl(t))??null}function z6(e,t){const n=Q1(t);return n?(e.model=n.model,n.engine&&!e.engine&&(e.engine=n.engine),!0):!1}function Kke(e){const t=e.split(",").map(n=>n.trim()).filter(Boolean);return t.length?t.every(n=>{const r=n.indexOf(":");if(r!==-1)return L6.includes(n.slice(0,r).trim().toLowerCase());const i=n.toLowerCase();return!!X1[i]||!!(Rl!=null&&Rl(i))||/^\d+$/.test(i)||["think","adaptive","nothink","nothinking"].includes(i)}):!1}function AA(e,t){let n=e;const r=[];for(;;){const i=n.match(Fke);if(!i)break;const a=i[1].trim();if((r.length||t!=null&&t.strict)&&a&&!Kke(a))break;r.push(a),n=i[2]}return{groups:r,body:n}}function qke(e){const{groups:t,body:n}=AA(e);if(!t.length)return{prompt:e,directives:{}};const r=t.filter(Boolean).join(","),i=n.trim();if(!r)return{prompt:i,directives:{}};const a={};let s=0,c;const u=r.split(","),f=u.some(p=>{const h=p.indexOf(":");return h!==-1&&L6.includes(p.slice(0,h).trim().toLowerCase())});for(const p of u){const h=p.trim();if(!h)continue;const m=h.indexOf(":");if(m!==-1){const v=h.slice(0,m).trim().toLowerCase(),x=h.slice(m+1).trim().toLowerCase();c=Gke(a,v,x)??c}else{const v=h.toLowerCase();s===0&&z6(a,v)||(s<=1&&/^\d+$/.test(v)?a.turns=parseInt(v,10):["think","adaptive"].includes(v)?a.thinking="adaptive":["nothink","nothinking"].includes(v)?a.thinking="disabled":s===0&&(f&&!Z1(v)&&(c??(c=h)),console.warn(Z1(v)?`[directives] Provider-qualified model needs key form: "[model:${h}]"`:`[directives] Unknown model alias: "${h}"`))),s++}}return{prompt:i,directives:a,unresolvedModel:c}}function Gke(e,t,n){switch(t){case"model":if(z6(e,n))break;if(Z1(n)){e.model=n;break}return n;case"turns":/^\d+$/.test(n)?e.turns=parseInt(n,10):console.warn(`[directives] Invalid turns value: "${n}"`);break;case"thinking":case"think":["adaptive","enabled","disabled"].includes(n)?e.thinking=n:console.warn(`[directives] Invalid thinking value: "${n}"`);break;case"effort":["low","medium","high","max"].includes(n)?e.effort=n:console.warn(`[directives] Invalid effort value: "${n}"`);break;case"engine":e.engine=n;break;default:console.warn(`[directives] Unknown directive key: "${t}"`)}}function Vke(e){return t=>{const n=t.toLowerCase(),r=[];for(const{name:i,models:a}of e())for(const s of a){if(!s.value)continue;const c=s.value.toLowerCase();if(c===n)return{model:s.value,engine:i};c.slice(c.lastIndexOf("/")+1)===n&&r.push({model:s.value,engine:i})}return r.length===1?r[0]:(r.length>1&&console.warn(`[directives] Ambiguous model "${t}" (${r.map(i=>`${i.engine}:${i.model}`).join(", ")}) — use the full id`),null)}}let Zm=[];Hke(Vke(()=>Zm));function $6(e,t=!0){const[n,r]=y.useState(Zm),[i,a]=y.useState(!1);return y.useEffect(()=>{if(!t)return;let s=!0;return e().then(c=>{!c||!s||fetch("/api/engines",{headers:{Authorization:`Bearer ${c}`}}).then(u=>u.json()).then(u=>{s&&(Zm=u.engines??[],r(Zm),a(u.multiEngine??!1))}).catch(u=>console.warn("[engines] load failed",u))}),()=>{s=!1}},[t,e]),{engines:n,multiEngine:i}}async function eo(e,t,n){const r=await t(),i=await fetch(e,{...n,headers:{Authorization:`Bearer ${r??""}`,"Content-Type":"application/json",...n==null?void 0:n.headers}});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(a.error||`${i.status} ${i.statusText}`)}return i.json()}function Wke({getToken:e}){const[t,n]=y.useState(null),[r,i]=y.useState(null),[a,s]=y.useState(""),[c,u]=y.useState(!1),[f,p]=y.useState(null),h=y.useCallback(()=>{eo("/api/claude-account",e).then(n).catch(_=>{console.warn("[ClaudeAccountSection] status failed",_),p(_.message)})},[e]);y.useEffect(h,[h]);const m=async _=>{u(!0),p(null);try{await _()}catch(O){p(O.message)}finally{u(!1)}},v=_=>m(async()=>{const O=window.open("about:blank","_blank");try{const{url:k}=await eo(`/api/claude-account/${_}/login`,e,{method:"POST"});O&&(O.location.href=k),i({target:_,url:k}),s("")}catch(k){throw O==null||O.close(),k}}),x=()=>m(async()=>{r&&(await eo(`/api/claude-account/${r.target}/login/code`,e,{method:"POST",body:JSON.stringify({code:a})}),i(null),s(""),h())}),b=_=>m(async()=>{await eo(`/api/claude-account/${_}`,e,{method:"DELETE"}),h()}),S=(_,O,k)=>w.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[w.jsxs("div",{className:"text-sm min-w-0",children:[w.jsx("div",{className:"font-medium",children:O}),w.jsx("div",{className:"text-xs text-muted-foreground truncate",children:k!=null&&k.connected?`${k.account??"Connected"}${k.subscriptionType?` · ${k.subscriptionType}`:""}`:_==="me"?"Not connected — using the shared subscription":"Not connected"})]}),w.jsxs("div",{className:"flex gap-2",children:[w.jsx(Ne,{size:"sm",variant:"outline",disabled:c,onClick:()=>v(_),children:k!=null&&k.connected?"Replace":"Connect"}),_==="me"&&(k==null?void 0:k.connected)&&w.jsx(Ne,{size:"sm",variant:"ghost",disabled:c,onClick:()=>b(_),children:"Use shared"})]})]});return t?w.jsxs("div",{className:"space-y-3",children:[w.jsx("label",{className:"text-sm font-medium block",children:"Claude subscription"}),t.me?S("me","Your subscription",t.me):w.jsx("p",{className:"text-xs text-muted-foreground",children:"Personal subscription unavailable: you are not a contact on this agent."}),t.global&&S("global","Shared subscription",t.global),r&&w.jsxs("div",{className:"rounded-md bg-muted/50 px-3 py-2 space-y-2 text-xs",children:[w.jsxs("p",{children:["Sign in on the ",w.jsx("a",{className:"underline",href:r.url,target:"_blank",rel:"noreferrer",children:"Claude login page"}),", then paste the code it shows."]}),w.jsxs("div",{className:"flex gap-2",children:[w.jsx(_n,{value:a,onChange:_=>s(_.target.value),placeholder:"Paste code"}),w.jsx(Ne,{size:"sm",disabled:c||!a.trim(),onClick:x,children:"Submit"}),w.jsx(Ne,{size:"sm",variant:"ghost",disabled:c,onClick:()=>i(null),children:"Cancel"})]})]}),f&&w.jsx("p",{className:"text-xs text-destructive",children:f})]}):f?w.jsx("p",{className:"text-xs text-destructive",children:f}):null}const Yke=[{value:"",label:"Default (claude-sonnet-5)"},{value:"claude-fable-5-1",label:"Fable 5.1 — frontier, most capable"},{value:"claude-fable-5",label:"Fable 5"},{value:"claude-opus-5",label:"Opus 5 — most capable, best for complex/agentic tasks"},{value:"claude-opus-4-8",label:"Opus 4.8"},{value:"claude-opus-4-7",label:"Opus 4.7"},{value:"claude-opus-4-6",label:"Opus 4.6"},{value:"claude-sonnet-5",label:"Sonnet 5 — balanced speed & intelligence"},{value:"claude-sonnet-4-6",label:"Sonnet 4.6"},{value:"claude-haiku-4-5",label:"Haiku 4.5 — fastest"}],Xke=[{value:"acceptEdits",label:"Accept Edits (auto-approve file changes)"},{value:"plan",label:"Plan (read-only, suggest changes)"},{value:"bypassPermissions",label:"Bypass All (dangerous — no prompts)"}];function Zke({getToken:e,onSaved:t,trigger:n,sessionId:r,sessionDirectives:i,onDirectivesSaved:a}){var j;const s=_a(),[c,u]=y.useState({}),[f,p]=y.useState(!1),[h,m]=y.useState(!1),{engines:v,multiEngine:x}=$6(e,f),b=y.useRef({}),[S,_]=y.useState(!1);y.useEffect(()=>{f&&(_(!1),e().then(I=>{I&&fetch("/api/config",{headers:{Authorization:`Bearer ${I}`}}).then(F=>F.json()).then(F=>{b.current=F;const R=r?i:void 0;u({...F,...(R==null?void 0:R.engine)!==void 0?{engine:R.engine}:{},...(R==null?void 0:R.model)!==void 0?{model:R.model}:{},...(R==null?void 0:R.turns)!==void 0?{maxTurns:R.turns}:{},...(R==null?void 0:R.thinking)!==void 0?{thinking:R.thinking}:{}})}).catch(()=>{})}))},[f,e,r,i]);const O=async()=>{m(!0);const F={Authorization:`Bearer ${await e()??""}`,"Content-Type":"application/json"};try{if(r){const R=S?{engine:"",model:"",turns:null,thinking:""}:{engine:c.engine,model:c.model,turns:c.maxTurns,thinking:c.thinking},G=await fetch(`/api/sessions/${r}/directives`,{method:"PUT",headers:F,body:JSON.stringify(R)}).then(K=>K.json()).catch(K=>(console.warn("[config] directives save failed",K),null));G!=null&&G.directives&&(a==null||a(G.directives));const q=S?c:{...c,engine:b.current.engine,model:b.current.model,maxTurns:b.current.maxTurns,thinking:b.current.thinking};await fetch("/api/config",{method:"PUT",headers:F,body:JSON.stringify(q)}),t==null||t(q)}else await fetch("/api/config",{method:"PUT",headers:F,body:JSON.stringify(c)}),t==null||t(c);p(!1)}finally{m(!1)}},k=c.engine||"claude-code",T=v.find(I=>I.name===k),C=(T==null?void 0:T.models)??Yke;y.useEffect(()=>{!T||!C.length||C.some(I=>(I.value||"")===(c.model??""))||u(I=>({...I,model:C[0].value||void 0}))},[T,C,c.model]);const P=C.some(I=>I.provider)?Array.from(C.reduce((I,F)=>{const R=F.provider||"default";return I.has(R)||I.set(R,[]),I.get(R).push(F),I},new Map)):null,D="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2";return w.jsxs(_s,{open:f,onOpenChange:p,children:[w.jsx(uh,{asChild:!0,children:n||w.jsx(Ne,{variant:"ghost",size:"icon",title:"Agent Config",children:w.jsx(pG,{className:"w-4 h-4"})})}),w.jsxs(ho,{className:"max-w-lg",children:[w.jsx(zl,{children:w.jsx(As,{children:"Agent Configuration"})}),w.jsxs(Wz,{className:"space-y-4",children:[r&&w.jsxs("div",{className:"text-xs text-muted-foreground rounded-md bg-muted/50 px-3 py-2 space-y-2",children:[w.jsxs("p",{children:["Engine, Model, Max Turns & Thinking apply to"," ",w.jsx("strong",{children:S?"every conversation":"this conversation"}),". Other settings are always global defaults."]}),w.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[w.jsx("input",{type:"checkbox",checked:S,onChange:I=>_(I.target.checked)}),w.jsx("span",{children:"Apply globally — also the default for Slack, email & scheduled runs"})]})]}),x&&w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Engine"}),w.jsx("select",{value:c.engine??"",onChange:I=>{const F=I.target.value||void 0;u(R=>({...R,engine:F,model:void 0}))},className:D,children:v.map(I=>w.jsx("option",{value:I.name,children:I.name==="claude-code"?"Claude Code (default)":I.name},I.name))})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Model"}),w.jsx("select",{value:c.model??"",onChange:I=>u(F=>({...F,model:I.target.value||void 0})),className:D,children:P?P.map(([I,F])=>w.jsx("optgroup",{label:I.charAt(0).toUpperCase()+I.slice(1),children:F.map(R=>w.jsx("option",{value:R.value,children:R.label},R.value))},I)):C.map(I=>w.jsx("option",{value:I.value,children:I.label},I.value))})]}),(j=s.settingsSections)==null?void 0:j.call(s,{getToken:e,sessionId:r}),w.jsx(Wke,{getToken:e}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Permission Mode"}),w.jsx("select",{value:c.permissionMode??"acceptEdits",onChange:I=>u(F=>({...F,permissionMode:I.target.value})),className:D,children:Xke.map(I=>w.jsx("option",{value:I.value,children:I.label},I.value))})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Max Turns"}),w.jsx(_n,{type:"number",min:1,max:200,value:c.maxTurns??50,onChange:I=>u(F=>({...F,maxTurns:Number(I.target.value)||50}))})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Thinking"}),w.jsxs("select",{value:c.thinking??"",onChange:I=>u(F=>({...F,thinking:I.target.value||void 0})),className:D,children:[w.jsx("option",{value:"",children:"Default (off)"}),w.jsx("option",{value:"adaptive",children:"Adaptive (Claude decides)"}),w.jsx("option",{value:"enabled",children:"Enabled (always think)"}),w.jsx("option",{value:"disabled",children:"Disabled"})]})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Effort"}),w.jsxs("select",{value:c.effort??"",onChange:I=>u(F=>({...F,effort:I.target.value||void 0})),className:D,children:[w.jsx("option",{value:"",children:"Default"}),w.jsx("option",{value:"low",children:"Low — fast"}),w.jsx("option",{value:"medium",children:"Medium"}),w.jsx("option",{value:"high",children:"High"}),w.jsx("option",{value:"max",children:"Max"})]})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Allowed Tools"}),w.jsx(_n,{placeholder:"Read, Edit, Bash, WebSearch, Glob, LS",value:(c.allowedTools??[]).join(", "),onChange:I=>u(F=>({...F,allowedTools:I.target.value.split(",").map(R=>R.trim()).filter(Boolean)}))}),w.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of tools Claude can use"})]}),w.jsxs("div",{className:"flex items-center justify-between",children:[w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium",children:"Skill Discovery"}),w.jsx("p",{className:"text-xs text-muted-foreground",children:"Index all skills + auto-inject on trigger match"})]}),w.jsx("button",{type:"button",role:"switch","aria-checked":c.skillDiscovery!==!1,onClick:()=>u(I=>({...I,skillDiscovery:I.skillDiscovery===!1})),className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors ${c.skillDiscovery!==!1?"bg-primary":"bg-muted"}`,children:w.jsx("span",{className:`pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform ${c.skillDiscovery!==!1?"translate-x-5":"translate-x-0"}`})})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"System Prompt (optional)"}),w.jsx(_y,{placeholder:"Additional instructions appended to Claude's system prompt…",value:c.systemPrompt??"",onChange:I=>u(F=>({...F,systemPrompt:I.target.value||void 0})),rows:4})]})]}),w.jsx(Yz,{children:w.jsx(Ne,{onClick:O,disabled:h,children:h?"Saving…":"Save Configuration"})})]})]})}function Qke(e){const t=e.requestedEngine||"claude-code",n=e.actualEngine?"ran":e.actualModel?"ran-model":"pending",r=n==="ran"?e.actualEngine:n==="pending"?t:void 0,i=e.actualModel||e.requestedModel||(t==="cursor"?"cursor/composer-2.5":"sonnet-4-6"),a=n==="ran"&&r!==t?t:void 0,s=r==="claude-code"||r==="cursor",c=i.includes("/")?i.split("/")[0]:r==="claude-code"?"anthropic":r;return{provenance:n,engine:r,engineIsNative:s,engineMismatch:a,rawModel:i,billingProvider:c}}function Jke(e){const t=e.email.split("@")[0]||e.email,n=e.personal?"personal login":"shared login",r=`Claude.ai subscription (OAuth login) — no API key in use
1945
+ `?1:0),kind:"command"}),O(0)):q?(S({query:q[1],start:q.index,kind:"mention"}),O(0)):S(null)};return y.useEffect(()=>{const D=()=>S(null);return b&&document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[b]),w.jsxs("div",{className:"relative flex-1 min-w-0",children:[b&&k.length>0&&w.jsx("div",{className:"absolute bottom-full mb-1 left-0 z-50 bg-background border rounded-lg shadow-lg overflow-hidden min-w-[220px] max-h-64 overflow-y-auto",children:k.map((D,j)=>w.jsxs("button",{onMouseDown:I=>{I.preventDefault(),C(D.value)},className:`w-full text-left px-3 py-1.5 text-sm hover:bg-accent transition-colors flex items-center gap-2 ${j===_?"bg-accent":""}`,children:[w.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground shrink-0 w-14",children:(b==null?void 0:b.kind)==="command"?"cmd":D.kind==="skill"?"skill":"file"}),w.jsxs("span",{className:"truncate",children:[w.jsx("span",{className:"text-muted-foreground",children:(b==null?void 0:b.kind)==="command"?"/":"@"}),D.value]})]},`${D.kind}:${D.value}`))}),w.jsx("textarea",{ref:x,value:t,onChange:P,onKeyDown:N,onPaste:i,placeholder:c,disabled:p,rows:f,dir:"auto",className:u})]})}),_A="shraga:draft:";function ow(e,t){const n=_A+(e??"new");t.trim()?localStorage.setItem(n,t):localStorage.removeItem(n)}function aD(e){return localStorage.getItem(_A+(e??"new"))??""}function oD(e){localStorage.removeItem(_A+(e??"new"))}const $ke=y.forwardRef(function({onSend:t,onSteer:n,onQueue:r,onRemoveQueued:i,queue:a,onUpload:s,onCancel:c,disabled:u,busy:f,skills:p=[],workspaceFiles:h=[],sessionId:m,inputCtx:v},x){var U,W;const b=_a(),[S,_]=y.useState(()=>aD(m)),[O,k]=y.useState([]),[T,C]=y.useState(!1),N=y.useRef(null),P=y.useRef(null),D=y.useRef(m);y.useEffect(()=>{var z;if(D.current===m)return;const H=D.current;if(D.current=m,!m){oD(H),ow(void 0,S);return}ow(H,S);const Y=aD(m);_(Y),(z=P.current)==null||z.setValue(Y)},[m]);const j=y.useCallback(H=>{_(H),ow(D.current,H)},[]);y.useImperativeHandle(x,()=>({prefill(H){var Y,z;j(H),(Y=P.current)==null||Y.setValue(H),(z=P.current)==null||z.focus()},setText(H){var Y;j(H),(Y=P.current)==null||Y.setValue(H)},focus(){var H;(H=P.current)==null||H.focus()}}));const I=(H="send")=>{var z;const Y=S.trim();!Y&&O.length===0||(H==="steer"?n(Y):H==="queue"?r(Y):t(Y,O.length>0?O:void 0),_(""),oD(D.current),k([]),(z=P.current)==null||z.setValue(""))},F=typeof window<"u"&&((U=window.matchMedia)==null?void 0:U.call(window,"(pointer: coarse)").matches),R=H=>{if(H.key==="Enter"&&!H.shiftKey&&(!F||H.metaKey||H.ctrlKey)){H.preventDefault(),I(f?"steer":"send");return}if(H.key==="Tab"&&f&&S.trim()){H.preventDefault(),I("queue");return}},G=y.useCallback(async H=>{C(!0);try{const Y=await s(H);Y&&k(z=>[...z,Y])}finally{C(!1)}},[s]),q=y.useCallback(H=>{const Y=Array.from(H.clipboardData.items);for(const z of Y)if(z.type.startsWith("image/")||z.type==="application/pdf"){const $=z.getAsFile();$&&G($)}},[G]),K=H=>{var z;const Y=(z=H.target.files)==null?void 0:z[0];Y&&(G(Y),H.target.value="")};return w.jsx("div",{className:"border-t bg-background",style:{paddingBottom:"env(safe-area-inset-bottom)"},children:w.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-3",children:[(O.length>0||T)&&w.jsxs("div",{className:"flex gap-2 mb-2 flex-wrap items-center",children:[O.map((H,Y)=>w.jsxs("div",{className:"relative group",children:[H.mimeType.startsWith("image/")?w.jsx(SA,{src:H.url,alt:H.name,className:"h-16 w-16 object-cover rounded-lg border"}):w.jsxs("div",{className:"h-16 px-3 flex items-center gap-2 rounded-lg border bg-muted/50 text-xs text-muted-foreground",children:[w.jsx(gE,{className:"w-4 h-4 shrink-0"}),w.jsx("span",{className:"truncate max-w-[120px]",children:H.name})]}),w.jsx("button",{onClick:()=>k(z=>z.filter(($,Z)=>Z!==Y)),className:"absolute -top-1.5 -right-1.5 bg-destructive text-destructive-foreground rounded-full w-5 h-5 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity shadow-sm",children:w.jsx(jl,{className:"w-3 h-3"})})]},Y)),T&&w.jsx("span",{className:"text-xs text-muted-foreground animate-pulse",children:"Uploading…"})]}),w.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-xl border px-3 py-2",children:[w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:()=>{var H;return(H=N.current)==null?void 0:H.click()},disabled:u,title:"Attach file or image",children:w.jsx(cG,{className:"w-4 h-4"})}),w.jsx("input",{ref:N,type:"file",className:"hidden",onChange:K}),w.jsx(j6,{ref:P,value:S,onChange:j,onKeyDown:R,onPaste:q,skills:p,workspaceFiles:h,placeholder:f?"Steer or queue…":"Message Claude…",disabled:u,rows:1,className:"w-full bg-transparent border-none outline-none resize-none text-sm py-1.5 placeholder:text-muted-foreground min-h-[28px] max-h-[200px]"}),(W=b.inputAdornments)==null?void 0:W.call(b,v),f?w.jsxs("div",{className:"flex items-center gap-2",children:[S.trim()&&w.jsx(Ne,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>I("steer"),title:"Steer (inject into current turn)",children:w.jsx(og,{className:"w-4 h-4"})}),w.jsx(Ne,{variant:"destructive",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>c(),title:"Stop generation",children:w.jsx(Mj,{className:"w-3.5 h-3.5"})})]}):w.jsx(Ne,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>I(),disabled:u||T||!S.trim()&&O.length===0,children:w.jsx(og,{className:"w-4 h-4"})})]}),a.length>0&&w.jsx("div",{className:"flex gap-1.5 flex-wrap mt-2",children:a.map((H,Y)=>w.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-50 dark:bg-blue-950/40 px-2.5 py-1 text-xs text-blue-700 dark:text-blue-300 ring-1 ring-inset ring-blue-600/20 dark:ring-blue-400/30",children:[w.jsx("span",{className:"truncate max-w-[200px]",children:H}),w.jsx("button",{onClick:()=>i(Y),className:"hover:text-blue-900 dark:hover:text-blue-100",children:w.jsx(jl,{className:"w-3 h-3"})})]},Y))}),w.jsx("p",{className:"text-[10px] text-muted-foreground text-center mt-2",children:f?"Enter to steer (redirect) · Tab to queue (after done) · Shift+Enter for newline":"Enter to send · Shift+Enter for newline · @ for skills · / for commands"})]})})}),Bke={"fb-feed":[1080,1080],"fb-story":[1080,1920],"fb-landscape":[1200,628],"ig-square":[1080,1080],"ig-story":[1080,1920],"ig-landscape":[1080,566],"banner-leaderboard":[728,90],"banner-medium":[300,250]};function Uke({artifacts:e,selectedId:t,sessionId:n,getToken:r,onSelect:i,onClose:a}){var P;const[s,c]=y.useState(!1),[u,f]=y.useState(!1),[p,h]=y.useState(!1),[m,v]=y.useState(1),x=y.useRef(null),b=e.find(D=>D.id===t),S=y.useCallback(()=>{if(!x.current||!b)return;const{clientWidth:D,clientHeight:j}=x.current,I=32,F=D-I,R=j-I,[G,q]=b.dimensions;v(Math.min(F/G,R/q,1))},[b]);y.useEffect(()=>{let D=!0;return r().then(j=>fetch("/api/features",{headers:j?{Authorization:`Bearer ${j}`}:{}})).then(j=>j.json()).then(j=>{D&&h(!!j.artifactPngExport)}).catch(j=>console.error("[artifact] features fetch failed:",j)),()=>{D=!1}},[r]),y.useEffect(()=>{S();const D=x.current;if(!D)return;const j=new ResizeObserver(S);return j.observe(D),()=>j.disconnect()},[S]);const _=async()=>{if(b){f(!0);try{const D=await r(),j=await fetch(`/api/artifacts/${n}/${b.id}/export`,{method:"POST",headers:{"Content-Type":"application/json",...D?{Authorization:`Bearer ${D}`}:{}},body:JSON.stringify({dimensions:b.dimensions})});if(!j.ok)throw new Error(await j.text());const I=await j.blob(),F=URL.createObjectURL(I),R=document.createElement("a");R.href=F,R.download=`${b.title.replace(/\s+/g,"-").toLowerCase()}.png`,R.click(),URL.revokeObjectURL(F)}catch(D){console.error("[artifact] export failed:",D)}finally{f(!1)}}},O=b?(P=Object.entries(Bke).find(([,D])=>D[0]===b.dimensions[0]&&D[1]===b.dimensions[1]))==null?void 0:P[0]:null,[k,T]=(b==null?void 0:b.dimensions)??[0,0],C=k*m,N=T*m;return w.jsxs("div",{className:Ue("flex flex-col border-l bg-background transition-all",s?"fixed inset-0 z-50":"fixed inset-0 z-50 sm:relative sm:inset-auto sm:z-auto sm:w-[480px] sm:shrink-0"),children:[w.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b bg-muted/30",children:[w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-7 w-7 sm:hidden shrink-0",onClick:a,title:"Back to chat",children:w.jsx(kj,{className:"w-4 h-4"})}),e.length>1&&w.jsx("select",{className:"text-xs bg-transparent border rounded px-1 py-0.5 max-w-[160px] truncate",value:t??"",onChange:D=>i(D.target.value),children:e.map(D=>w.jsx("option",{value:D.id,children:D.title},D.id))}),e.length<=1&&b&&w.jsx("span",{className:"text-xs font-medium truncate max-w-[160px]",children:b.title}),b&&w.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[O??`${k}×${T}`,m<1&&` · ${Math.round(m*100)}%`]}),w.jsx("div",{className:"flex-1"}),p&&w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:_,disabled:!b||u,title:"Export PNG",children:u?w.jsx("span",{className:"w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):w.jsx(rG,{className:"w-3.5 h-3.5"})}),w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:()=>c(!s),title:s?"Minimize":"Maximize",children:s?w.jsx(yE,{className:"w-3.5 h-3.5"}):w.jsx(vE,{className:"w-3.5 h-3.5"})}),w.jsx(Ne,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:a,title:"Close",children:w.jsx(jl,{className:"w-3.5 h-3.5"})})]}),w.jsx("div",{ref:x,className:"flex-1 overflow-hidden flex items-center justify-center bg-muted/10",children:b?w.jsx("div",{style:{width:C,height:N},children:w.jsx("iframe",{src:`/api/artifacts/${n}/${b.id}`,sandbox:"allow-scripts",className:"border shadow-sm bg-white origin-top-left",style:{width:k,height:T,transform:`scale(${m})`},title:b.title})}):w.jsx("p",{className:"text-sm text-muted-foreground",children:"No artifact selected"})})]})}const _y=y.forwardRef(({className:e,...t},n)=>w.jsx("textarea",{className:Ue("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-none",e),ref:n,...t}));_y.displayName="Textarea";const X1={fable:"claude-fable-5-1","fable-5-1":"claude-fable-5-1","fable-5":"claude-fable-5",opus:"claude-opus-5","opus-5":"claude-opus-5","opus-4-8":"claude-opus-4-8","opus-4-7":"claude-opus-4-7","opus-4-6":"claude-opus-4-6",sonnet:"claude-sonnet-5","sonnet-5":"claude-sonnet-5","sonnet-4-6":"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"},Fke=/^\s*\[([^\]]*)\]\s*([\s\S]*)/,L6=["model","turns","thinking","think","effort","engine","resume"],Z1=e=>/^[a-z0-9._-]+\/[a-z0-9./_-]+$/.test(e);let Rl=null;function Hke(e){Rl=e}function Q1(e){const t=e.trim().toLowerCase();return X1[t]?{model:X1[t]}:(Rl==null?void 0:Rl(t))??null}function z6(e,t){const n=Q1(t);return n?(e.model=n.model,n.engine&&!e.engine&&(e.engine=n.engine),!0):!1}function Kke(e){const t=e.split(",").map(n=>n.trim()).filter(Boolean);return t.length?t.every(n=>{const r=n.indexOf(":");if(r!==-1)return L6.includes(n.slice(0,r).trim().toLowerCase());const i=n.toLowerCase();return!!X1[i]||!!(Rl!=null&&Rl(i))||/^\d+$/.test(i)||["think","adaptive","nothink","nothinking"].includes(i)}):!1}function AA(e,t){let n=e;const r=[];for(;;){const i=n.match(Fke);if(!i)break;const a=i[1].trim();if((r.length||t!=null&&t.strict)&&a&&!Kke(a))break;r.push(a),n=i[2]}return{groups:r,body:n}}function qke(e){const{groups:t,body:n}=AA(e);if(!t.length)return{prompt:e,directives:{}};const r=t.filter(Boolean).join(","),i=n.trim();if(!r)return{prompt:i,directives:{}};const a={};let s=0,c;const u=r.split(","),f=u.some(p=>{const h=p.indexOf(":");return h!==-1&&L6.includes(p.slice(0,h).trim().toLowerCase())});for(const p of u){const h=p.trim();if(!h)continue;const m=h.indexOf(":");if(m!==-1){const v=h.slice(0,m).trim().toLowerCase(),x=h.slice(m+1).trim().toLowerCase();c=Gke(a,v,x)??c}else{const v=h.toLowerCase();s===0&&z6(a,v)||(s<=1&&/^\d+$/.test(v)?a.turns=parseInt(v,10):["think","adaptive"].includes(v)?a.thinking="adaptive":["nothink","nothinking"].includes(v)?a.thinking="disabled":s===0&&(f&&!Z1(v)&&(c??(c=h)),console.warn(Z1(v)?`[directives] Provider-qualified model needs key form: "[model:${h}]"`:`[directives] Unknown model alias: "${h}"`))),s++}}return{prompt:i,directives:a,unresolvedModel:c}}function Gke(e,t,n){switch(t){case"model":if(z6(e,n))break;if(Z1(n)){e.model=n;break}return n;case"turns":/^\d+$/.test(n)?e.turns=parseInt(n,10):console.warn(`[directives] Invalid turns value: "${n}"`);break;case"thinking":case"think":["adaptive","enabled","disabled"].includes(n)?e.thinking=n:console.warn(`[directives] Invalid thinking value: "${n}"`);break;case"effort":["low","medium","high","max"].includes(n)?e.effort=n:console.warn(`[directives] Invalid effort value: "${n}"`);break;case"engine":e.engine=n;break;case"resume":["on","true","1"].includes(n)?e.resume=!0:["off","false","0"].includes(n)?e.resume=!1:console.warn(`[directives] Invalid resume value: "${n}"`);break;default:console.warn(`[directives] Unknown directive key: "${t}"`)}}function Vke(e){return t=>{const n=t.toLowerCase(),r=[];for(const{name:i,models:a}of e())for(const s of a){if(!s.value)continue;const c=s.value.toLowerCase();if(c===n)return{model:s.value,engine:i};c.slice(c.lastIndexOf("/")+1)===n&&r.push({model:s.value,engine:i})}return r.length===1?r[0]:(r.length>1&&console.warn(`[directives] Ambiguous model "${t}" (${r.map(i=>`${i.engine}:${i.model}`).join(", ")}) — use the full id`),null)}}let Zm=[];Hke(Vke(()=>Zm));function $6(e,t=!0){const[n,r]=y.useState(Zm),[i,a]=y.useState(!1);return y.useEffect(()=>{if(!t)return;let s=!0;return e().then(c=>{!c||!s||fetch("/api/engines",{headers:{Authorization:`Bearer ${c}`}}).then(u=>u.json()).then(u=>{s&&(Zm=u.engines??[],r(Zm),a(u.multiEngine??!1))}).catch(u=>console.warn("[engines] load failed",u))}),()=>{s=!1}},[t,e]),{engines:n,multiEngine:i}}async function eo(e,t,n){const r=await t(),i=await fetch(e,{...n,headers:{Authorization:`Bearer ${r??""}`,"Content-Type":"application/json",...n==null?void 0:n.headers}});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(a.error||`${i.status} ${i.statusText}`)}return i.json()}function Wke({getToken:e}){const[t,n]=y.useState(null),[r,i]=y.useState(null),[a,s]=y.useState(""),[c,u]=y.useState(!1),[f,p]=y.useState(null),h=y.useCallback(()=>{eo("/api/claude-account",e).then(n).catch(_=>{console.warn("[ClaudeAccountSection] status failed",_),p(_.message)})},[e]);y.useEffect(h,[h]);const m=async _=>{u(!0),p(null);try{await _()}catch(O){p(O.message)}finally{u(!1)}},v=_=>m(async()=>{const O=window.open("about:blank","_blank");try{const{url:k}=await eo(`/api/claude-account/${_}/login`,e,{method:"POST"});O&&(O.location.href=k),i({target:_,url:k}),s("")}catch(k){throw O==null||O.close(),k}}),x=()=>m(async()=>{r&&(await eo(`/api/claude-account/${r.target}/login/code`,e,{method:"POST",body:JSON.stringify({code:a})}),i(null),s(""),h())}),b=_=>m(async()=>{await eo(`/api/claude-account/${_}`,e,{method:"DELETE"}),h()}),S=(_,O,k)=>w.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[w.jsxs("div",{className:"text-sm min-w-0",children:[w.jsx("div",{className:"font-medium",children:O}),w.jsx("div",{className:"text-xs text-muted-foreground truncate",children:k!=null&&k.connected?`${k.account??"Connected"}${k.subscriptionType?` · ${k.subscriptionType}`:""}`:_==="me"?"Not connected — using the shared subscription":"Not connected"})]}),w.jsxs("div",{className:"flex gap-2",children:[w.jsx(Ne,{size:"sm",variant:"outline",disabled:c,onClick:()=>v(_),children:k!=null&&k.connected?"Replace":"Connect"}),_==="me"&&(k==null?void 0:k.connected)&&w.jsx(Ne,{size:"sm",variant:"ghost",disabled:c,onClick:()=>b(_),children:"Use shared"})]})]});return t?w.jsxs("div",{className:"space-y-3",children:[w.jsx("label",{className:"text-sm font-medium block",children:"Claude subscription"}),t.me?S("me","Your subscription",t.me):w.jsx("p",{className:"text-xs text-muted-foreground",children:"Personal subscription unavailable: you are not a contact on this agent."}),t.global&&S("global","Shared subscription",t.global),r&&w.jsxs("div",{className:"rounded-md bg-muted/50 px-3 py-2 space-y-2 text-xs",children:[w.jsxs("p",{children:["Sign in on the ",w.jsx("a",{className:"underline",href:r.url,target:"_blank",rel:"noreferrer",children:"Claude login page"}),", then paste the code it shows."]}),w.jsxs("div",{className:"flex gap-2",children:[w.jsx(_n,{value:a,onChange:_=>s(_.target.value),placeholder:"Paste code"}),w.jsx(Ne,{size:"sm",disabled:c||!a.trim(),onClick:x,children:"Submit"}),w.jsx(Ne,{size:"sm",variant:"ghost",disabled:c,onClick:()=>i(null),children:"Cancel"})]})]}),f&&w.jsx("p",{className:"text-xs text-destructive",children:f})]}):f?w.jsx("p",{className:"text-xs text-destructive",children:f}):null}const Yke=[{value:"",label:"Default (claude-sonnet-5)"},{value:"claude-fable-5-1",label:"Fable 5.1 — frontier, most capable"},{value:"claude-fable-5",label:"Fable 5"},{value:"claude-opus-5",label:"Opus 5 — most capable, best for complex/agentic tasks"},{value:"claude-opus-4-8",label:"Opus 4.8"},{value:"claude-opus-4-7",label:"Opus 4.7"},{value:"claude-opus-4-6",label:"Opus 4.6"},{value:"claude-sonnet-5",label:"Sonnet 5 — balanced speed & intelligence"},{value:"claude-sonnet-4-6",label:"Sonnet 4.6"},{value:"claude-haiku-4-5",label:"Haiku 4.5 — fastest"}],Xke=[{value:"acceptEdits",label:"Accept Edits (auto-approve file changes)"},{value:"plan",label:"Plan (read-only, suggest changes)"},{value:"bypassPermissions",label:"Bypass All (dangerous — no prompts)"}];function Zke({getToken:e,onSaved:t,trigger:n,sessionId:r,sessionDirectives:i,onDirectivesSaved:a}){var j;const s=_a(),[c,u]=y.useState({}),[f,p]=y.useState(!1),[h,m]=y.useState(!1),{engines:v,multiEngine:x}=$6(e,f),b=y.useRef({}),[S,_]=y.useState(!1);y.useEffect(()=>{f&&(_(!1),e().then(I=>{I&&fetch("/api/config",{headers:{Authorization:`Bearer ${I}`}}).then(F=>F.json()).then(F=>{b.current=F;const R=r?i:void 0;u({...F,...(R==null?void 0:R.engine)!==void 0?{engine:R.engine}:{},...(R==null?void 0:R.model)!==void 0?{model:R.model}:{},...(R==null?void 0:R.turns)!==void 0?{maxTurns:R.turns}:{},...(R==null?void 0:R.thinking)!==void 0?{thinking:R.thinking}:{}})}).catch(()=>{})}))},[f,e,r,i]);const O=async()=>{m(!0);const F={Authorization:`Bearer ${await e()??""}`,"Content-Type":"application/json"};try{if(r){const R=S?{engine:"",model:"",turns:null,thinking:""}:{engine:c.engine,model:c.model,turns:c.maxTurns,thinking:c.thinking},G=await fetch(`/api/sessions/${r}/directives`,{method:"PUT",headers:F,body:JSON.stringify(R)}).then(K=>K.json()).catch(K=>(console.warn("[config] directives save failed",K),null));G!=null&&G.directives&&(a==null||a(G.directives));const q=S?c:{...c,engine:b.current.engine,model:b.current.model,maxTurns:b.current.maxTurns,thinking:b.current.thinking};await fetch("/api/config",{method:"PUT",headers:F,body:JSON.stringify(q)}),t==null||t(q)}else await fetch("/api/config",{method:"PUT",headers:F,body:JSON.stringify(c)}),t==null||t(c);p(!1)}finally{m(!1)}},k=c.engine||"claude-code",T=v.find(I=>I.name===k),C=(T==null?void 0:T.models)??Yke;y.useEffect(()=>{!T||!C.length||C.some(I=>(I.value||"")===(c.model??""))||u(I=>({...I,model:C[0].value||void 0}))},[T,C,c.model]);const P=C.some(I=>I.provider)?Array.from(C.reduce((I,F)=>{const R=F.provider||"default";return I.has(R)||I.set(R,[]),I.get(R).push(F),I},new Map)):null,D="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2";return w.jsxs(_s,{open:f,onOpenChange:p,children:[w.jsx(uh,{asChild:!0,children:n||w.jsx(Ne,{variant:"ghost",size:"icon",title:"Agent Config",children:w.jsx(pG,{className:"w-4 h-4"})})}),w.jsxs(ho,{className:"max-w-lg",children:[w.jsx(zl,{children:w.jsx(As,{children:"Agent Configuration"})}),w.jsxs(Wz,{className:"space-y-4",children:[r&&w.jsxs("div",{className:"text-xs text-muted-foreground rounded-md bg-muted/50 px-3 py-2 space-y-2",children:[w.jsxs("p",{children:["Engine, Model, Max Turns & Thinking apply to"," ",w.jsx("strong",{children:S?"every conversation":"this conversation"}),". Other settings are always global defaults."]}),w.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[w.jsx("input",{type:"checkbox",checked:S,onChange:I=>_(I.target.checked)}),w.jsx("span",{children:"Apply globally — also the default for Slack, email & scheduled runs"})]})]}),x&&w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Engine"}),w.jsx("select",{value:c.engine??"",onChange:I=>{const F=I.target.value||void 0;u(R=>({...R,engine:F,model:void 0}))},className:D,children:v.map(I=>w.jsx("option",{value:I.name,children:I.name==="claude-code"?"Claude Code (default)":I.name},I.name))})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Model"}),w.jsx("select",{value:c.model??"",onChange:I=>u(F=>({...F,model:I.target.value||void 0})),className:D,children:P?P.map(([I,F])=>w.jsx("optgroup",{label:I.charAt(0).toUpperCase()+I.slice(1),children:F.map(R=>w.jsx("option",{value:R.value,children:R.label},R.value))},I)):C.map(I=>w.jsx("option",{value:I.value,children:I.label},I.value))})]}),(j=s.settingsSections)==null?void 0:j.call(s,{getToken:e,sessionId:r}),w.jsx(Wke,{getToken:e}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Permission Mode"}),w.jsx("select",{value:c.permissionMode??"acceptEdits",onChange:I=>u(F=>({...F,permissionMode:I.target.value})),className:D,children:Xke.map(I=>w.jsx("option",{value:I.value,children:I.label},I.value))})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Max Turns"}),w.jsx(_n,{type:"number",min:1,max:200,value:c.maxTurns??50,onChange:I=>u(F=>({...F,maxTurns:Number(I.target.value)||50}))})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Thinking"}),w.jsxs("select",{value:c.thinking??"",onChange:I=>u(F=>({...F,thinking:I.target.value||void 0})),className:D,children:[w.jsx("option",{value:"",children:"Default (off)"}),w.jsx("option",{value:"adaptive",children:"Adaptive (Claude decides)"}),w.jsx("option",{value:"enabled",children:"Enabled (always think)"}),w.jsx("option",{value:"disabled",children:"Disabled"})]})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Effort"}),w.jsxs("select",{value:c.effort??"",onChange:I=>u(F=>({...F,effort:I.target.value||void 0})),className:D,children:[w.jsx("option",{value:"",children:"Default"}),w.jsx("option",{value:"low",children:"Low — fast"}),w.jsx("option",{value:"medium",children:"Medium"}),w.jsx("option",{value:"high",children:"High"}),w.jsx("option",{value:"max",children:"Max"})]})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Allowed Tools"}),w.jsx(_n,{placeholder:"Read, Edit, Bash, WebSearch, Glob, LS",value:(c.allowedTools??[]).join(", "),onChange:I=>u(F=>({...F,allowedTools:I.target.value.split(",").map(R=>R.trim()).filter(Boolean)}))}),w.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of tools Claude can use"})]}),w.jsxs("div",{className:"flex items-center justify-between",children:[w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium",children:"Skill Discovery"}),w.jsx("p",{className:"text-xs text-muted-foreground",children:"Index all skills + auto-inject on trigger match"})]}),w.jsx("button",{type:"button",role:"switch","aria-checked":c.skillDiscovery!==!1,onClick:()=>u(I=>({...I,skillDiscovery:I.skillDiscovery===!1})),className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors ${c.skillDiscovery!==!1?"bg-primary":"bg-muted"}`,children:w.jsx("span",{className:`pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform ${c.skillDiscovery!==!1?"translate-x-5":"translate-x-0"}`})})]}),w.jsxs("div",{children:[w.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"System Prompt (optional)"}),w.jsx(_y,{placeholder:"Additional instructions appended to Claude's system prompt…",value:c.systemPrompt??"",onChange:I=>u(F=>({...F,systemPrompt:I.target.value||void 0})),rows:4})]})]}),w.jsx(Yz,{children:w.jsx(Ne,{onClick:O,disabled:h,children:h?"Saving…":"Save Configuration"})})]})]})}function Qke(e){const t=e.requestedEngine||"claude-code",n=e.actualEngine?"ran":e.actualModel?"ran-model":"pending",r=n==="ran"?e.actualEngine:n==="pending"?t:void 0,i=e.actualModel||e.requestedModel||(t==="cursor"?"cursor/composer-2.5":"sonnet-4-6"),a=n==="ran"&&r!==t?t:void 0,s=r==="claude-code"||r==="cursor",c=i.includes("/")?i.split("/")[0]:r==="claude-code"?"anthropic":r;return{provenance:n,engine:r,engineIsNative:s,engineMismatch:a,rawModel:i,billingProvider:c}}function Jke(e){const t=e.email.split("@")[0]||e.email,n=e.personal?"personal login":"shared login",r=`Claude.ai subscription (OAuth login) — no API key in use
1946
1946
  Account: ${e.email}${e.plan?`
1947
1947
  Plan: ${e.plan}`:""}
1948
1948
  ${n==="personal login"?"Personal login (routed to this user)":"Shared login (the agent box account)"}`;return{localPart:t,plan:e.plan,kind:n,title:r}}function eOe({sessionId:e,config:t,sessionDirectives:n,actualModel:r,actualEngine:i,actualAccount:a,scheduleId:s,onScheduleClick:c}){const[u,f]=y.useState(!1),{provenance:p,engine:h,engineIsNative:m,engineMismatch:v,rawModel:x,billingProvider:b}=Qke({requestedEngine:(n==null?void 0:n.engine)||t.engine,requestedModel:(n==null?void 0:n.model)||t.model,actualEngine:i,actualModel:r}),S=x.replace("claude-",""),_=h&&!m?`${h} · ${S}`:S,O=p==="pending",k=O?" border border-dashed border-current/40 opacity-80":"",T=O?"Nothing has run in this conversation yet — this is what the next turn is set to use.":p==="ran-model"?"Model recorded from the last turn. The engine that ran it was not recorded (this conversation predates engine tracking), so it is not named here.":"Engine and model that actually ran the last turn.",C=!O&&h==="claude-code"?a:void 0,N=h==="claude-code"&&(!!C||t.claudeAuthSource==="subscription"),P=C?Jke(C):void 0,D=b?N?"sub":b==="cursor"?"plan":"metered":"unknown",j=D==="unknown"?"bg-muted text-muted-foreground ring-border":D==="sub"?"bg-emerald-50 text-emerald-700 ring-emerald-600/20 dark:bg-emerald-950/50 dark:text-emerald-300 dark:ring-emerald-400/30":D==="plan"?"bg-amber-50 text-amber-700 ring-amber-600/20 dark:bg-amber-950/50 dark:text-amber-300 dark:ring-amber-400/30":"bg-rose-50 text-rose-700 ring-rose-600/20 dark:bg-rose-950/50 dark:text-rose-300 dark:ring-rose-400/30",I=D==="unknown"?"The engine that ran this turn was not recorded and the model id carries no provider prefix — the billed provider cannot be named from what was stored.":D==="sub"?(P==null?void 0:P.title)??"Claude.ai subscription (OAuth login) — no API key in use":D==="plan"?`Runs on your ${b} API key — usage may draw on your ${b} plan/subscription`:`Runs on your ${b} API key — metered per-token billing`,F=t.permissionMode||"acceptEdits",R=F==="bypassPermissions"?"bypass":F==="plan"?"plan":F==="default"?"prompt":"edits",G=(n==null?void 0:n.thinking)||t.thinking,q=()=>{e&&(navigator.clipboard.writeText(e),f(!0),setTimeout(()=>f(!1),1500))};return w.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[w.jsx("span",{title:T,className:`inline-flex items-center rounded-md bg-blue-50 px-1.5 py-0.5 text-[10px] font-medium text-blue-700 ring-1 ring-inset ring-blue-600/20 dark:bg-blue-950/50 dark:text-blue-300 dark:ring-blue-400/30${k}`,children:O?`→ ${_}`:_}),w.jsxs("span",{title:O?`${T} ${I}`:I,"data-account":P?C.email:void 0,className:`inline-flex min-w-0 items-center whitespace-nowrap rounded-md px-1.5 py-0.5 text-[10px] font-medium ring-1 ring-inset ${j}${k}`,children:[D==="unknown"?"API·?":N?"sub":`API·${b}`,D==="sub"&&P&&w.jsxs(w.Fragment,{children:[w.jsx("span",{"aria-hidden":"true",children:" · "}),w.jsx("span",{className:"max-w-[4.5rem] truncate sm:max-w-[10rem]",children:P.localPart}),P.plan&&w.jsxs("span",{className:"hidden sm:inline",children:[" · ",P.plan]})]})]}),v&&w.jsxs("span",{title:`This session requests the "${v}" engine, but the last turn actually ran on "${h}" — so the chips above report ${h}, and that provider was billed.`,className:"inline-flex items-center rounded-md bg-rose-50 px-1.5 py-0.5 text-[10px] font-medium text-rose-700 ring-1 ring-inset ring-rose-600/20 dark:bg-rose-950/50 dark:text-rose-300 dark:ring-rose-400/30",children:["≠ ",v]}),w.jsx("span",{className:"inline-flex items-center rounded-md bg-amber-50 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 ring-1 ring-inset ring-amber-600/20 dark:bg-amber-950/50 dark:text-amber-300 dark:ring-amber-400/30",children:R}),w.jsxs("span",{className:"inline-flex items-center rounded-md bg-green-50 px-1.5 py-0.5 text-[10px] font-medium text-green-700 ring-1 ring-inset ring-green-600/20 dark:bg-green-950/50 dark:text-green-300 dark:ring-green-400/30",children:[(n==null?void 0:n.turns)??t.maxTurns??50," steps"]}),G&&G!=="disabled"&&w.jsx("span",{className:"inline-flex items-center rounded-md bg-violet-50 px-1.5 py-0.5 text-[10px] font-medium text-violet-700 ring-1 ring-inset ring-violet-600/20 dark:bg-violet-950/50 dark:text-violet-300 dark:ring-violet-400/30",children:"think"}),e&&w.jsxs("button",{onClick:q,className:"inline-flex items-center gap-0.5 rounded-md bg-muted px-1.5 py-0.5 text-[10px] font-mono text-muted-foreground ring-1 ring-inset ring-border hover:bg-accent transition-colors",title:`Session: ${e}