shraga 0.1.138 → 0.1.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/system-prompt.md +14 -1
- package/dist/client/assets/{index-C1weaEkP.js → index-CXVwnqSZ.js} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +1 -1
- package/src/server/data-sync.ts +84 -4
- package/src/server/engine/claude-code.ts +10 -0
- package/src/server/jobs-mcp.ts +73 -0
- package/src/server/security/enforce.ts +9 -0
|
@@ -41,7 +41,20 @@ The workspace (`data/workspace/`) has two scopes. Full architecture: `defaults/w
|
|
|
41
41
|
- Always respond with a brief verbal acknowledgment before making tool calls. For example: "Let me check that" or "Looking into it." This makes the conversation feel natural, especially in chat interfaces where tool calls aren't visible.
|
|
42
42
|
- Do NOT spawn sub-agents. This gates the `Agent`/`Task` tool ONLY. External CLI processes you launch
|
|
43
43
|
with `Bash` (a headless agent CLI, `claude -p`, …) are not sub-agents and are never blocked by this
|
|
44
|
-
rule — when a skill documents a Bash launch, use it.
|
|
44
|
+
rule — when a skill documents a Bash launch, use it. A headless worker needs its contract enforced,
|
|
45
|
+
or it strands its task mid-flight:
|
|
46
|
+
- **The worker is headless: its process EXITS the moment it ends a turn.** Nothing wakes it later.
|
|
47
|
+
Append this to every worker prompt, verbatim: "HEADLESS: you exit when your turn ends. Never run
|
|
48
|
+
anything in the background and never end a turn waiting on a download/build/job — wait in a
|
|
49
|
+
bounded FOREGROUND loop, then finish the whole task in this run."
|
|
50
|
+
- **Launch it as a durable background job** (`job_start`, or `Shell({background:true})` where that
|
|
51
|
+
is the shell tool), so its exit wakes you — never folklore `nohup … &` (nothing reports its exit)
|
|
52
|
+
and never `run_in_background` for work that may exceed ~10 minutes (it dies with the turn's wait
|
|
53
|
+
budget).
|
|
54
|
+
- **A worker's exit is not completion.** When it exits, check its DELIVERABLE exists and is sound
|
|
55
|
+
(the output file, not the log saying it started); a worker that ended its turn early exits with
|
|
56
|
+
code 0 and an empty folder. If the deliverable is missing, read its log tail and relaunch with
|
|
57
|
+
the gap named.
|
|
45
58
|
- Never abort a task on a *suspected* capability or permission block. Load the relevant skill and actually
|
|
46
59
|
attempt the documented path first; report the real error, not an assumed one.
|
|
47
60
|
- **A file path is not a deliverable.** When a turn produces a file the user is meant to see or keep
|
|
@@ -1904,7 +1904,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),bn=ve,At=je),rt===void
|
|
|
1904
1904
|
`)},LM=function(){var e=parseInt(document.body.getAttribute(Cu)||"0",10);return isFinite(e)?e:0},dre=function(){b.useEffect(function(){return document.body.setAttribute(Cu,(LM()+1).toString()),function(){var e=LM()-1;e<=0?document.body.removeAttribute(Cu):document.body.setAttribute(Cu,e.toString())}},[])},fre=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;dre();var a=b.useMemo(function(){return lre(i)},[i]);return b.createElement(cre,{styles:ure(a,!t,i,n?"":"!important")})},s1=!1;if(typeof window<"u")try{var Ap=Object.defineProperty({},"passive",{get:function(){return s1=!0,!0}});window.addEventListener("test",Ap,Ap),window.removeEventListener("test",Ap,Ap)}catch{s1=!1}var nu=s1?{passive:!1}:!1,hre=function(e){return e.tagName==="TEXTAREA"},fz=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!hre(e)&&n[t]==="visible")},mre=function(e){return fz(e,"overflowY")},pre=function(e){return fz(e,"overflowX")},zM=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=hz(e,r);if(i){var a=mz(e,r),s=a[1],l=a[2];if(s>l)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},gre=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},vre=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},hz=function(e,t){return e==="v"?mre(t):pre(t)},mz=function(e,t){return e==="v"?gre(t):vre(t)},yre=function(e,t){return e==="h"&&t==="rtl"?-1:1},bre=function(e,t,n,r,i){var a=yre(e,window.getComputedStyle(t).direction),s=a*r,l=n.target,u=t.contains(l),d=!1,h=s>0,m=0,p=0;do{if(!l)break;var g=mz(e,l),w=g[0],x=g[1],E=g[2],_=x-E-a*w;(w||_)&&hz(e,l)&&(m+=_,p+=w);var k=l.parentNode;l=k&&k.nodeType===Node.DOCUMENT_FRAGMENT_NODE?k.host:k}while(!u&&l!==document.body||u&&(t.contains(l)||t===l));return(h&&Math.abs(m)<1||!h&&Math.abs(p)<1)&&(d=!0),d},kp=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},$M=function(e){return[e.deltaX,e.deltaY]},BM=function(e){return e&&"current"in e?e.current:e},xre=function(e,t){return e[0]===t[0]&&e[1]===t[1]},wre=function(e){return`
|
|
1905
1905
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
1906
1906
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
1907
|
-
`)},Ere=0,ru=[];function Sre(e){var t=b.useRef([]),n=b.useRef([0,0]),r=b.useRef(),i=b.useState(Ere++)[0],a=b.useState(dz)[0],s=b.useRef(e);b.useEffect(function(){s.current=e},[e]),b.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var x=R7([e.lockRef.current],(e.shards||[]).map(BM),!0).filter(Boolean);return x.forEach(function(E){return E.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),x.forEach(function(E){return E.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var l=b.useCallback(function(x,E){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!s.current.allowPinchZoom;var _=kp(x),k=n.current,O="deltaX"in x?x.deltaX:k[0]-_[0],N="deltaY"in x?x.deltaY:k[1]-_[1],T,C=x.target,M=Math.abs(O)>Math.abs(N)?"h":"v";if("touches"in x&&M==="h"&&C.type==="range")return!1;var D=window.getSelection(),j=D&&D.anchorNode,R=j?j===C||j.contains(C):!1;if(R)return!1;var H=zM(M,C);if(!H)return!0;if(H?T=M:(T=M==="v"?"h":"v",H=zM(M,C)),!H)return!1;if(!r.current&&"changedTouches"in x&&(O||N)&&(r.current=T),!T)return!0;var P=r.current||T;return bre(P,E,x,P==="h"?O:N)},[]),u=b.useCallback(function(x){var E=x;if(!(!ru.length||ru[ru.length-1]!==a)){var _="deltaY"in E?$M(E):kp(E),k=t.current.filter(function(T){return T.name===E.type&&(T.target===E.target||E.target===T.shadowParent)&&xre(T.delta,_)})[0];if(k&&k.should){E.cancelable&&E.preventDefault();return}if(!k){var O=(s.current.shards||[]).map(BM).filter(Boolean).filter(function(T){return T.contains(E.target)}),N=O.length>0?l(E,O[0]):!s.current.noIsolation;N&&E.cancelable&&E.preventDefault()}}},[]),d=b.useCallback(function(x,E,_,k){var O={name:x,delta:E,target:_,should:k,shadowParent:_re(_)};t.current.push(O),setTimeout(function(){t.current=t.current.filter(function(N){return N!==O})},1)},[]),h=b.useCallback(function(x){n.current=kp(x),r.current=void 0},[]),m=b.useCallback(function(x){d(x.type,$M(x),x.target,l(x,e.lockRef.current))},[]),p=b.useCallback(function(x){d(x.type,kp(x),x.target,l(x,e.lockRef.current))},[]);b.useEffect(function(){return ru.push(a),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:p}),document.addEventListener("wheel",u,nu),document.addEventListener("touchmove",u,nu),document.addEventListener("touchstart",h,nu),function(){ru=ru.filter(function(x){return x!==a}),document.removeEventListener("wheel",u,nu),document.removeEventListener("touchmove",u,nu),document.removeEventListener("touchstart",h,nu)}},[]);var g=e.removeScrollBar,w=e.inert;return b.createElement(b.Fragment,null,w?b.createElement(a,{styles:wre(i)}):null,g?b.createElement(fre,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function _re(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Are=Jne(uz,Sre);var vS=b.forwardRef(function(e,t){return b.createElement(Yv,xa({},e,{ref:t,sideCar:Are}))});vS.classNames=Yv.classNames;var kre=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},iu=new WeakMap,Op=new WeakMap,Np={},zx=0,pz=function(e){return e&&(e.host||pz(e.parentNode))},Ore=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})},Nre=function(e,t,n,r){var i=Ore(t,Array.isArray(e)?e:[e]);Np[n]||(Np[n]=new WeakMap);var a=Np[n],s=[],l=new Set,u=new Set(i),d=function(m){!m||l.has(m)||(l.add(m),d(m.parentNode))};i.forEach(d);var h=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(p){if(l.has(p))h(p);else try{var g=p.getAttribute(r),w=g!==null&&g!=="false",x=(iu.get(p)||0)+1,E=(a.get(p)||0)+1;iu.set(p,x),a.set(p,E),s.push(p),x===1&&w&&Op.set(p,!0),E===1&&p.setAttribute(n,"true"),w||p.setAttribute(r,"true")}catch(_){console.error("aria-hidden: cannot operate on ",p,_)}})};return h(t),l.clear(),zx++,function(){s.forEach(function(m){var p=iu.get(m)-1,g=a.get(m)-1;iu.set(m,p),a.set(m,g),p||(Op.has(m)||m.removeAttribute(r),Op.delete(m)),g||m.removeAttribute(n)}),zx--,zx||(iu=new WeakMap,iu=new WeakMap,Op=new WeakMap,Np={})}},gz=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=kre(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),Nre(r,i,n,"aria-hidden")):function(){return null}},Xv="Dialog",[vz]=hL(Xv),[Cre,Ji]=vz(Xv),yz=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,l=b.useRef(null),u=b.useRef(null),[d,h]=_ne({prop:r,defaultProp:i??!1,onChange:a,caller:Xv});return y.jsx(Cre,{scope:t,triggerRef:l,contentRef:u,contentId:Ix(),titleId:Ix(),descriptionId:Ix(),open:d,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(m=>!m),[h]),modal:s,children:n})};yz.displayName=Xv;var bz="DialogTrigger",xz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(bz,n),a=ui(t,i.triggerRef);return y.jsx(Fr.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":ES(i.open),...r,ref:a,onClick:Sr(e.onClick,i.onOpenToggle)})});xz.displayName=bz;var yS="DialogPortal",[Tre,wz]=vz(yS,{forceMount:void 0}),Ez=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Ji(yS,t);return y.jsx(Tre,{scope:t,forceMount:n,children:b.Children.map(r,s=>y.jsx(Zs,{present:n||a.open,children:y.jsx(lz,{asChild:!0,container:i,children:s})}))})};Ez.displayName=yS;var Pg="DialogOverlay",bS=b.forwardRef((e,t)=>{const n=wz(Pg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Ji(Pg,e.__scopeDialog);return a.modal?y.jsx(Zs,{present:r||a.open,children:y.jsx(Ire,{...i,ref:t})}):null});bS.displayName=Pg;var Mre=GE("DialogOverlay.RemoveScroll"),Ire=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(Pg,n),a=Ine(),s=ui(t,a);return y.jsx(vS,{as:Mre,allowPinchZoom:!0,shards:[i.contentRef],children:y.jsx(Fr.div,{"data-state":ES(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),Uu="DialogContent",xS=b.forwardRef((e,t)=>{const n=wz(Uu,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Ji(Uu,e.__scopeDialog);return y.jsx(Zs,{present:r||a.open,children:a.modal?y.jsx(Rre,{...i,ref:t}):y.jsx(Pre,{...i,ref:t})})});xS.displayName=Uu;var Rre=b.forwardRef((e,t)=>{const n=Ji(Uu,e.__scopeDialog),r=b.useRef(null),i=ui(t,n.contentRef,r);return b.useEffect(()=>{const a=r.current;if(a)return gz(a)},[]),y.jsx(Sz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:Sr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:Sr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,l=s.button===0&&s.ctrlKey===!0;(s.button===2||l)&&a.preventDefault()}),onFocusOutside:Sr(e.onFocusOutside,a=>a.preventDefault())})}),Pre=b.forwardRef((e,t)=>{const n=Ji(Uu,e.__scopeDialog),r=b.useRef(!1),i=b.useRef(!1);return y.jsx(Sz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,l;(s=e.onCloseAutoFocus)==null||s.call(e,a),a.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var u,d;(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;((d=n.triggerRef.current)==null?void 0:d.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),Sz=b.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,l=Ji(Uu,n);return Kne(),y.jsx(y.Fragment,{children:y.jsx(oz,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:y.jsx(iz,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ES(l.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),_z="DialogTitle",wS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(_z,n);return y.jsx(Fr.h2,{id:i.titleId,...r,ref:t})});wS.displayName=_z;var Az="DialogDescription",Dre=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(Az,n);return y.jsx(Fr.p,{id:i.descriptionId,...r,ref:t})});Dre.displayName=Az;var kz="DialogClose",Oz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(kz,n);return y.jsx(Fr.button,{type:"button",...r,ref:t,onClick:Sr(e.onClick,()=>i.onOpenChange(!1))})});Oz.displayName=kz;function ES(e){return e?"open":"closed"}const Oo=yz,rd=xz,jre=Ez,Nz=b.forwardRef(({className:e,...t},n)=>y.jsx(bS,{ref:n,className:ze("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}));Nz.displayName=bS.displayName;const Na=b.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(jre,{children:[y.jsx(Nz,{}),y.jsxs(xS,{ref:r,className:ze("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,y.jsxs(Oz,{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:[y.jsx(Bs,{className:"h-4 w-4"}),y.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Na.displayName=xS.displayName;function Us({className:e,...t}){return y.jsx("div",{className:ze("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function Cz({className:e,...t}){return y.jsx("div",{"data-dialog-body":!0,className:ze("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Tz({className:e,...t}){return y.jsx("div",{className:ze("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 No=b.forwardRef(({className:e,...t},n)=>y.jsx(wS,{ref:n,className:ze("text-lg font-semibold leading-none tracking-tight",e),...t}));No.displayName=wS.displayName;const Lre=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),zre=new Set(["pdf","mp4","webm","mp3","ogg","wav"]);async function $re(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 Bre({getToken:e,onRefresh:t,refreshKey:n}){const[r,i]=b.useState(new Map),[a,s]=b.useState(()=>new Set),[l,u]=b.useState(null),[d,h]=b.useState(!1),[m,p]=b.useState("fit"),[g,w]=b.useState(null),[x,E]=b.useState(null),_=b.useRef(null),[k,O]=b.useState(null),[N,T]=b.useState(!1),[C,M]=b.useState([]),D=b.useCallback(async U=>{const K=await $re(U,e);i(F=>new Map(F).set(U,K))},[e]);b.useEffect(()=>{D(""),a.forEach(U=>D(U))},[D,n]);const j=r.get("")??[],R=b.useCallback(U=>{try{const K=U.contentDocument;if(!(K!=null&&K.body))return;const F=Math.max(K.body.offsetWidth,K.body.scrollWidth),V=Math.max(K.body.offsetHeight,K.body.scrollHeight);F&&V&&E({w:F,h:V})}catch{}},[]),H=b.useCallback(()=>{const U=_.current,K=x;if(!U||!K)return;const F=16,V=U.clientWidth-F,$=U.clientHeight-F,L=Math.min(V/K.w,$/K.h,1);w({scale:L,w:K.w,h:K.h})},[x]);b.useEffect(()=>{if(!(l!=null&&l.html)||m!=="fit"){w(null);return}const U=_.current;if(!U)return;const K=new ResizeObserver(()=>requestAnimationFrame(H));return K.observe(U),()=>K.disconnect()},[l==null?void 0:l.html,d,m,H]),b.useEffect(()=>{N&&e().then(U=>{U&&fetch("/api/data-sync/log",{headers:{Authorization:`Bearer ${U}`}}).then(K=>K.json()).then(M).catch(()=>{})})},[N]);const P=U=>{s(K=>{const F=new Set(K);return F.has(U)?F.delete(U):(F.add(U),r.has(U)||D(U)),F})},G=(U,K)=>{const F=new URLSearchParams({path:U});return k&&F.set("token",k),K&&F.set("dl","1"),`/api/workspace/raw?${F}`},q=async U=>{var V;const K=await e();if(!K)return;O(K);const F=((V=U.split(".").pop())==null?void 0:V.toLowerCase())??"";if(F==="html"||F==="htm"){u({path:U,content:"",binary:!1,html:!0});return}if(Lre.has(F)){u({path:U,content:"",binary:!1,image:!0});return}if(zre.has(F)){u({path:U,content:"",binary:!1,html:!0});return}try{const $=await fetch(`/api/workspace/file?path=${encodeURIComponent(U)}`,{headers:{Authorization:`Bearer ${K}`}});if(!$.ok)return;const L=await $.json();u({path:U,content:L.content,binary:!!L.binary})}catch{}},X=(U,K)=>y.jsx(y.Fragment,{children:U.map(F=>{const V=F.path.split("/").pop();return y.jsxs("div",{children:[F.type==="dir"?y.jsxs("button",{onClick:()=>P(F.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+K*12},children:[y.jsx(Xs,{className:ze("w-3 h-3 shrink-0 transition-transform",a.has(F.path)&&"rotate-90")}),y.jsx(JG,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),y.jsx("span",{className:"truncate",children:V})]}):y.jsxs("button",{onClick:()=>q(F.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+K*12+12},title:F.oneLiner||F.path,children:[y.jsx(UE,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),y.jsx("span",{className:"truncate",children:V})]}),F.type==="dir"&&a.has(F.path)&&X(r.get(F.path)??[],K+1)]},F.path)})});return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1 shrink-0",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Workspace"}),y.jsxs("div",{className:"flex items-center gap-0.5",children:[y.jsx("button",{onClick:()=>T(!0),className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Activity log",children:y.jsx(tV,{className:"w-3 h-3"})}),y.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:y.jsx(ed,{className:"w-3 h-3"})})]})]}),y.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:j.length===0?y.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."}):X(j,0)}),y.jsx(Oo,{open:!!l,onOpenChange:U=>{U||(u(null),h(!1),p("fit"),E(null))},children:y.jsxs(Na,{className:ze(l!=null&&l.html?ze("!flex !flex-col !p-0 !gap-0 overflow-hidden",d?"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:[y.jsxs("div",{className:"absolute right-12 top-4 flex items-center gap-1.5 z-10",children:[(l==null?void 0:l.html)&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:()=>p(U=>U==="fit"?"scroll":"fit"),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:m==="fit"?"Switch to scrollable (1:1)":"Switch to scale-to-fit",children:m==="fit"?y.jsx(oV,{className:"w-4 h-4"}):y.jsx(fV,{className:"w-4 h-4"})}),y.jsx("button",{onClick:()=>h(U=>!U),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:d?"Restore":"Maximize",children:d?y.jsx(HE,{className:"w-4 h-4"}):y.jsx(FE,{className:"w-4 h-4"})})]}),l&&y.jsx("a",{href:G(l.path,!0),download:!0,className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:"Download",children:y.jsx(lL,{className:"w-4 h-4"})})]}),y.jsx(Us,{className:ze((l==null?void 0:l.html)&&"px-4 py-3 shrink-0 border-b"),children:y.jsx(No,{className:"font-mono text-sm truncate pr-16",children:l==null?void 0:l.path})}),y.jsx("div",{ref:l!=null&&l.html?_:void 0,className:ze(l!=null&&l.html?ze("flex-1 min-h-0 bg-muted/10",m==="fit"?"overflow-hidden flex items-center justify-center":"overflow-auto"):"flex-1 min-h-0 overflow-y-auto"),children:l!=null&&l.html?m==="fit"?y.jsx("div",{style:g?{width:g.w*g.scale,height:g.h*g.scale}:{width:"100%",height:"100%"},children:y.jsx("iframe",{src:G(l.path),className:"border-0 bg-white origin-top-left",title:l.path,onLoad:U=>{R(U.currentTarget),H()},style:g?{width:g.w,height:g.h,transform:`scale(${g.scale})`}:{width:"100%",height:"100%"}})}):y.jsx("iframe",{src:G(l.path),className:"border-0 bg-white mx-auto block",title:l.path,onLoad:U=>R(U.currentTarget),style:{width:(x==null?void 0:x.w)||"100%",height:(x==null?void 0:x.h)||"100%"}}):l!=null&&l.image?y.jsx("div",{className:"flex items-center justify-center p-4",children:y.jsx("img",{src:G(l.path),alt:l.path,className:"max-w-full max-h-[70vh] object-contain"})}):l!=null&&l.binary?y.jsx("p",{className:"text-sm text-muted-foreground",children:"(binary file — preview unavailable)"}):l!=null&&l.path.toLowerCase().endsWith(".md")||l!=null&&l.path.toLowerCase().endsWith(".markdown")?y.jsx("div",{className:"text-sm",children:y.jsx(d3,{remarkPlugins:[D3],rehypePlugins:[rz],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:l.content})}):y.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:l==null?void 0:l.content})})]})}),y.jsx(Oo,{open:N,onOpenChange:T,children:y.jsxs(Na,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[y.jsx(Us,{children:y.jsx(No,{className:"text-sm",children:"Activity Log"})}),y.jsxs("div",{className:"overflow-y-auto flex-1 space-y-2",children:[C.map(U=>y.jsxs("div",{className:"border-b border-border/50 pb-2 last:border-0",children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[y.jsx("span",{className:"text-sm text-foreground",children:U.message}),y.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:Ure(U.date)})]}),U.files.length>0&&y.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:U.files.map(K=>y.jsx("span",{className:"inline-block mr-2 font-mono",children:K},K))})]},U.hash)),C.length===0&&y.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No activity yet"})]})]})})]})}function Ure(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 ag(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),l=i%24;return l?`${s}d ${l}h`:`${s}d`}const Fre=/resets\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\s*\(UTC\)/i;function Hre(e,t=Date.now(),n=Date.now()){var m;const r=e.match(Fre);if(!r)return e;let i=Number(r[1]);const a=r[2]?Number(r[2]):0,s=(m=r[3])==null?void 0:m.toLowerCase();if(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0),i>23||a>59)return e;const l=new Date(t),u=new Date(Date.UTC(l.getUTCFullYear(),l.getUTCMonth(),l.getUTCDate(),i,a));u.getTime()<=t&&u.setUTCDate(u.getUTCDate()+1);const d=u.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),h=ag(u.toISOString(),n);return e.replace(r[0],`resets ${d}${h?` (in ${h})`:""}`)}var Kre=Object.defineProperty,id=(e,t)=>Kre(e,"name",{value:t,configurable:!0}),Mz=!!(typeof window<"u"&&window.document&&window.document.createElement);function Ds(e,t,{checkForDefaultPrevented:n=!0}={}){return id(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}id(Ds,"composeEventHandlers");function qre(e){var t;if(!Mz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}id(qre,"getOwnerWindow");function l1(e){if(!Mz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}id(l1,"getOwnerDocument");function Iz(e,t=!1){const{activeElement:n}=l1(e);if(!(n!=null&&n.nodeName))return null;if(Rz(n)&&n.contentDocument)return Iz(n.contentDocument.body,t);if(t){const r=n.getAttribute("aria-activedescendant");if(r){const i=l1(n).getElementById(r);if(i)return i}}return n}id(Iz,"getActiveElement");function Rz(e){return e.tagName==="IFRAME"}id(Rz,"isFrame");var Gre=Object.defineProperty,SS=(e,t)=>Gre(e,"name",{value:t,configurable:!0});function c1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}SS(c1,"setRef");function Pz(...e){return t=>{let n=!1;const r=e.map(i=>{const a=c1(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():c1(e[i],null)}}}}SS(Pz,"composeRefs");function ad(...e){return b.useCallback(Pz(...e),e)}SS(ad,"useComposedRefs");var Vre=Object.defineProperty,Ni=(e,t)=>Vre(e,"name",{value:t,configurable:!0});function Wre(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Ni(a=>{const{children:s,...l}=a,u=b.useMemo(()=>l,Object.values(l));return y.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:l=!1}=s,u=b.useContext(n);if(u)return u;if(t!==void 0)return t;if(!l)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ni(i,"useContext"),[r,i]}Ni(Wre,"createContext");function Dz(e,t=[]){let n=[];function r(a,s){const l=b.createContext(s);l.displayName=a+"Context";const u=n.length;n=[...n,s];const d=Ni(m=>{var _;const{scope:p,children:g,...w}=m,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useMemo(()=>w,Object.values(w));return y.jsx(x.Provider,{value:E,children:g})},"Provider");d.displayName=a+"Provider";function h(m,p,g={}){var _;const{optional:w=!1}=g,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useContext(x);if(E)return E;if(s!==void 0)return s;if(!w)throw new Error(`\`${m}\` must be used within \`${a}\``)}return Ni(h,"useContext"),[d,h]}Ni(r,"createContext");const i=Ni(()=>{const a=n.map(s=>b.createContext(s));return Ni(function(l){const u=(l==null?void 0:l[e])||a;return b.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])},"useScope")},"createScope");return i.scopeName=e,[r,jz(i,...t)]}Ni(Dz,"createContextScope");function jz(...e){const t=e[0];if(e.length===1)return t;const n=Ni(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ni(function(a){const s=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(a)[`__scope${d}`];return{...l,...m}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ni(jz,"composeContextScopes");var Yre=Object.defineProperty,ea=(e,t)=>Yre(e,"name",{value:t,configurable:!0});function _S(e){const t=b.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,l=!1;const u=[];u1(i)&&typeof Cp=="function"&&(i=Cp(i._payload)),b.Children.forEach(i,p=>{var g;if(Bz(p)){l=!0;const w=p;let x="child"in w.props?w.props.child:w.props.children;u1(x)&&typeof Cp=="function"&&(x=Cp(x._payload)),s=Zre(w,x),u.push((g=s==null?void 0:s.props)==null?void 0:g.children)}else u.push(p)}),s?s=b.cloneElement(s,void 0,u):!l&&b.Children.count(i)===1&&b.isValidElement(i)&&(s=i);const d=s?$z(s):void 0,h=ad(r,d);if(!s){if(i||i===0)throw new Error(l?eie(e):Jre(e));return i}const m=zz(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}ea(_S,"createSlot");var Lz=Symbol.for("radix.slottable");function Xre(e){const t=ea(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=Lz,t}ea(Xre,"createSlottable");var Zre=ea((e,t)=>{if("child"in e.props){const n=e.props.child;return b.isValidElement(n)?b.cloneElement(n,void 0,e.props.children(n.props.children)):null}return b.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function zz(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]=(...l)=>{const u=a(...l);return i(...l),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}ea(zz,"mergeProps");function $z(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)}ea($z,"getElementRef");function Bz(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Lz}ea(Bz,"isSlottable");var Qre=Symbol.for("react.lazy");function u1(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Qre&&"_payload"in e&&Uz(e._payload)}ea(u1,"isLazyComponent");function Uz(e){return typeof e=="object"&&e!==null&&"then"in e}ea(Uz,"isPromiseLike");var Jre=ea(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),eie=ea(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Cp=ja[" use ".trim().toString()],tie=Object.defineProperty,nie=(e,t)=>tie(e,"name",{value:t,configurable:!0}),rie=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Zv=rie.reduce((e,t)=>{const n=_S(`Primitive.${t}`),r=b.forwardRef((i,a)=>{const{asChild:s,...l}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),y.jsx(u,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Fz(e,t){e&&La.flushSync(()=>e.dispatchEvent(t))}nie(Fz,"dispatchDiscreteCustomEvent");var iie=Object.defineProperty,aie=(e,t)=>iie(e,"name",{value:t,configurable:!0});function Qv(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}aie(Qv,"useCallbackRef");var oie=Object.defineProperty,qn=(e,t)=>oie(e,"name",{value:t,configurable:!0}),d1="dismissableLayer.update",sie="dismissableLayer.pointerDownOutside",lie="dismissableLayer.focusOutside",UM,Hz=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),cie=b.forwardRef(qn(function(t,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:s,onFocusOutside:l,onInteractOutside:u,onDismiss:d,...h}=t,m=b.useContext(Hz),[p,g]=b.useState(null),w=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,x]=b.useState({}),E=ad(n,g),_=Array.from(m.layers),[k]=[...m.layersWithOutsidePointerEventsDisabled].slice(-1),O=k?_.indexOf(k):-1,N=p?_.indexOf(p):-1,T=m.layersWithOutsidePointerEventsDisabled.size>0,C=N>=O,M=b.useRef(!1),D=Kz(P=>{s==null||s(P),u==null||u(P),P.defaultPrevented||d==null||d()},{ownerDocument:w,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:M,dismissableSurfaces:m.dismissableSurfaces,shouldHandlePointerDownOutside:b.useCallback(P=>{if(!(P instanceof Node))return!1;const G=[...m.branches].some(q=>q.contains(P));return C&&!G},[m.branches,C])}),j=qz(P=>{if(i&&M.current)return;const G=P.target;[...m.branches].some(X=>X.contains(G))||(l==null||l(P),u==null||u(P),P.defaultPrevented||d==null||d())},w),R=p?N===_.length-1:!1,H=Qv(P=>{P.key==="Escape"&&(a==null||a(P),!P.defaultPrevented&&d&&(P.preventDefault(),d()))});return b.useEffect(()=>{if(R)return w.addEventListener("keydown",H,{capture:!0}),()=>w.removeEventListener("keydown",H,{capture:!0})},[w,R,H]),b.useEffect(()=>{if(p)return r&&(m.layersWithOutsidePointerEventsDisabled.size===0&&(UM=w.body.style.pointerEvents,w.body.style.pointerEvents="none"),m.layersWithOutsidePointerEventsDisabled.add(p)),m.layers.add(p),f1(),()=>{r&&(m.layersWithOutsidePointerEventsDisabled.delete(p),m.layersWithOutsidePointerEventsDisabled.size===0&&(w.body.style.pointerEvents=UM))}},[p,w,r,m]),b.useEffect(()=>()=>{p&&(m.layers.delete(p),m.layersWithOutsidePointerEventsDisabled.delete(p),f1())},[p,m]),b.useEffect(()=>{const P=qn(()=>x({}),"handleUpdate");return document.addEventListener(d1,P),()=>document.removeEventListener(d1,P)},[]),y.jsx(Zv.div,{...h,ref:E,style:{pointerEvents:T?C?"auto":"none":void 0,...t.style},onFocusCapture:Ds(t.onFocusCapture,j.onFocusCapture),onBlurCapture:Ds(t.onBlurCapture,j.onBlurCapture),onPointerDownCapture:Ds(t.onPointerDownCapture,D.onPointerDownCapture)})},"DismissableLayer"));function uie(){const e=b.useContext(Hz),[t,n]=b.useState(null);return b.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}qn(uie,"useDismissableLayerSurface");var die=qn(()=>!0,"IS_TRUE");function Kz(e,t){const{ownerDocument:n=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:s=die}=t,l=Qv(e),u=b.useRef(!1),d=b.useRef(!1),h=b.useRef(new Map),m=b.useRef(()=>{});return b.useEffect(()=>{function p(){d.current=!1,i.current=!1,h.current.clear()}qn(p,"resetOutsideInteraction");function g(){return Array.from(h.current.values()).some(Boolean)}qn(g,"isOutsideInteractionIntercepted");function w(O){if(!d.current)return;const N=O.target;N instanceof Node&&[...a].some(C=>C.contains(N))||h.current.set(O.type,!0),O.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}qn(w,"handleInteractionCapture");function x(O){d.current&&h.current.set(O.type,!1)}qn(x,"handleInteractionBubble");const E=qn(O=>{if(O.target&&!u.current){let N=function(){n.removeEventListener("click",m.current);const C=g();p(),C||AS(sie,l,T,{discrete:!0})};if(qn(N,"handleAndDispatchPointerDownOutsideEvent"),!s(O.target)){n.removeEventListener("click",m.current),p(),u.current=!1;return}const T={originalEvent:O};d.current=!0,i.current=r&&O.button===0,h.current.clear(),!r||O.button!==0?N():(n.removeEventListener("click",m.current),m.current=N,n.addEventListener("click",m.current,{once:!0}))}else n.removeEventListener("click",m.current),p();u.current=!1},"handlePointerDown"),_=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const O of _)n.addEventListener(O,w,!0),n.addEventListener(O,x);const k=window.setTimeout(()=>{n.addEventListener("pointerdown",E)},0);return()=>{window.clearTimeout(k),n.removeEventListener("pointerdown",E),n.removeEventListener("click",m.current);for(const O of _)n.removeEventListener(O,w,!0),n.removeEventListener(O,x)}},[n,l,r,i,a,s]),{onPointerDownCapture:qn(()=>u.current=!0,"onPointerDownCapture")}}qn(Kz,"usePointerDownOutside");function qz(e,t=globalThis==null?void 0:globalThis.document){const n=Qv(e),r=b.useRef(!1);return b.useEffect(()=>{const i=qn(a=>{a.target&&!r.current&&AS(lie,n,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,n]),{onFocusCapture:qn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:qn(()=>r.current=!1,"onBlurCapture")}}qn(qz,"useFocusOutside");function f1(){const e=new CustomEvent(d1);document.dispatchEvent(e)}qn(f1,"dispatchUpdate");function AS(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?Fz(i,a):i.dispatchEvent(a)}qn(AS,"handleAndDispatchCustomEvent");var fie=Object.defineProperty,kS=(e,t)=>fie(e,"name",{value:t,configurable:!0}),Tp=0,da=null;function hie(e){return OS(),e.children}kS(hie,"FocusGuards");function OS(){b.useEffect(()=>{da||(da={start:h1(),end:h1()});const{start:e,end:t}=da;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Tp++,()=>{Tp===1&&(da==null||da.start.remove(),da==null||da.end.remove(),da=null),Tp=Math.max(0,Tp-1)}},[])}kS(OS,"useFocusGuards");function h1(){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}kS(h1,"createFocusGuard");var mie=Object.defineProperty,pie=(e,t)=>mie(e,"name",{value:t,configurable:!0});function m1(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}pie(m1,"useCallbackRef");var gie=Object.defineProperty,xr=(e,t)=>gie(e,"name",{value:t,configurable:!0}),$x="focusScope.autoFocusOnMount",Bx="focusScope.autoFocusOnUnmount",FM={bubbles:!1,cancelable:!0},vie=b.forwardRef(xr(function(t,n){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:s,...l}=t,[u,d]=b.useState(null),h=m1(a),m=m1(s),p=b.useRef(null),g=ad(n,d),w=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(i){let E=function(N){if(w.paused||!u)return;const T=N.target;u.contains(T)?p.current=T:uo(p.current,{select:!0})},_=function(N){if(w.paused||!u)return;const T=N.relatedTarget;T!==null&&(u.contains(T)||uo(p.current,{select:!0}))},k=function(N){if(document.activeElement===document.body)for(const C of N)C.removedNodes.length>0&&uo(u)};xr(E,"handleFocusIn"),xr(_,"handleFocusOut"),xr(k,"handleMutations"),document.addEventListener("focusin",E),document.addEventListener("focusout",_);const O=new MutationObserver(k);return u&&O.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",E),document.removeEventListener("focusout",_),O.disconnect()}}},[i,u,w.paused]),b.useEffect(()=>{if(u){HM.add(w);const E=document.activeElement;if(!u.contains(E)){const k=new CustomEvent($x,FM);u.addEventListener($x,h),u.dispatchEvent(k),k.defaultPrevented||(Gz(Zz(NS(u)),{select:!0}),document.activeElement===E&&uo(u))}return()=>{u.removeEventListener($x,h),setTimeout(()=>{const k=new CustomEvent(Bx,FM);u.addEventListener(Bx,m),u.dispatchEvent(k),k.defaultPrevented||uo(E??document.body,{select:!0}),u.removeEventListener(Bx,m),HM.remove(w)},0)}}},[u,h,m,w]);const x=b.useCallback(E=>{if(!r&&!i||w.paused)return;const _=E.key==="Tab"&&!E.altKey&&!E.ctrlKey&&!E.metaKey,k=document.activeElement;if(_&&k){const O=E.currentTarget,[N,T]=Vz(O);N&&T?!E.shiftKey&&k===T?(E.preventDefault(),r&&uo(N,{select:!0})):E.shiftKey&&k===N&&(E.preventDefault(),r&&uo(T,{select:!0})):k===O&&E.preventDefault()}},[r,i,w.paused]);return y.jsx(Zv.div,{tabIndex:-1,...l,ref:g,onKeyDown:x})},"FocusScope"));function Gz(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(uo(r,{select:t}),document.activeElement!==n)return}xr(Gz,"focusFirst");function Vz(e){const t=NS(e),n=p1(t,e),r=p1(t.reverse(),e);return[n,r]}xr(Vz,"getTabbableEdges");function NS(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:xr(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}xr(NS,"getTabbableCandidates");function p1(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):Wz(r,{upTo:t})))return r}xr(p1,"findVisible");function Wz(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}xr(Wz,"isHidden");function Yz(e){return e instanceof HTMLInputElement&&"select"in e}xr(Yz,"isSelectableInput");function uo(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Yz(e)&&t&&e.select()}}xr(uo,"focus");var HM=Xz();function Xz(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=g1(e,t),e.unshift(t)},remove(t){var n;e=g1(e,t),(n=e[0])==null||n.resume()}}}xr(Xz,"createFocusScopesStack");function g1(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}xr(g1,"arrayRemove");function Zz(e){return e.filter(t=>t.tagName!=="A")}xr(Zz,"removeLinks");var yie=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},bie=Object.defineProperty,xie=(e,t)=>bie(e,"name",{value:t,configurable:!0}),wie=ja[" useId ".trim().toString()]||(()=>{}),Eie=0;function Qz(e){const[t,n]=b.useState(wie());return yie(()=>{e||n(r=>r??String(Eie++))},[e]),e||(t?`radix-${t}`:"")}xie(Qz,"useId");const Sie=["top","right","bottom","left"],Fs=Math.min,xo=Math.max,Dg=Math.round,Mp=Math.floor,wo=e=>({x:e,y:e}),_ie={left:"right",right:"left",bottom:"top",top:"bottom"};function Jz(e,t,n){return xo(e,Fs(t,n))}function Co(e,t){return typeof e=="function"?e(t):e}function Hs(e){return e.split("-")[0]}function od(e){return e.split("-")[1]}function CS(e){return e==="x"?"y":"x"}function TS(e){return e==="y"?"height":"width"}function wa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function MS(e){return CS(wa(e))}function Aie(e,t,n){n===void 0&&(n=!1);const r=od(e),i=MS(e),a=TS(i);let s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=jg(s)),[s,jg(s)]}function kie(e){const t=jg(e);return[v1(e),t,v1(t)]}function v1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const KM=["left","right"],qM=["right","left"],Oie=["top","bottom"],Nie=["bottom","top"];function Cie(e,t,n){switch(e){case"top":case"bottom":return n?t?qM:KM:t?KM:qM;case"left":case"right":return t?Oie:Nie;default:return[]}}function Tie(e,t,n,r){const i=od(e);let a=Cie(Hs(e),n==="start",r);return i&&(a=a.map(s=>s+"-"+i),t&&(a=a.concat(a.map(v1)))),a}function jg(e){const t=Hs(e);return _ie[t]+e.slice(t.length)}function Mie(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 e$(e){return typeof e!="number"?Mie(e):{top:e,right:e,bottom:e,left:e}}function Lg(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 GM(e,t,n){let{reference:r,floating:i}=e;const a=wa(t),s=MS(t),l=TS(s),u=Hs(t),d=a==="y",h=r.x+r.width/2-i.width/2,m=r.y+r.height/2-i.height/2,p=r[l]/2-i[l]/2;let g;switch(u){case"top":g={x:h,y:r.y-i.height};break;case"bottom":g={x:h,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:m};break;case"left":g={x:r.x-i.width,y:m};break;default:g={x:r.x,y:r.y}}const w=od(t);return w&&(g[s]+=p*(w==="end"?1:-1)*(n&&d?-1:1)),g}async function Iie(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:s,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:m="floating",altBoundary:p=!1,padding:g=0}=Co(t,e),w=e$(g),E=l[p?m==="floating"?"reference":"floating":m],_=Lg(await a.getClippingRect({element:(n=await(a.isElement==null?void 0:a.isElement(E)))==null||n?E:E.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=m==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,O=await(a.getOffsetParent==null?void 0:a.getOffsetParent(l.floating)),N=await(a.isElement==null?void 0:a.isElement(O))&&await(a.getScale==null?void 0:a.getScale(O))||{x:1,y:1},T=Lg(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:O,strategy:u}):k);return{top:(_.top-T.top+w.top)/N.y,bottom:(T.bottom-_.bottom+w.bottom)/N.y,left:(_.left-T.left+w.left)/N.x,right:(T.right-_.right+w.right)/N.x}}const Rie=50,Pie=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:s}=n,l=s.detectOverflow?s:{...s,detectOverflow:Iie},u=await(s.isRTL==null?void 0:s.isRTL(t));let d=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:m}=GM(d,r,u),p=r,g=0;const w={};for(let x=0;x<a.length;x++){const E=a[x];if(!E)continue;const{name:_,fn:k}=E,{x:O,y:N,data:T,reset:C}=await k({x:h,y:m,initialPlacement:r,placement:p,strategy:i,middlewareData:w,rects:d,platform:l,elements:{reference:e,floating:t}});h=O??h,m=N??m,w[_]={...w[_],...T},C&&g<Rie&&(g++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(d=C.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:i}):C.rects),{x:h,y:m}=GM(d,p,u)),x=-1)}return{x:h,y:m,placement:p,strategy:i,middlewareData:w}},Die=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:a,platform:s,elements:l,middlewareData:u}=t,{element:d,padding:h=0}=Co(e,t)||{};if(d==null)return{};const m=e$(h),p={x:n,y:r},g=MS(i),w=TS(g),x=await s.getDimensions(d),E=g==="y",_=E?"top":"left",k=E?"bottom":"right",O=E?"clientHeight":"clientWidth",N=a.reference[w]+a.reference[g]-p[g]-a.floating[w],T=p[g]-a.reference[g],C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(d));let M=C?C[O]:0;(!M||!await(s.isElement==null?void 0:s.isElement(C)))&&(M=l.floating[O]||a.floating[w]);const D=N/2-T/2,j=M/2-x[w]/2-1,R=Fs(m[_],j),H=Fs(m[k],j),P=M-x[w]-H,G=M/2-x[w]/2+D,q=Jz(R,G,P),X=!u.arrow&&od(i)!=null&&G!==q&&a.reference[w]/2-(G<R?R:H)-x[w]/2<0,U=X?G<R?G-R:G-P:0;return{[g]:p[g]+U,data:{[g]:q,centerOffset:G-q-U,...X&&{alignmentOffset:U}},reset:X}}}),jie=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:l,platform:u,elements:d}=t,{mainAxis:h=!0,crossAxis:m=!0,fallbackPlacements:p,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:x=!0,...E}=Co(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=Hs(i),k=wa(l),O=Hs(l)===l,N=await(u.isRTL==null?void 0:u.isRTL(d.floating)),T=p||(O||!x?[jg(l)]:kie(l)),C=w!=="none";!p&&C&&T.push(...Tie(l,x,w,N));const M=[l,...T],D=await u.detectOverflow(t,E),j=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&j.push(D[_]),m){const q=Aie(i,s,N);j.push(D[q[0]],D[q[1]])}if(R=[...R,{placement:i,overflows:j}],!j.every(q=>q<=0)){var H,P;const q=(((H=a.flip)==null?void 0:H.index)||0)+1,X=M[q];if(X&&(!(m==="alignment"?k!==wa(X):!1)||R.every(F=>wa(F.placement)===k?F.overflows[0]>0:!0)))return{data:{index:q,overflows:R},reset:{placement:X}};let U=(P=R.filter(K=>K.overflows[0]<=0).sort((K,F)=>K.overflows[1]-F.overflows[1])[0])==null?void 0:P.placement;if(!U)switch(g){case"bestFit":{var G;const K=(G=R.filter(F=>{if(C){const V=wa(F.placement);return V===k||V==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(V=>V>0).reduce((V,$)=>V+$,0)]).sort((F,V)=>F[1]-V[1])[0])==null?void 0:G[0];K&&(U=K);break}case"initialPlacement":U=l;break}if(i!==U)return{reset:{placement:U}}}return{}}}};function VM(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function WM(e){return Sie.some(t=>e[t]>=0)}const Lie=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...a}=Co(e,t);switch(i){case"referenceHidden":{const s=await r.detectOverflow(t,{...a,elementContext:"reference"}),l=VM(s,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:WM(l)}}}case"escaped":{const s=await r.detectOverflow(t,{...a,altBoundary:!0}),l=VM(s,n.floating);return{data:{escapedOffsets:l,escaped:WM(l)}}}default:return{}}}}},t$=new Set(["left","top"]);async function zie(e,t){const{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=Hs(n),l=od(n),u=wa(n)==="y",d=t$.has(s)?-1:1,h=a&&u?-1:1,m=Co(t,e);let{mainAxis:p,crossAxis:g,alignmentAxis:w}=typeof m=="number"?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:m.mainAxis||0,crossAxis:m.crossAxis||0,alignmentAxis:m.alignmentAxis};return l&&typeof w=="number"&&(g=l==="end"?w*-1:w),u?{x:g*h,y:p*d}:{x:p*d,y:g*h}}const $ie=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:l}=t,u=await zie(t,e);return s===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:a+u.y,data:{...u,placement:s}}}}},Bie=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:l=!1,limiter:u={fn:k=>{let{x:O,y:N}=k;return{x:O,y:N}}},...d}=Co(e,t),h={x:n,y:r},m=await a.detectOverflow(t,d),p=wa(i),g=CS(p);let w=h[g],x=h[p];const E=(k,O)=>Jz(O+m[k==="y"?"top":"left"],O,O-m[k==="y"?"bottom":"right"]);s&&(w=E(g,w)),l&&(x=E(p,x));const _=u.fn({...t,[g]:w,[p]:x});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[g]:s,[p]:l}}}}}},Uie=function(e){return e===void 0&&(e={}),{options:e,fn(t){var n,r;const{x:i,y:a,placement:s,rects:l,middlewareData:u}=t,{offset:d=0,mainAxis:h=!0,crossAxis:m=!0}=Co(e,t),p={x:i,y:a},g=wa(s),w=CS(g);let x=p[w],E=p[g];const _=Co(d,t),k=typeof _=="number"?{mainAxis:_,crossAxis:0}:{mainAxis:(n=_.mainAxis)!=null?n:0,crossAxis:(r=_.crossAxis)!=null?r:0};if(h){const T=w==="y"?"height":"width",C=l.reference[w]-l.floating[T]+k.mainAxis,M=l.reference[w]+l.reference[T]-k.mainAxis;x<C?x=C:x>M&&(x=M)}if(m){var O,N;const T=w==="y"?"width":"height",C=t$.has(Hs(s)),M=l.reference[g]-l.floating[T]+(C&&((O=u.offset)==null?void 0:O[g])||0)+(C?0:k.crossAxis),D=l.reference[g]+l.reference[T]+(C?0:((N=u.offset)==null?void 0:N[g])||0)-(C?k.crossAxis:0);E<M?E=M:E>D&&(E=D)}return{[w]:x,[g]:E}}}},Fie=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=()=>{},...l}=Co(e,t),u=await i.detectOverflow(t,l),d=Hs(n),h=od(n),m=wa(n)==="y",{width:p,height:g}=r.floating;let w,x;d==="top"||d==="bottom"?(w=d,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=d,w=h==="end"?"top":"bottom");const E=g-u.top-u.bottom,_=p-u.left-u.right,k=Fs(g-u[w],E),O=Fs(p-u[x],_),N=t.middlewareData.shift,T=!N;let C=k,M=O;N!=null&&N.enabled.x&&(M=_),N!=null&&N.enabled.y&&(C=E),T&&!h&&(m?M=p-2*xo(u.left,u.right):C=g-2*xo(u.top,u.bottom)),await s({...t,availableWidth:M,availableHeight:C});const D=await i.getDimensions(a.floating);return p!==D.width||g!==D.height?{reset:{rects:!0}}:{}}}};function Jv(){return typeof window<"u"}function sd(e){return n$(e)?(e.nodeName||"").toLowerCase():"#document"}function Ur(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jo(e){var t;return(t=(n$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function n$(e){return Jv()?e instanceof Node||e instanceof Ur(e).Node:!1}function Ca(e){return Jv()?e instanceof Element||e instanceof Ur(e).Element:!1}function Js(e){return Jv()?e instanceof HTMLElement||e instanceof Ur(e).HTMLElement:!1}function YM(e){return!Jv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ur(e).ShadowRoot}function ey(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Ta(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Hie(e){return/^(table|td|th)$/.test(sd(e))}function ty(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Kie=/transform|translate|scale|rotate|perspective|filter/,qie=/paint|layout|strict|content/,Al=e=>!!e&&e!=="none";let Ux;function IS(e){const t=Ca(e)?Ta(e):e;return Al(t.transform)||Al(t.translate)||Al(t.scale)||Al(t.rotate)||Al(t.perspective)||!RS()&&(Al(t.backdropFilter)||Al(t.filter))||Kie.test(t.willChange||"")||qie.test(t.contain||"")}function Gie(e){let t=ec(e);for(;Js(t)&&!nh(t);){if(IS(t))return t;if(ty(t))return null;t=ec(t)}return null}function RS(){return Ux==null&&(Ux=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Ux}function nh(e){return/^(html|body|#document)$/.test(sd(e))}function Ta(e){return Ur(e).getComputedStyle(e)}function ny(e){return Ca(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ec(e){if(sd(e)==="html")return e;const t=e.assignedSlot||e.parentNode||YM(e)&&e.host||jo(e);return YM(t)?t.host:t}function r$(e){const t=ec(e);return nh(t)?(e.ownerDocument||e).body:Js(t)&&ey(t)?t:r$(t)}function rh(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=r$(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=Ur(i);if(a){const l=y1(s);return t.concat(s,s.visualViewport||[],ey(i)?i:[],l&&n?rh(l):[])}else return t.concat(i,rh(i,[],n))}function y1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function i$(e){const t=Ta(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Js(e),a=i?e.offsetWidth:n,s=i?e.offsetHeight:r,l=Dg(n)!==a||Dg(r)!==s;return l&&(n=a,r=s),{width:n,height:r,$:l}}function PS(e){return Ca(e)?e:e.contextElement}function Tu(e){const t=PS(e);if(!Js(t))return wo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=i$(t);let s=(a?Dg(n.width):n.width)/r,l=(a?Dg(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!l||!Number.isFinite(l))&&(l=1),{x:s,y:l}}const Vie=wo(0);function a$(e){const t=Ur(e);return!RS()||!t.visualViewport?Vie:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Wie(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Ur(e)}function tc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=PS(e);let s=wo(1);t&&(r?Ca(r)&&(s=Tu(r)):s=Tu(e));const l=Wie(a,n,r)?a$(a):wo(0);let u=(i.left+l.x)/s.x,d=(i.top+l.y)/s.y,h=i.width/s.x,m=i.height/s.y;if(a&&r){const p=Ur(a),g=Ca(r)?Ur(r):r;let w=p,x=y1(w);for(;x&&g!==w;){const E=Tu(x),_=x.getBoundingClientRect(),k=Ta(x),O=_.left+(x.clientLeft+parseFloat(k.paddingLeft))*E.x,N=_.top+(x.clientTop+parseFloat(k.paddingTop))*E.y;u*=E.x,d*=E.y,h*=E.x,m*=E.y,u+=O,d+=N,w=Ur(x),x=y1(w)}}return Lg({width:h,height:m,x:u,y:d})}function ry(e,t){const n=ny(e).scrollLeft;return t?t.left+n:tc(jo(e)).left+n}function o$(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ry(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Yie(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const a=i==="fixed",s=jo(r),l=t?ty(t.floating):!1;if(r===s||l&&a)return n;let u={scrollLeft:0,scrollTop:0},d=wo(1);const h=wo(0),m=Js(r);if((m||!a)&&((sd(r)!=="body"||ey(s))&&(u=ny(r)),m)){const g=tc(r);d=Tu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const p=s&&!m&&!a?o$(s,u):wo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+p.x,y:n.y*d.y-u.scrollTop*d.y+h.y+p.y}}function Xie(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Zie(e){const t=ny(e),n=e.ownerDocument.body,r=xo(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=xo(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+ry(e);const s=-t.scrollTop;return Ta(n).direction==="rtl"&&(a+=xo(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:s}}const Qie=25;function Jie(e,t,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",i=Ur(e),a=jo(e),s=i.visualViewport;let l=a.clientWidth,u=a.clientHeight,d=0,h=0;if(s){const p=!RS()||t==="fixed";r?p||(d=-s.offsetLeft,h=-s.offsetTop):(l=s.width,u=s.height,p&&(d=s.offsetLeft,h=s.offsetTop))}if(ry(a)<=0){const p=a.ownerDocument,g=p.body,w=getComputedStyle(g),x=p.compatMode==="CSS1Compat"&&parseFloat(w.marginLeft)+parseFloat(w.marginRight)||0,E=Math.abs(a.clientWidth-g.clientWidth-x),_=getComputedStyle(a).scrollbarGutter==="stable both-edges"?E/2:E;_<=Qie&&(l-=_)}return{width:l,height:u,x:d,y:h}}function eae(e,t){const n=tc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Tu(e),s=e.clientWidth*a.x,l=e.clientHeight*a.y,u=i*a.x,d=r*a.y;return{width:s,height:l,x:u,y:d}}function XM(e,t,n){let r;if(t==="viewport"||t==="layoutViewport")r=Jie(e,n,t);else if(t==="document")r=Zie(jo(e));else if(Ca(t))r=eae(t,n);else{const i=a$(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Lg(r)}function tae(e,t){const n=t.get(e);if(n)return n;let r=rh(e,[],!1).filter(l=>Ca(l)&&sd(l)!=="body"),i=null;const a=Ta(e).position==="fixed";let s=a?ec(e):e;for(;Ca(s)&&!nh(s);){const l=Ta(s),u=IS(s),d=i?i.position:a?"fixed":"";!u&&(d==="fixed"||d==="absolute"&&l.position==="static")?r=r.filter(m=>m!==s):i=l,s=ec(s)}return t.set(e,r),r}function nae(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const s=[...n==="clippingAncestors"?ty(t)?[]:tae(t,this._c):[].concat(n),r],l=XM(t,s[0],i);let u=l.top,d=l.right,h=l.bottom,m=l.left;for(let p=1;p<s.length;p++){const g=XM(t,s[p],i);u=xo(g.top,u),d=Fs(g.right,d),h=Fs(g.bottom,h),m=xo(g.left,m)}return{width:d-m,height:h-u,x:m,y:u}}function rae(e){const{width:t,height:n}=i$(e);return{width:t,height:n}}function iae(e,t,n){const r=Js(t),i=jo(t),a=n==="fixed",s=tc(e,!0,a,t);let l={scrollLeft:0,scrollTop:0};const u=wo(0);if((r||!a)&&((sd(t)!=="body"||ey(i))&&(l=ny(t)),r)){const p=tc(t,!0,a,t);u.x=p.x+t.clientLeft,u.y=p.y+t.clientTop}!r&&i&&(u.x=ry(i));const d=i&&!r&&!a?o$(i,l):wo(0),h=s.left+l.scrollLeft-u.x-d.x,m=s.top+l.scrollTop-u.y-d.y;return{x:h,y:m,width:s.width,height:s.height}}function Fx(e){return Ta(e).position==="static"}function ZM(e,t){if(!Js(e)||Ta(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return jo(e)===n&&(n=n.ownerDocument.body),n}function s$(e,t){const n=Ur(e);if(ty(e))return n;if(!Js(e)){let i=ec(e);for(;i&&!nh(i);){if(Ca(i)&&!Fx(i))return i;i=ec(i)}return n}let r=ZM(e,t);for(;r&&Hie(r)&&Fx(r);)r=ZM(r,t);return r&&nh(r)&&Fx(r)&&!IS(r)?n:r||Gie(e)||n}const aae=async function(e){const t=this.getOffsetParent||s$,n=this.getDimensions,r=await n(e.floating);return{reference:iae(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function oae(e){return Ta(e).direction==="rtl"}const sae={convertOffsetParentRelativeRectToViewportRelativeRect:Yie,getDocumentElement:jo,getClippingRect:nae,getOffsetParent:s$,getElementRects:aae,getClientRects:Xie,getDimensions:rae,getScale:Tu,isElement:Ca,isRTL:oae};function l$(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function lae(e,t,n){let r=null,i;const a=jo(e);function s(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function l(h,m){h===void 0&&(h=!1),m===void 0&&(m=1),s();const p=e.getBoundingClientRect(),{left:g,top:w,width:x,height:E}=p;if(h||t(),!x||!E)return;const _=Mp(w),k=Mp(a.clientWidth-(g+x)),O=Mp(a.clientHeight-(w+E)),N=Mp(g),C={rootMargin:-_+"px "+-k+"px "+-O+"px "+-N+"px",threshold:xo(0,Fs(1,m))||1};let M=!0;function D(j){const R=j[0].intersectionRatio;if(!l$(p,e.getBoundingClientRect()))return l();if(R!==m){if(!M)return l();R?l(!1,R):i=setTimeout(()=>{l(!1,1e-7)},1e3)}M=!1}try{r=new IntersectionObserver(D,{...C,root:a.ownerDocument})}catch{r=new IntersectionObserver(D,C)}r.observe(e)}const u=Ur(e),d=()=>l(n);return u.addEventListener("resize",d),l(!0),()=>{u.removeEventListener("resize",d),s()}}function cae(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=PS(e),h=i||a?[...d?rh(d):[],...t?rh(t):[]]:[];h.forEach(_=>{i&&_.addEventListener("scroll",n),a&&_.addEventListener("resize",n)});const m=d&&l?lae(d,n,a):null;let p=-1,g=null;s&&(g=new ResizeObserver(_=>{let[k]=_;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var O;(O=g)==null||O.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let w,x=u?tc(e):null;u&&E();function E(){const _=tc(e);x&&!l$(x,_)&&n(),x=_,w=requestAnimationFrame(E)}return n(),()=>{var _;h.forEach(k=>{i&&k.removeEventListener("scroll",n),a&&k.removeEventListener("resize",n)}),m==null||m(),(_=g)==null||_.disconnect(),g=null,u&&cancelAnimationFrame(w)}}const uae=$ie,dae=Bie,fae=jie,hae=Fie,mae=Lie,QM=Die,pae=Uie,gae=(e,t,n)=>{const r=new Map,i=n??{},a={...sae,...i.platform,_c:r};return Pie(e,t,{...i,platform:a})};var vae=typeof document<"u",yae=function(){},og=vae?b.useLayoutEffect:yae;function zg(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(!zg(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)&&!zg(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function c$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function JM(e,t){const n=c$(e);return Math.round(t*n)/n}function Hx(e){const t=b.useRef(e);return og(()=>{t.current=e}),t}function bae(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:s}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[h,m]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,g]=b.useState(r);zg(p,r)||g(r);const[w,x]=b.useState(null),[E,_]=b.useState(null),k=b.useCallback(F=>{F!==C.current&&(C.current=F,x(F))},[]),O=b.useCallback(F=>{F!==M.current&&(M.current=F,_(F))},[]),N=a||w,T=s||E,C=b.useRef(null),M=b.useRef(null),D=b.useRef(h),j=u!=null,R=Hx(u),H=Hx(i),P=Hx(d),G=b.useCallback(()=>{if(!C.current||!M.current)return;const F={placement:t,strategy:n,middleware:p};H.current&&(F.platform=H.current),gae(C.current,M.current,F).then(V=>{const $={...V,isPositioned:P.current!==!1};q.current&&!zg(D.current,$)&&(D.current=$,La.flushSync(()=>{m($)}))})},[p,t,n,H,P]);og(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,m(F=>({...F,isPositioned:!1})))},[d]);const q=b.useRef(!1);og(()=>(q.current=!0,()=>{q.current=!1}),[]),og(()=>{if(N&&(C.current=N),T&&(M.current=T),N&&T){if(R.current)return R.current(N,T,G);G()}},[N,T,G,R,j]);const X=b.useMemo(()=>({reference:C,floating:M,setReference:k,setFloating:O}),[k,O]),U=b.useMemo(()=>({reference:N,floating:T}),[N,T]),K=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!U.floating)return F;const V=JM(U.floating,h.x),$=JM(U.floating,h.y);return l?{...F,transform:"translate("+V+"px, "+$+"px)",...c$(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:V,top:$}},[n,l,U.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:G,refs:X,elements:U,floatingStyles:K}),[h,G,X,U,K])}const xae=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?QM({element:r.current,padding:i}).fn(n):{}:r?QM({element:r,padding:i}).fn(n):{}}}},wae=(e,t)=>{const n=uae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eae=(e,t)=>{const n=dae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Sae=(e,t)=>({fn:pae(e).fn,options:[e,t]}),_ae=(e,t)=>{const n=fae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Aae=(e,t)=>{const n=hae(e);return{name:n.name,fn:n.fn,options:[e,t]}},kae=(e,t)=>{const n=mae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Oae=(e,t)=>{const n=xae(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Nae=Object.defineProperty,DS=(e,t)=>Nae(e,"name",{value:t,configurable:!0});function b1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}DS(b1,"setRef");function u$(...e){return t=>{let n=!1;const r=e.map(i=>{const a=b1(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():b1(e[i],null)}}}}DS(u$,"composeRefs");function iy(...e){return b.useCallback(u$(...e),e)}DS(iy,"useComposedRefs");var Cae=Object.defineProperty,Ci=(e,t)=>Cae(e,"name",{value:t,configurable:!0});function Tae(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Ci(a=>{const{children:s,...l}=a,u=b.useMemo(()=>l,Object.values(l));return y.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:l=!1}=s,u=b.useContext(n);if(u)return u;if(t!==void 0)return t;if(!l)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ci(i,"useContext"),[r,i]}Ci(Tae,"createContext");function d$(e,t=[]){let n=[];function r(a,s){const l=b.createContext(s);l.displayName=a+"Context";const u=n.length;n=[...n,s];const d=Ci(m=>{var _;const{scope:p,children:g,...w}=m,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useMemo(()=>w,Object.values(w));return y.jsx(x.Provider,{value:E,children:g})},"Provider");d.displayName=a+"Provider";function h(m,p,g={}){var _;const{optional:w=!1}=g,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useContext(x);if(E)return E;if(s!==void 0)return s;if(!w)throw new Error(`\`${m}\` must be used within \`${a}\``)}return Ci(h,"useContext"),[d,h]}Ci(r,"createContext");const i=Ci(()=>{const a=n.map(s=>b.createContext(s));return Ci(function(l){const u=(l==null?void 0:l[e])||a;return b.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])},"useScope")},"createScope");return i.scopeName=e,[r,f$(i,...t)]}Ci(d$,"createContextScope");function f$(...e){const t=e[0];if(e.length===1)return t;const n=Ci(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ci(function(a){const s=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(a)[`__scope${d}`];return{...l,...m}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ci(f$,"composeContextScopes");var Mae=Object.defineProperty,ta=(e,t)=>Mae(e,"name",{value:t,configurable:!0});function h$(e){const t=b.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,l=!1;const u=[];x1(i)&&typeof Ip=="function"&&(i=Ip(i._payload)),b.Children.forEach(i,p=>{var g;if(v$(p)){l=!0;const w=p;let x="child"in w.props?w.props.child:w.props.children;x1(x)&&typeof Ip=="function"&&(x=Ip(x._payload)),s=Rae(w,x),u.push((g=s==null?void 0:s.props)==null?void 0:g.children)}else u.push(p)}),s?s=b.cloneElement(s,void 0,u):!l&&b.Children.count(i)===1&&b.isValidElement(i)&&(s=i);const d=s?g$(s):void 0,h=iy(r,d);if(!s){if(i||i===0)throw new Error(l?jae(e):Dae(e));return i}const m=p$(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}ta(h$,"createSlot");var m$=Symbol.for("radix.slottable");function Iae(e){const t=ta(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=m$,t}ta(Iae,"createSlottable");var Rae=ta((e,t)=>{if("child"in e.props){const n=e.props.child;return b.isValidElement(n)?b.cloneElement(n,void 0,e.props.children(n.props.children)):null}return b.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function p$(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]=(...l)=>{const u=a(...l);return i(...l),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}ta(p$,"mergeProps");function g$(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)}ta(g$,"getElementRef");function v$(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===m$}ta(v$,"isSlottable");var Pae=Symbol.for("react.lazy");function x1(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Pae&&"_payload"in e&&y$(e._payload)}ta(x1,"isLazyComponent");function y$(e){return typeof e=="object"&&e!==null&&"then"in e}ta(y$,"isPromiseLike");var Dae=ta(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),jae=ta(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Ip=ja[" use ".trim().toString()],Lae=Object.defineProperty,zae=(e,t)=>Lae(e,"name",{value:t,configurable:!0}),$ae=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],b$=$ae.reduce((e,t)=>{const n=h$(`Primitive.${t}`),r=b.forwardRef((i,a)=>{const{asChild:s,...l}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),y.jsx(u,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bae(e,t){e&&La.flushSync(()=>e.dispatchEvent(t))}zae(Bae,"dispatchDiscreteCustomEvent");var Uae=Object.defineProperty,Fae=(e,t)=>Uae(e,"name",{value:t,configurable:!0});function x$(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}Fae(x$,"useCallbackRef");var Kx=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},Hae=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},Kae=Object.defineProperty,qae=(e,t)=>Kae(e,"name",{value:t,configurable:!0});function w$(e){const[t,n]=b.useState(void 0);return Hae(()=>{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,l;if("borderBoxSize"in a){const u=a.borderBoxSize,d=Array.isArray(u)?u[0]:u;s=d.inlineSize,l=d.blockSize}else s=e.offsetWidth,l=e.offsetHeight;n({width:s,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}qae(w$,"useSize");var Gae=Object.defineProperty,js=(e,t)=>Gae(e,"name",{value:t,configurable:!0}),E$="Popper",[S$,_$]=d$(E$),[Vae,A$]=S$(E$),Wae=js(e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null),[a,s]=b.useState(void 0);return y.jsx(Vae,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:s,children:n})},"Popper"),Yae="PopperAnchor",Xae=b.forwardRef(js(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=A$(Yae,r),l=b.useRef(null),u=s.onAnchorChange,d=b.useCallback(x=>{l.current=x,x&&u(x)},[u]),h=iy(n,d),m=b.useRef(null);b.useEffect(()=>{if(!i)return;const x=m.current;m.current=i.current,x!==m.current&&u(m.current)});const p=s.placementState&&ay(s.placementState),g=p==null?void 0:p[0],w=p==null?void 0:p[1];return i?null:y.jsx(b$.div,{"data-radix-popper-side":g,"data-radix-popper-align":w,...a,ref:h})},"PopperAnchor")),k$="PopperContent",[Zae,cCe]=S$(k$),Qae=b.forwardRef(js(function(t,n){var fe,Ee,Te,de,nt,He,Ae;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:s="center",alignOffset:l=0,arrowPadding:u=0,avoidCollisions:d=!0,collisionBoundary:h=[],collisionPadding:m=0,sticky:p="partial",hideWhenDetached:g=!1,updatePositionStrategy:w="optimized",onPlaced:x,...E}=t,_=A$(k$,r),[k,O]=b.useState(null),N=iy(n,O),[T,C]=b.useState(null),M=w$(T),D=(M==null?void 0:M.width)??0,j=(M==null?void 0:M.height)??0,R=i+(s!=="center"?"-"+s:""),H=typeof m=="number"?m:{top:0,right:0,bottom:0,left:0,...m},P=Array.isArray(h)?h:[h],G=P.length>0,q={padding:H,boundary:P.filter(O$),altBoundary:G},{refs:X,floatingStyles:U,placement:K,isPositioned:F,middlewareData:V}=bae({strategy:"fixed",placement:R,whileElementsMounted:js((...De)=>cae(...De,{animationFrame:w==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[wae({mainAxis:a+j,alignmentAxis:l}),d&&Eae({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Sae():void 0,...q}),d&&_ae({...q}),Aae({...q,apply:js(({elements:De,rects:Ht,availableWidth:un,availableHeight:Yn})=>{const{width:Or,height:Li}=Ht.reference,ir=De.floating.style;ir.setProperty("--radix-popper-available-width",`${un}px`),ir.setProperty("--radix-popper-available-height",`${Yn}px`),ir.setProperty("--radix-popper-anchor-width",`${Or}px`),ir.setProperty("--radix-popper-anchor-height",`${Li}px`)},"apply")}),T&&Oae({element:T,padding:u}),Jae({arrowWidth:D,arrowHeight:j}),g&&kae({strategy:"referenceHidden",...q,boundary:G?q.boundary:void 0})]}),$=_.setPlacementState;Kx(()=>($(K),()=>{$(void 0)}),[K,$]);const[L,W]=ay(K),z=x$(x);Kx(()=>{F&&(z==null||z())},[F,z]);const ie=(fe=V.arrow)==null?void 0:fe.x,he=(Ee=V.arrow)==null?void 0:Ee.y,ge=((Te=V.arrow)==null?void 0:Te.centerOffset)!==0,[Se,$e]=b.useState();return Kx(()=>{k&&$e(window.getComputedStyle(k).zIndex)},[k]),y.jsx("div",{ref:X.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:F?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Se,"--radix-popper-transform-origin":[(de=V.transformOrigin)==null?void 0:de.x,(nt=V.transformOrigin)==null?void 0:nt.y].join(" "),...((He=V.hide)==null?void 0:He.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:y.jsx(Zae,{scope:r,placedSide:L,placedAlign:W,onArrowChange:C,arrowX:ie,arrowY:he,shouldHideArrow:ge,children:y.jsx(b$.div,{"data-side":L,"data-align":W,...E,ref:N,style:{...E.style,animation:F?(Ae=E.style)==null?void 0:Ae.animation:"none"}})})})},"PopperContent"));function O$(e){return e!==null}js(O$,"isNotNull");var Jae=js(e=>({name:"transformOrigin",options:e,fn(t){var E,_,k;const{placement:n,rects:r,middlewareData:i}=t,s=((E=i.arrow)==null?void 0:E.centerOffset)!==0,l=s?0:e.arrowWidth,u=s?0:e.arrowHeight,[d,h]=ay(n),m={start:"0%",center:"50%",end:"100%"}[h],p=(((_=i.arrow)==null?void 0:_.x)??0)+l/2,g=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let w="",x="";return d==="bottom"?(w=s?m:`${p}px`,x=`${-u}px`):d==="top"?(w=s?m:`${p}px`,x=`${r.floating.height+u}px`):d==="right"?(w=`${-u}px`,x=s?m:`${g}px`):d==="left"&&(w=`${r.floating.width+u}px`,x=s?m:`${g}px`),{data:{x:w,y:x}}}}),"transformOrigin");function ay(e){const[t,n="center"]=e.split("-");return[t,n]}js(ay,"getSideAndAlignFromPlacement");var eoe=Wae,toe=Xae,noe=Qae,roe=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},ioe=Object.defineProperty,aoe=(e,t)=>ioe(e,"name",{value:t,configurable:!0}),ooe=b.forwardRef(aoe(function(t,n){var u;const{container:r,...i}=t,[a,s]=b.useState(!1);roe(()=>s(!0),[]);const l=r||a&&((u=globalThis==null?void 0:globalThis.document)==null?void 0:u.body);return l?La.createPortal(y.jsx(Zv.div,{...i,ref:n}),l):null},"Portal")),eI=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},soe=Object.defineProperty,To=(e,t)=>soe(e,"name",{value:t,configurable:!0});function N$(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}To(N$,"useStateMachine");var C$=To(e=>{const{present:t,children:n}=e,r=T$(t),i=typeof n=="function"?n({present:r.isPresent}):b.Children.only(n),a=M$(r.ref,I$(i));return typeof n=="function"||r.isPresent?b.cloneElement(i,{ref:a}):null},"Presence");function T$(e){const[t,n]=b.useState(),r=b.useRef(null),i=b.useRef(e),a=b.useRef("none"),s=b.useRef(void 0),l=e?"mounted":"unmounted",[u,d]=N$(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return b.useEffect(()=>{u==="mounted"?(a.current=s.current??bu(r.current),s.current=void 0):a.current="none"},[u]),eI(()=>{const h=r.current,m=i.current;if(m!==e){const g=a.current,w=bu(h);e?(s.current=w,d("MOUNT")):w==="none"||(h==null?void 0:h.display)==="none"?d("UNMOUNT"):d(m&&g!==w?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,d]),eI(()=>{if(t){let h;const m=t.ownerDocument.defaultView??window,p=To(w=>{const E=bu(r.current).includes(CSS.escape(w.animationName));if(w.target===t&&E&&(d("ANIMATION_END"),!i.current)){const _=t.style.animationFillMode;t.style.animationFillMode="forwards",h=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=_)})}},"handleAnimationEnd"),g=To(w=>{w.target===t&&(a.current=bu(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{m.clearTimeout(h),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:b.useCallback(h=>{if(h){const m=getComputedStyle(h);r.current=m,s.current=bu(m)}else r.current=null;n(h)},[])}}To(T$,"usePresence");function w1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}To(w1,"setRef");function M$(...e){const t=b.useRef(e);return t.current=e,b.useCallback(n=>{const r=t.current;let i=!1;const a=r.map(s=>{const l=w1(s,n);return!i&&typeof l=="function"&&(i=!0),l});if(i)return()=>{for(let s=0;s<a.length;s++){const l=a[s];typeof l=="function"?l():w1(r[s],null)}}},[])}To(M$,"useStableComposedRefs");function bu(e){return(e==null?void 0:e.animationName)||"none"}To(bu,"getAnimationName");function I$(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)}To(I$,"getElementRef");var R$=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},loe=Object.defineProperty,coe=(e,t)=>loe(e,"name",{value:t,configurable:!0}),tI=ja[" useEffectEvent ".trim().toString()],nI=ja[" useInsertionEffect ".trim().toString()];function P$(e){if(typeof tI=="function")return tI(e);const t=b.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof nI=="function"?nI(()=>{t.current=e}):R$(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}coe(P$,"useEffectEvent");var uoe=Object.defineProperty,Nh=(e,t)=>uoe(e,"name",{value:t,configurable:!0}),doe=ja[" useInsertionEffect ".trim().toString()]||R$;function D$({prop:e,defaultProp:t,onChange:n=Nh(()=>{},"onChange"),caller:r}){const[i,a,s]=j$({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:i,d=b.useCallback(h=>{var m;if(l){const p=L$(h)?h(e):h;p!==e&&((m=s.current)==null||m.call(s,p))}else a(h)},[l,e,a,s]);return[u,d]}Nh(D$,"useControllableState");function j$({defaultProp:e,onChange:t}){const[n,r]=b.useState(e),i=b.useRef(n),a=b.useRef(t);return doe(()=>{a.current=t},[t]),b.useEffect(()=>{var s;i.current!==n&&((s=a.current)==null||s.call(a,n),i.current=n)},[n,i]),[n,r,a]}Nh(j$,"useUncontrolledState");function L$(e){return typeof e=="function"}Nh(L$,"isFunction");var rI=Symbol("RADIX:SYNC_STATE");function foe(e,t,n,r){const{prop:i,defaultProp:a,onChange:s,caller:l}=t,u=i!==void 0,d=P$(s),h=[{...n,state:a}];r&&h.push(r);const[m,p]=b.useReducer((E,_)=>{if(_.type===rI)return{...E,state:_.state};const k=e(E,_);return u&&!Object.is(k.state,E.state)&&d(k.state),k},...h),g=m.state,w=b.useRef(g);b.useEffect(()=>{w.current!==g&&(w.current=g,u||d(g))},[g,w,u]);const x=b.useMemo(()=>i!==void 0?{...m,state:i}:m,[m,i]);return b.useEffect(()=>{u&&!Object.is(i,m.state)&&p({type:rI,state:i})},[i,m.state,u]),[x,p]}Nh(foe,"useControllableStateReducer");var hoe=Object.defineProperty,el=(e,t)=>hoe(e,"name",{value:t,configurable:!0}),jS="Popover",[z$,uCe]=Dz(jS,[_$]),LS=_$(),[moe,ld]=z$(jS),poe=el(e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!1}=e,l=LS(t),u=b.useRef(null),[d,h]=b.useState(!1),[m,p]=D$({prop:r,defaultProp:i??!1,onChange:a,caller:jS});return y.jsx(eoe,{...l,children:y.jsx(moe,{scope:t,contentId:Qz(),triggerRef:u,open:m,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(g=>!g),[p]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>h(!0),[]),onCustomAnchorRemove:b.useCallback(()=>h(!1),[]),modal:s,children:n})})},"Popover"),goe="PopoverTrigger",voe=b.forwardRef(el(function(t,n){const{__scopePopover:r,...i}=t,a=ld(goe,r),s=LS(r),l=ad(n,a.triggerRef),u=y.jsx(Zv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":zS(a.open),...i,ref:l,onClick:Ds(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:y.jsx(toe,{asChild:!0,...s,children:u})},"PopoverTrigger")),$$="PopoverPortal",[yoe,boe]=z$($$,{forceMount:void 0}),xoe=el(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=ld($$,t);return y.jsx(yoe,{scope:t,forceMount:n,children:y.jsx(C$,{present:n||a.open,children:y.jsx(ooe,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),ih="PopoverContent",woe=b.forwardRef(el(function(t,n){const r=boe(ih,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=ld(ih,t.__scopePopover);return y.jsx(C$,{present:i||s.open,children:s.modal?y.jsx(Soe,{...a,ref:n}):y.jsx(_oe,{...a,ref:n})})},"PopoverContent")),Eoe=_S("PopoverContent.RemoveScroll"),Soe=b.forwardRef(el(function(t,n){const r=ld(ih,t.__scopePopover),i=b.useRef(null),a=ad(n,i),s=b.useRef(!1);return b.useEffect(()=>{const l=i.current;if(l)return gz(l)},[]),y.jsx(vS,{as:Eoe,allowPinchZoom:!0,children:y.jsx(B$,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ds(t.onCloseAutoFocus,l=>{var u;l.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:Ds(t.onPointerDownOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;s.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:Ds(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),_oe=b.forwardRef(el(function(t,n){const r=ld(ih,t.__scopePopover),i=b.useRef(!1),a=b.useRef(!1);return y.jsx(B$,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var l,u;(l=t.onCloseAutoFocus)==null||l.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 d,h;(d=t.onInteractOutside)==null||d.call(t,s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const l=s.target;((h=r.triggerRef.current)==null?void 0:h.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&a.current&&s.preventDefault()}})},"PopoverContentNonModal")),B$=b.forwardRef(el(function(t,n){const{__scopePopover:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:s,disableOutsidePointerEvents:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:m,...p}=t,g=ld(ih,r),w=LS(r);return OS(),y.jsx(vie,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:s,children:y.jsx(cie,{asChild:!0,disableOutsidePointerEvents:l,onInteractOutside:m,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:h,onDismiss:()=>g.onOpenChange(!1),deferPointerDownOutside:!0,children:y.jsx(noe,{"data-state":zS(g.open),role:"dialog",id:g.contentId,...w,...p,ref:n,style:{...p.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 zS(e){return e?"open":"closed"}el(zS,"getState");var Aoe=poe,koe=voe,Ooe=xoe,U$=woe;const Noe=Aoe,Coe=koe,F$=b.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>y.jsx(Ooe,{children:y.jsx(U$,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:ze("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})}));F$.displayName=U$.displayName;const H$=92,K$=96;function qx(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 iI=3e5;function Toe({socket:e,getToken:t}){const[n,r]=b.useState([]);if(b.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]),b.useEffect(()=>{if(!e)return;const a=e.on(s=>{s.type==="stats"&&r(l=>[...l,s.sample].slice(-120))});return()=>{a()}},[e]),!n.length)return null;const i=n[n.length-1];return y.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:[y.jsx(sg,{label:"cpu",value:i.cpu,series:n.map(a=>a.cpu)}),y.jsx(sg,{label:"mem",value:i.mem,series:n.map(a=>a.mem)}),i.disk>=0&&y.jsx(sg,{label:"disk",value:i.disk,severity:Loe(i.disk),title:$oe(i)}),y.jsx(Moe,{getToken:t})]})}function Moe({getToken:e}){const[t,n]=b.useState(null);return b.useEffect(()=>{let r=!0,i=0;const a=async()=>{var d;try{const h=await e();if(!h)return;i=Date.now();const m=await fetch("/api/claude-usage",{headers:{Authorization:`Bearer ${h}`}});if(!r)return;if(m.status===204){n(null);return}if(m.status!==200)return;const p=await m.json();if(!r||!((d=p==null?void 0:p.limits)!=null&&d.length))return;n(p)}catch(h){console.warn("[MachineStats] claude usage poll failed",h)}},s=()=>{document.visibilityState==="visible"&&a()},l=()=>{document.visibilityState==="visible"&&Date.now()-i>=iI&&a()};s();const u=setInterval(s,iI);return document.addEventListener("visibilitychange",l),()=>{r=!1,clearInterval(u),document.removeEventListener("visibilitychange",l)}},[e]),y.jsx(q$,{usage:t})}function q$({usage:e,compact:t}){const n=e&&G$(e.limits),[r,i]=b.useState(E1),a=b.useRef(null),s=()=>{a.current&&(clearTimeout(a.current),a.current=null)},l=b.useCallback((u,d=0)=>{if(s(),!d){i(h=>oI(h,u));return}a.current=setTimeout(()=>{a.current=null,i(h=>oI(h,u))},d)},[]);return b.useEffect(()=>s,[]),!e||!n?null:y.jsxs(Noe,{open:r.open,onOpenChange:u=>l(u?{type:"activate"}:{type:"dismiss"}),children:[y.jsx(Coe,{asChild:!0,children:y.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:u=>l({type:"pointerenter",pointerType:u.pointerType},Ioe),onPointerLeave:u=>l({type:"pointerleave",pointerType:u.pointerType},aI),children:t?y.jsxs("span",{className:ze("tabular-nums",$g(n.percent,n.severity)),children:[n.percent,"% used"]}):y.jsx(sg,{label:"usage",value:n.percent,severity:n.severity})})}),y.jsx(F$,{onOpenAutoFocus:u=>u.preventDefault(),onPointerEnter:()=>s(),onPointerLeave:u=>l({type:"pointerleave",pointerType:u.pointerType},aI),children:y.jsx(Roe,{usage:e})})]})}const Ioe=120,aI=80,E1={open:!1,byHover:!1};function oI(e,t){switch(t.type){case"pointerenter":return sI(t.pointerType)?{open:!0,byHover:!0}:e;case"pointerleave":return sI(t.pointerType)&&e.byHover?E1:e;case"activate":return{open:!0,byHover:!1};case"dismiss":return E1}}const sI=e=>e==="mouse"||e==="";function Roe({usage:e}){const t=G$(e.limits);return y.jsxs("div",{className:"text-[11px] leading-tight",children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2 pb-2 text-muted-foreground",children:[y.jsx("span",{className:"uppercase tracking-wide",children:"claude usage"}),e.subscriptionType&&y.jsxs("span",{className:"tabular-nums",children:[e.subscriptionType," plan"]})]}),y.jsxs("div",{className:"-mt-1 flex items-baseline justify-between gap-2 pb-2 text-[10px] text-muted-foreground",children:[e.account&&y.jsx("span",{className:"truncate",title:e.account,children:e.account}),y.jsx("span",{className:ze("shrink-0",e.stale&&"text-amber-500"),children:Doe(e)})]}),e.stale&&e.error&&y.jsxs("div",{"data-refresh-error":!0,className:"-mt-1 pb-2 text-[10px] text-amber-500 break-words",children:[e.error,ag(e.retryAt??null)&&` · retrying in ${ag(e.retryAt??null)}`]}),y.jsx("div",{className:"flex flex-col gap-3",children:e.limits.map((n,r)=>{const i=ag(n.resetsAt),a=n===t;return y.jsxs("div",{"data-headline":a||void 0,className:ze("flex flex-col gap-1",!a&&"opacity-60"),children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[y.jsxs("span",{className:ze("truncate",a&&"font-medium"),children:[a&&y.jsx("span",{className:"mr-1 text-muted-foreground","aria-hidden":!0,children:"▸"}),Poe(n)]}),y.jsxs("span",{className:ze("tabular-nums shrink-0",$g(n.percent,n.severity)),children:[n.percent,"%"]})]}),y.jsx(V$,{value:n.percent,className:ze("w-full",$g(n.percent,n.severity))}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:i?`resets in ${i}`:"no reset reported"})]},`${n.kind}-${r}`)})}),y.jsx("div",{className:"mt-3 border-t pt-2 text-[10px] text-muted-foreground",children:"▸ is the window the strip is showing"})]})}function Poe(e){return e.scopeLabel?`${e.scopeLabel} window`:e.kind==="session"?"current session":e.kind==="weekly_all"?"all models":e.kind.replace(/_/g," ")}function G$(e){return e.reduce((t,n)=>!t||n.percent>t.percent?n:t,null)}function Doe(e){const t=joe(e.fetchedAt);return t?e.stale?`${t} old — refresh failed`:`updated ${t} ago`:e.stale?"last reading — refresh failed":"updated just now"}function joe(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 Loe(e){return e>=K$?"critical":e>=H$?"warning":"ok"}const zoe={critical:"text-red-500",exceeded:"text-red-500",warning:"text-amber-500",warn:"text-amber-500",ok:"text-emerald-500"};function $g(e,t){const n=t?zoe[t]:void 0;return n||(e>=90?"text-red-500":e>=75?"text-amber-500":"text-emerald-500")}function $oe(e){const t=`warn at ${H$}%, critical at ${K$}%`;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 — ${qx(e.diskUsedBytes)} of ${qx(e.diskTotalBytes)}, ${qx(n)} free — ${t}`}function sg({label:e,value:t,series:n,title:r,severity:i}){const a=$g(t,i),s=r??(n?`${e} ${t}% — last ${n.length} samples`:void 0);return y.jsxs("span",{className:"flex items-center gap-1",title:s,children:[y.jsx("span",{className:"uppercase tracking-wide",children:e}),n?y.jsx(Boe,{series:n,className:a}):y.jsx(V$,{value:t,className:a}),y.jsxs("span",{className:ze("tabular-nums",a),children:[t,"%"]})]})}function V$({value:e,className:t}){const i=Math.max(0,Math.min(100,e))/100*40;return y.jsxs("svg",{width:40,height:12,viewBox:"0 0 40 12",className:ze("overflow-visible",t),preserveAspectRatio:"none",children:[y.jsx("rect",{x:0,y:12/2-2,width:40,height:4,rx:2,fill:"currentColor",opacity:.2}),i>0&&y.jsx("rect",{x:0,y:12/2-2,width:i,height:4,rx:2,fill:"currentColor"})]})}function Boe({series:e,className:t}){const i=e.length;if(i<2)return null;const a=e.map((s,l)=>{const u=i>1?l/(i-1)*40:0,d=12-Math.max(0,Math.min(100,s))/100*12;return`${u.toFixed(1)},${d.toFixed(1)}`}).join(" ");return y.jsx("svg",{width:40,height:12,viewBox:"0 0 40 12",className:ze("overflow-visible",t),preserveAspectRatio:"none",children:y.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}const kf=50;function Uoe({getToken:e,filter:t,refreshKey:n,hydrateIds:r}){const[i,a]=b.useState([]),[s,l]=b.useState(null),[u,d]=b.useState(!1),[h,m]=b.useState({}),p=b.useRef(new Set),g=b.useRef(null),w=b.useRef(null),x=b.useRef(t);x.current=t;const E=b.useRef(kf),_=b.useRef(t);_.current!==t&&(_.current=t,E.current=kf);const k=b.useCallback(async(M,D)=>{const j=await e();if(!j||D!=null&&D.aborted)return null;const R=await fetch(`/api/sessions?${new URLSearchParams(M)}`,{signal:D,headers:{Authorization:`Bearer ${j}`}});if(!R.ok)return null;const H=await R.json();return Array.isArray(H==null?void 0:H.sessions)?H:null},[e]),O=b.useCallback(async(M,D,j)=>{const R=[];let H,P=null;for(;R.length<M;){const G={filter:D,limit:String(Math.min(kf,M-R.length))};H&&(G.before=H);const q=await k(G,j);if(!q)return null;if(R.push(...q.sessions),P=q.nextCursor,!P||!q.sessions.length)break;H=P}return{sessions:R,nextCursor:P}},[k]);b.useEffect(()=>{var D,j;(D=g.current)==null||D.abort(),(j=w.current)==null||j.abort();const M=new AbortController;return g.current=M,d(!0),p.current.clear(),m({}),O(E.current,t,M.signal).then(R=>{!R||M.signal.aborted||(a(R.sessions),l(R.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)}),()=>M.abort()},[O,t,n]);const N=b.useCallback(()=>{var j;if(!s||u)return;(j=w.current)==null||j.abort();const M=new AbortController;w.current=M;const D=x.current;d(!0),k({filter:D,limit:String(kf),before:s},M.signal).then(R=>{!R||M.signal.aborted||D!==x.current||(a(H=>{const P=new Set(H.map(q=>q.sessionId)),G=[...H,...R.sessions.filter(q=>!P.has(q.sessionId))];return E.current=Math.max(kf,G.length),G}),l(R.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)})},[s,u,k]),T=b.useMemo(()=>{const M=new Map;for(const D of Object.values(h))M.set(D.sessionId,D);for(const D of i)M.set(D.sessionId,D);return M},[i,h]),C=r.join(",");return b.useEffect(()=>{const M=r.filter(j=>!!j&&!T.has(j)&&!p.current.has(j)).slice(0,200);if(!M.length)return;for(const j of M)p.current.add(j);let D=!1;return k({ids:M.join(",")}).then(j=>{!j||D||m(R=>{const H={...R};for(const P of j.sessions)H[P.sessionId]=P;return H})}).catch(()=>{}),()=>{D=!0}},[C,T,k]),{sessions:i,cursor:s,loading:u,byId:T,loadMore:N}}const Of="0.1.138";function Foe(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 Nf="w-4 h-4 mt-0.5 shrink-0";function Hoe(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?y.jsx(aV,{className:`${Nf} text-purple-400`}):(t==null?void 0:t.type)==="mention"?y.jsx(qG,{className:`${Nf} text-blue-400`}):(t==null?void 0:t.type)==="channel"?y.jsx(eV,{className:`${Nf} text-green-400`}):e.sessionId.startsWith("slack-")?y.jsx(Vw,{className:`${Nf} text-yellow-400`}):y.jsx(Vw,{className:`${Nf} text-muted-foreground`})}function Koe(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 qoe(e,t,n){return Object.keys(e).map(r=>t.get(r)).filter(r=>!!r&&(n==="all"||r.mine!==!1))}const lI="chats-filter",cI="chats-unread-filter";function Goe({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,unreads:l={},busySessions:u=new Set,socket:d}){var F;const h=za(),[m,p]=b.useState(()=>localStorage.getItem(lI)||"mine"),[g,w]=b.useState(()=>localStorage.getItem(cI)==="true"),[x,E]=b.useState(""),_=b.useRef(null);function k(V){p(V),localStorage.setItem(lI,V)}function O(){const V=!g;w(V),localStorage.setItem(cI,String(V))}const N=b.useMemo(()=>[t,...Object.keys(l)].filter(V=>!!V),[t,l]),{sessions:T,cursor:C,loading:M,byId:D,loadMore:j}=Uoe({getToken:e,filter:m,refreshKey:i,hydrateIds:N}),R=b.useMemo(()=>qoe(l,D,m),[l,D,m]),H=R.length,P=b.useMemo(()=>g?[...R].sort((V,$)=>$.lastModified-V.lastModified):T,[g,R,T]),G=t&&!P.some(V=>V.sessionId===t)?D.get(t):void 0;b.useEffect(()=>{_.current&&_.current.scrollIntoView({block:"nearest"})},[t,P,G]);const q=b.useRef(null),X=b.useRef(j);X.current=j,b.useEffect(()=>{const V=q.current;if(!V||!C||g)return;const $=new IntersectionObserver(L=>{L.some(W=>W.isIntersecting)&&X.current()},{rootMargin:"300px"});return $.observe(V),()=>$.disconnect()},[C,M,g]),b.useEffect(()=>{e().then(V=>V?fetch("/api/version",{headers:{Authorization:`Bearer ${V}`}}):null).then(V=>V==null?void 0:V.json()).then(V=>V&&E(V.version)).catch(()=>{})},[]);const U=!!x&&x!=="unknown"&&Of!=="dev"&&x!==Of;b.useEffect(()=>{U&&console.warn(`[shraga] stale client bundle: built from v${Of}, server runs v${x} — rebuild dist/client`)},[U,x]);function K(V){const $=l[V.sessionId],L=u.has(V.sessionId)||V.runStatus==="running"||V.scheduleRunStatus==="running",W=!L&&(!!V.lastStopReason||V.scheduleRunStatus==="error"||V.scheduleRunStatus==="aborted"),z=L?"border-amber-500":W?"border-red-500":$?"border-blue-500":"",ie=!!(L||W||$);return y.jsx("button",{ref:V.sessionId===t?_:void 0,onClick:()=>n(V.sessionId,V.title),className:ze("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",ie?`rounded-r-lg border-l-[3px] ${z}`:"rounded-lg",t===V.sessionId&&"bg-accent"),children:y.jsxs("div",{className:"flex items-start gap-2",children:[Hoe(V),y.jsxs("div",{className:"min-w-0 flex-1",children:[y.jsx("span",{className:ze("block truncate text-sm leading-snug",$&&"font-semibold"),children:V.title||"New session"}),y.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[y.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:Koe(V)||V.userName}),y.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:Foe(V.lastModified)})]})]})]})},V.sessionId)}return y.jsxs("div",{className:"flex flex-col h-full bg-muted/30",children:[y.jsx("div",{className:"p-3",children:y.jsxs(we,{variant:"outline",size:"sm",className:"w-full gap-2 justify-start",onClick:r,title:"New Chat (Ctrl+N)",children:[y.jsx(ko,{className:"w-4 h-4"})," New Chat",y.jsx("span",{className:"ml-auto flex items-center gap-0.5 text-[10px] text-muted-foreground/50 font-mono",children:"⌃N"})]})}),y.jsx("div",{className:"border-b shrink-0 flex flex-col max-h-[40vh]",children:y.jsx(Bre,{getToken:e,onRefresh:s,refreshKey:a})}),y.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Chats"}),y.jsxs("div",{className:"flex gap-0.5",children:[["mine","all"].map(V=>y.jsx("button",{onClick:()=>k(V),className:ze("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",m===V?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:V},V)),y.jsxs("button",{onClick:O,className:ze("text-[10px] px-1.5 rounded-full transition-colors leading-none",g?"text-blue-600 dark:text-blue-400 font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:["unread",H>0&&y.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),y.jsx(OL,{className:"flex-1",children:y.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[P.length===0&&!G&&y.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:M?"Loading…":g?"No unread conversations":"No conversations yet"}),G&&K(G),P.map(K),!g&&C&&y.jsx("div",{ref:q,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:M?"Loading older…":"···"})]})}),y.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[y.jsx(Toe,{socket:d??null,getToken:e}),(F=h.sidebarExtras)==null?void 0:F.call(h),x&&(U?y.jsxs("button",{onClick:()=>location.reload(),title:`This page was built from v${Of}, the server runs v${x} — reload to update`,className:"text-[10px] text-amber-400 hover:text-amber-300 text-center underline decoration-dotted",children:["⚠️ stale page (v",Of," → v",x,") · reload"]}):y.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",x]}))]})]})}function ni(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:Ms(),role:"assistant",blocks:[t]}]}function uI(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:Ms(),role:"assistant",blocks:[i]}]}function W$(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(l=>l.type==="tool_use"&&l.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 Voe(e,t){const[n,r]=b.useState([]),[i,a]=b.useState(!1),[s,l]=b.useState([]),u=b.useRef(t.initialSessionId),d=b.useRef(!1),h=b.useRef(s);h.current=s;const m=b.useRef(t.getToken);m.current=t.getToken;const p=b.useRef(t.onNewSession);p.current=t.onNewSession;const g=b.useRef(t.onDirectivesChanged);g.current=t.onDirectivesChanged;const w=b.useRef(t.onParticipantsChanged);w.current=t.onParticipantsChanged;const x=b.useRef(t.onEvent);x.current=t.onEvent;const E=b.useRef(e);E.current=e;const _=b.useCallback(P=>P!=null&&P===u.current,[]),k=b.useCallback(async()=>{var G;const P=u.current;if(P)try{const X=await(await Ll(`/api/sessions/${P}/messages`,m.current)).json();r(nL(X)),a(!!X.busy),(G=w.current)==null||G.call(w,Array.isArray(X.participants)&&X.participants.length>1)}catch{}},[]);b.useEffect(()=>{if(!e)return;const P=e.on(G=>{var X,U,K,F,V,$;(X=x.current)==null||X.call(x,G);const q=G;if(q.type==="compact_marker")return _(q.sessionId)?r(L=>[...L,{id:Ms(),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(L=>ni(L,{type:"thinking",text:G.text})):void 0;case"text_delta":return _(G.sessionId)?r(L=>ni(L,{type:"text",text:G.text})):void 0;case"tool_use":return _(G.sessionId)?r(L=>ni(L,{type:"tool_use",tool:G.tool,toolUseId:G.toolUseId,input:G.input})):void 0;case"tool_use_input":return _(G.sessionId)?r(L=>W$(L,G.toolUseId,G.input)):void 0;case"tool_result":return _(G.sessionId)?r(L=>ni(L,{type:"tool_result",toolUseId:G.toolUseId,output:G.output})):void 0;case"tool_result_image":return _(G.sessionId)?r(L=>ni(L,{type:"image",src:G.dataUrl})):void 0;case"permission_request":return _(G.sessionId)?r(L=>ni(L,{type:"permission_request",id:G.id,tool:G.tool,input:G.input})):void 0;case"question_request":return _(G.sessionId)?r(L=>ni(L,{type:"question_request",id:G.id,questions:G.questions})):void 0;case"directives":return d.current?(U=g.current)==null?void 0:U.call(g,G.directives):void 0;case"session_id":return!d.current||u.current?void 0:(u.current=G.sessionId,(K=p.current)==null?void 0:K.call(p,G.sessionId));case"forked":return G.sourceSessionId!==u.current?void 0:(u.current=G.sessionId,(F=p.current)==null?void 0:F.call(p,G.sessionId));case"session_busy":G.sessionId===u.current&&a(G.busy);return;case"session_stream":return G.sessionId!==u.current?void 0:Woe(r,G.event);case"session_messages_changed":G.sessionId===u.current&&k();return;case"done":{if(G.sessionId!==u.current)return;G.stopReason==="max_turns_reached"&&r(W=>ni(W,{type:"text",text:`
|
|
1907
|
+
`)},Ere=0,ru=[];function Sre(e){var t=b.useRef([]),n=b.useRef([0,0]),r=b.useRef(),i=b.useState(Ere++)[0],a=b.useState(dz)[0],s=b.useRef(e);b.useEffect(function(){s.current=e},[e]),b.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var x=R7([e.lockRef.current],(e.shards||[]).map(BM),!0).filter(Boolean);return x.forEach(function(E){return E.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),x.forEach(function(E){return E.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var l=b.useCallback(function(x,E){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!s.current.allowPinchZoom;var _=kp(x),k=n.current,O="deltaX"in x?x.deltaX:k[0]-_[0],N="deltaY"in x?x.deltaY:k[1]-_[1],T,C=x.target,M=Math.abs(O)>Math.abs(N)?"h":"v";if("touches"in x&&M==="h"&&C.type==="range")return!1;var D=window.getSelection(),j=D&&D.anchorNode,R=j?j===C||j.contains(C):!1;if(R)return!1;var H=zM(M,C);if(!H)return!0;if(H?T=M:(T=M==="v"?"h":"v",H=zM(M,C)),!H)return!1;if(!r.current&&"changedTouches"in x&&(O||N)&&(r.current=T),!T)return!0;var P=r.current||T;return bre(P,E,x,P==="h"?O:N)},[]),u=b.useCallback(function(x){var E=x;if(!(!ru.length||ru[ru.length-1]!==a)){var _="deltaY"in E?$M(E):kp(E),k=t.current.filter(function(T){return T.name===E.type&&(T.target===E.target||E.target===T.shadowParent)&&xre(T.delta,_)})[0];if(k&&k.should){E.cancelable&&E.preventDefault();return}if(!k){var O=(s.current.shards||[]).map(BM).filter(Boolean).filter(function(T){return T.contains(E.target)}),N=O.length>0?l(E,O[0]):!s.current.noIsolation;N&&E.cancelable&&E.preventDefault()}}},[]),d=b.useCallback(function(x,E,_,k){var O={name:x,delta:E,target:_,should:k,shadowParent:_re(_)};t.current.push(O),setTimeout(function(){t.current=t.current.filter(function(N){return N!==O})},1)},[]),h=b.useCallback(function(x){n.current=kp(x),r.current=void 0},[]),m=b.useCallback(function(x){d(x.type,$M(x),x.target,l(x,e.lockRef.current))},[]),p=b.useCallback(function(x){d(x.type,kp(x),x.target,l(x,e.lockRef.current))},[]);b.useEffect(function(){return ru.push(a),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:p}),document.addEventListener("wheel",u,nu),document.addEventListener("touchmove",u,nu),document.addEventListener("touchstart",h,nu),function(){ru=ru.filter(function(x){return x!==a}),document.removeEventListener("wheel",u,nu),document.removeEventListener("touchmove",u,nu),document.removeEventListener("touchstart",h,nu)}},[]);var g=e.removeScrollBar,w=e.inert;return b.createElement(b.Fragment,null,w?b.createElement(a,{styles:wre(i)}):null,g?b.createElement(fre,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function _re(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Are=Jne(uz,Sre);var vS=b.forwardRef(function(e,t){return b.createElement(Yv,xa({},e,{ref:t,sideCar:Are}))});vS.classNames=Yv.classNames;var kre=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},iu=new WeakMap,Op=new WeakMap,Np={},zx=0,pz=function(e){return e&&(e.host||pz(e.parentNode))},Ore=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})},Nre=function(e,t,n,r){var i=Ore(t,Array.isArray(e)?e:[e]);Np[n]||(Np[n]=new WeakMap);var a=Np[n],s=[],l=new Set,u=new Set(i),d=function(m){!m||l.has(m)||(l.add(m),d(m.parentNode))};i.forEach(d);var h=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(p){if(l.has(p))h(p);else try{var g=p.getAttribute(r),w=g!==null&&g!=="false",x=(iu.get(p)||0)+1,E=(a.get(p)||0)+1;iu.set(p,x),a.set(p,E),s.push(p),x===1&&w&&Op.set(p,!0),E===1&&p.setAttribute(n,"true"),w||p.setAttribute(r,"true")}catch(_){console.error("aria-hidden: cannot operate on ",p,_)}})};return h(t),l.clear(),zx++,function(){s.forEach(function(m){var p=iu.get(m)-1,g=a.get(m)-1;iu.set(m,p),a.set(m,g),p||(Op.has(m)||m.removeAttribute(r),Op.delete(m)),g||m.removeAttribute(n)}),zx--,zx||(iu=new WeakMap,iu=new WeakMap,Op=new WeakMap,Np={})}},gz=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=kre(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),Nre(r,i,n,"aria-hidden")):function(){return null}},Xv="Dialog",[vz]=hL(Xv),[Cre,Ji]=vz(Xv),yz=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,l=b.useRef(null),u=b.useRef(null),[d,h]=_ne({prop:r,defaultProp:i??!1,onChange:a,caller:Xv});return y.jsx(Cre,{scope:t,triggerRef:l,contentRef:u,contentId:Ix(),titleId:Ix(),descriptionId:Ix(),open:d,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(m=>!m),[h]),modal:s,children:n})};yz.displayName=Xv;var bz="DialogTrigger",xz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(bz,n),a=ui(t,i.triggerRef);return y.jsx(Fr.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":ES(i.open),...r,ref:a,onClick:Sr(e.onClick,i.onOpenToggle)})});xz.displayName=bz;var yS="DialogPortal",[Tre,wz]=vz(yS,{forceMount:void 0}),Ez=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Ji(yS,t);return y.jsx(Tre,{scope:t,forceMount:n,children:b.Children.map(r,s=>y.jsx(Zs,{present:n||a.open,children:y.jsx(lz,{asChild:!0,container:i,children:s})}))})};Ez.displayName=yS;var Pg="DialogOverlay",bS=b.forwardRef((e,t)=>{const n=wz(Pg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Ji(Pg,e.__scopeDialog);return a.modal?y.jsx(Zs,{present:r||a.open,children:y.jsx(Ire,{...i,ref:t})}):null});bS.displayName=Pg;var Mre=GE("DialogOverlay.RemoveScroll"),Ire=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(Pg,n),a=Ine(),s=ui(t,a);return y.jsx(vS,{as:Mre,allowPinchZoom:!0,shards:[i.contentRef],children:y.jsx(Fr.div,{"data-state":ES(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),Uu="DialogContent",xS=b.forwardRef((e,t)=>{const n=wz(Uu,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Ji(Uu,e.__scopeDialog);return y.jsx(Zs,{present:r||a.open,children:a.modal?y.jsx(Rre,{...i,ref:t}):y.jsx(Pre,{...i,ref:t})})});xS.displayName=Uu;var Rre=b.forwardRef((e,t)=>{const n=Ji(Uu,e.__scopeDialog),r=b.useRef(null),i=ui(t,n.contentRef,r);return b.useEffect(()=>{const a=r.current;if(a)return gz(a)},[]),y.jsx(Sz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:Sr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:Sr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,l=s.button===0&&s.ctrlKey===!0;(s.button===2||l)&&a.preventDefault()}),onFocusOutside:Sr(e.onFocusOutside,a=>a.preventDefault())})}),Pre=b.forwardRef((e,t)=>{const n=Ji(Uu,e.__scopeDialog),r=b.useRef(!1),i=b.useRef(!1);return y.jsx(Sz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,l;(s=e.onCloseAutoFocus)==null||s.call(e,a),a.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var u,d;(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;((d=n.triggerRef.current)==null?void 0:d.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),Sz=b.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,l=Ji(Uu,n);return Kne(),y.jsx(y.Fragment,{children:y.jsx(oz,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:y.jsx(iz,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ES(l.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),_z="DialogTitle",wS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(_z,n);return y.jsx(Fr.h2,{id:i.titleId,...r,ref:t})});wS.displayName=_z;var Az="DialogDescription",Dre=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(Az,n);return y.jsx(Fr.p,{id:i.descriptionId,...r,ref:t})});Dre.displayName=Az;var kz="DialogClose",Oz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(kz,n);return y.jsx(Fr.button,{type:"button",...r,ref:t,onClick:Sr(e.onClick,()=>i.onOpenChange(!1))})});Oz.displayName=kz;function ES(e){return e?"open":"closed"}const Oo=yz,rd=xz,jre=Ez,Nz=b.forwardRef(({className:e,...t},n)=>y.jsx(bS,{ref:n,className:ze("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}));Nz.displayName=bS.displayName;const Na=b.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(jre,{children:[y.jsx(Nz,{}),y.jsxs(xS,{ref:r,className:ze("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,y.jsxs(Oz,{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:[y.jsx(Bs,{className:"h-4 w-4"}),y.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Na.displayName=xS.displayName;function Us({className:e,...t}){return y.jsx("div",{className:ze("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function Cz({className:e,...t}){return y.jsx("div",{"data-dialog-body":!0,className:ze("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Tz({className:e,...t}){return y.jsx("div",{className:ze("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 No=b.forwardRef(({className:e,...t},n)=>y.jsx(wS,{ref:n,className:ze("text-lg font-semibold leading-none tracking-tight",e),...t}));No.displayName=wS.displayName;const Lre=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),zre=new Set(["pdf","mp4","webm","mp3","ogg","wav"]);async function $re(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 Bre({getToken:e,onRefresh:t,refreshKey:n}){const[r,i]=b.useState(new Map),[a,s]=b.useState(()=>new Set),[l,u]=b.useState(null),[d,h]=b.useState(!1),[m,p]=b.useState("fit"),[g,w]=b.useState(null),[x,E]=b.useState(null),_=b.useRef(null),[k,O]=b.useState(null),[N,T]=b.useState(!1),[C,M]=b.useState([]),D=b.useCallback(async U=>{const K=await $re(U,e);i(F=>new Map(F).set(U,K))},[e]);b.useEffect(()=>{D(""),a.forEach(U=>D(U))},[D,n]);const j=r.get("")??[],R=b.useCallback(U=>{try{const K=U.contentDocument;if(!(K!=null&&K.body))return;const F=Math.max(K.body.offsetWidth,K.body.scrollWidth),V=Math.max(K.body.offsetHeight,K.body.scrollHeight);F&&V&&E({w:F,h:V})}catch{}},[]),H=b.useCallback(()=>{const U=_.current,K=x;if(!U||!K)return;const F=16,V=U.clientWidth-F,$=U.clientHeight-F,L=Math.min(V/K.w,$/K.h,1);w({scale:L,w:K.w,h:K.h})},[x]);b.useEffect(()=>{if(!(l!=null&&l.html)||m!=="fit"){w(null);return}const U=_.current;if(!U)return;const K=new ResizeObserver(()=>requestAnimationFrame(H));return K.observe(U),()=>K.disconnect()},[l==null?void 0:l.html,d,m,H]),b.useEffect(()=>{N&&e().then(U=>{U&&fetch("/api/data-sync/log",{headers:{Authorization:`Bearer ${U}`}}).then(K=>K.json()).then(M).catch(()=>{})})},[N]);const P=U=>{s(K=>{const F=new Set(K);return F.has(U)?F.delete(U):(F.add(U),r.has(U)||D(U)),F})},G=(U,K)=>{const F=new URLSearchParams({path:U});return k&&F.set("token",k),K&&F.set("dl","1"),`/api/workspace/raw?${F}`},q=async U=>{var V;const K=await e();if(!K)return;O(K);const F=((V=U.split(".").pop())==null?void 0:V.toLowerCase())??"";if(F==="html"||F==="htm"){u({path:U,content:"",binary:!1,html:!0});return}if(Lre.has(F)){u({path:U,content:"",binary:!1,image:!0});return}if(zre.has(F)){u({path:U,content:"",binary:!1,html:!0});return}try{const $=await fetch(`/api/workspace/file?path=${encodeURIComponent(U)}`,{headers:{Authorization:`Bearer ${K}`}});if(!$.ok)return;const L=await $.json();u({path:U,content:L.content,binary:!!L.binary})}catch{}},X=(U,K)=>y.jsx(y.Fragment,{children:U.map(F=>{const V=F.path.split("/").pop();return y.jsxs("div",{children:[F.type==="dir"?y.jsxs("button",{onClick:()=>P(F.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+K*12},children:[y.jsx(Xs,{className:ze("w-3 h-3 shrink-0 transition-transform",a.has(F.path)&&"rotate-90")}),y.jsx(JG,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),y.jsx("span",{className:"truncate",children:V})]}):y.jsxs("button",{onClick:()=>q(F.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+K*12+12},title:F.oneLiner||F.path,children:[y.jsx(UE,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),y.jsx("span",{className:"truncate",children:V})]}),F.type==="dir"&&a.has(F.path)&&X(r.get(F.path)??[],K+1)]},F.path)})});return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1 shrink-0",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Workspace"}),y.jsxs("div",{className:"flex items-center gap-0.5",children:[y.jsx("button",{onClick:()=>T(!0),className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Activity log",children:y.jsx(tV,{className:"w-3 h-3"})}),y.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:y.jsx(ed,{className:"w-3 h-3"})})]})]}),y.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:j.length===0?y.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."}):X(j,0)}),y.jsx(Oo,{open:!!l,onOpenChange:U=>{U||(u(null),h(!1),p("fit"),E(null))},children:y.jsxs(Na,{className:ze(l!=null&&l.html?ze("!flex !flex-col !p-0 !gap-0 overflow-hidden",d?"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:[y.jsxs("div",{className:"absolute right-12 top-4 flex items-center gap-1.5 z-10",children:[(l==null?void 0:l.html)&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:()=>p(U=>U==="fit"?"scroll":"fit"),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:m==="fit"?"Switch to scrollable (1:1)":"Switch to scale-to-fit",children:m==="fit"?y.jsx(oV,{className:"w-4 h-4"}):y.jsx(fV,{className:"w-4 h-4"})}),y.jsx("button",{onClick:()=>h(U=>!U),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:d?"Restore":"Maximize",children:d?y.jsx(HE,{className:"w-4 h-4"}):y.jsx(FE,{className:"w-4 h-4"})})]}),l&&y.jsx("a",{href:G(l.path,!0),download:!0,className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:"Download",children:y.jsx(lL,{className:"w-4 h-4"})})]}),y.jsx(Us,{className:ze((l==null?void 0:l.html)&&"px-4 py-3 shrink-0 border-b"),children:y.jsx(No,{className:"font-mono text-sm truncate pr-16",children:l==null?void 0:l.path})}),y.jsx("div",{ref:l!=null&&l.html?_:void 0,className:ze(l!=null&&l.html?ze("flex-1 min-h-0 bg-muted/10",m==="fit"?"overflow-hidden flex items-center justify-center":"overflow-auto"):"flex-1 min-h-0 overflow-y-auto"),children:l!=null&&l.html?m==="fit"?y.jsx("div",{style:g?{width:g.w*g.scale,height:g.h*g.scale}:{width:"100%",height:"100%"},children:y.jsx("iframe",{src:G(l.path),className:"border-0 bg-white origin-top-left",title:l.path,onLoad:U=>{R(U.currentTarget),H()},style:g?{width:g.w,height:g.h,transform:`scale(${g.scale})`}:{width:"100%",height:"100%"}})}):y.jsx("iframe",{src:G(l.path),className:"border-0 bg-white mx-auto block",title:l.path,onLoad:U=>R(U.currentTarget),style:{width:(x==null?void 0:x.w)||"100%",height:(x==null?void 0:x.h)||"100%"}}):l!=null&&l.image?y.jsx("div",{className:"flex items-center justify-center p-4",children:y.jsx("img",{src:G(l.path),alt:l.path,className:"max-w-full max-h-[70vh] object-contain"})}):l!=null&&l.binary?y.jsx("p",{className:"text-sm text-muted-foreground",children:"(binary file — preview unavailable)"}):l!=null&&l.path.toLowerCase().endsWith(".md")||l!=null&&l.path.toLowerCase().endsWith(".markdown")?y.jsx("div",{className:"text-sm",children:y.jsx(d3,{remarkPlugins:[D3],rehypePlugins:[rz],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:l.content})}):y.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:l==null?void 0:l.content})})]})}),y.jsx(Oo,{open:N,onOpenChange:T,children:y.jsxs(Na,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[y.jsx(Us,{children:y.jsx(No,{className:"text-sm",children:"Activity Log"})}),y.jsxs("div",{className:"overflow-y-auto flex-1 space-y-2",children:[C.map(U=>y.jsxs("div",{className:"border-b border-border/50 pb-2 last:border-0",children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[y.jsx("span",{className:"text-sm text-foreground",children:U.message}),y.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:Ure(U.date)})]}),U.files.length>0&&y.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:U.files.map(K=>y.jsx("span",{className:"inline-block mr-2 font-mono",children:K},K))})]},U.hash)),C.length===0&&y.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No activity yet"})]})]})})]})}function Ure(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 ag(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),l=i%24;return l?`${s}d ${l}h`:`${s}d`}const Fre=/resets\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\s*\(UTC\)/i;function Hre(e,t=Date.now(),n=Date.now()){var m;const r=e.match(Fre);if(!r)return e;let i=Number(r[1]);const a=r[2]?Number(r[2]):0,s=(m=r[3])==null?void 0:m.toLowerCase();if(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0),i>23||a>59)return e;const l=new Date(t),u=new Date(Date.UTC(l.getUTCFullYear(),l.getUTCMonth(),l.getUTCDate(),i,a));u.getTime()<=t&&u.setUTCDate(u.getUTCDate()+1);const d=u.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),h=ag(u.toISOString(),n);return e.replace(r[0],`resets ${d}${h?` (in ${h})`:""}`)}var Kre=Object.defineProperty,id=(e,t)=>Kre(e,"name",{value:t,configurable:!0}),Mz=!!(typeof window<"u"&&window.document&&window.document.createElement);function Ds(e,t,{checkForDefaultPrevented:n=!0}={}){return id(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}id(Ds,"composeEventHandlers");function qre(e){var t;if(!Mz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}id(qre,"getOwnerWindow");function l1(e){if(!Mz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}id(l1,"getOwnerDocument");function Iz(e,t=!1){const{activeElement:n}=l1(e);if(!(n!=null&&n.nodeName))return null;if(Rz(n)&&n.contentDocument)return Iz(n.contentDocument.body,t);if(t){const r=n.getAttribute("aria-activedescendant");if(r){const i=l1(n).getElementById(r);if(i)return i}}return n}id(Iz,"getActiveElement");function Rz(e){return e.tagName==="IFRAME"}id(Rz,"isFrame");var Gre=Object.defineProperty,SS=(e,t)=>Gre(e,"name",{value:t,configurable:!0});function c1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}SS(c1,"setRef");function Pz(...e){return t=>{let n=!1;const r=e.map(i=>{const a=c1(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():c1(e[i],null)}}}}SS(Pz,"composeRefs");function ad(...e){return b.useCallback(Pz(...e),e)}SS(ad,"useComposedRefs");var Vre=Object.defineProperty,Ni=(e,t)=>Vre(e,"name",{value:t,configurable:!0});function Wre(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Ni(a=>{const{children:s,...l}=a,u=b.useMemo(()=>l,Object.values(l));return y.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:l=!1}=s,u=b.useContext(n);if(u)return u;if(t!==void 0)return t;if(!l)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ni(i,"useContext"),[r,i]}Ni(Wre,"createContext");function Dz(e,t=[]){let n=[];function r(a,s){const l=b.createContext(s);l.displayName=a+"Context";const u=n.length;n=[...n,s];const d=Ni(m=>{var _;const{scope:p,children:g,...w}=m,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useMemo(()=>w,Object.values(w));return y.jsx(x.Provider,{value:E,children:g})},"Provider");d.displayName=a+"Provider";function h(m,p,g={}){var _;const{optional:w=!1}=g,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useContext(x);if(E)return E;if(s!==void 0)return s;if(!w)throw new Error(`\`${m}\` must be used within \`${a}\``)}return Ni(h,"useContext"),[d,h]}Ni(r,"createContext");const i=Ni(()=>{const a=n.map(s=>b.createContext(s));return Ni(function(l){const u=(l==null?void 0:l[e])||a;return b.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])},"useScope")},"createScope");return i.scopeName=e,[r,jz(i,...t)]}Ni(Dz,"createContextScope");function jz(...e){const t=e[0];if(e.length===1)return t;const n=Ni(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ni(function(a){const s=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(a)[`__scope${d}`];return{...l,...m}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ni(jz,"composeContextScopes");var Yre=Object.defineProperty,ea=(e,t)=>Yre(e,"name",{value:t,configurable:!0});function _S(e){const t=b.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,l=!1;const u=[];u1(i)&&typeof Cp=="function"&&(i=Cp(i._payload)),b.Children.forEach(i,p=>{var g;if(Bz(p)){l=!0;const w=p;let x="child"in w.props?w.props.child:w.props.children;u1(x)&&typeof Cp=="function"&&(x=Cp(x._payload)),s=Zre(w,x),u.push((g=s==null?void 0:s.props)==null?void 0:g.children)}else u.push(p)}),s?s=b.cloneElement(s,void 0,u):!l&&b.Children.count(i)===1&&b.isValidElement(i)&&(s=i);const d=s?$z(s):void 0,h=ad(r,d);if(!s){if(i||i===0)throw new Error(l?eie(e):Jre(e));return i}const m=zz(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}ea(_S,"createSlot");var Lz=Symbol.for("radix.slottable");function Xre(e){const t=ea(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=Lz,t}ea(Xre,"createSlottable");var Zre=ea((e,t)=>{if("child"in e.props){const n=e.props.child;return b.isValidElement(n)?b.cloneElement(n,void 0,e.props.children(n.props.children)):null}return b.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function zz(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]=(...l)=>{const u=a(...l);return i(...l),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}ea(zz,"mergeProps");function $z(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)}ea($z,"getElementRef");function Bz(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Lz}ea(Bz,"isSlottable");var Qre=Symbol.for("react.lazy");function u1(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Qre&&"_payload"in e&&Uz(e._payload)}ea(u1,"isLazyComponent");function Uz(e){return typeof e=="object"&&e!==null&&"then"in e}ea(Uz,"isPromiseLike");var Jre=ea(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),eie=ea(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Cp=ja[" use ".trim().toString()],tie=Object.defineProperty,nie=(e,t)=>tie(e,"name",{value:t,configurable:!0}),rie=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Zv=rie.reduce((e,t)=>{const n=_S(`Primitive.${t}`),r=b.forwardRef((i,a)=>{const{asChild:s,...l}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),y.jsx(u,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Fz(e,t){e&&La.flushSync(()=>e.dispatchEvent(t))}nie(Fz,"dispatchDiscreteCustomEvent");var iie=Object.defineProperty,aie=(e,t)=>iie(e,"name",{value:t,configurable:!0});function Qv(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}aie(Qv,"useCallbackRef");var oie=Object.defineProperty,qn=(e,t)=>oie(e,"name",{value:t,configurable:!0}),d1="dismissableLayer.update",sie="dismissableLayer.pointerDownOutside",lie="dismissableLayer.focusOutside",UM,Hz=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),cie=b.forwardRef(qn(function(t,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:s,onFocusOutside:l,onInteractOutside:u,onDismiss:d,...h}=t,m=b.useContext(Hz),[p,g]=b.useState(null),w=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,x]=b.useState({}),E=ad(n,g),_=Array.from(m.layers),[k]=[...m.layersWithOutsidePointerEventsDisabled].slice(-1),O=k?_.indexOf(k):-1,N=p?_.indexOf(p):-1,T=m.layersWithOutsidePointerEventsDisabled.size>0,C=N>=O,M=b.useRef(!1),D=Kz(P=>{s==null||s(P),u==null||u(P),P.defaultPrevented||d==null||d()},{ownerDocument:w,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:M,dismissableSurfaces:m.dismissableSurfaces,shouldHandlePointerDownOutside:b.useCallback(P=>{if(!(P instanceof Node))return!1;const G=[...m.branches].some(q=>q.contains(P));return C&&!G},[m.branches,C])}),j=qz(P=>{if(i&&M.current)return;const G=P.target;[...m.branches].some(X=>X.contains(G))||(l==null||l(P),u==null||u(P),P.defaultPrevented||d==null||d())},w),R=p?N===_.length-1:!1,H=Qv(P=>{P.key==="Escape"&&(a==null||a(P),!P.defaultPrevented&&d&&(P.preventDefault(),d()))});return b.useEffect(()=>{if(R)return w.addEventListener("keydown",H,{capture:!0}),()=>w.removeEventListener("keydown",H,{capture:!0})},[w,R,H]),b.useEffect(()=>{if(p)return r&&(m.layersWithOutsidePointerEventsDisabled.size===0&&(UM=w.body.style.pointerEvents,w.body.style.pointerEvents="none"),m.layersWithOutsidePointerEventsDisabled.add(p)),m.layers.add(p),f1(),()=>{r&&(m.layersWithOutsidePointerEventsDisabled.delete(p),m.layersWithOutsidePointerEventsDisabled.size===0&&(w.body.style.pointerEvents=UM))}},[p,w,r,m]),b.useEffect(()=>()=>{p&&(m.layers.delete(p),m.layersWithOutsidePointerEventsDisabled.delete(p),f1())},[p,m]),b.useEffect(()=>{const P=qn(()=>x({}),"handleUpdate");return document.addEventListener(d1,P),()=>document.removeEventListener(d1,P)},[]),y.jsx(Zv.div,{...h,ref:E,style:{pointerEvents:T?C?"auto":"none":void 0,...t.style},onFocusCapture:Ds(t.onFocusCapture,j.onFocusCapture),onBlurCapture:Ds(t.onBlurCapture,j.onBlurCapture),onPointerDownCapture:Ds(t.onPointerDownCapture,D.onPointerDownCapture)})},"DismissableLayer"));function uie(){const e=b.useContext(Hz),[t,n]=b.useState(null);return b.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}qn(uie,"useDismissableLayerSurface");var die=qn(()=>!0,"IS_TRUE");function Kz(e,t){const{ownerDocument:n=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:s=die}=t,l=Qv(e),u=b.useRef(!1),d=b.useRef(!1),h=b.useRef(new Map),m=b.useRef(()=>{});return b.useEffect(()=>{function p(){d.current=!1,i.current=!1,h.current.clear()}qn(p,"resetOutsideInteraction");function g(){return Array.from(h.current.values()).some(Boolean)}qn(g,"isOutsideInteractionIntercepted");function w(O){if(!d.current)return;const N=O.target;N instanceof Node&&[...a].some(C=>C.contains(N))||h.current.set(O.type,!0),O.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}qn(w,"handleInteractionCapture");function x(O){d.current&&h.current.set(O.type,!1)}qn(x,"handleInteractionBubble");const E=qn(O=>{if(O.target&&!u.current){let N=function(){n.removeEventListener("click",m.current);const C=g();p(),C||AS(sie,l,T,{discrete:!0})};if(qn(N,"handleAndDispatchPointerDownOutsideEvent"),!s(O.target)){n.removeEventListener("click",m.current),p(),u.current=!1;return}const T={originalEvent:O};d.current=!0,i.current=r&&O.button===0,h.current.clear(),!r||O.button!==0?N():(n.removeEventListener("click",m.current),m.current=N,n.addEventListener("click",m.current,{once:!0}))}else n.removeEventListener("click",m.current),p();u.current=!1},"handlePointerDown"),_=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const O of _)n.addEventListener(O,w,!0),n.addEventListener(O,x);const k=window.setTimeout(()=>{n.addEventListener("pointerdown",E)},0);return()=>{window.clearTimeout(k),n.removeEventListener("pointerdown",E),n.removeEventListener("click",m.current);for(const O of _)n.removeEventListener(O,w,!0),n.removeEventListener(O,x)}},[n,l,r,i,a,s]),{onPointerDownCapture:qn(()=>u.current=!0,"onPointerDownCapture")}}qn(Kz,"usePointerDownOutside");function qz(e,t=globalThis==null?void 0:globalThis.document){const n=Qv(e),r=b.useRef(!1);return b.useEffect(()=>{const i=qn(a=>{a.target&&!r.current&&AS(lie,n,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,n]),{onFocusCapture:qn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:qn(()=>r.current=!1,"onBlurCapture")}}qn(qz,"useFocusOutside");function f1(){const e=new CustomEvent(d1);document.dispatchEvent(e)}qn(f1,"dispatchUpdate");function AS(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?Fz(i,a):i.dispatchEvent(a)}qn(AS,"handleAndDispatchCustomEvent");var fie=Object.defineProperty,kS=(e,t)=>fie(e,"name",{value:t,configurable:!0}),Tp=0,da=null;function hie(e){return OS(),e.children}kS(hie,"FocusGuards");function OS(){b.useEffect(()=>{da||(da={start:h1(),end:h1()});const{start:e,end:t}=da;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Tp++,()=>{Tp===1&&(da==null||da.start.remove(),da==null||da.end.remove(),da=null),Tp=Math.max(0,Tp-1)}},[])}kS(OS,"useFocusGuards");function h1(){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}kS(h1,"createFocusGuard");var mie=Object.defineProperty,pie=(e,t)=>mie(e,"name",{value:t,configurable:!0});function m1(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}pie(m1,"useCallbackRef");var gie=Object.defineProperty,xr=(e,t)=>gie(e,"name",{value:t,configurable:!0}),$x="focusScope.autoFocusOnMount",Bx="focusScope.autoFocusOnUnmount",FM={bubbles:!1,cancelable:!0},vie=b.forwardRef(xr(function(t,n){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:s,...l}=t,[u,d]=b.useState(null),h=m1(a),m=m1(s),p=b.useRef(null),g=ad(n,d),w=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(i){let E=function(N){if(w.paused||!u)return;const T=N.target;u.contains(T)?p.current=T:uo(p.current,{select:!0})},_=function(N){if(w.paused||!u)return;const T=N.relatedTarget;T!==null&&(u.contains(T)||uo(p.current,{select:!0}))},k=function(N){if(document.activeElement===document.body)for(const C of N)C.removedNodes.length>0&&uo(u)};xr(E,"handleFocusIn"),xr(_,"handleFocusOut"),xr(k,"handleMutations"),document.addEventListener("focusin",E),document.addEventListener("focusout",_);const O=new MutationObserver(k);return u&&O.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",E),document.removeEventListener("focusout",_),O.disconnect()}}},[i,u,w.paused]),b.useEffect(()=>{if(u){HM.add(w);const E=document.activeElement;if(!u.contains(E)){const k=new CustomEvent($x,FM);u.addEventListener($x,h),u.dispatchEvent(k),k.defaultPrevented||(Gz(Zz(NS(u)),{select:!0}),document.activeElement===E&&uo(u))}return()=>{u.removeEventListener($x,h),setTimeout(()=>{const k=new CustomEvent(Bx,FM);u.addEventListener(Bx,m),u.dispatchEvent(k),k.defaultPrevented||uo(E??document.body,{select:!0}),u.removeEventListener(Bx,m),HM.remove(w)},0)}}},[u,h,m,w]);const x=b.useCallback(E=>{if(!r&&!i||w.paused)return;const _=E.key==="Tab"&&!E.altKey&&!E.ctrlKey&&!E.metaKey,k=document.activeElement;if(_&&k){const O=E.currentTarget,[N,T]=Vz(O);N&&T?!E.shiftKey&&k===T?(E.preventDefault(),r&&uo(N,{select:!0})):E.shiftKey&&k===N&&(E.preventDefault(),r&&uo(T,{select:!0})):k===O&&E.preventDefault()}},[r,i,w.paused]);return y.jsx(Zv.div,{tabIndex:-1,...l,ref:g,onKeyDown:x})},"FocusScope"));function Gz(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(uo(r,{select:t}),document.activeElement!==n)return}xr(Gz,"focusFirst");function Vz(e){const t=NS(e),n=p1(t,e),r=p1(t.reverse(),e);return[n,r]}xr(Vz,"getTabbableEdges");function NS(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:xr(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}xr(NS,"getTabbableCandidates");function p1(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):Wz(r,{upTo:t})))return r}xr(p1,"findVisible");function Wz(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}xr(Wz,"isHidden");function Yz(e){return e instanceof HTMLInputElement&&"select"in e}xr(Yz,"isSelectableInput");function uo(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Yz(e)&&t&&e.select()}}xr(uo,"focus");var HM=Xz();function Xz(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=g1(e,t),e.unshift(t)},remove(t){var n;e=g1(e,t),(n=e[0])==null||n.resume()}}}xr(Xz,"createFocusScopesStack");function g1(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}xr(g1,"arrayRemove");function Zz(e){return e.filter(t=>t.tagName!=="A")}xr(Zz,"removeLinks");var yie=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},bie=Object.defineProperty,xie=(e,t)=>bie(e,"name",{value:t,configurable:!0}),wie=ja[" useId ".trim().toString()]||(()=>{}),Eie=0;function Qz(e){const[t,n]=b.useState(wie());return yie(()=>{e||n(r=>r??String(Eie++))},[e]),e||(t?`radix-${t}`:"")}xie(Qz,"useId");const Sie=["top","right","bottom","left"],Fs=Math.min,xo=Math.max,Dg=Math.round,Mp=Math.floor,wo=e=>({x:e,y:e}),_ie={left:"right",right:"left",bottom:"top",top:"bottom"};function Jz(e,t,n){return xo(e,Fs(t,n))}function Co(e,t){return typeof e=="function"?e(t):e}function Hs(e){return e.split("-")[0]}function od(e){return e.split("-")[1]}function CS(e){return e==="x"?"y":"x"}function TS(e){return e==="y"?"height":"width"}function wa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function MS(e){return CS(wa(e))}function Aie(e,t,n){n===void 0&&(n=!1);const r=od(e),i=MS(e),a=TS(i);let s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=jg(s)),[s,jg(s)]}function kie(e){const t=jg(e);return[v1(e),t,v1(t)]}function v1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const KM=["left","right"],qM=["right","left"],Oie=["top","bottom"],Nie=["bottom","top"];function Cie(e,t,n){switch(e){case"top":case"bottom":return n?t?qM:KM:t?KM:qM;case"left":case"right":return t?Oie:Nie;default:return[]}}function Tie(e,t,n,r){const i=od(e);let a=Cie(Hs(e),n==="start",r);return i&&(a=a.map(s=>s+"-"+i),t&&(a=a.concat(a.map(v1)))),a}function jg(e){const t=Hs(e);return _ie[t]+e.slice(t.length)}function Mie(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 e$(e){return typeof e!="number"?Mie(e):{top:e,right:e,bottom:e,left:e}}function Lg(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 GM(e,t,n){let{reference:r,floating:i}=e;const a=wa(t),s=MS(t),l=TS(s),u=Hs(t),d=a==="y",h=r.x+r.width/2-i.width/2,m=r.y+r.height/2-i.height/2,p=r[l]/2-i[l]/2;let g;switch(u){case"top":g={x:h,y:r.y-i.height};break;case"bottom":g={x:h,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:m};break;case"left":g={x:r.x-i.width,y:m};break;default:g={x:r.x,y:r.y}}const w=od(t);return w&&(g[s]+=p*(w==="end"?1:-1)*(n&&d?-1:1)),g}async function Iie(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:s,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:m="floating",altBoundary:p=!1,padding:g=0}=Co(t,e),w=e$(g),E=l[p?m==="floating"?"reference":"floating":m],_=Lg(await a.getClippingRect({element:(n=await(a.isElement==null?void 0:a.isElement(E)))==null||n?E:E.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=m==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,O=await(a.getOffsetParent==null?void 0:a.getOffsetParent(l.floating)),N=await(a.isElement==null?void 0:a.isElement(O))&&await(a.getScale==null?void 0:a.getScale(O))||{x:1,y:1},T=Lg(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:O,strategy:u}):k);return{top:(_.top-T.top+w.top)/N.y,bottom:(T.bottom-_.bottom+w.bottom)/N.y,left:(_.left-T.left+w.left)/N.x,right:(T.right-_.right+w.right)/N.x}}const Rie=50,Pie=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:s}=n,l=s.detectOverflow?s:{...s,detectOverflow:Iie},u=await(s.isRTL==null?void 0:s.isRTL(t));let d=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:m}=GM(d,r,u),p=r,g=0;const w={};for(let x=0;x<a.length;x++){const E=a[x];if(!E)continue;const{name:_,fn:k}=E,{x:O,y:N,data:T,reset:C}=await k({x:h,y:m,initialPlacement:r,placement:p,strategy:i,middlewareData:w,rects:d,platform:l,elements:{reference:e,floating:t}});h=O??h,m=N??m,w[_]={...w[_],...T},C&&g<Rie&&(g++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(d=C.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:i}):C.rects),{x:h,y:m}=GM(d,p,u)),x=-1)}return{x:h,y:m,placement:p,strategy:i,middlewareData:w}},Die=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:a,platform:s,elements:l,middlewareData:u}=t,{element:d,padding:h=0}=Co(e,t)||{};if(d==null)return{};const m=e$(h),p={x:n,y:r},g=MS(i),w=TS(g),x=await s.getDimensions(d),E=g==="y",_=E?"top":"left",k=E?"bottom":"right",O=E?"clientHeight":"clientWidth",N=a.reference[w]+a.reference[g]-p[g]-a.floating[w],T=p[g]-a.reference[g],C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(d));let M=C?C[O]:0;(!M||!await(s.isElement==null?void 0:s.isElement(C)))&&(M=l.floating[O]||a.floating[w]);const D=N/2-T/2,j=M/2-x[w]/2-1,R=Fs(m[_],j),H=Fs(m[k],j),P=M-x[w]-H,G=M/2-x[w]/2+D,q=Jz(R,G,P),X=!u.arrow&&od(i)!=null&&G!==q&&a.reference[w]/2-(G<R?R:H)-x[w]/2<0,U=X?G<R?G-R:G-P:0;return{[g]:p[g]+U,data:{[g]:q,centerOffset:G-q-U,...X&&{alignmentOffset:U}},reset:X}}}),jie=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:l,platform:u,elements:d}=t,{mainAxis:h=!0,crossAxis:m=!0,fallbackPlacements:p,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:x=!0,...E}=Co(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=Hs(i),k=wa(l),O=Hs(l)===l,N=await(u.isRTL==null?void 0:u.isRTL(d.floating)),T=p||(O||!x?[jg(l)]:kie(l)),C=w!=="none";!p&&C&&T.push(...Tie(l,x,w,N));const M=[l,...T],D=await u.detectOverflow(t,E),j=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&j.push(D[_]),m){const q=Aie(i,s,N);j.push(D[q[0]],D[q[1]])}if(R=[...R,{placement:i,overflows:j}],!j.every(q=>q<=0)){var H,P;const q=(((H=a.flip)==null?void 0:H.index)||0)+1,X=M[q];if(X&&(!(m==="alignment"?k!==wa(X):!1)||R.every(F=>wa(F.placement)===k?F.overflows[0]>0:!0)))return{data:{index:q,overflows:R},reset:{placement:X}};let U=(P=R.filter(K=>K.overflows[0]<=0).sort((K,F)=>K.overflows[1]-F.overflows[1])[0])==null?void 0:P.placement;if(!U)switch(g){case"bestFit":{var G;const K=(G=R.filter(F=>{if(C){const V=wa(F.placement);return V===k||V==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(V=>V>0).reduce((V,$)=>V+$,0)]).sort((F,V)=>F[1]-V[1])[0])==null?void 0:G[0];K&&(U=K);break}case"initialPlacement":U=l;break}if(i!==U)return{reset:{placement:U}}}return{}}}};function VM(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function WM(e){return Sie.some(t=>e[t]>=0)}const Lie=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...a}=Co(e,t);switch(i){case"referenceHidden":{const s=await r.detectOverflow(t,{...a,elementContext:"reference"}),l=VM(s,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:WM(l)}}}case"escaped":{const s=await r.detectOverflow(t,{...a,altBoundary:!0}),l=VM(s,n.floating);return{data:{escapedOffsets:l,escaped:WM(l)}}}default:return{}}}}},t$=new Set(["left","top"]);async function zie(e,t){const{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=Hs(n),l=od(n),u=wa(n)==="y",d=t$.has(s)?-1:1,h=a&&u?-1:1,m=Co(t,e);let{mainAxis:p,crossAxis:g,alignmentAxis:w}=typeof m=="number"?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:m.mainAxis||0,crossAxis:m.crossAxis||0,alignmentAxis:m.alignmentAxis};return l&&typeof w=="number"&&(g=l==="end"?w*-1:w),u?{x:g*h,y:p*d}:{x:p*d,y:g*h}}const $ie=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:l}=t,u=await zie(t,e);return s===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:a+u.y,data:{...u,placement:s}}}}},Bie=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:l=!1,limiter:u={fn:k=>{let{x:O,y:N}=k;return{x:O,y:N}}},...d}=Co(e,t),h={x:n,y:r},m=await a.detectOverflow(t,d),p=wa(i),g=CS(p);let w=h[g],x=h[p];const E=(k,O)=>Jz(O+m[k==="y"?"top":"left"],O,O-m[k==="y"?"bottom":"right"]);s&&(w=E(g,w)),l&&(x=E(p,x));const _=u.fn({...t,[g]:w,[p]:x});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[g]:s,[p]:l}}}}}},Uie=function(e){return e===void 0&&(e={}),{options:e,fn(t){var n,r;const{x:i,y:a,placement:s,rects:l,middlewareData:u}=t,{offset:d=0,mainAxis:h=!0,crossAxis:m=!0}=Co(e,t),p={x:i,y:a},g=wa(s),w=CS(g);let x=p[w],E=p[g];const _=Co(d,t),k=typeof _=="number"?{mainAxis:_,crossAxis:0}:{mainAxis:(n=_.mainAxis)!=null?n:0,crossAxis:(r=_.crossAxis)!=null?r:0};if(h){const T=w==="y"?"height":"width",C=l.reference[w]-l.floating[T]+k.mainAxis,M=l.reference[w]+l.reference[T]-k.mainAxis;x<C?x=C:x>M&&(x=M)}if(m){var O,N;const T=w==="y"?"width":"height",C=t$.has(Hs(s)),M=l.reference[g]-l.floating[T]+(C&&((O=u.offset)==null?void 0:O[g])||0)+(C?0:k.crossAxis),D=l.reference[g]+l.reference[T]+(C?0:((N=u.offset)==null?void 0:N[g])||0)-(C?k.crossAxis:0);E<M?E=M:E>D&&(E=D)}return{[w]:x,[g]:E}}}},Fie=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=()=>{},...l}=Co(e,t),u=await i.detectOverflow(t,l),d=Hs(n),h=od(n),m=wa(n)==="y",{width:p,height:g}=r.floating;let w,x;d==="top"||d==="bottom"?(w=d,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=d,w=h==="end"?"top":"bottom");const E=g-u.top-u.bottom,_=p-u.left-u.right,k=Fs(g-u[w],E),O=Fs(p-u[x],_),N=t.middlewareData.shift,T=!N;let C=k,M=O;N!=null&&N.enabled.x&&(M=_),N!=null&&N.enabled.y&&(C=E),T&&!h&&(m?M=p-2*xo(u.left,u.right):C=g-2*xo(u.top,u.bottom)),await s({...t,availableWidth:M,availableHeight:C});const D=await i.getDimensions(a.floating);return p!==D.width||g!==D.height?{reset:{rects:!0}}:{}}}};function Jv(){return typeof window<"u"}function sd(e){return n$(e)?(e.nodeName||"").toLowerCase():"#document"}function Ur(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jo(e){var t;return(t=(n$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function n$(e){return Jv()?e instanceof Node||e instanceof Ur(e).Node:!1}function Ca(e){return Jv()?e instanceof Element||e instanceof Ur(e).Element:!1}function Js(e){return Jv()?e instanceof HTMLElement||e instanceof Ur(e).HTMLElement:!1}function YM(e){return!Jv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ur(e).ShadowRoot}function ey(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Ta(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Hie(e){return/^(table|td|th)$/.test(sd(e))}function ty(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Kie=/transform|translate|scale|rotate|perspective|filter/,qie=/paint|layout|strict|content/,Al=e=>!!e&&e!=="none";let Ux;function IS(e){const t=Ca(e)?Ta(e):e;return Al(t.transform)||Al(t.translate)||Al(t.scale)||Al(t.rotate)||Al(t.perspective)||!RS()&&(Al(t.backdropFilter)||Al(t.filter))||Kie.test(t.willChange||"")||qie.test(t.contain||"")}function Gie(e){let t=ec(e);for(;Js(t)&&!nh(t);){if(IS(t))return t;if(ty(t))return null;t=ec(t)}return null}function RS(){return Ux==null&&(Ux=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Ux}function nh(e){return/^(html|body|#document)$/.test(sd(e))}function Ta(e){return Ur(e).getComputedStyle(e)}function ny(e){return Ca(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ec(e){if(sd(e)==="html")return e;const t=e.assignedSlot||e.parentNode||YM(e)&&e.host||jo(e);return YM(t)?t.host:t}function r$(e){const t=ec(e);return nh(t)?(e.ownerDocument||e).body:Js(t)&&ey(t)?t:r$(t)}function rh(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=r$(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=Ur(i);if(a){const l=y1(s);return t.concat(s,s.visualViewport||[],ey(i)?i:[],l&&n?rh(l):[])}else return t.concat(i,rh(i,[],n))}function y1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function i$(e){const t=Ta(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Js(e),a=i?e.offsetWidth:n,s=i?e.offsetHeight:r,l=Dg(n)!==a||Dg(r)!==s;return l&&(n=a,r=s),{width:n,height:r,$:l}}function PS(e){return Ca(e)?e:e.contextElement}function Tu(e){const t=PS(e);if(!Js(t))return wo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=i$(t);let s=(a?Dg(n.width):n.width)/r,l=(a?Dg(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!l||!Number.isFinite(l))&&(l=1),{x:s,y:l}}const Vie=wo(0);function a$(e){const t=Ur(e);return!RS()||!t.visualViewport?Vie:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Wie(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Ur(e)}function tc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=PS(e);let s=wo(1);t&&(r?Ca(r)&&(s=Tu(r)):s=Tu(e));const l=Wie(a,n,r)?a$(a):wo(0);let u=(i.left+l.x)/s.x,d=(i.top+l.y)/s.y,h=i.width/s.x,m=i.height/s.y;if(a&&r){const p=Ur(a),g=Ca(r)?Ur(r):r;let w=p,x=y1(w);for(;x&&g!==w;){const E=Tu(x),_=x.getBoundingClientRect(),k=Ta(x),O=_.left+(x.clientLeft+parseFloat(k.paddingLeft))*E.x,N=_.top+(x.clientTop+parseFloat(k.paddingTop))*E.y;u*=E.x,d*=E.y,h*=E.x,m*=E.y,u+=O,d+=N,w=Ur(x),x=y1(w)}}return Lg({width:h,height:m,x:u,y:d})}function ry(e,t){const n=ny(e).scrollLeft;return t?t.left+n:tc(jo(e)).left+n}function o$(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ry(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Yie(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const a=i==="fixed",s=jo(r),l=t?ty(t.floating):!1;if(r===s||l&&a)return n;let u={scrollLeft:0,scrollTop:0},d=wo(1);const h=wo(0),m=Js(r);if((m||!a)&&((sd(r)!=="body"||ey(s))&&(u=ny(r)),m)){const g=tc(r);d=Tu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const p=s&&!m&&!a?o$(s,u):wo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+p.x,y:n.y*d.y-u.scrollTop*d.y+h.y+p.y}}function Xie(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Zie(e){const t=ny(e),n=e.ownerDocument.body,r=xo(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=xo(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+ry(e);const s=-t.scrollTop;return Ta(n).direction==="rtl"&&(a+=xo(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:s}}const Qie=25;function Jie(e,t,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",i=Ur(e),a=jo(e),s=i.visualViewport;let l=a.clientWidth,u=a.clientHeight,d=0,h=0;if(s){const p=!RS()||t==="fixed";r?p||(d=-s.offsetLeft,h=-s.offsetTop):(l=s.width,u=s.height,p&&(d=s.offsetLeft,h=s.offsetTop))}if(ry(a)<=0){const p=a.ownerDocument,g=p.body,w=getComputedStyle(g),x=p.compatMode==="CSS1Compat"&&parseFloat(w.marginLeft)+parseFloat(w.marginRight)||0,E=Math.abs(a.clientWidth-g.clientWidth-x),_=getComputedStyle(a).scrollbarGutter==="stable both-edges"?E/2:E;_<=Qie&&(l-=_)}return{width:l,height:u,x:d,y:h}}function eae(e,t){const n=tc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Tu(e),s=e.clientWidth*a.x,l=e.clientHeight*a.y,u=i*a.x,d=r*a.y;return{width:s,height:l,x:u,y:d}}function XM(e,t,n){let r;if(t==="viewport"||t==="layoutViewport")r=Jie(e,n,t);else if(t==="document")r=Zie(jo(e));else if(Ca(t))r=eae(t,n);else{const i=a$(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Lg(r)}function tae(e,t){const n=t.get(e);if(n)return n;let r=rh(e,[],!1).filter(l=>Ca(l)&&sd(l)!=="body"),i=null;const a=Ta(e).position==="fixed";let s=a?ec(e):e;for(;Ca(s)&&!nh(s);){const l=Ta(s),u=IS(s),d=i?i.position:a?"fixed":"";!u&&(d==="fixed"||d==="absolute"&&l.position==="static")?r=r.filter(m=>m!==s):i=l,s=ec(s)}return t.set(e,r),r}function nae(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const s=[...n==="clippingAncestors"?ty(t)?[]:tae(t,this._c):[].concat(n),r],l=XM(t,s[0],i);let u=l.top,d=l.right,h=l.bottom,m=l.left;for(let p=1;p<s.length;p++){const g=XM(t,s[p],i);u=xo(g.top,u),d=Fs(g.right,d),h=Fs(g.bottom,h),m=xo(g.left,m)}return{width:d-m,height:h-u,x:m,y:u}}function rae(e){const{width:t,height:n}=i$(e);return{width:t,height:n}}function iae(e,t,n){const r=Js(t),i=jo(t),a=n==="fixed",s=tc(e,!0,a,t);let l={scrollLeft:0,scrollTop:0};const u=wo(0);if((r||!a)&&((sd(t)!=="body"||ey(i))&&(l=ny(t)),r)){const p=tc(t,!0,a,t);u.x=p.x+t.clientLeft,u.y=p.y+t.clientTop}!r&&i&&(u.x=ry(i));const d=i&&!r&&!a?o$(i,l):wo(0),h=s.left+l.scrollLeft-u.x-d.x,m=s.top+l.scrollTop-u.y-d.y;return{x:h,y:m,width:s.width,height:s.height}}function Fx(e){return Ta(e).position==="static"}function ZM(e,t){if(!Js(e)||Ta(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return jo(e)===n&&(n=n.ownerDocument.body),n}function s$(e,t){const n=Ur(e);if(ty(e))return n;if(!Js(e)){let i=ec(e);for(;i&&!nh(i);){if(Ca(i)&&!Fx(i))return i;i=ec(i)}return n}let r=ZM(e,t);for(;r&&Hie(r)&&Fx(r);)r=ZM(r,t);return r&&nh(r)&&Fx(r)&&!IS(r)?n:r||Gie(e)||n}const aae=async function(e){const t=this.getOffsetParent||s$,n=this.getDimensions,r=await n(e.floating);return{reference:iae(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function oae(e){return Ta(e).direction==="rtl"}const sae={convertOffsetParentRelativeRectToViewportRelativeRect:Yie,getDocumentElement:jo,getClippingRect:nae,getOffsetParent:s$,getElementRects:aae,getClientRects:Xie,getDimensions:rae,getScale:Tu,isElement:Ca,isRTL:oae};function l$(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function lae(e,t,n){let r=null,i;const a=jo(e);function s(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function l(h,m){h===void 0&&(h=!1),m===void 0&&(m=1),s();const p=e.getBoundingClientRect(),{left:g,top:w,width:x,height:E}=p;if(h||t(),!x||!E)return;const _=Mp(w),k=Mp(a.clientWidth-(g+x)),O=Mp(a.clientHeight-(w+E)),N=Mp(g),C={rootMargin:-_+"px "+-k+"px "+-O+"px "+-N+"px",threshold:xo(0,Fs(1,m))||1};let M=!0;function D(j){const R=j[0].intersectionRatio;if(!l$(p,e.getBoundingClientRect()))return l();if(R!==m){if(!M)return l();R?l(!1,R):i=setTimeout(()=>{l(!1,1e-7)},1e3)}M=!1}try{r=new IntersectionObserver(D,{...C,root:a.ownerDocument})}catch{r=new IntersectionObserver(D,C)}r.observe(e)}const u=Ur(e),d=()=>l(n);return u.addEventListener("resize",d),l(!0),()=>{u.removeEventListener("resize",d),s()}}function cae(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=PS(e),h=i||a?[...d?rh(d):[],...t?rh(t):[]]:[];h.forEach(_=>{i&&_.addEventListener("scroll",n),a&&_.addEventListener("resize",n)});const m=d&&l?lae(d,n,a):null;let p=-1,g=null;s&&(g=new ResizeObserver(_=>{let[k]=_;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var O;(O=g)==null||O.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let w,x=u?tc(e):null;u&&E();function E(){const _=tc(e);x&&!l$(x,_)&&n(),x=_,w=requestAnimationFrame(E)}return n(),()=>{var _;h.forEach(k=>{i&&k.removeEventListener("scroll",n),a&&k.removeEventListener("resize",n)}),m==null||m(),(_=g)==null||_.disconnect(),g=null,u&&cancelAnimationFrame(w)}}const uae=$ie,dae=Bie,fae=jie,hae=Fie,mae=Lie,QM=Die,pae=Uie,gae=(e,t,n)=>{const r=new Map,i=n??{},a={...sae,...i.platform,_c:r};return Pie(e,t,{...i,platform:a})};var vae=typeof document<"u",yae=function(){},og=vae?b.useLayoutEffect:yae;function zg(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(!zg(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)&&!zg(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function c$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function JM(e,t){const n=c$(e);return Math.round(t*n)/n}function Hx(e){const t=b.useRef(e);return og(()=>{t.current=e}),t}function bae(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:s}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[h,m]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,g]=b.useState(r);zg(p,r)||g(r);const[w,x]=b.useState(null),[E,_]=b.useState(null),k=b.useCallback(F=>{F!==C.current&&(C.current=F,x(F))},[]),O=b.useCallback(F=>{F!==M.current&&(M.current=F,_(F))},[]),N=a||w,T=s||E,C=b.useRef(null),M=b.useRef(null),D=b.useRef(h),j=u!=null,R=Hx(u),H=Hx(i),P=Hx(d),G=b.useCallback(()=>{if(!C.current||!M.current)return;const F={placement:t,strategy:n,middleware:p};H.current&&(F.platform=H.current),gae(C.current,M.current,F).then(V=>{const $={...V,isPositioned:P.current!==!1};q.current&&!zg(D.current,$)&&(D.current=$,La.flushSync(()=>{m($)}))})},[p,t,n,H,P]);og(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,m(F=>({...F,isPositioned:!1})))},[d]);const q=b.useRef(!1);og(()=>(q.current=!0,()=>{q.current=!1}),[]),og(()=>{if(N&&(C.current=N),T&&(M.current=T),N&&T){if(R.current)return R.current(N,T,G);G()}},[N,T,G,R,j]);const X=b.useMemo(()=>({reference:C,floating:M,setReference:k,setFloating:O}),[k,O]),U=b.useMemo(()=>({reference:N,floating:T}),[N,T]),K=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!U.floating)return F;const V=JM(U.floating,h.x),$=JM(U.floating,h.y);return l?{...F,transform:"translate("+V+"px, "+$+"px)",...c$(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:V,top:$}},[n,l,U.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:G,refs:X,elements:U,floatingStyles:K}),[h,G,X,U,K])}const xae=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?QM({element:r.current,padding:i}).fn(n):{}:r?QM({element:r,padding:i}).fn(n):{}}}},wae=(e,t)=>{const n=uae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eae=(e,t)=>{const n=dae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Sae=(e,t)=>({fn:pae(e).fn,options:[e,t]}),_ae=(e,t)=>{const n=fae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Aae=(e,t)=>{const n=hae(e);return{name:n.name,fn:n.fn,options:[e,t]}},kae=(e,t)=>{const n=mae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Oae=(e,t)=>{const n=xae(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Nae=Object.defineProperty,DS=(e,t)=>Nae(e,"name",{value:t,configurable:!0});function b1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}DS(b1,"setRef");function u$(...e){return t=>{let n=!1;const r=e.map(i=>{const a=b1(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():b1(e[i],null)}}}}DS(u$,"composeRefs");function iy(...e){return b.useCallback(u$(...e),e)}DS(iy,"useComposedRefs");var Cae=Object.defineProperty,Ci=(e,t)=>Cae(e,"name",{value:t,configurable:!0});function Tae(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Ci(a=>{const{children:s,...l}=a,u=b.useMemo(()=>l,Object.values(l));return y.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:l=!1}=s,u=b.useContext(n);if(u)return u;if(t!==void 0)return t;if(!l)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ci(i,"useContext"),[r,i]}Ci(Tae,"createContext");function d$(e,t=[]){let n=[];function r(a,s){const l=b.createContext(s);l.displayName=a+"Context";const u=n.length;n=[...n,s];const d=Ci(m=>{var _;const{scope:p,children:g,...w}=m,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useMemo(()=>w,Object.values(w));return y.jsx(x.Provider,{value:E,children:g})},"Provider");d.displayName=a+"Provider";function h(m,p,g={}){var _;const{optional:w=!1}=g,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useContext(x);if(E)return E;if(s!==void 0)return s;if(!w)throw new Error(`\`${m}\` must be used within \`${a}\``)}return Ci(h,"useContext"),[d,h]}Ci(r,"createContext");const i=Ci(()=>{const a=n.map(s=>b.createContext(s));return Ci(function(l){const u=(l==null?void 0:l[e])||a;return b.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])},"useScope")},"createScope");return i.scopeName=e,[r,f$(i,...t)]}Ci(d$,"createContextScope");function f$(...e){const t=e[0];if(e.length===1)return t;const n=Ci(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ci(function(a){const s=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(a)[`__scope${d}`];return{...l,...m}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ci(f$,"composeContextScopes");var Mae=Object.defineProperty,ta=(e,t)=>Mae(e,"name",{value:t,configurable:!0});function h$(e){const t=b.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,l=!1;const u=[];x1(i)&&typeof Ip=="function"&&(i=Ip(i._payload)),b.Children.forEach(i,p=>{var g;if(v$(p)){l=!0;const w=p;let x="child"in w.props?w.props.child:w.props.children;x1(x)&&typeof Ip=="function"&&(x=Ip(x._payload)),s=Rae(w,x),u.push((g=s==null?void 0:s.props)==null?void 0:g.children)}else u.push(p)}),s?s=b.cloneElement(s,void 0,u):!l&&b.Children.count(i)===1&&b.isValidElement(i)&&(s=i);const d=s?g$(s):void 0,h=iy(r,d);if(!s){if(i||i===0)throw new Error(l?jae(e):Dae(e));return i}const m=p$(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}ta(h$,"createSlot");var m$=Symbol.for("radix.slottable");function Iae(e){const t=ta(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=m$,t}ta(Iae,"createSlottable");var Rae=ta((e,t)=>{if("child"in e.props){const n=e.props.child;return b.isValidElement(n)?b.cloneElement(n,void 0,e.props.children(n.props.children)):null}return b.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function p$(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]=(...l)=>{const u=a(...l);return i(...l),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}ta(p$,"mergeProps");function g$(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)}ta(g$,"getElementRef");function v$(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===m$}ta(v$,"isSlottable");var Pae=Symbol.for("react.lazy");function x1(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Pae&&"_payload"in e&&y$(e._payload)}ta(x1,"isLazyComponent");function y$(e){return typeof e=="object"&&e!==null&&"then"in e}ta(y$,"isPromiseLike");var Dae=ta(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),jae=ta(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Ip=ja[" use ".trim().toString()],Lae=Object.defineProperty,zae=(e,t)=>Lae(e,"name",{value:t,configurable:!0}),$ae=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],b$=$ae.reduce((e,t)=>{const n=h$(`Primitive.${t}`),r=b.forwardRef((i,a)=>{const{asChild:s,...l}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),y.jsx(u,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bae(e,t){e&&La.flushSync(()=>e.dispatchEvent(t))}zae(Bae,"dispatchDiscreteCustomEvent");var Uae=Object.defineProperty,Fae=(e,t)=>Uae(e,"name",{value:t,configurable:!0});function x$(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}Fae(x$,"useCallbackRef");var Kx=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},Hae=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},Kae=Object.defineProperty,qae=(e,t)=>Kae(e,"name",{value:t,configurable:!0});function w$(e){const[t,n]=b.useState(void 0);return Hae(()=>{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,l;if("borderBoxSize"in a){const u=a.borderBoxSize,d=Array.isArray(u)?u[0]:u;s=d.inlineSize,l=d.blockSize}else s=e.offsetWidth,l=e.offsetHeight;n({width:s,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}qae(w$,"useSize");var Gae=Object.defineProperty,js=(e,t)=>Gae(e,"name",{value:t,configurable:!0}),E$="Popper",[S$,_$]=d$(E$),[Vae,A$]=S$(E$),Wae=js(e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null),[a,s]=b.useState(void 0);return y.jsx(Vae,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:s,children:n})},"Popper"),Yae="PopperAnchor",Xae=b.forwardRef(js(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=A$(Yae,r),l=b.useRef(null),u=s.onAnchorChange,d=b.useCallback(x=>{l.current=x,x&&u(x)},[u]),h=iy(n,d),m=b.useRef(null);b.useEffect(()=>{if(!i)return;const x=m.current;m.current=i.current,x!==m.current&&u(m.current)});const p=s.placementState&&ay(s.placementState),g=p==null?void 0:p[0],w=p==null?void 0:p[1];return i?null:y.jsx(b$.div,{"data-radix-popper-side":g,"data-radix-popper-align":w,...a,ref:h})},"PopperAnchor")),k$="PopperContent",[Zae,cCe]=S$(k$),Qae=b.forwardRef(js(function(t,n){var fe,Ee,Te,de,nt,He,Ae;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:s="center",alignOffset:l=0,arrowPadding:u=0,avoidCollisions:d=!0,collisionBoundary:h=[],collisionPadding:m=0,sticky:p="partial",hideWhenDetached:g=!1,updatePositionStrategy:w="optimized",onPlaced:x,...E}=t,_=A$(k$,r),[k,O]=b.useState(null),N=iy(n,O),[T,C]=b.useState(null),M=w$(T),D=(M==null?void 0:M.width)??0,j=(M==null?void 0:M.height)??0,R=i+(s!=="center"?"-"+s:""),H=typeof m=="number"?m:{top:0,right:0,bottom:0,left:0,...m},P=Array.isArray(h)?h:[h],G=P.length>0,q={padding:H,boundary:P.filter(O$),altBoundary:G},{refs:X,floatingStyles:U,placement:K,isPositioned:F,middlewareData:V}=bae({strategy:"fixed",placement:R,whileElementsMounted:js((...De)=>cae(...De,{animationFrame:w==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[wae({mainAxis:a+j,alignmentAxis:l}),d&&Eae({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Sae():void 0,...q}),d&&_ae({...q}),Aae({...q,apply:js(({elements:De,rects:Ht,availableWidth:un,availableHeight:Yn})=>{const{width:Or,height:Li}=Ht.reference,ir=De.floating.style;ir.setProperty("--radix-popper-available-width",`${un}px`),ir.setProperty("--radix-popper-available-height",`${Yn}px`),ir.setProperty("--radix-popper-anchor-width",`${Or}px`),ir.setProperty("--radix-popper-anchor-height",`${Li}px`)},"apply")}),T&&Oae({element:T,padding:u}),Jae({arrowWidth:D,arrowHeight:j}),g&&kae({strategy:"referenceHidden",...q,boundary:G?q.boundary:void 0})]}),$=_.setPlacementState;Kx(()=>($(K),()=>{$(void 0)}),[K,$]);const[L,W]=ay(K),z=x$(x);Kx(()=>{F&&(z==null||z())},[F,z]);const ie=(fe=V.arrow)==null?void 0:fe.x,he=(Ee=V.arrow)==null?void 0:Ee.y,ge=((Te=V.arrow)==null?void 0:Te.centerOffset)!==0,[Se,$e]=b.useState();return Kx(()=>{k&&$e(window.getComputedStyle(k).zIndex)},[k]),y.jsx("div",{ref:X.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:F?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Se,"--radix-popper-transform-origin":[(de=V.transformOrigin)==null?void 0:de.x,(nt=V.transformOrigin)==null?void 0:nt.y].join(" "),...((He=V.hide)==null?void 0:He.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:y.jsx(Zae,{scope:r,placedSide:L,placedAlign:W,onArrowChange:C,arrowX:ie,arrowY:he,shouldHideArrow:ge,children:y.jsx(b$.div,{"data-side":L,"data-align":W,...E,ref:N,style:{...E.style,animation:F?(Ae=E.style)==null?void 0:Ae.animation:"none"}})})})},"PopperContent"));function O$(e){return e!==null}js(O$,"isNotNull");var Jae=js(e=>({name:"transformOrigin",options:e,fn(t){var E,_,k;const{placement:n,rects:r,middlewareData:i}=t,s=((E=i.arrow)==null?void 0:E.centerOffset)!==0,l=s?0:e.arrowWidth,u=s?0:e.arrowHeight,[d,h]=ay(n),m={start:"0%",center:"50%",end:"100%"}[h],p=(((_=i.arrow)==null?void 0:_.x)??0)+l/2,g=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let w="",x="";return d==="bottom"?(w=s?m:`${p}px`,x=`${-u}px`):d==="top"?(w=s?m:`${p}px`,x=`${r.floating.height+u}px`):d==="right"?(w=`${-u}px`,x=s?m:`${g}px`):d==="left"&&(w=`${r.floating.width+u}px`,x=s?m:`${g}px`),{data:{x:w,y:x}}}}),"transformOrigin");function ay(e){const[t,n="center"]=e.split("-");return[t,n]}js(ay,"getSideAndAlignFromPlacement");var eoe=Wae,toe=Xae,noe=Qae,roe=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},ioe=Object.defineProperty,aoe=(e,t)=>ioe(e,"name",{value:t,configurable:!0}),ooe=b.forwardRef(aoe(function(t,n){var u;const{container:r,...i}=t,[a,s]=b.useState(!1);roe(()=>s(!0),[]);const l=r||a&&((u=globalThis==null?void 0:globalThis.document)==null?void 0:u.body);return l?La.createPortal(y.jsx(Zv.div,{...i,ref:n}),l):null},"Portal")),eI=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},soe=Object.defineProperty,To=(e,t)=>soe(e,"name",{value:t,configurable:!0});function N$(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}To(N$,"useStateMachine");var C$=To(e=>{const{present:t,children:n}=e,r=T$(t),i=typeof n=="function"?n({present:r.isPresent}):b.Children.only(n),a=M$(r.ref,I$(i));return typeof n=="function"||r.isPresent?b.cloneElement(i,{ref:a}):null},"Presence");function T$(e){const[t,n]=b.useState(),r=b.useRef(null),i=b.useRef(e),a=b.useRef("none"),s=b.useRef(void 0),l=e?"mounted":"unmounted",[u,d]=N$(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return b.useEffect(()=>{u==="mounted"?(a.current=s.current??bu(r.current),s.current=void 0):a.current="none"},[u]),eI(()=>{const h=r.current,m=i.current;if(m!==e){const g=a.current,w=bu(h);e?(s.current=w,d("MOUNT")):w==="none"||(h==null?void 0:h.display)==="none"?d("UNMOUNT"):d(m&&g!==w?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,d]),eI(()=>{if(t){let h;const m=t.ownerDocument.defaultView??window,p=To(w=>{const E=bu(r.current).includes(CSS.escape(w.animationName));if(w.target===t&&E&&(d("ANIMATION_END"),!i.current)){const _=t.style.animationFillMode;t.style.animationFillMode="forwards",h=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=_)})}},"handleAnimationEnd"),g=To(w=>{w.target===t&&(a.current=bu(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{m.clearTimeout(h),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:b.useCallback(h=>{if(h){const m=getComputedStyle(h);r.current=m,s.current=bu(m)}else r.current=null;n(h)},[])}}To(T$,"usePresence");function w1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}To(w1,"setRef");function M$(...e){const t=b.useRef(e);return t.current=e,b.useCallback(n=>{const r=t.current;let i=!1;const a=r.map(s=>{const l=w1(s,n);return!i&&typeof l=="function"&&(i=!0),l});if(i)return()=>{for(let s=0;s<a.length;s++){const l=a[s];typeof l=="function"?l():w1(r[s],null)}}},[])}To(M$,"useStableComposedRefs");function bu(e){return(e==null?void 0:e.animationName)||"none"}To(bu,"getAnimationName");function I$(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)}To(I$,"getElementRef");var R$=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},loe=Object.defineProperty,coe=(e,t)=>loe(e,"name",{value:t,configurable:!0}),tI=ja[" useEffectEvent ".trim().toString()],nI=ja[" useInsertionEffect ".trim().toString()];function P$(e){if(typeof tI=="function")return tI(e);const t=b.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof nI=="function"?nI(()=>{t.current=e}):R$(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}coe(P$,"useEffectEvent");var uoe=Object.defineProperty,Nh=(e,t)=>uoe(e,"name",{value:t,configurable:!0}),doe=ja[" useInsertionEffect ".trim().toString()]||R$;function D$({prop:e,defaultProp:t,onChange:n=Nh(()=>{},"onChange"),caller:r}){const[i,a,s]=j$({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:i,d=b.useCallback(h=>{var m;if(l){const p=L$(h)?h(e):h;p!==e&&((m=s.current)==null||m.call(s,p))}else a(h)},[l,e,a,s]);return[u,d]}Nh(D$,"useControllableState");function j$({defaultProp:e,onChange:t}){const[n,r]=b.useState(e),i=b.useRef(n),a=b.useRef(t);return doe(()=>{a.current=t},[t]),b.useEffect(()=>{var s;i.current!==n&&((s=a.current)==null||s.call(a,n),i.current=n)},[n,i]),[n,r,a]}Nh(j$,"useUncontrolledState");function L$(e){return typeof e=="function"}Nh(L$,"isFunction");var rI=Symbol("RADIX:SYNC_STATE");function foe(e,t,n,r){const{prop:i,defaultProp:a,onChange:s,caller:l}=t,u=i!==void 0,d=P$(s),h=[{...n,state:a}];r&&h.push(r);const[m,p]=b.useReducer((E,_)=>{if(_.type===rI)return{...E,state:_.state};const k=e(E,_);return u&&!Object.is(k.state,E.state)&&d(k.state),k},...h),g=m.state,w=b.useRef(g);b.useEffect(()=>{w.current!==g&&(w.current=g,u||d(g))},[g,w,u]);const x=b.useMemo(()=>i!==void 0?{...m,state:i}:m,[m,i]);return b.useEffect(()=>{u&&!Object.is(i,m.state)&&p({type:rI,state:i})},[i,m.state,u]),[x,p]}Nh(foe,"useControllableStateReducer");var hoe=Object.defineProperty,el=(e,t)=>hoe(e,"name",{value:t,configurable:!0}),jS="Popover",[z$,uCe]=Dz(jS,[_$]),LS=_$(),[moe,ld]=z$(jS),poe=el(e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!1}=e,l=LS(t),u=b.useRef(null),[d,h]=b.useState(!1),[m,p]=D$({prop:r,defaultProp:i??!1,onChange:a,caller:jS});return y.jsx(eoe,{...l,children:y.jsx(moe,{scope:t,contentId:Qz(),triggerRef:u,open:m,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(g=>!g),[p]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>h(!0),[]),onCustomAnchorRemove:b.useCallback(()=>h(!1),[]),modal:s,children:n})})},"Popover"),goe="PopoverTrigger",voe=b.forwardRef(el(function(t,n){const{__scopePopover:r,...i}=t,a=ld(goe,r),s=LS(r),l=ad(n,a.triggerRef),u=y.jsx(Zv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":zS(a.open),...i,ref:l,onClick:Ds(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:y.jsx(toe,{asChild:!0,...s,children:u})},"PopoverTrigger")),$$="PopoverPortal",[yoe,boe]=z$($$,{forceMount:void 0}),xoe=el(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=ld($$,t);return y.jsx(yoe,{scope:t,forceMount:n,children:y.jsx(C$,{present:n||a.open,children:y.jsx(ooe,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),ih="PopoverContent",woe=b.forwardRef(el(function(t,n){const r=boe(ih,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=ld(ih,t.__scopePopover);return y.jsx(C$,{present:i||s.open,children:s.modal?y.jsx(Soe,{...a,ref:n}):y.jsx(_oe,{...a,ref:n})})},"PopoverContent")),Eoe=_S("PopoverContent.RemoveScroll"),Soe=b.forwardRef(el(function(t,n){const r=ld(ih,t.__scopePopover),i=b.useRef(null),a=ad(n,i),s=b.useRef(!1);return b.useEffect(()=>{const l=i.current;if(l)return gz(l)},[]),y.jsx(vS,{as:Eoe,allowPinchZoom:!0,children:y.jsx(B$,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ds(t.onCloseAutoFocus,l=>{var u;l.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:Ds(t.onPointerDownOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;s.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:Ds(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),_oe=b.forwardRef(el(function(t,n){const r=ld(ih,t.__scopePopover),i=b.useRef(!1),a=b.useRef(!1);return y.jsx(B$,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var l,u;(l=t.onCloseAutoFocus)==null||l.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 d,h;(d=t.onInteractOutside)==null||d.call(t,s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const l=s.target;((h=r.triggerRef.current)==null?void 0:h.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&a.current&&s.preventDefault()}})},"PopoverContentNonModal")),B$=b.forwardRef(el(function(t,n){const{__scopePopover:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:s,disableOutsidePointerEvents:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:m,...p}=t,g=ld(ih,r),w=LS(r);return OS(),y.jsx(vie,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:s,children:y.jsx(cie,{asChild:!0,disableOutsidePointerEvents:l,onInteractOutside:m,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:h,onDismiss:()=>g.onOpenChange(!1),deferPointerDownOutside:!0,children:y.jsx(noe,{"data-state":zS(g.open),role:"dialog",id:g.contentId,...w,...p,ref:n,style:{...p.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 zS(e){return e?"open":"closed"}el(zS,"getState");var Aoe=poe,koe=voe,Ooe=xoe,U$=woe;const Noe=Aoe,Coe=koe,F$=b.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>y.jsx(Ooe,{children:y.jsx(U$,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:ze("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})}));F$.displayName=U$.displayName;const H$=92,K$=96;function qx(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 iI=3e5;function Toe({socket:e,getToken:t}){const[n,r]=b.useState([]);if(b.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]),b.useEffect(()=>{if(!e)return;const a=e.on(s=>{s.type==="stats"&&r(l=>[...l,s.sample].slice(-120))});return()=>{a()}},[e]),!n.length)return null;const i=n[n.length-1];return y.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:[y.jsx(sg,{label:"cpu",value:i.cpu,series:n.map(a=>a.cpu)}),y.jsx(sg,{label:"mem",value:i.mem,series:n.map(a=>a.mem)}),i.disk>=0&&y.jsx(sg,{label:"disk",value:i.disk,severity:Loe(i.disk),title:$oe(i)}),y.jsx(Moe,{getToken:t})]})}function Moe({getToken:e}){const[t,n]=b.useState(null);return b.useEffect(()=>{let r=!0,i=0;const a=async()=>{var d;try{const h=await e();if(!h)return;i=Date.now();const m=await fetch("/api/claude-usage",{headers:{Authorization:`Bearer ${h}`}});if(!r)return;if(m.status===204){n(null);return}if(m.status!==200)return;const p=await m.json();if(!r||!((d=p==null?void 0:p.limits)!=null&&d.length))return;n(p)}catch(h){console.warn("[MachineStats] claude usage poll failed",h)}},s=()=>{document.visibilityState==="visible"&&a()},l=()=>{document.visibilityState==="visible"&&Date.now()-i>=iI&&a()};s();const u=setInterval(s,iI);return document.addEventListener("visibilitychange",l),()=>{r=!1,clearInterval(u),document.removeEventListener("visibilitychange",l)}},[e]),y.jsx(q$,{usage:t})}function q$({usage:e,compact:t}){const n=e&&G$(e.limits),[r,i]=b.useState(E1),a=b.useRef(null),s=()=>{a.current&&(clearTimeout(a.current),a.current=null)},l=b.useCallback((u,d=0)=>{if(s(),!d){i(h=>oI(h,u));return}a.current=setTimeout(()=>{a.current=null,i(h=>oI(h,u))},d)},[]);return b.useEffect(()=>s,[]),!e||!n?null:y.jsxs(Noe,{open:r.open,onOpenChange:u=>l(u?{type:"activate"}:{type:"dismiss"}),children:[y.jsx(Coe,{asChild:!0,children:y.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:u=>l({type:"pointerenter",pointerType:u.pointerType},Ioe),onPointerLeave:u=>l({type:"pointerleave",pointerType:u.pointerType},aI),children:t?y.jsxs("span",{className:ze("tabular-nums",$g(n.percent,n.severity)),children:[n.percent,"% used"]}):y.jsx(sg,{label:"usage",value:n.percent,severity:n.severity})})}),y.jsx(F$,{onOpenAutoFocus:u=>u.preventDefault(),onPointerEnter:()=>s(),onPointerLeave:u=>l({type:"pointerleave",pointerType:u.pointerType},aI),children:y.jsx(Roe,{usage:e})})]})}const Ioe=120,aI=80,E1={open:!1,byHover:!1};function oI(e,t){switch(t.type){case"pointerenter":return sI(t.pointerType)?{open:!0,byHover:!0}:e;case"pointerleave":return sI(t.pointerType)&&e.byHover?E1:e;case"activate":return{open:!0,byHover:!1};case"dismiss":return E1}}const sI=e=>e==="mouse"||e==="";function Roe({usage:e}){const t=G$(e.limits);return y.jsxs("div",{className:"text-[11px] leading-tight",children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2 pb-2 text-muted-foreground",children:[y.jsx("span",{className:"uppercase tracking-wide",children:"claude usage"}),e.subscriptionType&&y.jsxs("span",{className:"tabular-nums",children:[e.subscriptionType," plan"]})]}),y.jsxs("div",{className:"-mt-1 flex items-baseline justify-between gap-2 pb-2 text-[10px] text-muted-foreground",children:[e.account&&y.jsx("span",{className:"truncate",title:e.account,children:e.account}),y.jsx("span",{className:ze("shrink-0",e.stale&&"text-amber-500"),children:Doe(e)})]}),e.stale&&e.error&&y.jsxs("div",{"data-refresh-error":!0,className:"-mt-1 pb-2 text-[10px] text-amber-500 break-words",children:[e.error,ag(e.retryAt??null)&&` · retrying in ${ag(e.retryAt??null)}`]}),y.jsx("div",{className:"flex flex-col gap-3",children:e.limits.map((n,r)=>{const i=ag(n.resetsAt),a=n===t;return y.jsxs("div",{"data-headline":a||void 0,className:ze("flex flex-col gap-1",!a&&"opacity-60"),children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[y.jsxs("span",{className:ze("truncate",a&&"font-medium"),children:[a&&y.jsx("span",{className:"mr-1 text-muted-foreground","aria-hidden":!0,children:"▸"}),Poe(n)]}),y.jsxs("span",{className:ze("tabular-nums shrink-0",$g(n.percent,n.severity)),children:[n.percent,"%"]})]}),y.jsx(V$,{value:n.percent,className:ze("w-full",$g(n.percent,n.severity))}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:i?`resets in ${i}`:"no reset reported"})]},`${n.kind}-${r}`)})}),y.jsx("div",{className:"mt-3 border-t pt-2 text-[10px] text-muted-foreground",children:"▸ is the window the strip is showing"})]})}function Poe(e){return e.scopeLabel?`${e.scopeLabel} window`:e.kind==="session"?"current session":e.kind==="weekly_all"?"all models":e.kind.replace(/_/g," ")}function G$(e){return e.reduce((t,n)=>!t||n.percent>t.percent?n:t,null)}function Doe(e){const t=joe(e.fetchedAt);return t?e.stale?`${t} old — refresh failed`:`updated ${t} ago`:e.stale?"last reading — refresh failed":"updated just now"}function joe(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 Loe(e){return e>=K$?"critical":e>=H$?"warning":"ok"}const zoe={critical:"text-red-500",exceeded:"text-red-500",warning:"text-amber-500",warn:"text-amber-500",ok:"text-emerald-500"};function $g(e,t){const n=t?zoe[t]:void 0;return n||(e>=90?"text-red-500":e>=75?"text-amber-500":"text-emerald-500")}function $oe(e){const t=`warn at ${H$}%, critical at ${K$}%`;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 — ${qx(e.diskUsedBytes)} of ${qx(e.diskTotalBytes)}, ${qx(n)} free — ${t}`}function sg({label:e,value:t,series:n,title:r,severity:i}){const a=$g(t,i),s=r??(n?`${e} ${t}% — last ${n.length} samples`:void 0);return y.jsxs("span",{className:"flex items-center gap-1",title:s,children:[y.jsx("span",{className:"uppercase tracking-wide",children:e}),n?y.jsx(Boe,{series:n,className:a}):y.jsx(V$,{value:t,className:a}),y.jsxs("span",{className:ze("tabular-nums",a),children:[t,"%"]})]})}function V$({value:e,className:t}){const i=Math.max(0,Math.min(100,e))/100*40;return y.jsxs("svg",{width:40,height:12,viewBox:"0 0 40 12",className:ze("overflow-visible",t),preserveAspectRatio:"none",children:[y.jsx("rect",{x:0,y:12/2-2,width:40,height:4,rx:2,fill:"currentColor",opacity:.2}),i>0&&y.jsx("rect",{x:0,y:12/2-2,width:i,height:4,rx:2,fill:"currentColor"})]})}function Boe({series:e,className:t}){const i=e.length;if(i<2)return null;const a=e.map((s,l)=>{const u=i>1?l/(i-1)*40:0,d=12-Math.max(0,Math.min(100,s))/100*12;return`${u.toFixed(1)},${d.toFixed(1)}`}).join(" ");return y.jsx("svg",{width:40,height:12,viewBox:"0 0 40 12",className:ze("overflow-visible",t),preserveAspectRatio:"none",children:y.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}const kf=50;function Uoe({getToken:e,filter:t,refreshKey:n,hydrateIds:r}){const[i,a]=b.useState([]),[s,l]=b.useState(null),[u,d]=b.useState(!1),[h,m]=b.useState({}),p=b.useRef(new Set),g=b.useRef(null),w=b.useRef(null),x=b.useRef(t);x.current=t;const E=b.useRef(kf),_=b.useRef(t);_.current!==t&&(_.current=t,E.current=kf);const k=b.useCallback(async(M,D)=>{const j=await e();if(!j||D!=null&&D.aborted)return null;const R=await fetch(`/api/sessions?${new URLSearchParams(M)}`,{signal:D,headers:{Authorization:`Bearer ${j}`}});if(!R.ok)return null;const H=await R.json();return Array.isArray(H==null?void 0:H.sessions)?H:null},[e]),O=b.useCallback(async(M,D,j)=>{const R=[];let H,P=null;for(;R.length<M;){const G={filter:D,limit:String(Math.min(kf,M-R.length))};H&&(G.before=H);const q=await k(G,j);if(!q)return null;if(R.push(...q.sessions),P=q.nextCursor,!P||!q.sessions.length)break;H=P}return{sessions:R,nextCursor:P}},[k]);b.useEffect(()=>{var D,j;(D=g.current)==null||D.abort(),(j=w.current)==null||j.abort();const M=new AbortController;return g.current=M,d(!0),p.current.clear(),m({}),O(E.current,t,M.signal).then(R=>{!R||M.signal.aborted||(a(R.sessions),l(R.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)}),()=>M.abort()},[O,t,n]);const N=b.useCallback(()=>{var j;if(!s||u)return;(j=w.current)==null||j.abort();const M=new AbortController;w.current=M;const D=x.current;d(!0),k({filter:D,limit:String(kf),before:s},M.signal).then(R=>{!R||M.signal.aborted||D!==x.current||(a(H=>{const P=new Set(H.map(q=>q.sessionId)),G=[...H,...R.sessions.filter(q=>!P.has(q.sessionId))];return E.current=Math.max(kf,G.length),G}),l(R.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)})},[s,u,k]),T=b.useMemo(()=>{const M=new Map;for(const D of Object.values(h))M.set(D.sessionId,D);for(const D of i)M.set(D.sessionId,D);return M},[i,h]),C=r.join(",");return b.useEffect(()=>{const M=r.filter(j=>!!j&&!T.has(j)&&!p.current.has(j)).slice(0,200);if(!M.length)return;for(const j of M)p.current.add(j);let D=!1;return k({ids:M.join(",")}).then(j=>{!j||D||m(R=>{const H={...R};for(const P of j.sessions)H[P.sessionId]=P;return H})}).catch(()=>{}),()=>{D=!0}},[C,T,k]),{sessions:i,cursor:s,loading:u,byId:T,loadMore:N}}const Of="0.1.140";function Foe(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 Nf="w-4 h-4 mt-0.5 shrink-0";function Hoe(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?y.jsx(aV,{className:`${Nf} text-purple-400`}):(t==null?void 0:t.type)==="mention"?y.jsx(qG,{className:`${Nf} text-blue-400`}):(t==null?void 0:t.type)==="channel"?y.jsx(eV,{className:`${Nf} text-green-400`}):e.sessionId.startsWith("slack-")?y.jsx(Vw,{className:`${Nf} text-yellow-400`}):y.jsx(Vw,{className:`${Nf} text-muted-foreground`})}function Koe(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 qoe(e,t,n){return Object.keys(e).map(r=>t.get(r)).filter(r=>!!r&&(n==="all"||r.mine!==!1))}const lI="chats-filter",cI="chats-unread-filter";function Goe({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,unreads:l={},busySessions:u=new Set,socket:d}){var F;const h=za(),[m,p]=b.useState(()=>localStorage.getItem(lI)||"mine"),[g,w]=b.useState(()=>localStorage.getItem(cI)==="true"),[x,E]=b.useState(""),_=b.useRef(null);function k(V){p(V),localStorage.setItem(lI,V)}function O(){const V=!g;w(V),localStorage.setItem(cI,String(V))}const N=b.useMemo(()=>[t,...Object.keys(l)].filter(V=>!!V),[t,l]),{sessions:T,cursor:C,loading:M,byId:D,loadMore:j}=Uoe({getToken:e,filter:m,refreshKey:i,hydrateIds:N}),R=b.useMemo(()=>qoe(l,D,m),[l,D,m]),H=R.length,P=b.useMemo(()=>g?[...R].sort((V,$)=>$.lastModified-V.lastModified):T,[g,R,T]),G=t&&!P.some(V=>V.sessionId===t)?D.get(t):void 0;b.useEffect(()=>{_.current&&_.current.scrollIntoView({block:"nearest"})},[t,P,G]);const q=b.useRef(null),X=b.useRef(j);X.current=j,b.useEffect(()=>{const V=q.current;if(!V||!C||g)return;const $=new IntersectionObserver(L=>{L.some(W=>W.isIntersecting)&&X.current()},{rootMargin:"300px"});return $.observe(V),()=>$.disconnect()},[C,M,g]),b.useEffect(()=>{e().then(V=>V?fetch("/api/version",{headers:{Authorization:`Bearer ${V}`}}):null).then(V=>V==null?void 0:V.json()).then(V=>V&&E(V.version)).catch(()=>{})},[]);const U=!!x&&x!=="unknown"&&Of!=="dev"&&x!==Of;b.useEffect(()=>{U&&console.warn(`[shraga] stale client bundle: built from v${Of}, server runs v${x} — rebuild dist/client`)},[U,x]);function K(V){const $=l[V.sessionId],L=u.has(V.sessionId)||V.runStatus==="running"||V.scheduleRunStatus==="running",W=!L&&(!!V.lastStopReason||V.scheduleRunStatus==="error"||V.scheduleRunStatus==="aborted"),z=L?"border-amber-500":W?"border-red-500":$?"border-blue-500":"",ie=!!(L||W||$);return y.jsx("button",{ref:V.sessionId===t?_:void 0,onClick:()=>n(V.sessionId,V.title),className:ze("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",ie?`rounded-r-lg border-l-[3px] ${z}`:"rounded-lg",t===V.sessionId&&"bg-accent"),children:y.jsxs("div",{className:"flex items-start gap-2",children:[Hoe(V),y.jsxs("div",{className:"min-w-0 flex-1",children:[y.jsx("span",{className:ze("block truncate text-sm leading-snug",$&&"font-semibold"),children:V.title||"New session"}),y.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[y.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:Koe(V)||V.userName}),y.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:Foe(V.lastModified)})]})]})]})},V.sessionId)}return y.jsxs("div",{className:"flex flex-col h-full bg-muted/30",children:[y.jsx("div",{className:"p-3",children:y.jsxs(we,{variant:"outline",size:"sm",className:"w-full gap-2 justify-start",onClick:r,title:"New Chat (Ctrl+N)",children:[y.jsx(ko,{className:"w-4 h-4"})," New Chat",y.jsx("span",{className:"ml-auto flex items-center gap-0.5 text-[10px] text-muted-foreground/50 font-mono",children:"⌃N"})]})}),y.jsx("div",{className:"border-b shrink-0 flex flex-col max-h-[40vh]",children:y.jsx(Bre,{getToken:e,onRefresh:s,refreshKey:a})}),y.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Chats"}),y.jsxs("div",{className:"flex gap-0.5",children:[["mine","all"].map(V=>y.jsx("button",{onClick:()=>k(V),className:ze("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",m===V?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:V},V)),y.jsxs("button",{onClick:O,className:ze("text-[10px] px-1.5 rounded-full transition-colors leading-none",g?"text-blue-600 dark:text-blue-400 font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:["unread",H>0&&y.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),y.jsx(OL,{className:"flex-1",children:y.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[P.length===0&&!G&&y.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:M?"Loading…":g?"No unread conversations":"No conversations yet"}),G&&K(G),P.map(K),!g&&C&&y.jsx("div",{ref:q,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:M?"Loading older…":"···"})]})}),y.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[y.jsx(Toe,{socket:d??null,getToken:e}),(F=h.sidebarExtras)==null?void 0:F.call(h),x&&(U?y.jsxs("button",{onClick:()=>location.reload(),title:`This page was built from v${Of}, the server runs v${x} — reload to update`,className:"text-[10px] text-amber-400 hover:text-amber-300 text-center underline decoration-dotted",children:["⚠️ stale page (v",Of," → v",x,") · reload"]}):y.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",x]}))]})]})}function ni(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:Ms(),role:"assistant",blocks:[t]}]}function uI(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:Ms(),role:"assistant",blocks:[i]}]}function W$(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(l=>l.type==="tool_use"&&l.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 Voe(e,t){const[n,r]=b.useState([]),[i,a]=b.useState(!1),[s,l]=b.useState([]),u=b.useRef(t.initialSessionId),d=b.useRef(!1),h=b.useRef(s);h.current=s;const m=b.useRef(t.getToken);m.current=t.getToken;const p=b.useRef(t.onNewSession);p.current=t.onNewSession;const g=b.useRef(t.onDirectivesChanged);g.current=t.onDirectivesChanged;const w=b.useRef(t.onParticipantsChanged);w.current=t.onParticipantsChanged;const x=b.useRef(t.onEvent);x.current=t.onEvent;const E=b.useRef(e);E.current=e;const _=b.useCallback(P=>P!=null&&P===u.current,[]),k=b.useCallback(async()=>{var G;const P=u.current;if(P)try{const X=await(await Ll(`/api/sessions/${P}/messages`,m.current)).json();r(nL(X)),a(!!X.busy),(G=w.current)==null||G.call(w,Array.isArray(X.participants)&&X.participants.length>1)}catch{}},[]);b.useEffect(()=>{if(!e)return;const P=e.on(G=>{var X,U,K,F,V,$;(X=x.current)==null||X.call(x,G);const q=G;if(q.type==="compact_marker")return _(q.sessionId)?r(L=>[...L,{id:Ms(),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(L=>ni(L,{type:"thinking",text:G.text})):void 0;case"text_delta":return _(G.sessionId)?r(L=>ni(L,{type:"text",text:G.text})):void 0;case"tool_use":return _(G.sessionId)?r(L=>ni(L,{type:"tool_use",tool:G.tool,toolUseId:G.toolUseId,input:G.input})):void 0;case"tool_use_input":return _(G.sessionId)?r(L=>W$(L,G.toolUseId,G.input)):void 0;case"tool_result":return _(G.sessionId)?r(L=>ni(L,{type:"tool_result",toolUseId:G.toolUseId,output:G.output})):void 0;case"tool_result_image":return _(G.sessionId)?r(L=>ni(L,{type:"image",src:G.dataUrl})):void 0;case"permission_request":return _(G.sessionId)?r(L=>ni(L,{type:"permission_request",id:G.id,tool:G.tool,input:G.input})):void 0;case"question_request":return _(G.sessionId)?r(L=>ni(L,{type:"question_request",id:G.id,questions:G.questions})):void 0;case"directives":return d.current?(U=g.current)==null?void 0:U.call(g,G.directives):void 0;case"session_id":return!d.current||u.current?void 0:(u.current=G.sessionId,(K=p.current)==null?void 0:K.call(p,G.sessionId));case"forked":return G.sourceSessionId!==u.current?void 0:(u.current=G.sessionId,(F=p.current)==null?void 0:F.call(p,G.sessionId));case"session_busy":G.sessionId===u.current&&a(G.busy);return;case"session_stream":return G.sessionId!==u.current?void 0:Woe(r,G.event);case"session_messages_changed":G.sessionId===u.current&&k();return;case"done":{if(G.sessionId!==u.current)return;G.stopReason==="max_turns_reached"&&r(W=>ni(W,{type:"text",text:`
|
|
1908
1908
|
|
|
1909
1909
|
---
|
|
1910
1910
|
⚠️ Reached the maximum number of steps for this turn. Send "continue" to pick up where I left off.`})),(V=p.current)==null||V.call(p,G.sessionId);const L=h.current;if(L.length>0){const W=L.join(`
|
package/dist/client/index.html
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
14
14
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
15
15
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet" />
|
|
16
|
-
<script type="module" crossorigin src="/assets/index-
|
|
16
|
+
<script type="module" crossorigin src="/assets/index-CXVwnqSZ.js"></script>
|
|
17
17
|
<link rel="stylesheet" crossorigin href="/assets/index-BLAQpfJ9.css">
|
|
18
18
|
</head>
|
|
19
19
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shraga",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.140",
|
|
4
4
|
"description": "The teammate you delegate coding to — a self-hostable, multi-user AI coding agent web UI (Claude Code, with a pluggable engine seam).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
package/src/server/data-sync.ts
CHANGED
|
@@ -12,6 +12,9 @@ const DEPLOYMENT_ID_FILE = '.deployment-id';
|
|
|
12
12
|
const AUDIT_DIR = 'audit';
|
|
13
13
|
const NOT_AUDIT = ['--', '.', `:(exclude)${AUDIT_DIR}`];
|
|
14
14
|
|
|
15
|
+
/** A git conflict-marker line (start or end of a hunk). */
|
|
16
|
+
const CONFLICT_MARKER = /^(<{7}|>{7}) /m;
|
|
17
|
+
|
|
15
18
|
/** How long the LLM commit-message call may take before we fall back (ms). */
|
|
16
19
|
const COMMIT_MSG_TIMEOUT_MS = 60_000;
|
|
17
20
|
/** Warn if the push latch has been held longer than this — the 2026-08 outage's signature was silence. */
|
|
@@ -437,12 +440,60 @@ export class DataSync {
|
|
|
437
440
|
}
|
|
438
441
|
}
|
|
439
442
|
|
|
440
|
-
if (dirty) await this.
|
|
441
|
-
console.error(`${TAG} Stash pop failed — local changes may be stuck in git stash:`, (err as Error).message);
|
|
442
|
-
});
|
|
443
|
+
if (dirty) await this.popStash();
|
|
443
444
|
this.rebuildLog().catch(() => {});
|
|
444
445
|
}
|
|
445
446
|
|
|
447
|
+
/** Restore the pre-pull stash. A failed pop used to be logged and left as-is: the worktree kept conflict
|
|
448
|
+
* markers and an unmerged index, every later flush's commit failed silently, and a `git add` of a marked
|
|
449
|
+
* file pushed the markers upstream (2026-09-23 on feedox, twice: para-links.json and push-tokens.json
|
|
450
|
+
* unparseable, para delivery + mobile push dead). The stash holds THIS instance's live writes, so on a
|
|
451
|
+
* conflict its side wins; the index is cleared, and the stash is dropped only when nothing in it is lost. */
|
|
452
|
+
private async popStash(): Promise<void> {
|
|
453
|
+
try {
|
|
454
|
+
await this.git('stash', 'pop');
|
|
455
|
+
return;
|
|
456
|
+
} catch (err) {
|
|
457
|
+
console.error(`${TAG} Stash pop failed, repairing the worktree:`, (err as Error).message);
|
|
458
|
+
}
|
|
459
|
+
const conflicted = await this.getConflictedFiles().catch(() => [] as string[]);
|
|
460
|
+
for (const f of conflicted) {
|
|
461
|
+
// In a stash apply, "theirs" is the stash (local writes). A path the stash deleted has no theirs side.
|
|
462
|
+
await this.git('checkout', '--theirs', '--', f).catch(async () => {
|
|
463
|
+
await this.git('checkout', '--ours', '--', f).catch(e =>
|
|
464
|
+
console.error(`${TAG} Could not take either side of ${f}:`, (e as Error).message));
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
// Clear the unmerged index (worktree kept) so later commits are not refused.
|
|
468
|
+
await this.git('reset', '-q').catch(e => console.error(`${TAG} Index reset after failed pop failed:`, (e as Error).message));
|
|
469
|
+
const marked = await this.filesWithMarkers(conflicted);
|
|
470
|
+
const lostUntracked = await this.stashUntrackedMissing();
|
|
471
|
+
const kept = marked.length > 0 || lostUntracked.length > 0;
|
|
472
|
+
if (!kept) {
|
|
473
|
+
await this.git('stash', 'drop').catch(e => console.error(`${TAG} Stash drop failed:`, (e as Error).message));
|
|
474
|
+
}
|
|
475
|
+
console.error(`${TAG} Stash pop conflict repaired: kept local side of ${conflicted.length} file(s)${conflicted.length ? ` (${conflicted.join(', ')})` : ''}${kept ? `; stash KEPT — markers: [${marked.join(', ')}], unrestored untracked: [${lostUntracked.join(', ')}]` : '; stash dropped'}`);
|
|
476
|
+
await this.alertOnce('stash-pop', [...conflicted, ...marked, ...lostUntracked].join('\n'),
|
|
477
|
+
`⚠️ Data sync: a pre-pull stash failed to re-apply. Kept this instance's version of: ${conflicted.join(', ') || '(none)'}.` +
|
|
478
|
+
(kept ? `\n\nNOT fully repaired — stash kept. Markers in: ${marked.join(', ') || '-'}; untracked not restored: ${lostUntracked.join(', ') || '-'}. Inspect: \`cd data && git stash show -p --include-untracked\`` : ''),
|
|
479
|
+
).catch(e => console.warn(`${TAG} Stash-pop notify failed:`, (e as Error).message));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** Worktree files (of the given paths) that still carry conflict markers. */
|
|
483
|
+
private async filesWithMarkers(files: string[]): Promise<string[]> {
|
|
484
|
+
const out: string[] = [];
|
|
485
|
+
for (const f of files) {
|
|
486
|
+
try { if (CONFLICT_MARKER.test(readFileSync(path.join(DATA_DIR, f), 'utf-8'))) out.push(f); } catch { /* missing = no markers */ }
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** Untracked files saved in stash@{0} that are not on disk (a pop that refused them: "already exists"). */
|
|
492
|
+
private async stashUntrackedMissing(): Promise<string[]> {
|
|
493
|
+
const listed = await this.git('ls-tree', '-r', '--name-only', 'stash@{0}^3').catch(() => '');
|
|
494
|
+
return listed.split('\n').filter(Boolean).filter(f => !existsSync(path.join(DATA_DIR, f)));
|
|
495
|
+
}
|
|
496
|
+
|
|
446
497
|
trackWrite(relativePath: string): void {
|
|
447
498
|
if (!this.isEnabled() || !this.ready) return;
|
|
448
499
|
this.pending.add(relativePath);
|
|
@@ -507,8 +558,10 @@ export class DataSync {
|
|
|
507
558
|
if (!status.trim()) return;
|
|
508
559
|
|
|
509
560
|
if (await this.guardMassDeletions('flush')) return;
|
|
561
|
+
if (await this.guardConflictMarkers()) return;
|
|
510
562
|
const msg = await this.generateCommitMessage(files);
|
|
511
|
-
await this.git('commit', '-m', auditHead ? `${msg}\n\naudit-head: ${auditHead}` : msg).catch(
|
|
563
|
+
await this.git('commit', '-m', auditHead ? `${msg}\n\naudit-head: ${auditHead}` : msg).catch(err =>
|
|
564
|
+
console.error(`${TAG} Commit failed — nothing from this flush is synced:`, (err as Error).message));
|
|
512
565
|
const ahead = await this.git('rev-list', '--count', `origin/${this.options.branch}..HEAD`).catch(() => '0');
|
|
513
566
|
if (parseInt(ahead.trim()) === 0) return;
|
|
514
567
|
await this.git('push', 'origin', this.options.branch).catch(async (err) => {
|
|
@@ -823,6 +876,33 @@ export class DataSync {
|
|
|
823
876
|
return runTextQuery({ prompt, model, maxTurns: 1, abortController });
|
|
824
877
|
}
|
|
825
878
|
|
|
879
|
+
/** Never commit a conflict marker: unstage marked files (they stay on disk for repair) and alert.
|
|
880
|
+
* An unmerged index blocks the whole commit, so that case is reported rather than committed around.
|
|
881
|
+
* Returns true when nothing is left to commit. */
|
|
882
|
+
private async guardConflictMarkers(): Promise<boolean> {
|
|
883
|
+
const unmerged = await this.getConflictedFiles().catch(() => [] as string[]);
|
|
884
|
+
if (unmerged.length) {
|
|
885
|
+
console.error(`${TAG} 🚫 Unmerged paths in data/ — commit skipped: ${unmerged.join(', ')}`);
|
|
886
|
+
await this.alertOnce('unmerged', unmerged.join('\n'),
|
|
887
|
+
`🚫 Data sync is not committing: unmerged paths in data/: ${unmerged.join(', ')}. Resolve them (keep both sides), then \`git add\` them.`,
|
|
888
|
+
).catch(e => console.warn(`${TAG} Unmerged notify failed:`, (e as Error).message));
|
|
889
|
+
return true;
|
|
890
|
+
}
|
|
891
|
+
this.clearAlert('unmerged');
|
|
892
|
+
// Only what this commit stages: grepping the whole index each flush would scan GBs on a real deployment.
|
|
893
|
+
const changed = (await this.git('diff', '--cached', '--name-only', '--diff-filter=AM').catch(() => '')).split('\n').filter(Boolean);
|
|
894
|
+
const staged = changed.length
|
|
895
|
+
? (await this.git('grep', '--cached', '-l', '-E', '^(<{7}|>{7}) ', '--', ...changed).catch(() => '')).split('\n').filter(Boolean)
|
|
896
|
+
: [];
|
|
897
|
+
if (!staged.length) { this.clearAlert('markers'); return false; }
|
|
898
|
+
console.error(`${TAG} 🚫 Conflict markers staged — unstaged, not committed: ${staged.join(', ')}`);
|
|
899
|
+
await this.git('reset', '-q', 'HEAD', '--', ...staged).catch(e => console.error(`${TAG} Unstaging marked files failed:`, (e as Error).message));
|
|
900
|
+
await this.alertOnce('markers', staged.join('\n'),
|
|
901
|
+
`🚫 Data sync refused to commit file(s) containing git conflict markers: ${staged.join(', ')}. They are left on disk unsynced; fix their content.`,
|
|
902
|
+
).catch(e => console.warn(`${TAG} Markers notify failed:`, (e as Error).message));
|
|
903
|
+
return !(await this.git('diff', '--cached', '--name-only').catch(() => '')).trim();
|
|
904
|
+
}
|
|
905
|
+
|
|
826
906
|
private async getConflictedFiles(): Promise<string[]> {
|
|
827
907
|
const output = await this.git('diff', '--name-only', '--diff-filter=U');
|
|
828
908
|
return output.split('\n').map(l => l.trim()).filter(Boolean);
|
|
@@ -27,6 +27,7 @@ import { claudeAccountDir, applyClaudeAccount, claudeForcesSubscription, claudeA
|
|
|
27
27
|
import { buildAgentEnv, builtinTools, filterMcpServers, allowsEscalate, allowsInternalToken, allowsShare, SHARE_TOOL_ID, SENSITIVE_PATH_PATTERNS } from '../security/enforce.ts';
|
|
28
28
|
import { escalateMcpServer } from '../security/escalate.ts';
|
|
29
29
|
import { shareMcpServer } from '../share-file.ts';
|
|
30
|
+
import { jobsMcpServer, JOBS_TOOL_IDS } from '../jobs-mcp.ts';
|
|
30
31
|
const IMMUTABLE_SYSTEM_PROMPT = readFileSync(path.resolve(import.meta.dirname, '../../../defaults/system-prompt.md'), 'utf-8');
|
|
31
32
|
const DEFAULT_USER_PROMPT = `You are a helpful assistant with access to MCP tools.`;
|
|
32
33
|
const DEFAULT_ALLOWED_TOOLS = ['Read', 'Edit', 'Bash', 'WebSearch', 'Glob', 'LS', 'ToolSearch'];
|
|
@@ -530,6 +531,15 @@ export class ClaudeCodeEngine implements AgentEngine {
|
|
|
530
531
|
options['mcpServers'] = { ...(options['mcpServers'] as object | undefined), [server.name]: server };
|
|
531
532
|
options['allowedTools'] = [...allowedTools, SHARE_TOOL_ID];
|
|
532
533
|
}
|
|
534
|
+
// Durable background jobs (in-process, like share_file): server-owned children that outlive the
|
|
535
|
+
// turn, the CLI process, and the bg-wait budget, with wake-on-exit (background-jobs.ts). Only
|
|
536
|
+
// where the profile grants Bash — job_start is arbitrary shell — and only for a real session id
|
|
537
|
+
// (wake reports need a session to land in).
|
|
538
|
+
if (opts.sessionId && (available === 'all' || available.includes('Bash'))) {
|
|
539
|
+
const server = jobsMcpServer({ sessionId: opts.sessionId, uid: opts.uid, userEmail: opts.userEmail, cwd });
|
|
540
|
+
options['mcpServers'] = { ...(options['mcpServers'] as object | undefined), [server.name]: server };
|
|
541
|
+
options['allowedTools'] = [...((options['allowedTools'] as string[] | undefined) ?? allowedTools), ...JOBS_TOOL_IDS];
|
|
542
|
+
}
|
|
533
543
|
|
|
534
544
|
const mcpNames = mcpServers ? Object.keys(mcpServers) : [];
|
|
535
545
|
const activeModel = (options['model'] as string) || 'default';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// In-process MCP server exposing the durable background-job registry (background-jobs.ts) to the
|
|
2
|
+
// claude-code engine.
|
|
3
|
+
//
|
|
4
|
+
// Why this exists: on the claude-code engine the model's only two ways to run long work were both
|
|
5
|
+
// broken. `Bash{run_in_background}` jobs live inside the CLI process, and the engine bounds the
|
|
6
|
+
// bg wait (BG_TASK_MAX_WAIT_MS) — a job longer than that dies with the CLI, silently. Folklore
|
|
7
|
+
// `nohup … &` survives, but nothing wakes the session when it exits, so the outcome lands nowhere
|
|
8
|
+
// (a headless worker "finished" and nobody checked its deliverable — the viral-quickcut incident).
|
|
9
|
+
// The server-owned registry solves exactly this (detached children, wake-on-exit via wake.ts,
|
|
10
|
+
// restart adoption), and the agentx engine already mounts it as Shell/ShellOutput/… tools. This
|
|
11
|
+
// file is the same registry behind SDK MCP tools, the way share-file.ts mounts `share_file`.
|
|
12
|
+
import { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
13
|
+
import { z } from 'zod/v4';
|
|
14
|
+
import { sessionJobRegistry, type JobOwner } from './background-jobs.ts';
|
|
15
|
+
import { JOBS_SERVER } from './security/enforce.ts';
|
|
16
|
+
/** Tool ids as the SDK exposes them, for allowedTools. */
|
|
17
|
+
export const JOBS_TOOL_IDS = ['job_start', 'job_status', 'job_output', 'job_kill', 'job_list']
|
|
18
|
+
.map((t) => `mcp__${JOBS_SERVER}__${t}`);
|
|
19
|
+
|
|
20
|
+
const text = (t: string, isError = false) => ({ content: [{ type: 'text' as const, text: t }], ...(isError ? { isError: true } : {}) });
|
|
21
|
+
|
|
22
|
+
/** In-process MCP server over the session's view of the job registry. Mount per turn (the view is
|
|
23
|
+
* stateless); the jobs belong to the server and outlive the turn, the CLI, and a server restart. */
|
|
24
|
+
export function jobsMcpServer(owner: JobOwner) {
|
|
25
|
+
const reg = sessionJobRegistry(owner);
|
|
26
|
+
return createSdkMcpServer({
|
|
27
|
+
name: JOBS_SERVER,
|
|
28
|
+
version: '1.0.0',
|
|
29
|
+
tools: [
|
|
30
|
+
tool(
|
|
31
|
+
'job_start',
|
|
32
|
+
'Run a shell command as a DURABLE background job, owned by the server: it survives the end of this turn (and even a server restart), and when it exits you are woken with its outcome — never use `nohup …/… &` for long work, and never launch work longer than ~10 minutes with Bash run_in_background (it is killed when the turn\'s wait budget ends). After starting one you may end your turn; you will be woken. A headless worker (`claude -p …`) MUST be launched this way.',
|
|
33
|
+
{ command: z.string().min(1).describe('Shell command line. Runs detached, in the session cwd; stdout+stderr go to the job log.') },
|
|
34
|
+
async ({ command }) => {
|
|
35
|
+
try {
|
|
36
|
+
const id = await reg.start(command);
|
|
37
|
+
return text(`Started background job ${id}. It keeps running after this turn ends; you will be woken when it exits. Check it with job_status/job_output. Its exit is NOT completion — on wake, verify the job\'s deliverable itself.`);
|
|
38
|
+
} catch (e) { return text(`job_start failed: ${(e as Error).message}`, true); }
|
|
39
|
+
},
|
|
40
|
+
),
|
|
41
|
+
tool(
|
|
42
|
+
'job_status',
|
|
43
|
+
'Status of one background job (running/exited + exit code). Returns no output; a finished job still wakes you later unless you read job_output.',
|
|
44
|
+
{ id: z.string().min(1) },
|
|
45
|
+
async ({ id }) => {
|
|
46
|
+
const s = reg.status(id);
|
|
47
|
+
return s ? text(JSON.stringify(s)) : text(`no such job in this session: ${id}`, true);
|
|
48
|
+
},
|
|
49
|
+
),
|
|
50
|
+
tool(
|
|
51
|
+
'job_output',
|
|
52
|
+
'Tail of a background job\'s log. Reading a FINISHED job\'s output marks it observed (no follow-up wake) — so only read it when you will act on the result now.',
|
|
53
|
+
{ id: z.string().min(1) },
|
|
54
|
+
async ({ id }) => {
|
|
55
|
+
const out = reg.output(id);
|
|
56
|
+
return out == null ? text(`no such job in this session: ${id}`, true) : text(out || '(no output yet)');
|
|
57
|
+
},
|
|
58
|
+
),
|
|
59
|
+
tool(
|
|
60
|
+
'job_kill',
|
|
61
|
+
'Kill a background job (its whole process group).',
|
|
62
|
+
{ id: z.string().min(1) },
|
|
63
|
+
async ({ id }) => (reg.kill(id) ? text(`killed ${id}`) : text(`no such running job: ${id}`, true)),
|
|
64
|
+
),
|
|
65
|
+
tool(
|
|
66
|
+
'job_list',
|
|
67
|
+
'List this session\'s background jobs.',
|
|
68
|
+
{},
|
|
69
|
+
async () => text(JSON.stringify(reg.list())),
|
|
70
|
+
),
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -43,6 +43,14 @@ export const SHARE_TOOL = 'share_file';
|
|
|
43
43
|
export const SHARE_TOOL_ID = `mcp__${SHARE_SERVER}__${SHARE_TOOL}`;
|
|
44
44
|
export const allowsShare = (p: Pick<Profile, 'tools'>) => p.tools.includes('*');
|
|
45
45
|
|
|
46
|
+
/** In-process MCP server carrying the durable background-job tools (jobs-mcp.ts). `job_start` runs
|
|
47
|
+
* arbitrary shell, so it is exactly as powerful as Bash — gate it the same way. */
|
|
48
|
+
export const JOBS_SERVER = 'jobs';
|
|
49
|
+
export const allowsJobs = (p: Pick<Profile, 'tools' | 'mcps'>) => {
|
|
50
|
+
const b = builtinTools(p);
|
|
51
|
+
return b === 'all' || b.includes('Bash');
|
|
52
|
+
};
|
|
53
|
+
|
|
46
54
|
/** `escalate` is opt-in by name (reply-only). `*` profiles don't get it: they can act, not just ask. */
|
|
47
55
|
export const allowsEscalate = (p: Pick<Profile, 'tools'>) => p.tools.includes(ESCALATE_TOOL);
|
|
48
56
|
export const allowsMcpServer = (p: Pick<Profile, 'mcps'>, server: string) => p.mcps.includes('*') || p.mcps.includes(server);
|
|
@@ -66,6 +74,7 @@ export function profileAllowsTool(p: Pick<Profile, 'tools' | 'mcps'>, tool: stri
|
|
|
66
74
|
const server = tool.slice(5).split('__')[0];
|
|
67
75
|
if (server === ESCALATE_SERVER) return allowsEscalate(p);
|
|
68
76
|
if (server === SHARE_SERVER) return allowsShare(p);
|
|
77
|
+
if (server === JOBS_SERVER) return allowsJobs(p);
|
|
69
78
|
return allowsMcpServer(p, server) || p.tools.includes(tool);
|
|
70
79
|
}
|
|
71
80
|
const b = builtinTools(p);
|