@damn-dev/cli 0.9.14 → 0.9.17

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.
@@ -57,7 +57,7 @@ Please change the parent <Route path="${w}"> to <Route path="${w==="/"?"*":`${w}
57
57
  `)},KF=function(){var e=parseInt(document.body.getAttribute(Md)||"0",10);return isFinite(e)?e:0},$oe=function(){y.useEffect(function(){return document.body.setAttribute(Md,(KF()+1).toString()),function(){var e=KF()-1;e<=0?document.body.removeAttribute(Md):document.body.setAttribute(Md,e.toString())}},[])},Voe=function(e){var t=e.noRelative,n=e.noImportant,s=e.gapMode,i=s===void 0?"margin":s;$oe();var a=y.useMemo(function(){return Loe(i)},[i]);return y.createElement(Boe,{styles:zoe(a,!t,i,n?"":"!important")})},W2=!1;if(typeof window<"u")try{var Ag=Object.defineProperty({},"passive",{get:function(){return W2=!0,!0}});window.addEventListener("test",Ag,Ag),window.removeEventListener("test",Ag,Ag)}catch{W2=!1}var ld=W2?{passive:!1}:!1,Uoe=function(e){return e.tagName==="TEXTAREA"},GL=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Uoe(e)&&n[t]==="visible")},Hoe=function(e){return GL(e,"overflowY")},Woe=function(e){return GL(e,"overflowX")},YF=function(e,t){var n=t.ownerDocument,s=t;do{typeof ShadowRoot<"u"&&s instanceof ShadowRoot&&(s=s.host);var i=KL(e,s);if(i){var a=YL(e,s),o=a[1],l=a[2];if(o>l)return!0}s=s.parentNode}while(s&&s!==n.body);return!1},qoe=function(e){var t=e.scrollTop,n=e.scrollHeight,s=e.clientHeight;return[t,n,s]},Goe=function(e){var t=e.scrollLeft,n=e.scrollWidth,s=e.clientWidth;return[t,n,s]},KL=function(e,t){return e==="v"?Hoe(t):Woe(t)},YL=function(e,t){return e==="v"?qoe(t):Goe(t)},Koe=function(e,t){return e==="h"&&t==="rtl"?-1:1},Yoe=function(e,t,n,s,i){var a=Koe(e,window.getComputedStyle(t).direction),o=a*s,l=n.target,c=t.contains(l),d=!1,f=o>0,p=0,m=0;do{if(!l)break;var g=YL(e,l),b=g[0],_=g[1],w=g[2],A=_-w-a*b;(b||A)&&KL(e,l)&&(p+=A,m+=b);var S=l.parentNode;l=S&&S.nodeType===Node.DOCUMENT_FRAGMENT_NODE?S.host:S}while(!c&&l!==document.body||c&&(t.contains(l)||t===l));return(f&&Math.abs(p)<1||!f&&Math.abs(m)<1)&&(d=!0),d},Sg=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},QF=function(e){return[e.deltaX,e.deltaY]},XF=function(e){return e&&"current"in e?e.current:e},Qoe=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Xoe=function(e){return`
58
58
  .block-interactivity-`.concat(e,` {pointer-events: none;}
59
59
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
60
- `)},Joe=0,cd=[];function Zoe(e){var t=y.useRef([]),n=y.useRef([0,0]),s=y.useRef(),i=y.useState(Joe++)[0],a=y.useState(qL)[0],o=y.useRef(e);y.useEffect(function(){o.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var _=yoe([e.lockRef.current],(e.shards||[]).map(XF),!0).filter(Boolean);return _.forEach(function(w){return w.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),_.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var l=y.useCallback(function(_,w){if("touches"in _&&_.touches.length===2||_.type==="wheel"&&_.ctrlKey)return!o.current.allowPinchZoom;var A=Sg(_),S=n.current,C="deltaX"in _?_.deltaX:S[0]-A[0],E="deltaY"in _?_.deltaY:S[1]-A[1],k,T=_.target,F=Math.abs(C)>Math.abs(E)?"h":"v";if("touches"in _&&F==="h"&&T.type==="range")return!1;var M=window.getSelection(),I=M&&M.anchorNode,R=I?I===T||I.contains(T):!1;if(R)return!1;var H=YF(F,T);if(!H)return!0;if(H?k=F:(k=F==="v"?"h":"v",H=YF(F,T)),!H)return!1;if(!s.current&&"changedTouches"in _&&(C||E)&&(s.current=k),!k)return!0;var V=s.current||k;return Yoe(V,w,_,V==="h"?C:E)},[]),c=y.useCallback(function(_){var w=_;if(!(!cd.length||cd[cd.length-1]!==a)){var A="deltaY"in w?QF(w):Sg(w),S=t.current.filter(function(k){return k.name===w.type&&(k.target===w.target||w.target===k.shadowParent)&&Qoe(k.delta,A)})[0];if(S&&S.should){w.cancelable&&w.preventDefault();return}if(!S){var C=(o.current.shards||[]).map(XF).filter(Boolean).filter(function(k){return k.contains(w.target)}),E=C.length>0?l(w,C[0]):!o.current.noIsolation;E&&w.cancelable&&w.preventDefault()}}},[]),d=y.useCallback(function(_,w,A,S){var C={name:_,delta:w,target:A,should:S,shadowParent:ele(A)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(E){return E!==C})},1)},[]),f=y.useCallback(function(_){n.current=Sg(_),s.current=void 0},[]),p=y.useCallback(function(_){d(_.type,QF(_),_.target,l(_,e.lockRef.current))},[]),m=y.useCallback(function(_){d(_.type,Sg(_),_.target,l(_,e.lockRef.current))},[]);y.useEffect(function(){return cd.push(a),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",c,ld),document.addEventListener("touchmove",c,ld),document.addEventListener("touchstart",f,ld),function(){cd=cd.filter(function(_){return _!==a}),document.removeEventListener("wheel",c,ld),document.removeEventListener("touchmove",c,ld),document.removeEventListener("touchstart",f,ld)}},[]);var g=e.removeScrollBar,b=e.inert;return y.createElement(y.Fragment,null,b?y.createElement(a,{styles:Xoe(i)}):null,g?y.createElement(Voe,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ele(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const tle=Eoe(WL,Zoe);var Sm=y.forwardRef(function(e,t){return y.createElement(wv,Fa({},e,{ref:t,sideCar:tle}))});Sm.classNames=wv.classNames;var nle=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ud=new WeakMap,Cg=new WeakMap,jg={},Nw=0,QL=function(e){return e&&(e.host||QL(e.parentNode))},sle=function(e,t){return t.map(function(n){if(e.contains(n))return n;var s=QL(n);return s&&e.contains(s)?s:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},ile=function(e,t,n,s){var i=sle(t,Array.isArray(e)?e:[e]);jg[n]||(jg[n]=new WeakMap);var a=jg[n],o=[],l=new Set,c=new Set(i),d=function(p){!p||l.has(p)||(l.add(p),d(p.parentNode))};i.forEach(d);var f=function(p){!p||c.has(p)||Array.prototype.forEach.call(p.children,function(m){if(l.has(m))f(m);else try{var g=m.getAttribute(s),b=g!==null&&g!=="false",_=(ud.get(m)||0)+1,w=(a.get(m)||0)+1;ud.set(m,_),a.set(m,w),o.push(m),_===1&&b&&Cg.set(m,!0),w===1&&m.setAttribute(n,"true"),b||m.setAttribute(s,"true")}catch(A){console.error("aria-hidden: cannot operate on ",m,A)}})};return f(t),l.clear(),Nw++,function(){o.forEach(function(p){var m=ud.get(p)-1,g=a.get(p)-1;ud.set(p,m),a.set(p,g),m||(Cg.has(p)||p.removeAttribute(s),Cg.delete(p)),g||p.removeAttribute(n)}),Nw--,Nw||(ud=new WeakMap,ud=new WeakMap,Cg=new WeakMap,jg={})}},Av=function(e,t,n){n===void 0&&(n="data-aria-hidden");var s=Array.from(Array.isArray(e)?e:[e]),i=nle(e);return i?(s.push.apply(s,Array.from(i.querySelectorAll("[aria-live], script"))),ile(s,i,n,"aria-hidden")):function(){return null}},Sv="Dialog",[XL]=Wa(Sv),[rle,ha]=XL(Sv),JL=e=>{const{__scopeDialog:t,children:n,open:s,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,l=y.useRef(null),c=y.useRef(null),[d,f]=Fo({prop:s,defaultProp:i??!1,onChange:a,caller:Sv});return r.jsx(rle,{scope:t,triggerRef:l,contentRef:c,contentId:Zi(),titleId:Zi(),descriptionId:Zi(),open:d,onOpenChange:f,onOpenToggle:y.useCallback(()=>f(p=>!p),[f]),modal:o,children:n})};JL.displayName=Sv;var ZL="DialogTrigger",e9=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(ZL,n),a=At(t,i.triggerRef);return r.jsx(lt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":W5(i.open),...s,ref:a,onClick:Oe(e.onClick,i.onOpenToggle)})});e9.displayName=ZL;var U5="DialogPortal",[ale,t9]=XL(U5,{forceMount:void 0}),n9=e=>{const{__scopeDialog:t,forceMount:n,children:s,container:i}=e,a=ha(U5,t);return r.jsx(ale,{scope:t,forceMount:n,children:y.Children.map(s,o=>r.jsx(zr,{present:n||a.open,children:r.jsx(hh,{asChild:!0,container:i,children:o})}))})};n9.displayName=U5;var l0="DialogOverlay",s9=y.forwardRef((e,t)=>{const n=t9(l0,e.__scopeDialog),{forceMount:s=n.forceMount,...i}=e,a=ha(l0,e.__scopeDialog);return a.modal?r.jsx(zr,{present:s||a.open,children:r.jsx(lle,{...i,ref:t})}):null});s9.displayName=l0;var ole=iu("DialogOverlay.RemoveScroll"),lle=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(l0,n);return r.jsx(Sm,{as:ole,allowPinchZoom:!0,shards:[i.contentRef],children:r.jsx(lt.div,{"data-state":W5(i.open),...s,ref:t,style:{pointerEvents:"auto",...s.style}})})}),ru="DialogContent",i9=y.forwardRef((e,t)=>{const n=t9(ru,e.__scopeDialog),{forceMount:s=n.forceMount,...i}=e,a=ha(ru,e.__scopeDialog);return r.jsx(zr,{present:s||a.open,children:a.modal?r.jsx(cle,{...i,ref:t}):r.jsx(ule,{...i,ref:t})})});i9.displayName=ru;var cle=y.forwardRef((e,t)=>{const n=ha(ru,e.__scopeDialog),s=y.useRef(null),i=At(t,n.contentRef,s);return y.useEffect(()=>{const a=s.current;if(a)return Av(a)},[]),r.jsx(r9,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Oe(e.onCloseAutoFocus,a=>{a.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Oe(e.onPointerDownOutside,a=>{const o=a.detail.originalEvent,l=o.button===0&&o.ctrlKey===!0;(o.button===2||l)&&a.preventDefault()}),onFocusOutside:Oe(e.onFocusOutside,a=>a.preventDefault())})}),ule=y.forwardRef((e,t)=>{const n=ha(ru,e.__scopeDialog),s=y.useRef(!1),i=y.useRef(!1);return r.jsx(r9,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{e.onCloseAutoFocus?.(a),a.defaultPrevented||(s.current||n.triggerRef.current?.focus(),a.preventDefault()),s.current=!1,i.current=!1},onInteractOutside:a=>{e.onInteractOutside?.(a),a.defaultPrevented||(s.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=a.target;n.triggerRef.current?.contains(o)&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),r9=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:s,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=e,l=ha(ru,n),c=y.useRef(null),d=At(t,c);return _v(),r.jsxs(r.Fragment,{children:[r.jsx(Am,{asChild:!0,loop:!0,trapped:s,onMountAutoFocus:i,onUnmountAutoFocus:a,children:r.jsx(dh,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":W5(l.open),...o,ref:d,onDismiss:()=>l.onOpenChange(!1)})}),r.jsxs(r.Fragment,{children:[r.jsx(hle,{titleId:l.titleId}),r.jsx(ple,{contentRef:c,descriptionId:l.descriptionId})]})]})}),H5="DialogTitle",a9=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(H5,n);return r.jsx(lt.h2,{id:i.titleId,...s,ref:t})});a9.displayName=H5;var o9="DialogDescription",dle=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(o9,n);return r.jsx(lt.p,{id:i.descriptionId,...s,ref:t})});dle.displayName=o9;var l9="DialogClose",c9=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(l9,n);return r.jsx(lt.button,{type:"button",...s,ref:t,onClick:Oe(e.onClick,()=>i.onOpenChange(!1))})});c9.displayName=l9;function W5(e){return e?"open":"closed"}var u9="DialogTitleWarning",[I8e,d9]=Vae(u9,{contentName:ru,titleName:H5,docsSlug:"dialog"}),hle=({titleId:e})=>{const t=d9(u9),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
60
+ `)},Joe=0,cd=[];function Zoe(e){var t=y.useRef([]),n=y.useRef([0,0]),s=y.useRef(),i=y.useState(Joe++)[0],a=y.useState(qL)[0],o=y.useRef(e);y.useEffect(function(){o.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var _=yoe([e.lockRef.current],(e.shards||[]).map(XF),!0).filter(Boolean);return _.forEach(function(w){return w.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),_.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var l=y.useCallback(function(_,w){if("touches"in _&&_.touches.length===2||_.type==="wheel"&&_.ctrlKey)return!o.current.allowPinchZoom;var A=Sg(_),S=n.current,C="deltaX"in _?_.deltaX:S[0]-A[0],E="deltaY"in _?_.deltaY:S[1]-A[1],k,T=_.target,F=Math.abs(C)>Math.abs(E)?"h":"v";if("touches"in _&&F==="h"&&T.type==="range")return!1;var M=window.getSelection(),I=M&&M.anchorNode,R=I?I===T||I.contains(T):!1;if(R)return!1;var H=YF(F,T);if(!H)return!0;if(H?k=F:(k=F==="v"?"h":"v",H=YF(F,T)),!H)return!1;if(!s.current&&"changedTouches"in _&&(C||E)&&(s.current=k),!k)return!0;var V=s.current||k;return Yoe(V,w,_,V==="h"?C:E)},[]),c=y.useCallback(function(_){var w=_;if(!(!cd.length||cd[cd.length-1]!==a)){var A="deltaY"in w?QF(w):Sg(w),S=t.current.filter(function(k){return k.name===w.type&&(k.target===w.target||w.target===k.shadowParent)&&Qoe(k.delta,A)})[0];if(S&&S.should){w.cancelable&&w.preventDefault();return}if(!S){var C=(o.current.shards||[]).map(XF).filter(Boolean).filter(function(k){return k.contains(w.target)}),E=C.length>0?l(w,C[0]):!o.current.noIsolation;E&&w.cancelable&&w.preventDefault()}}},[]),d=y.useCallback(function(_,w,A,S){var C={name:_,delta:w,target:A,should:S,shadowParent:ele(A)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(E){return E!==C})},1)},[]),f=y.useCallback(function(_){n.current=Sg(_),s.current=void 0},[]),p=y.useCallback(function(_){d(_.type,QF(_),_.target,l(_,e.lockRef.current))},[]),m=y.useCallback(function(_){d(_.type,Sg(_),_.target,l(_,e.lockRef.current))},[]);y.useEffect(function(){return cd.push(a),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",c,ld),document.addEventListener("touchmove",c,ld),document.addEventListener("touchstart",f,ld),function(){cd=cd.filter(function(_){return _!==a}),document.removeEventListener("wheel",c,ld),document.removeEventListener("touchmove",c,ld),document.removeEventListener("touchstart",f,ld)}},[]);var g=e.removeScrollBar,b=e.inert;return y.createElement(y.Fragment,null,b?y.createElement(a,{styles:Xoe(i)}):null,g?y.createElement(Voe,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ele(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const tle=Eoe(WL,Zoe);var Sm=y.forwardRef(function(e,t){return y.createElement(wv,Fa({},e,{ref:t,sideCar:tle}))});Sm.classNames=wv.classNames;var nle=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ud=new WeakMap,Cg=new WeakMap,jg={},Nw=0,QL=function(e){return e&&(e.host||QL(e.parentNode))},sle=function(e,t){return t.map(function(n){if(e.contains(n))return n;var s=QL(n);return s&&e.contains(s)?s:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},ile=function(e,t,n,s){var i=sle(t,Array.isArray(e)?e:[e]);jg[n]||(jg[n]=new WeakMap);var a=jg[n],o=[],l=new Set,c=new Set(i),d=function(p){!p||l.has(p)||(l.add(p),d(p.parentNode))};i.forEach(d);var f=function(p){!p||c.has(p)||Array.prototype.forEach.call(p.children,function(m){if(l.has(m))f(m);else try{var g=m.getAttribute(s),b=g!==null&&g!=="false",_=(ud.get(m)||0)+1,w=(a.get(m)||0)+1;ud.set(m,_),a.set(m,w),o.push(m),_===1&&b&&Cg.set(m,!0),w===1&&m.setAttribute(n,"true"),b||m.setAttribute(s,"true")}catch(A){console.error("aria-hidden: cannot operate on ",m,A)}})};return f(t),l.clear(),Nw++,function(){o.forEach(function(p){var m=ud.get(p)-1,g=a.get(p)-1;ud.set(p,m),a.set(p,g),m||(Cg.has(p)||p.removeAttribute(s),Cg.delete(p)),g||p.removeAttribute(n)}),Nw--,Nw||(ud=new WeakMap,ud=new WeakMap,Cg=new WeakMap,jg={})}},Av=function(e,t,n){n===void 0&&(n="data-aria-hidden");var s=Array.from(Array.isArray(e)?e:[e]),i=nle(e);return i?(s.push.apply(s,Array.from(i.querySelectorAll("[aria-live], script"))),ile(s,i,n,"aria-hidden")):function(){return null}},Sv="Dialog",[XL]=Wa(Sv),[rle,ha]=XL(Sv),JL=e=>{const{__scopeDialog:t,children:n,open:s,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,l=y.useRef(null),c=y.useRef(null),[d,f]=Fo({prop:s,defaultProp:i??!1,onChange:a,caller:Sv});return r.jsx(rle,{scope:t,triggerRef:l,contentRef:c,contentId:Zi(),titleId:Zi(),descriptionId:Zi(),open:d,onOpenChange:f,onOpenToggle:y.useCallback(()=>f(p=>!p),[f]),modal:o,children:n})};JL.displayName=Sv;var ZL="DialogTrigger",e9=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(ZL,n),a=At(t,i.triggerRef);return r.jsx(lt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":W5(i.open),...s,ref:a,onClick:Oe(e.onClick,i.onOpenToggle)})});e9.displayName=ZL;var U5="DialogPortal",[ale,t9]=XL(U5,{forceMount:void 0}),n9=e=>{const{__scopeDialog:t,forceMount:n,children:s,container:i}=e,a=ha(U5,t);return r.jsx(ale,{scope:t,forceMount:n,children:y.Children.map(s,o=>r.jsx(zr,{present:n||a.open,children:r.jsx(hh,{asChild:!0,container:i,children:o})}))})};n9.displayName=U5;var l0="DialogOverlay",s9=y.forwardRef((e,t)=>{const n=t9(l0,e.__scopeDialog),{forceMount:s=n.forceMount,...i}=e,a=ha(l0,e.__scopeDialog);return a.modal?r.jsx(zr,{present:s||a.open,children:r.jsx(lle,{...i,ref:t})}):null});s9.displayName=l0;var ole=iu("DialogOverlay.RemoveScroll"),lle=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(l0,n);return r.jsx(Sm,{as:ole,allowPinchZoom:!0,shards:[i.contentRef],children:r.jsx(lt.div,{"data-state":W5(i.open),...s,ref:t,style:{pointerEvents:"auto",...s.style}})})}),ru="DialogContent",i9=y.forwardRef((e,t)=>{const n=t9(ru,e.__scopeDialog),{forceMount:s=n.forceMount,...i}=e,a=ha(ru,e.__scopeDialog);return r.jsx(zr,{present:s||a.open,children:a.modal?r.jsx(cle,{...i,ref:t}):r.jsx(ule,{...i,ref:t})})});i9.displayName=ru;var cle=y.forwardRef((e,t)=>{const n=ha(ru,e.__scopeDialog),s=y.useRef(null),i=At(t,n.contentRef,s);return y.useEffect(()=>{const a=s.current;if(a)return Av(a)},[]),r.jsx(r9,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Oe(e.onCloseAutoFocus,a=>{a.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Oe(e.onPointerDownOutside,a=>{const o=a.detail.originalEvent,l=o.button===0&&o.ctrlKey===!0;(o.button===2||l)&&a.preventDefault()}),onFocusOutside:Oe(e.onFocusOutside,a=>a.preventDefault())})}),ule=y.forwardRef((e,t)=>{const n=ha(ru,e.__scopeDialog),s=y.useRef(!1),i=y.useRef(!1);return r.jsx(r9,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{e.onCloseAutoFocus?.(a),a.defaultPrevented||(s.current||n.triggerRef.current?.focus(),a.preventDefault()),s.current=!1,i.current=!1},onInteractOutside:a=>{e.onInteractOutside?.(a),a.defaultPrevented||(s.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=a.target;n.triggerRef.current?.contains(o)&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),r9=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:s,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=e,l=ha(ru,n),c=y.useRef(null),d=At(t,c);return _v(),r.jsxs(r.Fragment,{children:[r.jsx(Am,{asChild:!0,loop:!0,trapped:s,onMountAutoFocus:i,onUnmountAutoFocus:a,children:r.jsx(dh,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":W5(l.open),...o,ref:d,onDismiss:()=>l.onOpenChange(!1)})}),r.jsxs(r.Fragment,{children:[r.jsx(hle,{titleId:l.titleId}),r.jsx(ple,{contentRef:c,descriptionId:l.descriptionId})]})]})}),H5="DialogTitle",a9=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(H5,n);return r.jsx(lt.h2,{id:i.titleId,...s,ref:t})});a9.displayName=H5;var o9="DialogDescription",dle=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(o9,n);return r.jsx(lt.p,{id:i.descriptionId,...s,ref:t})});dle.displayName=o9;var l9="DialogClose",c9=y.forwardRef((e,t)=>{const{__scopeDialog:n,...s}=e,i=ha(l9,n);return r.jsx(lt.button,{type:"button",...s,ref:t,onClick:Oe(e.onClick,()=>i.onOpenChange(!1))})});c9.displayName=l9;function W5(e){return e?"open":"closed"}var u9="DialogTitleWarning",[L8e,d9]=Vae(u9,{contentName:ru,titleName:H5,docsSlug:"dialog"}),hle=({titleId:e})=>{const t=d9(u9),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
61
61
 
62
62
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
63
63
 
@@ -186,7 +186,7 @@ I don't engage with bad faith. I don't respond to bait. I escalate anything that
186
186
  Press space again to drop the item in its new position, or press escape to cancel.
187
187
  `},pAe={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function mAe(e){let{announcements:t=pAe,container:n,hiddenTextDescribedById:s,screenReaderInstructions:i=fAe}=e;const{announce:a,announcement:o}=uAe(),l=Wm("DndLiveRegion"),[c,d]=y.useState(!1);if(y.useEffect(()=>{d(!0)},[]),dAe(y.useMemo(()=>({onDragStart(p){let{active:m}=p;a(t.onDragStart({active:m}))},onDragMove(p){let{active:m,over:g}=p;t.onDragMove&&a(t.onDragMove({active:m,over:g}))},onDragOver(p){let{active:m,over:g}=p;a(t.onDragOver({active:m,over:g}))},onDragEnd(p){let{active:m,over:g}=p;a(t.onDragEnd({active:m,over:g}))},onDragCancel(p){let{active:m,over:g}=p;a(t.onDragCancel({active:m,over:g}))}}),[a,t])),!c)return null;const f=be.createElement(be.Fragment,null,be.createElement(lAe,{id:s,value:i.draggable}),be.createElement(cAe,{id:l,announcement:o}));return n?Xr.createPortal(f,n):f}var ns;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(ns||(ns={}));function O0(){}function wR(e,t){return y.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function xAe(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return y.useMemo(()=>[...t].filter(s=>s!=null),[...t])}const ca=Object.freeze({x:0,y:0});function gAe(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function bAe(e,t){const n=D0(e);if(!n)return"0 0";const s={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return s.x+"% "+s.y+"%"}function vAe(e,t){let{data:{value:n}}=e,{data:{value:s}}=t;return n-s}function yAe(e,t){let{data:{value:n}}=e,{data:{value:s}}=t;return s-n}function AR(e){let{left:t,top:n,height:s,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+s},{x:t+i,y:n+s}]}function _Ae(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}const sV=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:s}=e;const i=AR(t),a=[];for(const o of s){const{id:l}=o,c=n.get(l);if(c){const d=AR(c),f=i.reduce((m,g,b)=>m+gAe(d[b],g),0),p=Number((f/4).toFixed(4));a.push({id:l,data:{droppableContainer:o,value:p}})}}return a.sort(vAe)};function wAe(e,t){const n=Math.max(t.top,e.top),s=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-s,l=a-n;if(s<i&&n<a){const c=t.width*t.height,d=e.width*e.height,f=o*l,p=f/(c+d-f);return Number(p.toFixed(4))}return 0}const AAe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:s}=e;const i=[];for(const a of s){const{id:o}=a,l=n.get(o);if(l){const c=wAe(l,t);c>0&&i.push({id:o,data:{droppableContainer:a,value:c}})}}return i.sort(yAe)};function SAe(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function iV(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:ca}function CAe(e){return function(n){for(var s=arguments.length,i=new Array(s>1?s-1:0),a=1;a<s;a++)i[a-1]=arguments[a];return i.reduce((o,l)=>({...o,top:o.top+e*l.y,bottom:o.bottom+e*l.y,left:o.left+e*l.x,right:o.right+e*l.x}),{...n})}}const jAe=CAe(1);function rV(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function NAe(e,t,n){const s=rV(t);if(!s)return e;const{scaleX:i,scaleY:a,x:o,y:l}=s,c=e.left-o-(1-i)*parseFloat(n),d=e.top-l-(1-a)*parseFloat(n.slice(n.indexOf(" ")+1)),f=i?e.width/i:e.width,p=a?e.height/a:e.height;return{width:f,height:p,top:d,right:c+f,bottom:d+p,left:c}}const kAe={ignoreTransform:!1};function wh(e,t){t===void 0&&(t=kAe);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:d,transformOrigin:f}=fi(e).getComputedStyle(e);d&&(n=NAe(n,d,f))}const{top:s,left:i,width:a,height:o,bottom:l,right:c}=n;return{top:s,left:i,width:a,height:o,bottom:l,right:c}}function SR(e){return wh(e,{ignoreTransform:!0})}function EAe(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function FAe(e,t){return t===void 0&&(t=fi(e).getComputedStyle(e)),t.position==="fixed"}function TAe(e,t){t===void 0&&(t=fi(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(i=>{const a=t[i];return typeof a=="string"?n.test(a):!1})}function Qj(e,t){const n=[];function s(i){if(t!=null&&n.length>=t||!i)return n;if(Yj(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!Um(i)||eV(i)||n.includes(i))return n;const a=fi(e).getComputedStyle(i);return i!==e&&TAe(i,a)&&n.push(i),FAe(i,a)?n:s(i.parentNode)}return e?s(e):n}function aV(e){const[t]=Qj(e,1);return t??null}function yA(e){return!sy||!e?null:yh(e)?e:Kj(e)?Yj(e)||e===_h(e).scrollingElement?window:Um(e)?e:null:null}function oV(e){return yh(e)?e.scrollX:e.scrollLeft}function lV(e){return yh(e)?e.scrollY:e.scrollTop}function rC(e){return{x:oV(e),y:lV(e)}}var ws;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(ws||(ws={}));function cV(e){return!sy||!e?!1:e===document.scrollingElement}function uV(e){const t={x:0,y:0},n=cV(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},s={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},i=e.scrollTop<=t.y,a=e.scrollLeft<=t.x,o=e.scrollTop>=s.y,l=e.scrollLeft>=s.x;return{isTop:i,isLeft:a,isBottom:o,isRight:l,maxScroll:s,minScroll:t}}const MAe={x:.2,y:.2};function RAe(e,t,n,s,i){let{top:a,left:o,right:l,bottom:c}=n;s===void 0&&(s=10),i===void 0&&(i=MAe);const{isTop:d,isBottom:f,isLeft:p,isRight:m}=uV(e),g={x:0,y:0},b={x:0,y:0},_={height:t.height*i.y,width:t.width*i.x};return!d&&a<=t.top+_.height?(g.y=ws.Backward,b.y=s*Math.abs((t.top+_.height-a)/_.height)):!f&&c>=t.bottom-_.height&&(g.y=ws.Forward,b.y=s*Math.abs((t.bottom-_.height-c)/_.height)),!m&&l>=t.right-_.width?(g.x=ws.Forward,b.x=s*Math.abs((t.right-_.width-l)/_.width)):!p&&o<=t.left+_.width&&(g.x=ws.Backward,b.x=s*Math.abs((t.left+_.width-o)/_.width)),{direction:g,speed:b}}function DAe(e){if(e===document.scrollingElement){const{innerWidth:a,innerHeight:o}=window;return{top:0,left:0,right:a,bottom:o,width:a,height:o}}const{top:t,left:n,right:s,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:s,bottom:i,width:e.clientWidth,height:e.clientHeight}}function dV(e){return e.reduce((t,n)=>Pd(t,rC(n)),ca)}function OAe(e){return e.reduce((t,n)=>t+oV(n),0)}function PAe(e){return e.reduce((t,n)=>t+lV(n),0)}function hV(e,t){if(t===void 0&&(t=wh),!e)return;const{top:n,left:s,bottom:i,right:a}=t(e);aV(e)&&(i<=0||a<=0||n>=window.innerHeight||s>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const IAe=[["x",["left","right"],OAe],["y",["top","bottom"],PAe]];class Xj{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const s=Qj(n),i=dV(s);this.rect={...t},this.width=t.width,this.height=t.height;for(const[a,o,l]of IAe)for(const c of o)Object.defineProperty(this,c,{get:()=>{const d=l(s),f=i[a]-d;return this.rect[c]+f},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class fp{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var s;return(s=this.target)==null?void 0:s.removeEventListener(...n)})},this.target=t}add(t,n,s){var i;(i=this.target)==null||i.addEventListener(t,n,s),this.listeners.push([t,n,s])}}function LAe(e){const{EventTarget:t}=fi(e);return e instanceof t?e:_h(e)}function _A(e,t){const n=Math.abs(e.x),s=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+s**2)>t:"x"in t&&"y"in t?n>t.x&&s>t.y:"x"in t?n>t.x:"y"in t?s>t.y:!1}var Nr;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Nr||(Nr={}));function CR(e){e.preventDefault()}function BAe(e){e.stopPropagation()}var Ft;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Ft||(Ft={}));const fV={start:[Ft.Space,Ft.Enter],cancel:[Ft.Esc],end:[Ft.Space,Ft.Enter,Ft.Tab]},zAe=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case Ft.Right:return{...n,x:n.x+25};case Ft.Left:return{...n,x:n.x-25};case Ft.Down:return{...n,y:n.y+25};case Ft.Up:return{...n,y:n.y-25}}};class Jj{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new fp(_h(n)),this.windowListeners=new fp(fi(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Nr.Resize,this.handleCancel),this.windowListeners.add(Nr.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Nr.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,s=t.node.current;s&&hV(s),n(ca)}handleKeyDown(t){if(ry(t)){const{active:n,context:s,options:i}=this.props,{keyboardCodes:a=fV,coordinateGetter:o=zAe,scrollBehavior:l="smooth"}=i,{code:c}=t;if(a.end.includes(c)){this.handleEnd(t);return}if(a.cancel.includes(c)){this.handleCancel(t);return}const{collisionRect:d}=s.current,f=d?{x:d.left,y:d.top}:ca;this.referenceCoordinates||(this.referenceCoordinates=f);const p=o(t,{active:n,context:s.current,currentCoordinates:f});if(p){const m=R0(p,f),g={x:0,y:0},{scrollableAncestors:b}=s.current;for(const _ of b){const w=t.code,{isTop:A,isRight:S,isLeft:C,isBottom:E,maxScroll:k,minScroll:T}=uV(_),F=DAe(_),M={x:Math.min(w===Ft.Right?F.right-F.width/2:F.right,Math.max(w===Ft.Right?F.left:F.left+F.width/2,p.x)),y:Math.min(w===Ft.Down?F.bottom-F.height/2:F.bottom,Math.max(w===Ft.Down?F.top:F.top+F.height/2,p.y))},I=w===Ft.Right&&!S||w===Ft.Left&&!C,R=w===Ft.Down&&!E||w===Ft.Up&&!A;if(I&&M.x!==p.x){const H=_.scrollLeft+m.x,V=w===Ft.Right&&H<=k.x||w===Ft.Left&&H>=T.x;if(V&&!m.y){_.scrollTo({left:H,behavior:l});return}V?g.x=_.scrollLeft-H:g.x=w===Ft.Right?_.scrollLeft-k.x:_.scrollLeft-T.x,g.x&&_.scrollBy({left:-g.x,behavior:l});break}else if(R&&M.y!==p.y){const H=_.scrollTop+m.y,V=w===Ft.Down&&H<=k.y||w===Ft.Up&&H>=T.y;if(V&&!m.x){_.scrollTo({top:H,behavior:l});return}V?g.y=_.scrollTop-H:g.y=w===Ft.Down?_.scrollTop-k.y:_.scrollTop-T.y,g.y&&_.scrollBy({top:-g.y,behavior:l});break}}this.handleMove(t,Pd(R0(p,this.referenceCoordinates),g))}}}handleMove(t,n){const{onMove:s}=this.props;t.preventDefault(),s(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}Jj.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:s=fV,onActivation:i}=t,{active:a}=n;const{code:o}=e.nativeEvent;if(s.start.includes(o)){const l=a.activatorNode.current;return l&&e.target!==l?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function jR(e){return!!(e&&"distance"in e)}function NR(e){return!!(e&&"delay"in e)}class Zj{constructor(t,n,s){var i;s===void 0&&(s=LAe(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:a}=t,{target:o}=a;this.props=t,this.events=n,this.document=_h(o),this.documentListeners=new fp(this.document),this.listeners=new fp(s),this.windowListeners=new fp(fi(o)),this.initialCoordinates=(i=D0(a))!=null?i:ca,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:s}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(Nr.Resize,this.handleCancel),this.windowListeners.add(Nr.DragStart,CR),this.windowListeners.add(Nr.VisibilityChange,this.handleCancel),this.windowListeners.add(Nr.ContextMenu,CR),this.documentListeners.add(Nr.Keydown,this.handleKeydown),n){if(s!=null&&s({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(NR(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(jR(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:s,onPending:i}=this.props;i(s,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(Nr.Click,BAe,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Nr.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:s,initialCoordinates:i,props:a}=this,{onMove:o,options:{activationConstraint:l}}=a;if(!i)return;const c=(n=D0(t))!=null?n:ca,d=R0(i,c);if(!s&&l){if(jR(l)){if(l.tolerance!=null&&_A(d,l.tolerance))return this.handleCancel();if(_A(d,l.distance))return this.handleStart()}if(NR(l)&&_A(d,l.tolerance))return this.handleCancel();this.handlePending(l,d);return}t.cancelable&&t.preventDefault(),o(c)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===Ft.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const $Ae={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class eN extends Zj{constructor(t){const{event:n}=t,s=_h(n.target);super(t,$Ae,s)}}eN.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:s}=t;return!n.isPrimary||n.button!==0?!1:(s?.({event:n}),!0)}}];const VAe={move:{name:"mousemove"},end:{name:"mouseup"}};var aC;(function(e){e[e.RightClick=2]="RightClick"})(aC||(aC={}));class UAe extends Zj{constructor(t){super(t,VAe,_h(t.event.target))}}UAe.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:s}=t;return n.button===aC.RightClick?!1:(s?.({event:n}),!0)}}];const wA={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class HAe extends Zj{constructor(t){super(t,wA)}static setup(){return window.addEventListener(wA.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(wA.move.name,t)};function t(){}}}HAe.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:s}=t;const{touches:i}=n;return i.length>1?!1:(s?.({event:n}),!0)}}];var pp;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(pp||(pp={}));var P0;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(P0||(P0={}));function WAe(e){let{acceleration:t,activator:n=pp.Pointer,canScroll:s,draggingRect:i,enabled:a,interval:o=5,order:l=P0.TreeOrder,pointerCoordinates:c,scrollableAncestors:d,scrollableAncestorRects:f,delta:p,threshold:m}=e;const g=GAe({delta:p,disabled:!a}),[b,_]=sAe(),w=y.useRef({x:0,y:0}),A=y.useRef({x:0,y:0}),S=y.useMemo(()=>{switch(n){case pp.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case pp.DraggableRect:return i}},[n,i,c]),C=y.useRef(null),E=y.useCallback(()=>{const T=C.current;if(!T)return;const F=w.current.x*A.current.x,M=w.current.y*A.current.y;T.scrollBy(F,M)},[]),k=y.useMemo(()=>l===P0.TreeOrder?[...d].reverse():d,[l,d]);y.useEffect(()=>{if(!a||!d.length||!S){_();return}for(const T of k){if(s?.(T)===!1)continue;const F=d.indexOf(T),M=f[F];if(!M)continue;const{direction:I,speed:R}=RAe(T,M,S,t,m);for(const H of["x","y"])g[H][I[H]]||(R[H]=0,I[H]=0);if(R.x>0||R.y>0){_(),C.current=T,b(E,o),w.current=R,A.current=I;return}}w.current={x:0,y:0},A.current={x:0,y:0},_()},[t,E,s,_,a,o,JSON.stringify(S),JSON.stringify(g),b,d,k,f,JSON.stringify(m)])}const qAe={x:{[ws.Backward]:!1,[ws.Forward]:!1},y:{[ws.Backward]:!1,[ws.Forward]:!1}};function GAe(e){let{delta:t,disabled:n}=e;const s=M0(t);return Hm(i=>{if(n||!s||!i)return qAe;const a={x:Math.sign(t.x-s.x),y:Math.sign(t.y-s.y)};return{x:{[ws.Backward]:i.x[ws.Backward]||a.x===-1,[ws.Forward]:i.x[ws.Forward]||a.x===1},y:{[ws.Backward]:i.y[ws.Backward]||a.y===-1,[ws.Forward]:i.y[ws.Forward]||a.y===1}}},[n,t,s])}function KAe(e,t){const n=t!=null?e.get(t):void 0,s=n?n.node.current:null;return Hm(i=>{var a;return t==null?null:(a=s??i)!=null?a:null},[s,t])}function YAe(e,t){return y.useMemo(()=>e.reduce((n,s)=>{const{sensor:i}=s,a=i.activators.map(o=>({eventName:o.eventName,handler:t(o.handler,s)}));return[...n,...a]},[]),[e,t])}var Wp;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Wp||(Wp={}));var oC;(function(e){e.Optimized="optimized"})(oC||(oC={}));const kR=new Map;function QAe(e,t){let{dragging:n,dependencies:s,config:i}=t;const[a,o]=y.useState(null),{frequency:l,measure:c,strategy:d}=i,f=y.useRef(e),p=w(),m=Hp(p),g=y.useCallback(function(A){A===void 0&&(A=[]),!m.current&&o(S=>S===null?A:S.concat(A.filter(C=>!S.includes(C))))},[m]),b=y.useRef(null),_=Hm(A=>{if(p&&!n)return kR;if(!A||A===kR||f.current!==e||a!=null){const S=new Map;for(let C of e){if(!C)continue;if(a&&a.length>0&&!a.includes(C.id)&&C.rect.current){S.set(C.id,C.rect.current);continue}const E=C.node.current,k=E?new Xj(c(E),E):null;C.rect.current=k,k&&S.set(C.id,k)}return S}return A},[e,a,n,p,c]);return y.useEffect(()=>{f.current=e},[e]),y.useEffect(()=>{p||g()},[n,p]),y.useEffect(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),y.useEffect(()=>{p||typeof l!="number"||b.current!==null||(b.current=setTimeout(()=>{g(),b.current=null},l))},[l,p,g,...s]),{droppableRects:_,measureDroppableContainers:g,measuringScheduled:a!=null};function w(){switch(d){case Wp.Always:return!1;case Wp.BeforeDragging:return n;default:return!n}}}function tN(e,t){return Hm(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function XAe(e,t){return tN(e,t)}function JAe(e){let{callback:t,disabled:n}=e;const s=iy(t),i=y.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:a}=window;return new a(s)},[s,n]);return y.useEffect(()=>()=>i?.disconnect(),[i]),i}function ay(e){let{callback:t,disabled:n}=e;const s=iy(t),i=y.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:a}=window;return new a(s)},[n]);return y.useEffect(()=>()=>i?.disconnect(),[i]),i}function ZAe(e){return new Xj(wh(e),e)}function ER(e,t,n){t===void 0&&(t=ZAe);const[s,i]=y.useState(null);function a(){i(c=>{if(!e)return null;if(e.isConnected===!1){var d;return(d=c??n)!=null?d:null}const f=t(e);return JSON.stringify(c)===JSON.stringify(f)?c:f})}const o=JAe({callback(c){if(e)for(const d of c){const{type:f,target:p}=d;if(f==="childList"&&p instanceof HTMLElement&&p.contains(e)){a();break}}}}),l=ay({callback:a});return la(()=>{a(),e?(l?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(l?.disconnect(),o?.disconnect())},[e]),s}function e2e(e){const t=tN(e);return iV(e,t)}const FR=[];function t2e(e){const t=y.useRef(e),n=Hm(s=>e?s&&s!==FR&&e&&t.current&&e.parentNode===t.current.parentNode?s:Qj(e):FR,[e]);return y.useEffect(()=>{t.current=e},[e]),n}function n2e(e){const[t,n]=y.useState(null),s=y.useRef(e),i=y.useCallback(a=>{const o=yA(a.target);o&&n(l=>l?(l.set(o,rC(o)),new Map(l)):null)},[]);return y.useEffect(()=>{const a=s.current;if(e!==a){o(a);const l=e.map(c=>{const d=yA(c);return d?(d.addEventListener("scroll",i,{passive:!0}),[d,rC(d)]):null}).filter(c=>c!=null);n(l.length?new Map(l):null),s.current=e}return()=>{o(e),o(a)};function o(l){l.forEach(c=>{const d=yA(c);d?.removeEventListener("scroll",i)})}},[i,e]),y.useMemo(()=>e.length?t?Array.from(t.values()).reduce((a,o)=>Pd(a,o),ca):dV(e):ca,[e,t])}function TR(e,t){t===void 0&&(t=[]);const n=y.useRef(null);return y.useEffect(()=>{n.current=null},t),y.useEffect(()=>{const s=e!==ca;s&&!n.current&&(n.current=e),!s&&n.current&&(n.current=null)},[e]),n.current?R0(e,n.current):ca}function s2e(e){y.useEffect(()=>{if(!sy)return;const t=e.map(n=>{let{sensor:s}=n;return s.setup==null?void 0:s.setup()});return()=>{for(const n of t)n?.()}},e.map(t=>{let{sensor:n}=t;return n}))}function i2e(e,t){return y.useMemo(()=>e.reduce((n,s)=>{let{eventName:i,handler:a}=s;return n[i]=o=>{a(o,t)},n},{}),[e,t])}function pV(e){return y.useMemo(()=>e?EAe(e):null,[e])}const MR=[];function r2e(e,t){t===void 0&&(t=wh);const[n]=e,s=pV(n?fi(n):null),[i,a]=y.useState(MR);function o(){a(()=>e.length?e.map(c=>cV(c)?s:new Xj(t(c),c)):MR)}const l=ay({callback:o});return la(()=>{l?.disconnect(),o(),e.forEach(c=>l?.observe(c))},[e]),i}function mV(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Um(t)?t:e}function a2e(e){let{measure:t}=e;const[n,s]=y.useState(null),i=y.useCallback(d=>{for(const{target:f}of d)if(Um(f)){s(p=>{const m=t(f);return p?{...p,width:m.width,height:m.height}:m});break}},[t]),a=ay({callback:i}),o=y.useCallback(d=>{const f=mV(d);a?.disconnect(),f&&a?.observe(f),s(f?t(f):null)},[t,a]),[l,c]=T0(o);return y.useMemo(()=>({nodeRef:l,rect:n,setRef:c}),[n,l,c])}const o2e=[{sensor:eN,options:{}},{sensor:Jj,options:{}}],l2e={current:{}},$b={draggable:{measure:SR},droppable:{measure:SR,strategy:Wp.WhileDragging,frequency:oC.Optimized},dragOverlay:{measure:wh}};class mp extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,s;return(n=(s=this.get(t))==null?void 0:s.node.current)!=null?n:void 0}}const c2e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new mp,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:O0},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:$b,measureDroppableContainers:O0,windowRect:null,measuringScheduled:!1},xV={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:O0,draggableNodes:new Map,over:null,measureDroppableContainers:O0},qm=y.createContext(xV),gV=y.createContext(c2e);function u2e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new mp}}}function d2e(e,t){switch(t.type){case ns.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case ns.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case ns.DragEnd:case ns.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case ns.RegisterDroppable:{const{element:n}=t,{id:s}=n,i=new mp(e.droppable.containers);return i.set(s,n),{...e,droppable:{...e.droppable,containers:i}}}case ns.SetDroppableDisabled:{const{id:n,key:s,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||s!==a.key)return e;const o=new mp(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case ns.UnregisterDroppable:{const{id:n,key:s}=t,i=e.droppable.containers.get(n);if(!i||s!==i.key)return e;const a=new mp(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function h2e(e){let{disabled:t}=e;const{active:n,activatorEvent:s,draggableNodes:i}=y.useContext(qm),a=M0(s),o=M0(n?.id);return y.useEffect(()=>{if(!t&&!s&&a&&o!=null){if(!ry(a)||document.activeElement===a.target)return;const l=i.get(o);if(!l)return;const{activatorNode:c,node:d}=l;if(!c.current&&!d.current)return;requestAnimationFrame(()=>{for(const f of[c.current,d.current]){if(!f)continue;const p=aAe(f);if(p){p.focus();break}}})}},[s,t,i,o,a]),null}function bV(e,t){let{transform:n,...s}=t;return e!=null&&e.length?e.reduce((i,a)=>a({transform:i,...s}),n):n}function f2e(e){return y.useMemo(()=>({draggable:{...$b.draggable,...e?.draggable},droppable:{...$b.droppable,...e?.droppable},dragOverlay:{...$b.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function p2e(e){let{activeNode:t,measure:n,initialRect:s,config:i=!0}=e;const a=y.useRef(!1),{x:o,y:l}=typeof i=="boolean"?{x:i,y:i}:i;la(()=>{if(!o&&!l||!t){a.current=!1;return}if(a.current||!s)return;const d=t?.node.current;if(!d||d.isConnected===!1)return;const f=n(d),p=iV(f,s);if(o||(p.x=0),l||(p.y=0),a.current=!0,Math.abs(p.x)>0||Math.abs(p.y)>0){const m=aV(d);m&&m.scrollBy({top:p.y,left:p.x})}},[t,o,l,s,n])}const oy=y.createContext({...ca,scaleX:1,scaleY:1});var Tl;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Tl||(Tl={}));const vV=y.memo(function(t){var n,s,i,a;let{id:o,accessibility:l,autoScroll:c=!0,children:d,sensors:f=o2e,collisionDetection:p=AAe,measuring:m,modifiers:g,...b}=t;const _=y.useReducer(d2e,void 0,u2e),[w,A]=_,[S,C]=hAe(),[E,k]=y.useState(Tl.Uninitialized),T=E===Tl.Initialized,{draggable:{active:F,nodes:M,translate:I},droppable:{containers:R}}=w,H=F!=null?M.get(F):null,V=y.useRef({initial:null,translated:null}),K=y.useMemo(()=>{var ln;return F!=null?{id:F,data:(ln=H?.data)!=null?ln:l2e,rect:V}:null},[F,H]),q=y.useRef(null),[$,B]=y.useState(null),[Y,U]=y.useState(null),W=Hp(b,Object.values(b)),O=Wm("DndDescribedBy",o),D=y.useMemo(()=>R.getEnabled(),[R]),Q=f2e(m),{droppableRects:z,measureDroppableContainers:J,measuringScheduled:ee}=QAe(D,{dragging:T,dependencies:[I.x,I.y],config:Q.droppable}),re=KAe(M,F),oe=y.useMemo(()=>Y?D0(Y):null,[Y]),se=Go(),ae=XAe(re,Q.draggable.measure);p2e({activeNode:F!=null?M.get(F):null,config:se.layoutShiftCompensation,initialRect:ae,measure:Q.draggable.measure});const le=ER(re,Q.draggable.measure,ae),ge=ER(re?re.parentElement:null),je=y.useRef({activatorEvent:null,active:null,activeNode:re,collisionRect:null,collisions:null,droppableRects:z,draggableNodes:M,draggingNode:null,draggingNodeRect:null,droppableContainers:R,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),Ee=R.getNodeFor((n=je.current.over)==null?void 0:n.id),de=a2e({measure:Q.dragOverlay.measure}),me=(s=de.nodeRef.current)!=null?s:re,$e=T?(i=de.rect)!=null?i:le:null,nt=!!(de.nodeRef.current&&de.rect),Ae=e2e(nt?null:le),ct=pV(me?fi(me):null),Ut=t2e(T?Ee??re:null),Os=r2e(Ut),qt=bV(g,{transform:{x:I.x-Ae.x,y:I.y-Ae.y,scaleX:1,scaleY:1},activatorEvent:Y,active:K,activeNodeRect:le,containerNodeRect:ge,draggingNodeRect:$e,over:je.current.over,overlayNodeRect:de.rect,scrollableAncestors:Ut,scrollableAncestorRects:Os,windowRect:ct}),Gt=oe?Pd(oe,I):null,on=n2e(Ut),$r=TR(on),fe=TR(on,[le]),Ce=Pd(qt,$r),Ue=$e?jAe($e,qt):null,Ke=K&&Ue?p({active:K,collisionRect:Ue,droppableRects:z,droppableContainers:D,pointerCoordinates:Gt}):null,st=_Ae(Ke,"id"),[Zt,qn]=y.useState(null),Gn=nt?qt:Pd(qt,fe),pn=SAe(Gn,(a=Zt?.rect)!=null?a:null,le),kn=y.useRef(null),yt=y.useCallback((ln,cn)=>{let{sensor:He,options:_t}=cn;if(q.current==null)return;const kt=M.get(q.current);if(!kt)return;const Mt=ln.nativeEvent,Kn=new He({active:q.current,activeNode:kt,event:Mt,options:_t,context:je,onAbort(St){if(!M.get(St))return;const{onDragAbort:en}=W.current,un={id:St};en?.(un),S({type:"onDragAbort",event:un})},onPending(St,Ps,en,un){if(!M.get(St))return;const{onDragPending:Cs}=W.current,lr={id:St,constraint:Ps,initialCoordinates:en,offset:un};Cs?.(lr),S({type:"onDragPending",event:lr})},onStart(St){const Ps=q.current;if(Ps==null)return;const en=M.get(Ps);if(!en)return;const{onDragStart:un}=W.current,or={activatorEvent:Mt,active:{id:Ps,data:en.data,rect:V}};Xr.unstable_batchedUpdates(()=>{un?.(or),k(Tl.Initializing),A({type:ns.DragStart,initialCoordinates:St,active:Ps}),S({type:"onDragStart",event:or}),B(kn.current),U(Mt)})},onMove(St){A({type:ns.DragMove,coordinates:St})},onEnd:Rt(ns.DragEnd),onCancel:Rt(ns.DragCancel)});kn.current=Kn;function Rt(St){return async function(){const{active:en,collisions:un,over:or,scrollAdjustedTranslate:Cs}=je.current;let lr=null;if(en&&Cs){const{cancelDrop:Ko}=W.current;lr={activatorEvent:Mt,active:en,collisions:un,delta:Cs,over:or},St===ns.DragEnd&&typeof Ko=="function"&&await Promise.resolve(Ko(lr))&&(St=ns.DragCancel)}q.current=null,Xr.unstable_batchedUpdates(()=>{A({type:St}),k(Tl.Uninitialized),qn(null),B(null),U(null),kn.current=null;const Ko=St===ns.DragEnd?"onDragEnd":"onDragCancel";if(lr){const cr=W.current[Ko];cr?.(lr),S({type:Ko,event:lr})}})}}},[M]),rr=y.useCallback((ln,cn)=>(He,_t)=>{const kt=He.nativeEvent,Mt=M.get(_t);if(q.current!==null||!Mt||kt.dndKit||kt.defaultPrevented)return;const Kn={active:Mt};ln(He,cn.options,Kn)===!0&&(kt.dndKit={capturedBy:cn.sensor},q.current=_t,yt(He,cn))},[M,yt]),hs=YAe(f,rr);s2e(f),la(()=>{le&&E===Tl.Initializing&&k(Tl.Initialized)},[le,E]),y.useEffect(()=>{const{onDragMove:ln}=W.current,{active:cn,activatorEvent:He,collisions:_t,over:kt}=je.current;if(!cn||!He)return;const Mt={active:cn,activatorEvent:He,collisions:_t,delta:{x:Ce.x,y:Ce.y},over:kt};Xr.unstable_batchedUpdates(()=>{ln?.(Mt),S({type:"onDragMove",event:Mt})})},[Ce.x,Ce.y]),y.useEffect(()=>{const{active:ln,activatorEvent:cn,collisions:He,droppableContainers:_t,scrollAdjustedTranslate:kt}=je.current;if(!ln||q.current==null||!cn||!kt)return;const{onDragOver:Mt}=W.current,Kn=_t.get(st),Rt=Kn&&Kn.rect.current?{id:Kn.id,rect:Kn.rect.current,data:Kn.data,disabled:Kn.disabled}:null,St={active:ln,activatorEvent:cn,collisions:He,delta:{x:kt.x,y:kt.y},over:Rt};Xr.unstable_batchedUpdates(()=>{qn(Rt),Mt?.(St),S({type:"onDragOver",event:St})})},[st]),la(()=>{je.current={activatorEvent:Y,active:K,activeNode:re,collisionRect:Ue,collisions:Ke,droppableRects:z,draggableNodes:M,draggingNode:me,draggingNodeRect:$e,droppableContainers:R,over:Zt,scrollableAncestors:Ut,scrollAdjustedTranslate:Ce},V.current={initial:$e,translated:Ue}},[K,re,Ke,Ue,M,me,$e,z,R,Zt,Ut,Ce]),WAe({...se,delta:I,draggingRect:Ue,pointerCoordinates:Gt,scrollableAncestors:Ut,scrollableAncestorRects:Os});const ar=y.useMemo(()=>({active:K,activeNode:re,activeNodeRect:le,activatorEvent:Y,collisions:Ke,containerNodeRect:ge,dragOverlay:de,draggableNodes:M,droppableContainers:R,droppableRects:z,over:Zt,measureDroppableContainers:J,scrollableAncestors:Ut,scrollableAncestorRects:Os,measuringConfiguration:Q,measuringScheduled:ee,windowRect:ct}),[K,re,le,Y,Ke,ge,de,M,R,z,Zt,J,Ut,Os,Q,ee,ct]),qo=y.useMemo(()=>({activatorEvent:Y,activators:hs,active:K,activeNodeRect:le,ariaDescribedById:{draggable:O},dispatch:A,draggableNodes:M,over:Zt,measureDroppableContainers:J}),[Y,hs,K,le,A,O,M,Zt,J]);return be.createElement(nV.Provider,{value:C},be.createElement(qm.Provider,{value:qo},be.createElement(gV.Provider,{value:ar},be.createElement(oy.Provider,{value:pn},d)),be.createElement(h2e,{disabled:l?.restoreFocus===!1})),be.createElement(mAe,{...l,hiddenTextDescribedById:O}));function Go(){const ln=$?.autoScrollEnabled===!1,cn=typeof c=="object"?c.enabled===!1:c===!1,He=T&&!ln&&!cn;return typeof c=="object"?{...c,enabled:He}:{enabled:He}}}),m2e=y.createContext(null),RR="button",x2e="Draggable";function g2e(e){let{id:t,data:n,disabled:s=!1,attributes:i}=e;const a=Wm(x2e),{activators:o,activatorEvent:l,active:c,activeNodeRect:d,ariaDescribedById:f,draggableNodes:p,over:m}=y.useContext(qm),{role:g=RR,roleDescription:b="draggable",tabIndex:_=0}=i??{},w=c?.id===t,A=y.useContext(w?oy:m2e),[S,C]=T0(),[E,k]=T0(),T=i2e(o,t),F=Hp(n);la(()=>(p.set(t,{id:t,key:a,node:S,activatorNode:E,data:F}),()=>{const I=p.get(t);I&&I.key===a&&p.delete(t)}),[p,t]);const M=y.useMemo(()=>({role:g,tabIndex:_,"aria-disabled":s,"aria-pressed":w&&g===RR?!0:void 0,"aria-roledescription":b,"aria-describedby":f.draggable}),[s,g,_,w,b,f.draggable]);return{active:c,activatorEvent:l,activeNodeRect:d,attributes:M,isDragging:w,listeners:s?void 0:T,node:S,over:m,setNodeRef:C,setActivatorNodeRef:k,transform:A}}function yV(){return y.useContext(gV)}const b2e="Droppable",v2e={timeout:25};function _V(e){let{data:t,disabled:n=!1,id:s,resizeObserverConfig:i}=e;const a=Wm(b2e),{active:o,dispatch:l,over:c,measureDroppableContainers:d}=y.useContext(qm),f=y.useRef({disabled:n}),p=y.useRef(!1),m=y.useRef(null),g=y.useRef(null),{disabled:b,updateMeasurementsFor:_,timeout:w}={...v2e,...i},A=Hp(_??s),S=y.useCallback(()=>{if(!p.current){p.current=!0;return}g.current!=null&&clearTimeout(g.current),g.current=setTimeout(()=>{d(Array.isArray(A.current)?A.current:[A.current]),g.current=null},w)},[w]),C=ay({callback:S,disabled:b||!o}),E=y.useCallback((M,I)=>{C&&(I&&(C.unobserve(I),p.current=!1),M&&C.observe(M))},[C]),[k,T]=T0(E),F=Hp(t);return y.useEffect(()=>{!C||!k.current||(C.disconnect(),p.current=!1,C.observe(k.current))},[k,C]),y.useEffect(()=>(l({type:ns.RegisterDroppable,element:{id:s,key:a,disabled:n,node:k,rect:m,data:F}}),()=>l({type:ns.UnregisterDroppable,key:a,id:s})),[s]),y.useEffect(()=>{n!==f.current.disabled&&(l({type:ns.SetDroppableDisabled,id:s,key:a,disabled:n}),f.current.disabled=n)},[s,a,n,l]),{active:o,rect:m,isOver:c?.id===s,node:k,over:c,setNodeRef:T}}function y2e(e){let{animation:t,children:n}=e;const[s,i]=y.useState(null),[a,o]=y.useState(null),l=M0(n);return!n&&!s&&l&&i(l),la(()=>{if(!a)return;const c=s?.key,d=s?.props.id;if(c==null||d==null){i(null);return}Promise.resolve(t(d,a)).then(()=>{i(null)})},[t,s,a]),be.createElement(be.Fragment,null,n,s?y.cloneElement(s,{ref:o}):null)}const _2e={x:0,y:0,scaleX:1,scaleY:1};function w2e(e){let{children:t}=e;return be.createElement(qm.Provider,{value:xV},be.createElement(oy.Provider,{value:_2e},t))}const A2e={position:"fixed",touchAction:"none"},S2e=e=>ry(e)?"transform 250ms ease":void 0,C2e=y.forwardRef((e,t)=>{let{as:n,activatorEvent:s,adjustScale:i,children:a,className:o,rect:l,style:c,transform:d,transition:f=S2e}=e;if(!l)return null;const p=i?d:{...d,scaleX:1,scaleY:1},m={...A2e,width:l.width,height:l.height,top:l.top,left:l.left,transform:Oo.Transform.toString(p),transformOrigin:i&&s?bAe(s,l):void 0,transition:typeof f=="function"?f(s):f,...c};return be.createElement(n,{className:o,style:m,ref:t},a)}),j2e=e=>t=>{let{active:n,dragOverlay:s}=t;const i={},{styles:a,className:o}=e;if(a!=null&&a.active)for(const[l,c]of Object.entries(a.active))c!==void 0&&(i[l]=n.node.style.getPropertyValue(l),n.node.style.setProperty(l,c));if(a!=null&&a.dragOverlay)for(const[l,c]of Object.entries(a.dragOverlay))c!==void 0&&s.node.style.setProperty(l,c);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&s.node.classList.add(o.dragOverlay),function(){for(const[c,d]of Object.entries(i))n.node.style.setProperty(c,d);o!=null&&o.active&&n.node.classList.remove(o.active)}},N2e=e=>{let{transform:{initial:t,final:n}}=e;return[{transform:Oo.Transform.toString(t)},{transform:Oo.Transform.toString(n)}]},k2e={duration:250,easing:"ease",keyframes:N2e,sideEffects:j2e({styles:{active:{opacity:"0"}}})};function E2e(e){let{config:t,draggableNodes:n,droppableContainers:s,measuringConfiguration:i}=e;return iy((a,o)=>{if(t===null)return;const l=n.get(a);if(!l)return;const c=l.node.current;if(!c)return;const d=mV(o);if(!d)return;const{transform:f}=fi(o).getComputedStyle(o),p=rV(f);if(!p)return;const m=typeof t=="function"?t:F2e(t);return hV(c,i.draggable.measure),m({active:{id:a,data:l.data,node:c,rect:i.draggable.measure(c)},draggableNodes:n,dragOverlay:{node:o,rect:i.dragOverlay.measure(d)},droppableContainers:s,measuringConfiguration:i,transform:p})})}function F2e(e){const{duration:t,easing:n,sideEffects:s,keyframes:i}={...k2e,...e};return a=>{let{active:o,dragOverlay:l,transform:c,...d}=a;if(!t)return;const f={x:l.rect.left-o.rect.left,y:l.rect.top-o.rect.top},p={scaleX:c.scaleX!==1?o.rect.width*c.scaleX/l.rect.width:1,scaleY:c.scaleY!==1?o.rect.height*c.scaleY/l.rect.height:1},m={x:c.x-f.x,y:c.y-f.y,...p},g=i({...d,active:o,dragOverlay:l,transform:{initial:c,final:m}}),[b]=g,_=g[g.length-1];if(JSON.stringify(b)===JSON.stringify(_))return;const w=s?.({active:o,dragOverlay:l,...d}),A=l.node.animate(g,{duration:t,easing:n,fill:"forwards"});return new Promise(S=>{A.onfinish=()=>{w?.(),S()}})}}let DR=0;function T2e(e){return y.useMemo(()=>{if(e!=null)return DR++,DR},[e])}const wV=be.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:s,style:i,transition:a,modifiers:o,wrapperElement:l="div",className:c,zIndex:d=999}=e;const{activatorEvent:f,active:p,activeNodeRect:m,containerNodeRect:g,draggableNodes:b,droppableContainers:_,dragOverlay:w,over:A,measuringConfiguration:S,scrollableAncestors:C,scrollableAncestorRects:E,windowRect:k}=yV(),T=y.useContext(oy),F=T2e(p?.id),M=bV(o,{activatorEvent:f,active:p,activeNodeRect:m,containerNodeRect:g,draggingNodeRect:w.rect,over:A,overlayNodeRect:w.rect,scrollableAncestors:C,scrollableAncestorRects:E,transform:T,windowRect:k}),I=tN(m),R=E2e({config:s,draggableNodes:b,droppableContainers:_,measuringConfiguration:S}),H=I?w.setRef:void 0;return be.createElement(w2e,null,be.createElement(y2e,{animation:R},p&&F?be.createElement(C2e,{key:F,id:p.id,ref:H,as:l,activatorEvent:f,adjustScale:t,className:c,transition:a,rect:I,style:{zIndex:d,...i},transform:M},n):null))});function nN(e,t,n){const s=e.slice();return s.splice(n<0?s.length+n:n,0,s.splice(t,1)[0]),s}function M2e(e,t){return e.reduce((n,s,i)=>{const a=t.get(s);return a&&(n[i]=a),n},Array(e.length))}function $g(e){return e!==null&&e>=0}function R2e(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function D2e(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const AV=e=>{let{rects:t,activeIndex:n,overIndex:s,index:i}=e;const a=nN(t,s,n),o=t[i],l=a[i];return!l||!o?null:{x:l.left-o.left,y:l.top-o.top,scaleX:l.width/o.width,scaleY:l.height/o.height}},Vg={scaleX:1,scaleY:1},SV=e=>{var t;let{activeIndex:n,activeNodeRect:s,index:i,rects:a,overIndex:o}=e;const l=(t=a[n])!=null?t:s;if(!l)return null;if(i===n){const d=a[o];return d?{x:0,y:n<o?d.top+d.height-(l.top+l.height):d.top-l.top,...Vg}:null}const c=O2e(a,i,n);return i>n&&i<=o?{x:0,y:-l.height-c,...Vg}:i<n&&i>=o?{x:0,y:l.height+c,...Vg}:{x:0,y:0,...Vg}};function O2e(e,t,n){const s=e[t],i=e[t-1],a=e[t+1];return s?n<t?i?s.top-(i.top+i.height):a?a.top-(s.top+s.height):0:a?a.top-(s.top+s.height):i?s.top-(i.top+i.height):0:0}const CV="Sortable",jV=be.createContext({activeIndex:-1,containerId:CV,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:AV,disabled:{draggable:!1,droppable:!1}});function sN(e){let{children:t,id:n,items:s,strategy:i=AV,disabled:a=!1}=e;const{active:o,dragOverlay:l,droppableRects:c,over:d,measureDroppableContainers:f}=yV(),p=Wm(CV,n),m=l.rect!==null,g=y.useMemo(()=>s.map(T=>typeof T=="object"&&"id"in T?T.id:T),[s]),b=o!=null,_=o?g.indexOf(o.id):-1,w=d?g.indexOf(d.id):-1,A=y.useRef(g),S=!R2e(g,A.current),C=w!==-1&&_===-1||S,E=D2e(a);la(()=>{S&&b&&f(g)},[S,g,b,f]),y.useEffect(()=>{A.current=g},[g]);const k=y.useMemo(()=>({activeIndex:_,containerId:p,disabled:E,disableTransforms:C,items:g,overIndex:w,useDragOverlay:m,sortedRects:M2e(g,c),strategy:i}),[_,p,E.draggable,E.droppable,C,g,w,c,m,i]);return be.createElement(jV.Provider,{value:k},t)}const P2e=e=>{let{id:t,items:n,activeIndex:s,overIndex:i}=e;return nN(n,s,i).indexOf(t)},I2e=e=>{let{containerId:t,isSorting:n,wasDragging:s,index:i,items:a,newIndex:o,previousItems:l,previousContainerId:c,transition:d}=e;return!d||!s||l!==a&&i===o?!1:n?!0:o!==i&&t===c},L2e={duration:200,easing:"ease"},NV="transform",B2e=Oo.Transition.toString({property:NV,duration:0,easing:"linear"}),z2e={roleDescription:"sortable"};function $2e(e){let{disabled:t,index:n,node:s,rect:i}=e;const[a,o]=y.useState(null),l=y.useRef(n);return la(()=>{if(!t&&n!==l.current&&s.current){const c=i.current;if(c){const d=wh(s.current,{ignoreTransform:!0}),f={x:c.left-d.left,y:c.top-d.top,scaleX:c.width/d.width,scaleY:c.height/d.height};(f.x||f.y)&&o(f)}}n!==l.current&&(l.current=n)},[t,n,s,i]),y.useEffect(()=>{a&&o(null)},[a]),a}function iN(e){let{animateLayoutChanges:t=I2e,attributes:n,disabled:s,data:i,getNewIndex:a=P2e,id:o,strategy:l,resizeObserverConfig:c,transition:d=L2e}=e;const{items:f,containerId:p,activeIndex:m,disabled:g,disableTransforms:b,sortedRects:_,overIndex:w,useDragOverlay:A,strategy:S}=y.useContext(jV),C=V2e(s,g),E=f.indexOf(o),k=y.useMemo(()=>({sortable:{containerId:p,index:E,items:f},...i}),[p,i,E,f]),T=y.useMemo(()=>f.slice(f.indexOf(o)),[f,o]),{rect:F,node:M,isOver:I,setNodeRef:R}=_V({id:o,data:k,disabled:C.droppable,resizeObserverConfig:{updateMeasurementsFor:T,...c}}),{active:H,activatorEvent:V,activeNodeRect:K,attributes:q,setNodeRef:$,listeners:B,isDragging:Y,over:U,setActivatorNodeRef:W,transform:O}=g2e({id:o,data:k,attributes:{...z2e,...n},disabled:C.draggable}),D=nAe(R,$),Q=!!H,z=Q&&!b&&$g(m)&&$g(w),J=!A&&Y,ee=J&&z?O:null,oe=z?ee??(l??S)({rects:_,activeNodeRect:K,activeIndex:m,overIndex:w,index:E}):null,se=$g(m)&&$g(w)?a({id:o,items:f,activeIndex:m,overIndex:w}):E,ae=H?.id,le=y.useRef({activeId:ae,items:f,newIndex:se,containerId:p}),ge=f!==le.current.items,je=t({active:H,containerId:p,isDragging:Y,isSorting:Q,id:o,index:E,items:f,newIndex:le.current.newIndex,previousItems:le.current.items,previousContainerId:le.current.containerId,transition:d,wasDragging:le.current.activeId!=null}),Ee=$2e({disabled:!je,index:E,node:M,rect:F});return y.useEffect(()=>{Q&&le.current.newIndex!==se&&(le.current.newIndex=se),p!==le.current.containerId&&(le.current.containerId=p),f!==le.current.items&&(le.current.items=f)},[Q,se,p,f]),y.useEffect(()=>{if(ae===le.current.activeId)return;if(ae!=null&&le.current.activeId==null){le.current.activeId=ae;return}const me=setTimeout(()=>{le.current.activeId=ae},50);return()=>clearTimeout(me)},[ae]),{active:H,activeIndex:m,attributes:q,data:k,rect:F,index:E,newIndex:se,items:f,isOver:I,isSorting:Q,isDragging:Y,listeners:B,node:M,overIndex:w,over:U,setNodeRef:D,setActivatorNodeRef:W,setDroppableNodeRef:R,setDraggableNodeRef:$,transform:Ee??oe,transition:de()};function de(){if(Ee||ge&&le.current.newIndex===E)return B2e;if(!(J&&!ry(V)||!d)&&(Q||je))return Oo.Transition.toString({...d,property:NV})}}function V2e(e,t){var n,s;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(n=e?.draggable)!=null?n:t.draggable,droppable:(s=e?.droppable)!=null?s:t.droppable}}Ft.Down,Ft.Right,Ft.Up,Ft.Left;function U2e({card:e,columnId:t,onRemove:n,onEdit:s}){const{attributes:i,listeners:a,setNodeRef:o,transform:l,transition:c,isDragging:d}=iN({id:e.id,data:{type:"card",columnId:t}}),[f,p]=y.useState(!1),[m,g]=y.useState(e.title),[b,_]=y.useState(e.description??""),w={transform:Oo.Transform.toString(l),transition:c,opacity:d?.4:1},A=y.useCallback(()=>{m.trim()&&s(t,e.id,m.trim(),b.trim()),p(!1)},[t,e.id,m,b,s]);return f?r.jsxs("div",{ref:o,style:w,className:"bg-[#1C1C21] rounded-md p-2 border border-[#6366F1]/30",children:[r.jsx("input",{value:m,onChange:S=>g(S.target.value),onKeyDown:S=>S.key==="Enter"&&A(),className:"w-full bg-transparent text-[11px] text-[#F0F0F5] outline-none mb-1",autoFocus:!0}),r.jsx("textarea",{value:b,onChange:S=>_(S.target.value),rows:2,className:"w-full bg-transparent text-[10px] text-[#8A8A99] outline-none resize-none",placeholder:"Description..."}),r.jsxs("div",{className:"flex justify-end gap-1 mt-1",children:[r.jsx("button",{onClick:()=>p(!1),className:"p-0.5 text-[#5A5A6E] hover:text-[#C8C8D4]",children:r.jsx(Te,{className:"w-3 h-3"})}),r.jsx("button",{onClick:A,className:"p-0.5 text-[#10B981] hover:text-[#34D399]",children:r.jsx(Fe,{className:"w-3 h-3"})})]})]}):r.jsx("div",{ref:o,style:w,className:"bg-[#1C1C21] rounded-md p-2 border border-[#2A2A35] hover:border-[#3A3A45] transition-colors group cursor-grab active:cursor-grabbing",...i,...a,children:r.jsxs("div",{className:"flex items-start gap-1",children:[r.jsx(dL,{className:"w-3 h-3 text-[#3A3A45] mt-0.5 flex-shrink-0 opacity-0 group-hover:opacity-100 transition-opacity"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[11px] text-[#F0F0F5] leading-snug",children:e.title}),e.description&&r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5 leading-snug line-clamp-2",children:e.description}),e.assignee&&r.jsx("span",{className:"inline-block mt-1 px-1.5 py-0.5 rounded text-[9px] font-medium bg-[#6366F1]/10 text-[#818CF8]",children:e.assignee})]}),r.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[r.jsx("button",{onClick:S=>{S.stopPropagation(),p(!0)},className:"p-0.5 text-[#5A5A6E] hover:text-[#C8C8D4]",children:r.jsx(oh,{className:"w-2.5 h-2.5"})}),r.jsx("button",{onClick:S=>{S.stopPropagation(),n(t,e.id)},className:"p-0.5 text-[#5A5A6E] hover:text-[#EF4444]",children:r.jsx(Te,{className:"w-2.5 h-2.5"})})]})]})})}function H2e({column:e,onRemoveCard:t,onEditCard:n,onAddCard:s,onRenameColumn:i,onRemoveColumn:a}){const{setNodeRef:o}=W2e(e.id),[l,c]=y.useState(!1),[d,f]=y.useState(e.title),p=y.useMemo(()=>e.cards.map(g=>g.id),[e.cards]),m=y.useCallback(()=>{d.trim()&&i(e.id,d.trim()),c(!1)},[e.id,d,i]);return r.jsxs("div",{ref:o,className:"flex flex-col bg-[#16161A] rounded-lg border border-[#2A2A35] w-[220px] flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between px-2.5 py-2 border-b border-[#2A2A35]/50",children:[l?r.jsx("input",{value:d,onChange:g=>f(g.target.value),onBlur:m,onKeyDown:g=>g.key==="Enter"&&m(),className:"flex-1 bg-transparent text-[11px] font-semibold text-[#F0F0F5] outline-none",autoFocus:!0}):r.jsxs("span",{onDoubleClick:()=>c(!0),className:"text-[11px] font-semibold text-[#F0F0F5] cursor-default select-none",children:[e.title,r.jsx("span",{className:"ml-1.5 text-[10px] font-normal text-[#5A5A6E]",children:e.cards.length})]}),r.jsx("button",{onClick:()=>a(e.id),className:"p-0.5 text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:r.jsx(Te,{className:"w-3 h-3"})})]}),r.jsx("div",{className:"flex-1 p-1.5 space-y-1.5 min-h-[60px] overflow-y-auto max-h-[400px]",children:r.jsx(sN,{items:p,strategy:SV,children:e.cards.map(g=>r.jsx(U2e,{card:g,columnId:e.id,onRemove:t,onEdit:n},g.id))})}),r.jsxs("button",{onClick:()=>s(e.id),className:"flex items-center gap-1 px-2.5 py-1.5 text-[10px] text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/[0.02] transition-colors border-t border-[#2A2A35]/50",children:[r.jsx(wt,{className:"w-3 h-3"}),"Add card"]})]})}function W2e(e){const{setNodeRef:t}=iN({id:`droppable-${e}`,disabled:!0});return{setNodeRef:t}}let q2e=0;function OR(){return`c${Date.now()}-${++q2e}`}function G2e({data:e,onChange:t}){const[n,s]=y.useState(null),i=y.useRef(e.columns);i.current=e.columns;const a=xAe(wR(eN,{activationConstraint:{distance:4}}),wR(Jj)),o=y.useCallback(A=>i.current.find(S=>S.cards.some(C=>C.id===A)),[]),l=y.useCallback(A=>{const C=o(String(A.active.id))?.cards.find(E=>E.id===A.active.id);C&&s(C)},[o]),c=y.useCallback(A=>{const{active:S,over:C}=A;if(!C)return;const E=String(S.id),k=String(C.id),T=o(E),F=o(k)??i.current.find(R=>`droppable-${R.id}`===k);if(!T||!F||T.id===F.id)return;const M=T.cards.find(R=>R.id===E);if(!M)return;const I=i.current.map(R=>{if(R.id===T.id)return{...R,cards:R.cards.filter(H=>H.id!==E)};if(R.id===F.id){const H=R.cards.findIndex(q=>q.id===k),V=H>=0?H:R.cards.length,K=[...R.cards];return K.some(q=>q.id===E)||K.splice(V,0,M),{...R,cards:K}}return R});t({columns:I})},[o,t]),d=y.useCallback(A=>{s(null);const{active:S,over:C}=A;if(!C)return;const E=String(S.id),k=String(C.id);if(E===k)return;const T=o(E);if(!T)return;const F=T.cards.findIndex(R=>R.id===E),M=T.cards.findIndex(R=>R.id===k);if(F===-1||M===-1)return;const I=i.current.map(R=>R.id===T.id?{...R,cards:nN(R.cards,F,M)}:R);t({columns:I})},[o,t]),f=y.useCallback(A=>{const S=e.columns.map(C=>C.id===A?{...C,cards:[...C.cards,{id:OR(),title:"New card"}]}:C);t({columns:S})},[e.columns,t]),p=y.useCallback((A,S)=>{const C=e.columns.map(E=>E.id===A?{...E,cards:E.cards.filter(k=>k.id!==S)}:E);t({columns:C})},[e.columns,t]),m=y.useCallback((A,S,C,E)=>{const k=e.columns.map(T=>T.id===A?{...T,cards:T.cards.map(F=>F.id===S?{...F,title:C,description:E}:F)}:T);t({columns:k})},[e.columns,t]),g=y.useCallback(()=>{t({columns:[...e.columns,{id:OR(),title:"New Column",cards:[]}]})},[e.columns,t]),b=y.useCallback((A,S)=>{const C=e.columns.map(E=>E.id===A?{...E,title:S}:E);t({columns:C})},[e.columns,t]),_=y.useCallback(A=>{t({columns:e.columns.filter(S=>S.id!==A)})},[e.columns,t]),w=y.useMemo(()=>e.columns.flatMap(A=>[...A.cards.map(S=>S.id),`droppable-${A.id}`]),[e.columns]);return r.jsx("div",{className:"p-3",children:r.jsxs(vV,{sensors:a,collisionDetection:sV,onDragStart:l,onDragOver:c,onDragEnd:d,children:[r.jsx(sN,{items:w,children:r.jsxs("div",{className:"flex gap-2 overflow-x-auto pb-2",children:[e.columns.map(A=>r.jsx(H2e,{column:A,onRemoveCard:p,onEditCard:m,onAddCard:f,onRenameColumn:b,onRemoveColumn:_},A.id)),r.jsxs("button",{onClick:g,className:"flex items-center gap-1 px-3 py-2 h-fit rounded-lg border border-dashed border-[#2A2A35] text-[10px] text-[#5A5A6E] hover:text-[#C8C8D4] hover:border-[#3A3A45] transition-colors flex-shrink-0",children:[r.jsx(wt,{className:"w-3 h-3"}),"Column"]})]})}),Xr.createPortal(r.jsx(wV,{children:n&&r.jsxs("div",{className:"bg-[#1C1C21] rounded-md p-2 border border-[#6366F1]/40 shadow-lg shadow-black/40 w-[200px]",children:[r.jsx("p",{className:"text-[11px] text-[#F0F0F5]",children:n.title}),n.description&&r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:n.description})]})}),document.body)]})})}function Gm(e){return e+.5|0}const Dl=(e,t,n)=>Math.max(Math.min(e,n),t);function Zf(e){return Dl(Gm(e*2.55),0,255)}function zl(e){return Dl(Gm(e*255),0,255)}function _o(e){return Dl(Gm(e/2.55)/100,0,1)}function PR(e){return Dl(Gm(e*100),0,100)}const _r={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:10,B:11,C:12,D:13,E:14,F:15,a:10,b:11,c:12,d:13,e:14,f:15},lC=[..."0123456789ABCDEF"],K2e=e=>lC[e&15],Y2e=e=>lC[(e&240)>>4]+lC[e&15],Ug=e=>(e&240)>>4===(e&15),Q2e=e=>Ug(e.r)&&Ug(e.g)&&Ug(e.b)&&Ug(e.a);function X2e(e){var t=e.length,n;return e[0]==="#"&&(t===4||t===5?n={r:255&_r[e[1]]*17,g:255&_r[e[2]]*17,b:255&_r[e[3]]*17,a:t===5?_r[e[4]]*17:255}:(t===7||t===9)&&(n={r:_r[e[1]]<<4|_r[e[2]],g:_r[e[3]]<<4|_r[e[4]],b:_r[e[5]]<<4|_r[e[6]],a:t===9?_r[e[7]]<<4|_r[e[8]]:255})),n}const J2e=(e,t)=>e<255?t(e):"";function Z2e(e){var t=Q2e(e)?K2e:Y2e;return e?"#"+t(e.r)+t(e.g)+t(e.b)+J2e(e.a,t):void 0}const eSe=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;function kV(e,t,n){const s=t*Math.min(n,1-n),i=(a,o=(a+e/30)%12)=>n-s*Math.max(Math.min(o-3,9-o,1),-1);return[i(0),i(8),i(4)]}function tSe(e,t,n){const s=(i,a=(i+e/60)%6)=>n-n*t*Math.max(Math.min(a,4-a,1),0);return[s(5),s(3),s(1)]}function nSe(e,t,n){const s=kV(e,1,.5);let i;for(t+n>1&&(i=1/(t+n),t*=i,n*=i),i=0;i<3;i++)s[i]*=1-t-n,s[i]+=t;return s}function sSe(e,t,n,s,i){return e===i?(t-n)/s+(t<n?6:0):t===i?(n-e)/s+2:(e-t)/s+4}function rN(e){const n=e.r/255,s=e.g/255,i=e.b/255,a=Math.max(n,s,i),o=Math.min(n,s,i),l=(a+o)/2;let c,d,f;return a!==o&&(f=a-o,d=l>.5?f/(2-a-o):f/(a+o),c=sSe(n,s,i,f,a),c=c*60+.5),[c|0,d||0,l]}function aN(e,t,n,s){return(Array.isArray(t)?e(t[0],t[1],t[2]):e(t,n,s)).map(zl)}function oN(e,t,n){return aN(kV,e,t,n)}function iSe(e,t,n){return aN(nSe,e,t,n)}function rSe(e,t,n){return aN(tSe,e,t,n)}function EV(e){return(e%360+360)%360}function aSe(e){const t=eSe.exec(e);let n=255,s;if(!t)return;t[5]!==s&&(n=t[6]?Zf(+t[5]):zl(+t[5]));const i=EV(+t[2]),a=+t[3]/100,o=+t[4]/100;return t[1]==="hwb"?s=iSe(i,a,o):t[1]==="hsv"?s=rSe(i,a,o):s=oN(i,a,o),{r:s[0],g:s[1],b:s[2],a:n}}function oSe(e,t){var n=rN(e);n[0]=EV(n[0]+t),n=oN(n),e.r=n[0],e.g=n[1],e.b=n[2]}function lSe(e){if(!e)return;const t=rN(e),n=t[0],s=PR(t[1]),i=PR(t[2]);return e.a<255?`hsla(${n}, ${s}%, ${i}%, ${_o(e.a)})`:`hsl(${n}, ${s}%, ${i}%)`}const IR={x:"dark",Z:"light",Y:"re",X:"blu",W:"gr",V:"medium",U:"slate",A:"ee",T:"ol",S:"or",B:"ra",C:"lateg",D:"ights",R:"in",Q:"turquois",E:"hi",P:"ro",O:"al",N:"le",M:"de",L:"yello",F:"en",K:"ch",G:"arks",H:"ea",I:"ightg",J:"wh"},LR={OiceXe:"f0f8ff",antiquewEte:"faebd7",aqua:"ffff",aquamarRe:"7fffd4",azuY:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"0",blanKedOmond:"ffebcd",Xe:"ff",XeviTet:"8a2be2",bPwn:"a52a2a",burlywood:"deb887",caMtXe:"5f9ea0",KartYuse:"7fff00",KocTate:"d2691e",cSO:"ff7f50",cSnflowerXe:"6495ed",cSnsilk:"fff8dc",crimson:"dc143c",cyan:"ffff",xXe:"8b",xcyan:"8b8b",xgTMnPd:"b8860b",xWay:"a9a9a9",xgYF:"6400",xgYy:"a9a9a9",xkhaki:"bdb76b",xmagFta:"8b008b",xTivegYF:"556b2f",xSange:"ff8c00",xScEd:"9932cc",xYd:"8b0000",xsOmon:"e9967a",xsHgYF:"8fbc8f",xUXe:"483d8b",xUWay:"2f4f4f",xUgYy:"2f4f4f",xQe:"ced1",xviTet:"9400d3",dAppRk:"ff1493",dApskyXe:"bfff",dimWay:"696969",dimgYy:"696969",dodgerXe:"1e90ff",fiYbrick:"b22222",flSOwEte:"fffaf0",foYstWAn:"228b22",fuKsia:"ff00ff",gaRsbSo:"dcdcdc",ghostwEte:"f8f8ff",gTd:"ffd700",gTMnPd:"daa520",Way:"808080",gYF:"8000",gYFLw:"adff2f",gYy:"808080",honeyMw:"f0fff0",hotpRk:"ff69b4",RdianYd:"cd5c5c",Rdigo:"4b0082",ivSy:"fffff0",khaki:"f0e68c",lavFMr:"e6e6fa",lavFMrXsh:"fff0f5",lawngYF:"7cfc00",NmoncEffon:"fffacd",ZXe:"add8e6",ZcSO:"f08080",Zcyan:"e0ffff",ZgTMnPdLw:"fafad2",ZWay:"d3d3d3",ZgYF:"90ee90",ZgYy:"d3d3d3",ZpRk:"ffb6c1",ZsOmon:"ffa07a",ZsHgYF:"20b2aa",ZskyXe:"87cefa",ZUWay:"778899",ZUgYy:"778899",ZstAlXe:"b0c4de",ZLw:"ffffe0",lime:"ff00",limegYF:"32cd32",lRF:"faf0e6",magFta:"ff00ff",maPon:"800000",VaquamarRe:"66cdaa",VXe:"cd",VScEd:"ba55d3",VpurpN:"9370db",VsHgYF:"3cb371",VUXe:"7b68ee",VsprRggYF:"fa9a",VQe:"48d1cc",VviTetYd:"c71585",midnightXe:"191970",mRtcYam:"f5fffa",mistyPse:"ffe4e1",moccasR:"ffe4b5",navajowEte:"ffdead",navy:"80",Tdlace:"fdf5e6",Tive:"808000",TivedBb:"6b8e23",Sange:"ffa500",SangeYd:"ff4500",ScEd:"da70d6",pOegTMnPd:"eee8aa",pOegYF:"98fb98",pOeQe:"afeeee",pOeviTetYd:"db7093",papayawEp:"ffefd5",pHKpuff:"ffdab9",peru:"cd853f",pRk:"ffc0cb",plum:"dda0dd",powMrXe:"b0e0e6",purpN:"800080",YbeccapurpN:"663399",Yd:"ff0000",Psybrown:"bc8f8f",PyOXe:"4169e1",saddNbPwn:"8b4513",sOmon:"fa8072",sandybPwn:"f4a460",sHgYF:"2e8b57",sHshell:"fff5ee",siFna:"a0522d",silver:"c0c0c0",skyXe:"87ceeb",UXe:"6a5acd",UWay:"708090",UgYy:"708090",snow:"fffafa",sprRggYF:"ff7f",stAlXe:"4682b4",tan:"d2b48c",teO:"8080",tEstN:"d8bfd8",tomato:"ff6347",Qe:"40e0d0",viTet:"ee82ee",JHt:"f5deb3",wEte:"ffffff",wEtesmoke:"f5f5f5",Lw:"ffff00",LwgYF:"9acd32"};function cSe(){const e={},t=Object.keys(LR),n=Object.keys(IR);let s,i,a,o,l;for(s=0;s<t.length;s++){for(o=l=t[s],i=0;i<n.length;i++)a=n[i],l=l.replace(a,IR[a]);a=parseInt(LR[o],16),e[l]=[a>>16&255,a>>8&255,a&255]}return e}let Hg;function uSe(e){Hg||(Hg=cSe(),Hg.transparent=[0,0,0,0]);const t=Hg[e.toLowerCase()];return t&&{r:t[0],g:t[1],b:t[2],a:t.length===4?t[3]:255}}const dSe=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;function hSe(e){const t=dSe.exec(e);let n=255,s,i,a;if(t){if(t[7]!==s){const o=+t[7];n=t[8]?Zf(o):Dl(o*255,0,255)}return s=+t[1],i=+t[3],a=+t[5],s=255&(t[2]?Zf(s):Dl(s,0,255)),i=255&(t[4]?Zf(i):Dl(i,0,255)),a=255&(t[6]?Zf(a):Dl(a,0,255)),{r:s,g:i,b:a,a:n}}}function fSe(e){return e&&(e.a<255?`rgba(${e.r}, ${e.g}, ${e.b}, ${_o(e.a)})`:`rgb(${e.r}, ${e.g}, ${e.b})`)}const AA=e=>e<=.0031308?e*12.92:Math.pow(e,1/2.4)*1.055-.055,xd=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4);function pSe(e,t,n){const s=xd(_o(e.r)),i=xd(_o(e.g)),a=xd(_o(e.b));return{r:zl(AA(s+n*(xd(_o(t.r))-s))),g:zl(AA(i+n*(xd(_o(t.g))-i))),b:zl(AA(a+n*(xd(_o(t.b))-a))),a:e.a+n*(t.a-e.a)}}function Wg(e,t,n){if(e){let s=rN(e);s[t]=Math.max(0,Math.min(s[t]+s[t]*n,t===0?360:1)),s=oN(s),e.r=s[0],e.g=s[1],e.b=s[2]}}function FV(e,t){return e&&Object.assign(t||{},e)}function BR(e){var t={r:0,g:0,b:0,a:255};return Array.isArray(e)?e.length>=3&&(t={r:e[0],g:e[1],b:e[2],a:255},e.length>3&&(t.a=zl(e[3]))):(t=FV(e,{r:0,g:0,b:0,a:1}),t.a=zl(t.a)),t}function mSe(e){return e.charAt(0)==="r"?hSe(e):aSe(e)}class qp{constructor(t){if(t instanceof qp)return t;const n=typeof t;let s;n==="object"?s=BR(t):n==="string"&&(s=X2e(t)||uSe(t)||mSe(t)),this._rgb=s,this._valid=!!s}get valid(){return this._valid}get rgb(){var t=FV(this._rgb);return t&&(t.a=_o(t.a)),t}set rgb(t){this._rgb=BR(t)}rgbString(){return this._valid?fSe(this._rgb):void 0}hexString(){return this._valid?Z2e(this._rgb):void 0}hslString(){return this._valid?lSe(this._rgb):void 0}mix(t,n){if(t){const s=this.rgb,i=t.rgb;let a;const o=n===a?.5:n,l=2*o-1,c=s.a-i.a,d=((l*c===-1?l:(l+c)/(1+l*c))+1)/2;a=1-d,s.r=255&d*s.r+a*i.r+.5,s.g=255&d*s.g+a*i.g+.5,s.b=255&d*s.b+a*i.b+.5,s.a=o*s.a+(1-o)*i.a,this.rgb=s}return this}interpolate(t,n){return t&&(this._rgb=pSe(this._rgb,t._rgb,n)),this}clone(){return new qp(this.rgb)}alpha(t){return this._rgb.a=zl(t),this}clearer(t){const n=this._rgb;return n.a*=1-t,this}greyscale(){const t=this._rgb,n=Gm(t.r*.3+t.g*.59+t.b*.11);return t.r=t.g=t.b=n,this}opaquer(t){const n=this._rgb;return n.a*=1+t,this}negate(){const t=this._rgb;return t.r=255-t.r,t.g=255-t.g,t.b=255-t.b,this}lighten(t){return Wg(this._rgb,2,t),this}darken(t){return Wg(this._rgb,2,-t),this}saturate(t){return Wg(this._rgb,1,t),this}desaturate(t){return Wg(this._rgb,1,-t),this}rotate(t){return oSe(this._rgb,t),this}}function mo(){}const xSe=(()=>{let e=0;return()=>e++})();function Tt(e){return e==null}function Wn(e){if(Array.isArray&&Array.isArray(e))return!0;const t=Object.prototype.toString.call(e);return t.slice(0,7)==="[object"&&t.slice(-6)==="Array]"}function xt(e){return e!==null&&Object.prototype.toString.call(e)==="[object Object]"}function Js(e){return(typeof e=="number"||e instanceof Number)&&isFinite(+e)}function ya(e,t){return Js(e)?e:t}function it(e,t){return typeof e>"u"?t:e}const gSe=(e,t)=>typeof e=="string"&&e.endsWith("%")?parseFloat(e)/100:+e/t,TV=(e,t)=>typeof e=="string"&&e.endsWith("%")?parseFloat(e)/100*t:+e;function rn(e,t,n){if(e&&typeof e.call=="function")return e.apply(n,t)}function It(e,t,n,s){let i,a,o;if(Wn(e))for(a=e.length,i=0;i<a;i++)t.call(n,e[i],i);else if(xt(e))for(o=Object.keys(e),a=o.length,i=0;i<a;i++)t.call(n,e[o[i]],o[i])}function I0(e,t){let n,s,i,a;if(!e||!t||e.length!==t.length)return!1;for(n=0,s=e.length;n<s;++n)if(i=e[n],a=t[n],i.datasetIndex!==a.datasetIndex||i.index!==a.index)return!1;return!0}function L0(e){if(Wn(e))return e.map(L0);if(xt(e)){const t=Object.create(null),n=Object.keys(e),s=n.length;let i=0;for(;i<s;++i)t[n[i]]=L0(e[n[i]]);return t}return e}function MV(e){return["__proto__","prototype","constructor"].indexOf(e)===-1}function bSe(e,t,n,s){if(!MV(e))return;const i=t[e],a=n[e];xt(i)&&xt(a)?Gp(i,a,s):t[e]=L0(a)}function Gp(e,t,n){const s=Wn(t)?t:[t],i=s.length;if(!xt(e))return e;n=n||{};const a=n.merger||bSe;let o;for(let l=0;l<i;++l){if(o=s[l],!xt(o))continue;const c=Object.keys(o);for(let d=0,f=c.length;d<f;++d)a(c[d],e,o,n)}return e}function xp(e,t){return Gp(e,t,{merger:vSe})}function vSe(e,t,n){if(!MV(e))return;const s=t[e],i=n[e];xt(s)&&xt(i)?xp(s,i):Object.prototype.hasOwnProperty.call(t,e)||(t[e]=L0(i))}const zR={"":e=>e,x:e=>e.x,y:e=>e.y};function ySe(e){const t=e.split("."),n=[];let s="";for(const i of t)s+=i,s.endsWith("\\")?s=s.slice(0,-1)+".":(n.push(s),s="");return n}function _Se(e){const t=ySe(e);return n=>{for(const s of t){if(s==="")break;n=n&&n[s]}return n}}function hu(e,t){return(zR[t]||(zR[t]=_Se(t)))(e)}function lN(e){return e.charAt(0).toUpperCase()+e.slice(1)}const Kp=e=>typeof e<"u",Ql=e=>typeof e=="function",$R=(e,t)=>{if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0};function wSe(e){return e.type==="mouseup"||e.type==="click"||e.type==="contextmenu"}const Lt=Math.PI,_n=2*Lt,ASe=_n+Lt,B0=Number.POSITIVE_INFINITY,SSe=Lt/180,ls=Lt/2,Fc=Lt/4,VR=Lt*2/3,RV=Math.log10,za=Math.sign;function gp(e,t,n){return Math.abs(e-t)<n}function UR(e){const t=Math.round(e);e=gp(e,t,e/1e3)?t:e;const n=Math.pow(10,Math.floor(RV(e))),s=e/n;return(s<=1?1:s<=2?2:s<=5?5:10)*n}function CSe(e){const t=[],n=Math.sqrt(e);let s;for(s=1;s<n;s++)e%s===0&&(t.push(s),t.push(e/s));return n===(n|0)&&t.push(n),t.sort((i,a)=>i-a).pop(),t}function jSe(e){return typeof e=="symbol"||typeof e=="object"&&e!==null&&!(Symbol.toPrimitive in e||"toString"in e||"valueOf"in e)}function Qd(e){return!jSe(e)&&!isNaN(parseFloat(e))&&isFinite(e)}function NSe(e,t){const n=Math.round(e);return n-t<=e&&n+t>=e}function kSe(e,t,n){let s,i,a;for(s=0,i=e.length;s<i;s++)a=e[s][n],isNaN(a)||(t.min=Math.min(t.min,a),t.max=Math.max(t.max,a))}function Ao(e){return e*(Lt/180)}function ESe(e){return e*(180/Lt)}function HR(e){if(!Js(e))return;let t=1,n=0;for(;Math.round(e*t)/t!==e;)t*=10,n++;return n}function DV(e,t){const n=t.x-e.x,s=t.y-e.y,i=Math.sqrt(n*n+s*s);let a=Math.atan2(s,n);return a<-.5*Lt&&(a+=_n),{angle:a,distance:i}}function cC(e,t){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function FSe(e,t){return(e-t+ASe)%_n-Lt}function Wi(e){return(e%_n+_n)%_n}function Yp(e,t,n,s){const i=Wi(e),a=Wi(t),o=Wi(n),l=Wi(a-i),c=Wi(o-i),d=Wi(i-a),f=Wi(i-o);return i===a||i===o||s&&a===o||l>c&&d<f}function Ws(e,t,n){return Math.max(t,Math.min(n,e))}function TSe(e){return Ws(e,-32768,32767)}function So(e,t,n,s=1e-6){return e>=Math.min(t,n)-s&&e<=Math.max(t,n)+s}function cN(e,t,n){n=n||(o=>e[o]<t);let s=e.length-1,i=0,a;for(;s-i>1;)a=i+s>>1,n(a)?i=a:s=a;return{lo:i,hi:s}}const Gc=(e,t,n,s)=>cN(e,n,s?i=>{const a=e[i][t];return a<n||a===n&&e[i+1][t]===n}:i=>e[i][t]<n),MSe=(e,t,n)=>cN(e,n,s=>e[s][t]>=n);function RSe(e,t,n){let s=0,i=e.length;for(;s<i&&e[s]<t;)s++;for(;i>s&&e[i-1]>n;)i--;return s>0||i<e.length?e.slice(s,i):e}const OV=["push","pop","shift","splice","unshift"];function DSe(e,t){if(e._chartjs){e._chartjs.listeners.push(t);return}Object.defineProperty(e,"_chartjs",{configurable:!0,enumerable:!1,value:{listeners:[t]}}),OV.forEach(n=>{const s="_onData"+lN(n),i=e[n];Object.defineProperty(e,n,{configurable:!0,enumerable:!1,value(...a){const o=i.apply(this,a);return e._chartjs.listeners.forEach(l=>{typeof l[s]=="function"&&l[s](...a)}),o}})})}function WR(e,t){const n=e._chartjs;if(!n)return;const s=n.listeners,i=s.indexOf(t);i!==-1&&s.splice(i,1),!(s.length>0)&&(OV.forEach(a=>{delete e[a]}),delete e._chartjs)}function PV(e){const t=new Set(e);return t.size===e.length?e:Array.from(t)}const IV=(function(){return typeof window>"u"?function(e){return e()}:window.requestAnimationFrame})();function LV(e,t){let n=[],s=!1;return function(...i){n=i,s||(s=!0,IV.call(window,()=>{s=!1,e.apply(t,n)}))}}function OSe(e,t){let n;return function(...s){return t?(clearTimeout(n),n=setTimeout(e,t,s)):e.apply(this,s),t}}const uN=e=>e==="start"?"left":e==="end"?"right":"center",zs=(e,t,n)=>e==="start"?t:e==="end"?n:(t+n)/2,PSe=(e,t,n,s)=>e===(s?"left":"right")?n:e==="center"?(t+n)/2:t;function BV(e,t,n){const s=t.length;let i=0,a=s;if(e._sorted){const{iScale:o,vScale:l,_parsed:c}=e,d=e.dataset&&e.dataset.options?e.dataset.options.spanGaps:null,f=o.axis,{min:p,max:m,minDefined:g,maxDefined:b}=o.getUserBounds();if(g){if(i=Math.min(Gc(c,f,p).lo,n?s:Gc(t,f,o.getPixelForValue(p)).lo),d){const _=c.slice(0,i+1).reverse().findIndex(w=>!Tt(w[l.axis]));i-=Math.max(0,_)}i=Ws(i,0,s-1)}if(b){let _=Math.max(Gc(c,o.axis,m,!0).hi+1,n?0:Gc(t,f,o.getPixelForValue(m),!0).hi+1);if(d){const w=c.slice(_-1).findIndex(A=>!Tt(A[l.axis]));_+=Math.max(0,w)}a=Ws(_,i,s)-i}else a=s-i}return{start:i,count:a}}function zV(e){const{xScale:t,yScale:n,_scaleRanges:s}=e,i={xmin:t.min,xmax:t.max,ymin:n.min,ymax:n.max};if(!s)return e._scaleRanges=i,!0;const a=s.xmin!==t.min||s.xmax!==t.max||s.ymin!==n.min||s.ymax!==n.max;return Object.assign(s,i),a}const qg=e=>e===0||e===1,qR=(e,t,n)=>-(Math.pow(2,10*(e-=1))*Math.sin((e-t)*_n/n)),GR=(e,t,n)=>Math.pow(2,-10*e)*Math.sin((e-t)*_n/n)+1,bp={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>-e*(e-2),easeInOutQuad:e=>(e/=.5)<1?.5*e*e:-.5*(--e*(e-2)-1),easeInCubic:e=>e*e*e,easeOutCubic:e=>(e-=1)*e*e+1,easeInOutCubic:e=>(e/=.5)<1?.5*e*e*e:.5*((e-=2)*e*e+2),easeInQuart:e=>e*e*e*e,easeOutQuart:e=>-((e-=1)*e*e*e-1),easeInOutQuart:e=>(e/=.5)<1?.5*e*e*e*e:-.5*((e-=2)*e*e*e-2),easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>(e-=1)*e*e*e*e+1,easeInOutQuint:e=>(e/=.5)<1?.5*e*e*e*e*e:.5*((e-=2)*e*e*e*e+2),easeInSine:e=>-Math.cos(e*ls)+1,easeOutSine:e=>Math.sin(e*ls),easeInOutSine:e=>-.5*(Math.cos(Lt*e)-1),easeInExpo:e=>e===0?0:Math.pow(2,10*(e-1)),easeOutExpo:e=>e===1?1:-Math.pow(2,-10*e)+1,easeInOutExpo:e=>qg(e)?e:e<.5?.5*Math.pow(2,10*(e*2-1)):.5*(-Math.pow(2,-10*(e*2-1))+2),easeInCirc:e=>e>=1?e:-(Math.sqrt(1-e*e)-1),easeOutCirc:e=>Math.sqrt(1-(e-=1)*e),easeInOutCirc:e=>(e/=.5)<1?-.5*(Math.sqrt(1-e*e)-1):.5*(Math.sqrt(1-(e-=2)*e)+1),easeInElastic:e=>qg(e)?e:qR(e,.075,.3),easeOutElastic:e=>qg(e)?e:GR(e,.075,.3),easeInOutElastic(e){return qg(e)?e:e<.5?.5*qR(e*2,.1125,.45):.5+.5*GR(e*2-1,.1125,.45)},easeInBack(e){return e*e*((1.70158+1)*e-1.70158)},easeOutBack(e){return(e-=1)*e*((1.70158+1)*e+1.70158)+1},easeInOutBack(e){let t=1.70158;return(e/=.5)<1?.5*(e*e*(((t*=1.525)+1)*e-t)):.5*((e-=2)*e*(((t*=1.525)+1)*e+t)+2)},easeInBounce:e=>1-bp.easeOutBounce(1-e),easeOutBounce(e){return e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375},easeInOutBounce:e=>e<.5?bp.easeInBounce(e*2)*.5:bp.easeOutBounce(e*2-1)*.5+.5};function dN(e){if(e&&typeof e=="object"){const t=e.toString();return t==="[object CanvasPattern]"||t==="[object CanvasGradient]"}return!1}function KR(e){return dN(e)?e:new qp(e)}function SA(e){return dN(e)?e:new qp(e).saturate(.5).darken(.1).hexString()}const ISe=["x","y","borderWidth","radius","tension"],LSe=["color","borderColor","backgroundColor"];function BSe(e){e.set("animation",{delay:void 0,duration:1e3,easing:"easeOutQuart",fn:void 0,from:void 0,loop:void 0,to:void 0,type:void 0}),e.describe("animation",{_fallback:!1,_indexable:!1,_scriptable:t=>t!=="onProgress"&&t!=="onComplete"&&t!=="fn"}),e.set("animations",{colors:{type:"color",properties:LSe},numbers:{type:"number",properties:ISe}}),e.describe("animations",{_fallback:"animation"}),e.set("transitions",{active:{animation:{duration:400}},resize:{animation:{duration:0}},show:{animations:{colors:{from:"transparent"},visible:{type:"boolean",duration:0}}},hide:{animations:{colors:{to:"transparent"},visible:{type:"boolean",easing:"linear",fn:t=>t|0}}}})}function zSe(e){e.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})}const YR=new Map;function $Se(e,t){t=t||{};const n=e+JSON.stringify(t);let s=YR.get(n);return s||(s=new Intl.NumberFormat(e,t),YR.set(n,s)),s}function hN(e,t,n){return $Se(t,n).format(e)}const VSe={values(e){return Wn(e)?e:""+e},numeric(e,t,n){if(e===0)return"0";const s=this.chart.options.locale;let i,a=e;if(n.length>1){const d=Math.max(Math.abs(n[0].value),Math.abs(n[n.length-1].value));(d<1e-4||d>1e15)&&(i="scientific"),a=USe(e,n)}const o=RV(Math.abs(a)),l=isNaN(o)?1:Math.max(Math.min(-1*Math.floor(o),20),0),c={notation:i,minimumFractionDigits:l,maximumFractionDigits:l};return Object.assign(c,this.options.ticks.format),hN(e,s,c)}};function USe(e,t){let n=t.length>3?t[2].value-t[1].value:t[1].value-t[0].value;return Math.abs(n)>=1&&e!==Math.floor(e)&&(n=e-Math.floor(e)),n}var $V={formatters:VSe};function HSe(e){e.set("scale",{display:!0,offset:!1,reverse:!1,beginAtZero:!1,bounds:"ticks",clip:!0,grace:0,grid:{display:!0,lineWidth:1,drawOnChartArea:!0,drawTicks:!0,tickLength:8,tickWidth:(t,n)=>n.lineWidth,tickColor:(t,n)=>n.color,offset:!1},border:{display:!0,dash:[],dashOffset:0,width:1},title:{display:!1,text:"",padding:{top:4,bottom:4}},ticks:{minRotation:0,maxRotation:50,mirror:!1,textStrokeWidth:0,textStrokeColor:"",padding:3,display:!0,autoSkip:!0,autoSkipPadding:3,labelOffset:0,callback:$V.formatters.values,minor:{},major:{},align:"center",crossAlign:"near",showLabelBackdrop:!1,backdropColor:"rgba(255, 255, 255, 0.75)",backdropPadding:2}}),e.route("scale.ticks","color","","color"),e.route("scale.grid","color","","borderColor"),e.route("scale.border","color","","borderColor"),e.route("scale.title","color","","color"),e.describe("scale",{_fallback:!1,_scriptable:t=>!t.startsWith("before")&&!t.startsWith("after")&&t!=="callback"&&t!=="parser",_indexable:t=>t!=="borderDash"&&t!=="tickBorderDash"&&t!=="dash"}),e.describe("scales",{_fallback:"scale"}),e.describe("scale.ticks",{_scriptable:t=>t!=="backdropPadding"&&t!=="callback",_indexable:t=>t!=="backdropPadding"})}const fu=Object.create(null),uC=Object.create(null);function vp(e,t){if(!t)return e;const n=t.split(".");for(let s=0,i=n.length;s<i;++s){const a=n[s];e=e[a]||(e[a]=Object.create(null))}return e}function CA(e,t,n){return typeof t=="string"?Gp(vp(e,t),n):Gp(vp(e,""),t)}class WSe{constructor(t,n){this.animation=void 0,this.backgroundColor="rgba(0,0,0,0.1)",this.borderColor="rgba(0,0,0,0.1)",this.color="#666",this.datasets={},this.devicePixelRatio=s=>s.chart.platform.getDevicePixelRatio(),this.elements={},this.events=["mousemove","mouseout","click","touchstart","touchmove"],this.font={family:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",size:12,style:"normal",lineHeight:1.2,weight:null},this.hover={},this.hoverBackgroundColor=(s,i)=>SA(i.backgroundColor),this.hoverBorderColor=(s,i)=>SA(i.borderColor),this.hoverColor=(s,i)=>SA(i.color),this.indexAxis="x",this.interaction={mode:"nearest",intersect:!0,includeInvisible:!1},this.maintainAspectRatio=!0,this.onHover=null,this.onClick=null,this.parsing=!0,this.plugins={},this.responsive=!0,this.scale=void 0,this.scales={},this.showLine=!0,this.drawActiveElementsOnTop=!0,this.describe(t),this.apply(n)}set(t,n){return CA(this,t,n)}get(t){return vp(this,t)}describe(t,n){return CA(uC,t,n)}override(t,n){return CA(fu,t,n)}route(t,n,s,i){const a=vp(this,t),o=vp(this,s),l="_"+n;Object.defineProperties(a,{[l]:{value:a[n],writable:!0},[n]:{enumerable:!0,get(){const c=this[l],d=o[i];return xt(c)?Object.assign({},d,c):it(c,d)},set(c){this[l]=c}}})}apply(t){t.forEach(n=>n(this))}}var Rn=new WSe({_scriptable:e=>!e.startsWith("on"),_indexable:e=>e!=="events",hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[BSe,zSe,HSe]);function qSe(e){return!e||Tt(e.size)||Tt(e.family)?null:(e.style?e.style+" ":"")+(e.weight?e.weight+" ":"")+e.size+"px "+e.family}function QR(e,t,n,s,i){let a=t[i];return a||(a=t[i]=e.measureText(i).width,n.push(i)),a>s&&(s=a),s}function Tc(e,t,n){const s=e.currentDevicePixelRatio,i=n!==0?Math.max(n/2,.5):0;return Math.round((t-i)*s)/s+i}function XR(e,t){!t&&!e||(t=t||e.getContext("2d"),t.save(),t.resetTransform(),t.clearRect(0,0,e.width,e.height),t.restore())}function dC(e,t,n,s){VV(e,t,n,s,null)}function VV(e,t,n,s,i){let a,o,l,c,d,f,p,m;const g=t.pointStyle,b=t.rotation,_=t.radius;let w=(b||0)*SSe;if(g&&typeof g=="object"&&(a=g.toString(),a==="[object HTMLImageElement]"||a==="[object HTMLCanvasElement]")){e.save(),e.translate(n,s),e.rotate(w),e.drawImage(g,-g.width/2,-g.height/2,g.width,g.height),e.restore();return}if(!(isNaN(_)||_<=0)){switch(e.beginPath(),g){default:i?e.ellipse(n,s,i/2,_,0,0,_n):e.arc(n,s,_,0,_n),e.closePath();break;case"triangle":f=i?i/2:_,e.moveTo(n+Math.sin(w)*f,s-Math.cos(w)*_),w+=VR,e.lineTo(n+Math.sin(w)*f,s-Math.cos(w)*_),w+=VR,e.lineTo(n+Math.sin(w)*f,s-Math.cos(w)*_),e.closePath();break;case"rectRounded":d=_*.516,c=_-d,o=Math.cos(w+Fc)*c,p=Math.cos(w+Fc)*(i?i/2-d:c),l=Math.sin(w+Fc)*c,m=Math.sin(w+Fc)*(i?i/2-d:c),e.arc(n-p,s-l,d,w-Lt,w-ls),e.arc(n+m,s-o,d,w-ls,w),e.arc(n+p,s+l,d,w,w+ls),e.arc(n-m,s+o,d,w+ls,w+Lt),e.closePath();break;case"rect":if(!b){c=Math.SQRT1_2*_,f=i?i/2:c,e.rect(n-f,s-c,2*f,2*c);break}w+=Fc;case"rectRot":p=Math.cos(w)*(i?i/2:_),o=Math.cos(w)*_,l=Math.sin(w)*_,m=Math.sin(w)*(i?i/2:_),e.moveTo(n-p,s-l),e.lineTo(n+m,s-o),e.lineTo(n+p,s+l),e.lineTo(n-m,s+o),e.closePath();break;case"crossRot":w+=Fc;case"cross":p=Math.cos(w)*(i?i/2:_),o=Math.cos(w)*_,l=Math.sin(w)*_,m=Math.sin(w)*(i?i/2:_),e.moveTo(n-p,s-l),e.lineTo(n+p,s+l),e.moveTo(n+m,s-o),e.lineTo(n-m,s+o);break;case"star":p=Math.cos(w)*(i?i/2:_),o=Math.cos(w)*_,l=Math.sin(w)*_,m=Math.sin(w)*(i?i/2:_),e.moveTo(n-p,s-l),e.lineTo(n+p,s+l),e.moveTo(n+m,s-o),e.lineTo(n-m,s+o),w+=Fc,p=Math.cos(w)*(i?i/2:_),o=Math.cos(w)*_,l=Math.sin(w)*_,m=Math.sin(w)*(i?i/2:_),e.moveTo(n-p,s-l),e.lineTo(n+p,s+l),e.moveTo(n+m,s-o),e.lineTo(n-m,s+o);break;case"line":o=i?i/2:Math.cos(w)*_,l=Math.sin(w)*_,e.moveTo(n-o,s-l),e.lineTo(n+o,s+l);break;case"dash":e.moveTo(n,s),e.lineTo(n+Math.cos(w)*(i?i/2:_),s+Math.sin(w)*_);break;case!1:e.closePath();break}e.fill(),t.borderWidth>0&&e.stroke()}}function Qp(e,t,n){return n=n||.5,!t||e&&e.x>t.left-n&&e.x<t.right+n&&e.y>t.top-n&&e.y<t.bottom+n}function ly(e,t){e.save(),e.beginPath(),e.rect(t.left,t.top,t.right-t.left,t.bottom-t.top),e.clip()}function cy(e){e.restore()}function GSe(e,t,n,s,i){if(!t)return e.lineTo(n.x,n.y);if(i==="middle"){const a=(t.x+n.x)/2;e.lineTo(a,t.y),e.lineTo(a,n.y)}else i==="after"!=!!s?e.lineTo(t.x,n.y):e.lineTo(n.x,t.y);e.lineTo(n.x,n.y)}function KSe(e,t,n,s){if(!t)return e.lineTo(n.x,n.y);e.bezierCurveTo(s?t.cp1x:t.cp2x,s?t.cp1y:t.cp2y,s?n.cp2x:n.cp1x,s?n.cp2y:n.cp1y,n.x,n.y)}function YSe(e,t){t.translation&&e.translate(t.translation[0],t.translation[1]),Tt(t.rotation)||e.rotate(t.rotation),t.color&&(e.fillStyle=t.color),t.textAlign&&(e.textAlign=t.textAlign),t.textBaseline&&(e.textBaseline=t.textBaseline)}function QSe(e,t,n,s,i){if(i.strikethrough||i.underline){const a=e.measureText(s),o=t-a.actualBoundingBoxLeft,l=t+a.actualBoundingBoxRight,c=n-a.actualBoundingBoxAscent,d=n+a.actualBoundingBoxDescent,f=i.strikethrough?(c+d)/2:d;e.strokeStyle=e.fillStyle,e.beginPath(),e.lineWidth=i.decorationWidth||2,e.moveTo(o,f),e.lineTo(l,f),e.stroke()}}function XSe(e,t){const n=e.fillStyle;e.fillStyle=t.color,e.fillRect(t.left,t.top,t.width,t.height),e.fillStyle=n}function Xp(e,t,n,s,i,a={}){const o=Wn(t)?t:[t],l=a.strokeWidth>0&&a.strokeColor!=="";let c,d;for(e.save(),e.font=i.string,YSe(e,a),c=0;c<o.length;++c)d=o[c],a.backdrop&&XSe(e,a.backdrop),l&&(a.strokeColor&&(e.strokeStyle=a.strokeColor),Tt(a.strokeWidth)||(e.lineWidth=a.strokeWidth),e.strokeText(d,n,s,a.maxWidth)),e.fillText(d,n,s,a.maxWidth),QSe(e,n,s,d,a),s+=Number(i.lineHeight);e.restore()}function z0(e,t){const{x:n,y:s,w:i,h:a,radius:o}=t;e.arc(n+o.topLeft,s+o.topLeft,o.topLeft,1.5*Lt,Lt,!0),e.lineTo(n,s+a-o.bottomLeft),e.arc(n+o.bottomLeft,s+a-o.bottomLeft,o.bottomLeft,Lt,ls,!0),e.lineTo(n+i-o.bottomRight,s+a),e.arc(n+i-o.bottomRight,s+a-o.bottomRight,o.bottomRight,ls,0,!0),e.lineTo(n+i,s+o.topRight),e.arc(n+i-o.topRight,s+o.topRight,o.topRight,0,-ls,!0),e.lineTo(n+o.topLeft,s)}const JSe=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,ZSe=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;function eCe(e,t){const n=(""+e).match(JSe);if(!n||n[1]==="normal")return t*1.2;switch(e=+n[2],n[3]){case"px":return e;case"%":e/=100;break}return t*e}const tCe=e=>+e||0;function fN(e,t){const n={},s=xt(t),i=s?Object.keys(t):t,a=xt(e)?s?o=>it(e[o],e[t[o]]):o=>e[o]:()=>e;for(const o of i)n[o]=tCe(a(o));return n}function UV(e){return fN(e,{top:"y",right:"x",bottom:"y",left:"x"})}function Id(e){return fN(e,["topLeft","topRight","bottomLeft","bottomRight"])}function Lr(e){const t=UV(e);return t.width=t.left+t.right,t.height=t.top+t.bottom,t}function qs(e,t){e=e||{},t=t||Rn.font;let n=it(e.size,t.size);typeof n=="string"&&(n=parseInt(n,10));let s=it(e.style,t.style);s&&!(""+s).match(ZSe)&&(console.warn('Invalid font style specified: "'+s+'"'),s=void 0);const i={family:it(e.family,t.family),lineHeight:eCe(it(e.lineHeight,t.lineHeight),n),size:n,style:s,weight:it(e.weight,t.weight),string:""};return i.string=qSe(i),i}function Gg(e,t,n,s){let i,a,o;for(i=0,a=e.length;i<a;++i)if(o=e[i],o!==void 0&&o!==void 0)return o}function nCe(e,t,n){const{min:s,max:i}=e,a=TV(t,(i-s)/2),o=(l,c)=>n&&l===0?0:l+c;return{min:o(s,-Math.abs(a)),max:o(i,a)}}function wu(e,t){return Object.assign(Object.create(e),t)}function pN(e,t=[""],n,s,i=()=>e[0]){const a=n||e;typeof s>"u"&&(s=GV("_fallback",e));const o={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:e,_rootScopes:a,_fallback:s,_getTarget:i,override:l=>pN([l,...e],t,a,s)};return new Proxy(o,{deleteProperty(l,c){return delete l[c],delete l._keys,delete e[0][c],!0},get(l,c){return WV(l,c,()=>uCe(c,t,e,l))},getOwnPropertyDescriptor(l,c){return Reflect.getOwnPropertyDescriptor(l._scopes[0],c)},getPrototypeOf(){return Reflect.getPrototypeOf(e[0])},has(l,c){return ZR(l).includes(c)},ownKeys(l){return ZR(l)},set(l,c,d){const f=l._storage||(l._storage=i());return l[c]=f[c]=d,delete l._keys,!0}})}function Xd(e,t,n,s){const i={_cacheable:!1,_proxy:e,_context:t,_subProxy:n,_stack:new Set,_descriptors:HV(e,s),setContext:a=>Xd(e,a,n,s),override:a=>Xd(e.override(a),t,n,s)};return new Proxy(i,{deleteProperty(a,o){return delete a[o],delete e[o],!0},get(a,o,l){return WV(a,o,()=>iCe(a,o,l))},getOwnPropertyDescriptor(a,o){return a._descriptors.allKeys?Reflect.has(e,o)?{enumerable:!0,configurable:!0}:void 0:Reflect.getOwnPropertyDescriptor(e,o)},getPrototypeOf(){return Reflect.getPrototypeOf(e)},has(a,o){return Reflect.has(e,o)},ownKeys(){return Reflect.ownKeys(e)},set(a,o,l){return e[o]=l,delete a[o],!0}})}function HV(e,t={scriptable:!0,indexable:!0}){const{_scriptable:n=t.scriptable,_indexable:s=t.indexable,_allKeys:i=t.allKeys}=e;return{allKeys:i,scriptable:n,indexable:s,isScriptable:Ql(n)?n:()=>n,isIndexable:Ql(s)?s:()=>s}}const sCe=(e,t)=>e?e+lN(t):t,mN=(e,t)=>xt(t)&&e!=="adapters"&&(Object.getPrototypeOf(t)===null||t.constructor===Object);function WV(e,t,n){if(Object.prototype.hasOwnProperty.call(e,t)||t==="constructor")return e[t];const s=n();return e[t]=s,s}function iCe(e,t,n){const{_proxy:s,_context:i,_subProxy:a,_descriptors:o}=e;let l=s[t];return Ql(l)&&o.isScriptable(t)&&(l=rCe(t,l,e,n)),Wn(l)&&l.length&&(l=aCe(t,l,e,o.isIndexable)),mN(t,l)&&(l=Xd(l,i,a&&a[t],o)),l}function rCe(e,t,n,s){const{_proxy:i,_context:a,_subProxy:o,_stack:l}=n;if(l.has(e))throw new Error("Recursion detected: "+Array.from(l).join("->")+"->"+e);l.add(e);let c=t(a,o||s);return l.delete(e),mN(e,c)&&(c=xN(i._scopes,i,e,c)),c}function aCe(e,t,n,s){const{_proxy:i,_context:a,_subProxy:o,_descriptors:l}=n;if(typeof a.index<"u"&&s(e))return t[a.index%t.length];if(xt(t[0])){const c=t,d=i._scopes.filter(f=>f!==c);t=[];for(const f of c){const p=xN(d,i,e,f);t.push(Xd(p,a,o&&o[e],l))}}return t}function qV(e,t,n){return Ql(e)?e(t,n):e}const oCe=(e,t)=>e===!0?t:typeof e=="string"?hu(t,e):void 0;function lCe(e,t,n,s,i){for(const a of t){const o=oCe(n,a);if(o){e.add(o);const l=qV(o._fallback,n,i);if(typeof l<"u"&&l!==n&&l!==s)return l}else if(o===!1&&typeof s<"u"&&n!==s)return null}return!1}function xN(e,t,n,s){const i=t._rootScopes,a=qV(t._fallback,n,s),o=[...e,...i],l=new Set;l.add(s);let c=JR(l,o,n,a||n,s);return c===null||typeof a<"u"&&a!==n&&(c=JR(l,o,a,c,s),c===null)?!1:pN(Array.from(l),[""],i,a,()=>cCe(t,n,s))}function JR(e,t,n,s,i){for(;n;)n=lCe(e,t,n,s,i);return n}function cCe(e,t,n){const s=e._getTarget();t in s||(s[t]={});const i=s[t];return Wn(i)&&xt(n)?n:i||{}}function uCe(e,t,n,s){let i;for(const a of t)if(i=GV(sCe(a,e),n),typeof i<"u")return mN(e,i)?xN(n,s,e,i):i}function GV(e,t){for(const n of t){if(!n)continue;const s=n[e];if(typeof s<"u")return s}}function ZR(e){let t=e._keys;return t||(t=e._keys=dCe(e._scopes)),t}function dCe(e){const t=new Set;for(const n of e)for(const s of Object.keys(n).filter(i=>!i.startsWith("_")))t.add(s);return Array.from(t)}const hCe=Number.EPSILON||1e-14,Jd=(e,t)=>t<e.length&&!e[t].skip&&e[t],KV=e=>e==="x"?"y":"x";function fCe(e,t,n,s){const i=e.skip?t:e,a=t,o=n.skip?t:n,l=cC(a,i),c=cC(o,a);let d=l/(l+c),f=c/(l+c);d=isNaN(d)?0:d,f=isNaN(f)?0:f;const p=s*d,m=s*f;return{previous:{x:a.x-p*(o.x-i.x),y:a.y-p*(o.y-i.y)},next:{x:a.x+m*(o.x-i.x),y:a.y+m*(o.y-i.y)}}}function pCe(e,t,n){const s=e.length;let i,a,o,l,c,d=Jd(e,0);for(let f=0;f<s-1;++f)if(c=d,d=Jd(e,f+1),!(!c||!d)){if(gp(t[f],0,hCe)){n[f]=n[f+1]=0;continue}i=n[f]/t[f],a=n[f+1]/t[f],l=Math.pow(i,2)+Math.pow(a,2),!(l<=9)&&(o=3/Math.sqrt(l),n[f]=i*o*t[f],n[f+1]=a*o*t[f])}}function mCe(e,t,n="x"){const s=KV(n),i=e.length;let a,o,l,c=Jd(e,0);for(let d=0;d<i;++d){if(o=l,l=c,c=Jd(e,d+1),!l)continue;const f=l[n],p=l[s];o&&(a=(f-o[n])/3,l[`cp1${n}`]=f-a,l[`cp1${s}`]=p-a*t[d]),c&&(a=(c[n]-f)/3,l[`cp2${n}`]=f+a,l[`cp2${s}`]=p+a*t[d])}}function xCe(e,t="x"){const n=KV(t),s=e.length,i=Array(s).fill(0),a=Array(s);let o,l,c,d=Jd(e,0);for(o=0;o<s;++o)if(l=c,c=d,d=Jd(e,o+1),!!c){if(d){const f=d[t]-c[t];i[o]=f!==0?(d[n]-c[n])/f:0}a[o]=l?d?za(i[o-1])!==za(i[o])?0:(i[o-1]+i[o])/2:i[o-1]:i[o]}pCe(e,i,a),mCe(e,a,t)}function Kg(e,t,n){return Math.max(Math.min(e,n),t)}function gCe(e,t){let n,s,i,a,o,l=Qp(e[0],t);for(n=0,s=e.length;n<s;++n)o=a,a=l,l=n<s-1&&Qp(e[n+1],t),a&&(i=e[n],o&&(i.cp1x=Kg(i.cp1x,t.left,t.right),i.cp1y=Kg(i.cp1y,t.top,t.bottom)),l&&(i.cp2x=Kg(i.cp2x,t.left,t.right),i.cp2y=Kg(i.cp2y,t.top,t.bottom)))}function bCe(e,t,n,s,i){let a,o,l,c;if(t.spanGaps&&(e=e.filter(d=>!d.skip)),t.cubicInterpolationMode==="monotone")xCe(e,i);else{let d=s?e[e.length-1]:e[0];for(a=0,o=e.length;a<o;++a)l=e[a],c=fCe(d,l,e[Math.min(a+1,o-(s?0:1))%o],t.tension),l.cp1x=c.previous.x,l.cp1y=c.previous.y,l.cp2x=c.next.x,l.cp2y=c.next.y,d=l}t.capBezierPoints&&gCe(e,n)}function gN(){return typeof window<"u"&&typeof document<"u"}function bN(e){let t=e.parentNode;return t&&t.toString()==="[object ShadowRoot]"&&(t=t.host),t}function $0(e,t,n){let s;return typeof e=="string"?(s=parseInt(e,10),e.indexOf("%")!==-1&&(s=s/100*t.parentNode[n])):s=e,s}const uy=e=>e.ownerDocument.defaultView.getComputedStyle(e,null);function vCe(e,t){return uy(e).getPropertyValue(t)}const yCe=["top","right","bottom","left"];function Jc(e,t,n){const s={};n=n?"-"+n:"";for(let i=0;i<4;i++){const a=yCe[i];s[a]=parseFloat(e[t+"-"+a+n])||0}return s.width=s.left+s.right,s.height=s.top+s.bottom,s}const _Ce=(e,t,n)=>(e>0||t>0)&&(!n||!n.shadowRoot);function wCe(e,t){const n=e.touches,s=n&&n.length?n[0]:e,{offsetX:i,offsetY:a}=s;let o=!1,l,c;if(_Ce(i,a,e.target))l=i,c=a;else{const d=t.getBoundingClientRect();l=s.clientX-d.left,c=s.clientY-d.top,o=!0}return{x:l,y:c,box:o}}function Ic(e,t){if("native"in e)return e;const{canvas:n,currentDevicePixelRatio:s}=t,i=uy(n),a=i.boxSizing==="border-box",o=Jc(i,"padding"),l=Jc(i,"border","width"),{x:c,y:d,box:f}=wCe(e,n),p=o.left+(f&&l.left),m=o.top+(f&&l.top);let{width:g,height:b}=t;return a&&(g-=o.width+l.width,b-=o.height+l.height),{x:Math.round((c-p)/g*n.width/s),y:Math.round((d-m)/b*n.height/s)}}function ACe(e,t,n){let s,i;if(t===void 0||n===void 0){const a=e&&bN(e);if(!a)t=e.clientWidth,n=e.clientHeight;else{const o=a.getBoundingClientRect(),l=uy(a),c=Jc(l,"border","width"),d=Jc(l,"padding");t=o.width-d.width-c.width,n=o.height-d.height-c.height,s=$0(l.maxWidth,a,"clientWidth"),i=$0(l.maxHeight,a,"clientHeight")}}return{width:t,height:n,maxWidth:s||B0,maxHeight:i||B0}}const Ol=e=>Math.round(e*10)/10;function SCe(e,t,n,s){const i=uy(e),a=Jc(i,"margin"),o=$0(i.maxWidth,e,"clientWidth")||B0,l=$0(i.maxHeight,e,"clientHeight")||B0,c=ACe(e,t,n);let{width:d,height:f}=c;if(i.boxSizing==="content-box"){const m=Jc(i,"border","width"),g=Jc(i,"padding");d-=g.width+m.width,f-=g.height+m.height}return d=Math.max(0,d-a.width),f=Math.max(0,s?d/s:f-a.height),d=Ol(Math.min(d,o,c.maxWidth)),f=Ol(Math.min(f,l,c.maxHeight)),d&&!f&&(f=Ol(d/2)),(t!==void 0||n!==void 0)&&s&&c.height&&f>c.height&&(f=c.height,d=Ol(Math.floor(f*s))),{width:d,height:f}}function eD(e,t,n){const s=t||1,i=Ol(e.height*s),a=Ol(e.width*s);e.height=Ol(e.height),e.width=Ol(e.width);const o=e.canvas;return o.style&&(n||!o.style.height&&!o.style.width)&&(o.style.height=`${e.height}px`,o.style.width=`${e.width}px`),e.currentDevicePixelRatio!==s||o.height!==i||o.width!==a?(e.currentDevicePixelRatio=s,o.height=i,o.width=a,e.ctx.setTransform(s,0,0,s,0,0),!0):!1}const CCe=(function(){let e=!1;try{const t={get passive(){return e=!0,!1}};gN()&&(window.addEventListener("test",null,t),window.removeEventListener("test",null,t))}catch{}return e})();function tD(e,t){const n=vCe(e,t),s=n&&n.match(/^(\d+)(\.\d+)?px$/);return s?+s[1]:void 0}function Lc(e,t,n,s){return{x:e.x+n*(t.x-e.x),y:e.y+n*(t.y-e.y)}}function jCe(e,t,n,s){return{x:e.x+n*(t.x-e.x),y:s==="middle"?n<.5?e.y:t.y:s==="after"?n<1?e.y:t.y:n>0?t.y:e.y}}function NCe(e,t,n,s){const i={x:e.cp2x,y:e.cp2y},a={x:t.cp1x,y:t.cp1y},o=Lc(e,i,n),l=Lc(i,a,n),c=Lc(a,t,n),d=Lc(o,l,n),f=Lc(l,c,n);return Lc(d,f,n)}const kCe=function(e,t){return{x(n){return e+e+t-n},setWidth(n){t=n},textAlign(n){return n==="center"?n:n==="right"?"left":"right"},xPlus(n,s){return n-s},leftForLtr(n,s){return n-s}}},ECe=function(){return{x(e){return e},setWidth(e){},textAlign(e){return e},xPlus(e,t){return e+t},leftForLtr(e,t){return e}}};function Ld(e,t,n){return e?kCe(t,n):ECe()}function YV(e,t){let n,s;(t==="ltr"||t==="rtl")&&(n=e.canvas.style,s=[n.getPropertyValue("direction"),n.getPropertyPriority("direction")],n.setProperty("direction",t,"important"),e.prevTextDirection=s)}function QV(e,t){t!==void 0&&(delete e.prevTextDirection,e.canvas.style.setProperty("direction",t[0],t[1]))}function XV(e){return e==="angle"?{between:Yp,compare:FSe,normalize:Wi}:{between:So,compare:(t,n)=>t-n,normalize:t=>t}}function nD({start:e,end:t,count:n,loop:s,style:i}){return{start:e%n,end:t%n,loop:s&&(t-e+1)%n===0,style:i}}function FCe(e,t,n){const{property:s,start:i,end:a}=n,{between:o,normalize:l}=XV(s),c=t.length;let{start:d,end:f,loop:p}=e,m,g;if(p){for(d+=c,f+=c,m=0,g=c;m<g&&o(l(t[d%c][s]),i,a);++m)d--,f--;d%=c,f%=c}return f<d&&(f+=c),{start:d,end:f,loop:p,style:e.style}}function JV(e,t,n){if(!n)return[e];const{property:s,start:i,end:a}=n,o=t.length,{compare:l,between:c,normalize:d}=XV(s),{start:f,end:p,loop:m,style:g}=FCe(e,t,n),b=[];let _=!1,w=null,A,S,C;const E=()=>c(i,C,A)&&l(i,C)!==0,k=()=>l(a,A)===0||c(a,C,A),T=()=>_||E(),F=()=>!_||k();for(let M=f,I=f;M<=p;++M)S=t[M%o],!S.skip&&(A=d(S[s]),A!==C&&(_=c(A,i,a),w===null&&T()&&(w=l(A,i)===0?M:I),w!==null&&F()&&(b.push(nD({start:w,end:M,loop:m,count:o,style:g})),w=null),I=M,C=A));return w!==null&&b.push(nD({start:w,end:p,loop:m,count:o,style:g})),b}function ZV(e,t){const n=[],s=e.segments;for(let i=0;i<s.length;i++){const a=JV(s[i],e.points,t);a.length&&n.push(...a)}return n}function TCe(e,t,n,s){let i=0,a=t-1;if(n&&!s)for(;i<t&&!e[i].skip;)i++;for(;i<t&&e[i].skip;)i++;for(i%=t,n&&(a+=i);a>i&&e[a%t].skip;)a--;return a%=t,{start:i,end:a}}function MCe(e,t,n,s){const i=e.length,a=[];let o=t,l=e[t],c;for(c=t+1;c<=n;++c){const d=e[c%i];d.skip||d.stop?l.skip||(s=!1,a.push({start:t%i,end:(c-1)%i,loop:s}),t=o=d.stop?c:null):(o=c,l.skip&&(t=c)),l=d}return o!==null&&a.push({start:t%i,end:o%i,loop:s}),a}function RCe(e,t){const n=e.points,s=e.options.spanGaps,i=n.length;if(!i)return[];const a=!!e._loop,{start:o,end:l}=TCe(n,i,a,s);if(s===!0)return sD(e,[{start:o,end:l,loop:a}],n,t);const c=l<o?l+i:l,d=!!e._fullLoop&&o===0&&l===i-1;return sD(e,MCe(n,o,c,d),n,t)}function sD(e,t,n,s){return!s||!s.setContext||!n?t:DCe(e,t,n,s)}function DCe(e,t,n,s){const i=e._chart.getContext(),a=iD(e.options),{_datasetIndex:o,options:{spanGaps:l}}=e,c=n.length,d=[];let f=a,p=t[0].start,m=p;function g(b,_,w,A){const S=l?-1:1;if(b!==_){for(b+=c;n[b%c].skip;)b-=S;for(;n[_%c].skip;)_+=S;b%c!==_%c&&(d.push({start:b%c,end:_%c,loop:w,style:A}),f=A,p=_%c)}}for(const b of t){p=l?p:b.start;let _=n[p%c],w;for(m=p+1;m<=b.end;m++){const A=n[m%c];w=iD(s.setContext(wu(i,{type:"segment",p0:_,p1:A,p0DataIndex:(m-1)%c,p1DataIndex:m%c,datasetIndex:o}))),OCe(w,f)&&g(p,m-1,b.loop,f),_=A,f=w}p<m-1&&g(p,m-1,b.loop,f)}return d}function iD(e){return{backgroundColor:e.backgroundColor,borderCapStyle:e.borderCapStyle,borderDash:e.borderDash,borderDashOffset:e.borderDashOffset,borderJoinStyle:e.borderJoinStyle,borderWidth:e.borderWidth,borderColor:e.borderColor}}function OCe(e,t){if(!t)return!1;const n=[],s=function(i,a){return dN(a)?(n.includes(a)||n.push(a),n.indexOf(a)):a};return JSON.stringify(e,s)!==JSON.stringify(t,s)}function Yg(e,t,n){return e.options.clip?e[n]:t[n]}function PCe(e,t){const{xScale:n,yScale:s}=e;return n&&s?{left:Yg(n,t,"left"),right:Yg(n,t,"right"),top:Yg(s,t,"top"),bottom:Yg(s,t,"bottom")}:t}function eU(e,t){const n=t._clip;if(n.disabled)return!1;const s=PCe(t,e.chartArea);return{left:n.left===!1?0:s.left-(n.left===!0?0:n.left),right:n.right===!1?e.width:s.right+(n.right===!0?0:n.right),top:n.top===!1?0:s.top-(n.top===!0?0:n.top),bottom:n.bottom===!1?e.height:s.bottom+(n.bottom===!0?0:n.bottom)}}class ICe{constructor(){this._request=null,this._charts=new Map,this._running=!1,this._lastDate=void 0}_notify(t,n,s,i){const a=n.listeners[i],o=n.duration;a.forEach(l=>l({chart:t,initial:n.initial,numSteps:o,currentStep:Math.min(s-n.start,o)}))}_refresh(){this._request||(this._running=!0,this._request=IV.call(window,()=>{this._update(),this._request=null,this._running&&this._refresh()}))}_update(t=Date.now()){let n=0;this._charts.forEach((s,i)=>{if(!s.running||!s.items.length)return;const a=s.items;let o=a.length-1,l=!1,c;for(;o>=0;--o)c=a[o],c._active?(c._total>s.duration&&(s.duration=c._total),c.tick(t),l=!0):(a[o]=a[a.length-1],a.pop());l&&(i.draw(),this._notify(i,s,t,"progress")),a.length||(s.running=!1,this._notify(i,s,t,"complete"),s.initial=!1),n+=a.length}),this._lastDate=t,n===0&&(this._running=!1)}_getAnims(t){const n=this._charts;let s=n.get(t);return s||(s={running:!1,initial:!0,items:[],listeners:{complete:[],progress:[]}},n.set(t,s)),s}listen(t,n,s){this._getAnims(t).listeners[n].push(s)}add(t,n){!n||!n.length||this._getAnims(t).items.push(...n)}has(t){return this._getAnims(t).items.length>0}start(t){const n=this._charts.get(t);n&&(n.running=!0,n.start=Date.now(),n.duration=n.items.reduce((s,i)=>Math.max(s,i._duration),0),this._refresh())}running(t){if(!this._running)return!1;const n=this._charts.get(t);return!(!n||!n.running||!n.items.length)}stop(t){const n=this._charts.get(t);if(!n||!n.items.length)return;const s=n.items;let i=s.length-1;for(;i>=0;--i)s[i].cancel();n.items=[],this._notify(t,n,Date.now(),"complete")}remove(t){return this._charts.delete(t)}}var vo=new ICe;const rD="transparent",LCe={boolean(e,t,n){return n>.5?t:e},color(e,t,n){const s=KR(e||rD),i=s.valid&&KR(t||rD);return i&&i.valid?i.mix(s,n).hexString():t},number(e,t,n){return e+(t-e)*n}};class BCe{constructor(t,n,s,i){const a=n[s];i=Gg([t.to,i,a,t.from]);const o=Gg([t.from,a,i]);this._active=!0,this._fn=t.fn||LCe[t.type||typeof o],this._easing=bp[t.easing]||bp.linear,this._start=Math.floor(Date.now()+(t.delay||0)),this._duration=this._total=Math.floor(t.duration),this._loop=!!t.loop,this._target=n,this._prop=s,this._from=o,this._to=i,this._promises=void 0}active(){return this._active}update(t,n,s){if(this._active){this._notify(!1);const i=this._target[this._prop],a=s-this._start,o=this._duration-a;this._start=s,this._duration=Math.floor(Math.max(o,t.duration)),this._total+=a,this._loop=!!t.loop,this._to=Gg([t.to,n,i,t.from]),this._from=Gg([t.from,i,n])}}cancel(){this._active&&(this.tick(Date.now()),this._active=!1,this._notify(!1))}tick(t){const n=t-this._start,s=this._duration,i=this._prop,a=this._from,o=this._loop,l=this._to;let c;if(this._active=a!==l&&(o||n<s),!this._active){this._target[i]=l,this._notify(!0);return}if(n<0){this._target[i]=a;return}c=n/s%2,c=o&&c>1?2-c:c,c=this._easing(Math.min(1,Math.max(0,c))),this._target[i]=this._fn(a,l,c)}wait(){const t=this._promises||(this._promises=[]);return new Promise((n,s)=>{t.push({res:n,rej:s})})}_notify(t){const n=t?"res":"rej",s=this._promises||[];for(let i=0;i<s.length;i++)s[i][n]()}}class tU{constructor(t,n){this._chart=t,this._properties=new Map,this.configure(n)}configure(t){if(!xt(t))return;const n=Object.keys(Rn.animation),s=this._properties;Object.getOwnPropertyNames(t).forEach(i=>{const a=t[i];if(!xt(a))return;const o={};for(const l of n)o[l]=a[l];(Wn(a.properties)&&a.properties||[i]).forEach(l=>{(l===i||!s.has(l))&&s.set(l,o)})})}_animateOptions(t,n){const s=n.options,i=$Ce(t,s);if(!i)return[];const a=this._createAnimations(i,s);return s.$shared&&zCe(t.options.$animations,s).then(()=>{t.options=s},()=>{}),a}_createAnimations(t,n){const s=this._properties,i=[],a=t.$animations||(t.$animations={}),o=Object.keys(n),l=Date.now();let c;for(c=o.length-1;c>=0;--c){const d=o[c];if(d.charAt(0)==="$")continue;if(d==="options"){i.push(...this._animateOptions(t,n));continue}const f=n[d];let p=a[d];const m=s.get(d);if(p)if(m&&p.active()){p.update(m,f,l);continue}else p.cancel();if(!m||!m.duration){t[d]=f;continue}a[d]=p=new BCe(m,t,d,f),i.push(p)}return i}update(t,n){if(this._properties.size===0){Object.assign(t,n);return}const s=this._createAnimations(t,n);if(s.length)return vo.add(this._chart,s),!0}}function zCe(e,t){const n=[],s=Object.keys(t);for(let i=0;i<s.length;i++){const a=e[s[i]];a&&a.active()&&n.push(a.wait())}return Promise.all(n)}function $Ce(e,t){if(!t)return;let n=e.options;if(!n){e.options=t;return}return n.$shared&&(e.options=n=Object.assign({},n,{$shared:!1,$animations:{}})),n}function aD(e,t){const n=e&&e.options||{},s=n.reverse,i=n.min===void 0?t:0,a=n.max===void 0?t:0;return{start:s?a:i,end:s?i:a}}function VCe(e,t,n){if(n===!1)return!1;const s=aD(e,n),i=aD(t,n);return{top:i.end,right:s.end,bottom:i.start,left:s.start}}function UCe(e){let t,n,s,i;return xt(e)?(t=e.top,n=e.right,s=e.bottom,i=e.left):t=n=s=i=e,{top:t,right:n,bottom:s,left:i,disabled:e===!1}}function nU(e,t){const n=[],s=e._getSortedDatasetMetas(t);let i,a;for(i=0,a=s.length;i<a;++i)n.push(s[i].index);return n}function oD(e,t,n,s={}){const i=e.keys,a=s.mode==="single";let o,l,c,d;if(t===null)return;let f=!1;for(o=0,l=i.length;o<l;++o){if(c=+i[o],c===n){if(f=!0,s.all)continue;break}d=e.values[c],Js(d)&&(a||t===0||za(t)===za(d))&&(t+=d)}return!f&&!s.all?0:t}function HCe(e,t){const{iScale:n,vScale:s}=t,i=n.axis==="x"?"x":"y",a=s.axis==="x"?"x":"y",o=Object.keys(e),l=new Array(o.length);let c,d,f;for(c=0,d=o.length;c<d;++c)f=o[c],l[c]={[i]:f,[a]:e[f]};return l}function jA(e,t){const n=e&&e.options.stacked;return n||n===void 0&&t.stack!==void 0}function WCe(e,t,n){return`${e.id}.${t.id}.${n.stack||n.type}`}function qCe(e){const{min:t,max:n,minDefined:s,maxDefined:i}=e.getUserBounds();return{min:s?t:Number.NEGATIVE_INFINITY,max:i?n:Number.POSITIVE_INFINITY}}function GCe(e,t,n){const s=e[t]||(e[t]={});return s[n]||(s[n]={})}function lD(e,t,n,s){for(const i of t.getMatchingVisibleMetas(s).reverse()){const a=e[i.index];if(n&&a>0||!n&&a<0)return i.index}return null}function cD(e,t){const{chart:n,_cachedMeta:s}=e,i=n._stacks||(n._stacks={}),{iScale:a,vScale:o,index:l}=s,c=a.axis,d=o.axis,f=WCe(a,o,s),p=t.length;let m;for(let g=0;g<p;++g){const b=t[g],{[c]:_,[d]:w}=b,A=b._stacks||(b._stacks={});m=A[d]=GCe(i,f,_),m[l]=w,m._top=lD(m,o,!0,s.type),m._bottom=lD(m,o,!1,s.type);const S=m._visualValues||(m._visualValues={});S[l]=w}}function NA(e,t){const n=e.scales;return Object.keys(n).filter(s=>n[s].axis===t).shift()}function KCe(e,t){return wu(e,{active:!1,dataset:void 0,datasetIndex:t,index:t,mode:"default",type:"dataset"})}function YCe(e,t,n){return wu(e,{active:!1,dataIndex:t,parsed:void 0,raw:void 0,element:n,index:t,mode:"default",type:"data"})}function Pf(e,t){const n=e.controller.index,s=e.vScale&&e.vScale.axis;if(s){t=t||e._parsed;for(const i of t){const a=i._stacks;if(!a||a[s]===void 0||a[s][n]===void 0)return;delete a[s][n],a[s]._visualValues!==void 0&&a[s]._visualValues[n]!==void 0&&delete a[s]._visualValues[n]}}}const kA=e=>e==="reset"||e==="none",uD=(e,t)=>t?e:Object.assign({},e),QCe=(e,t,n)=>e&&!t.hidden&&t._stacked&&{keys:nU(n,!0),values:null};class Km{static defaults={};static datasetElementType=null;static dataElementType=null;constructor(t,n){this.chart=t,this._ctx=t.ctx,this.index=n,this._cachedDataOpts={},this._cachedMeta=this.getMeta(),this._type=this._cachedMeta.type,this.options=void 0,this._parsing=!1,this._data=void 0,this._objectData=void 0,this._sharedOptions=void 0,this._drawStart=void 0,this._drawCount=void 0,this.enableOptionSharing=!1,this.supportsDecimation=!1,this.$context=void 0,this._syncList=[],this.datasetElementType=new.target.datasetElementType,this.dataElementType=new.target.dataElementType,this.initialize()}initialize(){const t=this._cachedMeta;this.configure(),this.linkScales(),t._stacked=jA(t.vScale,t),this.addElements(),this.options.fill&&!this.chart.isPluginEnabled("filler")&&console.warn("Tried to use the 'fill' option without the 'Filler' plugin enabled. Please import and register the 'Filler' plugin and make sure it is not disabled in the options")}updateIndex(t){this.index!==t&&Pf(this._cachedMeta),this.index=t}linkScales(){const t=this.chart,n=this._cachedMeta,s=this.getDataset(),i=(p,m,g,b)=>p==="x"?m:p==="r"?b:g,a=n.xAxisID=it(s.xAxisID,NA(t,"x")),o=n.yAxisID=it(s.yAxisID,NA(t,"y")),l=n.rAxisID=it(s.rAxisID,NA(t,"r")),c=n.indexAxis,d=n.iAxisID=i(c,a,o,l),f=n.vAxisID=i(c,o,a,l);n.xScale=this.getScaleForId(a),n.yScale=this.getScaleForId(o),n.rScale=this.getScaleForId(l),n.iScale=this.getScaleForId(d),n.vScale=this.getScaleForId(f)}getDataset(){return this.chart.data.datasets[this.index]}getMeta(){return this.chart.getDatasetMeta(this.index)}getScaleForId(t){return this.chart.scales[t]}_getOtherScale(t){const n=this._cachedMeta;return t===n.iScale?n.vScale:n.iScale}reset(){this._update("reset")}_destroy(){const t=this._cachedMeta;this._data&&WR(this._data,this),t._stacked&&Pf(t)}_dataCheck(){const t=this.getDataset(),n=t.data||(t.data=[]),s=this._data;if(xt(n)){const i=this._cachedMeta;this._data=HCe(n,i)}else if(s!==n){if(s){WR(s,this);const i=this._cachedMeta;Pf(i),i._parsed=[]}n&&Object.isExtensible(n)&&DSe(n,this),this._syncList=[],this._data=n}}addElements(){const t=this._cachedMeta;this._dataCheck(),this.datasetElementType&&(t.dataset=new this.datasetElementType)}buildOrUpdateElements(t){const n=this._cachedMeta,s=this.getDataset();let i=!1;this._dataCheck();const a=n._stacked;n._stacked=jA(n.vScale,n),n.stack!==s.stack&&(i=!0,Pf(n),n.stack=s.stack),this._resyncElements(t),(i||a!==n._stacked)&&(cD(this,n._parsed),n._stacked=jA(n.vScale,n))}configure(){const t=this.chart.config,n=t.datasetScopeKeys(this._type),s=t.getOptionScopes(this.getDataset(),n,!0);this.options=t.createResolver(s,this.getContext()),this._parsing=this.options.parsing,this._cachedDataOpts={}}parse(t,n){const{_cachedMeta:s,_data:i}=this,{iScale:a,_stacked:o}=s,l=a.axis;let c=t===0&&n===i.length?!0:s._sorted,d=t>0&&s._parsed[t-1],f,p,m;if(this._parsing===!1)s._parsed=i,s._sorted=!0,m=i;else{Wn(i[t])?m=this.parseArrayData(s,i,t,n):xt(i[t])?m=this.parseObjectData(s,i,t,n):m=this.parsePrimitiveData(s,i,t,n);const g=()=>p[l]===null||d&&p[l]<d[l];for(f=0;f<n;++f)s._parsed[f+t]=p=m[f],c&&(g()&&(c=!1),d=p);s._sorted=c}o&&cD(this,m)}parsePrimitiveData(t,n,s,i){const{iScale:a,vScale:o}=t,l=a.axis,c=o.axis,d=a.getLabels(),f=a===o,p=new Array(i);let m,g,b;for(m=0,g=i;m<g;++m)b=m+s,p[m]={[l]:f||a.parse(d[b],b),[c]:o.parse(n[b],b)};return p}parseArrayData(t,n,s,i){const{xScale:a,yScale:o}=t,l=new Array(i);let c,d,f,p;for(c=0,d=i;c<d;++c)f=c+s,p=n[f],l[c]={x:a.parse(p[0],f),y:o.parse(p[1],f)};return l}parseObjectData(t,n,s,i){const{xScale:a,yScale:o}=t,{xAxisKey:l="x",yAxisKey:c="y"}=this._parsing,d=new Array(i);let f,p,m,g;for(f=0,p=i;f<p;++f)m=f+s,g=n[m],d[f]={x:a.parse(hu(g,l),m),y:o.parse(hu(g,c),m)};return d}getParsed(t){return this._cachedMeta._parsed[t]}getDataElement(t){return this._cachedMeta.data[t]}applyStack(t,n,s){const i=this.chart,a=this._cachedMeta,o=n[t.axis],l={keys:nU(i,!0),values:n._stacks[t.axis]._visualValues};return oD(l,o,a.index,{mode:s})}updateRangeFromParsed(t,n,s,i){const a=s[n.axis];let o=a===null?NaN:a;const l=i&&s._stacks[n.axis];i&&l&&(i.values=l,o=oD(i,a,this._cachedMeta.index)),t.min=Math.min(t.min,o),t.max=Math.max(t.max,o)}getMinMax(t,n){const s=this._cachedMeta,i=s._parsed,a=s._sorted&&t===s.iScale,o=i.length,l=this._getOtherScale(t),c=QCe(n,s,this.chart),d={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY},{min:f,max:p}=qCe(l);let m,g;function b(){g=i[m];const _=g[l.axis];return!Js(g[t.axis])||f>_||p<_}for(m=0;m<o&&!(!b()&&(this.updateRangeFromParsed(d,t,g,c),a));++m);if(a){for(m=o-1;m>=0;--m)if(!b()){this.updateRangeFromParsed(d,t,g,c);break}}return d}getAllParsedValues(t){const n=this._cachedMeta._parsed,s=[];let i,a,o;for(i=0,a=n.length;i<a;++i)o=n[i][t.axis],Js(o)&&s.push(o);return s}getMaxOverflow(){return!1}getLabelAndValue(t){const n=this._cachedMeta,s=n.iScale,i=n.vScale,a=this.getParsed(t);return{label:s?""+s.getLabelForValue(a[s.axis]):"",value:i?""+i.getLabelForValue(a[i.axis]):""}}_update(t){const n=this._cachedMeta;this.update(t||"default"),n._clip=UCe(it(this.options.clip,VCe(n.xScale,n.yScale,this.getMaxOverflow())))}update(t){}draw(){const t=this._ctx,n=this.chart,s=this._cachedMeta,i=s.data||[],a=n.chartArea,o=[],l=this._drawStart||0,c=this._drawCount||i.length-l,d=this.options.drawActiveElementsOnTop;let f;for(s.dataset&&s.dataset.draw(t,a,l,c),f=l;f<l+c;++f){const p=i[f];p.hidden||(p.active&&d?o.push(p):p.draw(t,a))}for(f=0;f<o.length;++f)o[f].draw(t,a)}getStyle(t,n){const s=n?"active":"default";return t===void 0&&this._cachedMeta.dataset?this.resolveDatasetElementOptions(s):this.resolveDataElementOptions(t||0,s)}getContext(t,n,s){const i=this.getDataset();let a;if(t>=0&&t<this._cachedMeta.data.length){const o=this._cachedMeta.data[t];a=o.$context||(o.$context=YCe(this.getContext(),t,o)),a.parsed=this.getParsed(t),a.raw=i.data[t],a.index=a.dataIndex=t}else a=this.$context||(this.$context=KCe(this.chart.getContext(),this.index)),a.dataset=i,a.index=a.datasetIndex=this.index;return a.active=!!n,a.mode=s,a}resolveDatasetElementOptions(t){return this._resolveElementOptions(this.datasetElementType.id,t)}resolveDataElementOptions(t,n){return this._resolveElementOptions(this.dataElementType.id,n,t)}_resolveElementOptions(t,n="default",s){const i=n==="active",a=this._cachedDataOpts,o=t+"-"+n,l=a[o],c=this.enableOptionSharing&&Kp(s);if(l)return uD(l,c);const d=this.chart.config,f=d.datasetElementScopeKeys(this._type,t),p=i?[`${t}Hover`,"hover",t,""]:[t,""],m=d.getOptionScopes(this.getDataset(),f),g=Object.keys(Rn.elements[t]),b=()=>this.getContext(s,i,n),_=d.resolveNamedOptions(m,g,b,p);return _.$shared&&(_.$shared=c,a[o]=Object.freeze(uD(_,c))),_}_resolveAnimations(t,n,s){const i=this.chart,a=this._cachedDataOpts,o=`animation-${n}`,l=a[o];if(l)return l;let c;if(i.options.animation!==!1){const f=this.chart.config,p=f.datasetAnimationScopeKeys(this._type,n),m=f.getOptionScopes(this.getDataset(),p);c=f.createResolver(m,this.getContext(t,s,n))}const d=new tU(i,c&&c.animations);return c&&c._cacheable&&(a[o]=Object.freeze(d)),d}getSharedOptions(t){if(t.$shared)return this._sharedOptions||(this._sharedOptions=Object.assign({},t))}includeOptions(t,n){return!n||kA(t)||this.chart._animationsDisabled}_getSharedOptions(t,n){const s=this.resolveDataElementOptions(t,n),i=this._sharedOptions,a=this.getSharedOptions(s),o=this.includeOptions(n,a)||a!==i;return this.updateSharedOptions(a,n,s),{sharedOptions:a,includeOptions:o}}updateElement(t,n,s,i){kA(i)?Object.assign(t,s):this._resolveAnimations(n,i).update(t,s)}updateSharedOptions(t,n,s){t&&!kA(n)&&this._resolveAnimations(void 0,n).update(t,s)}_setStyle(t,n,s,i){t.active=i;const a=this.getStyle(n,i);this._resolveAnimations(n,s,i).update(t,{options:!i&&this.getSharedOptions(a)||a})}removeHoverStyle(t,n,s){this._setStyle(t,s,"active",!1)}setHoverStyle(t,n,s){this._setStyle(t,s,"active",!0)}_removeDatasetHoverStyle(){const t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!1)}_setDatasetHoverStyle(){const t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!0)}_resyncElements(t){const n=this._data,s=this._cachedMeta.data;for(const[l,c,d]of this._syncList)this[l](c,d);this._syncList=[];const i=s.length,a=n.length,o=Math.min(a,i);o&&this.parse(0,o),a>i?this._insertElements(i,a-i,t):a<i&&this._removeElements(a,i-a)}_insertElements(t,n,s=!0){const i=this._cachedMeta,a=i.data,o=t+n;let l;const c=d=>{for(d.length+=n,l=d.length-1;l>=o;l--)d[l]=d[l-n]};for(c(a),l=t;l<o;++l)a[l]=new this.dataElementType;this._parsing&&c(i._parsed),this.parse(t,n),s&&this.updateElements(a,t,n,"reset")}updateElements(t,n,s,i){}_removeElements(t,n){const s=this._cachedMeta;if(this._parsing){const i=s._parsed.splice(t,n);s._stacked&&Pf(s,i)}s.data.splice(t,n)}_sync(t){if(this._parsing)this._syncList.push(t);else{const[n,s,i]=t;this[n](s,i)}this.chart._dataChanges.push([this.index,...t])}_onDataPush(){const t=arguments.length;this._sync(["_insertElements",this.getDataset().data.length-t,t])}_onDataPop(){this._sync(["_removeElements",this._cachedMeta.data.length-1,1])}_onDataShift(){this._sync(["_removeElements",0,1])}_onDataSplice(t,n){n&&this._sync(["_removeElements",t,n]);const s=arguments.length-2;s&&this._sync(["_insertElements",t,s])}_onDataUnshift(){this._sync(["_insertElements",0,arguments.length])}}function XCe(e,t){if(!e._cache.$bar){const n=e.getMatchingVisibleMetas(t);let s=[];for(let i=0,a=n.length;i<a;i++)s=s.concat(n[i].controller.getAllParsedValues(e));e._cache.$bar=PV(s.sort((i,a)=>i-a))}return e._cache.$bar}function JCe(e){const t=e.iScale,n=XCe(t,e.type);let s=t._length,i,a,o,l;const c=()=>{o===32767||o===-32768||(Kp(l)&&(s=Math.min(s,Math.abs(o-l)||s)),l=o)};for(i=0,a=n.length;i<a;++i)o=t.getPixelForValue(n[i]),c();for(l=void 0,i=0,a=t.ticks.length;i<a;++i)o=t.getPixelForTick(i),c();return s}function ZCe(e,t,n,s){const i=n.barThickness;let a,o;return Tt(i)?(a=t.min*n.categoryPercentage,o=n.barPercentage):(a=i*s,o=1),{chunk:a/s,ratio:o,start:t.pixels[e]-a/2}}function e5e(e,t,n,s){const i=t.pixels,a=i[e];let o=e>0?i[e-1]:null,l=e<i.length-1?i[e+1]:null;const c=n.categoryPercentage;o===null&&(o=a-(l===null?t.end-t.start:l-a)),l===null&&(l=a+a-o);const d=a-(a-Math.min(o,l))/2*c;return{chunk:Math.abs(l-o)/2*c/s,ratio:n.barPercentage,start:d}}function t5e(e,t,n,s){const i=n.parse(e[0],s),a=n.parse(e[1],s),o=Math.min(i,a),l=Math.max(i,a);let c=o,d=l;Math.abs(o)>Math.abs(l)&&(c=l,d=o),t[n.axis]=d,t._custom={barStart:c,barEnd:d,start:i,end:a,min:o,max:l}}function sU(e,t,n,s){return Wn(e)?t5e(e,t,n,s):t[n.axis]=n.parse(e,s),t}function dD(e,t,n,s){const i=e.iScale,a=e.vScale,o=i.getLabels(),l=i===a,c=[];let d,f,p,m;for(d=n,f=n+s;d<f;++d)m=t[d],p={},p[i.axis]=l||i.parse(o[d],d),c.push(sU(m,p,a,d));return c}function EA(e){return e&&e.barStart!==void 0&&e.barEnd!==void 0}function n5e(e,t,n){return e!==0?za(e):(t.isHorizontal()?1:-1)*(t.min>=n?1:-1)}function s5e(e){let t,n,s,i,a;return e.horizontal?(t=e.base>e.x,n="left",s="right"):(t=e.base<e.y,n="bottom",s="top"),t?(i="end",a="start"):(i="start",a="end"),{start:n,end:s,reverse:t,top:i,bottom:a}}function i5e(e,t,n,s){let i=t.borderSkipped;const a={};if(!i){e.borderSkipped=a;return}if(i===!0){e.borderSkipped={top:!0,right:!0,bottom:!0,left:!0};return}const{start:o,end:l,reverse:c,top:d,bottom:f}=s5e(e);i==="middle"&&n&&(e.enableBorderRadius=!0,(n._top||0)===s?i=d:(n._bottom||0)===s?i=f:(a[hD(f,o,l,c)]=!0,i=d)),a[hD(i,o,l,c)]=!0,e.borderSkipped=a}function hD(e,t,n,s){return s?(e=r5e(e,t,n),e=fD(e,n,t)):e=fD(e,t,n),e}function r5e(e,t,n){return e===t?n:e===n?t:e}function fD(e,t,n){return e==="start"?t:e==="end"?n:e}function a5e(e,{inflateAmount:t},n){e.inflateAmount=t==="auto"?n===1?.33:0:t}class o5e extends Km{static id="bar";static defaults={datasetElementType:!1,dataElementType:"bar",categoryPercentage:.8,barPercentage:.9,grouped:!0,animations:{numbers:{type:"number",properties:["x","y","base","width","height"]}}};static overrides={scales:{_index_:{type:"category",offset:!0,grid:{offset:!0}},_value_:{type:"linear",beginAtZero:!0}}};parsePrimitiveData(t,n,s,i){return dD(t,n,s,i)}parseArrayData(t,n,s,i){return dD(t,n,s,i)}parseObjectData(t,n,s,i){const{iScale:a,vScale:o}=t,{xAxisKey:l="x",yAxisKey:c="y"}=this._parsing,d=a.axis==="x"?l:c,f=o.axis==="x"?l:c,p=[];let m,g,b,_;for(m=s,g=s+i;m<g;++m)_=n[m],b={},b[a.axis]=a.parse(hu(_,d),m),p.push(sU(hu(_,f),b,o,m));return p}updateRangeFromParsed(t,n,s,i){super.updateRangeFromParsed(t,n,s,i);const a=s._custom;a&&n===this._cachedMeta.vScale&&(t.min=Math.min(t.min,a.min),t.max=Math.max(t.max,a.max))}getMaxOverflow(){return 0}getLabelAndValue(t){const n=this._cachedMeta,{iScale:s,vScale:i}=n,a=this.getParsed(t),o=a._custom,l=EA(o)?"["+o.start+", "+o.end+"]":""+i.getLabelForValue(a[i.axis]);return{label:""+s.getLabelForValue(a[s.axis]),value:l}}initialize(){this.enableOptionSharing=!0,super.initialize();const t=this._cachedMeta;t.stack=this.getDataset().stack}update(t){const n=this._cachedMeta;this.updateElements(n.data,0,n.data.length,t)}updateElements(t,n,s,i){const a=i==="reset",{index:o,_cachedMeta:{vScale:l}}=this,c=l.getBasePixel(),d=l.isHorizontal(),f=this._getRuler(),{sharedOptions:p,includeOptions:m}=this._getSharedOptions(n,i);for(let g=n;g<n+s;g++){const b=this.getParsed(g),_=a||Tt(b[l.axis])?{base:c,head:c}:this._calculateBarValuePixels(g),w=this._calculateBarIndexPixels(g,f),A=(b._stacks||{})[l.axis],S={horizontal:d,base:_.base,enableBorderRadius:!A||EA(b._custom)||o===A._top||o===A._bottom,x:d?_.head:w.center,y:d?w.center:_.head,height:d?w.size:Math.abs(_.size),width:d?Math.abs(_.size):w.size};m&&(S.options=p||this.resolveDataElementOptions(g,t[g].active?"active":i));const C=S.options||t[g].options;i5e(S,C,A,o),a5e(S,C,f.ratio),this.updateElement(t[g],g,S,i)}}_getStacks(t,n){const{iScale:s}=this._cachedMeta,i=s.getMatchingVisibleMetas(this._type).filter(f=>f.controller.options.grouped),a=s.options.stacked,o=[],l=this._cachedMeta.controller.getParsed(n),c=l&&l[s.axis],d=f=>{const p=f._parsed.find(g=>g[s.axis]===c),m=p&&p[f.vScale.axis];if(Tt(m)||isNaN(m))return!0};for(const f of i)if(!(n!==void 0&&d(f))&&((a===!1||o.indexOf(f.stack)===-1||a===void 0&&f.stack===void 0)&&o.push(f.stack),f.index===t))break;return o.length||o.push(void 0),o}_getStackCount(t){return this._getStacks(void 0,t).length}_getAxisCount(){return this._getAxis().length}getFirstScaleIdForIndexAxis(){const t=this.chart.scales,n=this.chart.options.indexAxis;return Object.keys(t).filter(s=>t[s].axis===n).shift()}_getAxis(){const t={},n=this.getFirstScaleIdForIndexAxis();for(const s of this.chart.data.datasets)t[it(this.chart.options.indexAxis==="x"?s.xAxisID:s.yAxisID,n)]=!0;return Object.keys(t)}_getStackIndex(t,n,s){const i=this._getStacks(t,s),a=n!==void 0?i.indexOf(n):-1;return a===-1?i.length-1:a}_getRuler(){const t=this.options,n=this._cachedMeta,s=n.iScale,i=[];let a,o;for(a=0,o=n.data.length;a<o;++a)i.push(s.getPixelForValue(this.getParsed(a)[s.axis],a));const l=t.barThickness;return{min:l||JCe(n),pixels:i,start:s._startPixel,end:s._endPixel,stackCount:this._getStackCount(),scale:s,grouped:t.grouped,ratio:l?1:t.categoryPercentage*t.barPercentage}}_calculateBarValuePixels(t){const{_cachedMeta:{vScale:n,_stacked:s,index:i},options:{base:a,minBarLength:o}}=this,l=a||0,c=this.getParsed(t),d=c._custom,f=EA(d);let p=c[n.axis],m=0,g=s?this.applyStack(n,c,s):p,b,_;g!==p&&(m=g-p,g=p),f&&(p=d.barStart,g=d.barEnd-d.barStart,p!==0&&za(p)!==za(d.barEnd)&&(m=0),m+=p);const w=!Tt(a)&&!f?a:m;let A=n.getPixelForValue(w);if(this.chart.getDataVisibility(t)?b=n.getPixelForValue(m+g):b=A,_=b-A,Math.abs(_)<o){_=n5e(_,n,l)*o,p===l&&(A-=_/2);const S=n.getPixelForDecimal(0),C=n.getPixelForDecimal(1),E=Math.min(S,C),k=Math.max(S,C);A=Math.max(Math.min(A,k),E),b=A+_,s&&!f&&(c._stacks[n.axis]._visualValues[i]=n.getValueForPixel(b)-n.getValueForPixel(A))}if(A===n.getPixelForValue(l)){const S=za(_)*n.getLineWidthForValue(l)/2;A+=S,_-=S}return{size:_,base:A,head:b,center:b+_/2}}_calculateBarIndexPixels(t,n){const s=n.scale,i=this.options,a=i.skipNull,o=it(i.maxBarThickness,1/0);let l,c;const d=this._getAxisCount();if(n.grouped){const f=a?this._getStackCount(t):n.stackCount,p=i.barThickness==="flex"?e5e(t,n,i,f*d):ZCe(t,n,i,f*d),m=this.chart.options.indexAxis==="x"?this.getDataset().xAxisID:this.getDataset().yAxisID,g=this._getAxis().indexOf(it(m,this.getFirstScaleIdForIndexAxis())),b=this._getStackIndex(this.index,this._cachedMeta.stack,a?t:void 0)+g;l=p.start+p.chunk*b+p.chunk/2,c=Math.min(o,p.chunk*p.ratio)}else l=s.getPixelForValue(this.getParsed(t)[s.axis],t),c=Math.min(o,n.min*n.ratio);return{base:l-c/2,head:l+c/2,center:l,size:c}}draw(){const t=this._cachedMeta,n=t.vScale,s=t.data,i=s.length;let a=0;for(;a<i;++a)this.getParsed(a)[n.axis]!==null&&!s[a].hidden&&s[a].draw(this._ctx)}}function l5e(e,t,n){let s=1,i=1,a=0,o=0;if(t<_n){const l=e,c=l+t,d=Math.cos(l),f=Math.sin(l),p=Math.cos(c),m=Math.sin(c),g=(C,E,k)=>Yp(C,l,c,!0)?1:Math.max(E,E*n,k,k*n),b=(C,E,k)=>Yp(C,l,c,!0)?-1:Math.min(E,E*n,k,k*n),_=g(0,d,p),w=g(ls,f,m),A=b(Lt,d,p),S=b(Lt+ls,f,m);s=(_-A)/2,i=(w-S)/2,a=-(_+A)/2,o=-(w+S)/2}return{ratioX:s,ratioY:i,offsetX:a,offsetY:o}}class c5e extends Km{static id="doughnut";static defaults={datasetElementType:!1,dataElementType:"arc",animation:{animateRotate:!0,animateScale:!1},animations:{numbers:{type:"number",properties:["circumference","endAngle","innerRadius","outerRadius","startAngle","x","y","offset","borderWidth","spacing"]}},cutout:"50%",rotation:0,circumference:360,radius:"100%",spacing:0,indexAxis:"r"};static descriptors={_scriptable:t=>t!=="spacing",_indexable:t=>t!=="spacing"&&!t.startsWith("borderDash")&&!t.startsWith("hoverBorderDash")};static overrides={aspectRatio:1,plugins:{legend:{labels:{generateLabels(t){const n=t.data,{labels:{pointStyle:s,textAlign:i,color:a,useBorderRadius:o,borderRadius:l}}=t.legend.options;return n.labels.length&&n.datasets.length?n.labels.map((c,d)=>{const p=t.getDatasetMeta(0).controller.getStyle(d);return{text:c,fillStyle:p.backgroundColor,fontColor:a,hidden:!t.getDataVisibility(d),lineDash:p.borderDash,lineDashOffset:p.borderDashOffset,lineJoin:p.borderJoinStyle,lineWidth:p.borderWidth,strokeStyle:p.borderColor,textAlign:i,pointStyle:s,borderRadius:o&&(l||p.borderRadius),index:d}}):[]}},onClick(t,n,s){s.chart.toggleDataVisibility(n.index),s.chart.update()}}}};constructor(t,n){super(t,n),this.enableOptionSharing=!0,this.innerRadius=void 0,this.outerRadius=void 0,this.offsetX=void 0,this.offsetY=void 0}linkScales(){}parse(t,n){const s=this.getDataset().data,i=this._cachedMeta;if(this._parsing===!1)i._parsed=s;else{let a=c=>+s[c];if(xt(s[t])){const{key:c="value"}=this._parsing;a=d=>+hu(s[d],c)}let o,l;for(o=t,l=t+n;o<l;++o)i._parsed[o]=a(o)}}_getRotation(){return Ao(this.options.rotation-90)}_getCircumference(){return Ao(this.options.circumference)}_getRotationExtents(){let t=_n,n=-_n;for(let s=0;s<this.chart.data.datasets.length;++s)if(this.chart.isDatasetVisible(s)&&this.chart.getDatasetMeta(s).type===this._type){const i=this.chart.getDatasetMeta(s).controller,a=i._getRotation(),o=i._getCircumference();t=Math.min(t,a),n=Math.max(n,a+o)}return{rotation:t,circumference:n-t}}update(t){const n=this.chart,{chartArea:s}=n,i=this._cachedMeta,a=i.data,o=this.getMaxBorderWidth()+this.getMaxOffset(a)+this.options.spacing,l=Math.max((Math.min(s.width,s.height)-o)/2,0),c=Math.min(gSe(this.options.cutout,l),1),d=this._getRingWeight(this.index),{circumference:f,rotation:p}=this._getRotationExtents(),{ratioX:m,ratioY:g,offsetX:b,offsetY:_}=l5e(p,f,c),w=(s.width-o)/m,A=(s.height-o)/g,S=Math.max(Math.min(w,A)/2,0),C=TV(this.options.radius,S),E=Math.max(C*c,0),k=(C-E)/this._getVisibleDatasetWeightTotal();this.offsetX=b*C,this.offsetY=_*C,i.total=this.calculateTotal(),this.outerRadius=C-k*this._getRingWeightOffset(this.index),this.innerRadius=Math.max(this.outerRadius-k*d,0),this.updateElements(a,0,a.length,t)}_circumference(t,n){const s=this.options,i=this._cachedMeta,a=this._getCircumference();return n&&s.animation.animateRotate||!this.chart.getDataVisibility(t)||i._parsed[t]===null||i.data[t].hidden?0:this.calculateCircumference(i._parsed[t]*a/_n)}updateElements(t,n,s,i){const a=i==="reset",o=this.chart,l=o.chartArea,d=o.options.animation,f=(l.left+l.right)/2,p=(l.top+l.bottom)/2,m=a&&d.animateScale,g=m?0:this.innerRadius,b=m?0:this.outerRadius,{sharedOptions:_,includeOptions:w}=this._getSharedOptions(n,i);let A=this._getRotation(),S;for(S=0;S<n;++S)A+=this._circumference(S,a);for(S=n;S<n+s;++S){const C=this._circumference(S,a),E=t[S],k={x:f+this.offsetX,y:p+this.offsetY,startAngle:A,endAngle:A+C,circumference:C,outerRadius:b,innerRadius:g};w&&(k.options=_||this.resolveDataElementOptions(S,E.active?"active":i)),A+=C,this.updateElement(E,S,k,i)}}calculateTotal(){const t=this._cachedMeta,n=t.data;let s=0,i;for(i=0;i<n.length;i++){const a=t._parsed[i];a!==null&&!isNaN(a)&&this.chart.getDataVisibility(i)&&!n[i].hidden&&(s+=Math.abs(a))}return s}calculateCircumference(t){const n=this._cachedMeta.total;return n>0&&!isNaN(t)?_n*(Math.abs(t)/n):0}getLabelAndValue(t){const n=this._cachedMeta,s=this.chart,i=s.data.labels||[],a=hN(n._parsed[t],s.options.locale);return{label:i[t]||"",value:a}}getMaxBorderWidth(t){let n=0;const s=this.chart;let i,a,o,l,c;if(!t){for(i=0,a=s.data.datasets.length;i<a;++i)if(s.isDatasetVisible(i)){o=s.getDatasetMeta(i),t=o.data,l=o.controller;break}}if(!t)return 0;for(i=0,a=t.length;i<a;++i)c=l.resolveDataElementOptions(i),c.borderAlign!=="inner"&&(n=Math.max(n,c.borderWidth||0,c.hoverBorderWidth||0));return n}getMaxOffset(t){let n=0;for(let s=0,i=t.length;s<i;++s){const a=this.resolveDataElementOptions(s);n=Math.max(n,a.offset||0,a.hoverOffset||0)}return n}_getRingWeightOffset(t){let n=0;for(let s=0;s<t;++s)this.chart.isDatasetVisible(s)&&(n+=this._getRingWeight(s));return n}_getRingWeight(t){return Math.max(it(this.chart.data.datasets[t].weight,1),0)}_getVisibleDatasetWeightTotal(){return this._getRingWeightOffset(this.chart.data.datasets.length)||1}}class u5e extends Km{static id="line";static defaults={datasetElementType:"line",dataElementType:"point",showLine:!0,spanGaps:!1};static overrides={scales:{_index_:{type:"category"},_value_:{type:"linear"}}};initialize(){this.enableOptionSharing=!0,this.supportsDecimation=!0,super.initialize()}update(t){const n=this._cachedMeta,{dataset:s,data:i=[],_dataset:a}=n,o=this.chart._animationsDisabled;let{start:l,count:c}=BV(n,i,o);this._drawStart=l,this._drawCount=c,zV(n)&&(l=0,c=i.length),s._chart=this.chart,s._datasetIndex=this.index,s._decimated=!!a._decimated,s.points=i;const d=this.resolveDatasetElementOptions(t);this.options.showLine||(d.borderWidth=0),d.segment=this.options.segment,this.updateElement(s,void 0,{animated:!o,options:d},t),this.updateElements(i,l,c,t)}updateElements(t,n,s,i){const a=i==="reset",{iScale:o,vScale:l,_stacked:c,_dataset:d}=this._cachedMeta,{sharedOptions:f,includeOptions:p}=this._getSharedOptions(n,i),m=o.axis,g=l.axis,{spanGaps:b,segment:_}=this.options,w=Qd(b)?b:Number.POSITIVE_INFINITY,A=this.chart._animationsDisabled||a||i==="none",S=n+s,C=t.length;let E=n>0&&this.getParsed(n-1);for(let k=0;k<C;++k){const T=t[k],F=A?T:{};if(k<n||k>=S){F.skip=!0;continue}const M=this.getParsed(k),I=Tt(M[g]),R=F[m]=o.getPixelForValue(M[m],k),H=F[g]=a||I?l.getBasePixel():l.getPixelForValue(c?this.applyStack(l,M,c):M[g],k);F.skip=isNaN(R)||isNaN(H)||I,F.stop=k>0&&Math.abs(M[m]-E[m])>w,_&&(F.parsed=M,F.raw=d.data[k]),p&&(F.options=f||this.resolveDataElementOptions(k,T.active?"active":i)),A||this.updateElement(T,k,F,i),E=M}}getMaxOverflow(){const t=this._cachedMeta,n=t.dataset,s=n.options&&n.options.borderWidth||0,i=t.data||[];if(!i.length)return s;const a=i[0].size(this.resolveDataElementOptions(0)),o=i[i.length-1].size(this.resolveDataElementOptions(i.length-1));return Math.max(s,a,o)/2}draw(){const t=this._cachedMeta;t.dataset.updateControlPoints(this.chart.chartArea,t.iScale.axis),super.draw()}}class d5e extends c5e{static id="pie";static defaults={cutout:0,rotation:0,circumference:360,radius:"100%"}}class h5e extends Km{static id="scatter";static defaults={datasetElementType:!1,dataElementType:"point",showLine:!1,fill:!1};static overrides={interaction:{mode:"point"},scales:{x:{type:"linear"},y:{type:"linear"}}};getLabelAndValue(t){const n=this._cachedMeta,s=this.chart.data.labels||[],{xScale:i,yScale:a}=n,o=this.getParsed(t),l=i.getLabelForValue(o.x),c=a.getLabelForValue(o.y);return{label:s[t]||"",value:"("+l+", "+c+")"}}update(t){const n=this._cachedMeta,{data:s=[]}=n,i=this.chart._animationsDisabled;let{start:a,count:o}=BV(n,s,i);if(this._drawStart=a,this._drawCount=o,zV(n)&&(a=0,o=s.length),this.options.showLine){this.datasetElementType||this.addElements();const{dataset:l,_dataset:c}=n;l._chart=this.chart,l._datasetIndex=this.index,l._decimated=!!c._decimated,l.points=s;const d=this.resolveDatasetElementOptions(t);d.segment=this.options.segment,this.updateElement(l,void 0,{animated:!i,options:d},t)}else this.datasetElementType&&(delete n.dataset,this.datasetElementType=!1);this.updateElements(s,a,o,t)}addElements(){const{showLine:t}=this.options;!this.datasetElementType&&t&&(this.datasetElementType=this.chart.registry.getElement("line")),super.addElements()}updateElements(t,n,s,i){const a=i==="reset",{iScale:o,vScale:l,_stacked:c,_dataset:d}=this._cachedMeta,f=this.resolveDataElementOptions(n,i),p=this.getSharedOptions(f),m=this.includeOptions(i,p),g=o.axis,b=l.axis,{spanGaps:_,segment:w}=this.options,A=Qd(_)?_:Number.POSITIVE_INFINITY,S=this.chart._animationsDisabled||a||i==="none";let C=n>0&&this.getParsed(n-1);for(let E=n;E<n+s;++E){const k=t[E],T=this.getParsed(E),F=S?k:{},M=Tt(T[b]),I=F[g]=o.getPixelForValue(T[g],E),R=F[b]=a||M?l.getBasePixel():l.getPixelForValue(c?this.applyStack(l,T,c):T[b],E);F.skip=isNaN(I)||isNaN(R)||M,F.stop=E>0&&Math.abs(T[g]-C[g])>A,w&&(F.parsed=T,F.raw=d.data[E]),m&&(F.options=p||this.resolveDataElementOptions(E,k.active?"active":i)),S||this.updateElement(k,E,F,i),C=T}this.updateSharedOptions(p,i,f)}getMaxOverflow(){const t=this._cachedMeta,n=t.data||[];if(!this.options.showLine){let l=0;for(let c=n.length-1;c>=0;--c)l=Math.max(l,n[c].size(this.resolveDataElementOptions(c))/2);return l>0&&l}const s=t.dataset,i=s.options&&s.options.borderWidth||0;if(!n.length)return i;const a=n[0].size(this.resolveDataElementOptions(0)),o=n[n.length-1].size(this.resolveDataElementOptions(n.length-1));return Math.max(i,a,o)/2}}function Mc(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}class vN{static override(t){Object.assign(vN.prototype,t)}options;constructor(t){this.options=t||{}}init(){}formats(){return Mc()}parse(){return Mc()}format(){return Mc()}add(){return Mc()}diff(){return Mc()}startOf(){return Mc()}endOf(){return Mc()}}var f5e={_date:vN};function p5e(e,t,n,s){const{controller:i,data:a,_sorted:o}=e,l=i._cachedMeta.iScale,c=e.dataset&&e.dataset.options?e.dataset.options.spanGaps:null;if(l&&t===l.axis&&t!=="r"&&o&&a.length){const d=l._reversePixels?MSe:Gc;if(s){if(i._sharedOptions){const f=a[0],p=typeof f.getRange=="function"&&f.getRange(t);if(p){const m=d(a,t,n-p),g=d(a,t,n+p);return{lo:m.lo,hi:g.hi}}}}else{const f=d(a,t,n);if(c){const{vScale:p}=i._cachedMeta,{_parsed:m}=e,g=m.slice(0,f.lo+1).reverse().findIndex(_=>!Tt(_[p.axis]));f.lo-=Math.max(0,g);const b=m.slice(f.hi).findIndex(_=>!Tt(_[p.axis]));f.hi+=Math.max(0,b)}return f}}return{lo:0,hi:a.length-1}}function dy(e,t,n,s,i){const a=e.getSortedVisibleDatasetMetas(),o=n[t];for(let l=0,c=a.length;l<c;++l){const{index:d,data:f}=a[l],{lo:p,hi:m}=p5e(a[l],t,o,i);for(let g=p;g<=m;++g){const b=f[g];b.skip||s(b,d,g)}}}function m5e(e){const t=e.indexOf("x")!==-1,n=e.indexOf("y")!==-1;return function(s,i){const a=t?Math.abs(s.x-i.x):0,o=n?Math.abs(s.y-i.y):0;return Math.sqrt(Math.pow(a,2)+Math.pow(o,2))}}function FA(e,t,n,s,i){const a=[];return!i&&!e.isPointInArea(t)||dy(e,n,t,function(l,c,d){!i&&!Qp(l,e.chartArea,0)||l.inRange(t.x,t.y,s)&&a.push({element:l,datasetIndex:c,index:d})},!0),a}function x5e(e,t,n,s){let i=[];function a(o,l,c){const{startAngle:d,endAngle:f}=o.getProps(["startAngle","endAngle"],s),{angle:p}=DV(o,{x:t.x,y:t.y});Yp(p,d,f)&&i.push({element:o,datasetIndex:l,index:c})}return dy(e,n,t,a),i}function g5e(e,t,n,s,i,a){let o=[];const l=m5e(n);let c=Number.POSITIVE_INFINITY;function d(f,p,m){const g=f.inRange(t.x,t.y,i);if(s&&!g)return;const b=f.getCenterPoint(i);if(!(!!a||e.isPointInArea(b))&&!g)return;const w=l(t,b);w<c?(o=[{element:f,datasetIndex:p,index:m}],c=w):w===c&&o.push({element:f,datasetIndex:p,index:m})}return dy(e,n,t,d),o}function TA(e,t,n,s,i,a){return!a&&!e.isPointInArea(t)?[]:n==="r"&&!s?x5e(e,t,n,i):g5e(e,t,n,s,i,a)}function pD(e,t,n,s,i){const a=[],o=n==="x"?"inXRange":"inYRange";let l=!1;return dy(e,n,t,(c,d,f)=>{c[o]&&c[o](t[n],i)&&(a.push({element:c,datasetIndex:d,index:f}),l=l||c.inRange(t.x,t.y,i))}),s&&!l?[]:a}var b5e={modes:{index(e,t,n,s){const i=Ic(t,e),a=n.axis||"x",o=n.includeInvisible||!1,l=n.intersect?FA(e,i,a,s,o):TA(e,i,a,!1,s,o),c=[];return l.length?(e.getSortedVisibleDatasetMetas().forEach(d=>{const f=l[0].index,p=d.data[f];p&&!p.skip&&c.push({element:p,datasetIndex:d.index,index:f})}),c):[]},dataset(e,t,n,s){const i=Ic(t,e),a=n.axis||"xy",o=n.includeInvisible||!1;let l=n.intersect?FA(e,i,a,s,o):TA(e,i,a,!1,s,o);if(l.length>0){const c=l[0].datasetIndex,d=e.getDatasetMeta(c).data;l=[];for(let f=0;f<d.length;++f)l.push({element:d[f],datasetIndex:c,index:f})}return l},point(e,t,n,s){const i=Ic(t,e),a=n.axis||"xy",o=n.includeInvisible||!1;return FA(e,i,a,s,o)},nearest(e,t,n,s){const i=Ic(t,e),a=n.axis||"xy",o=n.includeInvisible||!1;return TA(e,i,a,n.intersect,s,o)},x(e,t,n,s){const i=Ic(t,e);return pD(e,i,"x",n.intersect,s)},y(e,t,n,s){const i=Ic(t,e);return pD(e,i,"y",n.intersect,s)}}};const iU=["left","top","right","bottom"];function If(e,t){return e.filter(n=>n.pos===t)}function mD(e,t){return e.filter(n=>iU.indexOf(n.pos)===-1&&n.box.axis===t)}function Lf(e,t){return e.sort((n,s)=>{const i=t?s:n,a=t?n:s;return i.weight===a.weight?i.index-a.index:i.weight-a.weight})}function v5e(e){const t=[];let n,s,i,a,o,l;for(n=0,s=(e||[]).length;n<s;++n)i=e[n],{position:a,options:{stack:o,stackWeight:l=1}}=i,t.push({index:n,box:i,pos:a,horizontal:i.isHorizontal(),weight:i.weight,stack:o&&a+o,stackWeight:l});return t}function y5e(e){const t={};for(const n of e){const{stack:s,pos:i,stackWeight:a}=n;if(!s||!iU.includes(i))continue;const o=t[s]||(t[s]={count:0,placed:0,weight:0,size:0});o.count++,o.weight+=a}return t}function _5e(e,t){const n=y5e(e),{vBoxMaxWidth:s,hBoxMaxHeight:i}=t;let a,o,l;for(a=0,o=e.length;a<o;++a){l=e[a];const{fullSize:c}=l.box,d=n[l.stack],f=d&&l.stackWeight/d.weight;l.horizontal?(l.width=f?f*s:c&&t.availableWidth,l.height=i):(l.width=s,l.height=f?f*i:c&&t.availableHeight)}return n}function w5e(e){const t=v5e(e),n=Lf(t.filter(d=>d.box.fullSize),!0),s=Lf(If(t,"left"),!0),i=Lf(If(t,"right")),a=Lf(If(t,"top"),!0),o=Lf(If(t,"bottom")),l=mD(t,"x"),c=mD(t,"y");return{fullSize:n,leftAndTop:s.concat(a),rightAndBottom:i.concat(c).concat(o).concat(l),chartArea:If(t,"chartArea"),vertical:s.concat(i).concat(c),horizontal:a.concat(o).concat(l)}}function xD(e,t,n,s){return Math.max(e[n],t[n])+Math.max(e[s],t[s])}function rU(e,t){e.top=Math.max(e.top,t.top),e.left=Math.max(e.left,t.left),e.bottom=Math.max(e.bottom,t.bottom),e.right=Math.max(e.right,t.right)}function A5e(e,t,n,s){const{pos:i,box:a}=n,o=e.maxPadding;if(!xt(i)){n.size&&(e[i]-=n.size);const p=s[n.stack]||{size:0,count:1};p.size=Math.max(p.size,n.horizontal?a.height:a.width),n.size=p.size/p.count,e[i]+=n.size}a.getPadding&&rU(o,a.getPadding());const l=Math.max(0,t.outerWidth-xD(o,e,"left","right")),c=Math.max(0,t.outerHeight-xD(o,e,"top","bottom")),d=l!==e.w,f=c!==e.h;return e.w=l,e.h=c,n.horizontal?{same:d,other:f}:{same:f,other:d}}function S5e(e){const t=e.maxPadding;function n(s){const i=Math.max(t[s]-e[s],0);return e[s]+=i,i}e.y+=n("top"),e.x+=n("left"),n("right"),n("bottom")}function C5e(e,t){const n=t.maxPadding;function s(i){const a={left:0,top:0,right:0,bottom:0};return i.forEach(o=>{a[o]=Math.max(t[o],n[o])}),a}return s(e?["left","right"]:["top","bottom"])}function ep(e,t,n,s){const i=[];let a,o,l,c,d,f;for(a=0,o=e.length,d=0;a<o;++a){l=e[a],c=l.box,c.update(l.width||t.w,l.height||t.h,C5e(l.horizontal,t));const{same:p,other:m}=A5e(t,n,l,s);d|=p&&i.length,f=f||m,c.fullSize||i.push(l)}return d&&ep(i,t,n,s)||f}function Qg(e,t,n,s,i){e.top=n,e.left=t,e.right=t+s,e.bottom=n+i,e.width=s,e.height=i}function gD(e,t,n,s){const i=n.padding;let{x:a,y:o}=t;for(const l of e){const c=l.box,d=s[l.stack]||{placed:0,weight:1},f=l.stackWeight/d.weight||1;if(l.horizontal){const p=t.w*f,m=d.size||c.height;Kp(d.start)&&(o=d.start),c.fullSize?Qg(c,i.left,o,n.outerWidth-i.right-i.left,m):Qg(c,t.left+d.placed,o,p,m),d.start=o,d.placed+=p,o=c.bottom}else{const p=t.h*f,m=d.size||c.width;Kp(d.start)&&(a=d.start),c.fullSize?Qg(c,a,i.top,m,n.outerHeight-i.bottom-i.top):Qg(c,a,t.top+d.placed,m,p),d.start=a,d.placed+=p,a=c.right}}t.x=a,t.y=o}var Tr={addBox(e,t){e.boxes||(e.boxes=[]),t.fullSize=t.fullSize||!1,t.position=t.position||"top",t.weight=t.weight||0,t._layers=t._layers||function(){return[{z:0,draw(n){t.draw(n)}}]},e.boxes.push(t)},removeBox(e,t){const n=e.boxes?e.boxes.indexOf(t):-1;n!==-1&&e.boxes.splice(n,1)},configure(e,t,n){t.fullSize=n.fullSize,t.position=n.position,t.weight=n.weight},update(e,t,n,s){if(!e)return;const i=Lr(e.options.layout.padding),a=Math.max(t-i.width,0),o=Math.max(n-i.height,0),l=w5e(e.boxes),c=l.vertical,d=l.horizontal;It(e.boxes,_=>{typeof _.beforeLayout=="function"&&_.beforeLayout()});const f=c.reduce((_,w)=>w.box.options&&w.box.options.display===!1?_:_+1,0)||1,p=Object.freeze({outerWidth:t,outerHeight:n,padding:i,availableWidth:a,availableHeight:o,vBoxMaxWidth:a/2/f,hBoxMaxHeight:o/2}),m=Object.assign({},i);rU(m,Lr(s));const g=Object.assign({maxPadding:m,w:a,h:o,x:i.left,y:i.top},i),b=_5e(c.concat(d),p);ep(l.fullSize,g,p,b),ep(c,g,p,b),ep(d,g,p,b)&&ep(c,g,p,b),S5e(g),gD(l.leftAndTop,g,p,b),g.x+=g.w,g.y+=g.h,gD(l.rightAndBottom,g,p,b),e.chartArea={left:g.left,top:g.top,right:g.left+g.w,bottom:g.top+g.h,height:g.h,width:g.w},It(l.chartArea,_=>{const w=_.box;Object.assign(w,e.chartArea),w.update(g.w,g.h,{left:0,top:0,right:0,bottom:0})})}};class aU{acquireContext(t,n){}releaseContext(t){return!1}addEventListener(t,n,s){}removeEventListener(t,n,s){}getDevicePixelRatio(){return 1}getMaximumSize(t,n,s,i){return n=Math.max(0,n||t.width),s=s||t.height,{width:n,height:Math.max(0,i?Math.floor(n/i):s)}}isAttached(t){return!0}updateConfig(t){}}class j5e extends aU{acquireContext(t){return t&&t.getContext&&t.getContext("2d")||null}updateConfig(t){t.options.animation=!1}}const Vb="$chartjs",N5e={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},bD=e=>e===null||e==="";function k5e(e,t){const n=e.style,s=e.getAttribute("height"),i=e.getAttribute("width");if(e[Vb]={initial:{height:s,width:i,style:{display:n.display,height:n.height,width:n.width}}},n.display=n.display||"block",n.boxSizing=n.boxSizing||"border-box",bD(i)){const a=tD(e,"width");a!==void 0&&(e.width=a)}if(bD(s))if(e.style.height==="")e.height=e.width/(t||2);else{const a=tD(e,"height");a!==void 0&&(e.height=a)}return e}const oU=CCe?{passive:!0}:!1;function E5e(e,t,n){e&&e.addEventListener(t,n,oU)}function F5e(e,t,n){e&&e.canvas&&e.canvas.removeEventListener(t,n,oU)}function T5e(e,t){const n=N5e[e.type]||e.type,{x:s,y:i}=Ic(e,t);return{type:n,chart:t,native:e,x:s!==void 0?s:null,y:i!==void 0?i:null}}function V0(e,t){for(const n of e)if(n===t||n.contains(t))return!0}function M5e(e,t,n){const s=e.canvas,i=new MutationObserver(a=>{let o=!1;for(const l of a)o=o||V0(l.addedNodes,s),o=o&&!V0(l.removedNodes,s);o&&n()});return i.observe(document,{childList:!0,subtree:!0}),i}function R5e(e,t,n){const s=e.canvas,i=new MutationObserver(a=>{let o=!1;for(const l of a)o=o||V0(l.removedNodes,s),o=o&&!V0(l.addedNodes,s);o&&n()});return i.observe(document,{childList:!0,subtree:!0}),i}const Jp=new Map;let vD=0;function lU(){const e=window.devicePixelRatio;e!==vD&&(vD=e,Jp.forEach((t,n)=>{n.currentDevicePixelRatio!==e&&t()}))}function D5e(e,t){Jp.size||window.addEventListener("resize",lU),Jp.set(e,t)}function O5e(e){Jp.delete(e),Jp.size||window.removeEventListener("resize",lU)}function P5e(e,t,n){const s=e.canvas,i=s&&bN(s);if(!i)return;const a=LV((l,c)=>{const d=i.clientWidth;n(l,c),d<i.clientWidth&&n()},window),o=new ResizeObserver(l=>{const c=l[0],d=c.contentRect.width,f=c.contentRect.height;d===0&&f===0||a(d,f)});return o.observe(i),D5e(e,a),o}function MA(e,t,n){n&&n.disconnect(),t==="resize"&&O5e(e)}function I5e(e,t,n){const s=e.canvas,i=LV(a=>{e.ctx!==null&&n(T5e(a,e))},e);return E5e(s,t,i),i}class L5e extends aU{acquireContext(t,n){const s=t&&t.getContext&&t.getContext("2d");return s&&s.canvas===t?(k5e(t,n),s):null}releaseContext(t){const n=t.canvas;if(!n[Vb])return!1;const s=n[Vb].initial;["height","width"].forEach(a=>{const o=s[a];Tt(o)?n.removeAttribute(a):n.setAttribute(a,o)});const i=s.style||{};return Object.keys(i).forEach(a=>{n.style[a]=i[a]}),n.width=n.width,delete n[Vb],!0}addEventListener(t,n,s){this.removeEventListener(t,n);const i=t.$proxies||(t.$proxies={}),o={attach:M5e,detach:R5e,resize:P5e}[n]||I5e;i[n]=o(t,n,s)}removeEventListener(t,n){const s=t.$proxies||(t.$proxies={}),i=s[n];if(!i)return;({attach:MA,detach:MA,resize:MA}[n]||F5e)(t,n,i),s[n]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(t,n,s,i){return SCe(t,n,s,i)}isAttached(t){const n=t&&bN(t);return!!(n&&n.isConnected)}}function B5e(e){return!gN()||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas?j5e:L5e}let Wo=class{static defaults={};static defaultRoutes=void 0;x;y;active=!1;options;$animations;tooltipPosition(t){const{x:n,y:s}=this.getProps(["x","y"],t);return{x:n,y:s}}hasValue(){return Qd(this.x)&&Qd(this.y)}getProps(t,n){const s=this.$animations;if(!n||!s)return this;const i={};return t.forEach(a=>{i[a]=s[a]&&s[a].active()?s[a]._to:this[a]}),i}};function z5e(e,t){const n=e.options.ticks,s=$5e(e),i=Math.min(n.maxTicksLimit||s,s),a=n.major.enabled?U5e(t):[],o=a.length,l=a[0],c=a[o-1],d=[];if(o>i)return H5e(t,d,a,o/i),d;const f=V5e(a,t,i);if(o>0){let p,m;const g=o>1?Math.round((c-l)/(o-1)):null;for(Xg(t,d,f,Tt(g)?0:l-g,l),p=0,m=o-1;p<m;p++)Xg(t,d,f,a[p],a[p+1]);return Xg(t,d,f,c,Tt(g)?t.length:c+g),d}return Xg(t,d,f),d}function $5e(e){const t=e.options.offset,n=e._tickSize(),s=e._length/n+(t?0:1),i=e._maxLength/n;return Math.floor(Math.min(s,i))}function V5e(e,t,n){const s=W5e(e),i=t.length/n;if(!s)return Math.max(i,1);const a=CSe(s);for(let o=0,l=a.length-1;o<l;o++){const c=a[o];if(c>i)return c}return Math.max(i,1)}function U5e(e){const t=[];let n,s;for(n=0,s=e.length;n<s;n++)e[n].major&&t.push(n);return t}function H5e(e,t,n,s){let i=0,a=n[0],o;for(s=Math.ceil(s),o=0;o<e.length;o++)o===a&&(t.push(e[o]),i++,a=n[i*s])}function Xg(e,t,n,s,i){const a=it(s,0),o=Math.min(it(i,e.length),e.length);let l=0,c,d,f;for(n=Math.ceil(n),i&&(c=i-s,n=c/Math.floor(c/n)),f=a;f<0;)l++,f=Math.round(a+l*n);for(d=Math.max(a,0);d<o;d++)d===f&&(t.push(e[d]),l++,f=Math.round(a+l*n))}function W5e(e){const t=e.length;let n,s;if(t<2)return!1;for(s=e[0],n=1;n<t;++n)if(e[n]-e[n-1]!==s)return!1;return s}const q5e=e=>e==="left"?"right":e==="right"?"left":e,yD=(e,t,n)=>t==="top"||t==="left"?e[t]+n:e[t]-n,_D=(e,t)=>Math.min(t||e,e);function wD(e,t){const n=[],s=e.length/t,i=e.length;let a=0;for(;a<i;a+=s)n.push(e[Math.floor(a)]);return n}function G5e(e,t,n){const s=e.ticks.length,i=Math.min(t,s-1),a=e._startPixel,o=e._endPixel,l=1e-6;let c=e.getPixelForTick(i),d;if(!(n&&(s===1?d=Math.max(c-a,o-c):t===0?d=(e.getPixelForTick(1)-c)/2:d=(c-e.getPixelForTick(i-1))/2,c+=i<t?d:-d,c<a-l||c>o+l)))return c}function K5e(e,t){It(e,n=>{const s=n.gc,i=s.length/2;let a;if(i>t){for(a=0;a<i;++a)delete n.data[s[a]];s.splice(0,i)}})}function Bf(e){return e.drawTicks?e.tickLength:0}function AD(e,t){if(!e.display)return 0;const n=qs(e.font,t),s=Lr(e.padding);return(Wn(e.text)?e.text.length:1)*n.lineHeight+s.height}function Y5e(e,t){return wu(e,{scale:t,type:"scale"})}function Q5e(e,t,n){return wu(e,{tick:n,index:t,type:"tick"})}function X5e(e,t,n){let s=uN(e);return(n&&t!=="right"||!n&&t==="right")&&(s=q5e(s)),s}function J5e(e,t,n,s){const{top:i,left:a,bottom:o,right:l,chart:c}=e,{chartArea:d,scales:f}=c;let p=0,m,g,b;const _=o-i,w=l-a;if(e.isHorizontal()){if(g=zs(s,a,l),xt(n)){const A=Object.keys(n)[0],S=n[A];b=f[A].getPixelForValue(S)+_-t}else n==="center"?b=(d.bottom+d.top)/2+_-t:b=yD(e,n,t);m=l-a}else{if(xt(n)){const A=Object.keys(n)[0],S=n[A];g=f[A].getPixelForValue(S)-w+t}else n==="center"?g=(d.left+d.right)/2-w+t:g=yD(e,n,t);b=zs(s,o,i),p=n==="left"?-ls:ls}return{titleX:g,titleY:b,maxWidth:m,rotation:p}}class Ah extends Wo{constructor(t){super(),this.id=t.id,this.type=t.type,this.options=void 0,this.ctx=t.ctx,this.chart=t.chart,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this._margins={left:0,right:0,top:0,bottom:0},this.maxWidth=void 0,this.maxHeight=void 0,this.paddingTop=void 0,this.paddingBottom=void 0,this.paddingLeft=void 0,this.paddingRight=void 0,this.axis=void 0,this.labelRotation=void 0,this.min=void 0,this.max=void 0,this._range=void 0,this.ticks=[],this._gridLineItems=null,this._labelItems=null,this._labelSizes=null,this._length=0,this._maxLength=0,this._longestTextCache={},this._startPixel=void 0,this._endPixel=void 0,this._reversePixels=!1,this._userMax=void 0,this._userMin=void 0,this._suggestedMax=void 0,this._suggestedMin=void 0,this._ticksLength=0,this._borderValue=0,this._cache={},this._dataLimitsCached=!1,this.$context=void 0}init(t){this.options=t.setContext(this.getContext()),this.axis=t.axis,this._userMin=this.parse(t.min),this._userMax=this.parse(t.max),this._suggestedMin=this.parse(t.suggestedMin),this._suggestedMax=this.parse(t.suggestedMax)}parse(t,n){return t}getUserBounds(){let{_userMin:t,_userMax:n,_suggestedMin:s,_suggestedMax:i}=this;return t=ya(t,Number.POSITIVE_INFINITY),n=ya(n,Number.NEGATIVE_INFINITY),s=ya(s,Number.POSITIVE_INFINITY),i=ya(i,Number.NEGATIVE_INFINITY),{min:ya(t,s),max:ya(n,i),minDefined:Js(t),maxDefined:Js(n)}}getMinMax(t){let{min:n,max:s,minDefined:i,maxDefined:a}=this.getUserBounds(),o;if(i&&a)return{min:n,max:s};const l=this.getMatchingVisibleMetas();for(let c=0,d=l.length;c<d;++c)o=l[c].controller.getMinMax(this,t),i||(n=Math.min(n,o.min)),a||(s=Math.max(s,o.max));return n=a&&n>s?s:n,s=i&&n>s?n:s,{min:ya(n,ya(s,n)),max:ya(s,ya(n,s))}}getPadding(){return{left:this.paddingLeft||0,top:this.paddingTop||0,right:this.paddingRight||0,bottom:this.paddingBottom||0}}getTicks(){return this.ticks}getLabels(){const t=this.chart.data;return this.options.labels||(this.isHorizontal()?t.xLabels:t.yLabels)||t.labels||[]}getLabelItems(t=this.chart.chartArea){return this._labelItems||(this._labelItems=this._computeLabelItems(t))}beforeLayout(){this._cache={},this._dataLimitsCached=!1}beforeUpdate(){rn(this.options.beforeUpdate,[this])}update(t,n,s){const{beginAtZero:i,grace:a,ticks:o}=this.options,l=o.sampleSize;this.beforeUpdate(),this.maxWidth=t,this.maxHeight=n,this._margins=s=Object.assign({left:0,right:0,top:0,bottom:0},s),this.ticks=null,this._labelSizes=null,this._gridLineItems=null,this._labelItems=null,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this._maxLength=this.isHorizontal()?this.width+s.left+s.right:this.height+s.top+s.bottom,this._dataLimitsCached||(this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this._range=nCe(this,a,i),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();const c=l<this.ticks.length;this._convertTicksToLabels(c?wD(this.ticks,l):this.ticks),this.configure(),this.beforeCalculateLabelRotation(),this.calculateLabelRotation(),this.afterCalculateLabelRotation(),o.display&&(o.autoSkip||o.source==="auto")&&(this.ticks=z5e(this,this.ticks),this._labelSizes=null,this.afterAutoSkip()),c&&this._convertTicksToLabels(this.ticks),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate()}configure(){let t=this.options.reverse,n,s;this.isHorizontal()?(n=this.left,s=this.right):(n=this.top,s=this.bottom,t=!t),this._startPixel=n,this._endPixel=s,this._reversePixels=t,this._length=s-n,this._alignToPixels=this.options.alignToPixels}afterUpdate(){rn(this.options.afterUpdate,[this])}beforeSetDimensions(){rn(this.options.beforeSetDimensions,[this])}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0}afterSetDimensions(){rn(this.options.afterSetDimensions,[this])}_callHooks(t){this.chart.notifyPlugins(t,this.getContext()),rn(this.options[t],[this])}beforeDataLimits(){this._callHooks("beforeDataLimits")}determineDataLimits(){}afterDataLimits(){this._callHooks("afterDataLimits")}beforeBuildTicks(){this._callHooks("beforeBuildTicks")}buildTicks(){return[]}afterBuildTicks(){this._callHooks("afterBuildTicks")}beforeTickToLabelConversion(){rn(this.options.beforeTickToLabelConversion,[this])}generateTickLabels(t){const n=this.options.ticks;let s,i,a;for(s=0,i=t.length;s<i;s++)a=t[s],a.label=rn(n.callback,[a.value,s,t],this)}afterTickToLabelConversion(){rn(this.options.afterTickToLabelConversion,[this])}beforeCalculateLabelRotation(){rn(this.options.beforeCalculateLabelRotation,[this])}calculateLabelRotation(){const t=this.options,n=t.ticks,s=_D(this.ticks.length,t.ticks.maxTicksLimit),i=n.minRotation||0,a=n.maxRotation;let o=i,l,c,d;if(!this._isVisible()||!n.display||i>=a||s<=1||!this.isHorizontal()){this.labelRotation=i;return}const f=this._getLabelSizes(),p=f.widest.width,m=f.highest.height,g=Ws(this.chart.width-p,0,this.maxWidth);l=t.offset?this.maxWidth/s:g/(s-1),p+6>l&&(l=g/(s-(t.offset?.5:1)),c=this.maxHeight-Bf(t.grid)-n.padding-AD(t.title,this.chart.options.font),d=Math.sqrt(p*p+m*m),o=ESe(Math.min(Math.asin(Ws((f.highest.height+6)/l,-1,1)),Math.asin(Ws(c/d,-1,1))-Math.asin(Ws(m/d,-1,1)))),o=Math.max(i,Math.min(a,o))),this.labelRotation=o}afterCalculateLabelRotation(){rn(this.options.afterCalculateLabelRotation,[this])}afterAutoSkip(){}beforeFit(){rn(this.options.beforeFit,[this])}fit(){const t={width:0,height:0},{chart:n,options:{ticks:s,title:i,grid:a}}=this,o=this._isVisible(),l=this.isHorizontal();if(o){const c=AD(i,n.options.font);if(l?(t.width=this.maxWidth,t.height=Bf(a)+c):(t.height=this.maxHeight,t.width=Bf(a)+c),s.display&&this.ticks.length){const{first:d,last:f,widest:p,highest:m}=this._getLabelSizes(),g=s.padding*2,b=Ao(this.labelRotation),_=Math.cos(b),w=Math.sin(b);if(l){const A=s.mirror?0:w*p.width+_*m.height;t.height=Math.min(this.maxHeight,t.height+A+g)}else{const A=s.mirror?0:_*p.width+w*m.height;t.width=Math.min(this.maxWidth,t.width+A+g)}this._calculatePadding(d,f,w,_)}}this._handleMargins(),l?(this.width=this._length=n.width-this._margins.left-this._margins.right,this.height=t.height):(this.width=t.width,this.height=this._length=n.height-this._margins.top-this._margins.bottom)}_calculatePadding(t,n,s,i){const{ticks:{align:a,padding:o},position:l}=this.options,c=this.labelRotation!==0,d=l!=="top"&&this.axis==="x";if(this.isHorizontal()){const f=this.getPixelForTick(0)-this.left,p=this.right-this.getPixelForTick(this.ticks.length-1);let m=0,g=0;c?d?(m=i*t.width,g=s*n.height):(m=s*t.height,g=i*n.width):a==="start"?g=n.width:a==="end"?m=t.width:a!=="inner"&&(m=t.width/2,g=n.width/2),this.paddingLeft=Math.max((m-f+o)*this.width/(this.width-f),0),this.paddingRight=Math.max((g-p+o)*this.width/(this.width-p),0)}else{let f=n.height/2,p=t.height/2;a==="start"?(f=0,p=t.height):a==="end"&&(f=n.height,p=0),this.paddingTop=f+o,this.paddingBottom=p+o}}_handleMargins(){this._margins&&(this._margins.left=Math.max(this.paddingLeft,this._margins.left),this._margins.top=Math.max(this.paddingTop,this._margins.top),this._margins.right=Math.max(this.paddingRight,this._margins.right),this._margins.bottom=Math.max(this.paddingBottom,this._margins.bottom))}afterFit(){rn(this.options.afterFit,[this])}isHorizontal(){const{axis:t,position:n}=this.options;return n==="top"||n==="bottom"||t==="x"}isFullSize(){return this.options.fullSize}_convertTicksToLabels(t){this.beforeTickToLabelConversion(),this.generateTickLabels(t);let n,s;for(n=0,s=t.length;n<s;n++)Tt(t[n].label)&&(t.splice(n,1),s--,n--);this.afterTickToLabelConversion()}_getLabelSizes(){let t=this._labelSizes;if(!t){const n=this.options.ticks.sampleSize;let s=this.ticks;n<s.length&&(s=wD(s,n)),this._labelSizes=t=this._computeLabelSizes(s,s.length,this.options.ticks.maxTicksLimit)}return t}_computeLabelSizes(t,n,s){const{ctx:i,_longestTextCache:a}=this,o=[],l=[],c=Math.floor(n/_D(n,s));let d=0,f=0,p,m,g,b,_,w,A,S,C,E,k;for(p=0;p<n;p+=c){if(b=t[p].label,_=this._resolveTickFontOptions(p),i.font=w=_.string,A=a[w]=a[w]||{data:{},gc:[]},S=_.lineHeight,C=E=0,!Tt(b)&&!Wn(b))C=QR(i,A.data,A.gc,C,b),E=S;else if(Wn(b))for(m=0,g=b.length;m<g;++m)k=b[m],!Tt(k)&&!Wn(k)&&(C=QR(i,A.data,A.gc,C,k),E+=S);o.push(C),l.push(E),d=Math.max(C,d),f=Math.max(E,f)}K5e(a,n);const T=o.indexOf(d),F=l.indexOf(f),M=I=>({width:o[I]||0,height:l[I]||0});return{first:M(0),last:M(n-1),widest:M(T),highest:M(F),widths:o,heights:l}}getLabelForValue(t){return t}getPixelForValue(t,n){return NaN}getValueForPixel(t){}getPixelForTick(t){const n=this.ticks;return t<0||t>n.length-1?null:this.getPixelForValue(n[t].value)}getPixelForDecimal(t){this._reversePixels&&(t=1-t);const n=this._startPixel+t*this._length;return TSe(this._alignToPixels?Tc(this.chart,n,0):n)}getDecimalForPixel(t){const n=(t-this._startPixel)/this._length;return this._reversePixels?1-n:n}getBasePixel(){return this.getPixelForValue(this.getBaseValue())}getBaseValue(){const{min:t,max:n}=this;return t<0&&n<0?n:t>0&&n>0?t:0}getContext(t){const n=this.ticks||[];if(t>=0&&t<n.length){const s=n[t];return s.$context||(s.$context=Q5e(this.getContext(),t,s))}return this.$context||(this.$context=Y5e(this.chart.getContext(),this))}_tickSize(){const t=this.options.ticks,n=Ao(this.labelRotation),s=Math.abs(Math.cos(n)),i=Math.abs(Math.sin(n)),a=this._getLabelSizes(),o=t.autoSkipPadding||0,l=a?a.widest.width+o:0,c=a?a.highest.height+o:0;return this.isHorizontal()?c*s>l*i?l/s:c/i:c*i<l*s?c/s:l/i}_isVisible(){const t=this.options.display;return t!=="auto"?!!t:this.getMatchingVisibleMetas().length>0}_computeGridLineItems(t){const n=this.axis,s=this.chart,i=this.options,{grid:a,position:o,border:l}=i,c=a.offset,d=this.isHorizontal(),p=this.ticks.length+(c?1:0),m=Bf(a),g=[],b=l.setContext(this.getContext()),_=b.display?b.width:0,w=_/2,A=function(B){return Tc(s,B,_)};let S,C,E,k,T,F,M,I,R,H,V,K;if(o==="top")S=A(this.bottom),F=this.bottom-m,I=S-w,H=A(t.top)+w,K=t.bottom;else if(o==="bottom")S=A(this.top),H=t.top,K=A(t.bottom)-w,F=S+w,I=this.top+m;else if(o==="left")S=A(this.right),T=this.right-m,M=S-w,R=A(t.left)+w,V=t.right;else if(o==="right")S=A(this.left),R=t.left,V=A(t.right)-w,T=S+w,M=this.left+m;else if(n==="x"){if(o==="center")S=A((t.top+t.bottom)/2+.5);else if(xt(o)){const B=Object.keys(o)[0],Y=o[B];S=A(this.chart.scales[B].getPixelForValue(Y))}H=t.top,K=t.bottom,F=S+w,I=F+m}else if(n==="y"){if(o==="center")S=A((t.left+t.right)/2);else if(xt(o)){const B=Object.keys(o)[0],Y=o[B];S=A(this.chart.scales[B].getPixelForValue(Y))}T=S-w,M=T-m,R=t.left,V=t.right}const q=it(i.ticks.maxTicksLimit,p),$=Math.max(1,Math.ceil(p/q));for(C=0;C<p;C+=$){const B=this.getContext(C),Y=a.setContext(B),U=l.setContext(B),W=Y.lineWidth,O=Y.color,D=U.dash||[],Q=U.dashOffset,z=Y.tickWidth,J=Y.tickColor,ee=Y.tickBorderDash||[],re=Y.tickBorderDashOffset;E=G5e(this,C,c),E!==void 0&&(k=Tc(s,E,W),d?T=M=R=V=k:F=I=H=K=k,g.push({tx1:T,ty1:F,tx2:M,ty2:I,x1:R,y1:H,x2:V,y2:K,width:W,color:O,borderDash:D,borderDashOffset:Q,tickWidth:z,tickColor:J,tickBorderDash:ee,tickBorderDashOffset:re}))}return this._ticksLength=p,this._borderValue=S,g}_computeLabelItems(t){const n=this.axis,s=this.options,{position:i,ticks:a}=s,o=this.isHorizontal(),l=this.ticks,{align:c,crossAlign:d,padding:f,mirror:p}=a,m=Bf(s.grid),g=m+f,b=p?-f:g,_=-Ao(this.labelRotation),w=[];let A,S,C,E,k,T,F,M,I,R,H,V,K="middle";if(i==="top")T=this.bottom-b,F=this._getXAxisLabelAlignment();else if(i==="bottom")T=this.top+b,F=this._getXAxisLabelAlignment();else if(i==="left"){const $=this._getYAxisLabelAlignment(m);F=$.textAlign,k=$.x}else if(i==="right"){const $=this._getYAxisLabelAlignment(m);F=$.textAlign,k=$.x}else if(n==="x"){if(i==="center")T=(t.top+t.bottom)/2+g;else if(xt(i)){const $=Object.keys(i)[0],B=i[$];T=this.chart.scales[$].getPixelForValue(B)+g}F=this._getXAxisLabelAlignment()}else if(n==="y"){if(i==="center")k=(t.left+t.right)/2-g;else if(xt(i)){const $=Object.keys(i)[0],B=i[$];k=this.chart.scales[$].getPixelForValue(B)}F=this._getYAxisLabelAlignment(m).textAlign}n==="y"&&(c==="start"?K="top":c==="end"&&(K="bottom"));const q=this._getLabelSizes();for(A=0,S=l.length;A<S;++A){C=l[A],E=C.label;const $=a.setContext(this.getContext(A));M=this.getPixelForTick(A)+a.labelOffset,I=this._resolveTickFontOptions(A),R=I.lineHeight,H=Wn(E)?E.length:1;const B=H/2,Y=$.color,U=$.textStrokeColor,W=$.textStrokeWidth;let O=F;o?(k=M,F==="inner"&&(A===S-1?O=this.options.reverse?"left":"right":A===0?O=this.options.reverse?"right":"left":O="center"),i==="top"?d==="near"||_!==0?V=-H*R+R/2:d==="center"?V=-q.highest.height/2-B*R+R:V=-q.highest.height+R/2:d==="near"||_!==0?V=R/2:d==="center"?V=q.highest.height/2-B*R:V=q.highest.height-H*R,p&&(V*=-1),_!==0&&!$.showLabelBackdrop&&(k+=R/2*Math.sin(_))):(T=M,V=(1-H)*R/2);let D;if($.showLabelBackdrop){const Q=Lr($.backdropPadding),z=q.heights[A],J=q.widths[A];let ee=V-Q.top,re=0-Q.left;switch(K){case"middle":ee-=z/2;break;case"bottom":ee-=z;break}switch(F){case"center":re-=J/2;break;case"right":re-=J;break;case"inner":A===S-1?re-=J:A>0&&(re-=J/2);break}D={left:re,top:ee,width:J+Q.width,height:z+Q.height,color:$.backdropColor}}w.push({label:E,font:I,textOffset:V,options:{rotation:_,color:Y,strokeColor:U,strokeWidth:W,textAlign:O,textBaseline:K,translation:[k,T],backdrop:D}})}return w}_getXAxisLabelAlignment(){const{position:t,ticks:n}=this.options;if(-Ao(this.labelRotation))return t==="top"?"left":"right";let i="center";return n.align==="start"?i="left":n.align==="end"?i="right":n.align==="inner"&&(i="inner"),i}_getYAxisLabelAlignment(t){const{position:n,ticks:{crossAlign:s,mirror:i,padding:a}}=this.options,o=this._getLabelSizes(),l=t+a,c=o.widest.width;let d,f;return n==="left"?i?(f=this.right+a,s==="near"?d="left":s==="center"?(d="center",f+=c/2):(d="right",f+=c)):(f=this.right-l,s==="near"?d="right":s==="center"?(d="center",f-=c/2):(d="left",f=this.left)):n==="right"?i?(f=this.left+a,s==="near"?d="right":s==="center"?(d="center",f-=c/2):(d="left",f-=c)):(f=this.left+l,s==="near"?d="left":s==="center"?(d="center",f+=c/2):(d="right",f=this.right)):d="right",{textAlign:d,x:f}}_computeLabelArea(){if(this.options.ticks.mirror)return;const t=this.chart,n=this.options.position;if(n==="left"||n==="right")return{top:0,left:this.left,bottom:t.height,right:this.right};if(n==="top"||n==="bottom")return{top:this.top,left:0,bottom:this.bottom,right:t.width}}drawBackground(){const{ctx:t,options:{backgroundColor:n},left:s,top:i,width:a,height:o}=this;n&&(t.save(),t.fillStyle=n,t.fillRect(s,i,a,o),t.restore())}getLineWidthForValue(t){const n=this.options.grid;if(!this._isVisible()||!n.display)return 0;const i=this.ticks.findIndex(a=>a.value===t);return i>=0?n.setContext(this.getContext(i)).lineWidth:0}drawGrid(t){const n=this.options.grid,s=this.ctx,i=this._gridLineItems||(this._gridLineItems=this._computeGridLineItems(t));let a,o;const l=(c,d,f)=>{!f.width||!f.color||(s.save(),s.lineWidth=f.width,s.strokeStyle=f.color,s.setLineDash(f.borderDash||[]),s.lineDashOffset=f.borderDashOffset,s.beginPath(),s.moveTo(c.x,c.y),s.lineTo(d.x,d.y),s.stroke(),s.restore())};if(n.display)for(a=0,o=i.length;a<o;++a){const c=i[a];n.drawOnChartArea&&l({x:c.x1,y:c.y1},{x:c.x2,y:c.y2},c),n.drawTicks&&l({x:c.tx1,y:c.ty1},{x:c.tx2,y:c.ty2},{color:c.tickColor,width:c.tickWidth,borderDash:c.tickBorderDash,borderDashOffset:c.tickBorderDashOffset})}}drawBorder(){const{chart:t,ctx:n,options:{border:s,grid:i}}=this,a=s.setContext(this.getContext()),o=s.display?a.width:0;if(!o)return;const l=i.setContext(this.getContext(0)).lineWidth,c=this._borderValue;let d,f,p,m;this.isHorizontal()?(d=Tc(t,this.left,o)-o/2,f=Tc(t,this.right,l)+l/2,p=m=c):(p=Tc(t,this.top,o)-o/2,m=Tc(t,this.bottom,l)+l/2,d=f=c),n.save(),n.lineWidth=a.width,n.strokeStyle=a.color,n.beginPath(),n.moveTo(d,p),n.lineTo(f,m),n.stroke(),n.restore()}drawLabels(t){if(!this.options.ticks.display)return;const s=this.ctx,i=this._computeLabelArea();i&&ly(s,i);const a=this.getLabelItems(t);for(const o of a){const l=o.options,c=o.font,d=o.label,f=o.textOffset;Xp(s,d,0,f,c,l)}i&&cy(s)}drawTitle(){const{ctx:t,options:{position:n,title:s,reverse:i}}=this;if(!s.display)return;const a=qs(s.font),o=Lr(s.padding),l=s.align;let c=a.lineHeight/2;n==="bottom"||n==="center"||xt(n)?(c+=o.bottom,Wn(s.text)&&(c+=a.lineHeight*(s.text.length-1))):c+=o.top;const{titleX:d,titleY:f,maxWidth:p,rotation:m}=J5e(this,c,n,l);Xp(t,s.text,0,0,a,{color:s.color,maxWidth:p,rotation:m,textAlign:X5e(l,n,i),textBaseline:"middle",translation:[d,f]})}draw(t){this._isVisible()&&(this.drawBackground(),this.drawGrid(t),this.drawBorder(),this.drawTitle(),this.drawLabels(t))}_layers(){const t=this.options,n=t.ticks&&t.ticks.z||0,s=it(t.grid&&t.grid.z,-1),i=it(t.border&&t.border.z,0);return!this._isVisible()||this.draw!==Ah.prototype.draw?[{z:n,draw:a=>{this.draw(a)}}]:[{z:s,draw:a=>{this.drawBackground(),this.drawGrid(a),this.drawTitle()}},{z:i,draw:()=>{this.drawBorder()}},{z:n,draw:a=>{this.drawLabels(a)}}]}getMatchingVisibleMetas(t){const n=this.chart.getSortedVisibleDatasetMetas(),s=this.axis+"AxisID",i=[];let a,o;for(a=0,o=n.length;a<o;++a){const l=n[a];l[s]===this.id&&(!t||l.type===t)&&i.push(l)}return i}_resolveTickFontOptions(t){const n=this.options.ticks.setContext(this.getContext(t));return qs(n.font)}_maxDigits(){const t=this._resolveTickFontOptions(0).lineHeight;return(this.isHorizontal()?this.width:this.height)/t}}class Jg{constructor(t,n,s){this.type=t,this.scope=n,this.override=s,this.items=Object.create(null)}isForType(t){return Object.prototype.isPrototypeOf.call(this.type.prototype,t.prototype)}register(t){const n=Object.getPrototypeOf(t);let s;tje(n)&&(s=this.register(n));const i=this.items,a=t.id,o=this.scope+"."+a;if(!a)throw new Error("class does not have id: "+t);return a in i||(i[a]=t,Z5e(t,o,s),this.override&&Rn.override(t.id,t.overrides)),o}get(t){return this.items[t]}unregister(t){const n=this.items,s=t.id,i=this.scope;s in n&&delete n[s],i&&s in Rn[i]&&(delete Rn[i][s],this.override&&delete fu[s])}}function Z5e(e,t,n){const s=Gp(Object.create(null),[n?Rn.get(n):{},Rn.get(t),e.defaults]);Rn.set(t,s),e.defaultRoutes&&eje(t,e.defaultRoutes),e.descriptors&&Rn.describe(t,e.descriptors)}function eje(e,t){Object.keys(t).forEach(n=>{const s=n.split("."),i=s.pop(),a=[e].concat(s).join("."),o=t[n].split("."),l=o.pop(),c=o.join(".");Rn.route(a,i,c,l)})}function tje(e){return"id"in e&&"defaults"in e}let nje=class{constructor(){this.controllers=new Jg(Km,"datasets",!0),this.elements=new Jg(Wo,"elements"),this.plugins=new Jg(Object,"plugins"),this.scales=new Jg(Ah,"scales"),this._typedRegistries=[this.controllers,this.scales,this.elements]}add(...t){this._each("register",t)}remove(...t){this._each("unregister",t)}addControllers(...t){this._each("register",t,this.controllers)}addElements(...t){this._each("register",t,this.elements)}addPlugins(...t){this._each("register",t,this.plugins)}addScales(...t){this._each("register",t,this.scales)}getController(t){return this._get(t,this.controllers,"controller")}getElement(t){return this._get(t,this.elements,"element")}getPlugin(t){return this._get(t,this.plugins,"plugin")}getScale(t){return this._get(t,this.scales,"scale")}removeControllers(...t){this._each("unregister",t,this.controllers)}removeElements(...t){this._each("unregister",t,this.elements)}removePlugins(...t){this._each("unregister",t,this.plugins)}removeScales(...t){this._each("unregister",t,this.scales)}_each(t,n,s){[...n].forEach(i=>{const a=s||this._getRegistryForType(i);s||a.isForType(i)||a===this.plugins&&i.id?this._exec(t,a,i):It(i,o=>{const l=s||this._getRegistryForType(o);this._exec(t,l,o)})})}_exec(t,n,s){const i=lN(t);rn(s["before"+i],[],s),n[t](s),rn(s["after"+i],[],s)}_getRegistryForType(t){for(let n=0;n<this._typedRegistries.length;n++){const s=this._typedRegistries[n];if(s.isForType(t))return s}return this.plugins}_get(t,n,s){const i=n.get(t);if(i===void 0)throw new Error('"'+t+'" is not a registered '+s+".");return i}};var Na=new nje;class sje{constructor(){this._init=void 0}notify(t,n,s,i){if(n==="beforeInit"&&(this._init=this._createDescriptors(t,!0),this._notify(this._init,t,"install")),this._init===void 0)return;const a=i?this._descriptors(t).filter(i):this._descriptors(t),o=this._notify(a,t,n,s);return n==="afterDestroy"&&(this._notify(a,t,"stop"),this._notify(this._init,t,"uninstall"),this._init=void 0),o}_notify(t,n,s,i){i=i||{};for(const a of t){const o=a.plugin,l=o[s],c=[n,i,a.options];if(rn(l,c,o)===!1&&i.cancelable)return!1}return!0}invalidate(){Tt(this._cache)||(this._oldCache=this._cache,this._cache=void 0)}_descriptors(t){if(this._cache)return this._cache;const n=this._cache=this._createDescriptors(t);return this._notifyStateChanges(t),n}_createDescriptors(t,n){const s=t&&t.config,i=it(s.options&&s.options.plugins,{}),a=ije(s);return i===!1&&!n?[]:aje(t,a,i,n)}_notifyStateChanges(t){const n=this._oldCache||[],s=this._cache,i=(a,o)=>a.filter(l=>!o.some(c=>l.plugin.id===c.plugin.id));this._notify(i(n,s),t,"stop"),this._notify(i(s,n),t,"start")}}function ije(e){const t={},n=[],s=Object.keys(Na.plugins.items);for(let a=0;a<s.length;a++)n.push(Na.getPlugin(s[a]));const i=e.plugins||[];for(let a=0;a<i.length;a++){const o=i[a];n.indexOf(o)===-1&&(n.push(o),t[o.id]=!0)}return{plugins:n,localIds:t}}function rje(e,t){return!t&&e===!1?null:e===!0?{}:e}function aje(e,{plugins:t,localIds:n},s,i){const a=[],o=e.getContext();for(const l of t){const c=l.id,d=rje(s[c],i);d!==null&&a.push({plugin:l,options:oje(e.config,{plugin:l,local:n[c]},d,o)})}return a}function oje(e,{plugin:t,local:n},s,i){const a=e.pluginScopeKeys(t),o=e.getOptionScopes(s,a);return n&&t.defaults&&o.push(t.defaults),e.createResolver(o,i,[""],{scriptable:!1,indexable:!1,allKeys:!0})}function hC(e,t){const n=Rn.datasets[e]||{};return((t.datasets||{})[e]||{}).indexAxis||t.indexAxis||n.indexAxis||"x"}function lje(e,t){let n=e;return e==="_index_"?n=t:e==="_value_"&&(n=t==="x"?"y":"x"),n}function cje(e,t){return e===t?"_index_":"_value_"}function SD(e){if(e==="x"||e==="y"||e==="r")return e}function uje(e){if(e==="top"||e==="bottom")return"x";if(e==="left"||e==="right")return"y"}function fC(e,...t){if(SD(e))return e;for(const n of t){const s=n.axis||uje(n.position)||e.length>1&&SD(e[0].toLowerCase());if(s)return s}throw new Error(`Cannot determine type of '${e}' axis. Please provide 'axis' or 'position' option.`)}function CD(e,t,n){if(n[t+"AxisID"]===e)return{axis:t}}function dje(e,t){if(t.data&&t.data.datasets){const n=t.data.datasets.filter(s=>s.xAxisID===e||s.yAxisID===e);if(n.length)return CD(e,"x",n[0])||CD(e,"y",n[0])}return{}}function hje(e,t){const n=fu[e.type]||{scales:{}},s=t.scales||{},i=hC(e.type,t),a=Object.create(null);return Object.keys(s).forEach(o=>{const l=s[o];if(!xt(l))return console.error(`Invalid scale configuration for scale: ${o}`);if(l._proxy)return console.warn(`Ignoring resolver passed as options for scale: ${o}`);const c=fC(o,l,dje(o,e),Rn.scales[l.type]),d=cje(c,i),f=n.scales||{};a[o]=xp(Object.create(null),[{axis:c},l,f[c],f[d]])}),e.data.datasets.forEach(o=>{const l=o.type||e.type,c=o.indexAxis||hC(l,t),f=(fu[l]||{}).scales||{};Object.keys(f).forEach(p=>{const m=lje(p,c),g=o[m+"AxisID"]||m;a[g]=a[g]||Object.create(null),xp(a[g],[{axis:m},s[g],f[p]])})}),Object.keys(a).forEach(o=>{const l=a[o];xp(l,[Rn.scales[l.type],Rn.scale])}),a}function cU(e){const t=e.options||(e.options={});t.plugins=it(t.plugins,{}),t.scales=hje(e,t)}function uU(e){return e=e||{},e.datasets=e.datasets||[],e.labels=e.labels||[],e}function fje(e){return e=e||{},e.data=uU(e.data),cU(e),e}const jD=new Map,dU=new Set;function Zg(e,t){let n=jD.get(e);return n||(n=t(),jD.set(e,n),dU.add(n)),n}const zf=(e,t,n)=>{const s=hu(t,n);s!==void 0&&e.add(s)};class pje{constructor(t){this._config=fje(t),this._scopeCache=new Map,this._resolverCache=new Map}get platform(){return this._config.platform}get type(){return this._config.type}set type(t){this._config.type=t}get data(){return this._config.data}set data(t){this._config.data=uU(t)}get options(){return this._config.options}set options(t){this._config.options=t}get plugins(){return this._config.plugins}update(){const t=this._config;this.clearCache(),cU(t)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(t){return Zg(t,()=>[[`datasets.${t}`,""]])}datasetAnimationScopeKeys(t,n){return Zg(`${t}.transition.${n}`,()=>[[`datasets.${t}.transitions.${n}`,`transitions.${n}`],[`datasets.${t}`,""]])}datasetElementScopeKeys(t,n){return Zg(`${t}-${n}`,()=>[[`datasets.${t}.elements.${n}`,`datasets.${t}`,`elements.${n}`,""]])}pluginScopeKeys(t){const n=t.id,s=this.type;return Zg(`${s}-plugin-${n}`,()=>[[`plugins.${n}`,...t.additionalOptionScopes||[]]])}_cachedScopes(t,n){const s=this._scopeCache;let i=s.get(t);return(!i||n)&&(i=new Map,s.set(t,i)),i}getOptionScopes(t,n,s){const{options:i,type:a}=this,o=this._cachedScopes(t,s),l=o.get(n);if(l)return l;const c=new Set;n.forEach(f=>{t&&(c.add(t),f.forEach(p=>zf(c,t,p))),f.forEach(p=>zf(c,i,p)),f.forEach(p=>zf(c,fu[a]||{},p)),f.forEach(p=>zf(c,Rn,p)),f.forEach(p=>zf(c,uC,p))});const d=Array.from(c);return d.length===0&&d.push(Object.create(null)),dU.has(n)&&o.set(n,d),d}chartOptionScopes(){const{options:t,type:n}=this;return[t,fu[n]||{},Rn.datasets[n]||{},{type:n},Rn,uC]}resolveNamedOptions(t,n,s,i=[""]){const a={$shared:!0},{resolver:o,subPrefixes:l}=ND(this._resolverCache,t,i);let c=o;if(xje(o,n)){a.$shared=!1,s=Ql(s)?s():s;const d=this.createResolver(t,s,l);c=Xd(o,s,d)}for(const d of n)a[d]=c[d];return a}createResolver(t,n,s=[""],i){const{resolver:a}=ND(this._resolverCache,t,s);return xt(n)?Xd(a,n,void 0,i):a}}function ND(e,t,n){let s=e.get(t);s||(s=new Map,e.set(t,s));const i=n.join();let a=s.get(i);return a||(a={resolver:pN(t,n),subPrefixes:n.filter(l=>!l.toLowerCase().includes("hover"))},s.set(i,a)),a}const mje=e=>xt(e)&&Object.getOwnPropertyNames(e).some(t=>Ql(e[t]));function xje(e,t){const{isScriptable:n,isIndexable:s}=HV(e);for(const i of t){const a=n(i),o=s(i),l=(o||a)&&e[i];if(a&&(Ql(l)||mje(l))||o&&Wn(l))return!0}return!1}var gje="4.5.1";const bje=["top","bottom","left","right","chartArea"];function kD(e,t){return e==="top"||e==="bottom"||bje.indexOf(e)===-1&&t==="x"}function ED(e,t){return function(n,s){return n[e]===s[e]?n[t]-s[t]:n[e]-s[e]}}function FD(e){const t=e.chart,n=t.options.animation;t.notifyPlugins("afterRender"),rn(n&&n.onComplete,[e],t)}function vje(e){const t=e.chart,n=t.options.animation;rn(n&&n.onProgress,[e],t)}function hU(e){return gN()&&typeof e=="string"?e=document.getElementById(e):e&&e.length&&(e=e[0]),e&&e.canvas&&(e=e.canvas),e}const Ub={},TD=e=>{const t=hU(e);return Object.values(Ub).filter(n=>n.canvas===t).pop()};function yje(e,t,n){const s=Object.keys(e);for(const i of s){const a=+i;if(a>=t){const o=e[i];delete e[i],(n>0||a>t)&&(e[a+n]=o)}}}function _je(e,t,n,s){return!n||e.type==="mouseout"?null:s?t:e}let hy=class{static defaults=Rn;static instances=Ub;static overrides=fu;static registry=Na;static version=gje;static getChart=TD;static register(...t){Na.add(...t),MD()}static unregister(...t){Na.remove(...t),MD()}constructor(t,n){const s=this.config=new pje(n),i=hU(t),a=TD(i);if(a)throw new Error("Canvas is already in use. Chart with ID '"+a.id+"' must be destroyed before the canvas with ID '"+a.canvas.id+"' can be reused.");const o=s.createResolver(s.chartOptionScopes(),this.getContext());this.platform=new(s.platform||B5e(i)),this.platform.updateConfig(s);const l=this.platform.acquireContext(i,o.aspectRatio),c=l&&l.canvas,d=c&&c.height,f=c&&c.width;if(this.id=xSe(),this.ctx=l,this.canvas=c,this.width=f,this.height=d,this._options=o,this._aspectRatio=this.aspectRatio,this._layers=[],this._metasets=[],this._stacks=void 0,this.boxes=[],this.currentDevicePixelRatio=void 0,this.chartArea=void 0,this._active=[],this._lastEvent=void 0,this._listeners={},this._responsiveListeners=void 0,this._sortedMetasets=[],this.scales={},this._plugins=new sje,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=OSe(p=>this.update(p),o.resizeDelay||0),this._dataChanges=[],Ub[this.id]=this,!l||!c){console.error("Failed to create chart: can't acquire context from the given item");return}vo.listen(this,"complete",FD),vo.listen(this,"progress",vje),this._initialize(),this.attached&&this.update()}get aspectRatio(){const{options:{aspectRatio:t,maintainAspectRatio:n},width:s,height:i,_aspectRatio:a}=this;return Tt(t)?n&&a?a:i?s/i:null:t}get data(){return this.config.data}set data(t){this.config.data=t}get options(){return this._options}set options(t){this.config.options=t}get registry(){return Na}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():eD(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return XR(this.canvas,this.ctx),this}stop(){return vo.stop(this),this}resize(t,n){vo.running(this)?this._resizeBeforeDraw={width:t,height:n}:this._resize(t,n)}_resize(t,n){const s=this.options,i=this.canvas,a=s.maintainAspectRatio&&this.aspectRatio,o=this.platform.getMaximumSize(i,t,n,a),l=s.devicePixelRatio||this.platform.getDevicePixelRatio(),c=this.width?"resize":"attach";this.width=o.width,this.height=o.height,this._aspectRatio=this.aspectRatio,eD(this,l,!0)&&(this.notifyPlugins("resize",{size:o}),rn(s.onResize,[this,o],this),this.attached&&this._doResize(c)&&this.render())}ensureScalesHaveIDs(){const n=this.options.scales||{};It(n,(s,i)=>{s.id=i})}buildOrUpdateScales(){const t=this.options,n=t.scales,s=this.scales,i=Object.keys(s).reduce((o,l)=>(o[l]=!1,o),{});let a=[];n&&(a=a.concat(Object.keys(n).map(o=>{const l=n[o],c=fC(o,l),d=c==="r",f=c==="x";return{options:l,dposition:d?"chartArea":f?"bottom":"left",dtype:d?"radialLinear":f?"category":"linear"}}))),It(a,o=>{const l=o.options,c=l.id,d=fC(c,l),f=it(l.type,o.dtype);(l.position===void 0||kD(l.position,d)!==kD(o.dposition))&&(l.position=o.dposition),i[c]=!0;let p=null;if(c in s&&s[c].type===f)p=s[c];else{const m=Na.getScale(f);p=new m({id:c,type:f,ctx:this.ctx,chart:this}),s[p.id]=p}p.init(l,t)}),It(i,(o,l)=>{o||delete s[l]}),It(s,o=>{Tr.configure(this,o,o.options),Tr.addBox(this,o)})}_updateMetasets(){const t=this._metasets,n=this.data.datasets.length,s=t.length;if(t.sort((i,a)=>i.index-a.index),s>n){for(let i=n;i<s;++i)this._destroyDatasetMeta(i);t.splice(n,s-n)}this._sortedMetasets=t.slice(0).sort(ED("order","index"))}_removeUnreferencedMetasets(){const{_metasets:t,data:{datasets:n}}=this;t.length>n.length&&delete this._stacks,t.forEach((s,i)=>{n.filter(a=>a===s._dataset).length===0&&this._destroyDatasetMeta(i)})}buildOrUpdateControllers(){const t=[],n=this.data.datasets;let s,i;for(this._removeUnreferencedMetasets(),s=0,i=n.length;s<i;s++){const a=n[s];let o=this.getDatasetMeta(s);const l=a.type||this.config.type;if(o.type&&o.type!==l&&(this._destroyDatasetMeta(s),o=this.getDatasetMeta(s)),o.type=l,o.indexAxis=a.indexAxis||hC(l,this.options),o.order=a.order||0,o.index=s,o.label=""+a.label,o.visible=this.isDatasetVisible(s),o.controller)o.controller.updateIndex(s),o.controller.linkScales();else{const c=Na.getController(l),{datasetElementType:d,dataElementType:f}=Rn.datasets[l];Object.assign(c,{dataElementType:Na.getElement(f),datasetElementType:d&&Na.getElement(d)}),o.controller=new c(this,s),t.push(o.controller)}}return this._updateMetasets(),t}_resetElements(){It(this.data.datasets,(t,n)=>{this.getDatasetMeta(n).controller.reset()},this)}reset(){this._resetElements(),this.notifyPlugins("reset")}update(t){const n=this.config;n.update();const s=this._options=n.createResolver(n.chartOptionScopes(),this.getContext()),i=this._animationsDisabled=!s.animation;if(this._updateScales(),this._checkEventBindings(),this._updateHiddenIndices(),this._plugins.invalidate(),this.notifyPlugins("beforeUpdate",{mode:t,cancelable:!0})===!1)return;const a=this.buildOrUpdateControllers();this.notifyPlugins("beforeElementsUpdate");let o=0;for(let d=0,f=this.data.datasets.length;d<f;d++){const{controller:p}=this.getDatasetMeta(d),m=!i&&a.indexOf(p)===-1;p.buildOrUpdateElements(m),o=Math.max(+p.getMaxOverflow(),o)}o=this._minPadding=s.layout.autoPadding?o:0,this._updateLayout(o),i||It(a,d=>{d.reset()}),this._updateDatasets(t),this.notifyPlugins("afterUpdate",{mode:t}),this._layers.sort(ED("z","_idx"));const{_active:l,_lastEvent:c}=this;c?this._eventHandler(c,!0):l.length&&this._updateHoverStyles(l,l,!0),this.render()}_updateScales(){It(this.scales,t=>{Tr.removeBox(this,t)}),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){const t=this.options,n=new Set(Object.keys(this._listeners)),s=new Set(t.events);(!$R(n,s)||!!this._responsiveListeners!==t.responsive)&&(this.unbindEvents(),this.bindEvents())}_updateHiddenIndices(){const{_hiddenIndices:t}=this,n=this._getUniformDataChanges()||[];for(const{method:s,start:i,count:a}of n){const o=s==="_removeElements"?-a:a;yje(t,i,o)}}_getUniformDataChanges(){const t=this._dataChanges;if(!t||!t.length)return;this._dataChanges=[];const n=this.data.datasets.length,s=a=>new Set(t.filter(o=>o[0]===a).map((o,l)=>l+","+o.splice(1).join(","))),i=s(0);for(let a=1;a<n;a++)if(!$R(i,s(a)))return;return Array.from(i).map(a=>a.split(",")).map(a=>({method:a[1],start:+a[2],count:+a[3]}))}_updateLayout(t){if(this.notifyPlugins("beforeLayout",{cancelable:!0})===!1)return;Tr.update(this,this.width,this.height,t);const n=this.chartArea,s=n.width<=0||n.height<=0;this._layers=[],It(this.boxes,i=>{s&&i.position==="chartArea"||(i.configure&&i.configure(),this._layers.push(...i._layers()))},this),this._layers.forEach((i,a)=>{i._idx=a}),this.notifyPlugins("afterLayout")}_updateDatasets(t){if(this.notifyPlugins("beforeDatasetsUpdate",{mode:t,cancelable:!0})!==!1){for(let n=0,s=this.data.datasets.length;n<s;++n)this.getDatasetMeta(n).controller.configure();for(let n=0,s=this.data.datasets.length;n<s;++n)this._updateDataset(n,Ql(t)?t({datasetIndex:n}):t);this.notifyPlugins("afterDatasetsUpdate",{mode:t})}}_updateDataset(t,n){const s=this.getDatasetMeta(t),i={meta:s,index:t,mode:n,cancelable:!0};this.notifyPlugins("beforeDatasetUpdate",i)!==!1&&(s.controller._update(n),i.cancelable=!1,this.notifyPlugins("afterDatasetUpdate",i))}render(){this.notifyPlugins("beforeRender",{cancelable:!0})!==!1&&(vo.has(this)?this.attached&&!vo.running(this)&&vo.start(this):(this.draw(),FD({chart:this})))}draw(){let t;if(this._resizeBeforeDraw){const{width:s,height:i}=this._resizeBeforeDraw;this._resizeBeforeDraw=null,this._resize(s,i)}if(this.clear(),this.width<=0||this.height<=0||this.notifyPlugins("beforeDraw",{cancelable:!0})===!1)return;const n=this._layers;for(t=0;t<n.length&&n[t].z<=0;++t)n[t].draw(this.chartArea);for(this._drawDatasets();t<n.length;++t)n[t].draw(this.chartArea);this.notifyPlugins("afterDraw")}_getSortedDatasetMetas(t){const n=this._sortedMetasets,s=[];let i,a;for(i=0,a=n.length;i<a;++i){const o=n[i];(!t||o.visible)&&s.push(o)}return s}getSortedVisibleDatasetMetas(){return this._getSortedDatasetMetas(!0)}_drawDatasets(){if(this.notifyPlugins("beforeDatasetsDraw",{cancelable:!0})===!1)return;const t=this.getSortedVisibleDatasetMetas();for(let n=t.length-1;n>=0;--n)this._drawDataset(t[n]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(t){const n=this.ctx,s={meta:t,index:t.index,cancelable:!0},i=eU(this,t);this.notifyPlugins("beforeDatasetDraw",s)!==!1&&(i&&ly(n,i),t.controller.draw(),i&&cy(n),s.cancelable=!1,this.notifyPlugins("afterDatasetDraw",s))}isPointInArea(t){return Qp(t,this.chartArea,this._minPadding)}getElementsAtEventForMode(t,n,s,i){const a=b5e.modes[n];return typeof a=="function"?a(this,t,s,i):[]}getDatasetMeta(t){const n=this.data.datasets[t],s=this._metasets;let i=s.filter(a=>a&&a._dataset===n).pop();return i||(i={type:null,data:[],dataset:null,controller:null,hidden:null,xAxisID:null,yAxisID:null,order:n&&n.order||0,index:t,_dataset:n,_parsed:[],_sorted:!1},s.push(i)),i}getContext(){return this.$context||(this.$context=wu(null,{chart:this,type:"chart"}))}getVisibleDatasetCount(){return this.getSortedVisibleDatasetMetas().length}isDatasetVisible(t){const n=this.data.datasets[t];if(!n)return!1;const s=this.getDatasetMeta(t);return typeof s.hidden=="boolean"?!s.hidden:!n.hidden}setDatasetVisibility(t,n){const s=this.getDatasetMeta(t);s.hidden=!n}toggleDataVisibility(t){this._hiddenIndices[t]=!this._hiddenIndices[t]}getDataVisibility(t){return!this._hiddenIndices[t]}_updateVisibility(t,n,s){const i=s?"show":"hide",a=this.getDatasetMeta(t),o=a.controller._resolveAnimations(void 0,i);Kp(n)?(a.data[n].hidden=!s,this.update()):(this.setDatasetVisibility(t,s),o.update(a,{visible:s}),this.update(l=>l.datasetIndex===t?i:void 0))}hide(t,n){this._updateVisibility(t,n,!1)}show(t,n){this._updateVisibility(t,n,!0)}_destroyDatasetMeta(t){const n=this._metasets[t];n&&n.controller&&n.controller._destroy(),delete this._metasets[t]}_stop(){let t,n;for(this.stop(),vo.remove(this),t=0,n=this.data.datasets.length;t<n;++t)this._destroyDatasetMeta(t)}destroy(){this.notifyPlugins("beforeDestroy");const{canvas:t,ctx:n}=this;this._stop(),this.config.clearCache(),t&&(this.unbindEvents(),XR(t,n),this.platform.releaseContext(n),this.canvas=null,this.ctx=null),delete Ub[this.id],this.notifyPlugins("afterDestroy")}toBase64Image(...t){return this.canvas.toDataURL(...t)}bindEvents(){this.bindUserEvents(),this.options.responsive?this.bindResponsiveEvents():this.attached=!0}bindUserEvents(){const t=this._listeners,n=this.platform,s=(a,o)=>{n.addEventListener(this,a,o),t[a]=o},i=(a,o,l)=>{a.offsetX=o,a.offsetY=l,this._eventHandler(a)};It(this.options.events,a=>s(a,i))}bindResponsiveEvents(){this._responsiveListeners||(this._responsiveListeners={});const t=this._responsiveListeners,n=this.platform,s=(c,d)=>{n.addEventListener(this,c,d),t[c]=d},i=(c,d)=>{t[c]&&(n.removeEventListener(this,c,d),delete t[c])},a=(c,d)=>{this.canvas&&this.resize(c,d)};let o;const l=()=>{i("attach",l),this.attached=!0,this.resize(),s("resize",a),s("detach",o)};o=()=>{this.attached=!1,i("resize",a),this._stop(),this._resize(0,0),s("attach",l)},n.isAttached(this.canvas)?l():o()}unbindEvents(){It(this._listeners,(t,n)=>{this.platform.removeEventListener(this,n,t)}),this._listeners={},It(this._responsiveListeners,(t,n)=>{this.platform.removeEventListener(this,n,t)}),this._responsiveListeners=void 0}updateHoverStyle(t,n,s){const i=s?"set":"remove";let a,o,l,c;for(n==="dataset"&&(a=this.getDatasetMeta(t[0].datasetIndex),a.controller["_"+i+"DatasetHoverStyle"]()),l=0,c=t.length;l<c;++l){o=t[l];const d=o&&this.getDatasetMeta(o.datasetIndex).controller;d&&d[i+"HoverStyle"](o.element,o.datasetIndex,o.index)}}getActiveElements(){return this._active||[]}setActiveElements(t){const n=this._active||[],s=t.map(({datasetIndex:a,index:o})=>{const l=this.getDatasetMeta(a);if(!l)throw new Error("No dataset found at index "+a);return{datasetIndex:a,element:l.data[o],index:o}});!I0(s,n)&&(this._active=s,this._lastEvent=null,this._updateHoverStyles(s,n))}notifyPlugins(t,n,s){return this._plugins.notify(this,t,n,s)}isPluginEnabled(t){return this._plugins._cache.filter(n=>n.plugin.id===t).length===1}_updateHoverStyles(t,n,s){const i=this.options.hover,a=(c,d)=>c.filter(f=>!d.some(p=>f.datasetIndex===p.datasetIndex&&f.index===p.index)),o=a(n,t),l=s?t:a(t,n);o.length&&this.updateHoverStyle(o,i.mode,!1),l.length&&i.mode&&this.updateHoverStyle(l,i.mode,!0)}_eventHandler(t,n){const s={event:t,replay:n,cancelable:!0,inChartArea:this.isPointInArea(t)},i=o=>(o.options.events||this.options.events).includes(t.native.type);if(this.notifyPlugins("beforeEvent",s,i)===!1)return;const a=this._handleEvent(t,n,s.inChartArea);return s.cancelable=!1,this.notifyPlugins("afterEvent",s,i),(a||s.changed)&&this.render(),this}_handleEvent(t,n,s){const{_active:i=[],options:a}=this,o=n,l=this._getActiveElements(t,i,s,o),c=wSe(t),d=_je(t,this._lastEvent,s,c);s&&(this._lastEvent=null,rn(a.onHover,[t,l,this],this),c&&rn(a.onClick,[t,l,this],this));const f=!I0(l,i);return(f||n)&&(this._active=l,this._updateHoverStyles(l,i,n)),this._lastEvent=d,f}_getActiveElements(t,n,s,i){if(t.type==="mouseout")return[];if(!s)return n;const a=this.options.hover;return this.getElementsAtEventForMode(t,a.mode,a,i)}};function MD(){return It(hy.instances,e=>e._plugins.invalidate())}function wje(e,t,n){const{startAngle:s,x:i,y:a,outerRadius:o,innerRadius:l,options:c}=t,{borderWidth:d,borderJoinStyle:f}=c,p=Math.min(d/o,Wi(s-n));if(e.beginPath(),e.arc(i,a,o-d/2,s+p/2,n-p/2),l>0){const m=Math.min(d/l,Wi(s-n));e.arc(i,a,l+d/2,n-m/2,s+m/2,!0)}else{const m=Math.min(d/2,o*Wi(s-n));if(f==="round")e.arc(i,a,m,n-Lt/2,s+Lt/2,!0);else if(f==="bevel"){const g=2*m*m,b=-g*Math.cos(n+Lt/2)+i,_=-g*Math.sin(n+Lt/2)+a,w=g*Math.cos(s+Lt/2)+i,A=g*Math.sin(s+Lt/2)+a;e.lineTo(b,_),e.lineTo(w,A)}}e.closePath(),e.moveTo(0,0),e.rect(0,0,e.canvas.width,e.canvas.height),e.clip("evenodd")}function Aje(e,t,n){const{startAngle:s,pixelMargin:i,x:a,y:o,outerRadius:l,innerRadius:c}=t;let d=i/l;e.beginPath(),e.arc(a,o,l,s-d,n+d),c>i?(d=i/c,e.arc(a,o,c,n+d,s-d,!0)):e.arc(a,o,i,n+ls,s-ls),e.closePath(),e.clip()}function Sje(e){return fN(e,["outerStart","outerEnd","innerStart","innerEnd"])}function Cje(e,t,n,s){const i=Sje(e.options.borderRadius),a=(n-t)/2,o=Math.min(a,s*t/2),l=c=>{const d=(n-Math.min(a,c))*s/2;return Ws(c,0,Math.min(a,d))};return{outerStart:l(i.outerStart),outerEnd:l(i.outerEnd),innerStart:Ws(i.innerStart,0,o),innerEnd:Ws(i.innerEnd,0,o)}}function gd(e,t,n,s){return{x:n+e*Math.cos(t),y:s+e*Math.sin(t)}}function U0(e,t,n,s,i,a){const{x:o,y:l,startAngle:c,pixelMargin:d,innerRadius:f}=t,p=Math.max(t.outerRadius+s+n-d,0),m=f>0?f+s+n+d:0;let g=0;const b=i-c;if(s){const $=f>0?f-s:0,B=p>0?p-s:0,Y=($+B)/2,U=Y!==0?b*Y/(Y+s):b;g=(b-U)/2}const _=Math.max(.001,b*p-n/Lt)/p,w=(b-_)/2,A=c+w+g,S=i-w-g,{outerStart:C,outerEnd:E,innerStart:k,innerEnd:T}=Cje(t,m,p,S-A),F=p-C,M=p-E,I=A+C/F,R=S-E/M,H=m+k,V=m+T,K=A+k/H,q=S-T/V;if(e.beginPath(),a){const $=(I+R)/2;if(e.arc(o,l,p,I,$),e.arc(o,l,p,$,R),E>0){const W=gd(M,R,o,l);e.arc(W.x,W.y,E,R,S+ls)}const B=gd(V,S,o,l);if(e.lineTo(B.x,B.y),T>0){const W=gd(V,q,o,l);e.arc(W.x,W.y,T,S+ls,q+Math.PI)}const Y=(S-T/m+(A+k/m))/2;if(e.arc(o,l,m,S-T/m,Y,!0),e.arc(o,l,m,Y,A+k/m,!0),k>0){const W=gd(H,K,o,l);e.arc(W.x,W.y,k,K+Math.PI,A-ls)}const U=gd(F,A,o,l);if(e.lineTo(U.x,U.y),C>0){const W=gd(F,I,o,l);e.arc(W.x,W.y,C,A-ls,I)}}else{e.moveTo(o,l);const $=Math.cos(I)*p+o,B=Math.sin(I)*p+l;e.lineTo($,B);const Y=Math.cos(R)*p+o,U=Math.sin(R)*p+l;e.lineTo(Y,U)}e.closePath()}function jje(e,t,n,s,i){const{fullCircles:a,startAngle:o,circumference:l}=t;let c=t.endAngle;if(a){U0(e,t,n,s,c,i);for(let d=0;d<a;++d)e.fill();isNaN(l)||(c=o+(l%_n||_n))}return U0(e,t,n,s,c,i),e.fill(),c}function Nje(e,t,n,s,i){const{fullCircles:a,startAngle:o,circumference:l,options:c}=t,{borderWidth:d,borderJoinStyle:f,borderDash:p,borderDashOffset:m,borderRadius:g}=c,b=c.borderAlign==="inner";if(!d)return;e.setLineDash(p||[]),e.lineDashOffset=m,b?(e.lineWidth=d*2,e.lineJoin=f||"round"):(e.lineWidth=d,e.lineJoin=f||"bevel");let _=t.endAngle;if(a){U0(e,t,n,s,_,i);for(let w=0;w<a;++w)e.stroke();isNaN(l)||(_=o+(l%_n||_n))}b&&Aje(e,t,_),c.selfJoin&&_-o>=Lt&&g===0&&f!=="miter"&&wje(e,t,_),a||(U0(e,t,n,s,_,i),e.stroke())}class kje extends Wo{static id="arc";static defaults={borderAlign:"center",borderColor:"#fff",borderDash:[],borderDashOffset:0,borderJoinStyle:void 0,borderRadius:0,borderWidth:2,offset:0,spacing:0,angle:void 0,circular:!0,selfJoin:!1};static defaultRoutes={backgroundColor:"backgroundColor"};static descriptors={_scriptable:!0,_indexable:t=>t!=="borderDash"};circumference;endAngle;fullCircles;innerRadius;outerRadius;pixelMargin;startAngle;constructor(t){super(),this.options=void 0,this.circumference=void 0,this.startAngle=void 0,this.endAngle=void 0,this.innerRadius=void 0,this.outerRadius=void 0,this.pixelMargin=0,this.fullCircles=0,t&&Object.assign(this,t)}inRange(t,n,s){const i=this.getProps(["x","y"],s),{angle:a,distance:o}=DV(i,{x:t,y:n}),{startAngle:l,endAngle:c,innerRadius:d,outerRadius:f,circumference:p}=this.getProps(["startAngle","endAngle","innerRadius","outerRadius","circumference"],s),m=(this.options.spacing+this.options.borderWidth)/2,g=it(p,c-l),b=Yp(a,l,c)&&l!==c,_=g>=_n||b,w=So(o,d+m,f+m);return _&&w}getCenterPoint(t){const{x:n,y:s,startAngle:i,endAngle:a,innerRadius:o,outerRadius:l}=this.getProps(["x","y","startAngle","endAngle","innerRadius","outerRadius"],t),{offset:c,spacing:d}=this.options,f=(i+a)/2,p=(o+l+d+c)/2;return{x:n+Math.cos(f)*p,y:s+Math.sin(f)*p}}tooltipPosition(t){return this.getCenterPoint(t)}draw(t){const{options:n,circumference:s}=this,i=(n.offset||0)/4,a=(n.spacing||0)/2,o=n.circular;if(this.pixelMargin=n.borderAlign==="inner"?.33:0,this.fullCircles=s>_n?Math.floor(s/_n):0,s===0||this.innerRadius<0||this.outerRadius<0)return;t.save();const l=(this.startAngle+this.endAngle)/2;t.translate(Math.cos(l)*i,Math.sin(l)*i);const c=1-Math.sin(Math.min(Lt,s||0)),d=i*c;t.fillStyle=n.backgroundColor,t.strokeStyle=n.borderColor,jje(t,this,d,a,o),Nje(t,this,d,a,o),t.restore()}}function fU(e,t,n=t){e.lineCap=it(n.borderCapStyle,t.borderCapStyle),e.setLineDash(it(n.borderDash,t.borderDash)),e.lineDashOffset=it(n.borderDashOffset,t.borderDashOffset),e.lineJoin=it(n.borderJoinStyle,t.borderJoinStyle),e.lineWidth=it(n.borderWidth,t.borderWidth),e.strokeStyle=it(n.borderColor,t.borderColor)}function Eje(e,t,n){e.lineTo(n.x,n.y)}function Fje(e){return e.stepped?GSe:e.tension||e.cubicInterpolationMode==="monotone"?KSe:Eje}function pU(e,t,n={}){const s=e.length,{start:i=0,end:a=s-1}=n,{start:o,end:l}=t,c=Math.max(i,o),d=Math.min(a,l),f=i<o&&a<o||i>l&&a>l;return{count:s,start:c,loop:t.loop,ilen:d<c&&!f?s+d-c:d-c}}function Tje(e,t,n,s){const{points:i,options:a}=t,{count:o,start:l,loop:c,ilen:d}=pU(i,n,s),f=Fje(a);let{move:p=!0,reverse:m}=s||{},g,b,_;for(g=0;g<=d;++g)b=i[(l+(m?d-g:g))%o],!b.skip&&(p?(e.moveTo(b.x,b.y),p=!1):f(e,_,b,m,a.stepped),_=b);return c&&(b=i[(l+(m?d:0))%o],f(e,_,b,m,a.stepped)),!!c}function Mje(e,t,n,s){const i=t.points,{count:a,start:o,ilen:l}=pU(i,n,s),{move:c=!0,reverse:d}=s||{};let f=0,p=0,m,g,b,_,w,A;const S=E=>(o+(d?l-E:E))%a,C=()=>{_!==w&&(e.lineTo(f,w),e.lineTo(f,_),e.lineTo(f,A))};for(c&&(g=i[S(0)],e.moveTo(g.x,g.y)),m=0;m<=l;++m){if(g=i[S(m)],g.skip)continue;const E=g.x,k=g.y,T=E|0;T===b?(k<_?_=k:k>w&&(w=k),f=(p*f+E)/++p):(C(),e.lineTo(E,k),b=T,p=0,_=w=k),A=k}C()}function pC(e){const t=e.options,n=t.borderDash&&t.borderDash.length;return!e._decimated&&!e._loop&&!t.tension&&t.cubicInterpolationMode!=="monotone"&&!t.stepped&&!n?Mje:Tje}function Rje(e){return e.stepped?jCe:e.tension||e.cubicInterpolationMode==="monotone"?NCe:Lc}function Dje(e,t,n,s){let i=t._path;i||(i=t._path=new Path2D,t.path(i,n,s)&&i.closePath()),fU(e,t.options),e.stroke(i)}function Oje(e,t,n,s){const{segments:i,options:a}=t,o=pC(t);for(const l of i)fU(e,a,l.style),e.beginPath(),o(e,t,l,{start:n,end:n+s-1})&&e.closePath(),e.stroke()}const Pje=typeof Path2D=="function";function Ije(e,t,n,s){Pje&&!t.options.segment?Dje(e,t,n,s):Oje(e,t,n,s)}class fy extends Wo{static id="line";static defaults={borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:3,capBezierPoints:!0,cubicInterpolationMode:"default",fill:!1,spanGaps:!1,stepped:!1,tension:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};static descriptors={_scriptable:!0,_indexable:t=>t!=="borderDash"&&t!=="fill"};constructor(t){super(),this.animated=!0,this.options=void 0,this._chart=void 0,this._loop=void 0,this._fullLoop=void 0,this._path=void 0,this._points=void 0,this._segments=void 0,this._decimated=!1,this._pointsUpdated=!1,this._datasetIndex=void 0,t&&Object.assign(this,t)}updateControlPoints(t,n){const s=this.options;if((s.tension||s.cubicInterpolationMode==="monotone")&&!s.stepped&&!this._pointsUpdated){const i=s.spanGaps?this._loop:this._fullLoop;bCe(this._points,s,t,i,n),this._pointsUpdated=!0}}set points(t){this._points=t,delete this._segments,delete this._path,this._pointsUpdated=!1}get points(){return this._points}get segments(){return this._segments||(this._segments=RCe(this,this.options.segment))}first(){const t=this.segments,n=this.points;return t.length&&n[t[0].start]}last(){const t=this.segments,n=this.points,s=t.length;return s&&n[t[s-1].end]}interpolate(t,n){const s=this.options,i=t[n],a=this.points,o=ZV(this,{property:n,start:i,end:i});if(!o.length)return;const l=[],c=Rje(s);let d,f;for(d=0,f=o.length;d<f;++d){const{start:p,end:m}=o[d],g=a[p],b=a[m];if(g===b){l.push(g);continue}const _=Math.abs((i-g[n])/(b[n]-g[n])),w=c(g,b,_,s.stepped);w[n]=t[n],l.push(w)}return l.length===1?l[0]:l}pathSegment(t,n,s){return pC(this)(t,this,n,s)}path(t,n,s){const i=this.segments,a=pC(this);let o=this._loop;n=n||0,s=s||this.points.length-n;for(const l of i)o&=a(t,this,l,{start:n,end:n+s-1});return!!o}draw(t,n,s,i){const a=this.options||{};(this.points||[]).length&&a.borderWidth&&(t.save(),Ije(t,this,s,i),t.restore()),this.animated&&(this._pointsUpdated=!1,this._path=void 0)}}function RD(e,t,n,s){const i=e.options,{[n]:a}=e.getProps([n],s);return Math.abs(t-a)<i.radius+i.hitRadius}class Lje extends Wo{static id="point";parsed;skip;stop;static defaults={borderWidth:1,hitRadius:1,hoverBorderWidth:1,hoverRadius:4,pointStyle:"circle",radius:3,rotation:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(t){super(),this.options=void 0,this.parsed=void 0,this.skip=void 0,this.stop=void 0,t&&Object.assign(this,t)}inRange(t,n,s){const i=this.options,{x:a,y:o}=this.getProps(["x","y"],s);return Math.pow(t-a,2)+Math.pow(n-o,2)<Math.pow(i.hitRadius+i.radius,2)}inXRange(t,n){return RD(this,t,"x",n)}inYRange(t,n){return RD(this,t,"y",n)}getCenterPoint(t){const{x:n,y:s}=this.getProps(["x","y"],t);return{x:n,y:s}}size(t){t=t||this.options||{};let n=t.radius||0;n=Math.max(n,n&&t.hoverRadius||0);const s=n&&t.borderWidth||0;return(n+s)*2}draw(t,n){const s=this.options;this.skip||s.radius<.1||!Qp(this,n,this.size(s)/2)||(t.strokeStyle=s.borderColor,t.lineWidth=s.borderWidth,t.fillStyle=s.backgroundColor,dC(t,s,this.x,this.y))}getRange(){const t=this.options||{};return t.radius+t.hitRadius}}function mU(e,t){const{x:n,y:s,base:i,width:a,height:o}=e.getProps(["x","y","base","width","height"],t);let l,c,d,f,p;return e.horizontal?(p=o/2,l=Math.min(n,i),c=Math.max(n,i),d=s-p,f=s+p):(p=a/2,l=n-p,c=n+p,d=Math.min(s,i),f=Math.max(s,i)),{left:l,top:d,right:c,bottom:f}}function Pl(e,t,n,s){return e?0:Ws(t,n,s)}function Bje(e,t,n){const s=e.options.borderWidth,i=e.borderSkipped,a=UV(s);return{t:Pl(i.top,a.top,0,n),r:Pl(i.right,a.right,0,t),b:Pl(i.bottom,a.bottom,0,n),l:Pl(i.left,a.left,0,t)}}function zje(e,t,n){const{enableBorderRadius:s}=e.getProps(["enableBorderRadius"]),i=e.options.borderRadius,a=Id(i),o=Math.min(t,n),l=e.borderSkipped,c=s||xt(i);return{topLeft:Pl(!c||l.top||l.left,a.topLeft,0,o),topRight:Pl(!c||l.top||l.right,a.topRight,0,o),bottomLeft:Pl(!c||l.bottom||l.left,a.bottomLeft,0,o),bottomRight:Pl(!c||l.bottom||l.right,a.bottomRight,0,o)}}function $je(e){const t=mU(e),n=t.right-t.left,s=t.bottom-t.top,i=Bje(e,n/2,s/2),a=zje(e,n/2,s/2);return{outer:{x:t.left,y:t.top,w:n,h:s,radius:a},inner:{x:t.left+i.l,y:t.top+i.t,w:n-i.l-i.r,h:s-i.t-i.b,radius:{topLeft:Math.max(0,a.topLeft-Math.max(i.t,i.l)),topRight:Math.max(0,a.topRight-Math.max(i.t,i.r)),bottomLeft:Math.max(0,a.bottomLeft-Math.max(i.b,i.l)),bottomRight:Math.max(0,a.bottomRight-Math.max(i.b,i.r))}}}}function RA(e,t,n,s){const i=t===null,a=n===null,l=e&&!(i&&a)&&mU(e,s);return l&&(i||So(t,l.left,l.right))&&(a||So(n,l.top,l.bottom))}function Vje(e){return e.topLeft||e.topRight||e.bottomLeft||e.bottomRight}function Uje(e,t){e.rect(t.x,t.y,t.w,t.h)}function DA(e,t,n={}){const s=e.x!==n.x?-t:0,i=e.y!==n.y?-t:0,a=(e.x+e.w!==n.x+n.w?t:0)-s,o=(e.y+e.h!==n.y+n.h?t:0)-i;return{x:e.x+s,y:e.y+i,w:e.w+a,h:e.h+o,radius:e.radius}}class Hje extends Wo{static id="bar";static defaults={borderSkipped:"start",borderWidth:0,borderRadius:0,inflateAmount:"auto",pointStyle:void 0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(t){super(),this.options=void 0,this.horizontal=void 0,this.base=void 0,this.width=void 0,this.height=void 0,this.inflateAmount=void 0,t&&Object.assign(this,t)}draw(t){const{inflateAmount:n,options:{borderColor:s,backgroundColor:i}}=this,{inner:a,outer:o}=$je(this),l=Vje(o.radius)?z0:Uje;t.save(),(o.w!==a.w||o.h!==a.h)&&(t.beginPath(),l(t,DA(o,n,a)),t.clip(),l(t,DA(a,-n,o)),t.fillStyle=s,t.fill("evenodd")),t.beginPath(),l(t,DA(a,n)),t.fillStyle=i,t.fill(),t.restore()}inRange(t,n,s){return RA(this,t,n,s)}inXRange(t,n){return RA(this,t,null,n)}inYRange(t,n){return RA(this,null,t,n)}getCenterPoint(t){const{x:n,y:s,base:i,horizontal:a}=this.getProps(["x","y","base","horizontal"],t);return{x:a?(n+i)/2:n,y:a?s:(s+i)/2}}getRange(t){return t==="x"?this.width/2:this.height/2}}function Wje(e,t,n){const s=e.segments,i=e.points,a=t.points,o=[];for(const l of s){let{start:c,end:d}=l;d=py(c,d,i);const f=mC(n,i[c],i[d],l.loop);if(!t.segments){o.push({source:l,target:f,start:i[c],end:i[d]});continue}const p=ZV(t,f);for(const m of p){const g=mC(n,a[m.start],a[m.end],m.loop),b=JV(l,i,g);for(const _ of b)o.push({source:_,target:m,start:{[n]:DD(f,g,"start",Math.max)},end:{[n]:DD(f,g,"end",Math.min)}})}}return o}function mC(e,t,n,s){if(s)return;let i=t[e],a=n[e];return e==="angle"&&(i=Wi(i),a=Wi(a)),{property:e,start:i,end:a}}function qje(e,t){const{x:n=null,y:s=null}=e||{},i=t.points,a=[];return t.segments.forEach(({start:o,end:l})=>{l=py(o,l,i);const c=i[o],d=i[l];s!==null?(a.push({x:c.x,y:s}),a.push({x:d.x,y:s})):n!==null&&(a.push({x:n,y:c.y}),a.push({x:n,y:d.y}))}),a}function py(e,t,n){for(;t>e;t--){const s=n[t];if(!isNaN(s.x)&&!isNaN(s.y))break}return t}function DD(e,t,n,s){return e&&t?s(e[n],t[n]):e?e[n]:t?t[n]:0}function xU(e,t){let n=[],s=!1;return Wn(e)?(s=!0,n=e):n=qje(e,t),n.length?new fy({points:n,options:{tension:0},_loop:s,_fullLoop:s}):null}function OD(e){return e&&e.fill!==!1}function Gje(e,t,n){let i=e[t].fill;const a=[t];let o;if(!n)return i;for(;i!==!1&&a.indexOf(i)===-1;){if(!Js(i))return i;if(o=e[i],!o)return!1;if(o.visible)return i;a.push(i),i=o.fill}return!1}function Kje(e,t,n){const s=Jje(e);if(xt(s))return isNaN(s.value)?!1:s;let i=parseFloat(s);return Js(i)&&Math.floor(i)===i?Yje(s[0],t,i,n):["origin","start","end","stack","shape"].indexOf(s)>=0&&s}function Yje(e,t,n,s){return(e==="-"||e==="+")&&(n=t+n),n===t||n<0||n>=s?!1:n}function Qje(e,t){let n=null;return e==="start"?n=t.bottom:e==="end"?n=t.top:xt(e)?n=t.getPixelForValue(e.value):t.getBasePixel&&(n=t.getBasePixel()),n}function Xje(e,t,n){let s;return e==="start"?s=n:e==="end"?s=t.options.reverse?t.min:t.max:xt(e)?s=e.value:s=t.getBaseValue(),s}function Jje(e){const t=e.options,n=t.fill;let s=it(n&&n.target,n);return s===void 0&&(s=!!t.backgroundColor),s===!1||s===null?!1:s===!0?"origin":s}function Zje(e){const{scale:t,index:n,line:s}=e,i=[],a=s.segments,o=s.points,l=eNe(t,n);l.push(xU({x:null,y:t.bottom},s));for(let c=0;c<a.length;c++){const d=a[c];for(let f=d.start;f<=d.end;f++)tNe(i,o[f],l)}return new fy({points:i,options:{}})}function eNe(e,t){const n=[],s=e.getMatchingVisibleMetas("line");for(let i=0;i<s.length;i++){const a=s[i];if(a.index===t)break;a.hidden||n.unshift(a.dataset)}return n}function tNe(e,t,n){const s=[];for(let i=0;i<n.length;i++){const a=n[i],{first:o,last:l,point:c}=nNe(a,t,"x");if(!(!c||o&&l)){if(o)s.unshift(c);else if(e.push(c),!l)break}}e.push(...s)}function nNe(e,t,n){const s=e.interpolate(t,n);if(!s)return{};const i=s[n],a=e.segments,o=e.points;let l=!1,c=!1;for(let d=0;d<a.length;d++){const f=a[d],p=o[f.start][n],m=o[f.end][n];if(So(i,p,m)){l=i===p,c=i===m;break}}return{first:l,last:c,point:s}}class gU{constructor(t){this.x=t.x,this.y=t.y,this.radius=t.radius}pathSegment(t,n,s){const{x:i,y:a,radius:o}=this;return n=n||{start:0,end:_n},t.arc(i,a,o,n.end,n.start,!0),!s.bounds}interpolate(t){const{x:n,y:s,radius:i}=this,a=t.angle;return{x:n+Math.cos(a)*i,y:s+Math.sin(a)*i,angle:a}}}function sNe(e){const{chart:t,fill:n,line:s}=e;if(Js(n))return iNe(t,n);if(n==="stack")return Zje(e);if(n==="shape")return!0;const i=rNe(e);return i instanceof gU?i:xU(i,s)}function iNe(e,t){const n=e.getDatasetMeta(t);return n&&e.isDatasetVisible(t)?n.dataset:null}function rNe(e){return(e.scale||{}).getPointPositionForValue?oNe(e):aNe(e)}function aNe(e){const{scale:t={},fill:n}=e,s=Qje(n,t);if(Js(s)){const i=t.isHorizontal();return{x:i?s:null,y:i?null:s}}return null}function oNe(e){const{scale:t,fill:n}=e,s=t.options,i=t.getLabels().length,a=s.reverse?t.max:t.min,o=Xje(n,t,a),l=[];if(s.grid.circular){const c=t.getPointPositionForValue(0,a);return new gU({x:c.x,y:c.y,radius:t.getDistanceFromCenterForValue(o)})}for(let c=0;c<i;++c)l.push(t.getPointPositionForValue(c,o));return l}function OA(e,t,n){const s=sNe(t),{chart:i,index:a,line:o,scale:l,axis:c}=t,d=o.options,f=d.fill,p=d.backgroundColor,{above:m=p,below:g=p}=f||{},b=i.getDatasetMeta(a),_=eU(i,b);s&&o.points.length&&(ly(e,n),lNe(e,{line:o,target:s,above:m,below:g,area:n,scale:l,axis:c,clip:_}),cy(e))}function lNe(e,t){const{line:n,target:s,above:i,below:a,area:o,scale:l,clip:c}=t,d=n._loop?"angle":t.axis;e.save();let f=a;a!==i&&(d==="x"?(PD(e,s,o.top),PA(e,{line:n,target:s,color:i,scale:l,property:d,clip:c}),e.restore(),e.save(),PD(e,s,o.bottom)):d==="y"&&(ID(e,s,o.left),PA(e,{line:n,target:s,color:a,scale:l,property:d,clip:c}),e.restore(),e.save(),ID(e,s,o.right),f=i)),PA(e,{line:n,target:s,color:f,scale:l,property:d,clip:c}),e.restore()}function PD(e,t,n){const{segments:s,points:i}=t;let a=!0,o=!1;e.beginPath();for(const l of s){const{start:c,end:d}=l,f=i[c],p=i[py(c,d,i)];a?(e.moveTo(f.x,f.y),a=!1):(e.lineTo(f.x,n),e.lineTo(f.x,f.y)),o=!!t.pathSegment(e,l,{move:o}),o?e.closePath():e.lineTo(p.x,n)}e.lineTo(t.first().x,n),e.closePath(),e.clip()}function ID(e,t,n){const{segments:s,points:i}=t;let a=!0,o=!1;e.beginPath();for(const l of s){const{start:c,end:d}=l,f=i[c],p=i[py(c,d,i)];a?(e.moveTo(f.x,f.y),a=!1):(e.lineTo(n,f.y),e.lineTo(f.x,f.y)),o=!!t.pathSegment(e,l,{move:o}),o?e.closePath():e.lineTo(n,p.y)}e.lineTo(n,t.first().y),e.closePath(),e.clip()}function PA(e,t){const{line:n,target:s,property:i,color:a,scale:o,clip:l}=t,c=Wje(n,s,i);for(const{source:d,target:f,start:p,end:m}of c){const{style:{backgroundColor:g=a}={}}=d,b=s!==!0;e.save(),e.fillStyle=g,cNe(e,o,l,b&&mC(i,p,m)),e.beginPath();const _=!!n.pathSegment(e,d);let w;if(b){_?e.closePath():LD(e,s,m,i);const A=!!s.pathSegment(e,f,{move:_,reverse:!0});w=_&&A,w||LD(e,s,p,i)}e.closePath(),e.fill(w?"evenodd":"nonzero"),e.restore()}}function cNe(e,t,n,s){const i=t.chart.chartArea,{property:a,start:o,end:l}=s||{};if(a==="x"||a==="y"){let c,d,f,p;a==="x"?(c=o,d=i.top,f=l,p=i.bottom):(c=i.left,d=o,f=i.right,p=l),e.beginPath(),n&&(c=Math.max(c,n.left),f=Math.min(f,n.right),d=Math.max(d,n.top),p=Math.min(p,n.bottom)),e.rect(c,d,f-c,p-d),e.clip()}}function LD(e,t,n,s){const i=t.interpolate(n,s);i&&e.lineTo(i.x,i.y)}var uNe={id:"filler",afterDatasetsUpdate(e,t,n){const s=(e.data.datasets||[]).length,i=[];let a,o,l,c;for(o=0;o<s;++o)a=e.getDatasetMeta(o),l=a.dataset,c=null,l&&l.options&&l instanceof fy&&(c={visible:e.isDatasetVisible(o),index:o,fill:Kje(l,o,s),chart:e,axis:a.controller.options.indexAxis,scale:a.vScale,line:l}),a.$filler=c,i.push(c);for(o=0;o<s;++o)c=i[o],!(!c||c.fill===!1)&&(c.fill=Gje(i,o,n.propagate))},beforeDraw(e,t,n){const s=n.drawTime==="beforeDraw",i=e.getSortedVisibleDatasetMetas(),a=e.chartArea;for(let o=i.length-1;o>=0;--o){const l=i[o].$filler;l&&(l.line.updateControlPoints(a,l.axis),s&&l.fill&&OA(e.ctx,l,a))}},beforeDatasetsDraw(e,t,n){if(n.drawTime!=="beforeDatasetsDraw")return;const s=e.getSortedVisibleDatasetMetas();for(let i=s.length-1;i>=0;--i){const a=s[i].$filler;OD(a)&&OA(e.ctx,a,e.chartArea)}},beforeDatasetDraw(e,t,n){const s=t.meta.$filler;!OD(s)||n.drawTime!=="beforeDatasetDraw"||OA(e.ctx,s,e.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}};const BD=(e,t)=>{let{boxHeight:n=t,boxWidth:s=t}=e;return e.usePointStyle&&(n=Math.min(n,t),s=e.pointStyleWidth||Math.min(s,t)),{boxWidth:s,boxHeight:n,itemHeight:Math.max(t,n)}},dNe=(e,t)=>e!==null&&t!==null&&e.datasetIndex===t.datasetIndex&&e.index===t.index;class zD extends Wo{constructor(t){super(),this._added=!1,this.legendHitBoxes=[],this._hoveredItem=null,this.doughnutMode=!1,this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this.legendItems=void 0,this.columnSizes=void 0,this.lineWidths=void 0,this.maxHeight=void 0,this.maxWidth=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.height=void 0,this.width=void 0,this._margins=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,n,s){this.maxWidth=t,this.maxHeight=n,this._margins=s,this.setDimensions(),this.buildLabels(),this.fit()}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=this._margins.left,this.right=this.width):(this.height=this.maxHeight,this.top=this._margins.top,this.bottom=this.height)}buildLabels(){const t=this.options.labels||{};let n=rn(t.generateLabels,[this.chart],this)||[];t.filter&&(n=n.filter(s=>t.filter(s,this.chart.data))),t.sort&&(n=n.sort((s,i)=>t.sort(s,i,this.chart.data))),this.options.reverse&&n.reverse(),this.legendItems=n}fit(){const{options:t,ctx:n}=this;if(!t.display){this.width=this.height=0;return}const s=t.labels,i=qs(s.font),a=i.size,o=this._computeTitleHeight(),{boxWidth:l,itemHeight:c}=BD(s,a);let d,f;n.font=i.string,this.isHorizontal()?(d=this.maxWidth,f=this._fitRows(o,a,l,c)+10):(f=this.maxHeight,d=this._fitCols(o,i,l,c)+10),this.width=Math.min(d,t.maxWidth||this.maxWidth),this.height=Math.min(f,t.maxHeight||this.maxHeight)}_fitRows(t,n,s,i){const{ctx:a,maxWidth:o,options:{labels:{padding:l}}}=this,c=this.legendHitBoxes=[],d=this.lineWidths=[0],f=i+l;let p=t;a.textAlign="left",a.textBaseline="middle";let m=-1,g=-f;return this.legendItems.forEach((b,_)=>{const w=s+n/2+a.measureText(b.text).width;(_===0||d[d.length-1]+w+2*l>o)&&(p+=f,d[d.length-(_>0?0:1)]=0,g+=f,m++),c[_]={left:0,top:g,row:m,width:w,height:i},d[d.length-1]+=w+l}),p}_fitCols(t,n,s,i){const{ctx:a,maxHeight:o,options:{labels:{padding:l}}}=this,c=this.legendHitBoxes=[],d=this.columnSizes=[],f=o-t;let p=l,m=0,g=0,b=0,_=0;return this.legendItems.forEach((w,A)=>{const{itemWidth:S,itemHeight:C}=hNe(s,n,a,w,i);A>0&&g+C+2*l>f&&(p+=m+l,d.push({width:m,height:g}),b+=m+l,_++,m=g=0),c[A]={left:b,top:g,col:_,width:S,height:C},m=Math.max(m,S),g+=C+l}),p+=m,d.push({width:m,height:g}),p}adjustHitBoxes(){if(!this.options.display)return;const t=this._computeTitleHeight(),{legendHitBoxes:n,options:{align:s,labels:{padding:i},rtl:a}}=this,o=Ld(a,this.left,this.width);if(this.isHorizontal()){let l=0,c=zs(s,this.left+i,this.right-this.lineWidths[l]);for(const d of n)l!==d.row&&(l=d.row,c=zs(s,this.left+i,this.right-this.lineWidths[l])),d.top+=this.top+t+i,d.left=o.leftForLtr(o.x(c),d.width),c+=d.width+i}else{let l=0,c=zs(s,this.top+t+i,this.bottom-this.columnSizes[l].height);for(const d of n)d.col!==l&&(l=d.col,c=zs(s,this.top+t+i,this.bottom-this.columnSizes[l].height)),d.top=c,d.left+=this.left+i,d.left=o.leftForLtr(o.x(d.left),d.width),c+=d.height+i}}isHorizontal(){return this.options.position==="top"||this.options.position==="bottom"}draw(){if(this.options.display){const t=this.ctx;ly(t,this),this._draw(),cy(t)}}_draw(){const{options:t,columnSizes:n,lineWidths:s,ctx:i}=this,{align:a,labels:o}=t,l=Rn.color,c=Ld(t.rtl,this.left,this.width),d=qs(o.font),{padding:f}=o,p=d.size,m=p/2;let g;this.drawTitle(),i.textAlign=c.textAlign("left"),i.textBaseline="middle",i.lineWidth=.5,i.font=d.string;const{boxWidth:b,boxHeight:_,itemHeight:w}=BD(o,p),A=function(T,F,M){if(isNaN(b)||b<=0||isNaN(_)||_<0)return;i.save();const I=it(M.lineWidth,1);if(i.fillStyle=it(M.fillStyle,l),i.lineCap=it(M.lineCap,"butt"),i.lineDashOffset=it(M.lineDashOffset,0),i.lineJoin=it(M.lineJoin,"miter"),i.lineWidth=I,i.strokeStyle=it(M.strokeStyle,l),i.setLineDash(it(M.lineDash,[])),o.usePointStyle){const R={radius:_*Math.SQRT2/2,pointStyle:M.pointStyle,rotation:M.rotation,borderWidth:I},H=c.xPlus(T,b/2),V=F+m;VV(i,R,H,V,o.pointStyleWidth&&b)}else{const R=F+Math.max((p-_)/2,0),H=c.leftForLtr(T,b),V=Id(M.borderRadius);i.beginPath(),Object.values(V).some(K=>K!==0)?z0(i,{x:H,y:R,w:b,h:_,radius:V}):i.rect(H,R,b,_),i.fill(),I!==0&&i.stroke()}i.restore()},S=function(T,F,M){Xp(i,M.text,T,F+w/2,d,{strikethrough:M.hidden,textAlign:c.textAlign(M.textAlign)})},C=this.isHorizontal(),E=this._computeTitleHeight();C?g={x:zs(a,this.left+f,this.right-s[0]),y:this.top+f+E,line:0}:g={x:this.left+f,y:zs(a,this.top+E+f,this.bottom-n[0].height),line:0},YV(this.ctx,t.textDirection);const k=w+f;this.legendItems.forEach((T,F)=>{i.strokeStyle=T.fontColor,i.fillStyle=T.fontColor;const M=i.measureText(T.text).width,I=c.textAlign(T.textAlign||(T.textAlign=o.textAlign)),R=b+m+M;let H=g.x,V=g.y;c.setWidth(this.width),C?F>0&&H+R+f>this.right&&(V=g.y+=k,g.line++,H=g.x=zs(a,this.left+f,this.right-s[g.line])):F>0&&V+k>this.bottom&&(H=g.x=H+n[g.line].width+f,g.line++,V=g.y=zs(a,this.top+E+f,this.bottom-n[g.line].height));const K=c.x(H);if(A(K,V,T),H=PSe(I,H+b+m,C?H+R:this.right,t.rtl),S(c.x(H),V,T),C)g.x+=R+f;else if(typeof T.text!="string"){const q=d.lineHeight;g.y+=bU(T,q)+f}else g.y+=k}),QV(this.ctx,t.textDirection)}drawTitle(){const t=this.options,n=t.title,s=qs(n.font),i=Lr(n.padding);if(!n.display)return;const a=Ld(t.rtl,this.left,this.width),o=this.ctx,l=n.position,c=s.size/2,d=i.top+c;let f,p=this.left,m=this.width;if(this.isHorizontal())m=Math.max(...this.lineWidths),f=this.top+d,p=zs(t.align,p,this.right-m);else{const b=this.columnSizes.reduce((_,w)=>Math.max(_,w.height),0);f=d+zs(t.align,this.top,this.bottom-b-t.labels.padding-this._computeTitleHeight())}const g=zs(l,p,p+m);o.textAlign=a.textAlign(uN(l)),o.textBaseline="middle",o.strokeStyle=n.color,o.fillStyle=n.color,o.font=s.string,Xp(o,n.text,g,f,s)}_computeTitleHeight(){const t=this.options.title,n=qs(t.font),s=Lr(t.padding);return t.display?n.lineHeight+s.height:0}_getLegendItemAt(t,n){let s,i,a;if(So(t,this.left,this.right)&&So(n,this.top,this.bottom)){for(a=this.legendHitBoxes,s=0;s<a.length;++s)if(i=a[s],So(t,i.left,i.left+i.width)&&So(n,i.top,i.top+i.height))return this.legendItems[s]}return null}handleEvent(t){const n=this.options;if(!mNe(t.type,n))return;const s=this._getLegendItemAt(t.x,t.y);if(t.type==="mousemove"||t.type==="mouseout"){const i=this._hoveredItem,a=dNe(i,s);i&&!a&&rn(n.onLeave,[t,i,this],this),this._hoveredItem=s,s&&!a&&rn(n.onHover,[t,s,this],this)}else s&&rn(n.onClick,[t,s,this],this)}}function hNe(e,t,n,s,i){const a=fNe(s,e,t,n),o=pNe(i,s,t.lineHeight);return{itemWidth:a,itemHeight:o}}function fNe(e,t,n,s){let i=e.text;return i&&typeof i!="string"&&(i=i.reduce((a,o)=>a.length>o.length?a:o)),t+n.size/2+s.measureText(i).width}function pNe(e,t,n){let s=e;return typeof t.text!="string"&&(s=bU(t,n)),s}function bU(e,t){const n=e.text?e.text.length:0;return t*n}function mNe(e,t){return!!((e==="mousemove"||e==="mouseout")&&(t.onHover||t.onLeave)||t.onClick&&(e==="click"||e==="mouseup"))}var xNe={id:"legend",_element:zD,start(e,t,n){const s=e.legend=new zD({ctx:e.ctx,options:n,chart:e});Tr.configure(e,s,n),Tr.addBox(e,s)},stop(e){Tr.removeBox(e,e.legend),delete e.legend},beforeUpdate(e,t,n){const s=e.legend;Tr.configure(e,s,n),s.options=n},afterUpdate(e){const t=e.legend;t.buildLabels(),t.adjustHitBoxes()},afterEvent(e,t){t.replay||e.legend.handleEvent(t.event)},defaults:{display:!0,position:"top",align:"center",fullSize:!0,reverse:!1,weight:1e3,onClick(e,t,n){const s=t.datasetIndex,i=n.chart;i.isDatasetVisible(s)?(i.hide(s),t.hidden=!0):(i.show(s),t.hidden=!1)},onHover:null,onLeave:null,labels:{color:e=>e.chart.options.color,boxWidth:40,padding:10,generateLabels(e){const t=e.data.datasets,{labels:{usePointStyle:n,pointStyle:s,textAlign:i,color:a,useBorderRadius:o,borderRadius:l}}=e.legend.options;return e._getSortedDatasetMetas().map(c=>{const d=c.controller.getStyle(n?0:void 0),f=Lr(d.borderWidth);return{text:t[c.index].label,fillStyle:d.backgroundColor,fontColor:a,hidden:!c.visible,lineCap:d.borderCapStyle,lineDash:d.borderDash,lineDashOffset:d.borderDashOffset,lineJoin:d.borderJoinStyle,lineWidth:(f.width+f.height)/4,strokeStyle:d.borderColor,pointStyle:s||d.pointStyle,rotation:d.rotation,textAlign:i||d.textAlign,borderRadius:o&&(l||d.borderRadius),datasetIndex:c.index}},this)}},title:{color:e=>e.chart.options.color,display:!1,position:"center",text:""}},descriptors:{_scriptable:e=>!e.startsWith("on"),labels:{_scriptable:e=>!["generateLabels","filter","sort"].includes(e)}}};class vU extends Wo{constructor(t){super(),this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this._padding=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,n){const s=this.options;if(this.left=0,this.top=0,!s.display){this.width=this.height=this.right=this.bottom=0;return}this.width=this.right=t,this.height=this.bottom=n;const i=Wn(s.text)?s.text.length:1;this._padding=Lr(s.padding);const a=i*qs(s.font).lineHeight+this._padding.height;this.isHorizontal()?this.height=a:this.width=a}isHorizontal(){const t=this.options.position;return t==="top"||t==="bottom"}_drawArgs(t){const{top:n,left:s,bottom:i,right:a,options:o}=this,l=o.align;let c=0,d,f,p;return this.isHorizontal()?(f=zs(l,s,a),p=n+t,d=a-s):(o.position==="left"?(f=s+t,p=zs(l,i,n),c=Lt*-.5):(f=a-t,p=zs(l,n,i),c=Lt*.5),d=i-n),{titleX:f,titleY:p,maxWidth:d,rotation:c}}draw(){const t=this.ctx,n=this.options;if(!n.display)return;const s=qs(n.font),a=s.lineHeight/2+this._padding.top,{titleX:o,titleY:l,maxWidth:c,rotation:d}=this._drawArgs(a);Xp(t,n.text,0,0,s,{color:n.color,maxWidth:c,rotation:d,textAlign:uN(n.align),textBaseline:"middle",translation:[o,l]})}}function gNe(e,t){const n=new vU({ctx:e.ctx,options:t,chart:e});Tr.configure(e,n,t),Tr.addBox(e,n),e.titleBlock=n}var bNe={id:"title",_element:vU,start(e,t,n){gNe(e,n)},stop(e){const t=e.titleBlock;Tr.removeBox(e,t),delete e.titleBlock},beforeUpdate(e,t,n){const s=e.titleBlock;Tr.configure(e,s,n),s.options=n},defaults:{align:"center",display:!1,font:{weight:"bold"},fullSize:!0,padding:10,position:"top",text:"",weight:2e3},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const tp={average(e){if(!e.length)return!1;let t,n,s=new Set,i=0,a=0;for(t=0,n=e.length;t<n;++t){const l=e[t].element;if(l&&l.hasValue()){const c=l.tooltipPosition();s.add(c.x),i+=c.y,++a}}return a===0||s.size===0?!1:{x:[...s].reduce((l,c)=>l+c)/s.size,y:i/a}},nearest(e,t){if(!e.length)return!1;let n=t.x,s=t.y,i=Number.POSITIVE_INFINITY,a,o,l;for(a=0,o=e.length;a<o;++a){const c=e[a].element;if(c&&c.hasValue()){const d=c.getCenterPoint(),f=cC(t,d);f<i&&(i=f,l=c)}}if(l){const c=l.tooltipPosition();n=c.x,s=c.y}return{x:n,y:s}}};function wa(e,t){return t&&(Wn(t)?Array.prototype.push.apply(e,t):e.push(t)),e}function yo(e){return(typeof e=="string"||e instanceof String)&&e.indexOf(`
188
188
  `)>-1?e.split(`
189
- `):e}function vNe(e,t){const{element:n,datasetIndex:s,index:i}=t,a=e.getDatasetMeta(s).controller,{label:o,value:l}=a.getLabelAndValue(i);return{chart:e,label:o,parsed:a.getParsed(i),raw:e.data.datasets[s].data[i],formattedValue:l,dataset:a.getDataset(),dataIndex:i,datasetIndex:s,element:n}}function $D(e,t){const n=e.chart.ctx,{body:s,footer:i,title:a}=e,{boxWidth:o,boxHeight:l}=t,c=qs(t.bodyFont),d=qs(t.titleFont),f=qs(t.footerFont),p=a.length,m=i.length,g=s.length,b=Lr(t.padding);let _=b.height,w=0,A=s.reduce((E,k)=>E+k.before.length+k.lines.length+k.after.length,0);if(A+=e.beforeBody.length+e.afterBody.length,p&&(_+=p*d.lineHeight+(p-1)*t.titleSpacing+t.titleMarginBottom),A){const E=t.displayColors?Math.max(l,c.lineHeight):c.lineHeight;_+=g*E+(A-g)*c.lineHeight+(A-1)*t.bodySpacing}m&&(_+=t.footerMarginTop+m*f.lineHeight+(m-1)*t.footerSpacing);let S=0;const C=function(E){w=Math.max(w,n.measureText(E).width+S)};return n.save(),n.font=d.string,It(e.title,C),n.font=c.string,It(e.beforeBody.concat(e.afterBody),C),S=t.displayColors?o+2+t.boxPadding:0,It(s,E=>{It(E.before,C),It(E.lines,C),It(E.after,C)}),S=0,n.font=f.string,It(e.footer,C),n.restore(),w+=b.width,{width:w,height:_}}function yNe(e,t){const{y:n,height:s}=t;return n<s/2?"top":n>e.height-s/2?"bottom":"center"}function _Ne(e,t,n,s){const{x:i,width:a}=s,o=n.caretSize+n.caretPadding;if(e==="left"&&i+a+o>t.width||e==="right"&&i-a-o<0)return!0}function wNe(e,t,n,s){const{x:i,width:a}=n,{width:o,chartArea:{left:l,right:c}}=e;let d="center";return s==="center"?d=i<=(l+c)/2?"left":"right":i<=a/2?d="left":i>=o-a/2&&(d="right"),_Ne(d,e,t,n)&&(d="center"),d}function VD(e,t,n){const s=n.yAlign||t.yAlign||yNe(e,n);return{xAlign:n.xAlign||t.xAlign||wNe(e,t,n,s),yAlign:s}}function ANe(e,t){let{x:n,width:s}=e;return t==="right"?n-=s:t==="center"&&(n-=s/2),n}function SNe(e,t,n){let{y:s,height:i}=e;return t==="top"?s+=n:t==="bottom"?s-=i+n:s-=i/2,s}function UD(e,t,n,s){const{caretSize:i,caretPadding:a,cornerRadius:o}=e,{xAlign:l,yAlign:c}=n,d=i+a,{topLeft:f,topRight:p,bottomLeft:m,bottomRight:g}=Id(o);let b=ANe(t,l);const _=SNe(t,c,d);return c==="center"?l==="left"?b+=d:l==="right"&&(b-=d):l==="left"?b-=Math.max(f,m)+i:l==="right"&&(b+=Math.max(p,g)+i),{x:Ws(b,0,s.width-t.width),y:Ws(_,0,s.height-t.height)}}function eb(e,t,n){const s=Lr(n.padding);return t==="center"?e.x+e.width/2:t==="right"?e.x+e.width-s.right:e.x+s.left}function HD(e){return wa([],yo(e))}function CNe(e,t,n){return wu(e,{tooltip:t,tooltipItems:n,type:"tooltip"})}function WD(e,t){const n=t&&t.dataset&&t.dataset.tooltip&&t.dataset.tooltip.callbacks;return n?e.override(n):e}const yU={beforeTitle:mo,title(e){if(e.length>0){const t=e[0],n=t.chart.data.labels,s=n?n.length:0;if(this&&this.options&&this.options.mode==="dataset")return t.dataset.label||"";if(t.label)return t.label;if(s>0&&t.dataIndex<s)return n[t.dataIndex]}return""},afterTitle:mo,beforeBody:mo,beforeLabel:mo,label(e){if(this&&this.options&&this.options.mode==="dataset")return e.label+": "+e.formattedValue||e.formattedValue;let t=e.dataset.label||"";t&&(t+=": ");const n=e.formattedValue;return Tt(n)||(t+=n),t},labelColor(e){const n=e.chart.getDatasetMeta(e.datasetIndex).controller.getStyle(e.dataIndex);return{borderColor:n.borderColor,backgroundColor:n.backgroundColor,borderWidth:n.borderWidth,borderDash:n.borderDash,borderDashOffset:n.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(e){const n=e.chart.getDatasetMeta(e.datasetIndex).controller.getStyle(e.dataIndex);return{pointStyle:n.pointStyle,rotation:n.rotation}},afterLabel:mo,afterBody:mo,beforeFooter:mo,footer:mo,afterFooter:mo};function wi(e,t,n,s){const i=e[t].call(n,s);return typeof i>"u"?yU[t].call(n,s):i}class qD extends Wo{static positioners=tp;constructor(t){super(),this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=t.chart,this.options=t.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(t){this.options=t,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){const t=this._cachedAnimations;if(t)return t;const n=this.chart,s=this.options.setContext(this.getContext()),i=s.enabled&&n.options.animation&&s.animations,a=new tU(this.chart,i);return i._cacheable&&(this._cachedAnimations=Object.freeze(a)),a}getContext(){return this.$context||(this.$context=CNe(this.chart.getContext(),this,this._tooltipItems))}getTitle(t,n){const{callbacks:s}=n,i=wi(s,"beforeTitle",this,t),a=wi(s,"title",this,t),o=wi(s,"afterTitle",this,t);let l=[];return l=wa(l,yo(i)),l=wa(l,yo(a)),l=wa(l,yo(o)),l}getBeforeBody(t,n){return HD(wi(n.callbacks,"beforeBody",this,t))}getBody(t,n){const{callbacks:s}=n,i=[];return It(t,a=>{const o={before:[],lines:[],after:[]},l=WD(s,a);wa(o.before,yo(wi(l,"beforeLabel",this,a))),wa(o.lines,wi(l,"label",this,a)),wa(o.after,yo(wi(l,"afterLabel",this,a))),i.push(o)}),i}getAfterBody(t,n){return HD(wi(n.callbacks,"afterBody",this,t))}getFooter(t,n){const{callbacks:s}=n,i=wi(s,"beforeFooter",this,t),a=wi(s,"footer",this,t),o=wi(s,"afterFooter",this,t);let l=[];return l=wa(l,yo(i)),l=wa(l,yo(a)),l=wa(l,yo(o)),l}_createItems(t){const n=this._active,s=this.chart.data,i=[],a=[],o=[];let l=[],c,d;for(c=0,d=n.length;c<d;++c)l.push(vNe(this.chart,n[c]));return t.filter&&(l=l.filter((f,p,m)=>t.filter(f,p,m,s))),t.itemSort&&(l=l.sort((f,p)=>t.itemSort(f,p,s))),It(l,f=>{const p=WD(t.callbacks,f);i.push(wi(p,"labelColor",this,f)),a.push(wi(p,"labelPointStyle",this,f)),o.push(wi(p,"labelTextColor",this,f))}),this.labelColors=i,this.labelPointStyles=a,this.labelTextColors=o,this.dataPoints=l,l}update(t,n){const s=this.options.setContext(this.getContext()),i=this._active;let a,o=[];if(!i.length)this.opacity!==0&&(a={opacity:0});else{const l=tp[s.position].call(this,i,this._eventPosition);o=this._createItems(s),this.title=this.getTitle(o,s),this.beforeBody=this.getBeforeBody(o,s),this.body=this.getBody(o,s),this.afterBody=this.getAfterBody(o,s),this.footer=this.getFooter(o,s);const c=this._size=$D(this,s),d=Object.assign({},l,c),f=VD(this.chart,s,d),p=UD(s,d,f,this.chart);this.xAlign=f.xAlign,this.yAlign=f.yAlign,a={opacity:1,x:p.x,y:p.y,width:c.width,height:c.height,caretX:l.x,caretY:l.y}}this._tooltipItems=o,this.$context=void 0,a&&this._resolveAnimations().update(this,a),t&&s.external&&s.external.call(this,{chart:this.chart,tooltip:this,replay:n})}drawCaret(t,n,s,i){const a=this.getCaretPosition(t,s,i);n.lineTo(a.x1,a.y1),n.lineTo(a.x2,a.y2),n.lineTo(a.x3,a.y3)}getCaretPosition(t,n,s){const{xAlign:i,yAlign:a}=this,{caretSize:o,cornerRadius:l}=s,{topLeft:c,topRight:d,bottomLeft:f,bottomRight:p}=Id(l),{x:m,y:g}=t,{width:b,height:_}=n;let w,A,S,C,E,k;return a==="center"?(E=g+_/2,i==="left"?(w=m,A=w-o,C=E+o,k=E-o):(w=m+b,A=w+o,C=E-o,k=E+o),S=w):(i==="left"?A=m+Math.max(c,f)+o:i==="right"?A=m+b-Math.max(d,p)-o:A=this.caretX,a==="top"?(C=g,E=C-o,w=A-o,S=A+o):(C=g+_,E=C+o,w=A+o,S=A-o),k=C),{x1:w,x2:A,x3:S,y1:C,y2:E,y3:k}}drawTitle(t,n,s){const i=this.title,a=i.length;let o,l,c;if(a){const d=Ld(s.rtl,this.x,this.width);for(t.x=eb(this,s.titleAlign,s),n.textAlign=d.textAlign(s.titleAlign),n.textBaseline="middle",o=qs(s.titleFont),l=s.titleSpacing,n.fillStyle=s.titleColor,n.font=o.string,c=0;c<a;++c)n.fillText(i[c],d.x(t.x),t.y+o.lineHeight/2),t.y+=o.lineHeight+l,c+1===a&&(t.y+=s.titleMarginBottom-l)}}_drawColorBox(t,n,s,i,a){const o=this.labelColors[s],l=this.labelPointStyles[s],{boxHeight:c,boxWidth:d}=a,f=qs(a.bodyFont),p=eb(this,"left",a),m=i.x(p),g=c<f.lineHeight?(f.lineHeight-c)/2:0,b=n.y+g;if(a.usePointStyle){const _={radius:Math.min(d,c)/2,pointStyle:l.pointStyle,rotation:l.rotation,borderWidth:1},w=i.leftForLtr(m,d)+d/2,A=b+c/2;t.strokeStyle=a.multiKeyBackground,t.fillStyle=a.multiKeyBackground,dC(t,_,w,A),t.strokeStyle=o.borderColor,t.fillStyle=o.backgroundColor,dC(t,_,w,A)}else{t.lineWidth=xt(o.borderWidth)?Math.max(...Object.values(o.borderWidth)):o.borderWidth||1,t.strokeStyle=o.borderColor,t.setLineDash(o.borderDash||[]),t.lineDashOffset=o.borderDashOffset||0;const _=i.leftForLtr(m,d),w=i.leftForLtr(i.xPlus(m,1),d-2),A=Id(o.borderRadius);Object.values(A).some(S=>S!==0)?(t.beginPath(),t.fillStyle=a.multiKeyBackground,z0(t,{x:_,y:b,w:d,h:c,radius:A}),t.fill(),t.stroke(),t.fillStyle=o.backgroundColor,t.beginPath(),z0(t,{x:w,y:b+1,w:d-2,h:c-2,radius:A}),t.fill()):(t.fillStyle=a.multiKeyBackground,t.fillRect(_,b,d,c),t.strokeRect(_,b,d,c),t.fillStyle=o.backgroundColor,t.fillRect(w,b+1,d-2,c-2))}t.fillStyle=this.labelTextColors[s]}drawBody(t,n,s){const{body:i}=this,{bodySpacing:a,bodyAlign:o,displayColors:l,boxHeight:c,boxWidth:d,boxPadding:f}=s,p=qs(s.bodyFont);let m=p.lineHeight,g=0;const b=Ld(s.rtl,this.x,this.width),_=function(M){n.fillText(M,b.x(t.x+g),t.y+m/2),t.y+=m+a},w=b.textAlign(o);let A,S,C,E,k,T,F;for(n.textAlign=o,n.textBaseline="middle",n.font=p.string,t.x=eb(this,w,s),n.fillStyle=s.bodyColor,It(this.beforeBody,_),g=l&&w!=="right"?o==="center"?d/2+f:d+2+f:0,E=0,T=i.length;E<T;++E){for(A=i[E],S=this.labelTextColors[E],n.fillStyle=S,It(A.before,_),C=A.lines,l&&C.length&&(this._drawColorBox(n,t,E,b,s),m=Math.max(p.lineHeight,c)),k=0,F=C.length;k<F;++k)_(C[k]),m=p.lineHeight;It(A.after,_)}g=0,m=p.lineHeight,It(this.afterBody,_),t.y-=a}drawFooter(t,n,s){const i=this.footer,a=i.length;let o,l;if(a){const c=Ld(s.rtl,this.x,this.width);for(t.x=eb(this,s.footerAlign,s),t.y+=s.footerMarginTop,n.textAlign=c.textAlign(s.footerAlign),n.textBaseline="middle",o=qs(s.footerFont),n.fillStyle=s.footerColor,n.font=o.string,l=0;l<a;++l)n.fillText(i[l],c.x(t.x),t.y+o.lineHeight/2),t.y+=o.lineHeight+s.footerSpacing}}drawBackground(t,n,s,i){const{xAlign:a,yAlign:o}=this,{x:l,y:c}=t,{width:d,height:f}=s,{topLeft:p,topRight:m,bottomLeft:g,bottomRight:b}=Id(i.cornerRadius);n.fillStyle=i.backgroundColor,n.strokeStyle=i.borderColor,n.lineWidth=i.borderWidth,n.beginPath(),n.moveTo(l+p,c),o==="top"&&this.drawCaret(t,n,s,i),n.lineTo(l+d-m,c),n.quadraticCurveTo(l+d,c,l+d,c+m),o==="center"&&a==="right"&&this.drawCaret(t,n,s,i),n.lineTo(l+d,c+f-b),n.quadraticCurveTo(l+d,c+f,l+d-b,c+f),o==="bottom"&&this.drawCaret(t,n,s,i),n.lineTo(l+g,c+f),n.quadraticCurveTo(l,c+f,l,c+f-g),o==="center"&&a==="left"&&this.drawCaret(t,n,s,i),n.lineTo(l,c+p),n.quadraticCurveTo(l,c,l+p,c),n.closePath(),n.fill(),i.borderWidth>0&&n.stroke()}_updateAnimationTarget(t){const n=this.chart,s=this.$animations,i=s&&s.x,a=s&&s.y;if(i||a){const o=tp[t.position].call(this,this._active,this._eventPosition);if(!o)return;const l=this._size=$D(this,t),c=Object.assign({},o,this._size),d=VD(n,t,c),f=UD(t,c,d,n);(i._to!==f.x||a._to!==f.y)&&(this.xAlign=d.xAlign,this.yAlign=d.yAlign,this.width=l.width,this.height=l.height,this.caretX=o.x,this.caretY=o.y,this._resolveAnimations().update(this,f))}}_willRender(){return!!this.opacity}draw(t){const n=this.options.setContext(this.getContext());let s=this.opacity;if(!s)return;this._updateAnimationTarget(n);const i={width:this.width,height:this.height},a={x:this.x,y:this.y};s=Math.abs(s)<.001?0:s;const o=Lr(n.padding),l=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;n.enabled&&l&&(t.save(),t.globalAlpha=s,this.drawBackground(a,t,i,n),YV(t,n.textDirection),a.y+=o.top,this.drawTitle(a,t,n),this.drawBody(a,t,n),this.drawFooter(a,t,n),QV(t,n.textDirection),t.restore())}getActiveElements(){return this._active||[]}setActiveElements(t,n){const s=this._active,i=t.map(({datasetIndex:l,index:c})=>{const d=this.chart.getDatasetMeta(l);if(!d)throw new Error("Cannot find a dataset at index "+l);return{datasetIndex:l,element:d.data[c],index:c}}),a=!I0(s,i),o=this._positionChanged(i,n);(a||o)&&(this._active=i,this._eventPosition=n,this._ignoreReplayEvents=!0,this.update(!0))}handleEvent(t,n,s=!0){if(n&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;const i=this.options,a=this._active||[],o=this._getActiveElements(t,a,n,s),l=this._positionChanged(o,t),c=n||!I0(o,a)||l;return c&&(this._active=o,(i.enabled||i.external)&&(this._eventPosition={x:t.x,y:t.y},this.update(!0,n))),c}_getActiveElements(t,n,s,i){const a=this.options;if(t.type==="mouseout")return[];if(!i)return n.filter(l=>this.chart.data.datasets[l.datasetIndex]&&this.chart.getDatasetMeta(l.datasetIndex).controller.getParsed(l.index)!==void 0);const o=this.chart.getElementsAtEventForMode(t,a.mode,a,s);return a.reverse&&o.reverse(),o}_positionChanged(t,n){const{caretX:s,caretY:i,options:a}=this,o=tp[a.position].call(this,t,n);return o!==!1&&(s!==o.x||i!==o.y)}}var jNe={id:"tooltip",_element:qD,positioners:tp,afterInit(e,t,n){n&&(e.tooltip=new qD({chart:e,options:n}))},beforeUpdate(e,t,n){e.tooltip&&e.tooltip.initialize(n)},reset(e,t,n){e.tooltip&&e.tooltip.initialize(n)},afterDraw(e){const t=e.tooltip;if(t&&t._willRender()){const n={tooltip:t};if(e.notifyPlugins("beforeTooltipDraw",{...n,cancelable:!0})===!1)return;t.draw(e.ctx),e.notifyPlugins("afterTooltipDraw",n)}},afterEvent(e,t){if(e.tooltip){const n=t.replay;e.tooltip.handleEvent(t.event,n,t.inChartArea)&&(t.changed=!0)}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(e,t)=>t.bodyFont.size,boxWidth:(e,t)=>t.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:yU},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:e=>e!=="filter"&&e!=="itemSort"&&e!=="external",_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]};const NNe=(e,t,n,s)=>(typeof t=="string"?(n=e.push(t)-1,s.unshift({index:n,label:t})):isNaN(t)&&(n=null),n);function kNe(e,t,n,s){const i=e.indexOf(t);if(i===-1)return NNe(e,t,n,s);const a=e.lastIndexOf(t);return i!==a?n:i}const ENe=(e,t)=>e===null?null:Ws(Math.round(e),0,t);function GD(e){const t=this.getLabels();return e>=0&&e<t.length?t[e]:e}class FNe extends Ah{static id="category";static defaults={ticks:{callback:GD}};constructor(t){super(t),this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(t){const n=this._addedLabels;if(n.length){const s=this.getLabels();for(const{index:i,label:a}of n)s[i]===a&&s.splice(i,1);this._addedLabels=[]}super.init(t)}parse(t,n){if(Tt(t))return null;const s=this.getLabels();return n=isFinite(n)&&s[n]===t?n:kNe(s,t,it(n,t),this._addedLabels),ENe(n,s.length-1)}determineDataLimits(){const{minDefined:t,maxDefined:n}=this.getUserBounds();let{min:s,max:i}=this.getMinMax(!0);this.options.bounds==="ticks"&&(t||(s=0),n||(i=this.getLabels().length-1)),this.min=s,this.max=i}buildTicks(){const t=this.min,n=this.max,s=this.options.offset,i=[];let a=this.getLabels();a=t===0&&n===a.length-1?a:a.slice(t,n+1),this._valueRange=Math.max(a.length-(s?0:1),1),this._startValue=this.min-(s?.5:0);for(let o=t;o<=n;o++)i.push({value:o});return i}getLabelForValue(t){return GD.call(this,t)}configure(){super.configure(),this.isHorizontal()||(this._reversePixels=!this._reversePixels)}getPixelForValue(t){return typeof t!="number"&&(t=this.parse(t)),t===null?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getPixelForTick(t){const n=this.ticks;return t<0||t>n.length-1?null:this.getPixelForValue(n[t].value)}getValueForPixel(t){return Math.round(this._startValue+this.getDecimalForPixel(t)*this._valueRange)}getBasePixel(){return this.bottom}}function TNe(e,t){const n=[],{bounds:i,step:a,min:o,max:l,precision:c,count:d,maxTicks:f,maxDigits:p,includeBounds:m}=e,g=a||1,b=f-1,{min:_,max:w}=t,A=!Tt(o),S=!Tt(l),C=!Tt(d),E=(w-_)/(p+1);let k=UR((w-_)/b/g)*g,T,F,M,I;if(k<1e-14&&!A&&!S)return[{value:_},{value:w}];I=Math.ceil(w/k)-Math.floor(_/k),I>b&&(k=UR(I*k/b/g)*g),Tt(c)||(T=Math.pow(10,c),k=Math.ceil(k*T)/T),i==="ticks"?(F=Math.floor(_/k)*k,M=Math.ceil(w/k)*k):(F=_,M=w),A&&S&&a&&NSe((l-o)/a,k/1e3)?(I=Math.round(Math.min((l-o)/k,f)),k=(l-o)/I,F=o,M=l):C?(F=A?o:F,M=S?l:M,I=d-1,k=(M-F)/I):(I=(M-F)/k,gp(I,Math.round(I),k/1e3)?I=Math.round(I):I=Math.ceil(I));const R=Math.max(HR(k),HR(F));T=Math.pow(10,Tt(c)?R:c),F=Math.round(F*T)/T,M=Math.round(M*T)/T;let H=0;for(A&&(m&&F!==o?(n.push({value:o}),F<o&&H++,gp(Math.round((F+H*k)*T)/T,o,KD(o,E,e))&&H++):F<o&&H++);H<I;++H){const V=Math.round((F+H*k)*T)/T;if(S&&V>l)break;n.push({value:V})}return S&&m&&M!==l?n.length&&gp(n[n.length-1].value,l,KD(l,E,e))?n[n.length-1].value=l:n.push({value:l}):(!S||M===l)&&n.push({value:M}),n}function KD(e,t,{horizontal:n,minRotation:s}){const i=Ao(s),a=(n?Math.sin(i):Math.cos(i))||.001,o=.75*t*(""+e).length;return Math.min(t/a,o)}class MNe extends Ah{constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(t,n){return Tt(t)||(typeof t=="number"||t instanceof Number)&&!isFinite(+t)?null:+t}handleTickRangeOptions(){const{beginAtZero:t}=this.options,{minDefined:n,maxDefined:s}=this.getUserBounds();let{min:i,max:a}=this;const o=c=>i=n?i:c,l=c=>a=s?a:c;if(t){const c=za(i),d=za(a);c<0&&d<0?l(0):c>0&&d>0&&o(0)}if(i===a){let c=a===0?1:Math.abs(a*.05);l(a+c),t||o(i-c)}this.min=i,this.max=a}getTickLimit(){const t=this.options.ticks;let{maxTicksLimit:n,stepSize:s}=t,i;return s?(i=Math.ceil(this.max/s)-Math.floor(this.min/s)+1,i>1e3&&(console.warn(`scales.${this.id}.ticks.stepSize: ${s} would result generating up to ${i} ticks. Limiting to 1000.`),i=1e3)):(i=this.computeTickLimit(),n=n||11),n&&(i=Math.min(n,i)),i}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){const t=this.options,n=t.ticks;let s=this.getTickLimit();s=Math.max(2,s);const i={maxTicks:s,bounds:t.bounds,min:t.min,max:t.max,precision:n.precision,step:n.stepSize,count:n.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:n.minRotation||0,includeBounds:n.includeBounds!==!1},a=this._range||this,o=TNe(i,a);return t.bounds==="ticks"&&kSe(o,this,"value"),t.reverse?(o.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),o}configure(){const t=this.ticks;let n=this.min,s=this.max;if(super.configure(),this.options.offset&&t.length){const i=(s-n)/Math.max(t.length-1,1)/2;n-=i,s+=i}this._startValue=n,this._endValue=s,this._valueRange=s-n}getLabelForValue(t){return hN(t,this.chart.options.locale,this.options.ticks.format)}}class RNe extends MNe{static id="linear";static defaults={ticks:{callback:$V.formatters.numeric}};determineDataLimits(){const{min:t,max:n}=this.getMinMax(!0);this.min=Js(t)?t:0,this.max=Js(n)?n:1,this.handleTickRangeOptions()}computeTickLimit(){const t=this.isHorizontal(),n=t?this.width:this.height,s=Ao(this.options.ticks.minRotation),i=(t?Math.sin(s):Math.cos(s))||.001,a=this._resolveTickFontOptions(0);return Math.ceil(n/Math.min(40,a.lineHeight/i))}getPixelForValue(t){return t===null?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getValueForPixel(t){return this._startValue+this.getDecimalForPixel(t)*this._valueRange}}const my={millisecond:{common:!0,size:1,steps:1e3},second:{common:!0,size:1e3,steps:60},minute:{common:!0,size:6e4,steps:60},hour:{common:!0,size:36e5,steps:24},day:{common:!0,size:864e5,steps:30},week:{common:!1,size:6048e5,steps:4},month:{common:!0,size:2628e6,steps:12},quarter:{common:!1,size:7884e6,steps:4},year:{common:!0,size:3154e7}},Ci=Object.keys(my);function YD(e,t){return e-t}function QD(e,t){if(Tt(t))return null;const n=e._adapter,{parser:s,round:i,isoWeekday:a}=e._parseOpts;let o=t;return typeof s=="function"&&(o=s(o)),Js(o)||(o=typeof s=="string"?n.parse(o,s):n.parse(o)),o===null?null:(i&&(o=i==="week"&&(Qd(a)||a===!0)?n.startOf(o,"isoWeek",a):n.startOf(o,i)),+o)}function XD(e,t,n,s){const i=Ci.length;for(let a=Ci.indexOf(e);a<i-1;++a){const o=my[Ci[a]],l=o.steps?o.steps:Number.MAX_SAFE_INTEGER;if(o.common&&Math.ceil((n-t)/(l*o.size))<=s)return Ci[a]}return Ci[i-1]}function DNe(e,t,n,s,i){for(let a=Ci.length-1;a>=Ci.indexOf(n);a--){const o=Ci[a];if(my[o].common&&e._adapter.diff(i,s,o)>=t-1)return o}return Ci[n?Ci.indexOf(n):0]}function ONe(e){for(let t=Ci.indexOf(e)+1,n=Ci.length;t<n;++t)if(my[Ci[t]].common)return Ci[t]}function JD(e,t,n){if(!n)e[t]=!0;else if(n.length){const{lo:s,hi:i}=cN(n,t),a=n[s]>=t?n[s]:n[i];e[a]=!0}}function PNe(e,t,n,s){const i=e._adapter,a=+i.startOf(t[0].value,s),o=t[t.length-1].value;let l,c;for(l=a;l<=o;l=+i.add(l,1,s))c=n[l],c>=0&&(t[c].major=!0);return t}function ZD(e,t,n){const s=[],i={},a=t.length;let o,l;for(o=0;o<a;++o)l=t[o],i[l]=o,s.push({value:l,major:!1});return a===0||!n?s:PNe(e,s,i,n)}class e8 extends Ah{static id="time";static defaults={bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}};constructor(t){super(t),this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(t,n={}){const s=t.time||(t.time={}),i=this._adapter=new f5e._date(t.adapters.date);i.init(n),xp(s.displayFormats,i.formats()),this._parseOpts={parser:s.parser,round:s.round,isoWeekday:s.isoWeekday},super.init(t),this._normalized=n.normalized}parse(t,n){return t===void 0?null:QD(this,t)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){const t=this.options,n=this._adapter,s=t.time.unit||"day";let{min:i,max:a,minDefined:o,maxDefined:l}=this.getUserBounds();function c(d){!o&&!isNaN(d.min)&&(i=Math.min(i,d.min)),!l&&!isNaN(d.max)&&(a=Math.max(a,d.max))}(!o||!l)&&(c(this._getLabelBounds()),(t.bounds!=="ticks"||t.ticks.source!=="labels")&&c(this.getMinMax(!1))),i=Js(i)&&!isNaN(i)?i:+n.startOf(Date.now(),s),a=Js(a)&&!isNaN(a)?a:+n.endOf(Date.now(),s)+1,this.min=Math.min(i,a-1),this.max=Math.max(i+1,a)}_getLabelBounds(){const t=this.getLabelTimestamps();let n=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;return t.length&&(n=t[0],s=t[t.length-1]),{min:n,max:s}}buildTicks(){const t=this.options,n=t.time,s=t.ticks,i=s.source==="labels"?this.getLabelTimestamps():this._generate();t.bounds==="ticks"&&i.length&&(this.min=this._userMin||i[0],this.max=this._userMax||i[i.length-1]);const a=this.min,o=this.max,l=RSe(i,a,o);return this._unit=n.unit||(s.autoSkip?XD(n.minUnit,this.min,this.max,this._getLabelCapacity(a)):DNe(this,l.length,n.minUnit,this.min,this.max)),this._majorUnit=!s.major.enabled||this._unit==="year"?void 0:ONe(this._unit),this.initOffsets(i),t.reverse&&l.reverse(),ZD(this,l,this._majorUnit)}afterAutoSkip(){this.options.offsetAfterAutoskip&&this.initOffsets(this.ticks.map(t=>+t.value))}initOffsets(t=[]){let n=0,s=0,i,a;this.options.offset&&t.length&&(i=this.getDecimalForValue(t[0]),t.length===1?n=1-i:n=(this.getDecimalForValue(t[1])-i)/2,a=this.getDecimalForValue(t[t.length-1]),t.length===1?s=a:s=(a-this.getDecimalForValue(t[t.length-2]))/2);const o=t.length<3?.5:.25;n=Ws(n,0,o),s=Ws(s,0,o),this._offsets={start:n,end:s,factor:1/(n+1+s)}}_generate(){const t=this._adapter,n=this.min,s=this.max,i=this.options,a=i.time,o=a.unit||XD(a.minUnit,n,s,this._getLabelCapacity(n)),l=it(i.ticks.stepSize,1),c=o==="week"?a.isoWeekday:!1,d=Qd(c)||c===!0,f={};let p=n,m,g;if(d&&(p=+t.startOf(p,"isoWeek",c)),p=+t.startOf(p,d?"day":o),t.diff(s,n,o)>1e5*l)throw new Error(n+" and "+s+" are too far apart with stepSize of "+l+" "+o);const b=i.ticks.source==="data"&&this.getDataTimestamps();for(m=p,g=0;m<s;m=+t.add(m,l,o),g++)JD(f,m,b);return(m===s||i.bounds==="ticks"||g===1)&&JD(f,m,b),Object.keys(f).sort(YD).map(_=>+_)}getLabelForValue(t){const n=this._adapter,s=this.options.time;return s.tooltipFormat?n.format(t,s.tooltipFormat):n.format(t,s.displayFormats.datetime)}format(t,n){const i=this.options.time.displayFormats,a=this._unit,o=n||i[a];return this._adapter.format(t,o)}_tickFormatFunction(t,n,s,i){const a=this.options,o=a.ticks.callback;if(o)return rn(o,[t,n,s],this);const l=a.time.displayFormats,c=this._unit,d=this._majorUnit,f=c&&l[c],p=d&&l[d],m=s[n],g=d&&p&&m&&m.major;return this._adapter.format(t,i||(g?p:f))}generateTickLabels(t){let n,s,i;for(n=0,s=t.length;n<s;++n)i=t[n],i.label=this._tickFormatFunction(i.value,n,t)}getDecimalForValue(t){return t===null?NaN:(t-this.min)/(this.max-this.min)}getPixelForValue(t){const n=this._offsets,s=this.getDecimalForValue(t);return this.getPixelForDecimal((n.start+s)*n.factor)}getValueForPixel(t){const n=this._offsets,s=this.getDecimalForPixel(t)/n.factor-n.end;return this.min+s*(this.max-this.min)}_getLabelSize(t){const n=this.options.ticks,s=this.ctx.measureText(t).width,i=Ao(this.isHorizontal()?n.maxRotation:n.minRotation),a=Math.cos(i),o=Math.sin(i),l=this._resolveTickFontOptions(0).size;return{w:s*a+l*o,h:s*o+l*a}}_getLabelCapacity(t){const n=this.options.time,s=n.displayFormats,i=s[n.unit]||s.millisecond,a=this._tickFormatFunction(t,0,ZD(this,[t],this._majorUnit),i),o=this._getLabelSize(a),l=Math.floor(this.isHorizontal()?this.width/o.w:this.height/o.h)-1;return l>0?l:1}getDataTimestamps(){let t=this._cache.data||[],n,s;if(t.length)return t;const i=this.getMatchingVisibleMetas();if(this._normalized&&i.length)return this._cache.data=i[0].controller.getAllParsedValues(this);for(n=0,s=i.length;n<s;++n)t=t.concat(i[n].controller.getAllParsedValues(this));return this._cache.data=this.normalize(t)}getLabelTimestamps(){const t=this._cache.labels||[];let n,s;if(t.length)return t;const i=this.getLabels();for(n=0,s=i.length;n<s;++n)t.push(QD(this,i[n]));return this._cache.labels=this._normalized?t:this.normalize(t)}normalize(t){return PV(t.sort(YD))}}function tb(e,t,n){let s=0,i=e.length-1,a,o,l,c;n?(t>=e[s].pos&&t<=e[i].pos&&({lo:s,hi:i}=Gc(e,"pos",t)),{pos:a,time:l}=e[s],{pos:o,time:c}=e[i]):(t>=e[s].time&&t<=e[i].time&&({lo:s,hi:i}=Gc(e,"time",t)),{time:a,pos:l}=e[s],{time:o,pos:c}=e[i]);const d=o-a;return d?l+(c-l)*(t-a)/d:l}class Y8e extends e8{static id="timeseries";static defaults=e8.defaults;constructor(t){super(t),this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){const t=this._getTimestampsForTable(),n=this._table=this.buildLookupTable(t);this._minPos=tb(n,this.min),this._tableRange=tb(n,this.max)-this._minPos,super.initOffsets(t)}buildLookupTable(t){const{min:n,max:s}=this,i=[],a=[];let o,l,c,d,f;for(o=0,l=t.length;o<l;++o)d=t[o],d>=n&&d<=s&&i.push(d);if(i.length<2)return[{time:n,pos:0},{time:s,pos:1}];for(o=0,l=i.length;o<l;++o)f=i[o+1],c=i[o-1],d=i[o],Math.round((f+c)/2)!==d&&a.push({time:d,pos:o/(l-1)});return a}_generate(){const t=this.min,n=this.max;let s=super.getDataTimestamps();return(!s.includes(t)||!s.length)&&s.splice(0,0,t),(!s.includes(n)||s.length===1)&&s.push(n),s.sort((i,a)=>i-a)}_getTimestampsForTable(){let t=this._cache.all||[];if(t.length)return t;const n=this.getDataTimestamps(),s=this.getLabelTimestamps();return n.length&&s.length?t=this.normalize(n.concat(s)):t=n.length?n:s,t=this._cache.all=t,t}getDecimalForValue(t){return(tb(this._table,t)-this._minPos)/this._tableRange}getValueForPixel(t){const n=this._offsets,s=this.getDecimalForPixel(t)/n.factor-n.end;return tb(this._table,s*this._tableRange+this._minPos,!0)}}const _U="label";function t8(e,t){typeof e=="function"?e(t):e&&(e.current=t)}function INe(e,t){const n=e.options;n&&t&&Object.assign(n,t)}function wU(e,t){e.labels=t}function AU(e,t,n=_U){const s=[];e.datasets=t.map(i=>{const a=e.datasets.find(o=>o[n]===i[n]);return!a||!i.data||s.includes(a)?{...i}:(s.push(a),Object.assign(a,i),a)})}function LNe(e,t=_U){const n={labels:[],datasets:[]};return wU(n,e.labels),AU(n,e.datasets,t),n}function BNe(e,t){const{height:n=150,width:s=300,redraw:i=!1,datasetIdKey:a,type:o,data:l,options:c,plugins:d=[],fallbackContent:f,updateMode:p,...m}=e,g=y.useRef(null),b=y.useRef(null),_=()=>{g.current&&(b.current=new hy(g.current,{type:o,data:LNe(l,a),options:c&&{...c},plugins:d}),t8(t,b.current))},w=()=>{t8(t,null),b.current&&(b.current.destroy(),b.current=null)};return y.useEffect(()=>{!i&&b.current&&c&&INe(b.current,c)},[i,c]),y.useEffect(()=>{!i&&b.current&&wU(b.current.config.data,l.labels)},[i,l.labels]),y.useEffect(()=>{!i&&b.current&&l.datasets&&AU(b.current.config.data,l.datasets,a)},[i,l.datasets]),y.useEffect(()=>{b.current&&(i?(w(),setTimeout(_)):b.current.update(p))},[i,c,l.labels,l.datasets,p]),y.useEffect(()=>{b.current&&(w(),setTimeout(_))},[o]),y.useEffect(()=>(_(),()=>w()),[]),r.jsx("canvas",{ref:g,role:"img",height:n,width:s,...m,children:f})}const zNe=y.forwardRef(BNe);function xy(e,t){return hy.register(t),y.forwardRef((n,s)=>r.jsx(zNe,{...n,ref:s,type:e}))}const $Ne=xy("line",u5e),n8=xy("bar",o5e),VNe=xy("pie",d5e),UNe=xy("scatter",h5e);hy.register(FNe,RNe,Lje,fy,Hje,kje,bNe,jNe,xNe,uNe);const $f=["#6366F1","#8B5CF6","#EC4899","#10B981","#F59E0B","#EF4444","#3B82F6","#14B8A6","#F97316","#84CC16"];function HNe({data:e}){const t=y.useMemo(()=>({labels:e.labels,datasets:e.datasets.map((i,a)=>({...i,backgroundColor:i.backgroundColor??(e.type==="pie"?$f.slice(0,e.labels.length):`${$f[a%$f.length]}88`),borderColor:i.borderColor??$f[a%$f.length],borderWidth:e.type==="pie"?0:2,pointRadius:e.type==="scatter"?4:3,tension:.3}))}),[e]),n=y.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,plugins:{title:e.title?{display:!0,text:e.title,color:"#F0F0F5",font:{size:12,weight:500},padding:{bottom:12}}:{display:!1},legend:{display:e.datasets.length>1||e.type==="pie",position:"bottom",labels:{color:"#8A8A99",font:{size:10},boxWidth:10,padding:8}},tooltip:{backgroundColor:"#1C1C21",titleColor:"#F0F0F5",bodyColor:"#C8C8D4",borderColor:"#2A2A35",borderWidth:1,titleFont:{size:11},bodyFont:{size:10},padding:8}},scales:e.type==="pie"?{}:{x:{ticks:{color:"#5A5A6E",font:{size:10}},grid:{color:"#2A2A35",drawBorder:!1}},y:{ticks:{color:"#5A5A6E",font:{size:10}},grid:{color:"#2A2A35",drawBorder:!1}}}}),[e]),s={bar:n8,line:$Ne,pie:VNe,scatter:UNe}[e.type]??n8;return r.jsx("div",{className:"p-4",style:{height:e.type==="pie"?320:280},children:r.jsx(s,{data:t,options:n})})}function WNe({data:e,onChange:t}){const[n,s]=y.useState(null),[i,a]=y.useState(!0),[o,l]=y.useState(""),[c,d]=y.useState(null),[f,p]=y.useState(""),m=y.useCallback(A=>{n===A?a(S=>!S):(s(A),a(!0))},[n]),g=y.useMemo(()=>{if(!o.trim())return e.rows;const A=o.toLowerCase();return e.rows.filter(S=>e.columns.some(C=>String(S[C.key]??"").toLowerCase().includes(A)))},[e.rows,e.columns,o]),b=y.useMemo(()=>{if(!n)return g;const A=e.columns.find(S=>S.key===n);return[...g].sort((S,C)=>{const E=S[n]??"",k=C[n]??"";return A?.type==="number"||typeof E=="number"&&typeof k=="number"?i?Number(E)-Number(k):Number(k)-Number(E):i?String(E).localeCompare(String(k)):String(k).localeCompare(String(E))})},[g,n,i,e.columns]),_=y.useCallback((A,S,C)=>{d({row:A,key:S}),p(String(C??""))},[]),w=y.useCallback(()=>{if(!c)return;if(!e.rows[c.row]){d(null);return}const S=e.columns.find(k=>k.key===c.key);let C=f;S?.type==="number"&&(C=Number(f)||0);const E=e.rows.map((k,T)=>T===c.row?{...k,[c.key]:C}:k);t({...e,rows:E}),d(null)},[c,f,e,t]);return r.jsxs("div",{className:"flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-[#2A2A35]",children:[e.title&&r.jsx("span",{className:"text-[11px] font-semibold text-[#F0F0F5] mr-2",children:e.title}),r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded bg-[#1C1C21] border border-[#2A2A35] flex-1 max-w-[200px]",children:[r.jsx(Io,{className:"w-3 h-3 text-[#5A5A6E]"}),r.jsx("input",{value:o,onChange:A=>l(A.target.value),placeholder:"Filter...",className:"flex-1 bg-transparent text-[11px] text-[#C8C8D4] placeholder-[#5A5A6E] outline-none"})]}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E] ml-auto",children:[b.length," / ",e.rows.length]})]}),r.jsxs("div",{className:"overflow-auto max-h-[500px]",children:[r.jsxs("table",{className:"w-full text-[11px]",children:[r.jsx("thead",{className:"sticky top-0 bg-[#16161A] z-10",children:r.jsx("tr",{className:"border-b border-[#2A2A35]",children:e.columns.map(A=>r.jsx("th",{onClick:()=>m(A.key),className:"px-3 py-2 text-left text-[#8A8A99] font-medium cursor-pointer hover:text-[#C8C8D4] transition-colors whitespace-nowrap select-none",children:r.jsxs("span",{className:"inline-flex items-center gap-1",children:[A.label,n===A.key?i?r.jsx(vse,{className:"w-3 h-3 text-[#6366F1]"}):r.jsx(fse,{className:"w-3 h-3 text-[#6366F1]"}):r.jsx(gse,{className:"w-3 h-3 opacity-30"})]})},A.key))})}),r.jsx("tbody",{children:b.map((A,S)=>{const C=e.rows.indexOf(A);return r.jsx("tr",{className:"border-b border-[#2A2A35]/50 hover:bg-white/[0.02]",children:e.columns.map(E=>{const k=c?.row===C&&c?.key===E.key;return r.jsx("td",{className:"px-3 py-1.5 text-[#C8C8D4]",children:k?r.jsx("input",{value:f,onChange:T=>p(T.target.value),onBlur:w,onKeyDown:T=>{T.key==="Enter"&&w(),T.key==="Escape"&&d(null)},className:"w-full bg-[#1C1C21] text-[11px] text-[#F0F0F5] rounded px-1 py-0.5 outline-none border border-[#6366F1]/30",autoFocus:!0}):r.jsx("span",{onDoubleClick:()=>_(C,E.key,A[E.key]),className:"cursor-default",children:String(A[E.key]??"")})},E.key)})},S)})})]}),b.length===0&&r.jsx("p",{className:"px-4 py-6 text-center text-[11px] text-[#5A5A6E] italic",children:o?"No matching rows.":"No data."})]})]})}const s8=[{bg:"bg-[#6366F1]/10",text:"text-[#818CF8]"},{bg:"bg-[#10B981]/10",text:"text-[#34D399]"},{bg:"bg-[#EC4899]/10",text:"text-[#F472B6]"},{bg:"bg-[#F59E0B]/10",text:"text-[#FBBF24]"},{bg:"bg-[#EF4444]/10",text:"text-[#F87171]"},{bg:"bg-[#3B82F6]/10",text:"text-[#60A5FA]"}];function qNe(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return s8[Math.abs(t)%s8.length]}function GNe({card:e,onEdit:t,onRemove:n}){const[s,i]=y.useState(!1),[a,o]=y.useState(e.title),[l,c]=y.useState(e.description??""),d=y.useCallback(()=>{a.trim()&&t(e.id,a.trim(),l.trim()),i(!1)},[e.id,a,l,t]);return s?r.jsxs("div",{className:"bg-[#16161A] rounded-lg border border-[#6366F1]/30 p-3",children:[r.jsx("input",{value:a,onChange:f=>o(f.target.value),onKeyDown:f=>f.key==="Enter"&&d(),className:"w-full bg-transparent text-[12px] text-[#F0F0F5] outline-none font-medium mb-1.5",autoFocus:!0}),r.jsx("textarea",{value:l,onChange:f=>c(f.target.value),rows:3,className:"w-full bg-transparent text-[11px] text-[#8A8A99] outline-none resize-none",placeholder:"Description..."}),r.jsxs("div",{className:"flex justify-end gap-1 mt-2",children:[r.jsx("button",{onClick:()=>i(!1),className:"p-1 text-[#5A5A6E] hover:text-[#C8C8D4]",children:r.jsx(Te,{className:"w-3 h-3"})}),r.jsx("button",{onClick:d,className:"p-1 text-[#10B981] hover:text-[#34D399]",children:r.jsx(Fe,{className:"w-3 h-3"})})]})]}):r.jsxs("div",{className:"bg-[#16161A] rounded-lg border border-[#2A2A35] hover:border-[#3A3A45] transition-colors group",children:[e.image&&r.jsx("div",{className:"aspect-video overflow-hidden rounded-t-lg",children:r.jsx("img",{src:e.image,alt:"",className:"w-full h-full object-cover"})}),r.jsxs("div",{className:"p-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsx("h4",{className:"text-[12px] font-medium text-[#F0F0F5] leading-snug",children:e.title}),r.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:[e.url&&r.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"p-0.5 text-[#5A5A6E] hover:text-[#6366F1]",children:r.jsx(cs,{className:"w-2.5 h-2.5"})}),r.jsx("button",{onClick:()=>i(!0),className:"p-0.5 text-[#5A5A6E] hover:text-[#C8C8D4]",children:r.jsx(oh,{className:"w-2.5 h-2.5"})}),r.jsx("button",{onClick:()=>n(e.id),className:"p-0.5 text-[#5A5A6E] hover:text-[#EF4444]",children:r.jsx(Te,{className:"w-2.5 h-2.5"})})]})]}),e.description&&r.jsx("p",{className:"text-[11px] text-[#8A8A99] mt-1 leading-snug line-clamp-3",children:e.description}),e.tags&&e.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:e.tags.map(f=>{const p=qNe(f);return r.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-medium ${p.bg} ${p.text}`,children:f},f)})}),e.meta&&Object.keys(e.meta).length>0&&r.jsx("div",{className:"mt-2 pt-2 border-t border-[#2A2A35]/50 space-y-0.5",children:Object.entries(e.meta).map(([f,p])=>r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px]",children:[r.jsxs("span",{className:"text-[#5A5A6E]",children:[f,":"]}),r.jsx("span",{className:"text-[#C8C8D4]",children:p})]},f))})]})]})}function KNe({data:e,onChange:t}){const n=e.columns??3,s=y.useCallback((a,o,l)=>{const c=e.cards.map(d=>d.id===a?{...d,title:o,description:l}:d);t({...e,cards:c})},[e,t]),i=y.useCallback(a=>{t({...e,cards:e.cards.filter(o=>o.id!==a)})},[e,t]);return r.jsxs("div",{className:"p-3",children:[e.title&&r.jsx("h3",{className:"text-[12px] font-semibold text-[#F0F0F5] mb-3",children:e.title}),r.jsx("div",{className:"grid gap-2",style:{gridTemplateColumns:`repeat(${Math.min(n,4)}, minmax(0, 1fr))`},children:e.cards.map(a=>r.jsx(GNe,{card:a,onEdit:s,onRemove:i},a.id))}),e.cards.length===0&&r.jsx("p",{className:"text-center py-8 text-[11px] text-[#5A5A6E] italic",children:"No cards"})]})}function SU(e){return e.endsWith(".kanban.json")?"kanban":e.endsWith(".chart.json")?"chart":e.endsWith(".table.json")?"table":e.endsWith(".board.json")?"board":null}function CU(e){return SU(e)!==null}function YNe(e,t){if(!t||typeof t!="object")return!1;switch(e){case"kanban":return Array.isArray(t.columns);case"chart":return typeof t.type=="string"&&Array.isArray(t.labels)&&Array.isArray(t.datasets);case"table":return Array.isArray(t.columns)&&Array.isArray(t.rows);case"board":return Array.isArray(t.cards);default:return!1}}function jU({agentId:e,filePath:t,content:n}){const s=SU(t),i=L.files.writeStructured.useMutation(),a=y.useRef(void 0),o=y.useMemo(()=>{try{return JSON.parse(n)}catch{return null}},[n]),[l,c]=y.useState(o),[d,f]=y.useState(!1);y.useEffect(()=>{c(o),f(!1)},[o]);const p=y.useCallback(m=>{c(m),f(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{const g=JSON.stringify(m,null,2);i.mutate({agentId:e,filePath:t,content:g}),f(!1)},800)},[e,t,i]);return y.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]),!s||!l||!YNe(s,l)?null:r.jsxs("div",{className:"relative",children:[d&&r.jsx("div",{className:"absolute top-2 right-3 z-10",children:r.jsx("span",{className:"text-[9px] text-[#F59E0B] bg-[#F59E0B]/10 px-1.5 py-0.5 rounded",children:"Saving..."})}),s==="kanban"&&r.jsx(G2e,{data:l,onChange:p}),s==="chart"&&r.jsx(HNe,{data:l}),s==="table"&&r.jsx(WNe,{data:l,onChange:p}),s==="board"&&r.jsx(KNe,{data:l,onChange:p})]})}const QNe={kanban:"Kanban Board",chart:"Chart",table:"Data Table",board:"Card Grid"};function XNe(e){for(const[t,n]of Object.entries(QNe))if(e.endsWith(`.${t}.json`))return n;return"Structured File"}function yN({agentId:e,filePath:t,onClose:n}){const s=t.split("/").pop()??t,i=XNe(s),{data:a,isLoading:o}=L.files.read.useQuery({agentId:e,filePath:t},{retry:!1});return r.jsx(ji,{open:!0,onOpenChange:l=>{l||n()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-40"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[90vw] max-w-[1100px] max-h-[85vh] bg-[#13131A] border border-[#2A2A35] rounded-xl shadow-2xl z-50 flex flex-col",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(nr,{className:"text-[13px] font-semibold text-[#F0F0F5] truncate",children:s}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] bg-white/[0.04] px-1.5 py-0.5 rounded flex-shrink-0",children:i})]}),r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})})]}),r.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[o&&r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]})}),!o&&a?.content&&r.jsx(jU,{agentId:e,filePath:t,content:a.content}),!o&&!a?.content&&r.jsx("p",{className:"text-center py-12 text-[12px] text-[#5A5A6E]",children:"Unable to load file."})]})]})]})})}const JNe=/\.(kanban|chart|table|board)\.json$/;function ZNe(e){const t=e.match(JNe);return t?t[1]:null}const eke={kanban:nL,chart:M5,table:wL,board:ym},tke={kanban:"#6366F1",chart:"#10B981",table:"#3B82F6",board:"#8B5CF6"};function nke(e,t){try{const n=JSON.parse(t);switch(e){case"kanban":{const s=Array.isArray(n.columns)?n.columns.length:0,i=Array.isArray(n.columns)?n.columns.reduce((a,o)=>a+(Array.isArray(o.cards)?o.cards.length:0),0):0;return`${s} columns, ${i} cards`}case"chart":{const s=n.type??"unknown",i=Array.isArray(n.labels)?n.labels.length:0;return`${s} chart — ${i} data points`}case"table":{const s=Array.isArray(n.rows)?n.rows.length:0,i=Array.isArray(n.columns)?n.columns.length:0;return`${s} rows × ${i} columns`}case"board":return`${Array.isArray(n.cards)?n.cards.length:0} cards`}}catch{return"structured file"}}function ske({agentId:e,filePath:t,filename:n,content:s}){const[i,a]=y.useState(!1),o=ZNe(n);if(!o)return null;const l=eke[o],c=tke[o],d=s?nke(o,s):null;return r.jsxs(r.Fragment,{children:[r.jsxs(ne.button,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2},onClick:()=>a(!0),className:"flex items-center gap-2.5 px-3 py-2 rounded-lg border transition-colors duration-100 hover:brightness-110 w-fit max-w-[380px] group",style:{backgroundColor:`${c}08`,borderColor:`${c}25`},children:[r.jsx("div",{className:"w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0",style:{backgroundColor:`${c}18`},children:r.jsx(l,{className:"w-3.5 h-3.5",style:{color:c}})}),r.jsxs("div",{className:"flex flex-col items-start min-w-0",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5] truncate max-w-[280px]",children:n}),d&&r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:d})]})]}),i&&r.jsx(yN,{agentId:e,filePath:t,onClose:()=>a(!1)})]})}const NU=$o(e=>({cardsByChannel:{},addCard:(t,n)=>e(s=>{const i=s.cardsByChannel[t]??[],a=`${n.agentId}:${n.filePath}`,o=i.filter(l=>`${l.agentId}:${l.filePath}`!==a);return{cardsByChannel:{...s.cardsByChannel,[t]:[...o,n]}}}),dismissCard:(t,n)=>e(s=>{const i=s.cardsByChannel[t];return i?{cardsByChannel:{...s.cardsByChannel,[t]:i.filter(a=>a.id!==n)}}:s})}));function ike({channelId:e,agentForChannel:t,agentColor:n,messages:s=[],isThinking:i,isLoading:a,loadMore:o,firstUnreadId:l}){const{data:c=[]}=Vo(),d=y.useRef(null),f=y.useRef(null),[p,m]=y.useState(!1),[g,b]=y.useState(!0),_=y.useRef(0),w=L.readReceipts.markRead.useMutation(),A=Je(R=>R.setUnreadCount),S=y.useRef(!1),C=Je(R=>R.fileEditApprovalsByChannel[e])??[],E=Je(R=>R.removeFileEditApproval),k=NU(R=>R.cardsByChannel[e])??[],{data:T}=L.fileEditApprovals.list.useQuery({channelId:e},{staleTime:3e4});y.useEffect(()=>{if(!T)return;const R=Je.getState().addFileEditApproval;for(const H of T)R(H)},[T]),y.useEffect(()=>{d.current?.scrollIntoView({behavior:"instant"})},[e]);const F=s.length>0?s[s.length-1]?.id:null;y.useEffect(()=>{d.current?.scrollIntoView({behavior:"smooth"})},[F]),y.useEffect(()=>{if(l&&!S.current){const R=document.getElementById(`msg-${l}`);R&&(R.scrollIntoView({behavior:"smooth",block:"start"}),S.current=!0)}},[l,s]),y.useEffect(()=>{S.current=!1},[e]),y.useEffect(()=>{s.length!==0&&(w.mutate({channelId:e}),A(e,0))},[e,s.length]);const M=y.useCallback(async()=>{const R=f.current;if(!(!R||!o||p||!g)&&R.scrollTop<100){m(!0),_.current=R.scrollHeight;const H=await o();b(H??!1),m(!1),requestAnimationFrame(()=>{const V=R.scrollHeight;R.scrollTop=V-_.current})}},[o,p,g]),I=i&&t?[{...t,status:"thinking"}]:t?[t].filter(R=>R.status==="thinking"||R.status==="executing"):c.filter(R=>s.some(V=>V.sender.id===R.id)&&(R.status==="thinking"||R.status==="executing"));return a?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsxs("div",{className:"flex items-center gap-2 text-[#8A8A99]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.4s]"})]})}):r.jsxs("div",{ref:f,onScroll:M,className:"flex-1 overflow-y-auto overflow-x-hidden py-2 scrollbar-agent",style:n?{"--agent-color":n}:void 0,"data-channel":e,children:[p&&r.jsx("div",{className:"flex justify-center py-3",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99]",children:[r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse"}),r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.15s]"}),r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.3s]"})]})}),r.jsx(Me,{initial:!1,children:s.map(R=>{if(R.sender.type==="context_reset"){const V=R.content.startsWith("compacted:");return r.jsxs("div",{id:`msg-${R.id}`,className:"flex items-center gap-3 py-2 px-4",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:V?"earlier messages summarized":"new context"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]},R.id)}const H=R.id===l;return r.jsxs("div",{id:`msg-${R.id}`,children:[H&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"flex items-center gap-3 px-4 py-1 my-1",children:[r.jsx("div",{className:"flex-1 h-px bg-[#6366F1]/40"}),r.jsx("span",{className:"text-[11px] text-[#6366F1] font-medium shrink-0",children:"New messages"}),r.jsx("div",{className:"flex-1 h-px bg-[#6366F1]/40"})]}),r.jsx(Z7,{message:R,agentColor:n})]},R.id)})}),I.map(R=>r.jsx(U7,{agent:R},`thinking-${R.id}`)),C.length>0&&r.jsx("div",{className:"px-4 py-2",children:C.map(R=>{const H=c.find(V=>V.id===R.agentId);return r.jsx(tAe,{approval:R,agentName:H?.name??R.agentId,onDecided:V=>E(e,V)},R.id)})}),k.length>0&&r.jsx("div",{className:"px-4 py-2 space-y-1.5",children:k.map(R=>r.jsx(ske,{agentId:R.agentId,filePath:R.filePath,filename:R.filename},R.id))}),r.jsx("div",{ref:d,className:"h-4"})]})}function rke(e){const t=e.split(`
189
+ `):e}function vNe(e,t){const{element:n,datasetIndex:s,index:i}=t,a=e.getDatasetMeta(s).controller,{label:o,value:l}=a.getLabelAndValue(i);return{chart:e,label:o,parsed:a.getParsed(i),raw:e.data.datasets[s].data[i],formattedValue:l,dataset:a.getDataset(),dataIndex:i,datasetIndex:s,element:n}}function $D(e,t){const n=e.chart.ctx,{body:s,footer:i,title:a}=e,{boxWidth:o,boxHeight:l}=t,c=qs(t.bodyFont),d=qs(t.titleFont),f=qs(t.footerFont),p=a.length,m=i.length,g=s.length,b=Lr(t.padding);let _=b.height,w=0,A=s.reduce((E,k)=>E+k.before.length+k.lines.length+k.after.length,0);if(A+=e.beforeBody.length+e.afterBody.length,p&&(_+=p*d.lineHeight+(p-1)*t.titleSpacing+t.titleMarginBottom),A){const E=t.displayColors?Math.max(l,c.lineHeight):c.lineHeight;_+=g*E+(A-g)*c.lineHeight+(A-1)*t.bodySpacing}m&&(_+=t.footerMarginTop+m*f.lineHeight+(m-1)*t.footerSpacing);let S=0;const C=function(E){w=Math.max(w,n.measureText(E).width+S)};return n.save(),n.font=d.string,It(e.title,C),n.font=c.string,It(e.beforeBody.concat(e.afterBody),C),S=t.displayColors?o+2+t.boxPadding:0,It(s,E=>{It(E.before,C),It(E.lines,C),It(E.after,C)}),S=0,n.font=f.string,It(e.footer,C),n.restore(),w+=b.width,{width:w,height:_}}function yNe(e,t){const{y:n,height:s}=t;return n<s/2?"top":n>e.height-s/2?"bottom":"center"}function _Ne(e,t,n,s){const{x:i,width:a}=s,o=n.caretSize+n.caretPadding;if(e==="left"&&i+a+o>t.width||e==="right"&&i-a-o<0)return!0}function wNe(e,t,n,s){const{x:i,width:a}=n,{width:o,chartArea:{left:l,right:c}}=e;let d="center";return s==="center"?d=i<=(l+c)/2?"left":"right":i<=a/2?d="left":i>=o-a/2&&(d="right"),_Ne(d,e,t,n)&&(d="center"),d}function VD(e,t,n){const s=n.yAlign||t.yAlign||yNe(e,n);return{xAlign:n.xAlign||t.xAlign||wNe(e,t,n,s),yAlign:s}}function ANe(e,t){let{x:n,width:s}=e;return t==="right"?n-=s:t==="center"&&(n-=s/2),n}function SNe(e,t,n){let{y:s,height:i}=e;return t==="top"?s+=n:t==="bottom"?s-=i+n:s-=i/2,s}function UD(e,t,n,s){const{caretSize:i,caretPadding:a,cornerRadius:o}=e,{xAlign:l,yAlign:c}=n,d=i+a,{topLeft:f,topRight:p,bottomLeft:m,bottomRight:g}=Id(o);let b=ANe(t,l);const _=SNe(t,c,d);return c==="center"?l==="left"?b+=d:l==="right"&&(b-=d):l==="left"?b-=Math.max(f,m)+i:l==="right"&&(b+=Math.max(p,g)+i),{x:Ws(b,0,s.width-t.width),y:Ws(_,0,s.height-t.height)}}function eb(e,t,n){const s=Lr(n.padding);return t==="center"?e.x+e.width/2:t==="right"?e.x+e.width-s.right:e.x+s.left}function HD(e){return wa([],yo(e))}function CNe(e,t,n){return wu(e,{tooltip:t,tooltipItems:n,type:"tooltip"})}function WD(e,t){const n=t&&t.dataset&&t.dataset.tooltip&&t.dataset.tooltip.callbacks;return n?e.override(n):e}const yU={beforeTitle:mo,title(e){if(e.length>0){const t=e[0],n=t.chart.data.labels,s=n?n.length:0;if(this&&this.options&&this.options.mode==="dataset")return t.dataset.label||"";if(t.label)return t.label;if(s>0&&t.dataIndex<s)return n[t.dataIndex]}return""},afterTitle:mo,beforeBody:mo,beforeLabel:mo,label(e){if(this&&this.options&&this.options.mode==="dataset")return e.label+": "+e.formattedValue||e.formattedValue;let t=e.dataset.label||"";t&&(t+=": ");const n=e.formattedValue;return Tt(n)||(t+=n),t},labelColor(e){const n=e.chart.getDatasetMeta(e.datasetIndex).controller.getStyle(e.dataIndex);return{borderColor:n.borderColor,backgroundColor:n.backgroundColor,borderWidth:n.borderWidth,borderDash:n.borderDash,borderDashOffset:n.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(e){const n=e.chart.getDatasetMeta(e.datasetIndex).controller.getStyle(e.dataIndex);return{pointStyle:n.pointStyle,rotation:n.rotation}},afterLabel:mo,afterBody:mo,beforeFooter:mo,footer:mo,afterFooter:mo};function wi(e,t,n,s){const i=e[t].call(n,s);return typeof i>"u"?yU[t].call(n,s):i}class qD extends Wo{static positioners=tp;constructor(t){super(),this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=t.chart,this.options=t.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(t){this.options=t,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){const t=this._cachedAnimations;if(t)return t;const n=this.chart,s=this.options.setContext(this.getContext()),i=s.enabled&&n.options.animation&&s.animations,a=new tU(this.chart,i);return i._cacheable&&(this._cachedAnimations=Object.freeze(a)),a}getContext(){return this.$context||(this.$context=CNe(this.chart.getContext(),this,this._tooltipItems))}getTitle(t,n){const{callbacks:s}=n,i=wi(s,"beforeTitle",this,t),a=wi(s,"title",this,t),o=wi(s,"afterTitle",this,t);let l=[];return l=wa(l,yo(i)),l=wa(l,yo(a)),l=wa(l,yo(o)),l}getBeforeBody(t,n){return HD(wi(n.callbacks,"beforeBody",this,t))}getBody(t,n){const{callbacks:s}=n,i=[];return It(t,a=>{const o={before:[],lines:[],after:[]},l=WD(s,a);wa(o.before,yo(wi(l,"beforeLabel",this,a))),wa(o.lines,wi(l,"label",this,a)),wa(o.after,yo(wi(l,"afterLabel",this,a))),i.push(o)}),i}getAfterBody(t,n){return HD(wi(n.callbacks,"afterBody",this,t))}getFooter(t,n){const{callbacks:s}=n,i=wi(s,"beforeFooter",this,t),a=wi(s,"footer",this,t),o=wi(s,"afterFooter",this,t);let l=[];return l=wa(l,yo(i)),l=wa(l,yo(a)),l=wa(l,yo(o)),l}_createItems(t){const n=this._active,s=this.chart.data,i=[],a=[],o=[];let l=[],c,d;for(c=0,d=n.length;c<d;++c)l.push(vNe(this.chart,n[c]));return t.filter&&(l=l.filter((f,p,m)=>t.filter(f,p,m,s))),t.itemSort&&(l=l.sort((f,p)=>t.itemSort(f,p,s))),It(l,f=>{const p=WD(t.callbacks,f);i.push(wi(p,"labelColor",this,f)),a.push(wi(p,"labelPointStyle",this,f)),o.push(wi(p,"labelTextColor",this,f))}),this.labelColors=i,this.labelPointStyles=a,this.labelTextColors=o,this.dataPoints=l,l}update(t,n){const s=this.options.setContext(this.getContext()),i=this._active;let a,o=[];if(!i.length)this.opacity!==0&&(a={opacity:0});else{const l=tp[s.position].call(this,i,this._eventPosition);o=this._createItems(s),this.title=this.getTitle(o,s),this.beforeBody=this.getBeforeBody(o,s),this.body=this.getBody(o,s),this.afterBody=this.getAfterBody(o,s),this.footer=this.getFooter(o,s);const c=this._size=$D(this,s),d=Object.assign({},l,c),f=VD(this.chart,s,d),p=UD(s,d,f,this.chart);this.xAlign=f.xAlign,this.yAlign=f.yAlign,a={opacity:1,x:p.x,y:p.y,width:c.width,height:c.height,caretX:l.x,caretY:l.y}}this._tooltipItems=o,this.$context=void 0,a&&this._resolveAnimations().update(this,a),t&&s.external&&s.external.call(this,{chart:this.chart,tooltip:this,replay:n})}drawCaret(t,n,s,i){const a=this.getCaretPosition(t,s,i);n.lineTo(a.x1,a.y1),n.lineTo(a.x2,a.y2),n.lineTo(a.x3,a.y3)}getCaretPosition(t,n,s){const{xAlign:i,yAlign:a}=this,{caretSize:o,cornerRadius:l}=s,{topLeft:c,topRight:d,bottomLeft:f,bottomRight:p}=Id(l),{x:m,y:g}=t,{width:b,height:_}=n;let w,A,S,C,E,k;return a==="center"?(E=g+_/2,i==="left"?(w=m,A=w-o,C=E+o,k=E-o):(w=m+b,A=w+o,C=E-o,k=E+o),S=w):(i==="left"?A=m+Math.max(c,f)+o:i==="right"?A=m+b-Math.max(d,p)-o:A=this.caretX,a==="top"?(C=g,E=C-o,w=A-o,S=A+o):(C=g+_,E=C+o,w=A+o,S=A-o),k=C),{x1:w,x2:A,x3:S,y1:C,y2:E,y3:k}}drawTitle(t,n,s){const i=this.title,a=i.length;let o,l,c;if(a){const d=Ld(s.rtl,this.x,this.width);for(t.x=eb(this,s.titleAlign,s),n.textAlign=d.textAlign(s.titleAlign),n.textBaseline="middle",o=qs(s.titleFont),l=s.titleSpacing,n.fillStyle=s.titleColor,n.font=o.string,c=0;c<a;++c)n.fillText(i[c],d.x(t.x),t.y+o.lineHeight/2),t.y+=o.lineHeight+l,c+1===a&&(t.y+=s.titleMarginBottom-l)}}_drawColorBox(t,n,s,i,a){const o=this.labelColors[s],l=this.labelPointStyles[s],{boxHeight:c,boxWidth:d}=a,f=qs(a.bodyFont),p=eb(this,"left",a),m=i.x(p),g=c<f.lineHeight?(f.lineHeight-c)/2:0,b=n.y+g;if(a.usePointStyle){const _={radius:Math.min(d,c)/2,pointStyle:l.pointStyle,rotation:l.rotation,borderWidth:1},w=i.leftForLtr(m,d)+d/2,A=b+c/2;t.strokeStyle=a.multiKeyBackground,t.fillStyle=a.multiKeyBackground,dC(t,_,w,A),t.strokeStyle=o.borderColor,t.fillStyle=o.backgroundColor,dC(t,_,w,A)}else{t.lineWidth=xt(o.borderWidth)?Math.max(...Object.values(o.borderWidth)):o.borderWidth||1,t.strokeStyle=o.borderColor,t.setLineDash(o.borderDash||[]),t.lineDashOffset=o.borderDashOffset||0;const _=i.leftForLtr(m,d),w=i.leftForLtr(i.xPlus(m,1),d-2),A=Id(o.borderRadius);Object.values(A).some(S=>S!==0)?(t.beginPath(),t.fillStyle=a.multiKeyBackground,z0(t,{x:_,y:b,w:d,h:c,radius:A}),t.fill(),t.stroke(),t.fillStyle=o.backgroundColor,t.beginPath(),z0(t,{x:w,y:b+1,w:d-2,h:c-2,radius:A}),t.fill()):(t.fillStyle=a.multiKeyBackground,t.fillRect(_,b,d,c),t.strokeRect(_,b,d,c),t.fillStyle=o.backgroundColor,t.fillRect(w,b+1,d-2,c-2))}t.fillStyle=this.labelTextColors[s]}drawBody(t,n,s){const{body:i}=this,{bodySpacing:a,bodyAlign:o,displayColors:l,boxHeight:c,boxWidth:d,boxPadding:f}=s,p=qs(s.bodyFont);let m=p.lineHeight,g=0;const b=Ld(s.rtl,this.x,this.width),_=function(M){n.fillText(M,b.x(t.x+g),t.y+m/2),t.y+=m+a},w=b.textAlign(o);let A,S,C,E,k,T,F;for(n.textAlign=o,n.textBaseline="middle",n.font=p.string,t.x=eb(this,w,s),n.fillStyle=s.bodyColor,It(this.beforeBody,_),g=l&&w!=="right"?o==="center"?d/2+f:d+2+f:0,E=0,T=i.length;E<T;++E){for(A=i[E],S=this.labelTextColors[E],n.fillStyle=S,It(A.before,_),C=A.lines,l&&C.length&&(this._drawColorBox(n,t,E,b,s),m=Math.max(p.lineHeight,c)),k=0,F=C.length;k<F;++k)_(C[k]),m=p.lineHeight;It(A.after,_)}g=0,m=p.lineHeight,It(this.afterBody,_),t.y-=a}drawFooter(t,n,s){const i=this.footer,a=i.length;let o,l;if(a){const c=Ld(s.rtl,this.x,this.width);for(t.x=eb(this,s.footerAlign,s),t.y+=s.footerMarginTop,n.textAlign=c.textAlign(s.footerAlign),n.textBaseline="middle",o=qs(s.footerFont),n.fillStyle=s.footerColor,n.font=o.string,l=0;l<a;++l)n.fillText(i[l],c.x(t.x),t.y+o.lineHeight/2),t.y+=o.lineHeight+s.footerSpacing}}drawBackground(t,n,s,i){const{xAlign:a,yAlign:o}=this,{x:l,y:c}=t,{width:d,height:f}=s,{topLeft:p,topRight:m,bottomLeft:g,bottomRight:b}=Id(i.cornerRadius);n.fillStyle=i.backgroundColor,n.strokeStyle=i.borderColor,n.lineWidth=i.borderWidth,n.beginPath(),n.moveTo(l+p,c),o==="top"&&this.drawCaret(t,n,s,i),n.lineTo(l+d-m,c),n.quadraticCurveTo(l+d,c,l+d,c+m),o==="center"&&a==="right"&&this.drawCaret(t,n,s,i),n.lineTo(l+d,c+f-b),n.quadraticCurveTo(l+d,c+f,l+d-b,c+f),o==="bottom"&&this.drawCaret(t,n,s,i),n.lineTo(l+g,c+f),n.quadraticCurveTo(l,c+f,l,c+f-g),o==="center"&&a==="left"&&this.drawCaret(t,n,s,i),n.lineTo(l,c+p),n.quadraticCurveTo(l,c,l+p,c),n.closePath(),n.fill(),i.borderWidth>0&&n.stroke()}_updateAnimationTarget(t){const n=this.chart,s=this.$animations,i=s&&s.x,a=s&&s.y;if(i||a){const o=tp[t.position].call(this,this._active,this._eventPosition);if(!o)return;const l=this._size=$D(this,t),c=Object.assign({},o,this._size),d=VD(n,t,c),f=UD(t,c,d,n);(i._to!==f.x||a._to!==f.y)&&(this.xAlign=d.xAlign,this.yAlign=d.yAlign,this.width=l.width,this.height=l.height,this.caretX=o.x,this.caretY=o.y,this._resolveAnimations().update(this,f))}}_willRender(){return!!this.opacity}draw(t){const n=this.options.setContext(this.getContext());let s=this.opacity;if(!s)return;this._updateAnimationTarget(n);const i={width:this.width,height:this.height},a={x:this.x,y:this.y};s=Math.abs(s)<.001?0:s;const o=Lr(n.padding),l=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;n.enabled&&l&&(t.save(),t.globalAlpha=s,this.drawBackground(a,t,i,n),YV(t,n.textDirection),a.y+=o.top,this.drawTitle(a,t,n),this.drawBody(a,t,n),this.drawFooter(a,t,n),QV(t,n.textDirection),t.restore())}getActiveElements(){return this._active||[]}setActiveElements(t,n){const s=this._active,i=t.map(({datasetIndex:l,index:c})=>{const d=this.chart.getDatasetMeta(l);if(!d)throw new Error("Cannot find a dataset at index "+l);return{datasetIndex:l,element:d.data[c],index:c}}),a=!I0(s,i),o=this._positionChanged(i,n);(a||o)&&(this._active=i,this._eventPosition=n,this._ignoreReplayEvents=!0,this.update(!0))}handleEvent(t,n,s=!0){if(n&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;const i=this.options,a=this._active||[],o=this._getActiveElements(t,a,n,s),l=this._positionChanged(o,t),c=n||!I0(o,a)||l;return c&&(this._active=o,(i.enabled||i.external)&&(this._eventPosition={x:t.x,y:t.y},this.update(!0,n))),c}_getActiveElements(t,n,s,i){const a=this.options;if(t.type==="mouseout")return[];if(!i)return n.filter(l=>this.chart.data.datasets[l.datasetIndex]&&this.chart.getDatasetMeta(l.datasetIndex).controller.getParsed(l.index)!==void 0);const o=this.chart.getElementsAtEventForMode(t,a.mode,a,s);return a.reverse&&o.reverse(),o}_positionChanged(t,n){const{caretX:s,caretY:i,options:a}=this,o=tp[a.position].call(this,t,n);return o!==!1&&(s!==o.x||i!==o.y)}}var jNe={id:"tooltip",_element:qD,positioners:tp,afterInit(e,t,n){n&&(e.tooltip=new qD({chart:e,options:n}))},beforeUpdate(e,t,n){e.tooltip&&e.tooltip.initialize(n)},reset(e,t,n){e.tooltip&&e.tooltip.initialize(n)},afterDraw(e){const t=e.tooltip;if(t&&t._willRender()){const n={tooltip:t};if(e.notifyPlugins("beforeTooltipDraw",{...n,cancelable:!0})===!1)return;t.draw(e.ctx),e.notifyPlugins("afterTooltipDraw",n)}},afterEvent(e,t){if(e.tooltip){const n=t.replay;e.tooltip.handleEvent(t.event,n,t.inChartArea)&&(t.changed=!0)}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(e,t)=>t.bodyFont.size,boxWidth:(e,t)=>t.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:yU},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:e=>e!=="filter"&&e!=="itemSort"&&e!=="external",_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]};const NNe=(e,t,n,s)=>(typeof t=="string"?(n=e.push(t)-1,s.unshift({index:n,label:t})):isNaN(t)&&(n=null),n);function kNe(e,t,n,s){const i=e.indexOf(t);if(i===-1)return NNe(e,t,n,s);const a=e.lastIndexOf(t);return i!==a?n:i}const ENe=(e,t)=>e===null?null:Ws(Math.round(e),0,t);function GD(e){const t=this.getLabels();return e>=0&&e<t.length?t[e]:e}class FNe extends Ah{static id="category";static defaults={ticks:{callback:GD}};constructor(t){super(t),this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(t){const n=this._addedLabels;if(n.length){const s=this.getLabels();for(const{index:i,label:a}of n)s[i]===a&&s.splice(i,1);this._addedLabels=[]}super.init(t)}parse(t,n){if(Tt(t))return null;const s=this.getLabels();return n=isFinite(n)&&s[n]===t?n:kNe(s,t,it(n,t),this._addedLabels),ENe(n,s.length-1)}determineDataLimits(){const{minDefined:t,maxDefined:n}=this.getUserBounds();let{min:s,max:i}=this.getMinMax(!0);this.options.bounds==="ticks"&&(t||(s=0),n||(i=this.getLabels().length-1)),this.min=s,this.max=i}buildTicks(){const t=this.min,n=this.max,s=this.options.offset,i=[];let a=this.getLabels();a=t===0&&n===a.length-1?a:a.slice(t,n+1),this._valueRange=Math.max(a.length-(s?0:1),1),this._startValue=this.min-(s?.5:0);for(let o=t;o<=n;o++)i.push({value:o});return i}getLabelForValue(t){return GD.call(this,t)}configure(){super.configure(),this.isHorizontal()||(this._reversePixels=!this._reversePixels)}getPixelForValue(t){return typeof t!="number"&&(t=this.parse(t)),t===null?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getPixelForTick(t){const n=this.ticks;return t<0||t>n.length-1?null:this.getPixelForValue(n[t].value)}getValueForPixel(t){return Math.round(this._startValue+this.getDecimalForPixel(t)*this._valueRange)}getBasePixel(){return this.bottom}}function TNe(e,t){const n=[],{bounds:i,step:a,min:o,max:l,precision:c,count:d,maxTicks:f,maxDigits:p,includeBounds:m}=e,g=a||1,b=f-1,{min:_,max:w}=t,A=!Tt(o),S=!Tt(l),C=!Tt(d),E=(w-_)/(p+1);let k=UR((w-_)/b/g)*g,T,F,M,I;if(k<1e-14&&!A&&!S)return[{value:_},{value:w}];I=Math.ceil(w/k)-Math.floor(_/k),I>b&&(k=UR(I*k/b/g)*g),Tt(c)||(T=Math.pow(10,c),k=Math.ceil(k*T)/T),i==="ticks"?(F=Math.floor(_/k)*k,M=Math.ceil(w/k)*k):(F=_,M=w),A&&S&&a&&NSe((l-o)/a,k/1e3)?(I=Math.round(Math.min((l-o)/k,f)),k=(l-o)/I,F=o,M=l):C?(F=A?o:F,M=S?l:M,I=d-1,k=(M-F)/I):(I=(M-F)/k,gp(I,Math.round(I),k/1e3)?I=Math.round(I):I=Math.ceil(I));const R=Math.max(HR(k),HR(F));T=Math.pow(10,Tt(c)?R:c),F=Math.round(F*T)/T,M=Math.round(M*T)/T;let H=0;for(A&&(m&&F!==o?(n.push({value:o}),F<o&&H++,gp(Math.round((F+H*k)*T)/T,o,KD(o,E,e))&&H++):F<o&&H++);H<I;++H){const V=Math.round((F+H*k)*T)/T;if(S&&V>l)break;n.push({value:V})}return S&&m&&M!==l?n.length&&gp(n[n.length-1].value,l,KD(l,E,e))?n[n.length-1].value=l:n.push({value:l}):(!S||M===l)&&n.push({value:M}),n}function KD(e,t,{horizontal:n,minRotation:s}){const i=Ao(s),a=(n?Math.sin(i):Math.cos(i))||.001,o=.75*t*(""+e).length;return Math.min(t/a,o)}class MNe extends Ah{constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(t,n){return Tt(t)||(typeof t=="number"||t instanceof Number)&&!isFinite(+t)?null:+t}handleTickRangeOptions(){const{beginAtZero:t}=this.options,{minDefined:n,maxDefined:s}=this.getUserBounds();let{min:i,max:a}=this;const o=c=>i=n?i:c,l=c=>a=s?a:c;if(t){const c=za(i),d=za(a);c<0&&d<0?l(0):c>0&&d>0&&o(0)}if(i===a){let c=a===0?1:Math.abs(a*.05);l(a+c),t||o(i-c)}this.min=i,this.max=a}getTickLimit(){const t=this.options.ticks;let{maxTicksLimit:n,stepSize:s}=t,i;return s?(i=Math.ceil(this.max/s)-Math.floor(this.min/s)+1,i>1e3&&(console.warn(`scales.${this.id}.ticks.stepSize: ${s} would result generating up to ${i} ticks. Limiting to 1000.`),i=1e3)):(i=this.computeTickLimit(),n=n||11),n&&(i=Math.min(n,i)),i}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){const t=this.options,n=t.ticks;let s=this.getTickLimit();s=Math.max(2,s);const i={maxTicks:s,bounds:t.bounds,min:t.min,max:t.max,precision:n.precision,step:n.stepSize,count:n.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:n.minRotation||0,includeBounds:n.includeBounds!==!1},a=this._range||this,o=TNe(i,a);return t.bounds==="ticks"&&kSe(o,this,"value"),t.reverse?(o.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),o}configure(){const t=this.ticks;let n=this.min,s=this.max;if(super.configure(),this.options.offset&&t.length){const i=(s-n)/Math.max(t.length-1,1)/2;n-=i,s+=i}this._startValue=n,this._endValue=s,this._valueRange=s-n}getLabelForValue(t){return hN(t,this.chart.options.locale,this.options.ticks.format)}}class RNe extends MNe{static id="linear";static defaults={ticks:{callback:$V.formatters.numeric}};determineDataLimits(){const{min:t,max:n}=this.getMinMax(!0);this.min=Js(t)?t:0,this.max=Js(n)?n:1,this.handleTickRangeOptions()}computeTickLimit(){const t=this.isHorizontal(),n=t?this.width:this.height,s=Ao(this.options.ticks.minRotation),i=(t?Math.sin(s):Math.cos(s))||.001,a=this._resolveTickFontOptions(0);return Math.ceil(n/Math.min(40,a.lineHeight/i))}getPixelForValue(t){return t===null?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getValueForPixel(t){return this._startValue+this.getDecimalForPixel(t)*this._valueRange}}const my={millisecond:{common:!0,size:1,steps:1e3},second:{common:!0,size:1e3,steps:60},minute:{common:!0,size:6e4,steps:60},hour:{common:!0,size:36e5,steps:24},day:{common:!0,size:864e5,steps:30},week:{common:!1,size:6048e5,steps:4},month:{common:!0,size:2628e6,steps:12},quarter:{common:!1,size:7884e6,steps:4},year:{common:!0,size:3154e7}},Ci=Object.keys(my);function YD(e,t){return e-t}function QD(e,t){if(Tt(t))return null;const n=e._adapter,{parser:s,round:i,isoWeekday:a}=e._parseOpts;let o=t;return typeof s=="function"&&(o=s(o)),Js(o)||(o=typeof s=="string"?n.parse(o,s):n.parse(o)),o===null?null:(i&&(o=i==="week"&&(Qd(a)||a===!0)?n.startOf(o,"isoWeek",a):n.startOf(o,i)),+o)}function XD(e,t,n,s){const i=Ci.length;for(let a=Ci.indexOf(e);a<i-1;++a){const o=my[Ci[a]],l=o.steps?o.steps:Number.MAX_SAFE_INTEGER;if(o.common&&Math.ceil((n-t)/(l*o.size))<=s)return Ci[a]}return Ci[i-1]}function DNe(e,t,n,s,i){for(let a=Ci.length-1;a>=Ci.indexOf(n);a--){const o=Ci[a];if(my[o].common&&e._adapter.diff(i,s,o)>=t-1)return o}return Ci[n?Ci.indexOf(n):0]}function ONe(e){for(let t=Ci.indexOf(e)+1,n=Ci.length;t<n;++t)if(my[Ci[t]].common)return Ci[t]}function JD(e,t,n){if(!n)e[t]=!0;else if(n.length){const{lo:s,hi:i}=cN(n,t),a=n[s]>=t?n[s]:n[i];e[a]=!0}}function PNe(e,t,n,s){const i=e._adapter,a=+i.startOf(t[0].value,s),o=t[t.length-1].value;let l,c;for(l=a;l<=o;l=+i.add(l,1,s))c=n[l],c>=0&&(t[c].major=!0);return t}function ZD(e,t,n){const s=[],i={},a=t.length;let o,l;for(o=0;o<a;++o)l=t[o],i[l]=o,s.push({value:l,major:!1});return a===0||!n?s:PNe(e,s,i,n)}class e8 extends Ah{static id="time";static defaults={bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}};constructor(t){super(t),this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(t,n={}){const s=t.time||(t.time={}),i=this._adapter=new f5e._date(t.adapters.date);i.init(n),xp(s.displayFormats,i.formats()),this._parseOpts={parser:s.parser,round:s.round,isoWeekday:s.isoWeekday},super.init(t),this._normalized=n.normalized}parse(t,n){return t===void 0?null:QD(this,t)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){const t=this.options,n=this._adapter,s=t.time.unit||"day";let{min:i,max:a,minDefined:o,maxDefined:l}=this.getUserBounds();function c(d){!o&&!isNaN(d.min)&&(i=Math.min(i,d.min)),!l&&!isNaN(d.max)&&(a=Math.max(a,d.max))}(!o||!l)&&(c(this._getLabelBounds()),(t.bounds!=="ticks"||t.ticks.source!=="labels")&&c(this.getMinMax(!1))),i=Js(i)&&!isNaN(i)?i:+n.startOf(Date.now(),s),a=Js(a)&&!isNaN(a)?a:+n.endOf(Date.now(),s)+1,this.min=Math.min(i,a-1),this.max=Math.max(i+1,a)}_getLabelBounds(){const t=this.getLabelTimestamps();let n=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;return t.length&&(n=t[0],s=t[t.length-1]),{min:n,max:s}}buildTicks(){const t=this.options,n=t.time,s=t.ticks,i=s.source==="labels"?this.getLabelTimestamps():this._generate();t.bounds==="ticks"&&i.length&&(this.min=this._userMin||i[0],this.max=this._userMax||i[i.length-1]);const a=this.min,o=this.max,l=RSe(i,a,o);return this._unit=n.unit||(s.autoSkip?XD(n.minUnit,this.min,this.max,this._getLabelCapacity(a)):DNe(this,l.length,n.minUnit,this.min,this.max)),this._majorUnit=!s.major.enabled||this._unit==="year"?void 0:ONe(this._unit),this.initOffsets(i),t.reverse&&l.reverse(),ZD(this,l,this._majorUnit)}afterAutoSkip(){this.options.offsetAfterAutoskip&&this.initOffsets(this.ticks.map(t=>+t.value))}initOffsets(t=[]){let n=0,s=0,i,a;this.options.offset&&t.length&&(i=this.getDecimalForValue(t[0]),t.length===1?n=1-i:n=(this.getDecimalForValue(t[1])-i)/2,a=this.getDecimalForValue(t[t.length-1]),t.length===1?s=a:s=(a-this.getDecimalForValue(t[t.length-2]))/2);const o=t.length<3?.5:.25;n=Ws(n,0,o),s=Ws(s,0,o),this._offsets={start:n,end:s,factor:1/(n+1+s)}}_generate(){const t=this._adapter,n=this.min,s=this.max,i=this.options,a=i.time,o=a.unit||XD(a.minUnit,n,s,this._getLabelCapacity(n)),l=it(i.ticks.stepSize,1),c=o==="week"?a.isoWeekday:!1,d=Qd(c)||c===!0,f={};let p=n,m,g;if(d&&(p=+t.startOf(p,"isoWeek",c)),p=+t.startOf(p,d?"day":o),t.diff(s,n,o)>1e5*l)throw new Error(n+" and "+s+" are too far apart with stepSize of "+l+" "+o);const b=i.ticks.source==="data"&&this.getDataTimestamps();for(m=p,g=0;m<s;m=+t.add(m,l,o),g++)JD(f,m,b);return(m===s||i.bounds==="ticks"||g===1)&&JD(f,m,b),Object.keys(f).sort(YD).map(_=>+_)}getLabelForValue(t){const n=this._adapter,s=this.options.time;return s.tooltipFormat?n.format(t,s.tooltipFormat):n.format(t,s.displayFormats.datetime)}format(t,n){const i=this.options.time.displayFormats,a=this._unit,o=n||i[a];return this._adapter.format(t,o)}_tickFormatFunction(t,n,s,i){const a=this.options,o=a.ticks.callback;if(o)return rn(o,[t,n,s],this);const l=a.time.displayFormats,c=this._unit,d=this._majorUnit,f=c&&l[c],p=d&&l[d],m=s[n],g=d&&p&&m&&m.major;return this._adapter.format(t,i||(g?p:f))}generateTickLabels(t){let n,s,i;for(n=0,s=t.length;n<s;++n)i=t[n],i.label=this._tickFormatFunction(i.value,n,t)}getDecimalForValue(t){return t===null?NaN:(t-this.min)/(this.max-this.min)}getPixelForValue(t){const n=this._offsets,s=this.getDecimalForValue(t);return this.getPixelForDecimal((n.start+s)*n.factor)}getValueForPixel(t){const n=this._offsets,s=this.getDecimalForPixel(t)/n.factor-n.end;return this.min+s*(this.max-this.min)}_getLabelSize(t){const n=this.options.ticks,s=this.ctx.measureText(t).width,i=Ao(this.isHorizontal()?n.maxRotation:n.minRotation),a=Math.cos(i),o=Math.sin(i),l=this._resolveTickFontOptions(0).size;return{w:s*a+l*o,h:s*o+l*a}}_getLabelCapacity(t){const n=this.options.time,s=n.displayFormats,i=s[n.unit]||s.millisecond,a=this._tickFormatFunction(t,0,ZD(this,[t],this._majorUnit),i),o=this._getLabelSize(a),l=Math.floor(this.isHorizontal()?this.width/o.w:this.height/o.h)-1;return l>0?l:1}getDataTimestamps(){let t=this._cache.data||[],n,s;if(t.length)return t;const i=this.getMatchingVisibleMetas();if(this._normalized&&i.length)return this._cache.data=i[0].controller.getAllParsedValues(this);for(n=0,s=i.length;n<s;++n)t=t.concat(i[n].controller.getAllParsedValues(this));return this._cache.data=this.normalize(t)}getLabelTimestamps(){const t=this._cache.labels||[];let n,s;if(t.length)return t;const i=this.getLabels();for(n=0,s=i.length;n<s;++n)t.push(QD(this,i[n]));return this._cache.labels=this._normalized?t:this.normalize(t)}normalize(t){return PV(t.sort(YD))}}function tb(e,t,n){let s=0,i=e.length-1,a,o,l,c;n?(t>=e[s].pos&&t<=e[i].pos&&({lo:s,hi:i}=Gc(e,"pos",t)),{pos:a,time:l}=e[s],{pos:o,time:c}=e[i]):(t>=e[s].time&&t<=e[i].time&&({lo:s,hi:i}=Gc(e,"time",t)),{time:a,pos:l}=e[s],{time:o,pos:c}=e[i]);const d=o-a;return d?l+(c-l)*(t-a)/d:l}class Q8e extends e8{static id="timeseries";static defaults=e8.defaults;constructor(t){super(t),this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){const t=this._getTimestampsForTable(),n=this._table=this.buildLookupTable(t);this._minPos=tb(n,this.min),this._tableRange=tb(n,this.max)-this._minPos,super.initOffsets(t)}buildLookupTable(t){const{min:n,max:s}=this,i=[],a=[];let o,l,c,d,f;for(o=0,l=t.length;o<l;++o)d=t[o],d>=n&&d<=s&&i.push(d);if(i.length<2)return[{time:n,pos:0},{time:s,pos:1}];for(o=0,l=i.length;o<l;++o)f=i[o+1],c=i[o-1],d=i[o],Math.round((f+c)/2)!==d&&a.push({time:d,pos:o/(l-1)});return a}_generate(){const t=this.min,n=this.max;let s=super.getDataTimestamps();return(!s.includes(t)||!s.length)&&s.splice(0,0,t),(!s.includes(n)||s.length===1)&&s.push(n),s.sort((i,a)=>i-a)}_getTimestampsForTable(){let t=this._cache.all||[];if(t.length)return t;const n=this.getDataTimestamps(),s=this.getLabelTimestamps();return n.length&&s.length?t=this.normalize(n.concat(s)):t=n.length?n:s,t=this._cache.all=t,t}getDecimalForValue(t){return(tb(this._table,t)-this._minPos)/this._tableRange}getValueForPixel(t){const n=this._offsets,s=this.getDecimalForPixel(t)/n.factor-n.end;return tb(this._table,s*this._tableRange+this._minPos,!0)}}const _U="label";function t8(e,t){typeof e=="function"?e(t):e&&(e.current=t)}function INe(e,t){const n=e.options;n&&t&&Object.assign(n,t)}function wU(e,t){e.labels=t}function AU(e,t,n=_U){const s=[];e.datasets=t.map(i=>{const a=e.datasets.find(o=>o[n]===i[n]);return!a||!i.data||s.includes(a)?{...i}:(s.push(a),Object.assign(a,i),a)})}function LNe(e,t=_U){const n={labels:[],datasets:[]};return wU(n,e.labels),AU(n,e.datasets,t),n}function BNe(e,t){const{height:n=150,width:s=300,redraw:i=!1,datasetIdKey:a,type:o,data:l,options:c,plugins:d=[],fallbackContent:f,updateMode:p,...m}=e,g=y.useRef(null),b=y.useRef(null),_=()=>{g.current&&(b.current=new hy(g.current,{type:o,data:LNe(l,a),options:c&&{...c},plugins:d}),t8(t,b.current))},w=()=>{t8(t,null),b.current&&(b.current.destroy(),b.current=null)};return y.useEffect(()=>{!i&&b.current&&c&&INe(b.current,c)},[i,c]),y.useEffect(()=>{!i&&b.current&&wU(b.current.config.data,l.labels)},[i,l.labels]),y.useEffect(()=>{!i&&b.current&&l.datasets&&AU(b.current.config.data,l.datasets,a)},[i,l.datasets]),y.useEffect(()=>{b.current&&(i?(w(),setTimeout(_)):b.current.update(p))},[i,c,l.labels,l.datasets,p]),y.useEffect(()=>{b.current&&(w(),setTimeout(_))},[o]),y.useEffect(()=>(_(),()=>w()),[]),r.jsx("canvas",{ref:g,role:"img",height:n,width:s,...m,children:f})}const zNe=y.forwardRef(BNe);function xy(e,t){return hy.register(t),y.forwardRef((n,s)=>r.jsx(zNe,{...n,ref:s,type:e}))}const $Ne=xy("line",u5e),n8=xy("bar",o5e),VNe=xy("pie",d5e),UNe=xy("scatter",h5e);hy.register(FNe,RNe,Lje,fy,Hje,kje,bNe,jNe,xNe,uNe);const $f=["#6366F1","#8B5CF6","#EC4899","#10B981","#F59E0B","#EF4444","#3B82F6","#14B8A6","#F97316","#84CC16"];function HNe({data:e}){const t=y.useMemo(()=>({labels:e.labels,datasets:e.datasets.map((i,a)=>({...i,backgroundColor:i.backgroundColor??(e.type==="pie"?$f.slice(0,e.labels.length):`${$f[a%$f.length]}88`),borderColor:i.borderColor??$f[a%$f.length],borderWidth:e.type==="pie"?0:2,pointRadius:e.type==="scatter"?4:3,tension:.3}))}),[e]),n=y.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,plugins:{title:e.title?{display:!0,text:e.title,color:"#F0F0F5",font:{size:12,weight:500},padding:{bottom:12}}:{display:!1},legend:{display:e.datasets.length>1||e.type==="pie",position:"bottom",labels:{color:"#8A8A99",font:{size:10},boxWidth:10,padding:8}},tooltip:{backgroundColor:"#1C1C21",titleColor:"#F0F0F5",bodyColor:"#C8C8D4",borderColor:"#2A2A35",borderWidth:1,titleFont:{size:11},bodyFont:{size:10},padding:8}},scales:e.type==="pie"?{}:{x:{ticks:{color:"#5A5A6E",font:{size:10}},grid:{color:"#2A2A35",drawBorder:!1}},y:{ticks:{color:"#5A5A6E",font:{size:10}},grid:{color:"#2A2A35",drawBorder:!1}}}}),[e]),s={bar:n8,line:$Ne,pie:VNe,scatter:UNe}[e.type]??n8;return r.jsx("div",{className:"p-4",style:{height:e.type==="pie"?320:280},children:r.jsx(s,{data:t,options:n})})}function WNe({data:e,onChange:t}){const[n,s]=y.useState(null),[i,a]=y.useState(!0),[o,l]=y.useState(""),[c,d]=y.useState(null),[f,p]=y.useState(""),m=y.useCallback(A=>{n===A?a(S=>!S):(s(A),a(!0))},[n]),g=y.useMemo(()=>{if(!o.trim())return e.rows;const A=o.toLowerCase();return e.rows.filter(S=>e.columns.some(C=>String(S[C.key]??"").toLowerCase().includes(A)))},[e.rows,e.columns,o]),b=y.useMemo(()=>{if(!n)return g;const A=e.columns.find(S=>S.key===n);return[...g].sort((S,C)=>{const E=S[n]??"",k=C[n]??"";return A?.type==="number"||typeof E=="number"&&typeof k=="number"?i?Number(E)-Number(k):Number(k)-Number(E):i?String(E).localeCompare(String(k)):String(k).localeCompare(String(E))})},[g,n,i,e.columns]),_=y.useCallback((A,S,C)=>{d({row:A,key:S}),p(String(C??""))},[]),w=y.useCallback(()=>{if(!c)return;if(!e.rows[c.row]){d(null);return}const S=e.columns.find(k=>k.key===c.key);let C=f;S?.type==="number"&&(C=Number(f)||0);const E=e.rows.map((k,T)=>T===c.row?{...k,[c.key]:C}:k);t({...e,rows:E}),d(null)},[c,f,e,t]);return r.jsxs("div",{className:"flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-[#2A2A35]",children:[e.title&&r.jsx("span",{className:"text-[11px] font-semibold text-[#F0F0F5] mr-2",children:e.title}),r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded bg-[#1C1C21] border border-[#2A2A35] flex-1 max-w-[200px]",children:[r.jsx(Io,{className:"w-3 h-3 text-[#5A5A6E]"}),r.jsx("input",{value:o,onChange:A=>l(A.target.value),placeholder:"Filter...",className:"flex-1 bg-transparent text-[11px] text-[#C8C8D4] placeholder-[#5A5A6E] outline-none"})]}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E] ml-auto",children:[b.length," / ",e.rows.length]})]}),r.jsxs("div",{className:"overflow-auto max-h-[500px]",children:[r.jsxs("table",{className:"w-full text-[11px]",children:[r.jsx("thead",{className:"sticky top-0 bg-[#16161A] z-10",children:r.jsx("tr",{className:"border-b border-[#2A2A35]",children:e.columns.map(A=>r.jsx("th",{onClick:()=>m(A.key),className:"px-3 py-2 text-left text-[#8A8A99] font-medium cursor-pointer hover:text-[#C8C8D4] transition-colors whitespace-nowrap select-none",children:r.jsxs("span",{className:"inline-flex items-center gap-1",children:[A.label,n===A.key?i?r.jsx(vse,{className:"w-3 h-3 text-[#6366F1]"}):r.jsx(fse,{className:"w-3 h-3 text-[#6366F1]"}):r.jsx(gse,{className:"w-3 h-3 opacity-30"})]})},A.key))})}),r.jsx("tbody",{children:b.map((A,S)=>{const C=e.rows.indexOf(A);return r.jsx("tr",{className:"border-b border-[#2A2A35]/50 hover:bg-white/[0.02]",children:e.columns.map(E=>{const k=c?.row===C&&c?.key===E.key;return r.jsx("td",{className:"px-3 py-1.5 text-[#C8C8D4]",children:k?r.jsx("input",{value:f,onChange:T=>p(T.target.value),onBlur:w,onKeyDown:T=>{T.key==="Enter"&&w(),T.key==="Escape"&&d(null)},className:"w-full bg-[#1C1C21] text-[11px] text-[#F0F0F5] rounded px-1 py-0.5 outline-none border border-[#6366F1]/30",autoFocus:!0}):r.jsx("span",{onDoubleClick:()=>_(C,E.key,A[E.key]),className:"cursor-default",children:String(A[E.key]??"")})},E.key)})},S)})})]}),b.length===0&&r.jsx("p",{className:"px-4 py-6 text-center text-[11px] text-[#5A5A6E] italic",children:o?"No matching rows.":"No data."})]})]})}const s8=[{bg:"bg-[#6366F1]/10",text:"text-[#818CF8]"},{bg:"bg-[#10B981]/10",text:"text-[#34D399]"},{bg:"bg-[#EC4899]/10",text:"text-[#F472B6]"},{bg:"bg-[#F59E0B]/10",text:"text-[#FBBF24]"},{bg:"bg-[#EF4444]/10",text:"text-[#F87171]"},{bg:"bg-[#3B82F6]/10",text:"text-[#60A5FA]"}];function qNe(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return s8[Math.abs(t)%s8.length]}function GNe({card:e,onEdit:t,onRemove:n}){const[s,i]=y.useState(!1),[a,o]=y.useState(e.title),[l,c]=y.useState(e.description??""),d=y.useCallback(()=>{a.trim()&&t(e.id,a.trim(),l.trim()),i(!1)},[e.id,a,l,t]);return s?r.jsxs("div",{className:"bg-[#16161A] rounded-lg border border-[#6366F1]/30 p-3",children:[r.jsx("input",{value:a,onChange:f=>o(f.target.value),onKeyDown:f=>f.key==="Enter"&&d(),className:"w-full bg-transparent text-[12px] text-[#F0F0F5] outline-none font-medium mb-1.5",autoFocus:!0}),r.jsx("textarea",{value:l,onChange:f=>c(f.target.value),rows:3,className:"w-full bg-transparent text-[11px] text-[#8A8A99] outline-none resize-none",placeholder:"Description..."}),r.jsxs("div",{className:"flex justify-end gap-1 mt-2",children:[r.jsx("button",{onClick:()=>i(!1),className:"p-1 text-[#5A5A6E] hover:text-[#C8C8D4]",children:r.jsx(Te,{className:"w-3 h-3"})}),r.jsx("button",{onClick:d,className:"p-1 text-[#10B981] hover:text-[#34D399]",children:r.jsx(Fe,{className:"w-3 h-3"})})]})]}):r.jsxs("div",{className:"bg-[#16161A] rounded-lg border border-[#2A2A35] hover:border-[#3A3A45] transition-colors group",children:[e.image&&r.jsx("div",{className:"aspect-video overflow-hidden rounded-t-lg",children:r.jsx("img",{src:e.image,alt:"",className:"w-full h-full object-cover"})}),r.jsxs("div",{className:"p-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsx("h4",{className:"text-[12px] font-medium text-[#F0F0F5] leading-snug",children:e.title}),r.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:[e.url&&r.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"p-0.5 text-[#5A5A6E] hover:text-[#6366F1]",children:r.jsx(cs,{className:"w-2.5 h-2.5"})}),r.jsx("button",{onClick:()=>i(!0),className:"p-0.5 text-[#5A5A6E] hover:text-[#C8C8D4]",children:r.jsx(oh,{className:"w-2.5 h-2.5"})}),r.jsx("button",{onClick:()=>n(e.id),className:"p-0.5 text-[#5A5A6E] hover:text-[#EF4444]",children:r.jsx(Te,{className:"w-2.5 h-2.5"})})]})]}),e.description&&r.jsx("p",{className:"text-[11px] text-[#8A8A99] mt-1 leading-snug line-clamp-3",children:e.description}),e.tags&&e.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:e.tags.map(f=>{const p=qNe(f);return r.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-medium ${p.bg} ${p.text}`,children:f},f)})}),e.meta&&Object.keys(e.meta).length>0&&r.jsx("div",{className:"mt-2 pt-2 border-t border-[#2A2A35]/50 space-y-0.5",children:Object.entries(e.meta).map(([f,p])=>r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px]",children:[r.jsxs("span",{className:"text-[#5A5A6E]",children:[f,":"]}),r.jsx("span",{className:"text-[#C8C8D4]",children:p})]},f))})]})]})}function KNe({data:e,onChange:t}){const n=e.columns??3,s=y.useCallback((a,o,l)=>{const c=e.cards.map(d=>d.id===a?{...d,title:o,description:l}:d);t({...e,cards:c})},[e,t]),i=y.useCallback(a=>{t({...e,cards:e.cards.filter(o=>o.id!==a)})},[e,t]);return r.jsxs("div",{className:"p-3",children:[e.title&&r.jsx("h3",{className:"text-[12px] font-semibold text-[#F0F0F5] mb-3",children:e.title}),r.jsx("div",{className:"grid gap-2",style:{gridTemplateColumns:`repeat(${Math.min(n,4)}, minmax(0, 1fr))`},children:e.cards.map(a=>r.jsx(GNe,{card:a,onEdit:s,onRemove:i},a.id))}),e.cards.length===0&&r.jsx("p",{className:"text-center py-8 text-[11px] text-[#5A5A6E] italic",children:"No cards"})]})}function SU(e){return e.endsWith(".kanban.json")?"kanban":e.endsWith(".chart.json")?"chart":e.endsWith(".table.json")?"table":e.endsWith(".board.json")?"board":null}function CU(e){return SU(e)!==null}function YNe(e,t){if(!t||typeof t!="object")return!1;switch(e){case"kanban":return Array.isArray(t.columns);case"chart":return typeof t.type=="string"&&Array.isArray(t.labels)&&Array.isArray(t.datasets);case"table":return Array.isArray(t.columns)&&Array.isArray(t.rows);case"board":return Array.isArray(t.cards);default:return!1}}function jU({agentId:e,filePath:t,content:n}){const s=SU(t),i=L.files.writeStructured.useMutation(),a=y.useRef(void 0),o=y.useMemo(()=>{try{return JSON.parse(n)}catch{return null}},[n]),[l,c]=y.useState(o),[d,f]=y.useState(!1);y.useEffect(()=>{c(o),f(!1)},[o]);const p=y.useCallback(m=>{c(m),f(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{const g=JSON.stringify(m,null,2);i.mutate({agentId:e,filePath:t,content:g}),f(!1)},800)},[e,t,i]);return y.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]),!s||!l||!YNe(s,l)?null:r.jsxs("div",{className:"relative",children:[d&&r.jsx("div",{className:"absolute top-2 right-3 z-10",children:r.jsx("span",{className:"text-[9px] text-[#F59E0B] bg-[#F59E0B]/10 px-1.5 py-0.5 rounded",children:"Saving..."})}),s==="kanban"&&r.jsx(G2e,{data:l,onChange:p}),s==="chart"&&r.jsx(HNe,{data:l}),s==="table"&&r.jsx(WNe,{data:l,onChange:p}),s==="board"&&r.jsx(KNe,{data:l,onChange:p})]})}const QNe={kanban:"Kanban Board",chart:"Chart",table:"Data Table",board:"Card Grid"};function XNe(e){for(const[t,n]of Object.entries(QNe))if(e.endsWith(`.${t}.json`))return n;return"Structured File"}function yN({agentId:e,filePath:t,onClose:n}){const s=t.split("/").pop()??t,i=XNe(s),{data:a,isLoading:o}=L.files.read.useQuery({agentId:e,filePath:t},{retry:!1});return r.jsx(ji,{open:!0,onOpenChange:l=>{l||n()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-40"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[90vw] max-w-[1100px] max-h-[85vh] bg-[#13131A] border border-[#2A2A35] rounded-xl shadow-2xl z-50 flex flex-col",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(nr,{className:"text-[13px] font-semibold text-[#F0F0F5] truncate",children:s}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] bg-white/[0.04] px-1.5 py-0.5 rounded flex-shrink-0",children:i})]}),r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})})]}),r.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[o&&r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]})}),!o&&a?.content&&r.jsx(jU,{agentId:e,filePath:t,content:a.content}),!o&&!a?.content&&r.jsx("p",{className:"text-center py-12 text-[12px] text-[#5A5A6E]",children:"Unable to load file."})]})]})]})})}const JNe=/\.(kanban|chart|table|board)\.json$/;function ZNe(e){const t=e.match(JNe);return t?t[1]:null}const eke={kanban:nL,chart:M5,table:wL,board:ym},tke={kanban:"#6366F1",chart:"#10B981",table:"#3B82F6",board:"#8B5CF6"};function nke(e,t){try{const n=JSON.parse(t);switch(e){case"kanban":{const s=Array.isArray(n.columns)?n.columns.length:0,i=Array.isArray(n.columns)?n.columns.reduce((a,o)=>a+(Array.isArray(o.cards)?o.cards.length:0),0):0;return`${s} columns, ${i} cards`}case"chart":{const s=n.type??"unknown",i=Array.isArray(n.labels)?n.labels.length:0;return`${s} chart — ${i} data points`}case"table":{const s=Array.isArray(n.rows)?n.rows.length:0,i=Array.isArray(n.columns)?n.columns.length:0;return`${s} rows × ${i} columns`}case"board":return`${Array.isArray(n.cards)?n.cards.length:0} cards`}}catch{return"structured file"}}function ske({agentId:e,filePath:t,filename:n,content:s}){const[i,a]=y.useState(!1),o=ZNe(n);if(!o)return null;const l=eke[o],c=tke[o],d=s?nke(o,s):null;return r.jsxs(r.Fragment,{children:[r.jsxs(ne.button,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2},onClick:()=>a(!0),className:"flex items-center gap-2.5 px-3 py-2 rounded-lg border transition-colors duration-100 hover:brightness-110 w-fit max-w-[380px] group",style:{backgroundColor:`${c}08`,borderColor:`${c}25`},children:[r.jsx("div",{className:"w-7 h-7 rounded-md flex items-center justify-center flex-shrink-0",style:{backgroundColor:`${c}18`},children:r.jsx(l,{className:"w-3.5 h-3.5",style:{color:c}})}),r.jsxs("div",{className:"flex flex-col items-start min-w-0",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5] truncate max-w-[280px]",children:n}),d&&r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:d})]})]}),i&&r.jsx(yN,{agentId:e,filePath:t,onClose:()=>a(!1)})]})}const NU=$o(e=>({cardsByChannel:{},addCard:(t,n)=>e(s=>{const i=s.cardsByChannel[t]??[],a=`${n.agentId}:${n.filePath}`,o=i.filter(l=>`${l.agentId}:${l.filePath}`!==a);return{cardsByChannel:{...s.cardsByChannel,[t]:[...o,n]}}}),dismissCard:(t,n)=>e(s=>{const i=s.cardsByChannel[t];return i?{cardsByChannel:{...s.cardsByChannel,[t]:i.filter(a=>a.id!==n)}}:s})}));function ike({channelId:e,agentForChannel:t,agentColor:n,messages:s=[],isThinking:i,isLoading:a,loadMore:o,firstUnreadId:l}){const{data:c=[]}=Vo(),d=y.useRef(null),f=y.useRef(null),[p,m]=y.useState(!1),[g,b]=y.useState(!0),_=y.useRef(0),w=L.readReceipts.markRead.useMutation(),A=Je(R=>R.setUnreadCount),S=y.useRef(!1),C=Je(R=>R.fileEditApprovalsByChannel[e])??[],E=Je(R=>R.removeFileEditApproval),k=NU(R=>R.cardsByChannel[e])??[],{data:T}=L.fileEditApprovals.list.useQuery({channelId:e},{staleTime:3e4});y.useEffect(()=>{if(!T)return;const R=Je.getState().addFileEditApproval;for(const H of T)R(H)},[T]),y.useEffect(()=>{d.current?.scrollIntoView({behavior:"instant"})},[e]);const F=s.length>0?s[s.length-1]?.id:null;y.useEffect(()=>{d.current?.scrollIntoView({behavior:"smooth"})},[F]),y.useEffect(()=>{if(l&&!S.current){const R=document.getElementById(`msg-${l}`);R&&(R.scrollIntoView({behavior:"smooth",block:"start"}),S.current=!0)}},[l,s]),y.useEffect(()=>{S.current=!1},[e]),y.useEffect(()=>{s.length!==0&&(w.mutate({channelId:e}),A(e,0))},[e,s.length]);const M=y.useCallback(async()=>{const R=f.current;if(!(!R||!o||p||!g)&&R.scrollTop<100){m(!0),_.current=R.scrollHeight;const H=await o();b(H??!1),m(!1),requestAnimationFrame(()=>{const V=R.scrollHeight;R.scrollTop=V-_.current})}},[o,p,g]),I=i&&t?[{...t,status:"thinking"}]:t?[t].filter(R=>R.status==="thinking"||R.status==="executing"):c.filter(R=>s.some(V=>V.sender.id===R.id)&&(R.status==="thinking"||R.status==="executing"));return a?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsxs("div",{className:"flex items-center gap-2 text-[#8A8A99]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.4s]"})]})}):r.jsxs("div",{ref:f,onScroll:M,className:"flex-1 overflow-y-auto overflow-x-hidden py-2 scrollbar-agent",style:n?{"--agent-color":n}:void 0,"data-channel":e,children:[p&&r.jsx("div",{className:"flex justify-center py-3",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99]",children:[r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse"}),r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.15s]"}),r.jsx("div",{className:"w-1 h-1 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.3s]"})]})}),r.jsx(Me,{initial:!1,children:s.map(R=>{if(R.sender.type==="context_reset"){const V=R.content.startsWith("compacted:");return r.jsxs("div",{id:`msg-${R.id}`,className:"flex items-center gap-3 py-2 px-4",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:V?"earlier messages summarized":"new context"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]},R.id)}const H=R.id===l;return r.jsxs("div",{id:`msg-${R.id}`,children:[H&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"flex items-center gap-3 px-4 py-1 my-1",children:[r.jsx("div",{className:"flex-1 h-px bg-[#6366F1]/40"}),r.jsx("span",{className:"text-[11px] text-[#6366F1] font-medium shrink-0",children:"New messages"}),r.jsx("div",{className:"flex-1 h-px bg-[#6366F1]/40"})]}),r.jsx(Z7,{message:R,agentColor:n})]},R.id)})}),I.map(R=>r.jsx(U7,{agent:R},`thinking-${R.id}`)),C.length>0&&r.jsx("div",{className:"px-4 py-2",children:C.map(R=>{const H=c.find(V=>V.id===R.agentId);return r.jsx(tAe,{approval:R,agentName:H?.name??R.agentId,onDecided:V=>E(e,V)},R.id)})}),k.length>0&&r.jsx("div",{className:"px-4 py-2 space-y-1.5",children:k.map(R=>r.jsx(ske,{agentId:R.agentId,filePath:R.filePath,filename:R.filename},R.id))}),r.jsx("div",{ref:d,className:"h-4"})]})}function rke(e){const t=e.split(`
190
190
  `),n=[];let s=0,i=0;for(const a of t)if(!(a.startsWith("===")||a.startsWith("---")||a.startsWith("+++"))&&!a.startsWith("Index:")&&a!=="\"){if(a.startsWith("@@")){const o=a.match(/@@ -(\d+)/);if(o){s=parseInt(o[1],10);const l=a.match(/\+(\d+)/);l&&(i=parseInt(l[1],10))}n.push({type:"header",content:a});continue}a.startsWith("+")?(n.push({type:"add",content:a.slice(1),newLineNo:i}),i++):a.startsWith("-")?(n.push({type:"remove",content:a.slice(1),oldLineNo:s}),s++):a.startsWith(" ")&&(n.push({type:"context",content:a.slice(1),oldLineNo:s,newLineNo:i}),s++,i++)}return n}function ake({id:e,filePath:t,diff:n,newContent:s,reverted:i}){const a=rke(n),o=a.filter(C=>C.type==="add").length,l=a.filter(C=>C.type==="remove").length,c=a.filter(C=>C.type!=="header").length,d=c>50,[f,p]=y.useState(!d),[m,g]=y.useState(!1),b=L.useUtils(),_=L.fileChanges.revert.useMutation({onSuccess:()=>{b.fileChanges.list.invalidate()}}),w=f?a:a.slice(0,50),A=t.split(".").pop()??"";function S(){navigator.clipboard.writeText(s),g(!0),setTimeout(()=>g(!1),2e3)}return r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:"mt-2 rounded-lg overflow-hidden border border-[#2A2A35] bg-[#0D0D0F]",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#1A1A22]",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(li,{className:"w-3.5 h-3.5 text-[#5A5A6E] flex-shrink-0"}),r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4] truncate",children:t}),A&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E] bg-white/5 px-1.5 py-0.5 rounded flex-shrink-0",children:A})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[o>0&&r.jsxs("span",{className:"text-[10px] font-mono text-[#34D399]",children:["+",o]}),l>0&&r.jsxs("span",{className:"text-[10px] font-mono text-[#F87171]",children:["-",l]}),r.jsx("button",{onClick:S,className:"p-1 rounded hover:bg-white/10 transition-colors text-[#5A5A6E] hover:text-[#8A8A99]",title:"Copy new content",children:m?r.jsx(Fe,{className:"w-3 h-3 text-[#34D399]"}):r.jsx(Po,{className:"w-3 h-3"})}),r.jsxs("button",{onClick:()=>_.mutate({fileChangeId:e}),disabled:i||_.isPending||_.isSuccess,className:ye("flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium border transition-colors",i||_.isSuccess?"bg-[#10B981]/10 text-[#34D399] border-[#10B981]/30":"bg-[#EF4444]/10 text-[#F87171] border-[#EF4444]/30 hover:bg-[#EF4444]/20 disabled:opacity-50"),title:"Revert to previous version",children:[r.jsx(lh,{className:"w-3 h-3"}),i||_.isSuccess?"Reverted":_.isPending?"Reverting...":"Revert"]})]})]}),r.jsx("div",{className:"overflow-x-auto max-h-[400px] overflow-y-auto",children:r.jsx("table",{className:"w-full text-[12px] font-mono leading-relaxed",children:r.jsx("tbody",{children:w.map((C,E)=>{if(C.type==="header")return r.jsx("tr",{className:"bg-[#1A1A2E]/50",children:r.jsx("td",{colSpan:3,className:"px-3 py-1 text-[11px] text-[#6366F1]",children:C.content})},E);const k=C.type==="add"?"bg-[#10B981]/8":C.type==="remove"?"bg-[#EF4444]/8":"",T=C.type==="add"?"text-[#34D399]":C.type==="remove"?"text-[#F87171]":"text-[#8A8A99]",F=C.type==="add"?"bg-[#10B981]/15":C.type==="remove"?"bg-[#EF4444]/15":"",M=C.type==="add"?"+":C.type==="remove"?"-":" ";return r.jsxs("tr",{className:k,children:[r.jsx("td",{className:ye("w-[1px] whitespace-nowrap select-none text-right px-2 text-[10px] text-[#5A5A6E] border-r border-[#1A1A22]",F),children:C.oldLineNo??""}),r.jsx("td",{className:ye("w-[1px] whitespace-nowrap select-none text-right px-2 text-[10px] text-[#5A5A6E] border-r border-[#1A1A22]",F),children:C.newLineNo??""}),r.jsxs("td",{className:ye("px-3 whitespace-pre-wrap",T),children:[r.jsx("span",{className:"select-none opacity-50 mr-1",children:M}),C.content]})]},E)})})})}),d&&r.jsx("button",{onClick:()=>p(C=>!C),className:"flex items-center gap-1 w-full px-3 py-1.5 text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] border-t border-[#1A1A22] transition-colors",children:f?r.jsxs(r.Fragment,{children:[r.jsx(ah,{className:"w-3 h-3"})," Show less"]}):r.jsxs(r.Fragment,{children:[r.jsx(ft,{className:"w-3 h-3"})," Show all (",c," lines)"]})})]})}const kU="diff-seen:";function i8(e){try{const t=localStorage.getItem(kU+e);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function oke(e,t){localStorage.setItem(kU+e,JSON.stringify([...t]))}function lke(e){let t=0,n=0;for(const s of e.split(`
191
191
  `))s.startsWith("+++")||s.startsWith("---")||(s.startsWith("+")?t++:s.startsWith("-")&&n++);return{additions:t,deletions:n}}function cke({channelId:e}){const{data:t}=L.fileChanges.list.useQuery({channelId:e},{staleTime:3e4}),[n,s]=y.useState(!0),[i,a]=y.useState(()=>i8(e));y.useEffect(()=>{a(i8(e))},[e]);const o=y.useCallback(()=>{if(n&&t){const p=new Set(i);for(const m of t)p.add(m.id);a(p),oke(e,p)}s(p=>!p)},[n,t,i,e]);if(!t||t.length===0)return null;const l=t.filter(p=>!i.has(p.id)&&!p.reverted),c=l.length>0;let d=0,f=0;if(c)for(const p of l){const m=lke(p.diff);d+=m.additions,f+=m.deletions}return r.jsxs("div",{className:"flex-shrink-0 border-t border-[#2A2A35]",children:[r.jsxs("button",{onClick:o,className:"flex items-center w-full px-4 py-2 text-left hover:bg-white/[0.02] transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n?r.jsx(Jt,{className:"w-3 h-3 text-[#5A5A6E] flex-shrink-0"}):r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E] flex-shrink-0"}),r.jsx(li,{className:"w-3 h-3 text-[#5A5A6E] flex-shrink-0"}),r.jsx("span",{className:"text-[11px] font-medium text-[#8A8A99]",children:"File changes"}),c&&n&&r.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center px-1 rounded-full bg-[#6366F1] text-white text-[10px] font-bold leading-none",children:l.length})]}),c&&n&&r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[d>0&&r.jsxs("span",{className:"text-[10px] font-mono font-medium text-[#34D399]",children:["+",d]}),f>0&&r.jsxs("span",{className:"text-[10px] font-mono font-medium text-[#F87171]",children:["-",f]})]})]}),r.jsx(Me,{initial:!1,children:!n&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15,ease:[.16,1,.3,1]},className:"overflow-hidden",children:r.jsx("div",{className:"px-4 pb-2 space-y-2 max-h-[400px] overflow-y-auto",children:t.map(p=>r.jsx(ake,{id:p.id,filePath:p.filePath,diff:p.diff,newContent:p.newContent,reverted:p.reverted},p.id))})})})]})}function uke({message:e,agentColor:t}){const n=e.sender.type==="agent",s=e.sender.agentColor??t;return r.jsxs("div",{className:"flex items-start gap-3 px-5 py-2 hover:bg-white/[0.02] transition-colors group",children:[r.jsx("div",{className:"flex-shrink-0 mt-0.5",children:n?r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm",style:{backgroundColor:`${s??"#6366F1"}26`},children:e.sender.avatar??"⚡"}):r.jsx("div",{className:"w-7 h-7 rounded-full bg-gradient-to-br from-[#4A4A5E] to-[#2A2A3E] flex items-center justify-center border border-[#3A3A4E]",children:r.jsx("span",{className:"text-[10px] font-semibold text-[#A5A5C5]",children:e.sender.avatar??e.sender.name[0]})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-2 mb-0.5",children:[r.jsx("span",{className:"text-[13px] font-semibold",style:{color:n?s??"#6366F1":"#F0F0F5"},children:e.sender.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:Ir(e.timestamp)})]}),r.jsx("div",{className:"text-[13px] text-[#C8C8D4] leading-relaxed prose-message",children:r.jsx(Ei,{remarkPlugins:[Fi],children:e.content})})]})]})}function dke({parentMessageId:e,agentColor:t,onClose:n}){const[s,i]=y.useState(""),[a,o]=y.useState(!1),l=y.useRef(null),c=Je(w=>w.messagesByChannel),d=Object.values(c).flat().find(w=>w.id===e),{data:f=[],refetch:p}=L.threads.list.useQuery({parentMessageId:e},{enabled:!!e});y.useEffect(()=>{l.current?.scrollIntoView({behavior:"smooth"})},[f.length]);const m=L.threads.send.useMutation({onSuccess:()=>{i(""),p()}});function g(w){w.key==="Enter"&&!w.shiftKey&&(w.preventDefault(),s.trim()&&!m.isPending&&m.mutate({parentMessageId:e,content:s.trim()}))}const b=d?.sender.type==="agent",_=d?.sender.agentColor??t;return r.jsxs(r.Fragment,{children:[r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",style:{backdropFilter:"blur(2px)",backgroundColor:"rgba(0,0,0,0.25)"},onClick:n}),r.jsxs(ne.div,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.28,ease:[.16,1,.3,1]},className:"fixed right-0 top-0 h-screen w-[420px] bg-[#13131A] border-l border-[#2A2A35] flex flex-col z-50 shadow-2xl",children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 border-b border-[#2A2A35] flex-shrink-0",children:[r.jsx("h3",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Thread"}),r.jsx("button",{onClick:n,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto scrollbar-agent",children:[d&&r.jsx("div",{className:"px-5 py-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"flex-shrink-0 mt-0.5",children:b?r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-base",style:{backgroundColor:`${_??"#6366F1"}26`},children:d.sender.avatar??"⚡"}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-[#4A4A5E] to-[#2A2A3E] flex items-center justify-center border border-[#3A3A4E]",children:r.jsx("span",{className:"text-[11px] font-semibold text-[#A5A5C5]",children:d.sender.avatar??d.sender.name[0]})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[r.jsx("span",{className:"text-[13px] font-semibold",style:{color:b?_??"#6366F1":"#F0F0F5"},children:d.sender.name}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:Ir(d.timestamp)})]}),r.jsx("div",{className:"text-[14px] text-[#C8C8D4] leading-relaxed prose-message",children:r.jsx(Ei,{remarkPlugins:[Fi],children:d.content})})]})]})}),r.jsxs("div",{className:"flex items-center gap-3 px-5 py-1.5",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsxs("span",{className:"text-[11px] text-[#8A8A99] font-medium shrink-0",children:[f.length," ",f.length===1?"reply":"replies"]}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),f.length===0?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"No replies yet. Start the thread."})}):f.map(w=>r.jsx(uke,{message:w,agentColor:t},w.id)),r.jsx("div",{ref:l,className:"h-2"})]}),r.jsxs("div",{className:"px-4 pb-4 pt-3 flex-shrink-0 border-t border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-end gap-2 bg-[#1C1C21] border rounded-xl px-3 py-2.5 transition-colors duration-150",style:{borderColor:a&&t?`${t}60`:"#2A2A35",boxShadow:a&&t?`0 0 0 1px ${t}30`:void 0},children:[r.jsx("textarea",{value:s,onChange:w=>i(w.target.value),onKeyDown:g,onFocus:()=>o(!0),onBlur:()=>o(!1),placeholder:"Reply in thread...",rows:1,className:"flex-1 bg-transparent text-[14px] text-[#F0F0F5] placeholder:text-[#8A8A99]/60 resize-none outline-none leading-relaxed max-h-[120px] overflow-y-auto",style:{minHeight:"22px"},onInput:w=>{const A=w.currentTarget;A.style.height="auto",A.style.height=`${Math.min(A.scrollHeight,120)}px`}}),r.jsx("button",{onClick:()=>{s.trim()&&!m.isPending&&m.mutate({parentMessageId:e,content:s.trim()})},disabled:!s.trim()||m.isPending,className:"text-[#8A8A99] hover:text-[#F0F0F5] disabled:opacity-30 transition-colors mb-0.5 flex-shrink-0",children:r.jsx(Ji,{className:"w-4 h-4"})})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]/40 mt-1.5 px-1",children:"Enter to send · Shift+Enter for newline"})]})]})]})}function hke({agent:e,agentColor:t,onClose:n}){const s=t??e.color,{data:i,isLoading:a}=L.agents.getMemory.useQuery({agentId:e.id});return r.jsxs(ne.aside,{initial:{opacity:0,x:16},animate:{opacity:1,x:0},exit:{opacity:0,x:16},transition:{duration:.2},className:"w-[320px] flex-shrink-0 bg-[#16161A] border-l border-[#2A2A35] flex flex-col h-full overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",style:{background:`linear-gradient(135deg, rgba(${uh(s)}, 0.06) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-2.5",children:[r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-base flex-shrink-0",style:{backgroundColor:`${s}26`},children:e.emoji}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:e.name}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:"MEMORY.md"})]})]}),r.jsx("button",{onClick:n,className:"w-6 h-6 flex items-center justify-center rounded text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[a&&r.jsxs("div",{className:"flex items-center gap-2 text-[#8A8A99]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-pulse [animation-delay:0.4s]"})]}),!a&&!i?.content&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No memory file found for this agent."}),!a&&i?.content&&r.jsx("div",{className:"prose-message text-[13px]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:i.content})})]})]})}var gy="Switch",[fke]=Wa(gy),[pke,mke]=fke(gy),EU=y.forwardRef((e,t)=>{const{__scopeSwitch:n,name:s,checked:i,defaultChecked:a,required:o,disabled:l,value:c="on",onCheckedChange:d,form:f,...p}=e,[m,g]=y.useState(null),b=At(t,C=>g(C)),_=y.useRef(!1),w=m?f||!!m.closest("form"):!0,[A,S]=Fo({prop:i,defaultProp:a??!1,onChange:d,caller:gy});return r.jsxs(pke,{scope:n,checked:A,disabled:l,children:[r.jsx(lt.button,{type:"button",role:"switch","aria-checked":A,"aria-required":o,"data-state":RU(A),"data-disabled":l?"":void 0,disabled:l,value:c,...p,ref:b,onClick:Oe(e.onClick,C=>{S(E=>!E),w&&(_.current=C.isPropagationStopped(),_.current||C.stopPropagation())})}),w&&r.jsx(MU,{control:m,bubbles:!_.current,name:s,value:c,checked:A,required:o,disabled:l,form:f,style:{transform:"translateX(-100%)"}})]})});EU.displayName=gy;var FU="SwitchThumb",TU=y.forwardRef((e,t)=>{const{__scopeSwitch:n,...s}=e,i=mke(FU,n);return r.jsx(lt.span,{"data-state":RU(i.checked),"data-disabled":i.disabled?"":void 0,...s,ref:t})});TU.displayName=FU;var xke="SwitchBubbleInput",MU=y.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:s=!0,...i},a)=>{const o=y.useRef(null),l=At(o,a),c=m7(n),d=S9(t);return y.useEffect(()=>{const f=o.current;if(!f)return;const p=window.HTMLInputElement.prototype,g=Object.getOwnPropertyDescriptor(p,"checked").set;if(c!==n&&g){const b=new Event("click",{bubbles:s});g.call(f,n),f.dispatchEvent(b)}},[c,n,s]),r.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...i,tabIndex:-1,ref:l,style:{...i.style,...d,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});MU.displayName=xke;function RU(e){return e?"checked":"unchecked"}var Sh=EU,Ch=TU;function r8(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,s=Array(t);n<t;n++)s[n]=e[n];return s}function gke(e){if(Array.isArray(e))return e}function bke(e,t,n){return(t=Cke(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function vke(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var s,i,a,o,l=[],c=!0,d=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(s=a.call(n)).done)&&(l.push(s.value),l.length!==t);c=!0);}catch(f){d=!0,i=f}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(d)throw i}}return l}}function yke(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
192
192
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function a8(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,s)}return n}function o8(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?a8(Object(n),!0).forEach(function(s){bke(e,s,n[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a8(Object(n)).forEach(function(s){Object.defineProperty(e,s,Object.getOwnPropertyDescriptor(n,s))})}return e}function _ke(e,t){if(e==null)return{};var n,s,i=wke(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(s=0;s<a.length;s++)n=a[s],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function wke(e,t){if(e==null)return{};var n={};for(var s in e)if({}.hasOwnProperty.call(e,s)){if(t.indexOf(s)!==-1)continue;n[s]=e[s]}return n}function Ake(e,t){return gke(e)||vke(e,t)||jke(e,t)||yke()}function Ske(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var s=n.call(e,t);if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Cke(e){var t=Ske(e,"string");return typeof t=="symbol"?t:t+""}function jke(e,t){if(e){if(typeof e=="string")return r8(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r8(e,t):void 0}}function Nke(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l8(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,s)}return n}function c8(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?l8(Object(n),!0).forEach(function(s){Nke(e,s,n[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l8(Object(n)).forEach(function(s){Object.defineProperty(e,s,Object.getOwnPropertyDescriptor(n,s))})}return e}function kke(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(s){return t.reduceRight(function(i,a){return a(i)},s)}}function np(e){return function t(){for(var n=this,s=arguments.length,i=new Array(s),a=0;a<s;a++)i[a]=arguments[a];return i.length>=e.length?e.apply(this,i):function(){for(var o=arguments.length,l=new Array(o),c=0;c<o;c++)l[c]=arguments[c];return t.apply(n,[].concat(i,l))}}}function H0(e){return{}.toString.call(e).includes("Object")}function Eke(e){return!Object.keys(e).length}function Zp(e){return typeof e=="function"}function Fke(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Tke(e,t){return H0(t)||$l("changeType"),Object.keys(t).some(function(n){return!Fke(e,n)})&&$l("changeField"),t}function Mke(e){Zp(e)||$l("selectorType")}function Rke(e){Zp(e)||H0(e)||$l("handlerType"),H0(e)&&Object.values(e).some(function(t){return!Zp(t)})&&$l("handlersType")}function Dke(e){e||$l("initialIsRequired"),H0(e)||$l("initialType"),Eke(e)&&$l("initialContent")}function Oke(e,t){throw new Error(e[t]||e.default)}var Pke={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},$l=np(Oke)(Pke),nb={changes:Tke,selector:Mke,handler:Rke,initial:Dke};function Ike(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};nb.initial(e),nb.handler(t);var n={current:e},s=np(zke)(n,t),i=np(Bke)(n),a=np(nb.changes)(e),o=np(Lke)(n);function l(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(f){return f};return nb.selector(d),d(n.current)}function c(d){kke(s,i,a,o)(d)}return[l,c]}function Lke(e,t){return Zp(t)?t(e.current):t}function Bke(e,t){return e.current=c8(c8({},e.current),t),t}function zke(e,t,n){return Zp(t)?t(e.current):Object.keys(n).forEach(function(s){var i;return(i=t[s])===null||i===void 0?void 0:i.call(t,e.current[s])}),n}var $ke={create:Ike},Vke={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function Uke(e){return function t(){for(var n=this,s=arguments.length,i=new Array(s),a=0;a<s;a++)i[a]=arguments[a];return i.length>=e.length?e.apply(this,i):function(){for(var o=arguments.length,l=new Array(o),c=0;c<o;c++)l[c]=arguments[c];return t.apply(n,[].concat(i,l))}}}function Hke(e){return{}.toString.call(e).includes("Object")}function Wke(e){return e||u8("configIsRequired"),Hke(e)||u8("configType"),e.urls?(qke(),{paths:{vs:e.urls.monacoBase}}):e}function qke(){console.warn(DU.deprecation)}function Gke(e,t){throw new Error(e[t]||e.default)}var DU={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
@@ -351,7 +351,7 @@ XID_Start XIDS`.split(/\s/).map(e=>[ky(e),e])),zFe=new Map([["s",ts(383)],[ts(38
351
351
  ?|[
352
352
  \v\f…\u2028\u2029])`),t));else if(c==="posix")if(!i&&(f==="graph"||f==="print")){if(s==="strict")throw new Error(`POSIX class "${f}" requires min target ES2024 or non-strict accuracy`);let p={graph:"!-~",print:" -~"}[f];d&&(p=`\0-${ts(p.codePointAt(0)-1)}${ts(p.codePointAt(2)+1)}-􏿿`),n(Mn(go(`[${p}]`),t))}else n(Mn(ZA(go(UFe.get(f)),d),t));else if(c==="property")BN.has(ky(f))||(e.key="sc");else if(c==="space")n(El(Ad("space",{negate:d}),t));else if(c==="word")n(Mn(ZA(go(xo),d),t));else throw new Error(`Unexpected character set kind "${c}"`)},Directive({node:e,parent:t,root:n,remove:s,replaceWith:i,removeAllPrevSiblings:a,removeAllNextSiblings:o}){const{kind:l,flags:c}=e;if(l==="flags")if(!c.enable&&!c.disable)s();else{const d=Qr({flags:c});d.body[0].body=o(),i(Mn(d,t),{traverse:!0})}else if(l==="keep"){const d=n.body[0],p=n.body.length===1&&IH(d,{type:"Group"})&&d.body[0].body.length===1?d.body[0]:n;if(t.parent!==p||p.body.length>1)throw new Error(Xe`Uses "\K" in a way that's unsupported`);const m=zc({behind:!0});m.body[0].body=a(),i(Mn(m,t))}else throw new Error(`Unexpected directive kind "${l}"`)},Flags({node:e,parent:t}){if(e.posixIsAscii)throw new Error('Unsupported flag "P"');if(e.textSegmentMode==="word")throw new Error('Unsupported flag "y{w}"');["digitIsAscii","extended","posixIsAscii","spaceIsAscii","wordIsAscii","textSegmentMode"].forEach(n=>delete e[n]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;const{enable:t,disable:n}=e.flags;t?.extended&&delete t.extended,n?.extended&&delete n.extended,t?.dotAll&&n?.dotAll&&delete t.dotAll,t?.ignoreCase&&n?.ignoreCase&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable,n&&!Object.keys(n).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},LookaroundAssertion({node:e},t){const{kind:n}=e;n==="lookbehind"&&(t.passedLookbehind=!0)},NamedCallout({node:e,parent:t,replaceWith:n}){const{kind:s}=e;if(s==="fail")n(Mn(zc({negate:!0}),t));else throw new Error(`Unsupported named callout "(*${s.toUpperCase()}"`)},Quantifier({node:e}){if(e.body.type==="Quantifier"){const t=Qr();t.body[0].body.push(e.body),e.body=Mn(t,e)}},Regex:{enter({node:e},{supportedGNodes:t}){const n=[];let s=!1,i=!1;for(const a of e.body)if(a.body.length===1&&a.body[0].kind==="search_start")a.body.pop();else{const o=ZH(a.body);o?(s=!0,Array.isArray(o)?n.push(...o):n.push(o)):i=!0}s&&!i&&n.forEach(a=>t.add(a))},exit(e,{accuracy:t,passedLookbehind:n,strategy:s}){if(t==="strict"&&n&&s)throw new Error(Xe`Uses "\G" in a way that requires non-strict accuracy`)}},Subroutine({node:e},{jsGroupNameMap:t}){let{ref:n}=e;typeof n=="string"&&!JA(n)&&(n=XA(n,t),e.ref=n)}},GFe={Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByReferencer:n}){const{orphan:s,ref:i}=e;s||n.set(e,[...t.get(i).map(({node:a})=>a)])},CapturingGroup:{enter({node:e,parent:t,replaceWith:n,skip:s},{groupOriginByCopy:i,groupsByName:a,multiplexCapturesToLeftByRef:o,openRefs:l,reffedNodesByReferencer:c}){const d=i.get(e);if(d&&l.has(e.number)){const p=El(W8(e.number),t);c.set(p,l.get(e.number)),n(p);return}l.set(e.number,e),o.set(e.number,[]),e.name&&im(o,e.name,[]);const f=o.get(e.name??e.number);for(let p=0;p<f.length;p++){const m=f[p];if(d===m.node||d&&d===m.origin||e===m.origin){f.splice(p,1);break}}if(o.get(e.number).push({node:e,origin:d}),e.name&&o.get(e.name).push({node:e,origin:d}),e.name){const p=im(a,e.name,new Map);let m=!1;if(d)m=!0;else for(const g of p.values())if(!g.hasDuplicateNameToRemove){m=!0;break}a.get(e.name).set(e,{node:e,hasDuplicateNameToRemove:m})}},exit({node:e},{openRefs:t}){t.delete(e.number)}},Group:{enter({node:e},t){t.prevFlags=t.currentFlags,e.flags&&(t.currentFlags=tv(t.currentFlags,e.flags))},exit(e,t){t.currentFlags=t.prevFlags}},Subroutine({node:e,parent:t,replaceWith:n},s){const{isRecursive:i,ref:a}=e;if(i){let f=t;for(;(f=f.parent)&&!(f.type==="CapturingGroup"&&(f.name===a||f.number===a)););s.reffedNodesByReferencer.set(e,f);return}const o=s.subroutineRefMap.get(a),l=a===0,c=l?W8(0):QH(o,s.groupOriginByCopy,null);let d=c;if(!l){const f=XH(XFe(o,m=>m.type==="Group"&&!!m.flags)),p=f?tv(s.globalFlags,f):s.globalFlags;YFe(p,s.currentFlags)||(d=Qr({flags:JFe(p)}),d.body[0].body.push(c))}n(Mn(d,t),{traverse:!l})}},KFe={Backreference({node:e,parent:t,replaceWith:n},s){if(e.orphan){s.highestOrphanBackref=Math.max(s.highestOrphanBackref,e.ref);return}const a=s.reffedNodesByReferencer.get(e).filter(o=>QFe(o,e));if(!a.length)n(Mn(zc({negate:!0}),t));else if(a.length>1){const o=Qr({atomic:!0,body:a.reverse().map(l=>pu({body:[kC(l.number)]}))});n(Mn(o,t))}else e.ref=a[0].number},CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,e.name&&t.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Regex:{exit({node:e},t){const n=Math.max(t.highestOrphanBackref-t.numCapturesToLeft,0);for(let s=0;s<n;s++){const i=BH();e.body.at(-1).body.push(i)}}},Subroutine({node:e},t){!e.isRecursive||e.ref===0||(e.ref=t.reffedNodesByReferencer.get(e).number)}};function YH(e){wp(e,{"*"({node:t,parent:n}){t.parent=n}})}function YFe(e,t){return e.dotAll===t.dotAll&&e.ignoreCase===t.ignoreCase}function QFe(e,t){let n=t;do{if(n.type==="Regex")return!1;if(n.type==="Alternative")continue;if(n===e)return!1;const s=JH(n.parent);for(const i of s){if(i===n)break;if(i===e||eW(i,e))return!0}}while(n=n.parent);throw new Error("Unexpected path")}function QH(e,t,n,s){const i=Array.isArray(e)?[]:{};for(const[a,o]of Object.entries(e))a==="parent"?i.parent=Array.isArray(n)?s:n:o&&typeof o=="object"?i[a]=QH(o,t,i,n):(a==="type"&&o==="CapturingGroup"&&t.set(i,t.get(e)??e),i[a]=o);return i}function W8(e){const t=$H(e);return t.isRecursive=!0,t}function XFe(e,t){const n=[];for(;e=e.parent;)(!t||t(e))&&n.push(e);return n}function XA(e,t){if(t.has(e))return t.get(e);const n=`$${t.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug,"_")}`;return t.set(e,n),n}function XH(e){const t=["dotAll","ignoreCase"],n={enable:{},disable:{}};return e.forEach(({flags:s})=>{t.forEach(i=>{s.enable?.[i]&&(delete n.disable[i],n.enable[i]=!0),s.disable?.[i]&&(n.disable[i]=!0)})}),Object.keys(n.enable).length||delete n.enable,Object.keys(n.disable).length||delete n.disable,n.enable||n.disable?n:null}function JFe({dotAll:e,ignoreCase:t}){const n={};return(e||t)&&(n.enable={},e&&(n.enable.dotAll=!0),t&&(n.enable.ignoreCase=!0)),(!e||!t)&&(n.disable={},!e&&(n.disable.dotAll=!0),!t&&(n.disable.ignoreCase=!0)),n}function JH(e){if(!e)throw new Error("Node expected");const{body:t}=e;return Array.isArray(t)?t:t?[t]:null}function ZH(e){const t=e.find(n=>n.kind==="search_start"||tTe(n,{negate:!1})||!ZFe(n));if(!t)return null;if(t.kind==="search_start")return t;if(t.type==="LookaroundAssertion")return t.body[0].body[0];if(t.type==="CapturingGroup"||t.type==="Group"){const n=[];for(const s of t.body){const i=ZH(s.body);if(!i)return null;Array.isArray(i)?n.push(...i):n.push(i)}return n}return null}function eW(e,t){const n=JH(e)??[];for(const s of n)if(s===t||eW(s,t))return!0;return!1}function ZFe({type:e}){return e==="Assertion"||e==="Directive"||e==="LookaroundAssertion"}function eTe(e){const t=["Character","CharacterClass","CharacterSet"];return t.includes(e.type)||e.type==="Quantifier"&&e.min&&t.includes(e.body.type)}function tTe(e,t){const n={negate:null,...t};return e.type==="LookaroundAssertion"&&(n.negate===null||e.negate===n.negate)&&e.body.length===1&&IH(e.body[0],{type:"Assertion",kind:"search_start"})}function JA(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function go(e,t){const s=LH(e,{...t,unicodePropertyMap:BN}).body;return s.length>1||s[0].body.length>1?Qr({body:s}):s[0].body[0]}function ZA(e,t){return e.negate=t,e}function El(e,t){return e.parent=t,e}function Mn(e,t){return YH(e),e.parent=t,e}function nTe(e,t){const n=qH(t),s=TC(n.target,"ES2024"),i=TC(n.target,"ES2025"),a=n.rules.recursionLimit;if(!Number.isInteger(a)||a<2||a>20)throw new Error("Invalid recursionLimit; use 2-20");let o=null,l=null;if(!i){const g=[e.flags.ignoreCase];wp(e,sTe,{getCurrentModI:()=>g.at(-1),popModI(){g.pop()},pushModI(b){g.push(b)},setHasCasedChar(){g.at(-1)?o=!0:l=!0}})}const c={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||o)&&!l)};let d=e;const f={accuracy:n.accuracy,appliedGlobalFlags:c,captureMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},inCharClass:!1,lastNode:d,originMap:e._originMap,recursionLimit:a,useAppliedIgnoreCase:!!(!i&&o&&l),useFlagMods:i,useFlagV:s,verbose:n.verbose};function p(g){return f.lastNode=d,d=g,PFe(iTe[g.type],`Unexpected node type "${g.type}"`)(g,f,p)}const m={pattern:e.body.map(p).join("|"),flags:p(e.flags),options:{...e.options}};return s||(delete m.options.force.v,m.options.disable.v=!0,m.options.unicodeSetsPlugin=null),m._captureTransfers=new Map,m._hiddenCaptures=[],f.captureMap.forEach((g,b)=>{g.hidden&&m._hiddenCaptures.push(b),g.transferTo&&im(m._captureTransfers,g.transferTo,[]).push(b)}),m}var sTe={"*":{enter({node:e},t){if(G8(e)){const n=t.getCurrentModI();t.pushModI(e.flags?tv({ignoreCase:n},e.flags).ignoreCase:n)}},exit({node:e},t){G8(e)&&t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){zN(ts(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},n){t(),tW(e,{firstOnly:!0}).length&&n.setHasCasedChar()},CharacterSet({node:e},t){e.kind==="property"&&KH.has(e.value)&&t.setHasCasedChar()}},iTe={Alternative({body:e},t,n){return e.map(n).join("")},Assertion({kind:e,negate:t}){if(e==="string_end")return"$";if(e==="string_start")return"^";if(e==="word_boundary")return t?Xe`\B`:Xe`\b`;throw new Error(`Unexpected assertion kind "${e}"`)},Backreference({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&t.accuracy==="strict"&&t.currentFlags.ignoreCase&&!t.captureMap.get(e).ignoreCase)throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");return"\\"+e},CapturingGroup(e,t,n){const{body:s,name:i,number:a}=e,o={ignoreCase:t.currentFlags.ignoreCase},l=t.originMap.get(e);return l&&(o.hidden=!0,a>l.number&&(o.transferTo=l.number)),t.captureMap.set(a,o),`(${i?`?<${i}>`:""}${s.map(n).join("|")})`},Character({value:e},t){const n=ts(e),s=vd(e,{escDigit:t.lastNode.type==="Backreference",inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(s!==n)return s;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&zN(n)){const i=GH(n);return t.inCharClass?i.join(""):i.length>1?`[${i.join("")}]`:i[0]}return n},CharacterClass(e,t,n){const{kind:s,negate:i,parent:a}=e;let{body:o}=e;if(s==="intersection"&&!t.useFlagV)throw new Error("Use of character class intersection requires min target ES2024");na.bugFlagVLiteralHyphenIsRange&&t.useFlagV&&o.some(K8)&&(o=[Ny(45),...o.filter(d=>!K8(d))]);const l=()=>`[${i?"^":""}${o.map(n).join(s==="intersection"?"&&":"")}]`;if(!t.inCharClass){if((!t.useFlagV||na.bugNestedClassIgnoresNegation)&&!i){const f=o.filter(p=>p.type==="CharacterClass"&&p.kind==="union"&&p.negate);if(f.length){const p=Qr(),m=p.body[0];return p.parent=a,m.parent=p,o=o.filter(g=>!f.includes(g)),e.body=o,o.length?(e.parent=m,m.body.push(e)):p.body.pop(),f.forEach(g=>{const b=pu({body:[g]});g.parent=b,b.parent=p,p.body.push(b)}),n(p)}}t.inCharClass=!0;const d=l();return t.inCharClass=!1,d}const c=o[0];if(s==="union"&&!i&&c&&((!t.useFlagV||!t.verbose)&&a.kind==="union"&&!(na.bugFlagVLiteralHyphenIsRange&&t.useFlagV)||!t.verbose&&a.kind==="intersection"&&o.length===1&&c.type!=="CharacterClassRange"))return o.map(n).join("");if(!t.useFlagV&&a.type==="CharacterClass")throw new Error("Uses nested character class in a way that requires min target ES2024");return l()},CharacterClassRange(e,t){const n=e.min.value,s=e.max.value,i={escDigit:!1,inCharClass:!0,useFlagV:t.useFlagV},a=vd(n,i),o=vd(s,i),l=new Set;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){const c=tW(e);cTe(c).forEach(f=>{l.add(Array.isArray(f)?`${vd(f[0],i)}-${vd(f[1],i)}`:vd(f,i))})}return`${a}-${o}${[...l].join("")}`},CharacterSet({kind:e,negate:t,value:n,key:s},i){if(e==="dot")return i.currentFlags.dotAll?i.appliedGlobalFlags.dotAll||i.useFlagMods?".":"[^]":Xe`[^\n]`;if(e==="digit")return t?Xe`\D`:Xe`\d`;if(e==="property"){if(i.useAppliedIgnoreCase&&i.currentFlags.ignoreCase&&KH.has(n))throw new Error(`Unicode property "${n}" can't be case-insensitive when other chars have specific case`);return`${t?Xe`\P`:Xe`\p`}{${s?`${s}=`:""}${n}}`}if(e==="word")return t?Xe`\W`:Xe`\w`;throw new Error(`Unexpected character set kind "${e}"`)},Flags(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")},Group({atomic:e,body:t,flags:n,parent:s},i,a){const o=i.currentFlags;n&&(i.currentFlags=tv(o,n));const l=t.map(a).join("|"),c=!i.verbose&&t.length===1&&s.type!=="Quantifier"&&!e&&(!i.useFlagMods||!n)?l:`(?${uTe(e,n,i.useFlagMods)}${l})`;return i.currentFlags=o,c},LookaroundAssertion({body:e,kind:t,negate:n},s,i){return`(?${`${t==="lookahead"?"":"<"}${n?"!":"="}`}${e.map(i).join("|")})`},Quantifier(e,t,n){return n(e.body)+dTe(e)},Subroutine({isRecursive:e,ref:t},n){if(!e)throw new Error("Unexpected non-recursive subroutine in transformed AST");const s=n.recursionLimit;return t===0?`(?R=${s})`:Xe`\g<${t}&R=${s}>`}},rTe=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),aTe=new Set(["-","\\","]","^","["]),oTe=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),q8=new Map([[9,Xe`\t`],[10,Xe`\n`],[11,Xe`\v`],[12,Xe`\f`],[13,Xe`\r`],[8232,Xe`\u2028`],[8233,Xe`\u2029`],[65279,Xe`\uFEFF`]]),lTe=new RegExp("^\\p{Cased}$","u");function zN(e){return lTe.test(e)}function tW(e,t){const n=!!t?.firstOnly,s=e.min.value,i=e.max.value,a=[];if(s<65&&(i===65535||i>=131071)||s===65536&&i>=131071)return a;for(let o=s;o<=i;o++){const l=ts(o);if(!zN(l))continue;const c=GH(l).filter(d=>{const f=d.codePointAt(0);return f<s||f>i});if(c.length&&(a.push(...c),n))break}return a}function vd(e,{escDigit:t,inCharClass:n,useFlagV:s}){if(q8.has(e))return q8.get(e);if(e<32||e>126&&e<160||e>262143||t&&hTe(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;const i=n?s?oTe:aTe:rTe,a=ts(e);return(i.has(a)?"\\":"")+a}function cTe(e){const t=e.map(i=>i.codePointAt(0)).sort((i,a)=>i-a),n=[];let s=null;for(let i=0;i<t.length;i++)t[i+1]===t[i]+1?s??=t[i]:s===null?n.push(t[i]):(n.push([s,t[i]]),s=null);return n}function uTe(e,t,n){if(e)return">";let s="";if(t&&n){const{enable:i,disable:a}=t;s=(i?.ignoreCase?"i":"")+(i?.dotAll?"s":"")+(a?"-":"")+(a?.ignoreCase?"i":"")+(a?.dotAll?"s":"")}return`${s}:`}function dTe({kind:e,max:t,min:n}){let s;return!n&&t===1?s="?":!n&&t===1/0?s="*":n===1&&t===1/0?s="+":n===t?s=`{${n}}`:s=`{${n},${t===1/0?"":t}}`,s+{greedy:"",lazy:"?",possessive:"+"}[e]}function G8({type:e}){return e==="CapturingGroup"||e==="Group"||e==="LookaroundAssertion"}function hTe(e){return e>47&&e<58}function K8({type:e,value:t}){return e==="Character"&&t===45}var fTe=class MC extends RegExp{#t=new Map;#e=null;#n;#i=null;#s=null;rawOptions={};get source(){return this.#n||"(?:)"}constructor(t,n,s){const i=!!s?.lazyCompile;if(t instanceof RegExp){if(s)throw new Error("Cannot provide options when copying a regexp");const a=t;super(a,n),this.#n=a.source,a instanceof MC&&(this.#t=a.#t,this.#i=a.#i,this.#s=a.#s,this.rawOptions=a.rawOptions)}else{const a={hiddenCaptures:[],strategy:null,transfers:[],...s};super(i?"":t,n),this.#n=t,this.#t=mTe(a.hiddenCaptures,a.transfers),this.#s=a.strategy,this.rawOptions=s??{}}i||(this.#e=this)}exec(t){if(!this.#e){const{lazyCompile:i,...a}=this.rawOptions;this.#e=new MC(this.#n,this.flags,a)}const n=this.global||this.sticky,s=this.lastIndex;if(this.#s==="clip_search"&&n&&s){this.lastIndex=0;const i=this.#r(t.slice(s));return i&&(pTe(i,s,t,this.hasIndices),this.lastIndex+=s),i}return this.#r(t)}#r(t){this.#e.lastIndex=this.lastIndex;const n=super.exec.call(this.#e,t);if(this.lastIndex=this.#e.lastIndex,!n||!this.#t.size)return n;const s=[...n];n.length=1;let i;this.hasIndices&&(i=[...n.indices],n.indices.length=1);const a=[0];for(let o=1;o<s.length;o++){const{hidden:l,transferTo:c}=this.#t.get(o)??{};if(l?a.push(null):(a.push(n.length),n.push(s[o]),this.hasIndices&&n.indices.push(i[o])),c&&s[o]!==void 0){const d=a[c];if(!d)throw new Error(`Invalid capture transfer to "${d}"`);if(n[d]=s[o],this.hasIndices&&(n.indices[d]=i[o]),n.groups){this.#i||(this.#i=xTe(this.source));const f=this.#i.get(c);f&&(n.groups[f]=s[o],this.hasIndices&&(n.indices.groups[f]=i[o]))}}}return n}};function pTe(e,t,n,s){if(e.index+=t,e.input=n,s){const i=e.indices;for(let o=0;o<i.length;o++){const l=i[o];l&&(i[o]=[l[0]+t,l[1]+t])}const a=i.groups;a&&Object.keys(a).forEach(o=>{const l=a[o];l&&(a[o]=[l[0]+t,l[1]+t])})}}function mTe(e,t){const n=new Map;for(const s of e)n.set(s,{hidden:!0});for(const[s,i]of t)for(const a of i)im(n,a,{}).transferTo=s;return n}function xTe(e){const t=/(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu,n=new Map;let s=0,i=0,a;for(;a=t.exec(e);){const{0:o,groups:{capture:l,name:c}}=a;o==="["?s++:s?o==="]"&&s--:l&&(i++,c&&n.set(i,c))}return n}function gTe(e,t){const n=bTe(e,t);return n.options?new fTe(n.pattern,n.flags,n.options):new RegExp(n.pattern,n.flags)}function bTe(e,t){const n=qH(t),s=LH(e,{flags:n.flags,normalizeUnknownPropertyNames:!0,rules:{captureGroup:n.rules.captureGroup,singleline:n.rules.singleline},skipBackrefValidation:n.rules.allowOrphanBackrefs,unicodePropertyMap:BN}),i=WFe(s,{accuracy:n.accuracy,asciiWordBoundaries:n.rules.asciiWordBoundaries,avoidSubclass:n.avoidSubclass,bestEffortTarget:n.target}),a=nTe(i,n),o=DFe(a.pattern,{captureTransfers:a._captureTransfers,hiddenCaptures:a._hiddenCaptures,mode:"external"}),l=MFe(o.pattern),c=TFe(l.pattern,{captureTransfers:o.captureTransfers,hiddenCaptures:o.hiddenCaptures}),d={pattern:c.pattern,flags:`${n.hasIndices?"d":""}${n.global?"g":""}${a.flags}${a.options.disable.v?"u":"v"}`};if(n.avoidSubclass){if(n.lazyCompileLength!==1/0)throw new Error("Lazy compilation requires subclass")}else{const f=c.hiddenCaptures.sort((b,_)=>b-_),p=Array.from(c.captureTransfers),m=i._strategy,g=d.pattern.length>=n.lazyCompileLength;(f.length||p.length||m||g)&&(d.options={...f.length&&{hiddenCaptures:f},...p.length&&{transfers:p},...m&&{strategy:m},...g&&{lazyCompile:g}})}return d}function nW(e,t){return gTe(e,{global:!0,hasIndices:!0,lazyCompileLength:3e3,rules:{allowOrphanBackrefs:!0,asciiWordBoundaries:!0,captureGroup:!0,recursionLimit:5,singleline:!0},...t})}function vTe(e={}){const t=Object.assign({target:"auto",cache:new Map},e);return t.regexConstructor||=n=>nW(n,{target:t.target}),{createScanner(n){return new O4e(n,t)},createString(n){return{content:n}}}}var yTe=_N({bundledLanguages:()=>SN,bundledLanguagesAlias:()=>AN,bundledLanguagesBase:()=>wN,bundledLanguagesInfo:()=>vy,bundledThemes:()=>jN,bundledThemesInfo:()=>CN,codeToHast:()=>jH,codeToHtml:()=>ON,codeToTokens:()=>NH,codeToTokensBase:()=>kH,codeToTokensWithThemes:()=>EH,createHighlighter:()=>DN,createJavaScriptRegexEngine:()=>vTe,createOnigurumaEngine:()=>qU,defaultJavaScriptRegexConstructor:()=>nW,getLastGrammarState:()=>TH,getSingletonHighlighter:()=>FH,loadWasm:()=>kN});UU(yTe,D4e);const _Te=new Set([".png",".jpg",".jpeg",".gif",".bmp",".ico",".webp",".svg"]),wTe=new Set([".mp3",".wav",".ogg"]),ATe=new Set([".mp4",".webm"]),STe=new Set([".ts",".tsx",".js",".jsx",".py",".rs",".go",".java",".c",".cpp",".h",".hpp",".cs",".rb",".php",".swift",".kt",".sh",".bash",".zsh",".fish",".sql",".graphql",".vue",".svelte",".css",".scss",".less",".html",".xml",".yaml",".yml",".toml",".prisma",".proto",".lua",".zig",".ex",".exs",".erl",".hrl",".clj",".cljs",".hs",".ml",".mli",".r",".jl",".dart",".tf",".jsonc"]),CTe={".ts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"jsx",".py":"python",".rs":"rust",".go":"go",".java":"java",".c":"c",".cpp":"cpp",".h":"c",".hpp":"cpp",".cs":"csharp",".rb":"ruby",".php":"php",".swift":"swift",".kt":"kotlin",".sh":"bash",".bash":"bash",".zsh":"bash",".fish":"bash",".sql":"sql",".graphql":"graphql",".vue":"vue",".svelte":"svelte",".css":"css",".scss":"scss",".less":"less",".html":"html",".xml":"xml",".yaml":"yaml",".yml":"yaml",".toml":"toml",".json":"json",".jsonc":"jsonc",".prisma":"prisma",".lua":"lua",".zig":"zig",".dart":"dart",".tf":"hcl",".r":"r",".md":"markdown"};function jTe(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t).toLowerCase():""}function sW(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function NTe(e,t){return`${oi}/api/files/serve/${e}/${t}`}function kTe({src:e}){const[t,n]=y.useState(!1);return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"p-4 flex items-center justify-center",children:r.jsx("img",{src:e,alt:"",className:"max-w-full max-h-[400px] rounded-md border border-[#2A2A35] cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>n(!0)})}),t&&r.jsxs("div",{className:"fixed inset-0 z-50 bg-black/80 flex items-center justify-center cursor-pointer",onClick:()=>n(!1),children:[r.jsx("button",{onClick:()=>n(!1),className:"absolute top-4 right-4 w-8 h-8 flex items-center justify-center rounded-full bg-white/10 text-white hover:bg-white/20 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})}),r.jsx("img",{src:e,alt:"",className:"max-w-[90vw] max-h-[90vh] rounded-lg",onClick:s=>s.stopPropagation()})]})]})}function Y8({content:e,separator:t}){const[n,s]=y.useState(null),[i,a]=y.useState(!0),{headers:o,rows:l}=y.useMemo(()=>{const f=e.trim().split(`
353
353
  `).filter(Boolean);if(f.length===0)return{headers:[],rows:[]};const p=f[0].split(t).map(g=>g.trim().replace(/^"|"$/g,"")),m=f.slice(1).map(g=>g.split(t).map(b=>b.trim().replace(/^"|"$/g,"")));return{headers:p,rows:m}},[e,t]),c=y.useMemo(()=>n===null?l:[...l].sort((f,p)=>{const m=f[n]??"",g=p[n]??"",b=Number(m),_=Number(g);return!isNaN(b)&&!isNaN(_)?i?b-_:_-b:i?m.localeCompare(g):g.localeCompare(m)}),[l,n,i]);function d(f){n===f?a(!i):(s(f),a(!0))}return o.length===0?r.jsx("p",{className:"p-4 text-[12px] text-[#5A5A6E]",children:"Empty CSV"}):r.jsx("div",{className:"overflow-auto",children:r.jsxs("table",{className:"w-full text-[11px]",children:[r.jsx("thead",{children:r.jsx("tr",{className:"border-b border-[#2A2A35]",children:o.map((f,p)=>r.jsxs("th",{onClick:()=>d(p),className:"px-3 py-2 text-left text-[#8A8A99] font-medium cursor-pointer hover:text-[#C8C8D4] transition-colors whitespace-nowrap select-none",children:[f,n===p&&r.jsx("span",{className:"ml-1 text-[#6366F1]",children:i?"↑":"↓"})]},p))})}),r.jsx("tbody",{children:c.map((f,p)=>r.jsx("tr",{className:"border-b border-[#2A2A35]/50 hover:bg-white/[0.02]",children:f.map((m,g)=>r.jsx("td",{className:"px-3 py-1.5 text-[#C8C8D4] whitespace-nowrap",children:m},g))},p))})]})})}function RC({data:e,depth:t=0}){const[n,s]=y.useState(t>2);if(e===null)return r.jsx("span",{className:"text-[#F59E0B]",children:"null"});if(typeof e=="boolean")return r.jsx("span",{className:"text-[#F59E0B]",children:String(e)});if(typeof e=="number")return r.jsx("span",{className:"text-[#10B981]",children:e});if(typeof e=="string")return r.jsxs("span",{className:"text-[#6366F1]",children:['"',e,'"']});if(Array.isArray(e))return e.length===0?r.jsx("span",{className:"text-[#5A5A6E]",children:"[]"}):r.jsxs("span",{children:[r.jsx("button",{onClick:()=>s(!n),className:"inline-flex items-center text-[#5A5A6E] hover:text-[#C8C8D4]",children:n?r.jsx(Jt,{className:"w-3 h-3"}):r.jsx(ft,{className:"w-3 h-3"})}),r.jsx("span",{className:"text-[#5A5A6E]",children:"["}),n?r.jsxs("span",{className:"text-[#5A5A6E] cursor-pointer",onClick:()=>s(!1),children:[e.length," items"]}):r.jsx("div",{style:{paddingLeft:16},children:e.map((i,a)=>r.jsxs("div",{children:[r.jsx(RC,{data:i,depth:t+1}),a<e.length-1&&r.jsx("span",{className:"text-[#5A5A6E]",children:","})]},a))}),r.jsx("span",{className:"text-[#5A5A6E]",children:"]"})]});if(typeof e=="object"){const i=Object.entries(e);return i.length===0?r.jsx("span",{className:"text-[#5A5A6E]",children:"{}"}):r.jsxs("span",{children:[r.jsx("button",{onClick:()=>s(!n),className:"inline-flex items-center text-[#5A5A6E] hover:text-[#C8C8D4]",children:n?r.jsx(Jt,{className:"w-3 h-3"}):r.jsx(ft,{className:"w-3 h-3"})}),r.jsx("span",{className:"text-[#5A5A6E]",children:"{"}),n?r.jsxs("span",{className:"text-[#5A5A6E] cursor-pointer",onClick:()=>s(!1),children:[i.length," keys"]}):r.jsx("div",{style:{paddingLeft:16},children:i.map(([a,o],l)=>r.jsxs("div",{children:[r.jsxs("span",{className:"text-[#EC4899]",children:['"',a,'"']}),r.jsx("span",{className:"text-[#5A5A6E]",children:": "}),r.jsx(RC,{data:o,depth:t+1}),l<i.length-1&&r.jsx("span",{className:"text-[#5A5A6E]",children:","})]},a))}),r.jsx("span",{className:"text-[#5A5A6E]",children:"}"})]})}return r.jsx("span",{className:"text-[#C8C8D4]",children:String(e)})}function iW({content:e,ext:t}){const[n,s]=y.useState(null);return y.useEffect(()=>{const i=CTe[t]??"text";let a=!1;return ON(e,{lang:i,theme:"github-dark-default"}).then(o=>{a||s(o)}).catch(()=>{a||s(null)}),()=>{a=!0}},[e,t]),n?r.jsx("div",{className:"px-1 py-1 text-[11px] leading-[1.6] [&_pre]:!bg-transparent [&_pre]:p-2 [&_code]:text-[11px] overflow-auto",dangerouslySetInnerHTML:{__html:n}}):r.jsx("pre",{className:"px-3 py-2 text-[11px] font-mono text-[#C8C8D4] leading-[1.6] whitespace-pre-wrap break-all",children:e})}function ETe({content:e,ext:t}){const n=y.useMemo(()=>{try{return JSON.parse(e)}catch{return null}},[e]);return n===null?r.jsx(iW,{content:e,ext:t}):r.jsx("div",{className:"px-3 py-2 text-[11px] font-mono leading-[1.6] overflow-auto",children:r.jsx(RC,{data:n})})}function FTe({agentId:e,filePath:t,content:n,binary:s,size:i,ext:a}){const o=t.split("/").pop()??t,l=a||jTe(o),c=NTe(e,t);return _Te.has(l)?r.jsxs("div",{children:[r.jsx(kTe,{src:c}),r.jsx(Uf,{url:c,filename:o,size:i})]}):wTe.has(l)?r.jsxs("div",{className:"p-4 space-y-3",children:[r.jsx("audio",{controls:!0,className:"w-full",preload:"metadata",children:r.jsx("source",{src:c})}),r.jsx(Uf,{url:c,filename:o,size:i})]}):ATe.has(l)?r.jsxs("div",{className:"p-4 space-y-3",children:[r.jsx("video",{controls:!0,className:"w-full max-h-[400px] rounded-md border border-[#2A2A35]",preload:"metadata",children:r.jsx("source",{src:c})}),r.jsx(Uf,{url:c,filename:o,size:i})]}):l===".pdf"?r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("iframe",{src:c,className:"flex-1 min-h-[400px] border-0",title:o}),r.jsx(Uf,{url:c,filename:o,size:i})]}):!n&&s?r.jsxs("div",{className:"p-4 text-center space-y-2",children:[r.jsxs("p",{className:"text-[12px] text-[#5A5A6E]",children:["Binary file (",l,")"]}),r.jsx(Uf,{url:c,filename:o,size:i})]}):n?l===".md"?r.jsx("div",{className:"px-4 py-3 prose-message text-[13px]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:n})}):l===".csv"?r.jsx(Y8,{content:n,separator:","}):l===".tsv"?r.jsx(Y8,{content:n,separator:"\\t"}):(l===".json"||l===".jsonc")&&CU(o)?r.jsx(jU,{agentId:e,filePath:t,content:n}):l===".json"||l===".jsonc"?r.jsx(ETe,{content:n,ext:l}):STe.has(l)?r.jsx(iW,{content:n,ext:l}):r.jsx("pre",{className:"px-3 py-2 text-[11px] font-mono text-[#C8C8D4] leading-[1.6] whitespace-pre-wrap break-all",children:n}):r.jsxs("div",{className:"p-4 text-center",children:[r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"No preview available"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:sW(i)})]})}function Uf({url:e,filename:t,size:n}){const s=y.useCallback(()=>{const i=document.createElement("a");i.href=e,i.download=t,i.click()},[e,t]);return r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-[#2A2A35]/50",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:sW(n)}),r.jsxs("button",{onClick:s,className:"flex items-center gap-1 text-[11px] text-[#8A8A99] hover:text-[#C8C8D4] transition-colors",children:[r.jsx(nu,{className:"w-3 h-3"}),"Download"]})]})}const rW=new Set([".ts",".tsx",".js",".jsx",".py",".rs",".go",".java",".c",".cpp",".h",".hpp",".cs",".rb",".php",".swift",".kt",".sh",".bash",".zsh",".fish",".sql",".graphql",".vue",".svelte",".css",".scss",".less",".html",".xml",".yaml",".yml",".toml",".json",".jsonc",".prisma",".proto",".lua",".zig",".ex",".exs",".erl",".hrl",".clj",".cljs",".hs",".ml",".mli",".r",".jl",".dart",".tf"]),aW=new Set([".png",".jpg",".jpeg",".gif",".bmp",".ico",".webp",".svg"]),oW=new Set([".mp3",".wav",".ogg"]),lW=new Set([".mp4",".webm"]),cW=new Set([".csv",".tsv",".json",".jsonc"]),TTe=new Set([".md",".txt",".pdf"]),MTe=new Set([...oW,...lW]),RTe=[{key:"all",label:"All"},{key:"documents",label:"Docs"},{key:"images",label:"Images"},{key:"code",label:"Code"},{key:"data",label:"Data"},{key:"media",label:"Media"}];function DTe(e){const t=e.includes(".")?`.${e.split(".").pop().toLowerCase()}`:"";return aW.has(t)?"images":rW.has(t)?"code":cW.has(t)?"data":MTe.has(t)?"media":(TTe.has(t),"documents")}function uW(e){const t=e.includes(".")?`.${e.split(".").pop().toLowerCase()}`:"";return aW.has(t)?r.jsx(fie,{className:"w-3.5 h-3.5 text-[#EC4899] flex-shrink-0"}):oW.has(t)?r.jsx(die,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}):lW.has(t)?r.jsx(mie,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}):cW.has(t)?r.jsx(gie,{className:"w-3.5 h-3.5 text-[#10B981] flex-shrink-0"}):rW.has(t)?r.jsx(aL,{className:"w-3.5 h-3.5 text-[#6366F1] flex-shrink-0"}):t===".md"?r.jsx(li,{className:"w-3.5 h-3.5 text-[#10B981] flex-shrink-0"}):r.jsx(gv,{className:"w-3.5 h-3.5 text-[#5A5A6E] flex-shrink-0"})}function DC(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function OTe(e){const t=new Date(e),s=new Date().getTime()-t.getTime(),i=Math.floor(s/6e4);if(i<1)return"just now";if(i<60)return`${i}m ago`;const a=Math.floor(i/60);if(a<24)return`${a}h ago`;const o=Math.floor(a/24);return o<30?`${o}d ago`:t.toLocaleDateString()}function dW(e,t,n){if(e.type==="file"){const s=!t||e.name.toLowerCase().includes(t.toLowerCase()),i=n==="all"||DTe(e.name)===n;return s&&i}return e.type==="dir"&&e.children?e.children.some(s=>dW(s,t,n)):!1}function hW(e,t,n){return!t&&n==="all"?e:e.filter(s=>dW(s,t,n)).map(s=>s.type==="dir"&&s.children?{...s,children:hW(s.children,t,n)}:s)}function fW(e){return[...e].sort((t,n)=>t.type==="dir"&&n.type!=="dir"?-1:t.type!=="dir"&&n.type==="dir"?1:new Date(n.modified).getTime()-new Date(t.modified).getTime()).map(t=>t.type==="dir"&&t.children?{...t,children:fW(t.children)}:t)}function pW({node:e,depth:t,agentId:n,mountSource:s,filter:i,onFileClick:a}){const o=e.type==="dir"&&(e.children?.length??0)>15,[l,c]=y.useState(()=>o?!1:t<1),d=i?!0:l,[f,p]=y.useState(!1),m=y.useCallback(()=>{e.type==="dir"?c(b=>!b):a(e.path,s)},[e,s,a]),g=e.type==="dir";return r.jsxs("div",{children:[r.jsxs("div",{onClick:m,onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),onContextMenu:b=>{b.preventDefault(),navigator.clipboard.writeText(e.path)},className:"flex items-center gap-1.5 py-[3px] pr-3 cursor-pointer hover:bg-white/[0.04] rounded-sm transition-colors group",style:{paddingLeft:`${12+t*16}px`},children:[g?r.jsxs(r.Fragment,{children:[r.jsx(ne.span,{animate:{rotate:d?90:0},transition:{duration:.1},className:"flex items-center justify-center w-3.5 h-3.5 flex-shrink-0",children:r.jsx(Jt,{className:"w-3 h-3 text-[#5A5A6E]"})}),d?r.jsx(vm,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"}):r.jsx(cL,{className:"w-3.5 h-3.5 text-[#F59E0B] flex-shrink-0"})]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"w-3.5 h-3.5 flex-shrink-0"}),uW(e.name)]}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] truncate flex-1",children:e.name}),f&&!g&&r.jsxs("span",{className:"text-[10px] text-[#5A5A6E] flex-shrink-0 whitespace-nowrap",children:[DC(e.size)," · ",OTe(e.modified)]})]}),g&&d&&e.children&&r.jsx(Me,{initial:!1,children:r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.1},className:"overflow-hidden",children:e.children.map(b=>r.jsx(pW,{node:b,depth:t+1,agentId:n,mountSource:s,filter:i,onFileClick:a},b.path))})})]})}function PTe({agentId:e,filePath:t,mountSource:n,onClose:s}){const{data:i,isLoading:a}=L.files.read.useQuery({agentId:e,filePath:t,mountSource:n},{retry:!1}),[o,l]=y.useState(!1);if(a)return r.jsx("div",{className:"border-t border-[#2A2A35] p-4",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]})});if(!i)return null;const c=t.split("/").pop()??t;return r.jsxs("div",{className:"border-t border-[#2A2A35] flex flex-col max-h-[60%] min-h-[120px]",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[uW(c),r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5] truncate",children:c}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:DC(i.size)})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[i.content&&r.jsx("button",{onClick:()=>{navigator.clipboard.writeText(i.content),l(!0),setTimeout(()=>l(!1),1500)},className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors",children:o?r.jsx(Fe,{className:"w-3 h-3 text-[#10B981]"}):r.jsx(Po,{className:"w-3 h-3"})}),r.jsx("button",{onClick:s,className:"text-[11px] text-[#5A5A6E] hover:text-[#C8C8D4] px-1.5 transition-colors",children:"Close"})]})]}),r.jsx("div",{className:"flex-1 overflow-auto min-h-0",children:"tooLarge"in i&&i.tooLarge?r.jsxs("div",{className:"p-4 text-center",children:[r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"File too large to preview."}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:DC(i.size)})]}):r.jsx(FTe,{agentId:e,filePath:t,content:i.content,binary:i.binary,size:i.size,ext:i.ext})})]})}function ITe({agentId:e}){const[t,n]=y.useState(""),[s,i]=y.useState("all"),[a,o]=y.useState(null),[l,c]=y.useState(null),d=y.useRef(null),f=y0(_=>_.openAgentFile),p=y.useCallback((_,w)=>{const A=_.split("/").pop()??_;_.endsWith(".md")&&!w?f(e,_):!w&&CU(A)?c(_):o({path:_,mountSource:w})},[e,f]),{data:m,isLoading:g}=L.files.tree.useQuery({agentId:e},{staleTime:1e4}),b=y.useMemo(()=>m?.roots?m.roots.map(_=>({..._,nodes:fW(hW(_.nodes,t,s))})):[],[m,t,s]);return y.useEffect(()=>{function _(w){w.key==="f"&&(w.metaKey||w.ctrlKey)&&(w.preventDefault(),d.current?.focus())}return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[]),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[r.jsxs("div",{className:"px-3 py-2 flex-shrink-0 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Io,{className:"w-3.5 h-3.5 text-[#5A5A6E] flex-shrink-0"}),r.jsx("input",{ref:d,value:t,onChange:_=>n(_.target.value),placeholder:"Filter files...",className:"flex-1 bg-transparent text-[12px] text-[#C8C8D4] placeholder-[#5A5A6E] outline-none"}),t&&r.jsx("button",{onClick:()=>n(""),className:"text-[10px] text-[#5A5A6E] hover:text-[#C8C8D4] transition-colors",children:"Clear"})]}),r.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:RTe.map(_=>r.jsx("button",{onClick:()=>i(_.key),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${s===_.key?"bg-[#6366F1]/20 text-[#818CF8] border border-[#6366F1]/30":"bg-white/[0.04] text-[#5A5A6E] border border-transparent hover:text-[#8A8A99] hover:bg-white/[0.06]"}`,children:_.label},_.key))})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[g&&r.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-4 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]}),!g&&b.length===0&&r.jsx("p",{className:"px-4 py-4 text-[12px] text-[#5A5A6E] italic",children:"No files found."}),b.map((_,w)=>r.jsxs("div",{children:[b.length>1&&r.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-[#2A2A35]/50",children:[r.jsx(bv,{className:"w-3 h-3 text-[#5A5A6E]"}),r.jsx("span",{className:"text-[11px] font-medium text-[#8A8A99]",children:_.label})]}),_.nodes.map(A=>r.jsx(pW,{node:A,depth:0,agentId:e,mountSource:b.length>1?_.source:void 0,filter:t,onFileClick:p},A.path)),_.nodes.length===0&&r.jsx("p",{className:"px-4 py-2 text-[11px] text-[#5A5A6E] italic",children:"Empty"})]},w))]}),a&&r.jsx(PTe,{agentId:e,filePath:a.path,mountSource:a.mountSource,onClose:()=>o(null)}),l&&r.jsx(yN,{agentId:e,filePath:l,onClose:()=>c(null)})]})}function LTe({agentId:e}){const{data:t=[],refetch:n}=L.git.worktreeList.useQuery({agentId:e}),{data:s=[]}=L.channels.list.useQuery(),a=s.find(c=>c.agentId===e)?.id??"",o=L.git.worktreeRemove.useMutation({onSuccess:()=>n()}),l=L.git.worktreeMerge.useMutation({onSuccess:()=>n()});return t.length===0?null:r.jsxs("div",{className:"mb-3",children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[r.jsx(Zl,{className:"w-3 h-3 text-[#8B5CF6]"}),r.jsx("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wider",children:"Worktrees"})]}),r.jsx("div",{className:"space-y-1",children:r.jsx(Me,{children:t.map(c=>r.jsxs(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-[#1C1C24] border border-[#2A2A35]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8B5CF6] flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] font-mono text-[#A78BFA] truncate block",children:c.branch}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] truncate block",children:c.worktreeDir})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[r.jsx("button",{onClick:()=>l.mutate({worktreeId:c.id,channelId:a}),disabled:l.isPending,className:"p-1 rounded text-[#34D399] hover:bg-[#10B981]/10 transition-colors disabled:opacity-50",title:"Merge back",children:r.jsx(D5,{className:"w-3 h-3"})}),r.jsx("button",{onClick:()=>o.mutate({worktreeId:c.id}),disabled:o.isPending,className:"p-1 rounded text-[#F87171] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-50",title:"Remove worktree",children:r.jsx(Dn,{className:"w-3 h-3"})})]})]},c.id))})})]})}function BTe({date:e}){const t=y.useMemo(()=>{const n=new Date(e),i=new Date().getTime()-n.getTime(),a=Math.floor(i/6e4);if(a<1)return"just now";if(a<60)return`${a}m ago`;const o=Math.floor(a/60);if(o<24)return`${o}h ago`;const l=Math.floor(o/24);return l<30?`${l}d ago`:n.toLocaleDateString()},[e]);return r.jsx("span",{children:t})}const zTe={modified:"text-[#F59E0B]",added:"text-[#10B981]",deleted:"text-[#EF4444]",renamed:"text-[#6366F1]",untracked:"text-[#5A5A6E]",staged:"text-[#10B981]"},$Te={modified:"M",added:"A",deleted:"D",renamed:"R",untracked:"?",staged:"S"};function e2({path:e,status:t,staged:n,selected:s,onSelect:i,onViewDiff:a}){const o=e.split("/").pop()??e,l=e.includes("/")?e.slice(0,e.lastIndexOf("/")+1):"";return r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 hover:bg-white/[0.04] transition-colors group",children:[r.jsx("button",{onClick:i,className:ye("w-4 h-4 rounded border flex items-center justify-center flex-shrink-0 transition-colors",s?"bg-[#6366F1] border-[#6366F1]":"border-[#3A3A4E] hover:border-[#5A5A6E]"),children:s&&r.jsx(Fe,{className:"w-2.5 h-2.5 text-white"})}),r.jsx("span",{className:ye("text-[10px] font-mono font-bold w-4 text-center flex-shrink-0",zTe[t]),children:$Te[t]??"?"}),r.jsxs("button",{onClick:a,className:"flex-1 min-w-0 text-left",children:[r.jsx("span",{className:"text-[12px] text-[#5A5A6E] font-mono",children:l}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] font-mono",children:o})]}),n&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#10B981]/10 text-[#10B981] font-medium flex-shrink-0",children:"staged"})]})}function VTe({agentId:e,selectedFiles:t,onCommitted:n}){const[s,i]=y.useState(""),a=L.git.commit.useMutation({onSuccess:()=>{i(""),n()}});return r.jsxs("div",{className:"px-3 py-2 border-t border-[#2A2A35]/50 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{value:s,onChange:o=>i(o.target.value),placeholder:"Commit message...",className:"flex-1 bg-[#1C1C21] border border-[#2A2A35] rounded-md px-2.5 py-1.5 text-[12px] text-[#C8C8D4] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1] transition-colors",onKeyDown:o=>{o.key==="Enter"&&s.trim()&&t.length>0&&a.mutate({agentId:e,message:s.trim(),files:t})}}),r.jsxs("button",{onClick:()=>a.mutate({agentId:e,message:s.trim(),files:t}),disabled:!s.trim()||t.length===0||a.isPending,className:ye("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[11px] font-medium transition-colors",s.trim()&&t.length>0?"bg-[#6366F1] text-white hover:bg-[#5558E6]":"bg-[#2A2A35] text-[#5A5A6E] cursor-not-allowed"),children:[a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(jie,{className:"w-3 h-3"}),"Commit"]})]}),t.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:[t.length," file",t.length!==1?"s":""," selected"]}),a.isError&&r.jsx("p",{className:"text-[10px] text-[#EF4444]",children:a.error.message})]})}function UTe({agentId:e,currentBranch:t}){const[n,s]=y.useState(!1),[i,a]=y.useState(!1),[o,l]=y.useState(""),{data:c=[]}=L.git.branches.useQuery({agentId:e},{enabled:n}),d=L.useUtils(),f=L.git.checkout.useMutation({onSuccess:()=>{s(!1),d.git.status.invalidate({agentId:e}),d.git.log.invalidate({agentId:e})}}),p=L.git.branch.useMutation({onSuccess:()=>{a(!1),l(""),s(!1),d.git.status.invalidate({agentId:e}),d.git.log.invalidate({agentId:e})}});return r.jsxs("div",{className:"relative",children:[r.jsxs("button",{onClick:()=>s(m=>!m),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] font-medium bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] text-[#C8C8D4] transition-colors",children:[r.jsx(Zl,{className:"w-3.5 h-3.5 text-[#6366F1]"}),r.jsx("span",{className:"truncate max-w-[140px]",children:t}),r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E]"})]}),r.jsx(Me,{children:n&&r.jsxs(ne.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:"absolute top-full left-0 mt-1 w-56 bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl z-50 overflow-hidden",children:[r.jsx("div",{className:"max-h-[200px] overflow-y-auto py-1",children:c.map(m=>r.jsxs("button",{onClick:()=>{m!==t&&f.mutate({agentId:e,branch:m})},className:ye("w-full flex items-center gap-2 px-3 py-1.5 text-[12px] text-left hover:bg-white/5 transition-colors",m===t?"text-[#6366F1]":"text-[#C8C8D4]"),children:[m===t&&r.jsx(Fe,{className:"w-3 h-3 flex-shrink-0"}),m!==t&&r.jsx("span",{className:"w-3 flex-shrink-0"}),r.jsx("span",{className:"truncate",children:m})]},m))}),r.jsx("div",{className:"border-t border-[#2A2A35] p-2",children:i?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("input",{value:o,onChange:m=>l(m.target.value),placeholder:"branch-name",autoFocus:!0,className:"flex-1 bg-[#13131A] border border-[#2A2A35] rounded px-2 py-1 text-[11px] text-[#C8C8D4] placeholder-[#5A5A6E] outline-none focus:border-[#6366F1]",onKeyDown:m=>{m.key==="Enter"&&o.trim()&&p.mutate({agentId:e,name:o.trim()}),m.key==="Escape"&&(a(!1),l(""))}}),r.jsx("button",{onClick:()=>{o.trim()&&p.mutate({agentId:e,name:o.trim()})},disabled:!o.trim()||p.isPending,className:"text-[#10B981] hover:text-[#34D399] transition-colors",children:p.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Fe,{className:"w-3.5 h-3.5"})}),r.jsx("button",{onClick:()=>{a(!1),l("")},className:"text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}):r.jsxs("button",{onClick:()=>a(!0),className:"flex items-center gap-1.5 w-full px-2 py-1 text-[11px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors rounded hover:bg-white/5",children:[r.jsx(wt,{className:"w-3 h-3"}),"New branch"]})})]})})]})}function HTe({agentId:e,filePath:t,onClose:n}){const{data:s,isLoading:i}=L.git.diff.useQuery({agentId:e,filePath:t},{retry:!1});return i?r.jsxs("div",{className:"border-t border-[#2A2A35] p-4 flex items-center gap-1.5 text-[#5A5A6E]",children:[r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),r.jsx("span",{className:"text-[11px]",children:"Loading diff..."})]}):s?r.jsxs("div",{className:"border-t border-[#2A2A35] flex flex-col max-h-[50%] min-h-[120px]",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(li,{className:"w-3.5 h-3.5 text-[#5A5A6E] flex-shrink-0"}),r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4] truncate",children:t})]}),r.jsx("button",{onClick:n,className:"text-[11px] text-[#5A5A6E] hover:text-[#C8C8D4] px-1.5 transition-colors",children:"Close"})]}),r.jsx("div",{className:"flex-1 overflow-auto min-h-0",children:r.jsx("pre",{className:"px-3 py-2 text-[11px] font-mono leading-[1.6] whitespace-pre-wrap break-all",children:s.split(`
354
- `).map((a,o)=>{let l="text-[#8A8A99]";return a.startsWith("+")&&!a.startsWith("+++")?l="text-[#34D399]":a.startsWith("-")&&!a.startsWith("---")?l="text-[#F87171]":a.startsWith("@@")&&(l="text-[#6366F1]"),r.jsx("div",{className:l,children:a||" "},o)})})})]}):r.jsxs("div",{className:"border-t border-[#2A2A35] p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4]",children:t}),r.jsx("button",{onClick:n,className:"text-[11px] text-[#5A5A6E] hover:text-[#C8C8D4] transition-colors",children:"Close"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] italic",children:"No changes to display."})]})}function WTe({agentId:e}){const[t,n]=y.useState(new Set),[s,i]=y.useState(null),a=L.useUtils(),{data:o,isLoading:l}=L.git.hasRepo.useQuery({agentId:e}),{data:c,isLoading:d}=L.git.status.useQuery({agentId:e},{enabled:!!o?.hasRepo,refetchInterval:1e4}),{data:f=[]}=L.git.log.useQuery({agentId:e,limit:10},{enabled:!!o?.hasRepo,refetchInterval:3e4}),p=y.useMemo(()=>c?[...c.staged.map(w=>({...w,category:"staged"})),...c.modified.map(w=>({...w,category:"modified"})),...c.untracked.map(w=>({...w,category:"untracked"}))]:[],[c]),m=y.useCallback(w=>{n(A=>{const S=new Set(A);return S.has(w)?S.delete(w):S.add(w),S})},[]),g=y.useCallback(()=>{n(new Set(p.map(w=>w.path)))},[p]),b=y.useCallback(()=>{n(new Set)},[]),_=y.useCallback(()=>{a.git.status.invalidate({agentId:e}),a.git.log.invalidate({agentId:e})},[a,e]);return l?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Pe,{className:"w-5 h-5 text-[#5A5A6E] animate-spin"})}):o?.hasRepo?r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:[c&&r.jsx(UTe,{agentId:e,currentBranch:c.branch}),r.jsx("button",{onClick:_,className:"p-1.5 rounded-md text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors",title:"Refresh",children:r.jsx(Xi,{className:ye("w-3.5 h-3.5",d&&"animate-spin")})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[r.jsx("div",{className:"px-3 pt-2",children:r.jsx(LTe,{agentId:e})}),d&&r.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-4 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]}),!d&&p.length===0&&f.length===0&&r.jsx("p",{className:"px-4 py-4 text-[12px] text-[#5A5A6E] italic",children:"Working tree clean. No changes."}),p.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:["Changes (",p.length,")"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:g,className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"All"}),r.jsx("button",{onClick:b,className:"text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"None"})]})]}),c?.staged&&c.staged.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#10B981] uppercase tracking-widest",children:"Staged"}),c.staged.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!0,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`staged-${w.path}`))]}),c?.modified&&c.modified.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#F59E0B] uppercase tracking-widest",children:"Modified"}),c.modified.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!1,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`modified-${w.path}`))]}),c?.untracked&&c.untracked.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:"Untracked"}),c.untracked.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!1,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`untracked-${w.path}`))]})]}),f.length>0&&r.jsxs("div",{className:"mt-2",children:[r.jsx("p",{className:"px-3 py-1.5 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest border-t border-[#2A2A35]/50",children:"Recent commits"}),f.map(w=>r.jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-white/[0.02] transition-colors",children:[r.jsx(Hse,{className:"w-2 h-2 text-[#5A5A6E] mt-1 flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] text-[#C8C8D4] truncate",children:w.message}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:[r.jsx("code",{className:"text-[#6366F1]",children:w.shortHash}),r.jsx("span",{className:"mx-1",children:"·"}),w.author,r.jsx("span",{className:"mx-1",children:"·"}),r.jsx(BTe,{date:w.date})]})]})]},w.hash))]})]}),s&&r.jsx(HTe,{agentId:e,filePath:s,onClose:()=>i(null)}),p.length>0&&r.jsx(VTe,{agentId:e,selectedFiles:[...t],onCommitted:()=>{n(new Set),_()}})]}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-5 gap-2",children:[r.jsx(Zl,{className:"w-8 h-8 text-[#3A3A45]"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic text-center",children:"No git repository detected"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] text-center",children:"Mount a project directory with a git repo in Settings → File Access."})]})}function qTe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const s=Math.floor(n/60);if(s<60)return`${s} min ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function GTe(e){return new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function KTe(e){const t=new Date(e).getTime()-Date.now();if(t<=0)return"eligible now";const n=Math.floor(t/(3600*1e3)),s=Math.floor(t%(3600*1e3)/(60*1e3));return n>0?`~${n}h ${s}m`:`~${s}m`}function YTe({agentId:e}){const{data:t}=L.dream.status.useQuery({agentId:e},{staleTime:3e4}),n=t?.[e];return n?r.jsxs("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(_L,{className:"w-3.5 h-3.5 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5]",children:"Dream Status"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-y-1.5 text-[11px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Last dream"}),r.jsx("span",{className:"text-[#C8C8D4]",children:qTe(n.lastDreamAt)}),r.jsx("span",{className:"text-[#8A8A99]",children:"Notes changed"}),r.jsx("span",{className:"text-[#C8C8D4]",children:n.lastDreamNotesChanged}),r.jsx("span",{className:"text-[#8A8A99]",children:"Cost"}),r.jsxs("span",{className:"text-[#10B981]",children:["$",n.lastDreamCostUsd.toFixed(4)]}),r.jsx("span",{className:"text-[#8A8A99]",children:"Next eligible"}),r.jsx("span",{className:"text-[#C8C8D4]",children:KTe(n.nextDreamEstimate)})]})]}):r.jsx("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:r.jsx("p",{className:"text-[12px] text-[#5A5A6E] italic",children:"No dream data yet. Trigger a dream to start memory consolidation."})})}function QTe({preferences:e}){return e.length===0?null:r.jsxs("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#F0F0F5] mb-2",children:"Routing Preferences"}),r.jsx("div",{className:"space-y-2",children:e.map((t,n)=>r.jsxs("div",{className:"flex items-start gap-2 text-[11px]",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[#C8C8D4]",children:t.taskPattern}),r.jsxs("p",{className:"text-[#5A5A6E] mt-0.5",children:["→ ",t.preferredAgentId," — ",t.reason]})]}),r.jsxs("span",{className:`flex-shrink-0 px-1.5 py-0.5 rounded text-[10px] font-medium ${t.confidence>=.8?"bg-[#10B981]/15 text-[#10B981]":t.confidence>=.5?"bg-[#F59E0B]/15 text-[#F59E0B]":"bg-[#EF4444]/15 text-[#EF4444]"}`,children:[(t.confidence*100).toFixed(0),"%"]})]},n))})]})}function XTe({entries:e}){return e.length===0?r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4 text-center italic",children:"No dream history."}):r.jsxs("div",{className:"relative",children:[e.length>0&&r.jsx("div",{className:"absolute left-[9px] top-0 bottom-0 w-px bg-[#2A2A35]"}),r.jsx("div",{className:"space-y-0",children:e.map(t=>r.jsxs("div",{className:"flex gap-3 py-2.5 relative",children:[r.jsx("div",{className:"w-5 h-5 rounded-full bg-[#1C1C24] border border-[#2A2A35] flex items-center justify-center text-[10px] flex-shrink-0 z-10 mt-0.5",children:"💤"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("p",{className:"text-[12px] text-[#C8C8D4] leading-snug",children:["+",t.notesAdded," added · ",t.notesMerged," merged · ",t.notesPruned," pruned",t.constraintsFlagged.length>0&&r.jsxs("span",{className:"text-[#F59E0B]",children:[" · ",t.constraintsFlagged.length," flagged"]})]}),t.constraintsFlagged.length>0&&r.jsx("div",{className:"mt-1 space-y-0.5",children:t.constraintsFlagged.map((n,s)=>r.jsxs("p",{className:"text-[10px] text-[#F59E0B]/80",children:["⚠ ",n]},s))}),t.agentHealthNotes&&t.agentHealthNotes.length>0&&r.jsx("div",{className:"mt-1 space-y-0.5",children:t.agentHealthNotes.map((n,s)=>r.jsxs("p",{className:"text-[10px] text-[#8A8A99]",children:[n.agentId,": ",n.observation]},s))}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:[GTe(t.ts),t.durationMs!=null&&` · ${Math.round(t.durationMs/1e3)}s`,t.costEstimateUsd>0&&` · $${t.costEstimateUsd.toFixed(4)}`]})]})]},t.id))})]})}function JTe({agentId:e}){const[t,n]=y.useState(!1),{data:s=[],isLoading:i}=L.dream.history.useQuery({agentId:e,limit:20},{refetchInterval:3e4}),a=L.useUtils(),o=y.useRef(0);o.current=s.length;const l=L.dream.trigger.useMutation({onSuccess:f=>{if(!f.started){n(!1);return}const p=o.current,m=setInterval(async()=>{await a.dream.history.invalidate({agentId:e}),await a.dream.status.invalidate({agentId:e});const g=a.dream.history.getData({agentId:e,limit:20});g&&g.length>p&&(clearInterval(m),n(!1))},4e3);setTimeout(()=>{clearInterval(m),n(!1)},12e4)},onError:()=>n(!1)}),c=e==="coo",d=c?s.find(f=>f.routingPreferences&&f.routingPreferences.length>0)?.routingPreferences??[]:[];return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[r.jsx(YTe,{agentId:e}),c&&d.length>0&&r.jsx(QTe,{preferences:d}),r.jsxs("div",{className:"px-4 mt-3 flex-shrink-0",children:[r.jsxs("button",{onClick:()=>{n(!0),l.mutate({agentId:e})},disabled:t||l.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#6366F1] text-white hover:bg-[#5558E6] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[t||l.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(_L,{className:"w-3 h-3"}),t?"Dreaming...":"Trigger Dream"]}),l.data&&!l.data.started&&r.jsx("p",{className:"text-[10px] text-[#F59E0B] mt-1",children:l.data.reason})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4 mt-3",children:[i&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4 text-center",children:"Loading..."}),!i&&r.jsx(XTe,{entries:s})]})]})}const ZTe=["complexity:low","complexity:medium","complexity:high","task:code","task:creative","task:analysis","task:tool_use"];function Gb({value:e,onChange:t,customModels:n=[],agentId:s}){const[i,a]=y.useState(""),o=L.useUtils(),l=L.agents.addCustomModel.useMutation({onSuccess:()=>o.agents.list.invalidate()}),c=L.agents.removeCustomModel.useMutation({onSuccess:()=>o.agents.list.invalidate()}),{groups:d}=Vm(),f=Up(e);return r.jsxs(ss,{value:e,onValueChange:t,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors min-w-[140px]",children:[r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[f]}`,children:f}),r.jsx(Ds,{children:ta(e)}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] max-h-[280px] overflow-y-auto z-[9999]",children:[s&&r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:i,onChange:a,onSubmit:p=>{s&&(l.mutate({agentId:s,modelId:p}),t(p),a(""))},placeholder:"Type model ID..."})}),r.jsxs(os,{children:[d.map(p=>r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:p.label}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo[p.tag]}`,children:p.tag})]}),p.models.map(m=>r.jsxs(vn,{value:m.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:m.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},m.id))]},p.label)),n.length>0&&r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:"Custom"}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo.custom}`,children:"custom"})]}),n.map(p=>r.jsxs(vn,{value:p,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:p}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})}),s&&r.jsx(bt,{label:"Remove model",children:r.jsx("button",{onClick:m=>{m.stopPropagation(),c.mutate({agentId:s,modelId:p})},className:"text-[#5A5A6E] hover:text-[#F87171] transition-colors",children:r.jsx(Te,{className:"w-3 h-3"})})})]})]},p))]})]})]})})]})}function eMe({value:e,onChange:t}){return r.jsxs(ss,{value:e,onValueChange:t,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors min-w-[150px]",children:[r.jsx(Ds,{children:e}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[170px] z-[9999]",children:r.jsx(os,{children:ZTe.map(n=>r.jsxs(vn,{value:n,className:"flex items-center justify-between px-3 py-2 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:n}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},n))})})})]})}function tMe(e,t){if(t.length===0)return`Always uses ${ta(e)}.`;const n=t.map(s=>`For ${s.condition} → ${ta(s.model)}`);return n.push(`For everything else → ${ta(e)}`),n.join(". ")+"."}function nMe({fallbacks:e,onAdd:t,onRemove:n,customModels:s,agentId:i}){const[a,o]=y.useState(!1),[l,c]=y.useState("");function d(){l&&(t(l),c(""),o(!1))}return r.jsxs("div",{className:"space-y-2",children:[e.map((f,p)=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-[11px] text-[#5A5A6E] w-4 flex-shrink-0",children:[p+1,"."]}),r.jsx("span",{className:"flex-1 text-[12px] text-[#C8C8D4] truncate",children:ta(f)}),r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[Up(f)]}`,children:Up(f)}),r.jsx("button",{onClick:()=>n(p),className:"w-5 h-5 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Te,{className:"w-3 h-3"})})]},p)),a?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Gb,{value:l||"qwen3:14b",onChange:c,customModels:s,agentId:i}),r.jsx("button",{onClick:d,className:"text-[11px] text-[#10B981] hover:text-[#34D399] font-medium transition-colors",children:"Add"}),r.jsx("button",{onClick:()=>o(!1),className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Cancel"})]}):r.jsxs("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add fallback"]})]})}const sMe=[{id:"__default__",label:"Workspace default"},{id:"openclaw",label:"OpenClaw"},{id:"anthropic",label:"Anthropic"},{id:"claude-code",label:"Claude Code"},{id:"ollama",label:"Ollama"},{id:"openrouter",label:"OpenRouter"}];function iMe({agentId:e}){const{data:t}=L.agents.getGateway.useQuery({agentId:e}),n=L.useUtils(),s=L.agents.setGateway.useMutation({onSuccess:()=>n.agents.getGateway.invalidate({agentId:e})}),i=t?.gatewayId||"__default__";return r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Runtime"}),r.jsxs(ss,{value:i,onValueChange:a=>s.mutate({agentId:e,gatewayId:a==="__default__"?null:a}),children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#1C1C21] text-[13px] text-[#F0F0F5] hover:bg-[#2A2A35] transition-colors",children:[r.jsx(Ds,{}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C21] border border-[#2A2A35] rounded-lg shadow-xl z-[9999] overflow-hidden",children:r.jsx(os,{className:"p-1",children:sMe.map(a=>r.jsxs(vn,{value:a.id,className:"flex items-center gap-2 px-3 py-2 rounded text-[13px] text-[#F0F0F5] cursor-pointer outline-none data-[highlighted]:bg-[#2A2A35]",children:[r.jsx(yn,{children:a.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"})})]},a.id))})})})]})]})}function rMe({agent:e,agentColor:t}){const{data:n}=L.onboarding.getState.useQuery(void 0,{staleTime:3e4,refetchOnWindowFocus:!1}),s=(()=>{try{return e.customModels?JSON.parse(e.customModels):[]}catch{return[]}})(),i=s[0]??null,a=n?.defaultReasoningModel??i??"qwen3:14b",o=!e.defaultModel&&!n?.defaultReasoningModel,[l,c]=y.useState(e.defaultModel??a),[d,f]=y.useState(()=>{try{return e.modelRules?JSON.parse(e.modelRules):[]}catch{return[]}}),p=s,[m,g]=y.useState("idle"),b=y.useRef(null),_=L.useUtils(),w=L.agents.setModelConfig.useMutation({onSuccess:()=>{_.agents.list.invalidate(),_.agents.getFallbackModels.invalidate({agentId:e.id})}}),A=e.gatewayId??n?.gatewayType??"openclaw",S=A==="openclaw"||A==="openrouter",{data:C}=L.agents.getFallbackModels.useQuery({agentId:e.id},{enabled:S}),[E,k]=y.useState(null),T=E??C?.agent??[],F=C?.defaults??[],M=T.length===0&&F.length>0,[I,R]=y.useState(e.fallbackModel??null);y.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const H=[{label:"Local",description:"Free · Fully offline",defaultModel:"qwen3:14b",rules:[{condition:"task:tool_use",model:"tomng/nanbeige4.1"}]},{label:"Hybrid",description:"Smart routing · Best bang for buck",defaultModel:"qwen3:14b",rules:[{condition:"task:tool_use",model:"tomng/nanbeige4.1"},{condition:"task:code",model:"claude-sonnet-4.6"},{condition:"complexity:high",model:"claude-opus-4.6"}]}];function V(W){c(W.defaultModel),f(W.rules)}function K(){f(W=>[...W,{condition:"complexity:high",model:"claude-sonnet-4.6"}])}function q(W){f(O=>O.filter((D,Q)=>Q!==W))}function $(W,O){f(D=>D.map((Q,z)=>z===W?{...Q,...O}:Q))}function B(W){k([...T,W])}function Y(W){k(T.filter((O,D)=>D!==W))}async function U(){g("saving"),await w.mutateAsync({agentId:e.id,defaultModel:l,modelRules:d,customModels:p,...S?{fallbackModels:E??void 0}:{fallbackModel:I}}),g("saved"),k(null),b.current=setTimeout(()=>g("idle"),2e3)}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-4 overflow-y-auto",children:[o&&r.jsx("div",{className:"flex items-start gap-2 px-3 py-2.5 rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20",children:r.jsx("span",{className:"text-[#F59E0B] text-[13px] leading-snug",children:"No model configured. Visit Settings → Models to set one."})}),r.jsx(iMe,{agentId:e.id}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Default Model"}),r.jsx(Gb,{value:l,onChange:c,customModels:p,agentId:e.id})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Presets"}),r.jsx("div",{className:"flex gap-2",children:H.map(W=>r.jsxs("button",{onClick:()=>V(W),className:"flex-1 rounded-lg border border-[#2A2A35] bg-[#1C1C21] hover:bg-[#2A2A35] transition-colors px-3 py-2 text-left",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#F0F0F5]",children:W.label}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:W.description})]},W.label))})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Routing Rules"}),r.jsx("div",{className:"space-y-2",children:d.map((W,O)=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(eMe,{value:W.condition,onChange:D=>$(O,{condition:D})}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E] flex-shrink-0",children:"→"}),r.jsx(Gb,{value:W.model,onChange:D=>$(O,{model:D}),customModels:p,agentId:e.id}),r.jsx(bt,{label:"Remove rule",children:r.jsx("button",{onClick:()=>q(O),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]},O))}),r.jsxs("button",{onClick:K,className:"mt-3 flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add rule"]})]}),S?r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Fallback Models"})]}),M&&T.length===0&&r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] mb-2",children:["Inheriting from defaults: ",F.map(ta).join(", ")]}),r.jsx(nMe,{fallbacks:T,onAdd:B,onRemove:Y,customModels:p,agentId:e.id}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-2",children:["Handled natively by ",A==="openclaw"?"OpenClaw":"OpenRouter","."]})]}):r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Fallback Model"})]}),I?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Gb,{value:I,onChange:W=>R(W),customModels:p,agentId:e.id}),r.jsx(bt,{label:"Remove fallback",children:r.jsx("button",{onClick:()=>R(null),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})})]}):r.jsxs("button",{onClick:()=>R(l),className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add fallback"]}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-2",children:"Used when the primary model is rate-limited or unavailable."})]}),r.jsx("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] px-3 py-2.5",children:r.jsx("p",{className:"text-[11px] text-[#8A8A99] italic leading-relaxed",children:tMe(l,d)})}),r.jsx("button",{onClick:U,disabled:w.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium transition-colors disabled:opacity-50",style:{backgroundColor:t,color:"#fff"},children:r.jsxs(Me,{mode:"wait",children:[m==="saving"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saving..."},"saving"),m==="saved"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved ✓"},"saved"),m==="idle"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")]})})]})}const aMe={"Be brief":"Keep all responses under 3 sentences. Be direct.","Be creative":"Be imaginative, use analogies, think laterally.","Be strict":"Only respond with facts. No speculation. Cite reasoning."};function mW(e,t=500){const[n,s]=y.useState("idle"),i=y.useRef(null),a=y.useRef(null);y.useEffect(()=>()=>{i.current&&clearTimeout(i.current),a.current&&clearTimeout(a.current)},[]);const o=y.useCallback(l=>{l!==void 0&&(i.current&&clearTimeout(i.current),a.current&&clearTimeout(a.current),s("saving"),i.current=setTimeout(async()=>{await e(l),s("saved"),a.current=setTimeout(()=>s("idle"),2e3)},t))},[e,t]);return{saveState:n,handleChange:o}}function xW({saveState:e}){return r.jsxs(Me,{mode:"wait",children:[e==="saving"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[11px] text-[#8A8A99]",children:"Saving..."},"saving"),e==="saved"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[11px] text-[#10B981]",children:"Saved ✓"},"saved")]})}const Q8={gateway:{label:"Gateway",color:"#3B82F6"},harness:{label:"Claude Code",color:"#8B5CF6"},terminal:{label:"Terminal",color:"#10B981"}};function oMe({agentId:e}){const{data:t}=L.events.activeRuntimes.useQuery({agentId:e},{staleTime:3e4,refetchInterval:3e4});return!t||t.length===0?null:r.jsx("div",{className:"flex items-center gap-1 ml-1",children:t.map(n=>{const s=Q8[n.source]??Q8.gateway,a=`Last active ${lMe(n.lastActiveAt)}${n.project?` via ${s.label} on ${n.project}`:` via ${s.label}`}`;return r.jsx(bt,{label:a,side:"bottom",children:r.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:s.color}})},n.source)})})}function lMe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const s=Math.floor(n/60);if(s<60)return`${s} min ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function cMe({status:e,color:t}){const n=e==="thinking"||e==="executing";return r.jsxs("span",{className:"relative flex items-center justify-center w-2 h-2",children:[n&&r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:t,opacity:.5},animate:{scale:[1,2.2,1],opacity:[.5,0,.5]},transition:{duration:1.8,repeat:1/0}}),r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e==="offline"?"#3A3A45":t,opacity:e==="idle"?.5:1}})]})}function uMe({agentId:e}){const{data:t}=L.agents.getSoul.useQuery({agentId:e}),n=L.agents.saveSoul.useMutation(),{saveState:s,handleChange:i}=mW(y.useCallback(a=>n.mutateAsync({agentId:e,content:a}),[e,n]));return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-visible",children:[r.jsx("div",{className:"flex items-center justify-end h-7 px-3 flex-shrink-0",children:r.jsx(xW,{saveState:s})}),r.jsx("div",{className:"flex-1 min-h-0",children:t?.content!==void 0&&r.jsx(VU,{height:"100%",defaultLanguage:"markdown",defaultValue:t.content??"",theme:"vs-dark",onChange:i,options:{minimap:{enabled:!1},wordWrap:"on",lineNumbers:"off",fontSize:13,scrollBeyondLastLine:!1,padding:{top:8,bottom:16},automaticLayout:!0,fixedOverflowWidgets:!0}})})]})}function dMe({agentId:e}){const{data:t}=L.agents.getTeam.useQuery({agentId:e}),n=L.agents.saveTeam.useMutation(),{saveState:s,handleChange:i}=mW(y.useCallback(a=>n.mutateAsync({agentId:e,content:a}),[e,n]));return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-visible",children:[r.jsx("div",{className:"flex items-center justify-end h-7 px-3 flex-shrink-0",children:r.jsx(xW,{saveState:s})}),r.jsx("div",{className:"flex-1 min-h-0",children:t?.content!==void 0&&r.jsx(VU,{height:"100%",defaultLanguage:"markdown",defaultValue:t.content??"",theme:"vs-dark",onChange:i,options:{minimap:{enabled:!1},wordWrap:"on",lineNumbers:"off",fontSize:13,scrollBeyondLastLine:!1,padding:{top:8,bottom:16},automaticLayout:!0,fixedOverflowWidgets:!0}})})]})}const hMe={healthy:"#10B981",degraded:"#F59E0B",failing:"#EF4444"};function fMe({health:e,detail:t}){const[n,s]=y.useState(!1),i=hMe[e.health]??"#5A5A6E";return r.jsxs("span",{className:"relative",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[r.jsx("span",{className:"inline-block w-2 h-2 rounded-full",style:{backgroundColor:i}}),n&&r.jsx("span",{className:"absolute top-full left-0 mt-1.5 px-2 py-1 rounded bg-[#1C1C24] border border-[#2A2A35] text-[10px] text-[#C8C8D4] whitespace-nowrap z-50 shadow-lg",children:t})]})}function pMe({agentId:e}){const{data:t=[]}=L.skills.getAgentSkills.useQuery({agentId:e}),{data:n={}}=L.events.skillHealth.useQuery({agentId:e},{refetchInterval:3e4}),{data:s={}}=L.events.skillComposition.useQuery({agentId:e},{refetchInterval:6e4}),i=L.useUtils(),a=L.skills.toggleAgentSkill.useMutation({onMutate:async({agentId:d,skillId:f,enabled:p})=>{await i.skills.getAgentSkills.cancel({agentId:d});const m=i.skills.getAgentSkills.getData({agentId:d});return i.skills.getAgentSkills.setData({agentId:d},g=>g&&g.map(b=>b.skillId===f?{...b,enabled:p}:b)),{prev:m}},onError:(d,{agentId:f},p)=>{p?.prev&&i.skills.getAgentSkills.setData({agentId:f},p.prev)}});if(t.length===0)return r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-5 gap-2",children:[r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No skills installed for this agent."}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"Go to Skills to install and assign."})]});const o=t.every(d=>d.enabled);function l(){const d=!o;t.forEach(f=>a.mutate({agentId:e,skillId:f.skillId,enabled:d}))}const c=new Map(t.map(d=>[d.skill.slug,d.skill.name]));return r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:[t.length," skill",t.length!==1?"s":""]}),r.jsx("button",{onClick:l,className:"text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:o?"Disable all":"Enable all"})]}),t.map(d=>{const f=n[d.skill.id]??n[d.skill.slug]??n[d.skill.name],p=s[d.skill.id]??s[d.skill.slug]??s[d.skill.name],m=f?`${f.successCount}/${f.totalCount} succeeded${f.avgDurationMs!=null?` · avg ${f.avgDurationMs}ms`:""}`:void 0;return r.jsxs("div",{className:"py-2.5 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[f&&r.jsx(fMe,{health:f,detail:m}),r.jsx("span",{className:"text-[13px] transition-all",style:{color:d.enabled?"#C8C8D4":"#5A5A6E",textDecoration:d.enabled?"none":"line-through"},children:d.skill.name})]}),r.jsx(Sh,{checked:d.enabled,onCheckedChange:g=>a.mutate({agentId:e,skillId:d.skillId,enabled:g}),className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35]",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]}),p&&p.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-1 ml-4",children:["Used together with ",p.map(g=>c.get(g)??g).join(", ")]})]},d.skillId)})]})}function mMe({agentId:e,onOverrideSet:t,onClose:n}){const{data:s}=L.agents.getOverride.useQuery({agentId:e}),i=L.agents.setOverride.useMutation(),[a,o]=y.useState("");y.useEffect(()=>{s?.override!==void 0&&o(s.override??"")},[s?.override]);async function l(){await i.mutateAsync({agentId:e,instruction:a}),t(a.trim()||null),n()}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-3",children:[r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[Object.entries(aMe).map(([c,d])=>r.jsx("button",{onClick:()=>o(d),className:"px-3 py-1 rounded-md text-[12px] bg-white/5 text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-[#2A2A35] hover:border-[#3A3A45]",children:c},c)),r.jsx("button",{onClick:()=>o(""),className:"px-3 py-1 rounded-md text-[12px] bg-white/5 text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-[#2A2A35] hover:border-[#3A3A45]",children:"Clear"})]}),r.jsx("textarea",{value:a,onChange:c=>o(c.target.value),rows:5,placeholder:"Add a temporary instruction for this session...",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2.5 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] resize-none outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("button",{onClick:l,disabled:i.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:"Set Override"})]})}const xMe=[{value:"15m",label:"Every 15 minutes"},{value:"30m",label:"Every 30 minutes"},{value:"1h",label:"Every hour"},{value:"3h",label:"Every 3 hours"},{value:"6h",label:"Every 6 hours"},{value:"12h",label:"Every 12 hours"},{value:"1d",label:"Daily"},{value:"2d",label:"Every 2 days"},{value:"7d",label:"Weekly"},{value:"custom",label:"Custom…"}];function gMe(e){return!e||e==="24h"?"1d@09:00":e==="48h"?"2d@09:00":e}function bMe(e){const t={preset:"1d",customValue:4,customUnit:"h",utcHour:9,utcMinute:0};if(e==="15m")return{...t,preset:"15m"};if(e==="30m")return{...t,preset:"30m"};const n=e.match(/^(\d+)h$/);if(n){const i=parseInt(n[1],10),a={1:"1h",3:"3h",6:"6h",12:"12h"};return a[i]?{...t,preset:a[i]}:{...t,preset:"custom",customValue:i,customUnit:"h"}}const s=e.match(/^(\d+)d@(\d{1,2}):(\d{2})$/);if(s){const i=parseInt(s[1],10),a=parseInt(s[2],10),o=parseInt(s[3],10);return{preset:{1:"1d",2:"2d",7:"7d"}[i]??"custom",customValue:i,customUnit:"d",utcHour:a,utcMinute:o}}return t}function vMe(e){return e.preset==="15m"||e.preset==="30m"||e.preset==="1h"||e.preset==="3h"||e.preset==="6h"||e.preset==="12h"?e.preset:e.preset==="1d"?`1d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="2d"?`2d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="7d"?`7d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="custom"?e.customUnit==="d"?`${e.customValue}d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:`${e.customValue}${e.customUnit}`:"1d@09:00"}function yMe(e,t){return e==="1d"||e==="2d"||e==="7d"||e==="custom"&&t==="d"}function gW(e,t){const n=new Date;return n.setUTCHours(e,t,0,0),{hour:n.getHours(),minute:n.getMinutes()}}function _Me(e,t){const n=new Date;return n.setHours(e,t,0,0),{hour:n.getUTCHours(),minute:n.getUTCMinutes()}}function wMe(e){if(e.preset==="custom"){if(e.customUnit==="m")return`Runs every ${e.customValue} minute${e.customValue===1?"":"s"}`;if(e.customUnit==="h")return`Runs every ${e.customValue} hour${e.customValue===1?"":"s"}`;const t=gW(e.utcHour,e.utcMinute);return`Runs every ${e.customValue} day${e.customValue===1?"":"s"} at ${String(t.hour).padStart(2,"0")}:${String(t.minute).padStart(2,"0")} local`}return""}function AMe({agentId:e}){const{data:t,refetch:n,isLoading:s}=L.agents.terminalInsights.useQuery({agentId:e}),i=L.agents.compactTerminalKnowledge.useMutation({onSuccess:()=>n()}),a=L.agents.clearTerminalKnowledge.useMutation({onSuccess:()=>n()}),o=t?.content??"";return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-4 overflow-auto",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Terminal Insights"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>i.mutate({agentId:e}),disabled:i.isPending,className:"px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:i.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Compact now"}),o&&r.jsx("button",{onClick:()=>a.mutate({agentId:e}),disabled:a.isPending,className:"px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#2A2A35] hover:bg-[#3A3A4E] text-[#C8C8D4] transition-colors disabled:opacity-50",children:a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Clear"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:"Terminal session summaries are stored in daily memory files. Compacting extracts lasting patterns into KNOWLEDGE.md."}),s?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Pe,{className:"w-5 h-5 animate-spin text-[#5A5A6E]"})}):o?r.jsx("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-lg p-4 text-[12px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap font-mono",children:o}):r.jsx("div",{className:"text-center py-8 text-[12px] text-[#5A5A6E]",children:"No terminal insights yet. Assign an agent to a terminal, run some commands, then compact."})]})}function SMe({agentId:e}){const{data:t}=L.agents.getHeartbeat.useQuery({agentId:e}),n=L.agents.setHeartbeat.useMutation(),[s,i]=y.useState(!1),[a,o]=y.useState("1d"),[l,c]=y.useState(4),[d,f]=y.useState("h"),[p,m]=y.useState(9),[g,b]=y.useState(0),[_,w]=y.useState("idle"),[A,S]=y.useState(null),C=y.useRef(null);y.useEffect(()=>{if(t){i(t.enabled);const I=bMe(gMe(t.every));o(I.preset),c(I.customValue),f(I.customUnit);const R=gW(I.utcHour,I.utcMinute);m(R.hour),b(R.minute)}},[t]),y.useEffect(()=>()=>{C.current&&clearTimeout(C.current)},[]);const E=yMe(a,d),k=y.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"local"}},[]),T=y.useMemo(()=>{const I=_Me(p,g),R={preset:a,customValue:l,customUnit:d,utcHour:I.hour,utcMinute:I.minute};return{every:vMe(R),description:wMe(R)}},[a,l,d,p,g]);async function F(){S(null);try{await n.mutateAsync({agentId:e,enabled:s,every:T.every}),w("saved"),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>w("idle"),2e3)}catch(I){w("error"),S(I instanceof Error?I.message:"Failed to save")}}const M=a!=="custom"||(d==="m"?l>=1&&l<=59:d==="h"?l>=1&&l<=23:l>=1&&l<=7);return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:"Heartbeat"}),r.jsx(Sh,{checked:s,onCheckedChange:i,className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35]",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]}),s&&r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Frequency"}),r.jsxs(ss,{value:a,onValueChange:I=>o(I),children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors w-full",children:[r.jsx(Ds,{}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] max-h-[280px] overflow-y-auto z-[9999]",children:r.jsx(os,{children:xMe.map(I=>r.jsxs(vn,{value:I.value,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:I.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},I.value))})})})]})]}),a==="custom"&&r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Every"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:1,max:d==="m"?59:d==="h"?23:7,value:l,onChange:I=>c(Math.max(1,parseInt(I.target.value||"1",10))),className:"w-20 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors"}),r.jsxs(ss,{value:d,onValueChange:I=>f(I),children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors flex-1",children:[r.jsx(Ds,{}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[140px] z-[9999]",children:r.jsx(os,{children:[{v:"m",label:"minutes"},{v:"h",label:"hours"},{v:"d",label:"days"}].map(I=>r.jsxs(vn,{value:I.v,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:I.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},I.v))})})})]})]}),!M&&r.jsx("p",{className:"text-[11px] text-[#F25757]",children:d==="m"?"Minutes must be 1–59":d==="h"?"Hours must be 1–23":"Days must be 1–7"})]}),E&&r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Time of day"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:0,max:23,value:p,onChange:I=>m(Math.max(0,Math.min(23,parseInt(I.target.value||"0",10)))),className:"w-16 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors text-center"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6E]",children:":"}),r.jsx("input",{type:"number",min:0,max:59,value:g,onChange:I=>b(Math.max(0,Math.min(59,parseInt(I.target.value||"0",10)))),className:"w-16 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors text-center"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:k})]})]})]}),r.jsxs("p",{className:"text-[12px] text-[#5A5A6E] leading-relaxed",children:["When active, your agent runs its HEARTBEAT.md at this interval — reviewing memory, running research loops, and evolving over time.",E&&r.jsxs(r.Fragment,{children:[r.jsx("br",{}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"Note: time is stored in UTC. Daylight saving changes may shift local display by ±1 hour."})]})]}),A&&_==="error"&&r.jsx("p",{className:"text-[11px] text-[#F25757]",children:A}),r.jsx("button",{onClick:F,disabled:n.isPending||s&&!M,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:r.jsx(Me,{mode:"wait",children:_==="saved"?r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved ✓"},"saved"):r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")})})]})}function CMe({agentId:e}){const t=L.agents.getTrust.useQuery({agentId:e}),n=L.agents.getSandboxOverride.useQuery({agentId:e}),s=L.agents.getMounts.useQuery({agentId:e}),i=L.agents.setAutoApprove.useMutation({onSuccess:()=>t.refetch()}),a=L.agents.setShellAllowlist.useMutation({onSuccess:()=>t.refetch()}),o=L.agents.setSandboxOverride.useMutation({onSuccess:()=>n.refetch()}),l=L.agents.addMount.useMutation({onSuccess:()=>s.refetch()}),c=L.agents.removeMount.useMutation({onSuccess:()=>s.refetch()}),[d,f]=y.useState(!1),[p,m]=y.useState(!1),[g,b]=y.useState(""),[_,w]=y.useState(!1),[A,S]=y.useState(""),[C,E]=y.useState(""),T=L.agents.getRunMode.useQuery().data?.mode==="docker";y.useEffect(()=>{t.data&&(b(t.data.shellAllowlist?t.data.shellAllowlist.join(", "):""),w(!1))},[t.data]);const F=t.data?.autoApprove??!1;function M(B){B?(f(!0),m(!0)):i.mutate({agentId:e,enabled:!1})}function I(){i.mutate({agentId:e,enabled:!0}),m(!1),f(!1)}function R(){m(!1),f(!1)}function H(B){b(B),w(!0)}function V(){const B=g.trim(),Y=B?B.split(",").map(U=>U.trim()).filter(Boolean):null;a.mutate({agentId:e,allowlist:Y}),w(!1)}function K(B){B.preventDefault(),!(!A.trim()||!C.trim())&&(l.mutate({agentId:e,hostPath:A.trim(),agentPath:C.trim()}),S(""),E(""))}const q=n.data?.mode??"inherit",$=n.data?.globalDefault??"non-main";return r.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-6",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Auto-approve"}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:"Skip confirmation prompts"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Execute all actions without asking"})]}),r.jsx(Sh,{checked:d||F,onCheckedChange:M,disabled:i.isPending,className:"w-9 h-5 rounded-full bg-[#2A2A35] data-[state=checked]:bg-[#EF4444] transition-colors outline-none cursor-pointer",children:r.jsx(Ch,{className:"block w-4 h-4 bg-white rounded-full shadow transition-transform translate-x-0.5 data-[state=checked]:translate-x-[18px]"})})]}),r.jsx(Me,{children:p&&r.jsxs(ne.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:"rounded-lg border border-[#EF4444]/40 bg-[#EF4444]/10 p-3 space-y-3",children:[r.jsx("p",{className:"text-[12px] text-[#FCA5A5] leading-relaxed",children:"This agent will execute all actions without asking for confirmation. Only enable for read-only agents or dedicated machines you fully control."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:I,className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#EF4444] hover:bg-[#DC2626] text-white transition-colors",children:"Enable anyway"}),r.jsx("button",{onClick:R,className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]})})]}),r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Sandbox"}),r.jsx("div",{className:"flex gap-1.5",children:["inherit","on","off"].map(B=>r.jsx("button",{onClick:()=>o.mutate({agentId:e,mode:B}),disabled:o.isPending,className:`flex-1 py-1.5 rounded-md text-[12px] font-medium transition-colors ${q===B?"bg-[#6366F1] text-white":"bg-[#1C1C21] border border-[#2A2A35] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45]"}`,children:B==="inherit"?`Inherit (${$==="non-main"?"sandboxed":"off"})`:B==="on"?"Sandboxed":"Unsandboxed"},B))})]}),r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Shell allowlist"}),r.jsx("input",{type:"text",value:g,onChange:B=>H(B.target.value),placeholder:"All commands allowed",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Comma-separated command names, e.g. git, npm, ls"}),_&&r.jsx("button",{onClick:V,disabled:a.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:"Save allowlist"})]}),T&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Filesystem mounts"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Mounting a directory gives this agent read/write access to those files."}),s.data&&s.data.length>0&&r.jsx("div",{className:"space-y-1.5",children:s.data.map(B=>r.jsxs("div",{className:"flex items-center gap-2 bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] truncate",children:B.hostPath}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:["→ ",B.agentPath]})]}),r.jsx("button",{onClick:()=>c.mutate({mountId:B.id}),disabled:c.isPending,className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})]},B.id))}),r.jsxs("form",{onSubmit:K,className:"space-y-2",children:[r.jsx("input",{type:"text",value:A,onChange:B=>S(B.target.value),placeholder:"Host path (e.g. /Users/you/projects)",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("input",{type:"text",value:C,onChange:B=>E(B.target.value),placeholder:"Agent path (e.g. /workspace/projects)",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsxs("button",{type:"submit",disabled:l.isPending||!A.trim()||!C.trim(),className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add mount"]})]})]})]})]})}function OC({className:e}){return r.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",className:e,children:r.jsx("path",{d:"M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"})})}const jMe=[{id:"telegram",label:"Telegram",icon:OC,available:!0},{id:"whatsapp",label:"WhatsApp",icon:Ji,available:!1},{id:"discord",label:"Discord",icon:Ji,available:!1},{id:"slack",label:"Slack",icon:Ji,available:!1}];function NMe({externalChannelId:e,botUsername:t}){const{data:n=[],refetch:s}=L.externalChannels.listPairings.useQuery({externalChannelId:e}),{data:i=[]}=L.workspace.listMembers.useQuery(),a=L.externalChannels.generatePairingCode.useMutation({onSuccess:()=>s()}),o=L.externalChannels.generatePairingCodeForUser.useMutation({onSuccess:()=>s()}),l=L.externalChannels.revokePairing.useMutation({onSuccess:()=>s()}),[c,d]=y.useState(!1),[f,p]=y.useState(""),[m,g]=y.useState(null),[b,_]=y.useState(null),[w,A]=y.useState(!1),S=new Set(n.map(F=>F.userId)),C=i.filter(F=>!S.has(F.userId));async function E(){g(null);try{const F=await a.mutateAsync({externalChannelId:e});g(F.code),d(!0)}catch{}}async function k(){if(f){g(null);try{const F=await o.mutateAsync({externalChannelId:e,userId:f});g(F.code)}catch{}}}function T(){m&&(navigator.clipboard.writeText(m).catch(()=>{}),A(!0),setTimeout(()=>A(!1),2e3))}return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Paired Users"}),r.jsxs("div",{className:"flex gap-1.5",children:[r.jsx("button",{onClick:E,disabled:a.isPending,className:"px-2 py-1 rounded text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] hover:bg-[#6366F1]/20 transition-colors",children:"Pair your Telegram"}),r.jsxs("button",{onClick:()=>{d(!0),g(null),p("")},className:"px-2 py-1 rounded text-[11px] font-medium bg-[#2A2A35] text-[#F0F0F5] hover:bg-[#3A3A45] transition-colors",children:[r.jsx(wt,{className:"w-3 h-3 inline -mt-px"})," Pair user"]})]})]}),n.length===0&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"No users paired yet. Pair your Telegram account to enable secure multi-user access."}),n.map(F=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded-md bg-[#13131A]",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] text-[#F0F0F5]",children:F.userName}),F.telegramUsername&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E] ml-1.5",children:["@",F.telegramUsername]}),r.jsx("span",{className:"text-[10px] text-[#3A3A45] ml-1.5",children:new Date(F.pairedAt).toLocaleDateString()})]}),b===F.id?r.jsxs("div",{className:"flex gap-1",children:[r.jsx("button",{onClick:()=>{l.mutate({pairingId:F.id}),_(null)},className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#EF4444] text-white",children:"Revoke"}),r.jsx("button",{onClick:()=>_(null),className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#2A2A35] text-[#F0F0F5]",children:"Cancel"})]}):r.jsx("button",{onClick:()=>_(F.id),className:"text-[10px] text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})]},F.id)),r.jsx(Me,{children:c&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"rounded-lg border border-[#2A2A35] bg-[#13131A] p-3 space-y-3 overflow-hidden",children:m?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium",children:"Pairing code"}),r.jsx("div",{onClick:T,className:"flex items-center justify-center gap-2 py-3 rounded-lg bg-[#1C1C21] border border-[#2A2A35] cursor-pointer hover:border-[#6366F1] transition-colors",children:r.jsx("span",{className:"text-2xl font-mono font-bold tracking-[0.25em] text-[#F0F0F5]",children:m})}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:[w?"Copied!":"Click to copy."," Send this to the user. They should message it to"," ",t?`@${t}`:"the bot"," on Telegram. Expires in 10 minutes."]}),r.jsx("button",{onClick:()=>{d(!1),g(null),s()},className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Done"})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium",children:"Pair a workspace member"}),C.length>0?r.jsxs(r.Fragment,{children:[r.jsxs(ss,{value:f,onValueChange:p,children:[r.jsxs(is,{className:"w-full flex items-center justify-between bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[12px] text-[#F0F0F5] outline-none",children:[r.jsx(Ds,{placeholder:"Select member"}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C21] border border-[#2A2A35] rounded-lg shadow-xl z-[100]",position:"popper",sideOffset:4,children:r.jsx(os,{className:"p-1",children:C.map(F=>r.jsxs(vn,{value:F.userId,className:"flex items-center px-3 py-2 text-[12px] text-[#F0F0F5] rounded cursor-pointer hover:bg-[#2A2A35] outline-none data-[highlighted]:bg-[#2A2A35]",children:[r.jsx(yn,{children:F.name}),r.jsx(ui,{className:"ml-auto",children:r.jsx(Fe,{className:"w-3 h-3"})})]},F.userId))})})})]}),r.jsx("button",{onClick:k,disabled:!f||o.isPending,className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:o.isPending?"Generating...":"Generate code"})]}):r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"All workspace members are already paired."}),r.jsx("button",{onClick:()=>d(!1),className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})})})]})}function kMe({agentId:e}){const{data:t=[],refetch:n}=L.externalChannels.list.useQuery({agentId:e}),s=L.externalChannels.configure.useMutation({onSuccess:()=>n()}),i=L.externalChannels.enable.useMutation({onSuccess:()=>n()}),a=L.externalChannels.disable.useMutation({onSuccess:()=>n()}),o=L.externalChannels.delete.useMutation({onSuccess:()=>n()}),[l,c]=y.useState(null),[d,f]=y.useState(""),[p,m]=y.useState(null),[g,b]=y.useState(null);async function _(){if(!(!d.trim()||!l)){m(null);try{await s.mutateAsync({agentId:e,provider:l,credentials:{botToken:d.trim()}}),f(""),c(null)}catch(A){m(A instanceof Error?A.message:"Connection failed")}}}const w=t.find(A=>A.provider==="telegram");return r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"External Channels"}),w&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] p-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:w.running?"#10B981":w.status==="error"?"#EF4444":"#5A5A6E"}}),r.jsx(OC,{className:"w-4 h-4 text-[#29B6F6]"}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:"Telegram"}),typeof w.metadata?.botUsername=="string"&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E]",children:["@",w.metadata.botUsername]})]}),r.jsx(Sh,{checked:w.enabled,onCheckedChange:A=>{A?i.mutate({agentId:e,provider:"telegram"}):a.mutate({agentId:e,provider:"telegram"})},className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35]",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]}),w.status==="error"&&r.jsx("p",{className:"text-[11px] text-[#EF4444]",children:"Bridge failed to start. Check the bot token."}),r.jsx("div",{className:"flex gap-2",children:g===w.id?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{o.mutate({id:w.id}),b(null)},className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#EF4444] hover:bg-[#DC2626] text-white transition-colors",children:"Confirm disconnect"}),r.jsx("button",{onClick:()=>b(null),className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]}):r.jsx("button",{onClick:()=>b(w.id),className:"text-[11px] text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:"Disconnect"})})]}),w&&r.jsx(NMe,{externalChannelId:w.id,botUsername:typeof w.metadata?.botUsername=="string"?w.metadata.botUsername:void 0}),w&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35]/50 bg-[#1C1C21]/50 p-3 space-y-2",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"BotFather Setup"}),r.jsxs("div",{className:"text-[11px] text-[#5A5A6E] leading-relaxed space-y-1",children:[r.jsx("p",{children:"Open @BotFather on Telegram and run these for your bot:"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setjoingroups"}),r.jsx("p",{className:"pl-3",children:"Disable (bot is DM-only)"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setprivacy"}),r.jsx("p",{className:"pl-3",children:"Enable (default)"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setdescription"}),r.jsx("p",{className:"pl-3",children:'e.g. "damn.dev workspace agent"'})]})]}),!w&&!l&&r.jsx("div",{className:"space-y-2",children:jMe.map(A=>r.jsxs("button",{onClick:()=>A.available?c(A.id):void 0,disabled:!A.available,className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg border border-[#2A2A35] bg-[#1C1C21] hover:bg-[#2A2A35] transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(A.icon,{className:"w-4 h-4 text-[#8A8A99]"}),r.jsxs("span",{className:"text-[13px] text-[#F0F0F5]",children:["Connect ",A.label]}),!A.available&&r.jsx("span",{className:"ml-auto text-[10px] text-[#5A5A6E]",children:"Coming soon"})]},A.id))}),l==="telegram"&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] p-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(OC,{className:"w-4 h-4 text-[#29B6F6]"}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Connect Telegram Bot"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:"Create a bot via @BotFather on Telegram, then paste the token below."}),r.jsx("input",{type:"password",value:d,onChange:A=>f(A.target.value),placeholder:"Bot token from @BotFather",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors",onKeyDown:A=>A.key==="Enter"&&_()}),p&&r.jsx("p",{className:"text-[11px] text-[#EF4444]",children:p}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{onClick:_,disabled:s.isPending||!d.trim(),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[s.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Ji,{className:"w-3.5 h-3.5"}),"Connect"]}),r.jsx("button",{onClick:()=>{c(null),f(""),m(null)},className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),!w&&!l&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] leading-relaxed",children:"Connect external messaging platforms to reach this agent outside of damn.dev. Messages flow through the same pipeline with full governance."})]})}function EMe({agentId:e}){const{data:t,refetch:n}=L.agents.getCapabilities.useQuery({agentId:e}),s=L.agents.setCapabilities.useMutation({onSuccess:()=>n()}),[i,a]=y.useState(""),[o,l]=y.useState(!0),[c,d]=y.useState("idle"),f=y.useRef(null);y.useEffect(()=>{t&&(a(t.capabilities.join(", ")),l(t.canReceiveDelegations))},[t]),y.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);async function p(){const m=i.split(",").map(g=>g.trim()).filter(Boolean);await s.mutateAsync({agentId:e,capabilities:m,canReceiveDelegations:o}),d("saved"),f.current=setTimeout(()=>d("idle"),2e3)}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-5 overflow-y-auto",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Capabilities"}),r.jsx("textarea",{value:i,onChange:m=>a(m.target.value),rows:3,placeholder:"write:code, exec:shell, analyze:data",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2.5 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] resize-none outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Comma-separated. Auto-inferred from skills and role when empty."})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:"Accept delegations"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Other agents can delegate tasks to this agent"})]}),r.jsx(Sh,{checked:o,onCheckedChange:l,className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35]",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]}),t&&t.capabilities.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.capabilities.map(m=>r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] border border-[#6366F1]/20",children:m},m))}),r.jsx("button",{onClick:p,disabled:s.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:r.jsx(Me,{mode:"wait",children:c==="saved"?r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved"},"saved"):r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")})})]})}const t2=["identity","config","live"],FMe={identity:["soul","team","model"],config:["skills","channels","capabilities","trust"],live:["activity","dream","files","git","terminal","schedule","override"]},TMe={identity:[],config:[],live:["activity","dream","files","git","terminal","override"]};function MMe({tabs:e,active:t,onChange:n}){return e.length<=1?null:r.jsx("div",{className:"flex gap-1 px-5 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:e.map(s=>r.jsx("button",{onClick:()=>n(s),className:`px-2.5 py-1 rounded-md text-[11px] font-medium capitalize transition-colors ${t===s?"bg-white/10 text-[#F0F0F5]":"text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5"}`,children:s},s))})}function X8(e,t){const n=atob(e),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n.charCodeAt(l);const i=new Blob([s],{type:"application/zip"}),a=URL.createObjectURL(i),o=document.createElement("a");o.href=a,o.download=t,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}function RMe({warnings:e,onExport:t,onCancel:n}){return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[60] flex items-center justify-center p-4",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},onClick:s=>s.stopPropagation(),className:"relative bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 w-full max-w-sm space-y-4 shadow-2xl",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Export warnings"}),r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:e.map((s,i)=>r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2",children:[r.jsx("p",{className:"text-[12px] text-[#FCD34D] leading-relaxed",children:s.message}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:[s.file,":",s.line]})]},i))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:t,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#F59E0B] hover:bg-[#D97706] text-black transition-colors",children:"Export anyway"}),r.jsx("button",{onClick:n,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]})]})}const DMe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],OMe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16"];function $N({agent:e,agentColor:t,onClose:n,onOverrideSet:s,initialTab:i}){const a=Uo(),o=a?FMe:TMe,l=a?"identity":"live",c=i&&t2.includes(i.category)?i.category:l,d=i&&o[c]?.includes(i.subTab)?i.subTab:o[c][0]??"activity",[f,p]=y.useState(c),[m,g]=y.useState(d),[b,_]=y.useState(null),[w,A]=y.useState(null),S=L.useUtils(),[C,E]=y.useState(!1),[k,T]=y.useState(e.name),F=y.useRef(null),M=L.agents.update.useMutation({onSuccess:()=>{S.agents.list.invalidate(),S.channels.list.invalidate()}});function I(){E(!1);const $=k.trim();$&&$!==e.name?M.mutate({agentId:e.id,name:$}):T(e.name)}y.useEffect(()=>{C&&F.current?.select()},[C]),y.useEffect(()=>{T(e.name)},[e.name]);const R=L.agents.export.useMutation();async function H(){try{const $=await R.mutateAsync({agentId:e.id});$.warnings.length>0?(_($.warnings),A({buffer:$.buffer,filename:$.filename})):X8($.buffer,$.filename)}catch{}}function V(){w&&X8(w.buffer,w.filename),_(null),A(null)}function K($){p($),g(o[$][0]??"")}const q=a?t2:t2.filter($=>o[$].length>0);return r.jsxs(r.Fragment,{children:[r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",style:{backdropFilter:"blur(2px)",backgroundColor:"rgba(0,0,0,0.25)"},onClick:n}),r.jsxs(ne.div,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.3,ease:[.16,1,.3,1]},className:"fixed right-0 top-0 h-screen w-[380px] bg-[#13131A] border-l border-[#2A2A35] flex flex-col z-50 shadow-2xl",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",style:{background:`linear-gradient(135deg, rgba(${uh(t)}, 0.08) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[a&&e.id!=="coo"?r.jsxs(Ys,{children:[r.jsx(ci,{asChild:!0,children:r.jsx("button",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xl flex-shrink-0 hover:ring-2 hover:ring-white/20 transition-all",style:{backgroundColor:`${t}26`},children:e.emoji})}),r.jsx(Qs,{children:r.jsxs(Xs,{sideOffset:8,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Emoji"}),r.jsx("div",{className:"grid grid-cols-10 gap-1 mb-3",children:DMe.map($=>r.jsx("button",{onClick:()=>M.mutate({agentId:e.id,emoji:$}),className:`w-6 h-6 flex items-center justify-center rounded text-sm hover:bg-white/10 transition-colors ${e.emoji===$?"bg-white/15 ring-1 ring-white/20":""}`,children:$},$))}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Color"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:OMe.map($=>r.jsx("button",{onClick:()=>M.mutate({agentId:e.id,color:$}),className:`w-6 h-6 rounded-full transition-all ${e.color===$?"ring-2 ring-white/40 scale-110":"hover:scale-110"}`,style:{backgroundColor:$}},$))}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]}):r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xl flex-shrink-0",style:{backgroundColor:`${t}26`},children:e.emoji}),r.jsxs("div",{className:"min-w-0",children:[C?r.jsx("input",{ref:F,value:k,onChange:$=>T($.target.value),onBlur:I,onKeyDown:$=>{$.key==="Enter"&&F.current?.blur(),$.key==="Escape"&&(T(e.name),E(!1))},className:"bg-transparent text-[14px] font-semibold text-[#F0F0F5] outline-none border-b border-[#6366F1]/60 pb-px w-full"}):r.jsxs("p",{className:`text-[14px] font-semibold text-[#F0F0F5] truncate ${a&&e.id!=="coo"?"cursor-pointer hover:text-[#818CF8] transition-colors group/name":""}`,onClick:()=>{a&&e.id!=="coo"&&E(!0)},children:[e.name,a&&e.id!=="coo"&&r.jsx(oh,{className:"w-3 h-3 inline-block ml-1.5 opacity-0 group-hover/name:opacity-60 transition-opacity"})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] truncate",children:e.role})]}),r.jsx(cMe,{status:e.status,color:t}),r.jsx(oMe,{agentId:e.id})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[a&&e.id!=="coo"&&r.jsx(bt,{label:"Export agent",side:"left",children:r.jsx("button",{onClick:H,disabled:R.isPending,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors disabled:opacity-50",children:R.isPending?r.jsx(Pe,{className:"w-4 h-4 animate-spin"}):r.jsx(nu,{className:"w-4 h-4"})})}),r.jsx(bt,{label:"Close",side:"left",children:r.jsx("button",{onClick:n,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})})]})]}),r.jsx("div",{className:"flex border-b border-[#2A2A35] flex-shrink-0 px-5",children:q.map($=>r.jsx("button",{onClick:()=>K($),className:`py-3 px-1 mr-4 text-[11px] font-medium capitalize border-b-2 transition-colors outline-none ${f===$?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"}`,children:$},$))}),r.jsx(MMe,{tabs:o[f],active:m,onChange:g}),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[a&&m==="soul"&&r.jsx(uMe,{agentId:e.id}),a&&m==="team"&&r.jsx(dMe,{agentId:e.id}),a&&m==="model"&&r.jsx(rMe,{agent:e,agentColor:t}),a&&m==="skills"&&r.jsx(pMe,{agentId:e.id}),a&&m==="channels"&&r.jsx(kMe,{agentId:e.id}),a&&m==="capabilities"&&r.jsx(EMe,{agentId:e.id}),a&&m==="trust"&&r.jsx(CMe,{agentId:e.id}),m==="activity"&&r.jsx(DEe,{agentId:e.id}),m==="dream"&&r.jsx(JTe,{agentId:e.id}),m==="files"&&r.jsx(ITe,{agentId:e.id}),m==="git"&&r.jsx(WTe,{agentId:e.id}),m==="terminal"&&r.jsx(AMe,{agentId:e.id}),a&&m==="schedule"&&r.jsx(SMe,{agentId:e.id}),m==="override"&&r.jsx(mMe,{agentId:e.id,onOverrideSet:s,onClose:n})]})]}),r.jsx(Me,{children:b&&r.jsx(RMe,{warnings:b,onExport:V,onCancel:()=>{_(null),A(null)}})})]})}async function PMe(e){if(Va)try{const{sendNotification:t,isPermissionGranted:n,requestPermission:s}=await X(async()=>{const{sendNotification:a,isPermissionGranted:o,requestPermission:l}=await import("./index-E-6oA41F.js");return{sendNotification:a,isPermissionGranted:o,requestPermission:l}},__vite__mapDeps([103,1]));let i=await n();if(i||(i=await s()==="granted"),!i)return;t({title:e.title,body:e.body})}catch{}}const IMe=/\.(kanban|chart|table|board)\.json$/,LMe=oi.replace(/^http/,"ws")+"/ws",BMe=25e3,zMe=3e3;function J8(e,t){if(Va){document.hidden&&PMe({title:e,body:t.slice(0,80)});return}!("Notification"in window)||Notification.permission!=="granted"||document.hidden&&new Notification(e,{body:t.slice(0,80),icon:"/favicon.ico"})}function $Me(e,t){return new RegExp(`@${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i").test(e)}const Z8=new Set;function bW(e){const t=L.useUtils(),{data:n}=Mi(),s=y.useRef(n?.user?.name??"");y.useLayoutEffect(()=>{s.current=n?.user?.name??""});const{appendMessage:i,setAgentStatus:a,updateMessageStatus:o,updateMessage:l,removeMessage:c,updateReactions:d,setUnreadCount:f,addFileEditApproval:p,removeFileEditApproval:m}=Je(),g=y.useRef(null),b=y.useRef(null),_=y.useRef(e),w=y.useRef(!0),A=y.useRef(!1);y.useLayoutEffect(()=>{_.current=e});const S=y.useCallback(async C=>{const k=Je.getState().messagesByChannel[C];if(!k||k.length===0)return;const T=k[k.length-1];try{const F=await t.messages.list.fetch({channelId:C,cursor:T.id,limit:100,direction:"after"});if(F.messages.length>0)for(const M of F.messages)i(M)}catch{}},[t,i]);y.useEffect(()=>{w.current=!0;let C=null;function E(){if(!w.current)return;const k=new WebSocket(LMe);g.current=k,k.onopen=()=>{if(!w.current){k.close(1e3);return}const T=_.current;T&&k.send(JSON.stringify({type:"subscribe",channelId:T})),A.current&&(T&&S(T),t.messages.list.invalidate(),t.channels.list.invalidate(),t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate()),A.current=!0,b.current=setInterval(()=>{k.readyState===WebSocket.OPEN&&k.send(JSON.stringify({type:"ping"}))},BMe)},k.onmessage=T=>{if(w.current)try{const F=JSON.parse(T.data);if(F.type==="message.new"){const M=F;i(M.payload),M.payload.sender.type==="agent"&&M.payload.channelId!==_.current&&J8(M.payload.sender.name,M.payload.content)}else if(F.type==="message.edited"){const M=F;l(M.payload.channelId,M.payload.messageId,{content:M.payload.content,editedAt:M.payload.editedAt})}else if(F.type==="message.deleted"){const M=F;c(M.payload.channelId,M.payload.messageId)}else if(F.type==="message.pinned"){const M=F;l(M.payload.channelId,M.payload.messageId,{pinnedAt:M.payload.pinnedAt,pinnedBy:M.payload.pinnedBy})}else if(F.type==="message.unpinned"){const M=F;l(M.payload.channelId,M.payload.messageId,{pinnedAt:void 0,pinnedBy:void 0})}else if(F.type==="message.metadata_updated"){const M=F;l(M.payload.channelId,M.payload.messageId,{metadata:M.payload.metadata})}else if(F.type==="reaction.toggled"){const M=F;d(M.payload.channelId,M.payload.messageId,M.payload.reactions)}else if(F.type==="thread.message.new"){const M=F,R=(Je.getState().messagesByChannel[M.payload.channelId]??[]).find(H=>H.id===M.payload.parentMessageId);R&&l(M.payload.channelId,M.payload.parentMessageId,{replyCount:(R.replyCount??0)+1})}else if(F.type==="agent.status"){const M=F;a(M.payload.agentId,M.payload.status),M.payload.status==="thinking"?Mw("thinking"):Mw("idle")}else if(F.type==="approval.decided"){const M=F;o(M.payload.channelId,M.payload.messageId,M.payload.decision),t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate()}else if(F.type==="approval.file_edit.created")p(F.payload);else if(F.type==="approval.file_edit.decided"){const M=F;m(M.payload.channelId,M.payload.id)}else if(F.type==="conversation.cleared"){const M=F;Je.getState().setMessages(M.payload.channelId,[])}else if(F.type==="channel.created"||F.type==="channel.closed"||F.type==="channel.updated")t.channels.list.invalidate(),F.type==="channel.created"&&t.readReceipts.getUnread.invalidate();else if(F.type==="channel.tabs.updated"){const M=F;t.channels.get.invalidate({channelId:M.payload.parentChannelId}),t.channels.list.invalidate()}else if(F.type==="channel.tokenUpdate"){const M=F;ny.getState().updateFromWs(M.payload.channelId,M.payload)}else if(F.type==="channel.compacted"){const M=F;Je.getState().appendMessage({id:`compaction-${Date.now()}`,channelId:M.payload.channelId,sender:{type:"context_reset",id:"system",name:"system"},content:`compacted:${M.payload.summarizedCount}`,timestamp:new Date().toISOString()})}else if(F.type==="presence.changed"){const M=F;t.workspace.listPresence.setData(void 0,I=>I&&I.map(R=>R.userId===M.payload.userId?{...R,online:M.payload.online,lastSeenAt:M.payload.lastSeenAt??R.lastSeenAt}:R))}else if(F.type==="agent.fileChanged"){const M=F;t.fileChanges.list.invalidate({channelId:M.payload.channelId})}else if(F.type==="agent.filesChanged"){const M=F;if(t.files.tree.invalidate({agentId:M.payload.agentId}),M.payload.filename&&IMe.test(M.payload.filename)){const R=t.channels.list.getData()?.find(H=>H.channelType==="dm"&&H.agentId===M.payload.agentId);R&&NU.getState().addCard(R.id,{id:`sf-${M.payload.agentId}-${M.payload.filename}-${Date.now()}`,agentId:M.payload.agentId,filename:M.payload.filename,filePath:M.payload.filePath??M.payload.filename,timestamp:Date.now()})}}else if(F.type==="agent.created"||F.type==="agent.deleted")t.agents.list.invalidate(),t.channels.list.invalidate();else if(F.type==="approval.created"||F.type==="approval.expired"){if(t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate(),F.type==="approval.created"){const M=F.payload;M?.channelId&&S(M.channelId),Mw("badge"),J8("Action required",M?.agentName?`${M.agentName} wants to: ${M.description??"perform an action"}`:"An agent requires approval"),window.dispatchEvent(new CustomEvent("pwa-push-prompt"))}}else(F.type==="mission.task.updated"||F.type==="mission.task.dispatched"||F.type==="mission.created")&&(t.missions.list.invalidate(),t.federation.activityFeed.invalidate());if(F.type==="message.new"){const M=F;if(M.payload.channelId!==_.current&&!Z8.has(M.payload.id)){Z8.add(M.payload.id);const{mutedChannels:I,unreadCounts:R}=Je.getState(),H=I[M.payload.channelId];H?H.notifyOnMention&&s.current&&$Me(M.payload.content,s.current)&&f(M.payload.channelId,(R[M.payload.channelId]??0)+1):f(M.payload.channelId,(R[M.payload.channelId]??0)+1)}}}catch{}},k.onclose=T=>{b.current&&clearInterval(b.current),w.current&&T.code!==1e3&&(C=setTimeout(E,zMe))},k.onerror=()=>{k.close()}}return E(),()=>{w.current=!1,b.current&&clearInterval(b.current),C&&clearTimeout(C),g.current?.close(1e3)}},[i,a,o,l,c,d,f,p,m,t,S]),y.useEffect(()=>{const C=g.current;!C||C.readyState!==WebSocket.OPEN||e&&C.send(JSON.stringify({type:"subscribe",channelId:e}))},[e])}const VMe={orchestrator:"#6366F1","content-agent":"#8B5CF6","engagement-agent":"#10B981"};function UMe(){const{channelId:e}=am(),t=an(),n=tz(D=>D.setActiveChannelId);y.useEffect(()=>(n(e??null),()=>n(null)),[e,n]);const{data:s}=L.channels.get.useQuery({channelId:e??""},{enabled:!!e,retry:!1});y.useEffect(()=>{if(!s||!e)return;const D=s.channel,Q=s.tabs,z=V7.getState();if(D.parentChannelId==null){const J=z.lastTab[e];J&&J!==e&&(Q.some(ee=>ee.id===J)?t(`/channels/${J}`,{replace:!0}):z.clearLast(e))}else z.lastTab[D.parentChannelId]!==e&&z.setLast(D.parentChannelId,e)},[s,e,t]);const[i,a]=y.useState(!1),[o,l]=y.useState(void 0),[c,d]=y.useState(!1),[f,p]=y.useState(null);y.useEffect(()=>{function D(){l({category:"live",subTab:"files"}),a(!0)}return window.addEventListener("open-agent-files",D),()=>window.removeEventListener("open-agent-files",D)},[]);const{data:m}=ez(e??""),{data:g}=pj(m?.agentId??""),{data:b=[]}=Vo(),{data:_}=Mi(),w=m?.channelType==="dm"&&!m.agentId,A=m?.channelType==="group"||m?.channelType==="topic",{data:S=[]}=L.workspace.listMembers.useQuery(void 0,{enabled:w||A}),C=w?m.participants.find(D=>D.participantType==="human"&&D.participantId!==_?.user?.id):void 0,E=C?S.find(D=>D.userId===C.participantId)?.name??void 0:void 0,k=C?.participantId,{data:T,isLoading:F,loadMore:M}=W7(e??""),I=Je(D=>D.agentStatuses),R=Je(D=>D.openThreadMessageId),H=Je(D=>D.closeThread),V=Je(D=>D.unreadCounts),{mutate:K,isPending:q}=q7();bW(e);const $=!!g&&((I[g.id]??g.status)==="thinking"||(I[g.id]??g.status)==="executing"),B=T.some(D=>D.status==="pending_approval"),Y=g?VMe[g.id]??g.color:void 0,U=e?V[e]??0:0,W=U>0&&T.length>=U?T[T.length-U]?.id:void 0,O=y.useCallback((D,Q)=>{e&&K({channelId:e,content:D,attachmentIds:Q})},[e,K]);return!e||!m?r.jsx("div",{className:"flex-1 flex items-center justify-center text-[#8A8A99]",children:r.jsx("p",{className:"text-[14px]",children:"Channel not found"})}):m.channelType==="terminal"?r.jsx("div",{className:"flex-1"}):m.channelType==="group"?r.jsx(dwe,{channel:m,agents:b}):r.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[r.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[r.jsx(swe,{channel:m,agent:w?void 0:g,agentColor:w?void 0:Y,hasPendingApproval:w?!1:B,rightPanelOpen:i,memoryPanelOpen:c,activeOverride:f,humanDmName:E,humanDmUserId:k,onToggleRightPanel:()=>a(D=>!D),onToggleMemoryPanel:()=>d(D=>!D),onAgentClick:()=>a(D=>!D),onClearOverride:()=>p(null),onClearConversation:()=>Je.getState().setMessages(e,[])}),r.jsx(ike,{channelId:e,agentForChannel:m.channelType==="topic"||w?void 0:g,agentColor:m.channelType==="topic"||w?void 0:Y,messages:T,isThinking:m.channelType==="topic"||w?!1:$,isLoading:F,loadMore:M,firstUnreadId:W}),r.jsx(cke,{channelId:e}),r.jsx(H7,{channelId:e,channelName:w?E??"User":m.name,agent:m.channelType==="topic"||w?void 0:g,agentColor:m.channelType==="topic"||w?void 0:Y,onSend:O,disabled:q,mentionableParticipants:m.channelType==="topic"?[...m.participants.filter(D=>D.participantType==="agent").map(D=>b.find(Q=>Q.id===D.participantId)).filter(D=>!!D).map(D=>({id:D.id,name:D.name,emoji:D.emoji,color:D.color,type:"agent"})),...m.participants.filter(D=>D.participantType==="human"&&D.participantId!==_?.user?.id).map(D=>{const Q=S.find(z=>z.userId===D.participantId);return Q?{id:Q.userId,name:Q.name,emoji:null,color:"#6366F1",type:"human"}:null}).filter(D=>!!D)]:void 0})]}),r.jsx(Me,{children:c&&g&&r.jsx(hke,{agent:g,agentColor:Y,onClose:()=>d(!1)})}),r.jsx(Me,{children:R&&r.jsx(dke,{parentMessageId:R,agentColor:Y,onClose:H})}),r.jsx(Me,{children:i&&g&&Y&&r.jsx($N,{agent:g,agentColor:Y,onClose:()=>{a(!1),l(void 0)},onOverrideSet:D=>p(D),initialTab:o},o?.subTab)})]})}function HMe({onClose:e,onSuccess:t}){const[n,s]=y.useState("pick"),[i,a]=y.useState(null),[o,l]=y.useState(null),[c,d]=y.useState(null),f=y.useRef(null),p=L.agentImport.previewImport.useMutation(),m=L.agentImport.confirmImport.useMutation(),g=y.useCallback(async S=>{if(!S.name.endsWith(".damnpack")){l("Please select a .damnpack file"),s("error");return}if(S.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const C=new FormData;C.append("file",S);const E=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:C,credentials:"include"});if(!E.ok){const F=await E.json().catch(()=>({error:"Upload failed"}));throw new Error(F.error||`Upload failed (${E.status})`)}const{uploadId:k}=await E.json(),T=await p.mutateAsync({uploadId:k});if("kind"in T&&T.kind==="skill-pack"){s("skill-pack");return}a(T),s("preview")}catch(C){l(C instanceof Error?C.message:"Upload failed"),s("error")}},[p]);async function b(S){if(i){s("confirming");try{const C=await m.mutateAsync({previewId:i.previewId,mode:S});d(C),s("done")}catch(C){l(C instanceof Error?C.message:"Import failed"),s("error")}}}const _=i?.warnings.filter(S=>S.type==="credential")??[],w=i?.warnings.filter(S=>S.type==="url")??[],A=i?.warnings.filter(S=>S.type==="shell_exec")??[];return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:e,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},onClick:S=>S.stopPropagation(),className:"relative w-full max-w-md bg-[#16161A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:n==="done"?"Import complete":n==="skill-pack"?"Skill pack":"Import agent"}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"p-5",children:[n==="pick"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("button",{onClick:()=>f.current?.click(),className:"w-full py-10 rounded-xl border-2 border-dashed border-[#2A2A35] hover:border-[#6366F1]/50 transition-colors flex flex-col items-center gap-3 group",children:[r.jsx(su,{className:"w-8 h-8 text-[#5A5A6E] group-hover:text-[#6366F1] transition-colors"}),r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-medium",children:"Choose .damnpack file"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Max 100MB"})]})]}),r.jsx("input",{ref:f,type:"file",accept:".damnpack",className:"hidden",onChange:S=>{const C=S.target.files?.[0];C&&g(C)}})]}),(n==="uploading"||n==="confirming")&&r.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[r.jsx(Pe,{className:"w-8 h-8 text-[#6366F1] animate-spin"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:n==="uploading"?"Scanning bundle...":"Importing agent..."})]}),n==="error"&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-4 py-3",children:r.jsx("p",{className:"text-[13px] text-[#FCA5A5]",children:o})}),r.jsx("button",{onClick:()=>{s("pick"),l(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),n==="skill-pack"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#6366F1]/15 border border-[#6366F1]/25 flex items-center justify-center",children:r.jsx(vv,{className:"w-5 h-5 text-[#818CF8]"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Skill pack detected"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"This bundle contains skills, not an agent."})]})]}),r.jsx(gn,{to:"/skills",onClick:e,className:"flex items-center justify-center w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Go to Skills page to import"}),r.jsx("button",{onClick:e,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]}),n==="preview"&&i&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#6366F1]/15 border border-[#6366F1]/25 flex items-center justify-center text-lg",children:i.manifest.name.slice(0,2)}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.manifest.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.manifest.version," by ",i.manifest.author.name]})]}),i.isUpdate&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20",children:"Update"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.manifest.description}),r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] p-3",children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:"Soul excerpt"}),r.jsx("p",{className:"text-[12px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap line-clamp-6",children:i.soulExcerpt})]}),i.manifest.skills.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Skills"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.manifest.skills.map(S=>r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] border border-[#6366F1]/20",children:S},S))})]}),i.isUpdate&&i.diff&&r.jsx("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] px-3 py-2",children:r.jsxs("p",{className:"text-[12px] text-[#C8C8D4]",children:["SOUL.md: ",r.jsxs("span",{className:"text-emerald-400",children:["+",i.diff.added]})," / ",r.jsxs("span",{className:"text-red-400",children:["-",i.diff.removed]})," lines",i.skillFiles.length>0&&`. ${i.skillFiles.length} skill file(s).`]})}),i.modelWarnings.length>0&&r.jsx("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:i.modelWarnings.map((S,C)=>r.jsxs("p",{className:"text-[11px] text-[#FCD34D] flex items-start gap-1.5",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),S]},C))}),i.missingSecrets.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1.5",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(Eo,{className:"w-3.5 h-3.5"}),"Required workspace secrets missing"]}),r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80",children:"This bundle's skills reference secrets that aren't set in this workspace. You can still import now, but agents will fail to call these tools until you add the secrets in Settings → Secrets:"}),r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:i.missingSecrets.map(S=>r.jsx("code",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono text-[#FCD34D] bg-[#F59E0B]/15 border border-[#F59E0B]/20",children:S},S))})]}),A.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5] flex items-center gap-1.5",children:[r.jsx(Ti,{className:"w-3.5 h-3.5"}),"Shell execution patterns detected"]}),A.map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80 ml-5",children:[S.file,":",S.line," — ",S.message]},C))]}),_.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),"Possible credentials found"]}),_.map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:[S.file,":",S.line]},C))]}),w.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#2A2A35]/50 border border-[#2A2A35] px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#8A8A99] flex items-center gap-1.5",children:[r.jsx(Xt,{className:"w-3.5 h-3.5"}),"External URLs (",w.length,")"]}),w.slice(0,5).map((S,C)=>r.jsx("p",{className:"text-[10px] text-[#5A5A6E] ml-5 truncate",children:S.message.replace("External URL: ","")},C)),w.length>5&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] ml-5",children:["...and ",w.length-5," more"]})]}),i.hasHeartbeat&&r.jsx("div",{className:"rounded-lg bg-[#6366F1]/10 border border-[#6366F1]/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-[#818CF8] flex items-start gap-1.5",children:[r.jsx(bm,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),"This agent includes a scheduled task. It will be disabled by default."]})}),i.isUpdate&&r.jsxs("p",{className:"text-[11px] text-[#8A8A99] italic",children:["Updating existing agent: ",i.manifest.name,". Your memory and experience will be preserved."]}),i.strippedFiles.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:["Stripped from bundle: ",i.strippedFiles.join(", ")]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[i.isUpdate?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>b("update"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Update"}),r.jsx("button",{onClick:()=>b("new"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Import as copy"})]}):r.jsx("button",{onClick:()=>b("new"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Import"}),r.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),n==="done"&&c&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center",children:r.jsx(Fe,{className:"w-5 h-5 text-emerald-400"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:c.name}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:c.mode==="update"?"Agent updated successfully":"Agent imported successfully"})]})]}),c.heartbeatNote&&r.jsx("p",{className:"text-[11px] text-[#818CF8] bg-[#6366F1]/10 border border-[#6366F1]/20 rounded-lg px-3 py-2",children:c.heartbeatNote}),c.diff&&r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:c.diff}),r.jsx("button",{onClick:()=>{t(),e()},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}function WMe({onClose:e}){const[t,n]=y.useState("select"),[s,i]=y.useState(new Set),[a,o]=y.useState(new Set),[l,c]=y.useState(null),[d,f]=y.useState([]),{data:p}=L.teamBundle.listExportable.useQuery(),m=L.teamBundle.exportTeam.useMutation(),g=p?.agents??[],b=p?.channels??[];function _(S){i(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})}function w(S){o(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})}async function A(){if(s.size!==0){n("exporting");try{const S=await m.mutateAsync({agentIds:[...s],channelIds:[...a]});f(S.warnings.map(M=>({file:M.file,message:M.message})));const C=atob(S.buffer),E=new Uint8Array(C.length);for(let M=0;M<C.length;M++)E[M]=C.charCodeAt(M);const k=new Blob([E],{type:"application/zip"}),T=URL.createObjectURL(k),F=document.createElement("a");F.href=T,F.download=S.filename,F.click(),URL.revokeObjectURL(T),n("done")}catch(S){c(S instanceof Error?S.message:"Export failed"),n("error")}}}return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:e,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},onClick:S=>S.stopPropagation(),className:"relative w-full max-w-md bg-[#16161A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:t==="done"?"Export complete":"Export team"}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"p-5",children:[t==="select"&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Agents (",s.size," selected)"]}),r.jsxs("div",{className:"space-y-1",children:[g.map(S=>r.jsxs("label",{className:"flex items-center gap-3 py-2 px-3 rounded-lg hover:bg-white/5 cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:s.has(S.id),onChange:()=>_(S.id),className:"w-3.5 h-3.5 rounded border-[#2A2A35] text-[#6366F1] focus:ring-0 focus:ring-offset-0"}),r.jsx("span",{className:"text-sm",children:S.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:S.name}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:S.role})]})]},S.id)),g.length===0&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-2",children:"No agents available"})]})]}),b.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Channels (",a.size," selected)"]}),r.jsx("div",{className:"space-y-1",children:b.map(S=>r.jsxs("label",{className:"flex items-center gap-3 py-2 px-3 rounded-lg hover:bg-white/5 cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:a.has(S.id),onChange:()=>w(S.id),className:"w-3.5 h-3.5 rounded border-[#2A2A35] text-[#6366F1] focus:ring-0 focus:ring-offset-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:S.name}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E]",children:[S.channelType," / ",S.visibility]})]})]},S.id))})]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsxs("button",{onClick:A,disabled:s.size===0,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-40 disabled:pointer-events-none flex items-center justify-center gap-2",children:[r.jsx(vv,{className:"w-4 h-4"}),"Export (",s.size," agents)"]}),r.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),t==="exporting"&&r.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[r.jsx(Pe,{className:"w-8 h-8 text-[#6366F1] animate-spin"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Packaging team bundle..."})]}),t==="error"&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-4 py-3",children:r.jsx("p",{className:"text-[13px] text-[#FCA5A5]",children:l})}),r.jsx("button",{onClick:()=>{n("select"),c(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),t==="done"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center",children:r.jsx(Fe,{className:"w-5 h-5 text-emerald-400"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Team exported"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[s.size," agents, ",a.size," channels"]})]})]}),r.jsx(Me,{children:d.length>0&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),d.length," warning(s)"]}),d.slice(0,5).map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:[S.file,": ",S.message]},C))]})}),r.jsx("button",{onClick:e,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}function qMe({onClose:e,onSuccess:t}){const[n,s]=y.useState("pick"),[i,a]=y.useState(null),[o,l]=y.useState(null),[c,d]=y.useState(null),[f,p]=y.useState(null),m=y.useRef(null),g=L.teamBundle.previewTeamImport.useMutation(),b=L.teamBundle.confirmTeamImport.useMutation(),_=y.useCallback(async C=>{if(!C.name.endsWith(".damnteam")){l("Please select a .damnteam file"),s("error");return}if(C.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const E=new FormData;E.append("file",C);const k=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:E,credentials:"include"});if(!k.ok){const M=await k.json().catch(()=>({error:"Upload failed"}));throw new Error(M.error||`Upload failed (${k.status})`)}const{uploadId:T}=await k.json(),F=await g.mutateAsync({uploadId:T});a(F),s("preview")}catch(E){l(E instanceof Error?E.message:"Upload failed"),s("error")}},[g]);async function w(){if(i){s("confirming");try{const C=await b.mutateAsync({previewId:i.previewId});d(C),s("done")}catch(C){l(C instanceof Error?C.message:"Import failed"),s("error")}}}const A=i?.warnings.filter(C=>C.type==="credential")??[],S=i?.warnings.filter(C=>C.type==="shell_exec")??[];return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:e,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},onClick:C=>C.stopPropagation(),className:"relative w-full max-w-lg bg-[#16161A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:n==="done"?"Team imported":"Import team"}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"p-5",children:[n==="pick"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("button",{onClick:()=>m.current?.click(),className:"w-full py-10 rounded-xl border-2 border-dashed border-[#2A2A35] hover:border-[#6366F1]/50 transition-colors flex flex-col items-center gap-3 group",children:[r.jsx(su,{className:"w-8 h-8 text-[#5A5A6E] group-hover:text-[#6366F1] transition-colors"}),r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-medium",children:"Choose .damnteam file"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Max 100MB"})]})]}),r.jsx("input",{ref:m,type:"file",accept:".damnteam",className:"hidden",onChange:C=>{const E=C.target.files?.[0];E&&_(E)}})]}),(n==="uploading"||n==="confirming")&&r.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[r.jsx(Pe,{className:"w-8 h-8 text-[#6366F1] animate-spin"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:n==="uploading"?"Scanning team bundle...":"Importing team..."})]}),n==="error"&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-4 py-3",children:r.jsx("p",{className:"text-[13px] text-[#FCA5A5]",children:o})}),r.jsx("button",{onClick:()=>{s("pick"),l(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),n==="preview"&&i&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#6366F1]/15 border border-[#6366F1]/25 flex items-center justify-center",children:r.jsx(wm,{className:"w-5 h-5 text-[#6366F1]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.teamManifest.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.teamManifest.version," by ",i.teamManifest.author.name]})]})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.teamManifest.description}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Agents (",i.agentPreviews.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.agentPreviews.map(C=>r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] overflow-hidden",children:[r.jsxs("button",{onClick:()=>p(f===C.slug?null:C.slug),className:"w-full flex items-center gap-3 px-3 py-2.5 text-left",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:C.manifest.name}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:C.manifest.description})]}),C.isUpdate&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20 flex-shrink-0",children:"Update"}),C.warnings.length>0&&r.jsx(ql,{className:"w-3.5 h-3.5 text-[#FCD34D] flex-shrink-0"}),r.jsx(ft,{className:`w-3.5 h-3.5 text-[#5A5A6E] transition-transform ${f===C.slug?"rotate-180":""}`})]}),r.jsx(Me,{children:f===C.slug&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:r.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-[#2A2A35]",children:[r.jsx("p",{className:"text-[11px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap line-clamp-4 pt-2",children:C.soulExcerpt}),C.modelWarnings.length>0&&r.jsx("div",{className:"space-y-0.5",children:C.modelWarnings.map((E,k)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D] flex items-center gap-1",children:[r.jsx(Wl,{className:"w-3 h-3"}),E]},k))}),C.hasHeartbeat&&r.jsxs("p",{className:"text-[10px] text-[#818CF8] flex items-center gap-1",children:[r.jsx(bm,{className:"w-3 h-3"}),"Includes scheduled task (will be disabled)"]})]})})})]},C.slug))})]}),i.channelDefinitions.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Channels (",i.channelDefinitions.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.channelDefinitions.map((C,E)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Tp,{className:"w-3.5 h-3.5 text-[#5A5A6E]"}),r.jsx("p",{className:"text-[12px] text-[#C8C8D4] flex-1",children:C.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:C.channelType}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:[C.agentSlugs.length," agents"]})]},E))})]}),i.delegationRules.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Delegation rules (",i.delegationRules.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.delegationRules.map((C,E)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(ch,{className:"w-3.5 h-3.5 text-[#5A5A6E]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.agentSlug}),r.jsx("code",{className:"text-[11px] font-mono text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:C.pattern}),r.jsx("span",{className:"ml-auto px-2 py-0.5 rounded-full text-[9px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/20",children:"Will require approval"})]},E))})]}),S.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5] flex items-center gap-1.5",children:[r.jsx(Ti,{className:"w-3.5 h-3.5"}),"Shell execution patterns detected"]}),S.slice(0,5).map((C,E)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80 ml-5",children:[C.file,": ",C.message]},E))]}),A.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),"Possible credentials found"]}),A.slice(0,5).map((C,E)=>r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:C.file},E))]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsx("button",{onClick:w,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Import all"}),r.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),n==="done"&&c&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center",children:r.jsx(Fe,{className:"w-5 h-5 text-emerald-400"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Team imported"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c.importedAgents.length," agents, ",c.createdChannels.length," channels"]})]})]}),c.importedAgents.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Imported agents"}),r.jsx("div",{className:"space-y-1",children:c.importedAgents.map(C=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Fe,{className:"w-3 h-3 text-emerald-400"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:C.mode})]},C.agentId))})]}),c.createdChannels.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Created channels"}),r.jsx("div",{className:"space-y-1",children:c.createdChannels.map(C=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Tp,{className:"w-3 h-3 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.name})]},C.id))})]}),c.pendingRules.length>0&&r.jsx("div",{className:"rounded-lg bg-amber-500/10 border border-amber-500/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-amber-400",children:[c.pendingRules.length," delegation rule(s) pending approval"]})}),c.failures.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5]",children:["Failed (",c.failures.length,")"]}),c.failures.map((C,E)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80",children:[C.slug,": ",C.error]},E))]}),r.jsx("button",{onClick:()=>{t(),e()},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}function GMe({status:e,color:t}){const n=e==="thinking"||e==="executing";return r.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3",children:[n&&r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:t,opacity:.5},animate:{scale:[1,2,1],opacity:[.5,0,.5]},transition:{duration:2,repeat:1/0,ease:"easeInOut"}}),r.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{backgroundColor:e==="offline"?"#3A3A45":t,opacity:e==="idle"?.5:1}})]})}function KMe({agent:e,onClose:t}){const{data:n,isLoading:s}=L.agents.getMemory.useQuery({agentId:e.id});return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:t,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},className:"relative w-full max-w-2xl bg-[#16161A] border border-[#2A2A35] rounded-2xl overflow-hidden shadow-2xl",onClick:i=>i.stopPropagation(),children:[r.jsxs("div",{className:"px-6 py-5 border-b border-[#2A2A35] flex items-center justify-between",style:{background:`linear-gradient(135deg, rgba(${uh(e.color)}, 0.08) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-2xl",children:e.emoji}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:e.name}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"MEMORY.md — read only"})]})]}),r.jsx("button",{onClick:t,className:"text-[#8A8A99] hover:text-[#F0F0F5] transition-colors text-[20px] leading-none w-8 h-8 flex items-center justify-center rounded-lg hover:bg-white/10",children:"×"})]}),r.jsxs("div",{className:"p-6 max-h-[60vh] overflow-y-auto",children:[s&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] animate-pulse",children:"Loading memory…"}),!s&&!n?.content&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No memory recorded yet."}),!s&&n?.content&&r.jsx("div",{className:"prose-message text-[13px]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:n.content})})]})]})]})}function YMe({agent:e,onConfirm:t,onCancel:n}){return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},className:"relative w-full max-w-sm bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6 shadow-2xl",onClick:s=>s.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx("span",{className:"text-3xl",children:e.emoji}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:["Delete ",e.name,"?"]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"This permanently removes the agent from OpenClaw, deletes all files (SOUL, MEMORY, TEAM), and removes the DM channel."})]})]}),r.jsxs("div",{className:"flex gap-2 mt-6",children:[r.jsx("button",{onClick:n,className:"flex-1 h-9 rounded-lg border border-[#2A2A35] text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45] transition-colors",children:"Cancel"}),r.jsx("button",{onClick:t,className:"flex-1 h-9 rounded-lg bg-red-500/10 border border-red-500/30 text-[13px] text-red-400 hover:bg-red-500/20 transition-colors",children:"Delete"})]})]})]})}function QMe({agent:e}){const[t,n]=y.useState(""),s=L.useUtils(),i=L.agents.update.useMutation({onSuccess:()=>s.agents.list.invalidate()}),{groups:a}=Vm();return r.jsxs(Yv,{onOpenChange:o=>{o||n("")},children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-white/5 hover:bg-white/10 transition-colors text-[12px] text-[#C8C8D4]",children:[r.jsx("span",{children:ta(e.model)}),r.jsx(Jt,{className:"w-3 h-3 rotate-90"})]})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-y-auto shadow-xl z-[9999] min-w-[160px] max-h-[280px]",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:t,onChange:n,onSubmit:o=>{i.mutate({agentId:e.id,model:o}),n("")},placeholder:"Type model ID..."})}),a.map(o=>r.jsxs(g_e,{children:[r.jsx(b_e,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-wider",children:o.label}),o.models.map(l=>r.jsx(Bl,{onSelect:()=>i.mutate({agentId:e.id,model:l.id}),className:ye("w-full text-left px-3 py-1.5 text-[12px] cursor-pointer outline-none hover:bg-white/10 transition-colors",e.model===l.id?"text-[#F0F0F5]":"text-[#8A8A99]"),children:l.label},l.id))]},o.label))]})})]})}function XMe(e,t){const n=atob(e),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n.charCodeAt(l);const i=new Blob([s],{type:"application/zip"}),a=URL.createObjectURL(i),o=document.createElement("a");o.href=a,o.download=t,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}const JMe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],ZMe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16"];function eRe({agent:e,onOpenPanel:t,canManage:n}){const[s,i]=y.useState(!1),[a,o]=y.useState(!1),[l,c]=y.useState(!1),[d,f]=y.useState(e.name),p=y.useRef(null),m=L.useUtils();y.useEffect(()=>{l&&p.current?.select()},[l]),y.useEffect(()=>{f(e.name)},[e.name]);const g=L.agents.update.useMutation({onSuccess:()=>{m.agents.list.invalidate(),m.channels.list.invalidate()}});function b(){c(!1);const C=d.trim();C&&C!==e.name?g.mutate({agentId:e.id,name:C}):f(e.name)}const _=L.agents.delete.useMutation({onSuccess:()=>m.agents.list.invalidate()}),w=L.agents.export.useMutation({onSuccess:C=>XMe(C.buffer,C.filename)}),A=e.status==="offline",S=uh(e.color);return r.jsxs(r.Fragment,{children:[r.jsxs(ne.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},onClick:()=>t(e),className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 hover:border-[#3A3A45] transition-colors group relative overflow-hidden cursor-pointer",children:[r.jsx("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",style:{background:`radial-gradient(400px circle at 0% 0%, rgba(${S}, 0.04), transparent 60%)`}}),r.jsxs("div",{className:"flex items-start gap-4 mb-4",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center text-2xl flex-shrink-0",style:{backgroundColor:`rgba(${S}, 0.15)`,border:`1px solid rgba(${S}, 0.25)`},children:e.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[l?r.jsx("input",{ref:p,value:d,onChange:C=>f(C.target.value),onBlur:b,onKeyDown:C=>{C.key==="Enter"&&p.current?.blur(),C.key==="Escape"&&(f(e.name),c(!1))},onClick:C=>C.stopPropagation(),className:"bg-transparent text-[15px] font-semibold text-[#F0F0F5] outline-none border-b border-[#6366F1]/60 pb-px flex-1 min-w-0"}):r.jsx("h3",{className:"text-[15px] font-semibold text-[#F0F0F5] truncate",children:e.name}),r.jsx(GMe,{status:e.status,color:e.color})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] truncate",children:e.role}),e.lastAction&&r.jsx("p",{className:"text-[11px] text-[#5A5A6A] mt-1",children:Ir(e.lastAction)})]}),n&&e.id!=="coo"&&r.jsx("div",{onClick:C=>C.stopPropagation(),children:r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/10 transition-colors opacity-0 group-hover:opacity-100",children:r.jsx(iL,{className:"w-4 h-4"})})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,align:"end",className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-hidden shadow-xl z-[9999] min-w-[160px]",children:[r.jsxs(Bl,{onSelect:()=>c(!0),className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(oh,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Rename"]}),r.jsxs(lR,{children:[r.jsxs(cR,{className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors data-[state=open]:bg-white/10",children:[r.jsx(Tre,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Change emoji",r.jsx(Jt,{className:"w-3 h-3 ml-auto text-[#5A5A6E]"})]}),r.jsx(Od,{children:r.jsxs(uR,{sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Choose emoji"}),r.jsx("div",{className:"grid grid-cols-10 gap-1",children:JMe.map(C=>r.jsx(Bl,{onSelect:()=>g.mutate({agentId:e.id,emoji:C}),className:`w-6 h-6 flex items-center justify-center rounded text-sm cursor-pointer outline-none hover:bg-white/10 transition-colors ${e.emoji===C?"bg-white/15 ring-1 ring-white/20":""}`,children:C},C))})]})})]}),r.jsxs(lR,{children:[r.jsxs(cR,{className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors data-[state=open]:bg-white/10",children:[r.jsx(Zie,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Change color",r.jsx(Jt,{className:"w-3 h-3 ml-auto text-[#5A5A6E]"})]}),r.jsx(Od,{children:r.jsxs(uR,{sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Choose color"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:ZMe.map(C=>r.jsx(Bl,{onSelect:()=>g.mutate({agentId:e.id,color:C}),className:`w-7 h-7 rounded-full cursor-pointer outline-none transition-all ${e.color===C?"ring-2 ring-white/40 scale-110":"hover:scale-110"}`,style:{backgroundColor:C}},C))})]})})]})]})})]})})]}),r.jsxs("p",{className:"text-[12px] text-[#6A6A7A] leading-relaxed line-clamp-2 mb-4 italic",children:['"',e.soulExcerpt,'"']}),r.jsxs("div",{className:"flex items-center gap-2",onClick:C=>C.stopPropagation(),children:[n&&r.jsx(QMe,{agent:e}),n&&r.jsx(bt,{label:"Edit soul",children:r.jsx(gn,{to:`/agents/edit-soul/${e.id}`,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Ese,{className:"w-3.5 h-3.5"})})}),r.jsx(bt,{label:"View memory",children:r.jsx("button",{onClick:()=>i(!0),className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(eie,{className:"w-3.5 h-3.5"})})}),n&&r.jsx(bt,{label:A?"Resume":"Pause",children:r.jsx("button",{onClick:()=>g.mutate({agentId:e.id,status:A?"idle":"offline"}),className:ye("w-7 h-7 flex items-center justify-center rounded-md transition-colors",A?"text-emerald-400 hover:bg-emerald-500/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10"),children:A?r.jsx(I5,{className:"w-3.5 h-3.5"}):r.jsx(gL,{className:"w-3.5 h-3.5"})})}),n&&e.id!=="coo"&&r.jsx(bt,{label:"Export agent",children:r.jsx("button",{onClick:()=>w.mutate({agentId:e.id}),disabled:w.isPending,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/10 transition-colors opacity-0 group-hover:opacity-100 disabled:opacity-50",children:r.jsx(nu,{className:"w-3.5 h-3.5"})})}),n&&r.jsx(bt,{label:"Delete agent",children:r.jsx("button",{onClick:()=>o(!0),className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors opacity-0 group-hover:opacity-100",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]})]}),r.jsxs(Me,{children:[s&&r.jsx(KMe,{agent:e,onClose:()=>i(!1)}),a&&r.jsx(YMe,{agent:e,onCancel:()=>o(!1),onConfirm:()=>{_.mutate({agentId:e.id}),o(!1)}})]})]})}function tRe(){const[e,t]=y.useState(null),[n,s]=y.useState(!1),[i,a]=y.useState(!1),[o,l]=y.useState(!1),{data:c=[],isLoading:d}=L.agents.list.useQuery(),f=L.useUtils(),p=Uo();return r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11]",children:[r.jsxs("div",{className:"max-w-4xl mx-auto px-8 py-10",children:[r.jsxs("div",{className:"flex items-center justify-between mb-8",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"Agents"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mt-0.5",children:"Your team of AI collaborators"})]}),p&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-xl border border-[#2A2A35] text-[#C8C8D4] text-[13px] font-medium hover:bg-white/5 transition-colors",children:[r.jsx(su,{className:"w-4 h-4"}),"Import",r.jsx(Jt,{className:"w-3 h-3 rotate-90 text-[#5A5A6E]"})]})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,align:"end",className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-hidden shadow-xl z-[9999] min-w-[180px]",children:[r.jsxs(Bl,{onSelect:()=>s(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(su,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Import agent"]}),r.jsxs(Bl,{onSelect:()=>l(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(wm,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Import team"]}),r.jsx(v_e,{className:"h-px bg-[#2A2A35] my-1"}),r.jsxs(Bl,{onSelect:()=>a(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(vv,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Export team"]})]})})]}),r.jsxs(gn,{to:"/agents/new",className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium hover:opacity-90 transition-opacity shadow-lg shadow-[#6366F1]/20",children:[r.jsx(wt,{className:"w-4 h-4"}),"New agent"]})]})]}),d&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[1,2,3].map(m=>r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 animate-pulse h-[180px]"},m))}),!d&&c.length===0&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mb-4 text-2xl",children:"🤖"}),r.jsx("h2",{className:"text-[16px] font-semibold text-[#F0F0F5] mb-2",children:"No agents yet"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mb-6 max-w-xs",children:"Create your first AI agent and it'll be live in under 60 seconds."}),p&&r.jsxs(gn,{to:"/agents/new",className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium hover:opacity-90 transition-opacity",children:[r.jsx(wt,{className:"w-4 h-4"}),"Create agent"]})]}),!d&&c.length>0&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:c.map(m=>r.jsx(eRe,{agent:m,onOpenPanel:t,canManage:p},m.id))})]}),r.jsxs(Me,{children:[e&&r.jsx($N,{agent:e,agentColor:e.color,onClose:()=>t(null),onOverrideSet:()=>t(null)},e.id),n&&r.jsx(HMe,{onClose:()=>s(!1),onSuccess:()=>f.agents.list.invalidate()}),i&&r.jsx(WMe,{onClose:()=>a(!1)}),o&&r.jsx(qMe,{onClose:()=>l(!1),onSuccess:()=>{f.agents.list.invalidate()}})]})]})}const nRe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],sRe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16","#6366F1"],iRe=[{id:"qwen3:14b",label:"Qwen 3 14B",note:"Fast · Local · Free"},{id:"tomng/nanbeige4.1",label:"NanBeige 4.1 · 3B",note:"Agentic · Local · Free"},{id:"anthropic/claude-sonnet-4.6",label:"Claude Sonnet",note:"Smart · Fast · $$$"},{id:"anthropic/claude-opus-4.6",label:"Claude Opus",note:"Best · Slow · $$$$"}];function rRe({color:e,name:t,emoji:n}){const s=uh(e),i=t||"Agent",a=n||"🤖";return r.jsxs("div",{className:"rounded-xl overflow-hidden border border-[#2A2A35] bg-[#0F0F11]",children:[r.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",style:{borderLeft:`3px solid ${e}`,background:`linear-gradient(90deg, rgba(${s}, 0.08) 0%, transparent 60%)`},children:[r.jsx("span",{className:"text-lg",children:a}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:i}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:"online"})]}),r.jsx("div",{className:"ml-auto w-2 h-2 rounded-full",style:{backgroundColor:e}})]}),r.jsx("div",{className:"px-4 py-3",children:r.jsx("div",{className:"rounded-xl px-3 py-2 max-w-[75%]",style:{backgroundColor:`rgba(${s}, 0.12)`,border:`1px solid rgba(${s}, 0.2)`},children:r.jsx("p",{className:"text-[12px] text-[#C8C8D4]",children:"Ready to help. What do you need?"})})})]})}function aRe({state:e,onChange:t,onNext:n}){const s=e.name.trim().length>0&&e.role.trim().length>0;return r.jsxs("div",{className:"flex gap-8 h-full",children:[r.jsxs("div",{className:"flex-1 space-y-6",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Name"}),r.jsx("input",{value:e.name,onChange:i=>t({name:i.target.value}),placeholder:"e.g. Nova, Relay, Axiom",className:"w-full h-10 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[14px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Role"}),r.jsx("input",{value:e.role,onChange:i=>t({role:i.target.value}),placeholder:"e.g. Content Strategist, Research Analyst",className:"w-full h-10 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[14px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Emoji"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:nRe.map(i=>r.jsx("button",{onClick:()=>t({emoji:i}),className:ye("w-9 h-9 rounded-lg text-lg transition-all",e.emoji===i?"bg-[#6366F1]/20 ring-2 ring-[#6366F1] scale-110":"bg-[#1E1E24] hover:bg-[#2A2A35]"),children:i},i))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Color"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:sRe.map(i=>r.jsx("button",{onClick:()=>t({color:i}),className:ye("w-7 h-7 rounded-full transition-all",e.color===i?"ring-2 ring-offset-2 ring-offset-[#0F0F11] scale-125":"hover:scale-110"),style:{backgroundColor:i,outlineColor:i}},i))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Model"}),r.jsx("div",{className:"space-y-2",children:iRe.map(i=>r.jsxs("button",{onClick:()=>t({model:i.id}),className:ye("w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all text-left",e.model===i.id?"bg-[#6366F1]/10 border-[#6366F1]/50 text-[#F0F0F5]":"bg-[#1E1E24] border-[#2A2A35] text-[#8A8A99] hover:border-[#3A3A45] hover:text-[#C8C8D4]"),children:[r.jsx("span",{className:"text-[13px] font-medium",children:i.label}),r.jsx("span",{className:"text-[11px] opacity-60",children:i.note})]},i.id))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Visibility"}),r.jsx("div",{className:"flex gap-2",children:[{value:"public",icon:Xt,label:"Public"},{value:"private",icon:Eo,label:"Private"},{value:"owner",icon:Ia,label:"Owner only"}].map(({value:i,icon:a,label:o})=>r.jsxs("button",{onClick:()=>t({visibility:i}),className:ye("flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-xl border transition-all text-[12px] font-medium",e.visibility===i?"bg-[#6366F1]/10 border-[#6366F1]/50 text-[#F0F0F5]":"bg-[#1E1E24] border-[#2A2A35] text-[#8A8A99] hover:border-[#3A3A45] hover:text-[#C8C8D4]"),children:[r.jsx(a,{className:"w-3 h-3"}),o]},i))})]})]}),r.jsxs("div",{className:"w-[260px] flex-shrink-0 space-y-4",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Preview"}),r.jsx(rRe,{color:e.color,name:e.name,emoji:e.emoji})]}),r.jsxs("button",{onClick:n,disabled:!s,className:"w-full h-10 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-30 disabled:cursor-not-allowed shadow-lg shadow-[#6366F1]/20",children:["Continue",r.jsx(tu,{className:"w-4 h-4"})]})]})]})}function vW({state:e,soul:t,onSoulChange:n,onNext:s,onBack:i,editMode:a,initialSoul:o}){const[l,c]=y.useState(()=>a&&o?[{role:"assistant",content:`I've loaded ${e.name}'s current soul. What would you like to change? You can say things like "make it more direct", "add a section about how to handle conflicts", or just describe the vibe you want.`}]:[]),[d,f]=y.useState(""),[p,m]=y.useState(!1),[g,b]=y.useState(""),[_,w]=y.useState(a&&!!o),A=y.useRef(null),S=y.useRef(null);y.useEffect(()=>{A.current?.scrollIntoView({behavior:"smooth"})},[l,g]);const C=y.useCallback(async(T,F)=>{m(!0),b("");const M={description:T,agentName:e.name,agentRole:e.role};F&&(M.refinement=F),a&&o&&(M.currentSoul=o);try{const I=await fetch(`${oi}/api/agents/generate-soul`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(!I.ok)throw new Error("Generation failed");const H=(await I.json()).text;n(H),b(""),w(!0),c(V=>[...V,{role:"assistant",content:"Here's the soul I've written. Take a look — you can refine it by telling me what to change, or proceed when you're happy."}])}catch{c(I=>[...I,{role:"assistant",content:"Something went wrong generating the soul. Please try again."}])}finally{m(!1)}},[e.name,e.role,n,a,o]);async function E(){const T=d.trim();if(!T||p)return;f("");const F={role:"user",content:T};c(M=>[...M,F]),_?await C(T,T):await C(T)}const k=uh(e.color);return r.jsxs("div",{className:"flex gap-6 h-full min-h-0",children:[r.jsxs("div",{className:"flex flex-col w-[320px] flex-shrink-0 min-h-0",children:[r.jsxs("div",{className:"flex-1 overflow-y-auto space-y-3 pr-1 min-h-0",children:[l.length===0&&r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`rgba(${k}, 0.2)`},children:e.emoji}),r.jsx("div",{className:"flex-1 bg-[#1E1E24] rounded-xl rounded-tl-sm px-3 py-2.5",children:r.jsxs("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:["I'm going to write ",e.name,"'s soul. Describe their personality in a few sentences. What do they care about? What makes them distinct? What won't they do?"]})})]}),l.map((T,F)=>r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:ye("flex items-start gap-3",T.role==="user"&&"flex-row-reverse"),children:[T.role==="assistant"&&r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`rgba(${k}, 0.2)`},children:e.emoji}),r.jsx("div",{className:ye("flex-1 rounded-xl px-3 py-2.5",T.role==="user"?"bg-[#6366F1]/15 rounded-tr-sm ml-8":"bg-[#1E1E24] rounded-tl-sm mr-8"),children:r.jsx("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:T.content})})]},F)),p&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"flex items-center gap-2 pl-10",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce [animation-delay:0.15s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce [animation-delay:0.3s]"})]}),r.jsx("div",{ref:A})]}),r.jsxs("div",{className:"mt-3 flex gap-2",children:[r.jsx("input",{ref:S,value:d,onChange:T=>f(T.target.value),onKeyDown:T=>T.key==="Enter"&&!T.shiftKey&&E(),placeholder:_?"Refine it…":"Describe their personality…",disabled:p,className:"flex-1 h-9 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors disabled:opacity-50"}),r.jsx("button",{onClick:E,disabled:!d.trim()||p,className:"w-9 h-9 rounded-xl flex items-center justify-center transition-all disabled:opacity-30",style:{backgroundColor:`rgba(${k}, 0.2)`,color:e.color},children:p?r.jsx(Xi,{className:"w-4 h-4 animate-spin"}):r.jsx(Ji,{className:"w-4 h-4"})})]})]}),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#8A8A99] uppercase tracking-wider",children:"SOUL.md preview"}),p&&r.jsx("p",{className:"text-[11px] text-[#8A8A99] animate-pulse",children:"Generating…"})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11] border border-[#2A2A35] rounded-xl p-4 min-h-0",children:[!t&&!g&&!p&&r.jsx("p",{className:"text-[13px] text-[#5A5A6A] italic",children:"The soul will appear here as it's generated…"}),(t||g)&&r.jsx("div",{className:"prose-message text-[12px] text-[#C8C8D4] leading-relaxed",children:r.jsx(Ei,{remarkPlugins:[Fi],children:g||t})})]}),r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 h-9 px-4 rounded-xl border border-[#2A2A35] text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45] transition-colors",children:[r.jsx(gm,{className:"w-4 h-4"}),"Back"]}),r.jsxs("button",{onClick:s,disabled:!t||p,className:"flex-1 h-9 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-30 disabled:cursor-not-allowed",children:["Looks good",r.jsx(tu,{className:"w-4 h-4"})]})]})]})]})}function oRe({title:e,content:t}){const[n,s]=y.useState(e==="SOUL.md");return r.jsxs("div",{className:"border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>s(i=>!i),className:"w-full flex items-center justify-between px-4 py-3 bg-[#1E1E24] hover:bg-[#2A2A35] transition-colors text-left",children:[r.jsx("span",{className:"text-[13px] font-mono font-medium text-[#C8C8D4]",children:e}),r.jsx(ne.span,{animate:{rotate:n?90:0},transition:{duration:.15},children:r.jsx(tu,{className:"w-3.5 h-3.5 text-[#8A8A99]"})})]}),r.jsx(Me,{children:n&&r.jsx(ne.div,{initial:{height:0},animate:{height:"auto"},exit:{height:0},transition:{duration:.2},className:"overflow-hidden",children:r.jsx("div",{className:"p-4 max-h-48 overflow-y-auto bg-[#0F0F11]",children:r.jsx("div",{className:"prose-message text-[12px] text-[#8A8A99]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:t})})})})})]})}function lRe(e){return`# IDENTITY.md — ${e.name}
354
+ `).map((a,o)=>{let l="text-[#8A8A99]";return a.startsWith("+")&&!a.startsWith("+++")?l="text-[#34D399]":a.startsWith("-")&&!a.startsWith("---")?l="text-[#F87171]":a.startsWith("@@")&&(l="text-[#6366F1]"),r.jsx("div",{className:l,children:a||" "},o)})})})]}):r.jsxs("div",{className:"border-t border-[#2A2A35] p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("code",{className:"text-[12px] font-mono text-[#C8C8D4]",children:t}),r.jsx("button",{onClick:n,className:"text-[11px] text-[#5A5A6E] hover:text-[#C8C8D4] transition-colors",children:"Close"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] italic",children:"No changes to display."})]})}function WTe({agentId:e}){const[t,n]=y.useState(new Set),[s,i]=y.useState(null),a=L.useUtils(),{data:o,isLoading:l}=L.git.hasRepo.useQuery({agentId:e}),{data:c,isLoading:d}=L.git.status.useQuery({agentId:e},{enabled:!!o?.hasRepo,refetchInterval:1e4}),{data:f=[]}=L.git.log.useQuery({agentId:e,limit:10},{enabled:!!o?.hasRepo,refetchInterval:3e4}),p=y.useMemo(()=>c?[...c.staged.map(w=>({...w,category:"staged"})),...c.modified.map(w=>({...w,category:"modified"})),...c.untracked.map(w=>({...w,category:"untracked"}))]:[],[c]),m=y.useCallback(w=>{n(A=>{const S=new Set(A);return S.has(w)?S.delete(w):S.add(w),S})},[]),g=y.useCallback(()=>{n(new Set(p.map(w=>w.path)))},[p]),b=y.useCallback(()=>{n(new Set)},[]),_=y.useCallback(()=>{a.git.status.invalidate({agentId:e}),a.git.log.invalidate({agentId:e})},[a,e]);return l?r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Pe,{className:"w-5 h-5 text-[#5A5A6E] animate-spin"})}):o?.hasRepo?r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:[c&&r.jsx(UTe,{agentId:e,currentBranch:c.branch}),r.jsx("button",{onClick:_,className:"p-1.5 rounded-md text-[#5A5A6E] hover:text-[#C8C8D4] hover:bg-white/5 transition-colors",title:"Refresh",children:r.jsx(Xi,{className:ye("w-3.5 h-3.5",d&&"animate-spin")})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[r.jsx("div",{className:"px-3 pt-2",children:r.jsx(LTe,{agentId:e})}),d&&r.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-4 text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.2s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse [animation-delay:0.4s]"})]}),!d&&p.length===0&&f.length===0&&r.jsx("p",{className:"px-4 py-4 text-[12px] text-[#5A5A6E] italic",children:"Working tree clean. No changes."}),p.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:["Changes (",p.length,")"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:g,className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"All"}),r.jsx("button",{onClick:b,className:"text-[10px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"None"})]})]}),c?.staged&&c.staged.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#10B981] uppercase tracking-widest",children:"Staged"}),c.staged.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!0,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`staged-${w.path}`))]}),c?.modified&&c.modified.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#F59E0B] uppercase tracking-widest",children:"Modified"}),c.modified.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!1,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`modified-${w.path}`))]}),c?.untracked&&c.untracked.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"px-3 py-1 text-[9px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:"Untracked"}),c.untracked.map(w=>r.jsx(e2,{path:w.path,status:w.status,staged:!1,selected:t.has(w.path),onSelect:()=>m(w.path),onViewDiff:()=>i(w.path)},`untracked-${w.path}`))]})]}),f.length>0&&r.jsxs("div",{className:"mt-2",children:[r.jsx("p",{className:"px-3 py-1.5 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest border-t border-[#2A2A35]/50",children:"Recent commits"}),f.map(w=>r.jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-white/[0.02] transition-colors",children:[r.jsx(Hse,{className:"w-2 h-2 text-[#5A5A6E] mt-1 flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] text-[#C8C8D4] truncate",children:w.message}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:[r.jsx("code",{className:"text-[#6366F1]",children:w.shortHash}),r.jsx("span",{className:"mx-1",children:"·"}),w.author,r.jsx("span",{className:"mx-1",children:"·"}),r.jsx(BTe,{date:w.date})]})]})]},w.hash))]})]}),s&&r.jsx(HTe,{agentId:e,filePath:s,onClose:()=>i(null)}),p.length>0&&r.jsx(VTe,{agentId:e,selectedFiles:[...t],onCommitted:()=>{n(new Set),_()}})]}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-5 gap-2",children:[r.jsx(Zl,{className:"w-8 h-8 text-[#3A3A45]"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic text-center",children:"No git repository detected"}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E] text-center",children:"Mount a project directory with a git repo in Settings → File Access."})]})}function qTe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const s=Math.floor(n/60);if(s<60)return`${s} min ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function GTe(e){return new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function KTe(e){const t=new Date(e).getTime()-Date.now();if(t<=0)return"eligible now";const n=Math.floor(t/(3600*1e3)),s=Math.floor(t%(3600*1e3)/(60*1e3));return n>0?`~${n}h ${s}m`:`~${s}m`}function YTe({agentId:e}){const{data:t}=L.dream.status.useQuery({agentId:e},{staleTime:3e4}),n=t?.[e];return n?r.jsxs("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(_L,{className:"w-3.5 h-3.5 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] font-medium text-[#F0F0F5]",children:"Dream Status"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-y-1.5 text-[11px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Last dream"}),r.jsx("span",{className:"text-[#C8C8D4]",children:qTe(n.lastDreamAt)}),r.jsx("span",{className:"text-[#8A8A99]",children:"Notes changed"}),r.jsx("span",{className:"text-[#C8C8D4]",children:n.lastDreamNotesChanged}),r.jsx("span",{className:"text-[#8A8A99]",children:"Cost"}),r.jsxs("span",{className:"text-[#10B981]",children:["$",n.lastDreamCostUsd.toFixed(4)]}),r.jsx("span",{className:"text-[#8A8A99]",children:"Next eligible"}),r.jsx("span",{className:"text-[#C8C8D4]",children:KTe(n.nextDreamEstimate)})]})]}):r.jsx("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:r.jsx("p",{className:"text-[12px] text-[#5A5A6E] italic",children:"No dream data yet. Trigger a dream to start memory consolidation."})})}function QTe({preferences:e}){return e.length===0?null:r.jsxs("div",{className:"mx-4 mt-3 px-4 py-3 bg-[#1C1C24] rounded-lg border border-[#2A2A35]",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#F0F0F5] mb-2",children:"Routing Preferences"}),r.jsx("div",{className:"space-y-2",children:e.map((t,n)=>r.jsxs("div",{className:"flex items-start gap-2 text-[11px]",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[#C8C8D4]",children:t.taskPattern}),r.jsxs("p",{className:"text-[#5A5A6E] mt-0.5",children:["→ ",t.preferredAgentId," — ",t.reason]})]}),r.jsxs("span",{className:`flex-shrink-0 px-1.5 py-0.5 rounded text-[10px] font-medium ${t.confidence>=.8?"bg-[#10B981]/15 text-[#10B981]":t.confidence>=.5?"bg-[#F59E0B]/15 text-[#F59E0B]":"bg-[#EF4444]/15 text-[#EF4444]"}`,children:[(t.confidence*100).toFixed(0),"%"]})]},n))})]})}function XTe({entries:e}){return e.length===0?r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4 text-center italic",children:"No dream history."}):r.jsxs("div",{className:"relative",children:[e.length>0&&r.jsx("div",{className:"absolute left-[9px] top-0 bottom-0 w-px bg-[#2A2A35]"}),r.jsx("div",{className:"space-y-0",children:e.map(t=>r.jsxs("div",{className:"flex gap-3 py-2.5 relative",children:[r.jsx("div",{className:"w-5 h-5 rounded-full bg-[#1C1C24] border border-[#2A2A35] flex items-center justify-center text-[10px] flex-shrink-0 z-10 mt-0.5",children:"💤"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("p",{className:"text-[12px] text-[#C8C8D4] leading-snug",children:["+",t.notesAdded," added · ",t.notesMerged," merged · ",t.notesPruned," pruned",t.constraintsFlagged.length>0&&r.jsxs("span",{className:"text-[#F59E0B]",children:[" · ",t.constraintsFlagged.length," flagged"]})]}),t.constraintsFlagged.length>0&&r.jsx("div",{className:"mt-1 space-y-0.5",children:t.constraintsFlagged.map((n,s)=>r.jsxs("p",{className:"text-[10px] text-[#F59E0B]/80",children:["⚠ ",n]},s))}),t.agentHealthNotes&&t.agentHealthNotes.length>0&&r.jsx("div",{className:"mt-1 space-y-0.5",children:t.agentHealthNotes.map((n,s)=>r.jsxs("p",{className:"text-[10px] text-[#8A8A99]",children:[n.agentId,": ",n.observation]},s))}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:[GTe(t.ts),t.durationMs!=null&&` · ${Math.round(t.durationMs/1e3)}s`,t.costEstimateUsd>0&&` · $${t.costEstimateUsd.toFixed(4)}`]})]})]},t.id))})]})}function JTe({agentId:e}){const[t,n]=y.useState(!1),{data:s=[],isLoading:i}=L.dream.history.useQuery({agentId:e,limit:20},{refetchInterval:3e4}),a=L.useUtils(),o=y.useRef(0);o.current=s.length;const l=L.dream.trigger.useMutation({onSuccess:f=>{if(!f.started){n(!1);return}const p=o.current,m=setInterval(async()=>{await a.dream.history.invalidate({agentId:e}),await a.dream.status.invalidate({agentId:e});const g=a.dream.history.getData({agentId:e,limit:20});g&&g.length>p&&(clearInterval(m),n(!1))},4e3);setTimeout(()=>{clearInterval(m),n(!1)},12e4)},onError:()=>n(!1)}),c=e==="coo",d=c?s.find(f=>f.routingPreferences&&f.routingPreferences.length>0)?.routingPreferences??[]:[];return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[r.jsx(YTe,{agentId:e}),c&&d.length>0&&r.jsx(QTe,{preferences:d}),r.jsxs("div",{className:"px-4 mt-3 flex-shrink-0",children:[r.jsxs("button",{onClick:()=>{n(!0),l.mutate({agentId:e})},disabled:t||l.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#6366F1] text-white hover:bg-[#5558E6] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[t||l.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(_L,{className:"w-3 h-3"}),t?"Dreaming...":"Trigger Dream"]}),l.data&&!l.data.started&&r.jsx("p",{className:"text-[10px] text-[#F59E0B] mt-1",children:l.data.reason})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4 mt-3",children:[i&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-4 text-center",children:"Loading..."}),!i&&r.jsx(XTe,{entries:s})]})]})}const ZTe=["complexity:low","complexity:medium","complexity:high","task:code","task:creative","task:analysis","task:tool_use"];function Gb({value:e,onChange:t,customModels:n=[],agentId:s}){const[i,a]=y.useState(""),o=L.useUtils(),l=L.agents.addCustomModel.useMutation({onSuccess:()=>o.agents.list.invalidate()}),c=L.agents.removeCustomModel.useMutation({onSuccess:()=>o.agents.list.invalidate()}),{groups:d}=Vm(),f=Up(e);return r.jsxs(ss,{value:e,onValueChange:t,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors min-w-[140px]",children:[r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[f]}`,children:f}),r.jsx(Ds,{children:ta(e)}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] max-h-[280px] overflow-y-auto z-[9999]",children:[s&&r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:i,onChange:a,onSubmit:p=>{s&&(l.mutate({agentId:s,modelId:p}),t(p),a(""))},placeholder:"Type model ID..."})}),r.jsxs(os,{children:[d.map(p=>r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:p.label}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo[p.tag]}`,children:p.tag})]}),p.models.map(m=>r.jsxs(vn,{value:m.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:m.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},m.id))]},p.label)),n.length>0&&r.jsxs(Ro,{children:[r.jsxs(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest flex items-center gap-1.5",children:[r.jsx("span",{children:"Custom"}),r.jsx("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${jo.custom}`,children:"custom"})]}),n.map(p=>r.jsxs(vn,{value:p,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:p}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})}),s&&r.jsx(bt,{label:"Remove model",children:r.jsx("button",{onClick:m=>{m.stopPropagation(),c.mutate({agentId:s,modelId:p})},className:"text-[#5A5A6E] hover:text-[#F87171] transition-colors",children:r.jsx(Te,{className:"w-3 h-3"})})})]})]},p))]})]})]})})]})}function eMe({value:e,onChange:t}){return r.jsxs(ss,{value:e,onValueChange:t,children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors min-w-[150px]",children:[r.jsx(Ds,{children:e}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[170px] z-[9999]",children:r.jsx(os,{children:ZTe.map(n=>r.jsxs(vn,{value:n,className:"flex items-center justify-between px-3 py-2 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:n}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},n))})})})]})}function tMe(e,t){if(t.length===0)return`Always uses ${ta(e)}.`;const n=t.map(s=>`For ${s.condition} → ${ta(s.model)}`);return n.push(`For everything else → ${ta(e)}`),n.join(". ")+"."}function nMe({fallbacks:e,onAdd:t,onRemove:n,customModels:s,agentId:i}){const[a,o]=y.useState(!1),[l,c]=y.useState("");function d(){l&&(t(l),c(""),o(!1))}return r.jsxs("div",{className:"space-y-2",children:[e.map((f,p)=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-[11px] text-[#5A5A6E] w-4 flex-shrink-0",children:[p+1,"."]}),r.jsx("span",{className:"flex-1 text-[12px] text-[#C8C8D4] truncate",children:ta(f)}),r.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium ${jo[Up(f)]}`,children:Up(f)}),r.jsx("button",{onClick:()=>n(p),className:"w-5 h-5 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Te,{className:"w-3 h-3"})})]},p)),a?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Gb,{value:l||"qwen3:14b",onChange:c,customModels:s,agentId:i}),r.jsx("button",{onClick:d,className:"text-[11px] text-[#10B981] hover:text-[#34D399] font-medium transition-colors",children:"Add"}),r.jsx("button",{onClick:()=>o(!1),className:"text-[11px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Cancel"})]}):r.jsxs("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add fallback"]})]})}const sMe=[{id:"__default__",label:"Workspace default"},{id:"openclaw",label:"OpenClaw"},{id:"anthropic",label:"Anthropic"},{id:"claude-code",label:"Claude Code"},{id:"ollama",label:"Ollama"},{id:"openrouter",label:"OpenRouter"}];function iMe({agentId:e}){const{data:t}=L.agents.getGateway.useQuery({agentId:e}),n=L.useUtils(),s=L.agents.setGateway.useMutation({onSuccess:()=>n.agents.getGateway.invalidate({agentId:e})}),i=t?.gatewayId||"__default__";return r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Runtime"}),r.jsxs(ss,{value:i,onValueChange:a=>s.mutate({agentId:e,gatewayId:a==="__default__"?null:a}),children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#1C1C21] text-[13px] text-[#F0F0F5] hover:bg-[#2A2A35] transition-colors",children:[r.jsx(Ds,{}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C21] border border-[#2A2A35] rounded-lg shadow-xl z-[9999] overflow-hidden",children:r.jsx(os,{className:"p-1",children:sMe.map(a=>r.jsxs(vn,{value:a.id,className:"flex items-center gap-2 px-3 py-2 rounded text-[13px] text-[#F0F0F5] cursor-pointer outline-none data-[highlighted]:bg-[#2A2A35]",children:[r.jsx(yn,{children:a.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"})})]},a.id))})})})]})]})}function rMe({agent:e,agentColor:t}){const{data:n}=L.onboarding.getState.useQuery(void 0,{staleTime:3e4,refetchOnWindowFocus:!1}),s=(()=>{try{return e.customModels?JSON.parse(e.customModels):[]}catch{return[]}})(),i=s[0]??null,a=n?.defaultReasoningModel??i??"qwen3:14b",o=!e.defaultModel&&!n?.defaultReasoningModel,[l,c]=y.useState(e.defaultModel??a),[d,f]=y.useState(()=>{try{return e.modelRules?JSON.parse(e.modelRules):[]}catch{return[]}}),p=s,[m,g]=y.useState("idle"),b=y.useRef(null),_=L.useUtils(),w=L.agents.setModelConfig.useMutation({onSuccess:()=>{_.agents.list.invalidate(),_.agents.getFallbackModels.invalidate({agentId:e.id})}}),A=e.gatewayId??n?.gatewayType??"openclaw",S=A==="openclaw"||A==="openrouter",{data:C}=L.agents.getFallbackModels.useQuery({agentId:e.id},{enabled:S}),[E,k]=y.useState(null),T=E??C?.agent??[],F=C?.defaults??[],M=T.length===0&&F.length>0,[I,R]=y.useState(e.fallbackModel??null);y.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const H=[{label:"Local",description:"Free · Fully offline",defaultModel:"qwen3:14b",rules:[{condition:"task:tool_use",model:"tomng/nanbeige4.1"}]},{label:"Hybrid",description:"Smart routing · Best bang for buck",defaultModel:"qwen3:14b",rules:[{condition:"task:tool_use",model:"tomng/nanbeige4.1"},{condition:"task:code",model:"claude-sonnet-4.6"},{condition:"complexity:high",model:"claude-opus-4.6"}]}];function V(W){c(W.defaultModel),f(W.rules)}function K(){f(W=>[...W,{condition:"complexity:high",model:"claude-sonnet-4.6"}])}function q(W){f(O=>O.filter((D,Q)=>Q!==W))}function $(W,O){f(D=>D.map((Q,z)=>z===W?{...Q,...O}:Q))}function B(W){k([...T,W])}function Y(W){k(T.filter((O,D)=>D!==W))}async function U(){g("saving"),await w.mutateAsync({agentId:e.id,defaultModel:l,modelRules:d,customModels:p,...S?{fallbackModels:E??void 0}:{fallbackModel:I}}),g("saved"),k(null),b.current=setTimeout(()=>g("idle"),2e3)}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-4 overflow-y-auto",children:[o&&r.jsx("div",{className:"flex items-start gap-2 px-3 py-2.5 rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20",children:r.jsx("span",{className:"text-[#F59E0B] text-[13px] leading-snug",children:"No model configured. Visit Settings → Models to set one."})}),r.jsx(iMe,{agentId:e.id}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Default Model"}),r.jsx(Gb,{value:l,onChange:c,customModels:p,agentId:e.id})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Presets"}),r.jsx("div",{className:"flex gap-2",children:H.map(W=>r.jsxs("button",{onClick:()=>V(W),className:"flex-1 rounded-lg border border-[#2A2A35] bg-[#1C1C21] hover:bg-[#2A2A35] transition-colors px-3 py-2 text-left",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#F0F0F5]",children:W.label}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:W.description})]},W.label))})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Routing Rules"}),r.jsx("div",{className:"space-y-2",children:d.map((W,O)=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(eMe,{value:W.condition,onChange:D=>$(O,{condition:D})}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E] flex-shrink-0",children:"→"}),r.jsx(Gb,{value:W.model,onChange:D=>$(O,{model:D}),customModels:p,agentId:e.id}),r.jsx(bt,{label:"Remove rule",children:r.jsx("button",{onClick:()=>q(O),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]},O))}),r.jsxs("button",{onClick:K,className:"mt-3 flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add rule"]})]}),S?r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Fallback Models"})]}),M&&T.length===0&&r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] mb-2",children:["Inheriting from defaults: ",F.map(ta).join(", ")]}),r.jsx(nMe,{fallbacks:T,onAdd:B,onRemove:Y,customModels:p,agentId:e.id}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-2",children:["Handled natively by ",A==="openclaw"?"OpenClaw":"OpenRouter","."]})]}):r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Fallback Model"})]}),I?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Gb,{value:I,onChange:W=>R(W),customModels:p,agentId:e.id}),r.jsx(bt,{label:"Remove fallback",children:r.jsx("button",{onClick:()=>R(null),className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#F87171] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})})]}):r.jsxs("button",{onClick:()=>R(l),className:"flex items-center gap-1.5 text-[12px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add fallback"]}),r.jsx("p",{className:"text-[10px] text-[#5A5A6E] mt-2",children:"Used when the primary model is rate-limited or unavailable."})]}),r.jsx("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] px-3 py-2.5",children:r.jsx("p",{className:"text-[11px] text-[#8A8A99] italic leading-relaxed",children:tMe(l,d)})}),r.jsx("button",{onClick:U,disabled:w.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium transition-colors disabled:opacity-50",style:{backgroundColor:t,color:"#fff"},children:r.jsxs(Me,{mode:"wait",children:[m==="saving"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saving..."},"saving"),m==="saved"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved ✓"},"saved"),m==="idle"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")]})})]})}const aMe={"Be brief":"Keep all responses under 3 sentences. Be direct.","Be creative":"Be imaginative, use analogies, think laterally.","Be strict":"Only respond with facts. No speculation. Cite reasoning."};function mW(e,t=500){const[n,s]=y.useState("idle"),i=y.useRef(null),a=y.useRef(null);y.useEffect(()=>()=>{i.current&&clearTimeout(i.current),a.current&&clearTimeout(a.current)},[]);const o=y.useCallback(l=>{l!==void 0&&(i.current&&clearTimeout(i.current),a.current&&clearTimeout(a.current),s("saving"),i.current=setTimeout(async()=>{await e(l),s("saved"),a.current=setTimeout(()=>s("idle"),2e3)},t))},[e,t]);return{saveState:n,handleChange:o}}function xW({saveState:e}){return r.jsxs(Me,{mode:"wait",children:[e==="saving"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[11px] text-[#8A8A99]",children:"Saving..."},"saving"),e==="saved"&&r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"text-[11px] text-[#10B981]",children:"Saved ✓"},"saved")]})}const Q8={gateway:{label:"Gateway",color:"#3B82F6"},harness:{label:"Claude Code",color:"#8B5CF6"},terminal:{label:"Terminal",color:"#10B981"}};function oMe({agentId:e}){const{data:t}=L.events.activeRuntimes.useQuery({agentId:e},{staleTime:3e4,refetchInterval:3e4});return!t||t.length===0?null:r.jsx("div",{className:"flex items-center gap-1 ml-1",children:t.map(n=>{const s=Q8[n.source]??Q8.gateway,a=`Last active ${lMe(n.lastActiveAt)}${n.project?` via ${s.label} on ${n.project}`:` via ${s.label}`}`;return r.jsx(bt,{label:a,side:"bottom",children:r.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:s.color}})},n.source)})})}function lMe(e){const t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const s=Math.floor(n/60);if(s<60)return`${s} min ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function cMe({status:e,color:t}){const n=e==="thinking"||e==="executing";return r.jsxs("span",{className:"relative flex items-center justify-center w-2 h-2",children:[n&&r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:t,opacity:.5},animate:{scale:[1,2.2,1],opacity:[.5,0,.5]},transition:{duration:1.8,repeat:1/0}}),r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e==="offline"?"#3A3A45":t,opacity:e==="idle"?.5:1}})]})}function uMe({agentId:e}){const{data:t}=L.agents.getSoul.useQuery({agentId:e}),n=L.agents.saveSoul.useMutation(),{saveState:s,handleChange:i}=mW(y.useCallback(a=>n.mutateAsync({agentId:e,content:a}),[e,n]));return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-visible",children:[r.jsx("div",{className:"flex items-center justify-end h-7 px-3 flex-shrink-0",children:r.jsx(xW,{saveState:s})}),r.jsx("div",{className:"flex-1 min-h-0",children:t?.content!==void 0&&r.jsx(VU,{height:"100%",defaultLanguage:"markdown",defaultValue:t.content??"",theme:"vs-dark",onChange:i,options:{minimap:{enabled:!1},wordWrap:"on",lineNumbers:"off",fontSize:13,scrollBeyondLastLine:!1,padding:{top:8,bottom:16},automaticLayout:!0,fixedOverflowWidgets:!0}})})]})}function dMe({agentId:e}){const{data:t}=L.agents.getTeam.useQuery({agentId:e}),n=L.agents.saveTeam.useMutation(),{saveState:s,handleChange:i}=mW(y.useCallback(a=>n.mutateAsync({agentId:e,content:a}),[e,n]));return r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-visible",children:[r.jsx("div",{className:"flex items-center justify-end h-7 px-3 flex-shrink-0",children:r.jsx(xW,{saveState:s})}),r.jsx("div",{className:"flex-1 min-h-0",children:t?.content!==void 0&&r.jsx(VU,{height:"100%",defaultLanguage:"markdown",defaultValue:t.content??"",theme:"vs-dark",onChange:i,options:{minimap:{enabled:!1},wordWrap:"on",lineNumbers:"off",fontSize:13,scrollBeyondLastLine:!1,padding:{top:8,bottom:16},automaticLayout:!0,fixedOverflowWidgets:!0}})})]})}const hMe={healthy:"#10B981",degraded:"#F59E0B",failing:"#EF4444"};function fMe({health:e,detail:t}){const[n,s]=y.useState(!1),i=hMe[e.health]??"#5A5A6E";return r.jsxs("span",{className:"relative",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[r.jsx("span",{className:"inline-block w-2 h-2 rounded-full",style:{backgroundColor:i}}),n&&r.jsx("span",{className:"absolute top-full left-0 mt-1.5 px-2 py-1 rounded bg-[#1C1C24] border border-[#2A2A35] text-[10px] text-[#C8C8D4] whitespace-nowrap z-50 shadow-lg",children:t})]})}function pMe({agentId:e}){const{data:t=[]}=L.skills.getAgentSkills.useQuery({agentId:e}),{data:n={}}=L.events.skillHealth.useQuery({agentId:e},{refetchInterval:3e4}),{data:s={}}=L.events.skillComposition.useQuery({agentId:e},{refetchInterval:6e4}),i=L.useUtils(),a=L.skills.toggleAgentSkill.useMutation({onMutate:async({agentId:d,skillId:f,enabled:p})=>{await i.skills.getAgentSkills.cancel({agentId:d});const m=i.skills.getAgentSkills.getData({agentId:d});return i.skills.getAgentSkills.setData({agentId:d},g=>g&&g.map(b=>b.skillId===f?{...b,enabled:p}:b)),{prev:m}},onError:(d,{agentId:f},p)=>{p?.prev&&i.skills.getAgentSkills.setData({agentId:f},p.prev)}});if(t.length===0)return r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-5 gap-2",children:[r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No skills installed for this agent."}),r.jsx("p",{className:"text-[12px] text-[#5A5A6E]",children:"Go to Skills to install and assign."})]});const o=t.every(d=>d.enabled);function l(){const d=!o;t.forEach(f=>a.mutate({agentId:e,skillId:f.skillId,enabled:d}))}const c=new Map(t.map(d=>[d.skill.slug,d.skill.name]));return r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:[t.length," skill",t.length!==1?"s":""]}),r.jsx("button",{onClick:l,className:"text-[11px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:o?"Disable all":"Enable all"})]}),t.map(d=>{const f=n[d.skill.id]??n[d.skill.slug]??n[d.skill.name],p=s[d.skill.id]??s[d.skill.slug]??s[d.skill.name],m=f?`${f.successCount}/${f.totalCount} succeeded${f.avgDurationMs!=null?` · avg ${f.avgDurationMs}ms`:""}`:void 0;return r.jsxs("div",{className:"py-2.5 border-b border-[#2A2A35] last:border-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[f&&r.jsx(fMe,{health:f,detail:m}),r.jsx("span",{className:"text-[13px] transition-all",style:{color:d.enabled?"#C8C8D4":"#5A5A6E",textDecoration:d.enabled?"none":"line-through"},children:d.skill.name})]}),r.jsx(Sh,{checked:d.enabled,onCheckedChange:g=>a.mutate({agentId:e,skillId:d.skillId,enabled:g}),className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35]",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]}),p&&p.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-1 ml-4",children:["Used together with ",p.map(g=>c.get(g)??g).join(", ")]})]},d.skillId)})]})}function mMe({agentId:e,onOverrideSet:t,onClose:n}){const{data:s}=L.agents.getOverride.useQuery({agentId:e}),i=L.agents.setOverride.useMutation(),[a,o]=y.useState("");y.useEffect(()=>{s?.override!==void 0&&o(s.override??"")},[s?.override]);async function l(){await i.mutateAsync({agentId:e,instruction:a}),t(a.trim()||null),n()}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-3",children:[r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[Object.entries(aMe).map(([c,d])=>r.jsx("button",{onClick:()=>o(d),className:"px-3 py-1 rounded-md text-[12px] bg-white/5 text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-[#2A2A35] hover:border-[#3A3A45]",children:c},c)),r.jsx("button",{onClick:()=>o(""),className:"px-3 py-1 rounded-md text-[12px] bg-white/5 text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors border border-[#2A2A35] hover:border-[#3A3A45]",children:"Clear"})]}),r.jsx("textarea",{value:a,onChange:c=>o(c.target.value),rows:5,placeholder:"Add a temporary instruction for this session...",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2.5 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] resize-none outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("button",{onClick:l,disabled:i.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:"Set Override"})]})}const xMe=[{value:"15m",label:"Every 15 minutes"},{value:"30m",label:"Every 30 minutes"},{value:"1h",label:"Every hour"},{value:"3h",label:"Every 3 hours"},{value:"6h",label:"Every 6 hours"},{value:"12h",label:"Every 12 hours"},{value:"1d",label:"Daily"},{value:"2d",label:"Every 2 days"},{value:"7d",label:"Weekly"},{value:"custom",label:"Custom…"}];function gMe(e){return!e||e==="24h"?"1d@09:00":e==="48h"?"2d@09:00":e}function bMe(e){const t={preset:"1d",customValue:4,customUnit:"h",utcHour:9,utcMinute:0};if(e==="15m")return{...t,preset:"15m"};if(e==="30m")return{...t,preset:"30m"};const n=e.match(/^(\d+)h$/);if(n){const i=parseInt(n[1],10),a={1:"1h",3:"3h",6:"6h",12:"12h"};return a[i]?{...t,preset:a[i]}:{...t,preset:"custom",customValue:i,customUnit:"h"}}const s=e.match(/^(\d+)d@(\d{1,2}):(\d{2})$/);if(s){const i=parseInt(s[1],10),a=parseInt(s[2],10),o=parseInt(s[3],10);return{preset:{1:"1d",2:"2d",7:"7d"}[i]??"custom",customValue:i,customUnit:"d",utcHour:a,utcMinute:o}}return t}function vMe(e){return e.preset==="15m"||e.preset==="30m"||e.preset==="1h"||e.preset==="3h"||e.preset==="6h"||e.preset==="12h"?e.preset:e.preset==="1d"?`1d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="2d"?`2d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="7d"?`7d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:e.preset==="custom"?e.customUnit==="d"?`${e.customValue}d@${String(e.utcHour).padStart(2,"0")}:${String(e.utcMinute).padStart(2,"0")}`:`${e.customValue}${e.customUnit}`:"1d@09:00"}function yMe(e,t){return e==="1d"||e==="2d"||e==="7d"||e==="custom"&&t==="d"}function gW(e,t){const n=new Date;return n.setUTCHours(e,t,0,0),{hour:n.getHours(),minute:n.getMinutes()}}function _Me(e,t){const n=new Date;return n.setHours(e,t,0,0),{hour:n.getUTCHours(),minute:n.getUTCMinutes()}}function wMe(e){if(e.preset==="custom"){if(e.customUnit==="m")return`Runs every ${e.customValue} minute${e.customValue===1?"":"s"}`;if(e.customUnit==="h")return`Runs every ${e.customValue} hour${e.customValue===1?"":"s"}`;const t=gW(e.utcHour,e.utcMinute);return`Runs every ${e.customValue} day${e.customValue===1?"":"s"} at ${String(t.hour).padStart(2,"0")}:${String(t.minute).padStart(2,"0")} local`}return""}function AMe({agentId:e}){const{data:t,refetch:n,isLoading:s}=L.agents.terminalInsights.useQuery({agentId:e}),i=L.agents.compactTerminalKnowledge.useMutation({onSuccess:()=>n()}),a=L.agents.clearTerminalKnowledge.useMutation({onSuccess:()=>n()}),o=t?.content??"";return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-4 overflow-auto",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Terminal Insights"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>i.mutate({agentId:e}),disabled:i.isPending,className:"px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:i.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Compact now"}),o&&r.jsx("button",{onClick:()=>a.mutate({agentId:e}),disabled:a.isPending,className:"px-3 py-1.5 rounded-md text-[11px] font-medium bg-[#2A2A35] hover:bg-[#3A3A4E] text-[#C8C8D4] transition-colors disabled:opacity-50",children:a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):"Clear"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:"Terminal session summaries are stored in daily memory files. Compacting extracts lasting patterns into KNOWLEDGE.md."}),s?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Pe,{className:"w-5 h-5 animate-spin text-[#5A5A6E]"})}):o?r.jsx("div",{className:"bg-[#13131A] border border-[#2A2A35] rounded-lg p-4 text-[12px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap font-mono",children:o}):r.jsx("div",{className:"text-center py-8 text-[12px] text-[#5A5A6E]",children:"No terminal insights yet. Assign an agent to a terminal, run some commands, then compact."})]})}function SMe({agentId:e}){const{data:t}=L.agents.getHeartbeat.useQuery({agentId:e}),n=L.agents.setHeartbeat.useMutation(),[s,i]=y.useState(!1),[a,o]=y.useState("1d"),[l,c]=y.useState(4),[d,f]=y.useState("h"),[p,m]=y.useState(9),[g,b]=y.useState(0),[_,w]=y.useState("idle"),[A,S]=y.useState(null),C=y.useRef(null);y.useEffect(()=>{if(t){i(t.enabled);const I=bMe(gMe(t.every));o(I.preset),c(I.customValue),f(I.customUnit);const R=gW(I.utcHour,I.utcMinute);m(R.hour),b(R.minute)}},[t]),y.useEffect(()=>()=>{C.current&&clearTimeout(C.current)},[]);const E=yMe(a,d),k=y.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"local"}},[]),T=y.useMemo(()=>{const I=_Me(p,g),R={preset:a,customValue:l,customUnit:d,utcHour:I.hour,utcMinute:I.minute};return{every:vMe(R),description:wMe(R)}},[a,l,d,p,g]);async function F(){S(null);try{await n.mutateAsync({agentId:e,enabled:s,every:T.every}),w("saved"),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>w("idle"),2e3)}catch(I){w("error"),S(I instanceof Error?I.message:"Failed to save")}}const M=a!=="custom"||(d==="m"?l>=1&&l<=59:d==="h"?l>=1&&l<=23:l>=1&&l<=7);return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:"Heartbeat"}),r.jsx(Sh,{checked:s,onCheckedChange:i,className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35]",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]}),s&&r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Frequency"}),r.jsxs(ss,{value:a,onValueChange:I=>o(I),children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors w-full",children:[r.jsx(Ds,{}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[200px] max-h-[280px] overflow-y-auto z-[9999]",children:r.jsx(os,{children:xMe.map(I=>r.jsxs(vn,{value:I.value,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:I.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},I.value))})})})]})]}),a==="custom"&&r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Every"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:1,max:d==="m"?59:d==="h"?23:7,value:l,onChange:I=>c(Math.max(1,parseInt(I.target.value||"1",10))),className:"w-20 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors"}),r.jsxs(ss,{value:d,onValueChange:I=>f(I),children:[r.jsxs(is,{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-[12px] text-[#C8C8D4] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] outline-none transition-colors flex-1",children:[r.jsx(Ds,{}),r.jsx(ft,{className:"w-3 h-3 opacity-60 ml-auto"})]}),r.jsx(rs,{children:r.jsx(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[140px] z-[9999]",children:r.jsx(os,{children:[{v:"m",label:"minutes"},{v:"h",label:"hours"},{v:"d",label:"days"}].map(I=>r.jsxs(vn,{value:I.v,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer hover:bg-white/5 outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:I.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},I.v))})})})]})]}),!M&&r.jsx("p",{className:"text-[11px] text-[#F25757]",children:d==="m"?"Minutes must be 1–59":d==="h"?"Hours must be 1–23":"Days must be 1–7"})]}),E&&r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("label",{className:"text-[11px] uppercase tracking-wide text-[#7A7A8E]",children:"Time of day"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:0,max:23,value:p,onChange:I=>m(Math.max(0,Math.min(23,parseInt(I.target.value||"0",10)))),className:"w-16 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors text-center"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6E]",children:":"}),r.jsx("input",{type:"number",min:0,max:59,value:g,onChange:I=>b(Math.max(0,Math.min(59,parseInt(I.target.value||"0",10)))),className:"w-16 px-2.5 py-1.5 rounded-md text-[12px] text-[#F0F0F5] bg-[#1C1C21] border border-[#2A2A35] hover:border-[#3A3A4E] focus:border-[#6366F1] outline-none transition-colors text-center"}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:k})]})]})]}),r.jsxs("p",{className:"text-[12px] text-[#5A5A6E] leading-relaxed",children:["When active, your agent runs its HEARTBEAT.md at this interval — reviewing memory, running research loops, and evolving over time.",E&&r.jsxs(r.Fragment,{children:[r.jsx("br",{}),r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"Note: time is stored in UTC. Daylight saving changes may shift local display by ±1 hour."})]})]}),A&&_==="error"&&r.jsx("p",{className:"text-[11px] text-[#F25757]",children:A}),r.jsx("button",{onClick:F,disabled:n.isPending||s&&!M,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:r.jsx(Me,{mode:"wait",children:_==="saved"?r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved ✓"},"saved"):r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")})})]})}function CMe({agentId:e}){const t=L.agents.getTrust.useQuery({agentId:e}),n=L.agents.getSandboxOverride.useQuery({agentId:e}),s=L.agents.getMounts.useQuery({agentId:e}),i=L.agents.setAutoApprove.useMutation({onSuccess:()=>t.refetch()}),a=L.agents.setShellAllowlist.useMutation({onSuccess:()=>t.refetch()}),o=L.agents.setSandboxOverride.useMutation({onSuccess:()=>n.refetch()}),l=L.agents.addMount.useMutation({onSuccess:()=>s.refetch()}),c=L.agents.removeMount.useMutation({onSuccess:()=>s.refetch()}),[d,f]=y.useState(!1),[p,m]=y.useState(!1),[g,b]=y.useState(""),[_,w]=y.useState(!1),[A,S]=y.useState(""),[C,E]=y.useState(""),T=L.agents.getRunMode.useQuery().data?.mode==="docker";y.useEffect(()=>{t.data&&(b(t.data.shellAllowlist?t.data.shellAllowlist.join(", "):""),w(!1))},[t.data]);const F=t.data?.autoApprove??!1;function M(B){B?(f(!0),m(!0)):i.mutate({agentId:e,enabled:!1})}function I(){i.mutate({agentId:e,enabled:!0}),m(!1),f(!1)}function R(){m(!1),f(!1)}function H(B){b(B),w(!0)}function V(){const B=g.trim(),Y=B?B.split(",").map(U=>U.trim()).filter(Boolean):null;a.mutate({agentId:e,allowlist:Y}),w(!1)}function K(B){B.preventDefault(),!(!A.trim()||!C.trim())&&(l.mutate({agentId:e,hostPath:A.trim(),agentPath:C.trim()}),S(""),E(""))}const q=n.data?.mode??"inherit",$=n.data?.globalDefault??"non-main";return r.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-6",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Auto-approve"}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:"Skip confirmation prompts"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Execute all actions without asking"})]}),r.jsx(Sh,{checked:d||F,onCheckedChange:M,disabled:i.isPending,className:"w-9 h-5 rounded-full bg-[#2A2A35] data-[state=checked]:bg-[#EF4444] transition-colors outline-none cursor-pointer",children:r.jsx(Ch,{className:"block w-4 h-4 bg-white rounded-full shadow transition-transform translate-x-0.5 data-[state=checked]:translate-x-[18px]"})})]}),r.jsx(Me,{children:p&&r.jsxs(ne.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},className:"rounded-lg border border-[#EF4444]/40 bg-[#EF4444]/10 p-3 space-y-3",children:[r.jsx("p",{className:"text-[12px] text-[#FCA5A5] leading-relaxed",children:"This agent will execute all actions without asking for confirmation. Only enable for read-only agents or dedicated machines you fully control."}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:I,className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#EF4444] hover:bg-[#DC2626] text-white transition-colors",children:"Enable anyway"}),r.jsx("button",{onClick:R,className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]})})]}),r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Sandbox"}),r.jsx("div",{className:"flex gap-1.5",children:["inherit","on","off"].map(B=>r.jsx("button",{onClick:()=>o.mutate({agentId:e,mode:B}),disabled:o.isPending,className:`flex-1 py-1.5 rounded-md text-[12px] font-medium transition-colors ${q===B?"bg-[#6366F1] text-white":"bg-[#1C1C21] border border-[#2A2A35] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45]"}`,children:B==="inherit"?`Inherit (${$==="non-main"?"sandboxed":"off"})`:B==="on"?"Sandboxed":"Unsandboxed"},B))})]}),r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Shell allowlist"}),r.jsx("input",{type:"text",value:g,onChange:B=>H(B.target.value),placeholder:"All commands allowed",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Comma-separated command names, e.g. git, npm, ls"}),_&&r.jsx("button",{onClick:V,disabled:a.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:"Save allowlist"})]}),T&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"h-px bg-[#2A2A35]"}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-wide",children:"Filesystem mounts"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Mounting a directory gives this agent read/write access to those files."}),s.data&&s.data.length>0&&r.jsx("div",{className:"space-y-1.5",children:s.data.map(B=>r.jsxs("div",{className:"flex items-center gap-2 bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] truncate",children:B.hostPath}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:["→ ",B.agentPath]})]}),r.jsx("button",{onClick:()=>c.mutate({mountId:B.id}),disabled:c.isPending,className:"w-6 h-6 flex items-center justify-center rounded text-[#5A5A6E] hover:text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors flex-shrink-0",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})]},B.id))}),r.jsxs("form",{onSubmit:K,className:"space-y-2",children:[r.jsx("input",{type:"text",value:A,onChange:B=>S(B.target.value),placeholder:"Host path (e.g. /Users/you/projects)",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("input",{type:"text",value:C,onChange:B=>E(B.target.value),placeholder:"Agent path (e.g. /workspace/projects)",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsxs("button",{type:"submit",disabled:l.isPending||!A.trim()||!C.trim(),className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[r.jsx(wt,{className:"w-3.5 h-3.5"}),"Add mount"]})]})]})]})]})}function OC({className:e}){return r.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",className:e,children:r.jsx("path",{d:"M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"})})}const jMe=[{id:"telegram",label:"Telegram",icon:OC,available:!0},{id:"whatsapp",label:"WhatsApp",icon:Ji,available:!1},{id:"discord",label:"Discord",icon:Ji,available:!1},{id:"slack",label:"Slack",icon:Ji,available:!1}];function NMe({externalChannelId:e,botUsername:t}){const{data:n=[],refetch:s}=L.externalChannels.listPairings.useQuery({externalChannelId:e}),{data:i=[]}=L.workspace.listMembers.useQuery(),a=L.externalChannels.generatePairingCode.useMutation({onSuccess:()=>s()}),o=L.externalChannels.generatePairingCodeForUser.useMutation({onSuccess:()=>s()}),l=L.externalChannels.revokePairing.useMutation({onSuccess:()=>s()}),[c,d]=y.useState(!1),[f,p]=y.useState(""),[m,g]=y.useState(null),[b,_]=y.useState(null),[w,A]=y.useState(!1),S=new Set(n.map(F=>F.userId)),C=i.filter(F=>!S.has(F.userId));async function E(){g(null);try{const F=await a.mutateAsync({externalChannelId:e});g(F.code),d(!0)}catch{}}async function k(){if(f){g(null);try{const F=await o.mutateAsync({externalChannelId:e,userId:f});g(F.code)}catch{}}}function T(){m&&(navigator.clipboard.writeText(m).catch(()=>{}),A(!0),setTimeout(()=>A(!1),2e3))}return r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"Paired Users"}),r.jsxs("div",{className:"flex gap-1.5",children:[r.jsx("button",{onClick:E,disabled:a.isPending,className:"px-2 py-1 rounded text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] hover:bg-[#6366F1]/20 transition-colors",children:"Pair your Telegram"}),r.jsxs("button",{onClick:()=>{d(!0),g(null),p("")},className:"px-2 py-1 rounded text-[11px] font-medium bg-[#2A2A35] text-[#F0F0F5] hover:bg-[#3A3A45] transition-colors",children:[r.jsx(wt,{className:"w-3 h-3 inline -mt-px"})," Pair user"]})]})]}),n.length===0&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"No users paired yet. Pair your Telegram account to enable secure multi-user access."}),n.map(F=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded-md bg-[#13131A]",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-[12px] text-[#F0F0F5]",children:F.userName}),F.telegramUsername&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E] ml-1.5",children:["@",F.telegramUsername]}),r.jsx("span",{className:"text-[10px] text-[#3A3A45] ml-1.5",children:new Date(F.pairedAt).toLocaleDateString()})]}),b===F.id?r.jsxs("div",{className:"flex gap-1",children:[r.jsx("button",{onClick:()=>{l.mutate({pairingId:F.id}),_(null)},className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#EF4444] text-white",children:"Revoke"}),r.jsx("button",{onClick:()=>_(null),className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-[#2A2A35] text-[#F0F0F5]",children:"Cancel"})]}):r.jsx("button",{onClick:()=>_(F.id),className:"text-[10px] text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:r.jsx(Dn,{className:"w-3 h-3"})})]},F.id)),r.jsx(Me,{children:c&&r.jsx(ne.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"rounded-lg border border-[#2A2A35] bg-[#13131A] p-3 space-y-3 overflow-hidden",children:m?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium",children:"Pairing code"}),r.jsx("div",{onClick:T,className:"flex items-center justify-center gap-2 py-3 rounded-lg bg-[#1C1C21] border border-[#2A2A35] cursor-pointer hover:border-[#6366F1] transition-colors",children:r.jsx("span",{className:"text-2xl font-mono font-bold tracking-[0.25em] text-[#F0F0F5]",children:m})}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:[w?"Copied!":"Click to copy."," Send this to the user. They should message it to"," ",t?`@${t}`:"the bot"," on Telegram. Expires in 10 minutes."]}),r.jsx("button",{onClick:()=>{d(!1),g(null),s()},className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Done"})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-[12px] text-[#F0F0F5] font-medium",children:"Pair a workspace member"}),C.length>0?r.jsxs(r.Fragment,{children:[r.jsxs(ss,{value:f,onValueChange:p,children:[r.jsxs(is,{className:"w-full flex items-center justify-between bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2 text-[12px] text-[#F0F0F5] outline-none",children:[r.jsx(Ds,{placeholder:"Select member"}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3 h-3 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsx(as,{className:"bg-[#1C1C21] border border-[#2A2A35] rounded-lg shadow-xl z-[100]",position:"popper",sideOffset:4,children:r.jsx(os,{className:"p-1",children:C.map(F=>r.jsxs(vn,{value:F.userId,className:"flex items-center px-3 py-2 text-[12px] text-[#F0F0F5] rounded cursor-pointer hover:bg-[#2A2A35] outline-none data-[highlighted]:bg-[#2A2A35]",children:[r.jsx(yn,{children:F.name}),r.jsx(ui,{className:"ml-auto",children:r.jsx(Fe,{className:"w-3 h-3"})})]},F.userId))})})})]}),r.jsx("button",{onClick:k,disabled:!f||o.isPending,className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:o.isPending?"Generating...":"Generate code"})]}):r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"All workspace members are already paired."}),r.jsx("button",{onClick:()=>d(!1),className:"w-full py-1.5 rounded-lg text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})})})]})}function kMe({agentId:e}){const{data:t=[],refetch:n}=L.externalChannels.list.useQuery({agentId:e}),s=L.externalChannels.configure.useMutation({onSuccess:()=>n()}),i=L.externalChannels.enable.useMutation({onSuccess:()=>n()}),a=L.externalChannels.disable.useMutation({onSuccess:()=>n()}),o=L.externalChannels.delete.useMutation({onSuccess:()=>n()}),[l,c]=y.useState(null),[d,f]=y.useState(""),[p,m]=y.useState(null),[g,b]=y.useState(null);async function _(){if(!(!d.trim()||!l)){m(null);try{await s.mutateAsync({agentId:e,provider:l,credentials:{botToken:d.trim()}}),f(""),c(null)}catch(A){m(A instanceof Error?A.message:"Connection failed")}}}const w=t.find(A=>A.provider==="telegram");return r.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"External Channels"}),w&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] p-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:w.running?"#10B981":w.status==="error"?"#EF4444":"#5A5A6E"}}),r.jsx(OC,{className:"w-4 h-4 text-[#29B6F6]"}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5]",children:"Telegram"}),typeof w.metadata?.botUsername=="string"&&r.jsxs("span",{className:"text-[11px] text-[#5A5A6E]",children:["@",w.metadata.botUsername]})]}),r.jsx(Sh,{checked:w.enabled,onCheckedChange:A=>{A?i.mutate({agentId:e,provider:"telegram"}):a.mutate({agentId:e,provider:"telegram"})},className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35]",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]}),w.status==="error"&&r.jsx("p",{className:"text-[11px] text-[#EF4444]",children:"Bridge failed to start. Check the bot token."}),r.jsx("div",{className:"flex gap-2",children:g===w.id?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{o.mutate({id:w.id}),b(null)},className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#EF4444] hover:bg-[#DC2626] text-white transition-colors",children:"Confirm disconnect"}),r.jsx("button",{onClick:()=>b(null),className:"flex-1 py-1.5 rounded-md text-[12px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]}):r.jsx("button",{onClick:()=>b(w.id),className:"text-[11px] text-[#5A5A6E] hover:text-[#EF4444] transition-colors",children:"Disconnect"})})]}),w&&r.jsx(NMe,{externalChannelId:w.id,botUsername:typeof w.metadata?.botUsername=="string"?w.metadata.botUsername:void 0}),w&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35]/50 bg-[#1C1C21]/50 p-3 space-y-2",children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:"BotFather Setup"}),r.jsxs("div",{className:"text-[11px] text-[#5A5A6E] leading-relaxed space-y-1",children:[r.jsx("p",{children:"Open @BotFather on Telegram and run these for your bot:"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setjoingroups"}),r.jsx("p",{className:"pl-3",children:"Disable (bot is DM-only)"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setprivacy"}),r.jsx("p",{className:"pl-3",children:"Enable (default)"}),r.jsx("p",{className:"text-[#8A8A99] font-mono",children:"/setdescription"}),r.jsx("p",{className:"pl-3",children:'e.g. "damn.dev workspace agent"'})]})]}),!w&&!l&&r.jsx("div",{className:"space-y-2",children:jMe.map(A=>r.jsxs("button",{onClick:()=>A.available?c(A.id):void 0,disabled:!A.available,className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg border border-[#2A2A35] bg-[#1C1C21] hover:bg-[#2A2A35] transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(A.icon,{className:"w-4 h-4 text-[#8A8A99]"}),r.jsxs("span",{className:"text-[13px] text-[#F0F0F5]",children:["Connect ",A.label]}),!A.available&&r.jsx("span",{className:"ml-auto text-[10px] text-[#5A5A6E]",children:"Coming soon"})]},A.id))}),l==="telegram"&&r.jsxs("div",{className:"rounded-lg border border-[#2A2A35] bg-[#1C1C21] p-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(OC,{className:"w-4 h-4 text-[#29B6F6]"}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Connect Telegram Bot"})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] leading-relaxed",children:"Create a bot via @BotFather on Telegram, then paste the token below."}),r.jsx("input",{type:"password",value:d,onChange:A=>f(A.target.value),placeholder:"Bot token from @BotFather",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors",onKeyDown:A=>A.key==="Enter"&&_()}),p&&r.jsx("p",{className:"text-[11px] text-[#EF4444]",children:p}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{onClick:_,disabled:s.isPending||!d.trim(),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[s.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Ji,{className:"w-3.5 h-3.5"}),"Connect"]}),r.jsx("button",{onClick:()=>{c(null),f(""),m(null)},className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),!w&&!l&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] leading-relaxed",children:"Connect external messaging platforms to reach this agent outside of damn.dev. Messages flow through the same pipeline with full governance."})]})}function EMe({agentId:e}){const{data:t,refetch:n}=L.agents.getCapabilities.useQuery({agentId:e}),s=L.agents.setCapabilities.useMutation({onSuccess:()=>n()}),[i,a]=y.useState(""),[o,l]=y.useState(!0),[c,d]=y.useState("idle"),f=y.useRef(null);y.useEffect(()=>{t&&(a(t.capabilities.join(", ")),l(t.canReceiveDelegations))},[t]),y.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);async function p(){const m=i.split(",").map(g=>g.trim()).filter(Boolean);await s.mutateAsync({agentId:e,capabilities:m,canReceiveDelegations:o}),d("saved"),f.current=setTimeout(()=>d("idle"),2e3)}return r.jsxs("div",{className:"flex-1 flex flex-col px-5 py-4 gap-5 overflow-y-auto",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest mb-2",children:"Capabilities"}),r.jsx("textarea",{value:i,onChange:m=>a(m.target.value),rows:3,placeholder:"write:code, exec:shell, analyze:data",className:"w-full bg-[#1C1C21] border border-[#2A2A35] rounded-lg px-3 py-2.5 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] resize-none outline-none focus:border-[#6366F1] focus:ring-1 focus:ring-[#6366F1]/30 transition-colors"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Comma-separated. Auto-inferred from skills and role when empty."})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5]",children:"Accept delegations"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:"Other agents can delegate tasks to this agent"})]}),r.jsx(Sh,{checked:o,onCheckedChange:l,className:"relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none data-[state=checked]:bg-[#6366F1] data-[state=unchecked]:bg-[#2A2A35]",children:r.jsx(Ch,{className:"pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-lg transition duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})]}),t&&t.capabilities.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.capabilities.map(m=>r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] border border-[#6366F1]/20",children:m},m))}),r.jsx("button",{onClick:p,disabled:s.isPending,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-50",children:r.jsx(Me,{mode:"wait",children:c==="saved"?r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Saved"},"saved"):r.jsx(ne.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:"Save"},"idle")})})]})}const t2=["identity","config","live"],FMe={identity:["soul","team","model"],config:["skills","channels","capabilities","trust"],live:["activity","dream","files","git","terminal","schedule","override"]},TMe={identity:[],config:[],live:["activity","dream","files","git","terminal","override"]};function MMe({tabs:e,active:t,onChange:n}){return e.length<=1?null:r.jsx("div",{className:"flex gap-1 px-5 py-2 border-b border-[#2A2A35]/50 flex-shrink-0",children:e.map(s=>r.jsx("button",{onClick:()=>n(s),className:`px-2.5 py-1 rounded-md text-[11px] font-medium capitalize transition-colors ${t===s?"bg-white/10 text-[#F0F0F5]":"text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/5"}`,children:s},s))})}function X8(e,t){const n=atob(e),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n.charCodeAt(l);const i=new Blob([s],{type:"application/zip"}),a=URL.createObjectURL(i),o=document.createElement("a");o.href=a,o.download=t,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}function RMe({warnings:e,onExport:t,onCancel:n}){return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[60] flex items-center justify-center p-4",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},onClick:s=>s.stopPropagation(),className:"relative bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 w-full max-w-sm space-y-4 shadow-2xl",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Export warnings"}),r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:e.map((s,i)=>r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2",children:[r.jsx("p",{className:"text-[12px] text-[#FCD34D] leading-relaxed",children:s.message}),r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] mt-0.5",children:[s.file,":",s.line]})]},i))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:t,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#F59E0B] hover:bg-[#D97706] text-black transition-colors",children:"Export anyway"}),r.jsx("button",{onClick:n,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]})]})}const DMe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],OMe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16"];function $N({agent:e,agentColor:t,onClose:n,onOverrideSet:s,initialTab:i}){const a=Uo(),o=a?FMe:TMe,l=a?"identity":"live",c=i&&t2.includes(i.category)?i.category:l,d=i&&o[c]?.includes(i.subTab)?i.subTab:o[c][0]??"activity",[f,p]=y.useState(c),[m,g]=y.useState(d),[b,_]=y.useState(null),[w,A]=y.useState(null),S=L.useUtils(),[C,E]=y.useState(!1),[k,T]=y.useState(e.name),F=y.useRef(null),M=L.agents.update.useMutation({onSuccess:()=>{S.agents.list.invalidate(),S.channels.list.invalidate()}});function I(){E(!1);const $=k.trim();$&&$!==e.name?M.mutate({agentId:e.id,name:$}):T(e.name)}y.useEffect(()=>{C&&F.current?.select()},[C]),y.useEffect(()=>{T(e.name)},[e.name]);const R=L.agents.export.useMutation();async function H(){try{const $=await R.mutateAsync({agentId:e.id});$.warnings.length>0?(_($.warnings),A({buffer:$.buffer,filename:$.filename})):X8($.buffer,$.filename)}catch{}}function V(){w&&X8(w.buffer,w.filename),_(null),A(null)}function K($){p($),g(o[$][0]??"")}const q=a?t2:t2.filter($=>o[$].length>0);return r.jsxs(r.Fragment,{children:[r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",style:{backdropFilter:"blur(2px)",backgroundColor:"rgba(0,0,0,0.25)"},onClick:n}),r.jsxs(ne.div,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.3,ease:[.16,1,.3,1]},className:"fixed right-0 top-0 h-screen w-[380px] bg-[#13131A] border-l border-[#2A2A35] flex flex-col z-50 shadow-2xl",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between flex-shrink-0",style:{background:`linear-gradient(135deg, rgba(${uh(t)}, 0.08) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[a&&e.id!=="coo"?r.jsxs(Ys,{children:[r.jsx(ci,{asChild:!0,children:r.jsx("button",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xl flex-shrink-0 hover:ring-2 hover:ring-white/20 transition-all",style:{backgroundColor:`${t}26`},children:e.emoji})}),r.jsx(Qs,{children:r.jsxs(Xs,{sideOffset:8,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Emoji"}),r.jsx("div",{className:"grid grid-cols-10 gap-1 mb-3",children:DMe.map($=>r.jsx("button",{onClick:()=>M.mutate({agentId:e.id,emoji:$}),className:`w-6 h-6 flex items-center justify-center rounded text-sm hover:bg-white/10 transition-colors ${e.emoji===$?"bg-white/15 ring-1 ring-white/20":""}`,children:$},$))}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Color"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:OMe.map($=>r.jsx("button",{onClick:()=>M.mutate({agentId:e.id,color:$}),className:`w-6 h-6 rounded-full transition-all ${e.color===$?"ring-2 ring-white/40 scale-110":"hover:scale-110"}`,style:{backgroundColor:$}},$))}),r.jsx(oa,{className:"fill-[#2A2A35]"})]})})]}):r.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xl flex-shrink-0",style:{backgroundColor:`${t}26`},children:e.emoji}),r.jsxs("div",{className:"min-w-0",children:[C?r.jsx("input",{ref:F,value:k,onChange:$=>T($.target.value),onBlur:I,onKeyDown:$=>{$.key==="Enter"&&F.current?.blur(),$.key==="Escape"&&(T(e.name),E(!1))},className:"bg-transparent text-[14px] font-semibold text-[#F0F0F5] outline-none border-b border-[#6366F1]/60 pb-px w-full"}):r.jsxs("p",{className:`text-[14px] font-semibold text-[#F0F0F5] truncate ${a&&e.id!=="coo"?"cursor-pointer hover:text-[#818CF8] transition-colors group/name":""}`,onClick:()=>{a&&e.id!=="coo"&&E(!0)},children:[e.name,a&&e.id!=="coo"&&r.jsx(oh,{className:"w-3 h-3 inline-block ml-1.5 opacity-0 group-hover/name:opacity-60 transition-opacity"})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] truncate",children:e.role})]}),r.jsx(cMe,{status:e.status,color:t}),r.jsx(oMe,{agentId:e.id})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[a&&e.id!=="coo"&&r.jsx(bt,{label:"Export agent",side:"left",children:r.jsx("button",{onClick:H,disabled:R.isPending,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors disabled:opacity-50",children:R.isPending?r.jsx(Pe,{className:"w-4 h-4 animate-spin"}):r.jsx(nu,{className:"w-4 h-4"})})}),r.jsx(bt,{label:"Close",side:"left",children:r.jsx("button",{onClick:n,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})})]})]}),r.jsx("div",{className:"flex border-b border-[#2A2A35] flex-shrink-0 px-5",children:q.map($=>r.jsx("button",{onClick:()=>K($),className:`py-3 px-1 mr-4 text-[11px] font-medium capitalize border-b-2 transition-colors outline-none ${f===$?"text-[#F0F0F5] border-[#6366F1]":"text-[#8A8A99] border-transparent hover:text-[#C8C8D4]"}`,children:$},$))}),r.jsx(MMe,{tabs:o[f],active:m,onChange:g}),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[a&&m==="soul"&&r.jsx(uMe,{agentId:e.id}),a&&m==="team"&&r.jsx(dMe,{agentId:e.id}),a&&m==="model"&&r.jsx(rMe,{agent:e,agentColor:t}),a&&m==="skills"&&r.jsx(pMe,{agentId:e.id}),a&&m==="channels"&&r.jsx(kMe,{agentId:e.id}),a&&m==="capabilities"&&r.jsx(EMe,{agentId:e.id}),a&&m==="trust"&&r.jsx(CMe,{agentId:e.id}),m==="activity"&&r.jsx(DEe,{agentId:e.id}),m==="dream"&&r.jsx(JTe,{agentId:e.id}),m==="files"&&r.jsx(ITe,{agentId:e.id}),m==="git"&&r.jsx(WTe,{agentId:e.id}),m==="terminal"&&r.jsx(AMe,{agentId:e.id}),a&&m==="schedule"&&r.jsx(SMe,{agentId:e.id}),m==="override"&&r.jsx(mMe,{agentId:e.id,onOverrideSet:s,onClose:n})]})]}),r.jsx(Me,{children:b&&r.jsx(RMe,{warnings:b,onExport:V,onCancel:()=>{_(null),A(null)}})})]})}async function PMe(e){if(Va)try{const{sendNotification:t,isPermissionGranted:n,requestPermission:s}=await X(async()=>{const{sendNotification:a,isPermissionGranted:o,requestPermission:l}=await import("./index-E-6oA41F.js");return{sendNotification:a,isPermissionGranted:o,requestPermission:l}},__vite__mapDeps([103,1]));let i=await n();if(i||(i=await s()==="granted"),!i)return;t({title:e.title,body:e.body})}catch{}}const IMe=/\.(kanban|chart|table|board)\.json$/,LMe=oi.replace(/^http/,"ws")+"/ws",BMe=25e3,zMe=3e3;function J8(e,t){if(Va){document.hidden&&PMe({title:e,body:t.slice(0,80)});return}!("Notification"in window)||Notification.permission!=="granted"||document.hidden&&new Notification(e,{body:t.slice(0,80),icon:"/favicon.ico"})}function $Me(e,t){return new RegExp(`@${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i").test(e)}const Z8=new Set;function bW(e){const t=L.useUtils(),{data:n}=Mi(),s=y.useRef(n?.user?.name??"");y.useLayoutEffect(()=>{s.current=n?.user?.name??""});const{appendMessage:i,setAgentStatus:a,updateMessageStatus:o,updateMessage:l,removeMessage:c,updateReactions:d,setUnreadCount:f,addFileEditApproval:p,removeFileEditApproval:m}=Je(),g=y.useRef(null),b=y.useRef(null),_=y.useRef(e),w=y.useRef(!0),A=y.useRef(!1);y.useLayoutEffect(()=>{_.current=e});const S=y.useCallback(async C=>{const k=Je.getState().messagesByChannel[C];if(!k||k.length===0)return;const T=k[k.length-1];try{const F=await t.messages.list.fetch({channelId:C,cursor:T.id,limit:100,direction:"after"});if(F.messages.length>0)for(const M of F.messages)i(M)}catch{}},[t,i]);y.useEffect(()=>{w.current=!0;let C=null;function E(){if(!w.current)return;const k=new WebSocket(LMe);g.current=k,k.onopen=()=>{if(!w.current){k.close(1e3);return}const T=_.current;T&&k.send(JSON.stringify({type:"subscribe",channelId:T})),A.current&&(T&&S(T),t.messages.list.invalidate(),t.channels.list.invalidate(),t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate()),A.current=!0,b.current=setInterval(()=>{k.readyState===WebSocket.OPEN&&k.send(JSON.stringify({type:"ping"}))},BMe)},k.onmessage=T=>{if(w.current)try{const F=JSON.parse(T.data);if(F.type==="message.new"){const M=F;i(M.payload),M.payload.sender.type==="agent"&&M.payload.channelId!==_.current&&J8(M.payload.sender.name,M.payload.content)}else if(F.type==="message.edited"){const M=F;l(M.payload.channelId,M.payload.messageId,{content:M.payload.content,editedAt:M.payload.editedAt})}else if(F.type==="message.deleted"){const M=F;c(M.payload.channelId,M.payload.messageId)}else if(F.type==="message.pinned"){const M=F;l(M.payload.channelId,M.payload.messageId,{pinnedAt:M.payload.pinnedAt,pinnedBy:M.payload.pinnedBy})}else if(F.type==="message.unpinned"){const M=F;l(M.payload.channelId,M.payload.messageId,{pinnedAt:void 0,pinnedBy:void 0})}else if(F.type==="message.metadata_updated"){const M=F;l(M.payload.channelId,M.payload.messageId,{metadata:M.payload.metadata})}else if(F.type==="reaction.toggled"){const M=F;d(M.payload.channelId,M.payload.messageId,M.payload.reactions)}else if(F.type==="thread.message.new"){const M=F,R=(Je.getState().messagesByChannel[M.payload.channelId]??[]).find(H=>H.id===M.payload.parentMessageId);R&&l(M.payload.channelId,M.payload.parentMessageId,{replyCount:(R.replyCount??0)+1})}else if(F.type==="agent.status"){const M=F;a(M.payload.agentId,M.payload.status),M.payload.status==="thinking"?Mw("thinking"):Mw("idle")}else if(F.type==="approval.decided"){const M=F;o(M.payload.channelId,M.payload.messageId,M.payload.decision),t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate()}else if(F.type==="approval.file_edit.created")p(F.payload);else if(F.type==="approval.file_edit.decided"){const M=F;m(M.payload.channelId,M.payload.id)}else if(F.type==="conversation.cleared"){const M=F;Je.getState().setMessages(M.payload.channelId,[])}else if(F.type==="channel.created"||F.type==="channel.closed"||F.type==="channel.updated")t.channels.list.invalidate(),F.type==="channel.created"&&t.readReceipts.getUnread.invalidate();else if(F.type==="channel.tabs.updated"){const M=F;t.channels.get.invalidate({channelId:M.payload.parentChannelId}),t.channels.list.invalidate()}else if(F.type==="channel.tokenUpdate"){const M=F;ny.getState().updateFromWs(M.payload.channelId,M.payload)}else if(F.type==="channel.compacted"){const M=F;Je.getState().appendMessage({id:`compaction-${Date.now()}`,channelId:M.payload.channelId,sender:{type:"context_reset",id:"system",name:"system"},content:`compacted:${M.payload.summarizedCount}`,timestamp:new Date().toISOString()})}else if(F.type==="presence.changed"){const M=F;t.workspace.listPresence.setData(void 0,I=>I&&I.map(R=>R.userId===M.payload.userId?{...R,online:M.payload.online,lastSeenAt:M.payload.lastSeenAt??R.lastSeenAt}:R))}else if(F.type==="agent.fileChanged"){const M=F;t.fileChanges.list.invalidate({channelId:M.payload.channelId})}else if(F.type==="agent.filesChanged"){const M=F;if(t.files.tree.invalidate({agentId:M.payload.agentId}),M.payload.filename&&IMe.test(M.payload.filename)){const R=t.channels.list.getData()?.find(H=>H.channelType==="dm"&&H.agentId===M.payload.agentId);R&&NU.getState().addCard(R.id,{id:`sf-${M.payload.agentId}-${M.payload.filename}-${Date.now()}`,agentId:M.payload.agentId,filename:M.payload.filename,filePath:M.payload.filePath??M.payload.filename,timestamp:Date.now()})}}else if(F.type==="agent.created"||F.type==="agent.deleted")t.agents.list.invalidate(),t.channels.list.invalidate();else if(F.type==="approval.created"||F.type==="approval.expired"){if(t.approvals.list.invalidate(),t.approvals.pendingCount.invalidate(),F.type==="approval.created"){const M=F.payload;M?.channelId&&S(M.channelId),Mw("badge"),J8("Action required",M?.agentName?`${M.agentName} wants to: ${M.description??"perform an action"}`:"An agent requires approval"),window.dispatchEvent(new CustomEvent("pwa-push-prompt"))}}else(F.type==="mission.task.updated"||F.type==="mission.task.dispatched"||F.type==="mission.created")&&(t.missions.list.invalidate(),t.federation.activityFeed.invalidate());if(F.type==="message.new"){const M=F;if(M.payload.channelId!==_.current&&!Z8.has(M.payload.id)){Z8.add(M.payload.id);const{mutedChannels:I,unreadCounts:R}=Je.getState(),H=I[M.payload.channelId];H?H.notifyOnMention&&s.current&&$Me(M.payload.content,s.current)&&f(M.payload.channelId,(R[M.payload.channelId]??0)+1):f(M.payload.channelId,(R[M.payload.channelId]??0)+1)}}}catch{}},k.onclose=T=>{b.current&&clearInterval(b.current),w.current&&T.code!==1e3&&(C=setTimeout(E,zMe))},k.onerror=()=>{k.close()}}return E(),()=>{w.current=!1,b.current&&clearInterval(b.current),C&&clearTimeout(C),g.current?.close(1e3)}},[i,a,o,l,c,d,f,p,m,t,S]),y.useEffect(()=>{const C=g.current;!C||C.readyState!==WebSocket.OPEN||e&&C.send(JSON.stringify({type:"subscribe",channelId:e}))},[e])}const VMe={orchestrator:"#6366F1","content-agent":"#8B5CF6","engagement-agent":"#10B981"};function UMe(){const{channelId:e}=am(),t=an(),n=tz(D=>D.setActiveChannelId);y.useEffect(()=>(n(e??null),()=>n(null)),[e,n]);const{data:s}=L.channels.get.useQuery({channelId:e??""},{enabled:!!e,retry:!1});y.useEffect(()=>{if(!s||!e)return;const D=s.channel,Q=s.tabs,z=V7.getState();if(D.parentChannelId==null){const J=z.lastTab[e];J&&J!==e&&(Q.some(ee=>ee.id===J)?t(`/channels/${J}`,{replace:!0}):z.clearLast(e))}else z.lastTab[D.parentChannelId]!==e&&z.setLast(D.parentChannelId,e)},[s,e,t]);const[i,a]=y.useState(!1),[o,l]=y.useState(void 0),[c,d]=y.useState(!1),[f,p]=y.useState(null);y.useEffect(()=>{function D(){l({category:"live",subTab:"files"}),a(!0)}return window.addEventListener("open-agent-files",D),()=>window.removeEventListener("open-agent-files",D)},[]);const{data:m}=ez(e??""),{data:g}=pj(m?.agentId??""),{data:b=[]}=Vo(),{data:_}=Mi(),w=m?.channelType==="dm"&&!m.agentId,A=m?.channelType==="group"||m?.channelType==="topic",{data:S=[]}=L.workspace.listMembers.useQuery(void 0,{enabled:w||A}),C=w?m.participants.find(D=>D.participantType==="human"&&D.participantId!==_?.user?.id):void 0,E=C?S.find(D=>D.userId===C.participantId)?.name??void 0:void 0,k=C?.participantId,{data:T,isLoading:F,loadMore:M}=W7(e??""),I=Je(D=>D.agentStatuses),R=Je(D=>D.openThreadMessageId),H=Je(D=>D.closeThread),V=Je(D=>D.unreadCounts),{mutate:K,isPending:q}=q7();bW(e);const $=!!g&&((I[g.id]??g.status)==="thinking"||(I[g.id]??g.status)==="executing"),B=T.some(D=>D.status==="pending_approval"),Y=g?VMe[g.id]??g.color:void 0,U=e?V[e]??0:0,W=U>0&&T.length>=U?T[T.length-U]?.id:void 0,O=y.useCallback((D,Q)=>{e&&K({channelId:e,content:D,attachmentIds:Q})},[e,K]);return!e||!m?r.jsx("div",{className:"flex-1 flex items-center justify-center text-[#8A8A99]",children:r.jsx("p",{className:"text-[14px]",children:"Channel not found"})}):m.channelType==="terminal"?r.jsx("div",{className:"flex-1"}):m.channelType==="group"?r.jsx(dwe,{channel:m,agents:b}):r.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[r.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[r.jsx(swe,{channel:m,agent:w?void 0:g,agentColor:w?void 0:Y,hasPendingApproval:w?!1:B,rightPanelOpen:i,memoryPanelOpen:c,activeOverride:f,humanDmName:E,humanDmUserId:k,onToggleRightPanel:()=>a(D=>!D),onToggleMemoryPanel:()=>d(D=>!D),onAgentClick:()=>a(D=>!D),onClearOverride:()=>p(null),onClearConversation:()=>Je.getState().setMessages(e,[])}),r.jsx(ike,{channelId:e,agentForChannel:m.channelType==="topic"||w?void 0:g,agentColor:m.channelType==="topic"||w?void 0:Y,messages:T,isThinking:m.channelType==="topic"||w?!1:$,isLoading:F,loadMore:M,firstUnreadId:W}),r.jsx(cke,{channelId:e}),r.jsx(H7,{channelId:e,channelName:w?E??"User":m.name,agent:m.channelType==="topic"||w?void 0:g,agentColor:m.channelType==="topic"||w?void 0:Y,onSend:O,disabled:q,mentionableParticipants:m.channelType==="topic"?[...m.participants.filter(D=>D.participantType==="agent").map(D=>b.find(Q=>Q.id===D.participantId)).filter(D=>!!D).map(D=>({id:D.id,name:D.name,emoji:D.emoji,color:D.color,type:"agent"})),...m.participants.filter(D=>D.participantType==="human"&&D.participantId!==_?.user?.id).map(D=>{const Q=S.find(z=>z.userId===D.participantId);return Q?{id:Q.userId,name:Q.name,emoji:null,color:"#6366F1",type:"human"}:null}).filter(D=>!!D)]:void 0})]}),r.jsx(Me,{children:c&&g&&r.jsx(hke,{agent:g,agentColor:Y,onClose:()=>d(!1)})}),r.jsx(Me,{children:R&&r.jsx(dke,{parentMessageId:R,agentColor:Y,onClose:H})}),r.jsx(Me,{children:i&&g&&Y&&r.jsx($N,{agent:g,agentColor:Y,onClose:()=>{a(!1),l(void 0)},onOverrideSet:D=>p(D),initialTab:o},o?.subTab)})]})}function HMe({onClose:e,onSuccess:t}){const[n,s]=y.useState("pick"),[i,a]=y.useState(null),[o,l]=y.useState(null),[c,d]=y.useState(null),f=y.useRef(null),p=L.agentImport.previewImport.useMutation(),m=L.agentImport.confirmImport.useMutation(),g=y.useCallback(async S=>{if(!S.name.endsWith(".damnpack")){l("Please select a .damnpack file"),s("error");return}if(S.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const C=new FormData;C.append("file",S);const E=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:C,credentials:"include"});if(!E.ok){const F=await E.json().catch(()=>({error:"Upload failed"}));throw new Error(F.error||`Upload failed (${E.status})`)}const{uploadId:k}=await E.json(),T=await p.mutateAsync({uploadId:k});if("kind"in T&&T.kind==="skill-pack"){s("skill-pack");return}a(T),s("preview")}catch(C){l(C instanceof Error?C.message:"Upload failed"),s("error")}},[p]);async function b(S){if(i){s("confirming");try{const C=await m.mutateAsync({previewId:i.previewId,mode:S});d(C),s("done")}catch(C){l(C instanceof Error?C.message:"Import failed"),s("error")}}}const _=i?.warnings.filter(S=>S.type==="credential")??[],w=i?.warnings.filter(S=>S.type==="url")??[],A=i?.warnings.filter(S=>S.type==="shell_exec")??[];return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:e,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},onClick:S=>S.stopPropagation(),className:"relative w-full max-w-md bg-[#16161A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:n==="done"?"Import complete":n==="skill-pack"?"Skill pack":"Import agent"}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"p-5",children:[n==="pick"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("button",{onClick:()=>f.current?.click(),className:"w-full py-10 rounded-xl border-2 border-dashed border-[#2A2A35] hover:border-[#6366F1]/50 transition-colors flex flex-col items-center gap-3 group",children:[r.jsx(su,{className:"w-8 h-8 text-[#5A5A6E] group-hover:text-[#6366F1] transition-colors"}),r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-medium",children:"Choose .damnpack file"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Max 100MB"})]})]}),r.jsx("input",{ref:f,type:"file",accept:".damnpack",className:"hidden",onChange:S=>{const C=S.target.files?.[0];C&&g(C)}})]}),(n==="uploading"||n==="confirming")&&r.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[r.jsx(Pe,{className:"w-8 h-8 text-[#6366F1] animate-spin"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:n==="uploading"?"Scanning bundle...":"Importing agent..."})]}),n==="error"&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-4 py-3",children:r.jsx("p",{className:"text-[13px] text-[#FCA5A5]",children:o})}),r.jsx("button",{onClick:()=>{s("pick"),l(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),n==="skill-pack"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#6366F1]/15 border border-[#6366F1]/25 flex items-center justify-center",children:r.jsx(vv,{className:"w-5 h-5 text-[#818CF8]"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Skill pack detected"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"This bundle contains skills, not an agent."})]})]}),r.jsx(gn,{to:"/skills",onClick:e,className:"flex items-center justify-center w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Go to Skills page to import"}),r.jsx("button",{onClick:e,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]}),n==="preview"&&i&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#6366F1]/15 border border-[#6366F1]/25 flex items-center justify-center text-lg",children:i.manifest.name.slice(0,2)}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.manifest.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.manifest.version," by ",i.manifest.author.name]})]}),i.isUpdate&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20",children:"Update"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.manifest.description}),r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] p-3",children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:"Soul excerpt"}),r.jsx("p",{className:"text-[12px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap line-clamp-6",children:i.soulExcerpt})]}),i.manifest.skills.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Skills"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.manifest.skills.map(S=>r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-medium bg-[#6366F1]/10 text-[#818CF8] border border-[#6366F1]/20",children:S},S))})]}),i.isUpdate&&i.diff&&r.jsx("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] px-3 py-2",children:r.jsxs("p",{className:"text-[12px] text-[#C8C8D4]",children:["SOUL.md: ",r.jsxs("span",{className:"text-emerald-400",children:["+",i.diff.added]})," / ",r.jsxs("span",{className:"text-red-400",children:["-",i.diff.removed]})," lines",i.skillFiles.length>0&&`. ${i.skillFiles.length} skill file(s).`]})}),i.modelWarnings.length>0&&r.jsx("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:i.modelWarnings.map((S,C)=>r.jsxs("p",{className:"text-[11px] text-[#FCD34D] flex items-start gap-1.5",children:[r.jsx(Wl,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),S]},C))}),i.missingSecrets.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1.5",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(Eo,{className:"w-3.5 h-3.5"}),"Required workspace secrets missing"]}),r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80",children:"This bundle's skills reference secrets that aren't set in this workspace. You can still import now, but agents will fail to call these tools until you add the secrets in Settings → Secrets:"}),r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:i.missingSecrets.map(S=>r.jsx("code",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono text-[#FCD34D] bg-[#F59E0B]/15 border border-[#F59E0B]/20",children:S},S))})]}),A.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5] flex items-center gap-1.5",children:[r.jsx(Ti,{className:"w-3.5 h-3.5"}),"Shell execution patterns detected"]}),A.map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80 ml-5",children:[S.file,":",S.line," — ",S.message]},C))]}),_.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),"Possible credentials found"]}),_.map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:[S.file,":",S.line]},C))]}),w.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#2A2A35]/50 border border-[#2A2A35] px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#8A8A99] flex items-center gap-1.5",children:[r.jsx(Xt,{className:"w-3.5 h-3.5"}),"External URLs (",w.length,")"]}),w.slice(0,5).map((S,C)=>r.jsx("p",{className:"text-[10px] text-[#5A5A6E] ml-5 truncate",children:S.message.replace("External URL: ","")},C)),w.length>5&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E] ml-5",children:["...and ",w.length-5," more"]})]}),i.hasHeartbeat&&r.jsx("div",{className:"rounded-lg bg-[#6366F1]/10 border border-[#6366F1]/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-[#818CF8] flex items-start gap-1.5",children:[r.jsx(bm,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5"}),"This agent includes a scheduled task. It will be disabled by default."]})}),i.isUpdate&&r.jsxs("p",{className:"text-[11px] text-[#8A8A99] italic",children:["Updating existing agent: ",i.manifest.name,". Your memory and experience will be preserved."]}),i.strippedFiles.length>0&&r.jsxs("p",{className:"text-[10px] text-[#5A5A6E]",children:["Stripped from bundle: ",i.strippedFiles.join(", ")]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[i.isUpdate?r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>b("update"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Update"}),r.jsx("button",{onClick:()=>b("new"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Import as copy"})]}):r.jsx("button",{onClick:()=>b("new"),className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Import"}),r.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),n==="done"&&c&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center",children:r.jsx(Fe,{className:"w-5 h-5 text-emerald-400"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:c.name}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:c.mode==="update"?"Agent updated successfully":"Agent imported successfully"})]})]}),c.heartbeatNote&&r.jsx("p",{className:"text-[11px] text-[#818CF8] bg-[#6366F1]/10 border border-[#6366F1]/20 rounded-lg px-3 py-2",children:c.heartbeatNote}),c.diff&&r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:c.diff}),r.jsx("button",{onClick:()=>{t(),e()},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}function WMe({onClose:e}){const[t,n]=y.useState("select"),[s,i]=y.useState(new Set),[a,o]=y.useState(new Set),[l,c]=y.useState(null),[d,f]=y.useState([]),{data:p}=L.teamBundle.listExportable.useQuery(),m=L.teamBundle.exportTeam.useMutation(),g=p?.agents??[],b=p?.channels??[];function _(S){i(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})}function w(S){o(C=>{const E=new Set(C);return E.has(S)?E.delete(S):E.add(S),E})}async function A(){if(s.size!==0){n("exporting");try{const S=await m.mutateAsync({agentIds:[...s],channelIds:[...a]});f(S.warnings.map(M=>({file:M.file,message:M.message})));const C=atob(S.buffer),E=new Uint8Array(C.length);for(let M=0;M<C.length;M++)E[M]=C.charCodeAt(M);const k=new Blob([E],{type:"application/zip"}),T=URL.createObjectURL(k),F=document.createElement("a");F.href=T,F.download=S.filename,F.click(),URL.revokeObjectURL(T),n("done")}catch(S){c(S instanceof Error?S.message:"Export failed"),n("error")}}}return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:e,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},onClick:S=>S.stopPropagation(),className:"relative w-full max-w-md bg-[#16161A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:t==="done"?"Export complete":"Export team"}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"p-5",children:[t==="select"&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Agents (",s.size," selected)"]}),r.jsxs("div",{className:"space-y-1",children:[g.map(S=>r.jsxs("label",{className:"flex items-center gap-3 py-2 px-3 rounded-lg hover:bg-white/5 cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:s.has(S.id),onChange:()=>_(S.id),className:"w-3.5 h-3.5 rounded border-[#2A2A35] text-[#6366F1] focus:ring-0 focus:ring-offset-0"}),r.jsx("span",{className:"text-sm",children:S.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:S.name}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:S.role})]})]},S.id)),g.length===0&&r.jsx("p",{className:"text-[12px] text-[#5A5A6E] py-2",children:"No agents available"})]})]}),b.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Channels (",a.size," selected)"]}),r.jsx("div",{className:"space-y-1",children:b.map(S=>r.jsxs("label",{className:"flex items-center gap-3 py-2 px-3 rounded-lg hover:bg-white/5 cursor-pointer transition-colors",children:[r.jsx("input",{type:"checkbox",checked:a.has(S.id),onChange:()=>w(S.id),className:"w-3.5 h-3.5 rounded border-[#2A2A35] text-[#6366F1] focus:ring-0 focus:ring-offset-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:S.name}),r.jsxs("p",{className:"text-[11px] text-[#5A5A6E]",children:[S.channelType," / ",S.visibility]})]})]},S.id))})]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsxs("button",{onClick:A,disabled:s.size===0,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors disabled:opacity-40 disabled:pointer-events-none flex items-center justify-center gap-2",children:[r.jsx(vv,{className:"w-4 h-4"}),"Export (",s.size," agents)"]}),r.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),t==="exporting"&&r.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[r.jsx(Pe,{className:"w-8 h-8 text-[#6366F1] animate-spin"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Packaging team bundle..."})]}),t==="error"&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-4 py-3",children:r.jsx("p",{className:"text-[13px] text-[#FCA5A5]",children:l})}),r.jsx("button",{onClick:()=>{n("select"),c(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),t==="done"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center",children:r.jsx(Fe,{className:"w-5 h-5 text-emerald-400"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Team exported"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[s.size," agents, ",a.size," channels"]})]})]}),r.jsx(Me,{children:d.length>0&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),d.length," warning(s)"]}),d.slice(0,5).map((S,C)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:[S.file,": ",S.message]},C))]})}),r.jsx("button",{onClick:e,className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}function qMe({onClose:e,onSuccess:t}){const[n,s]=y.useState("pick"),[i,a]=y.useState(null),[o,l]=y.useState(null),[c,d]=y.useState(null),[f,p]=y.useState(null),m=y.useRef(null),g=L.teamBundle.previewTeamImport.useMutation(),b=L.teamBundle.confirmTeamImport.useMutation(),_=y.useCallback(async C=>{if(!C.name.endsWith(".damnteam")){l("Please select a .damnteam file"),s("error");return}if(C.size>100*1024*1024){l("File too large (max 100MB)"),s("error");return}s("uploading");try{const E=new FormData;E.append("file",C);const k=await fetch(`${oi}/api/agents/import-upload`,{method:"POST",body:E,credentials:"include"});if(!k.ok){const M=await k.json().catch(()=>({error:"Upload failed"}));throw new Error(M.error||`Upload failed (${k.status})`)}const{uploadId:T}=await k.json(),F=await g.mutateAsync({uploadId:T});a(F),s("preview")}catch(E){l(E instanceof Error?E.message:"Upload failed"),s("error")}},[g]);async function w(){if(i){s("confirming");try{const C=await b.mutateAsync({previewId:i.previewId});d(C),s("done")}catch(C){l(C instanceof Error?C.message:"Import failed"),s("error")}}}const A=i?.warnings.filter(C=>C.type==="credential")??[],S=i?.warnings.filter(C=>C.type==="shell_exec")??[];return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:e,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},onClick:C=>C.stopPropagation(),className:"relative w-full max-w-lg bg-[#16161A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"px-5 py-4 border-b border-[#2A2A35] flex items-center justify-between",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:n==="done"?"Team imported":"Import team"}),r.jsx("button",{onClick:e,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Te,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"p-5",children:[n==="pick"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("button",{onClick:()=>m.current?.click(),className:"w-full py-10 rounded-xl border-2 border-dashed border-[#2A2A35] hover:border-[#6366F1]/50 transition-colors flex flex-col items-center gap-3 group",children:[r.jsx(su,{className:"w-8 h-8 text-[#5A5A6E] group-hover:text-[#6366F1] transition-colors"}),r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] font-medium",children:"Choose .damnteam file"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1",children:"Max 100MB"})]})]}),r.jsx("input",{ref:m,type:"file",accept:".damnteam",className:"hidden",onChange:C=>{const E=C.target.files?.[0];E&&_(E)}})]}),(n==="uploading"||n==="confirming")&&r.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[r.jsx(Pe,{className:"w-8 h-8 text-[#6366F1] animate-spin"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:n==="uploading"?"Scanning team bundle...":"Importing team..."})]}),n==="error"&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-4 py-3",children:r.jsx("p",{className:"text-[13px] text-[#FCA5A5]",children:o})}),r.jsx("button",{onClick:()=>{s("pick"),l(null)},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Try again"})]}),n==="preview"&&i&&r.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#6366F1]/15 border border-[#6366F1]/25 flex items-center justify-center",children:r.jsx(wm,{className:"w-5 h-5 text-[#6366F1]"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5] truncate",children:i.teamManifest.name}),r.jsxs("p",{className:"text-[11px] text-[#8A8A99]",children:["v",i.teamManifest.version," by ",i.teamManifest.author.name]})]})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:i.teamManifest.description}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Agents (",i.agentPreviews.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.agentPreviews.map(C=>r.jsxs("div",{className:"rounded-lg bg-[#1C1C21] border border-[#2A2A35] overflow-hidden",children:[r.jsxs("button",{onClick:()=>p(f===C.slug?null:C.slug),className:"w-full flex items-center gap-3 px-3 py-2.5 text-left",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-[13px] text-[#F0F0F5] truncate",children:C.manifest.name}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] truncate",children:C.manifest.description})]}),C.isUpdate&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-medium bg-[#F59E0B]/10 text-[#FCD34D] border border-[#F59E0B]/20 flex-shrink-0",children:"Update"}),C.warnings.length>0&&r.jsx(ql,{className:"w-3.5 h-3.5 text-[#FCD34D] flex-shrink-0"}),r.jsx(ft,{className:`w-3.5 h-3.5 text-[#5A5A6E] transition-transform ${f===C.slug?"rotate-180":""}`})]}),r.jsx(Me,{children:f===C.slug&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:r.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-[#2A2A35]",children:[r.jsx("p",{className:"text-[11px] text-[#C8C8D4] leading-relaxed whitespace-pre-wrap line-clamp-4 pt-2",children:C.soulExcerpt}),C.modelWarnings.length>0&&r.jsx("div",{className:"space-y-0.5",children:C.modelWarnings.map((E,k)=>r.jsxs("p",{className:"text-[10px] text-[#FCD34D] flex items-center gap-1",children:[r.jsx(Wl,{className:"w-3 h-3"}),E]},k))}),C.hasHeartbeat&&r.jsxs("p",{className:"text-[10px] text-[#818CF8] flex items-center gap-1",children:[r.jsx(bm,{className:"w-3 h-3"}),"Includes scheduled task (will be disabled)"]})]})})})]},C.slug))})]}),i.channelDefinitions.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Channels (",i.channelDefinitions.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.channelDefinitions.map((C,E)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Tp,{className:"w-3.5 h-3.5 text-[#5A5A6E]"}),r.jsx("p",{className:"text-[12px] text-[#C8C8D4] flex-1",children:C.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:C.channelType}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:[C.agentSlugs.length," agents"]})]},E))})]}),i.delegationRules.length>0&&r.jsxs("div",{children:[r.jsxs("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-2",children:["Delegation rules (",i.delegationRules.length,")"]}),r.jsx("div",{className:"space-y-1",children:i.delegationRules.map((C,E)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(ch,{className:"w-3.5 h-3.5 text-[#5A5A6E]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.agentSlug}),r.jsx("code",{className:"text-[11px] font-mono text-[#8A8A99] bg-white/5 px-1.5 py-0.5 rounded",children:C.pattern}),r.jsx("span",{className:"ml-auto px-2 py-0.5 rounded-full text-[9px] font-medium bg-amber-500/10 text-amber-400 border border-amber-500/20",children:"Will require approval"})]},E))})]}),S.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5] flex items-center gap-1.5",children:[r.jsx(Ti,{className:"w-3.5 h-3.5"}),"Shell execution patterns detected"]}),S.slice(0,5).map((C,E)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80 ml-5",children:[C.file,": ",C.message]},E))]}),A.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#F59E0B]/10 border border-[#F59E0B]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCD34D] flex items-center gap-1.5",children:[r.jsx(ql,{className:"w-3.5 h-3.5"}),"Possible credentials found"]}),A.slice(0,5).map((C,E)=>r.jsx("p",{className:"text-[10px] text-[#FCD34D]/80 ml-5",children:C.file},E))]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsx("button",{onClick:w,className:"flex-1 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Import all"}),r.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-[#2A2A35] hover:bg-[#3A3A45] text-[#F0F0F5] transition-colors",children:"Cancel"})]})]}),n==="done"&&c&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center gap-3 py-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center",children:r.jsx(Fe,{className:"w-5 h-5 text-emerald-400"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:"Team imported"}),r.jsxs("p",{className:"text-[12px] text-[#8A8A99]",children:[c.importedAgents.length," agents, ",c.createdChannels.length," channels"]})]})]}),c.importedAgents.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Imported agents"}),r.jsx("div",{className:"space-y-1",children:c.importedAgents.map(C=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Fe,{className:"w-3 h-3 text-emerald-400"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:C.mode})]},C.agentId))})]}),c.createdChannels.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest mb-1.5",children:"Created channels"}),r.jsx("div",{className:"space-y-1",children:c.createdChannels.map(C=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[#1C1C21] border border-[#2A2A35]",children:[r.jsx(Tp,{className:"w-3 h-3 text-[#6366F1]"}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4]",children:C.name})]},C.id))})]}),c.pendingRules.length>0&&r.jsx("div",{className:"rounded-lg bg-amber-500/10 border border-amber-500/20 px-3 py-2",children:r.jsxs("p",{className:"text-[11px] text-amber-400",children:[c.pendingRules.length," delegation rule(s) pending approval"]})}),c.failures.length>0&&r.jsxs("div",{className:"rounded-lg bg-[#EF4444]/10 border border-[#EF4444]/20 px-3 py-2 space-y-1",children:[r.jsxs("p",{className:"text-[11px] font-semibold text-[#FCA5A5]",children:["Failed (",c.failures.length,")"]}),c.failures.map((C,E)=>r.jsxs("p",{className:"text-[10px] text-[#FCA5A5]/80",children:[C.slug,": ",C.error]},E))]}),r.jsx("button",{onClick:()=>{t(),e()},className:"w-full py-2 rounded-lg text-[13px] font-medium bg-[#6366F1] hover:bg-[#5254CC] text-white transition-colors",children:"Done"})]})]})]})]})}function GMe({status:e,color:t}){const n=e==="thinking"||e==="executing";return r.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3",children:[n&&r.jsx(ne.span,{className:"absolute inset-0 rounded-full",style:{backgroundColor:t,opacity:.5},animate:{scale:[1,2,1],opacity:[.5,0,.5]},transition:{duration:2,repeat:1/0,ease:"easeInOut"}}),r.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{backgroundColor:e==="offline"?"#3A3A45":t,opacity:e==="idle"?.5:1}})]})}function KMe({agent:e,onClose:t}){const{data:n,isLoading:s}=L.agents.getMemory.useQuery({agentId:e.id});return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:t,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},className:"relative w-full max-w-2xl bg-[#16161A] border border-[#2A2A35] rounded-2xl overflow-hidden shadow-2xl",onClick:i=>i.stopPropagation(),children:[r.jsxs("div",{className:"px-6 py-5 border-b border-[#2A2A35] flex items-center justify-between",style:{background:`linear-gradient(135deg, rgba(${uh(e.color)}, 0.08) 0%, transparent 100%)`},children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-2xl",children:e.emoji}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[14px] font-semibold text-[#F0F0F5]",children:e.name}),r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"MEMORY.md — read only"})]})]}),r.jsx("button",{onClick:t,className:"text-[#8A8A99] hover:text-[#F0F0F5] transition-colors text-[20px] leading-none w-8 h-8 flex items-center justify-center rounded-lg hover:bg-white/10",children:"×"})]}),r.jsxs("div",{className:"p-6 max-h-[60vh] overflow-y-auto",children:[s&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] animate-pulse",children:"Loading memory…"}),!s&&!n?.content&&r.jsx("p",{className:"text-[13px] text-[#8A8A99] italic",children:"No memory recorded yet."}),!s&&n?.content&&r.jsx("div",{className:"prose-message text-[13px]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:n.content})})]})]})]})}function YMe({agent:e,onConfirm:t,onCancel:n}){return r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),r.jsxs(ne.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.15},className:"relative w-full max-w-sm bg-[#16161A] border border-[#2A2A35] rounded-2xl p-6 shadow-2xl",onClick:s=>s.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx("span",{className:"text-3xl",children:e.emoji}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:["Delete ",e.name,"?"]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"This permanently removes the agent from OpenClaw, deletes all files (SOUL, MEMORY, TEAM), and removes the DM channel."})]})]}),r.jsxs("div",{className:"flex gap-2 mt-6",children:[r.jsx("button",{onClick:n,className:"flex-1 h-9 rounded-lg border border-[#2A2A35] text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45] transition-colors",children:"Cancel"}),r.jsx("button",{onClick:t,className:"flex-1 h-9 rounded-lg bg-red-500/10 border border-red-500/30 text-[13px] text-red-400 hover:bg-red-500/20 transition-colors",children:"Delete"})]})]})]})}function QMe({agent:e}){const[t,n]=y.useState(""),s=L.useUtils(),i=L.agents.update.useMutation({onSuccess:()=>s.agents.list.invalidate()}),{groups:a}=Vm();return r.jsxs(Yv,{onOpenChange:o=>{o||n("")},children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-white/5 hover:bg-white/10 transition-colors text-[12px] text-[#C8C8D4]",children:[r.jsx("span",{children:ta(e.model)}),r.jsx(Jt,{className:"w-3 h-3 rotate-90"})]})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-y-auto shadow-xl z-[9999] min-w-[160px] max-h-[280px]",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx(ty,{value:t,onChange:n,onSubmit:o=>{i.mutate({agentId:e.id,model:o}),n("")},placeholder:"Type model ID..."})}),a.map(o=>r.jsxs(g_e,{children:[r.jsx(b_e,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-wider",children:o.label}),o.models.map(l=>r.jsx(Bl,{onSelect:()=>i.mutate({agentId:e.id,model:l.id}),className:ye("w-full text-left px-3 py-1.5 text-[12px] cursor-pointer outline-none hover:bg-white/10 transition-colors",e.model===l.id?"text-[#F0F0F5]":"text-[#8A8A99]"),children:l.label},l.id))]},o.label))]})})]})}function XMe(e,t){const n=atob(e),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n.charCodeAt(l);const i=new Blob([s],{type:"application/zip"}),a=URL.createObjectURL(i),o=document.createElement("a");o.href=a,o.download=t,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}const JMe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],ZMe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16"];function eRe({agent:e,onOpenPanel:t,canManage:n}){const[s,i]=y.useState(!1),[a,o]=y.useState(!1),[l,c]=y.useState(!1),[d,f]=y.useState(e.name),p=y.useRef(null),m=L.useUtils();y.useEffect(()=>{l&&p.current?.select()},[l]),y.useEffect(()=>{f(e.name)},[e.name]);const g=L.agents.update.useMutation({onSuccess:()=>{m.agents.list.invalidate(),m.channels.list.invalidate()}});function b(){c(!1);const C=d.trim();C&&C!==e.name?g.mutate({agentId:e.id,name:C}):f(e.name)}const _=L.agents.delete.useMutation({onSuccess:()=>m.agents.list.invalidate()}),w=L.agents.export.useMutation({onSuccess:C=>XMe(C.buffer,C.filename)}),A=e.status==="offline",S=uh(e.color);return r.jsxs(r.Fragment,{children:[r.jsxs(ne.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},onClick:()=>t(e),className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 hover:border-[#3A3A45] transition-colors group relative overflow-hidden cursor-pointer",children:[r.jsx("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",style:{background:`radial-gradient(400px circle at 0% 0%, rgba(${S}, 0.04), transparent 60%)`}}),r.jsxs("div",{className:"flex items-start gap-4 mb-4",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center text-2xl flex-shrink-0",style:{backgroundColor:`rgba(${S}, 0.15)`,border:`1px solid rgba(${S}, 0.25)`},children:e.emoji}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[l?r.jsx("input",{ref:p,value:d,onChange:C=>f(C.target.value),onBlur:b,onKeyDown:C=>{C.key==="Enter"&&p.current?.blur(),C.key==="Escape"&&(f(e.name),c(!1))},onClick:C=>C.stopPropagation(),className:"bg-transparent text-[15px] font-semibold text-[#F0F0F5] outline-none border-b border-[#6366F1]/60 pb-px flex-1 min-w-0"}):r.jsx("h3",{className:"text-[15px] font-semibold text-[#F0F0F5] truncate",children:e.name}),r.jsx(GMe,{status:e.status,color:e.color})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] truncate",children:e.role}),e.lastAction&&r.jsx("p",{className:"text-[11px] text-[#5A5A6A] mt-1",children:Ir(e.lastAction)})]}),n&&e.id!=="coo"&&r.jsx("div",{onClick:C=>C.stopPropagation(),children:r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/10 transition-colors opacity-0 group-hover:opacity-100",children:r.jsx(iL,{className:"w-4 h-4"})})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,align:"end",className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-hidden shadow-xl z-[9999] min-w-[160px]",children:[r.jsxs(Bl,{onSelect:()=>c(!0),className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(oh,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Rename"]}),r.jsxs(lR,{children:[r.jsxs(cR,{className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors data-[state=open]:bg-white/10",children:[r.jsx(Tre,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Change emoji",r.jsx(Jt,{className:"w-3 h-3 ml-auto text-[#5A5A6E]"})]}),r.jsx(Od,{children:r.jsxs(uR,{sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Choose emoji"}),r.jsx("div",{className:"grid grid-cols-10 gap-1",children:JMe.map(C=>r.jsx(Bl,{onSelect:()=>g.mutate({agentId:e.id,emoji:C}),className:`w-6 h-6 flex items-center justify-center rounded text-sm cursor-pointer outline-none hover:bg-white/10 transition-colors ${e.emoji===C?"bg-white/15 ring-1 ring-white/20":""}`,children:C},C))})]})})]}),r.jsxs(lR,{children:[r.jsxs(cR,{className:"flex items-center gap-2.5 px-3 py-2 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors data-[state=open]:bg-white/10",children:[r.jsx(Zie,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Change color",r.jsx(Jt,{className:"w-3 h-3 ml-auto text-[#5A5A6E]"})]}),r.jsx(Od,{children:r.jsxs(uR,{sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-xl p-3 z-[9999] w-[240px]",children:[r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2",children:"Choose color"}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:ZMe.map(C=>r.jsx(Bl,{onSelect:()=>g.mutate({agentId:e.id,color:C}),className:`w-7 h-7 rounded-full cursor-pointer outline-none transition-all ${e.color===C?"ring-2 ring-white/40 scale-110":"hover:scale-110"}`,style:{backgroundColor:C}},C))})]})})]})]})})]})})]}),r.jsxs("p",{className:"text-[12px] text-[#6A6A7A] leading-relaxed line-clamp-2 mb-4 italic",children:['"',e.soulExcerpt,'"']}),r.jsxs("div",{className:"flex items-center gap-2",onClick:C=>C.stopPropagation(),children:[n&&r.jsx(QMe,{agent:e}),n&&r.jsx(bt,{label:"Edit soul",children:r.jsx(gn,{to:`/agents/edit-soul/${e.id}`,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(Ese,{className:"w-3.5 h-3.5"})})}),r.jsx(bt,{label:"View memory",children:r.jsx("button",{onClick:()=>i(!0),className:"w-7 h-7 flex items-center justify-center rounded-md text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10 transition-colors",children:r.jsx(eie,{className:"w-3.5 h-3.5"})})}),n&&r.jsx(bt,{label:A?"Resume":"Pause",children:r.jsx("button",{onClick:()=>g.mutate({agentId:e.id,status:A?"idle":"offline"}),className:ye("w-7 h-7 flex items-center justify-center rounded-md transition-colors",A?"text-emerald-400 hover:bg-emerald-500/10":"text-[#8A8A99] hover:text-[#F0F0F5] hover:bg-white/10"),children:A?r.jsx(I5,{className:"w-3.5 h-3.5"}):r.jsx(gL,{className:"w-3.5 h-3.5"})})}),n&&e.id!=="coo"&&r.jsx(bt,{label:"Export agent",children:r.jsx("button",{onClick:()=>w.mutate({agentId:e.id}),disabled:w.isPending,className:"w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-[#8A8A99] hover:bg-white/10 transition-colors opacity-0 group-hover:opacity-100 disabled:opacity-50",children:r.jsx(nu,{className:"w-3.5 h-3.5"})})}),n&&r.jsx(bt,{label:"Delete agent",children:r.jsx("button",{onClick:()=>o(!0),className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-[#5A5A6E] hover:text-red-400 hover:bg-red-500/10 transition-colors opacity-0 group-hover:opacity-100",children:r.jsx(Dn,{className:"w-3.5 h-3.5"})})})]})]}),r.jsxs(Me,{children:[s&&r.jsx(KMe,{agent:e,onClose:()=>i(!1)}),a&&r.jsx(YMe,{agent:e,onCancel:()=>o(!1),onConfirm:()=>{_.mutate({agentId:e.id}),o(!1)}})]})]})}function tRe(){const[e,t]=y.useState(null),[n,s]=y.useState(!1),[i,a]=y.useState(!1),[o,l]=y.useState(!1),{data:c=[],isLoading:d}=L.agents.list.useQuery(),f=L.useUtils(),p=Uo();return r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11]",children:[r.jsxs("div",{className:"max-w-4xl mx-auto px-8 py-10",children:[r.jsxs("div",{className:"flex items-center justify-between mb-8",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"Agents"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mt-0.5",children:"Your team of AI collaborators"})]}),p&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Yv,{children:[r.jsx(Qv,{asChild:!0,children:r.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-xl border border-[#2A2A35] text-[#C8C8D4] text-[13px] font-medium hover:bg-white/5 transition-colors",children:[r.jsx(su,{className:"w-4 h-4"}),"Import",r.jsx(Jt,{className:"w-3 h-3 rotate-90 text-[#5A5A6E]"})]})}),r.jsx(Od,{children:r.jsxs(Xv,{sideOffset:4,align:"end",className:"bg-[#1E1E24] border border-[#2A2A35] rounded-xl overflow-hidden shadow-xl z-[9999] min-w-[180px]",children:[r.jsxs(Bl,{onSelect:()=>s(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(su,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Import agent"]}),r.jsxs(Bl,{onSelect:()=>l(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(wm,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Import team"]}),r.jsx(v_e,{className:"h-px bg-[#2A2A35] my-1"}),r.jsxs(Bl,{onSelect:()=>a(!0),className:"w-full flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-[#C8C8D4] cursor-pointer outline-none hover:bg-white/10 transition-colors",children:[r.jsx(vv,{className:"w-3.5 h-3.5 text-[#8A8A99]"}),"Export team"]})]})})]}),r.jsxs(gn,{to:"/agents/new",className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium hover:opacity-90 transition-opacity shadow-lg shadow-[#6366F1]/20",children:[r.jsx(wt,{className:"w-4 h-4"}),"New agent"]})]})]}),d&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[1,2,3].map(m=>r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 animate-pulse h-[180px]"},m))}),!d&&c.length===0&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mb-4 text-2xl",children:"🤖"}),r.jsx("h2",{className:"text-[16px] font-semibold text-[#F0F0F5] mb-2",children:"No agents yet"}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] mb-6 max-w-xs",children:"Create your first AI agent and it'll be live in under 60 seconds."}),p&&r.jsxs(gn,{to:"/agents/new",className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium hover:opacity-90 transition-opacity",children:[r.jsx(wt,{className:"w-4 h-4"}),"Create agent"]})]}),!d&&c.length>0&&r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:c.map(m=>r.jsx(eRe,{agent:m,onOpenPanel:t,canManage:p},m.id))})]}),r.jsxs(Me,{children:[e&&r.jsx($N,{agent:e,agentColor:e.color,onClose:()=>t(null),onOverrideSet:()=>t(null)},e.id),n&&r.jsx(HMe,{onClose:()=>s(!1),onSuccess:()=>f.agents.list.invalidate()}),i&&r.jsx(WMe,{onClose:()=>a(!1)}),o&&r.jsx(qMe,{onClose:()=>l(!1),onSuccess:()=>{f.agents.list.invalidate()}})]})]})}const nRe=["🧠","⚡","✨","🎯","🔥","💡","🚀","🛡️","🔬","📊","🌊","🌿","🎨","🔧","📝","🎭","💎","🦁","🦊","🐬","🌙","⭐","🏆","💼","🎯","🔮","🌺","⚗️","🧬","🕊️"],sRe=["#6366F1","#8B5CF6","#EC4899","#EF4444","#F97316","#EAB308","#22C55E","#10B981","#14B8A6","#3B82F6","#06B6D4","#A855F7","#F43F5E","#84CC16","#6366F1"],iRe=[{id:"qwen3:14b",label:"Qwen 3 14B",note:"Fast · Local · Free"},{id:"tomng/nanbeige4.1",label:"NanBeige 4.1 · 3B",note:"Agentic · Local · Free"},{id:"openrouter/anthropic/claude-sonnet-4.6",label:"Claude Sonnet",note:"Smart · Fast · $$$"},{id:"openrouter/anthropic/claude-opus-4.6",label:"Claude Opus",note:"Best · Slow · $$$$"}];function rRe({color:e,name:t,emoji:n}){const s=uh(e),i=t||"Agent",a=n||"🤖";return r.jsxs("div",{className:"rounded-xl overflow-hidden border border-[#2A2A35] bg-[#0F0F11]",children:[r.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",style:{borderLeft:`3px solid ${e}`,background:`linear-gradient(90deg, rgba(${s}, 0.08) 0%, transparent 60%)`},children:[r.jsx("span",{className:"text-lg",children:a}),r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-semibold text-[#F0F0F5]",children:i}),r.jsx("p",{className:"text-[11px] text-[#8A8A99]",children:"online"})]}),r.jsx("div",{className:"ml-auto w-2 h-2 rounded-full",style:{backgroundColor:e}})]}),r.jsx("div",{className:"px-4 py-3",children:r.jsx("div",{className:"rounded-xl px-3 py-2 max-w-[75%]",style:{backgroundColor:`rgba(${s}, 0.12)`,border:`1px solid rgba(${s}, 0.2)`},children:r.jsx("p",{className:"text-[12px] text-[#C8C8D4]",children:"Ready to help. What do you need?"})})})]})}function aRe({state:e,onChange:t,onNext:n}){const s=e.name.trim().length>0&&e.role.trim().length>0;return r.jsxs("div",{className:"flex gap-8 h-full",children:[r.jsxs("div",{className:"flex-1 space-y-6",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Name"}),r.jsx("input",{value:e.name,onChange:i=>t({name:i.target.value}),placeholder:"e.g. Nova, Relay, Axiom",className:"w-full h-10 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[14px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Role"}),r.jsx("input",{value:e.role,onChange:i=>t({role:i.target.value}),placeholder:"e.g. Content Strategist, Research Analyst",className:"w-full h-10 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[14px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Emoji"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:nRe.map(i=>r.jsx("button",{onClick:()=>t({emoji:i}),className:ye("w-9 h-9 rounded-lg text-lg transition-all",e.emoji===i?"bg-[#6366F1]/20 ring-2 ring-[#6366F1] scale-110":"bg-[#1E1E24] hover:bg-[#2A2A35]"),children:i},i))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Color"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:sRe.map(i=>r.jsx("button",{onClick:()=>t({color:i}),className:ye("w-7 h-7 rounded-full transition-all",e.color===i?"ring-2 ring-offset-2 ring-offset-[#0F0F11] scale-125":"hover:scale-110"),style:{backgroundColor:i,outlineColor:i}},i))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Model"}),r.jsx("div",{className:"space-y-2",children:iRe.map(i=>r.jsxs("button",{onClick:()=>t({model:i.id}),className:ye("w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all text-left",e.model===i.id?"bg-[#6366F1]/10 border-[#6366F1]/50 text-[#F0F0F5]":"bg-[#1E1E24] border-[#2A2A35] text-[#8A8A99] hover:border-[#3A3A45] hover:text-[#C8C8D4]"),children:[r.jsx("span",{className:"text-[13px] font-medium",children:i.label}),r.jsx("span",{className:"text-[11px] opacity-60",children:i.note})]},i.id))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Visibility"}),r.jsx("div",{className:"flex gap-2",children:[{value:"public",icon:Xt,label:"Public"},{value:"private",icon:Eo,label:"Private"},{value:"owner",icon:Ia,label:"Owner only"}].map(({value:i,icon:a,label:o})=>r.jsxs("button",{onClick:()=>t({visibility:i}),className:ye("flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-xl border transition-all text-[12px] font-medium",e.visibility===i?"bg-[#6366F1]/10 border-[#6366F1]/50 text-[#F0F0F5]":"bg-[#1E1E24] border-[#2A2A35] text-[#8A8A99] hover:border-[#3A3A45] hover:text-[#C8C8D4]"),children:[r.jsx(a,{className:"w-3 h-3"}),o]},i))})]})]}),r.jsxs("div",{className:"w-[260px] flex-shrink-0 space-y-4",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[12px] font-medium text-[#8A8A99] mb-2 uppercase tracking-wider",children:"Preview"}),r.jsx(rRe,{color:e.color,name:e.name,emoji:e.emoji})]}),r.jsxs("button",{onClick:n,disabled:!s,className:"w-full h-10 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-30 disabled:cursor-not-allowed shadow-lg shadow-[#6366F1]/20",children:["Continue",r.jsx(tu,{className:"w-4 h-4"})]})]})]})}function vW({state:e,soul:t,onSoulChange:n,onNext:s,onBack:i,editMode:a,initialSoul:o}){const[l,c]=y.useState(()=>a&&o?[{role:"assistant",content:`I've loaded ${e.name}'s current soul. What would you like to change? You can say things like "make it more direct", "add a section about how to handle conflicts", or just describe the vibe you want.`}]:[]),[d,f]=y.useState(""),[p,m]=y.useState(!1),[g,b]=y.useState(""),[_,w]=y.useState(a&&!!o),A=y.useRef(null),S=y.useRef(null);y.useEffect(()=>{A.current?.scrollIntoView({behavior:"smooth"})},[l,g]);const C=y.useCallback(async(T,F)=>{m(!0),b("");const M={description:T,agentName:e.name,agentRole:e.role};F&&(M.refinement=F),a&&o&&(M.currentSoul=o);try{const I=await fetch(`${oi}/api/agents/generate-soul`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)});if(!I.ok)throw new Error("Generation failed");const H=(await I.json()).text;n(H),b(""),w(!0),c(V=>[...V,{role:"assistant",content:"Here's the soul I've written. Take a look — you can refine it by telling me what to change, or proceed when you're happy."}])}catch{c(I=>[...I,{role:"assistant",content:"Something went wrong generating the soul. Please try again."}])}finally{m(!1)}},[e.name,e.role,n,a,o]);async function E(){const T=d.trim();if(!T||p)return;f("");const F={role:"user",content:T};c(M=>[...M,F]),_?await C(T,T):await C(T)}const k=uh(e.color);return r.jsxs("div",{className:"flex gap-6 h-full min-h-0",children:[r.jsxs("div",{className:"flex flex-col w-[320px] flex-shrink-0 min-h-0",children:[r.jsxs("div",{className:"flex-1 overflow-y-auto space-y-3 pr-1 min-h-0",children:[l.length===0&&r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`rgba(${k}, 0.2)`},children:e.emoji}),r.jsx("div",{className:"flex-1 bg-[#1E1E24] rounded-xl rounded-tl-sm px-3 py-2.5",children:r.jsxs("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:["I'm going to write ",e.name,"'s soul. Describe their personality in a few sentences. What do they care about? What makes them distinct? What won't they do?"]})})]}),l.map((T,F)=>r.jsxs(ne.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:ye("flex items-start gap-3",T.role==="user"&&"flex-row-reverse"),children:[T.role==="assistant"&&r.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-sm flex-shrink-0 mt-0.5",style:{backgroundColor:`rgba(${k}, 0.2)`},children:e.emoji}),r.jsx("div",{className:ye("flex-1 rounded-xl px-3 py-2.5",T.role==="user"?"bg-[#6366F1]/15 rounded-tr-sm ml-8":"bg-[#1E1E24] rounded-tl-sm mr-8"),children:r.jsx("p",{className:"text-[13px] text-[#C8C8D4] leading-relaxed",children:T.content})})]},F)),p&&r.jsxs(ne.div,{initial:{opacity:0},animate:{opacity:1},className:"flex items-center gap-2 pl-10",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce [animation-delay:0.15s]"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#8A8A99] animate-bounce [animation-delay:0.3s]"})]}),r.jsx("div",{ref:A})]}),r.jsxs("div",{className:"mt-3 flex gap-2",children:[r.jsx("input",{ref:S,value:d,onChange:T=>f(T.target.value),onKeyDown:T=>T.key==="Enter"&&!T.shiftKey&&E(),placeholder:_?"Refine it…":"Describe their personality…",disabled:p,className:"flex-1 h-9 px-3 rounded-xl bg-[#1E1E24] border border-[#2A2A35] text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6A] focus:outline-none focus:border-[#6366F1] transition-colors disabled:opacity-50"}),r.jsx("button",{onClick:E,disabled:!d.trim()||p,className:"w-9 h-9 rounded-xl flex items-center justify-center transition-all disabled:opacity-30",style:{backgroundColor:`rgba(${k}, 0.2)`,color:e.color},children:p?r.jsx(Xi,{className:"w-4 h-4 animate-spin"}):r.jsx(Ji,{className:"w-4 h-4"})})]})]}),r.jsxs("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-[12px] font-medium text-[#8A8A99] uppercase tracking-wider",children:"SOUL.md preview"}),p&&r.jsx("p",{className:"text-[11px] text-[#8A8A99] animate-pulse",children:"Generating…"})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto bg-[#0F0F11] border border-[#2A2A35] rounded-xl p-4 min-h-0",children:[!t&&!g&&!p&&r.jsx("p",{className:"text-[13px] text-[#5A5A6A] italic",children:"The soul will appear here as it's generated…"}),(t||g)&&r.jsx("div",{className:"prose-message text-[12px] text-[#C8C8D4] leading-relaxed",children:r.jsx(Ei,{remarkPlugins:[Fi],children:g||t})})]}),r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 h-9 px-4 rounded-xl border border-[#2A2A35] text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] hover:border-[#3A3A45] transition-colors",children:[r.jsx(gm,{className:"w-4 h-4"}),"Back"]}),r.jsxs("button",{onClick:s,disabled:!t||p,className:"flex-1 h-9 rounded-xl bg-gradient-to-r from-[#6366F1] to-[#8B5CF6] text-white text-[13px] font-medium flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-30 disabled:cursor-not-allowed",children:["Looks good",r.jsx(tu,{className:"w-4 h-4"})]})]})]})]})}function oRe({title:e,content:t}){const[n,s]=y.useState(e==="SOUL.md");return r.jsxs("div",{className:"border border-[#2A2A35] rounded-xl overflow-hidden",children:[r.jsxs("button",{onClick:()=>s(i=>!i),className:"w-full flex items-center justify-between px-4 py-3 bg-[#1E1E24] hover:bg-[#2A2A35] transition-colors text-left",children:[r.jsx("span",{className:"text-[13px] font-mono font-medium text-[#C8C8D4]",children:e}),r.jsx(ne.span,{animate:{rotate:n?90:0},transition:{duration:.15},children:r.jsx(tu,{className:"w-3.5 h-3.5 text-[#8A8A99]"})})]}),r.jsx(Me,{children:n&&r.jsx(ne.div,{initial:{height:0},animate:{height:"auto"},exit:{height:0},transition:{duration:.2},className:"overflow-hidden",children:r.jsx("div",{className:"p-4 max-h-48 overflow-y-auto bg-[#0F0F11]",children:r.jsx("div",{className:"prose-message text-[12px] text-[#8A8A99]",children:r.jsx(Ei,{remarkPlugins:[Fi],children:t})})})})})]})}function lRe(e){return`# IDENTITY.md — ${e.name}
355
355
 
356
356
  - **Name:** ${e.name}
357
357
  - **Role:** ${e.role}
@@ -432,4 +432,4 @@ Any required environment variables or binaries.
432
432
  ${o.trim()}`:o.trim();f.mutate({id:e.id,description:m})}}return r.jsxs("div",{className:"px-6 pb-4 border-t border-[#1E1E28]/50",children:[e.description&&r.jsx("p",{className:"text-[12px] text-[#8A8A99] mt-3 mb-3",children:e.description}),r.jsx("div",{className:"mt-2 space-y-1",children:e.tasks.map(m=>r.jsx(CW,{task:m,missionId:e.id,missionTitle:e.title,agent:m.agent??(m.agentId?t[m.agentId]:null),agentChannel:m.agent??(m.agentId?t[m.agentId]:null)?s.find(g=>g.agentId===m.agentId&&g.channelType==="dm"):void 0},m.id))}),r.jsx(XDe,{missionId:e.id}),r.jsx(i8e,{missionId:e.id}),r.jsxs("div",{className:"flex items-center gap-2 mt-3",children:[r.jsx("input",{value:o,onChange:m=>l(m.target.value),onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),p())},placeholder:d.length>0?`Message all ${d.length} active agent${d.length!==1?"s":""}...`:"Add context to this mission...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded px-3 py-1.5 text-[12px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsx("button",{onClick:p,disabled:!o.trim()||c.isPending,className:"px-3 py-1.5 rounded bg-[#6366F1]/10 text-[#6366F1] text-[11px] font-medium hover:bg-[#6366F1]/20 transition-colors disabled:opacity-30",children:c.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Ji,{className:"w-3 h-3"})})]}),i&&a.length>0&&r.jsx("div",{className:"flex items-center gap-2 mt-2",children:r.jsxs("button",{onClick:n,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-[#6366F1]/10 text-[#6366F1] text-[12px] font-medium hover:bg-[#6366F1]/20 transition-colors",children:[r.jsx(Ji,{className:"w-3 h-3"}),"Dispatch ",a.length," ready task",a.length!==1?"s":""]})})]})}function XDe({missionId:e}){const{data:t}=L.missions.worktreeStatus.useQuery({missionId:e}),n=L.useUtils(),s=L.missions.mergeWorktree.useMutation({onSuccess:()=>{n.missions.worktreeStatus.invalidate({missionId:e}),n.missions.list.invalidate()}}),i=L.missions.discardWorktree.useMutation({onSuccess:()=>{n.missions.worktreeStatus.invalidate({missionId:e}),n.missions.list.invalidate()}});return t?r.jsxs("div",{className:"mt-3 flex items-center gap-2.5 px-3 py-2 rounded-md bg-[#13131A] border border-[#2A2A35]/50",children:[r.jsx(Zl,{className:"w-3.5 h-3.5 text-[#8B5CF6] flex-shrink-0"}),r.jsx("span",{className:"text-[12px] font-mono text-[#A78BFA]",children:t.branch}),t.fileCount>0&&r.jsxs("span",{className:"text-[10px] text-[#8A8A99]",children:[t.fileCount," file",t.fileCount!==1?"s":""," changed"]}),r.jsx("div",{className:"flex-1"}),r.jsxs("button",{onClick:()=>s.mutate({missionId:e}),disabled:s.isPending,className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] text-[#10B981] hover:bg-[#10B981]/10 transition-colors disabled:opacity-50",children:[s.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(D5,{className:"w-3 h-3"}),"Merge"]}),r.jsxs("button",{onClick:()=>i.mutate({missionId:e}),disabled:i.isPending,className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors disabled:opacity-50",children:[r.jsx(Dn,{className:"w-3 h-3"}),"Discard"]})]}):null}function JDe({missions:e,agentMap:t}){const{data:n=[]}=L.channels.list.useQuery(),s=L.useUtils(),i=L.missions.update.useMutation({onSuccess:()=>s.missions.list.invalidate()}),[a,o]=y.useState(null),l=[{status:"planning",label:"Planning"},{status:"active",label:"Active"},{status:"paused",label:"Paused"},{status:"completed",label:"Completed"}];function c(m){o(m.active.id)}const d=L.missions.reorderMissions.useMutation({onSuccess:()=>s.missions.list.invalidate()});function f(m){o(null);const{active:g,over:b}=m;if(!b||!g)return;const _=g.id,w=b.id,A=e.find(E=>E.id===_);if(!A)return;const S=l.map(E=>E.status);let C;if(S.includes(w))C=w;else{const E=e.find(k=>k.id===w);if(!E)return;C=E.status}if(A.status!==C){i.mutate({id:_,status:C});return}if(!S.includes(w)&&w!==_){const k=e.filter(I=>I.status===C).map(I=>I.id),T=k.indexOf(_),F=k.indexOf(w);if(T===-1||F===-1)return;const M=[...k];M.splice(T,1),M.splice(F,0,_),d.mutate({missionIds:M})}}const p=a?e.find(m=>m.id===a):null;return r.jsxs(vV,{collisionDetection:sV,onDragStart:c,onDragEnd:f,children:[r.jsx("div",{className:"flex-1 overflow-x-auto overflow-y-hidden",children:r.jsx("div",{className:"flex gap-4 px-6 py-4 h-full min-w-max",children:l.map(m=>{const g=e.filter(b=>b.status===m.status);return r.jsx(ZDe,{status:m.status,label:m.label,count:g.length,children:r.jsx(sN,{items:g.map(b=>b.id),strategy:SV,children:g.map(b=>r.jsx(e8e,{mission:b,agentMap:t,channels:n},b.id))})},m.status)})})}),r.jsx(wV,{children:p&&r.jsxs("div",{className:"w-[280px] bg-[#16161A] border border-[#6366F1]/40 rounded-lg p-3 shadow-2xl rotate-2 opacity-90",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:My[p.priority]}}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5] font-medium truncate",children:p.title})]}),r.jsxs("span",{className:"text-[10px] text-[#5A5A6E] mt-1 block",children:[p.tasks.length," tasks"]})]})})]})}function ZDe({status:e,label:t,count:n,children:s}){const{setNodeRef:i,isOver:a}=_V({id:e});return r.jsxs("div",{ref:i,className:ye("w-[300px] flex flex-col flex-shrink-0 rounded-lg transition-colors",a&&"bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20"),children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 mb-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:Qi[e]}}),r.jsx("span",{className:"text-[12px] font-medium text-[#8A8A99] uppercase tracking-wider",children:t}),r.jsx("span",{className:"text-[10px] text-[#3A3A45] ml-1",children:n})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 px-1 min-h-[60px]",children:[s,n===0&&r.jsx("div",{className:"flex items-center justify-center py-8 text-[#2A2A35]",children:r.jsx("span",{className:"text-[11px]",children:"Drop here"})})]})]})}function e8e({mission:e,agentMap:t,channels:n}){const{attributes:s,listeners:i,setNodeRef:a,transform:o,transition:l,isDragging:c}=iN({id:e.id}),d={transform:Oo.Transform.toString(o),transition:l},[f,p]=y.useState(""),[m,g]=y.useState(!1),b=L.messages.send.useMutation({onSuccess:()=>p("")}),_=L.missions.update.useMutation({onSuccess:()=>L.useUtils().missions.list.invalidate()}),w=e.priority,A=e.tasks.length,S=e.tasks.filter(F=>F.status==="completed").length,C=e.tasks.filter(F=>F.status==="working"||F.status==="dispatched").length,E=[...new Set(e.tasks.map(F=>F.agentId).filter(Boolean))].map(F=>t[F]??e.tasks.find(M=>M.agentId===F)?.agent).filter(Boolean),k=[...new Set(e.tasks.filter(F=>F.status==="working"||F.status==="dispatched"||F.status==="completed").map(F=>F.agentId).filter(Boolean))];function T(){if(f.trim())if(k.length>0){const F=`[Mission: ${e.title}] ${f.trim()}`;for(const M of k){const I=n.find(R=>R.agentId===M&&R.channelType==="dm");I&&b.mutate({channelId:I.id,content:F})}p("")}else{const F=e.description?`${e.description}
433
433
  ${f.trim()}`:f.trim();_.mutate({id:e.id,description:F}),p("")}}return r.jsxs("div",{ref:a,style:d,...s,className:ye("bg-[#16161A] border border-[#2A2A35] rounded-lg hover:border-[#3A3A45] transition-colors",c&&"opacity-40 ring-2 ring-[#6366F1]/30"),children:[r.jsxs("div",{...i,className:"flex items-start gap-2 p-3 pb-0 cursor-grab active:cursor-grabbing group/header",children:[r.jsx(dL,{className:"w-3 h-3 mt-0.5 text-[#2A2A35] group-hover/header:text-[#5A5A6E] transition-colors flex-shrink-0"}),r.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-1.5 flex-shrink-0",style:{backgroundColor:My[w]}}),r.jsx("span",{className:"text-[13px] text-[#F0F0F5] font-medium leading-tight flex-1",children:e.title}),e.ephemeralNodeId&&r.jsx("span",{className:"text-[8px] px-1 py-0.5 rounded bg-[#10B981]/15 text-[#10B981] font-medium uppercase tracking-wider flex-shrink-0",children:"ephemeral"})]}),r.jsxs("div",{className:"px-3 pb-3",children:[e.description&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-1 mb-2 line-clamp-2 pl-6",children:e.description}),A>0&&r.jsxs("div",{className:"space-y-1 mt-2 mb-2",children:[(m?e.tasks:e.tasks.slice(0,3)).map(F=>{const M=F.agent??(F.agentId?t[F.agentId]:null),I=M?n.find(R=>R.agentId===M.id&&R.channelType==="dm"):void 0;return r.jsx(CW,{task:F,missionId:e.id,missionTitle:e.title,agent:M,agentChannel:I,compact:!0},F.id)}),e.tasks.length>3&&r.jsx("button",{onClick:()=>g(!m),className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] pl-5 transition-colors",children:m?"Show less":`+${e.tasks.length-3} more`}),(()=>{const F=e.tasks.filter(M=>M.status==="completed"&&M.agentTasks?.some(I=>I.result));return F.length===0?null:r.jsxs("div",{className:"flex items-center gap-1 pl-5 mt-0.5",children:[r.jsx(Fe,{className:"w-2.5 h-2.5 text-[#10B981]"}),r.jsxs("span",{className:"text-[10px] text-[#10B981]",children:[F.length," result",F.length!==1?"s":""," available"]})]})})()]}),r.jsxs("div",{className:"flex items-center gap-1.5 mt-2",children:[r.jsx("input",{value:f,onChange:F=>p(F.target.value),onKeyDown:F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),T())},placeholder:k.length>0?`Message ${k.length} agent${k.length!==1?"s":""}...`:"Add context...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded px-2 py-1 text-[10px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsx("button",{onClick:T,disabled:!f.trim()||b.isPending,className:"p-1 rounded text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors disabled:opacity-30",children:b.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Ji,{className:"w-3 h-3"})})]}),r.jsxs("div",{className:"flex items-center gap-2 pt-2 mt-2 border-t border-[#2A2A35]/50",children:[r.jsx("div",{className:"flex -space-x-1",children:E.slice(0,3).map((F,M)=>F&&r.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[9px] border border-[#16161A]",style:{backgroundColor:F.color+"20",zIndex:3-M},children:F.emoji},F.id))}),r.jsx("div",{className:"flex-1"}),A>0&&r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("div",{className:"w-12 h-1 bg-[#1E1E28] rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full",style:{width:`${S/A*100}%`,backgroundColor:Qi[e.status]}})}),r.jsxs("span",{className:"text-[9px] text-[#5A5A6E] tabular-nums",children:[S,"/",A]})]}),C>0&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[9px] text-[#6366F1]",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-[#6366F1] animate-pulse"}),C]})]})]})]})}function t8e({missions:e,agentMap:t}){return r.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:e.map(n=>r.jsx(n8e,{mission:n,agentMap:t},n.id))})}function n8e({mission:e,agentMap:t}){const{data:n}=L.dashboard.timeline.useQuery({missionId:e.id}),s=e.status;return r.jsxs("div",{className:"mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:Qi[s]}}),r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:e.title}),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{color:Qi[s],backgroundColor:Qi[s]+"15"},children:nv[s]})]}),r.jsx("div",{className:"space-y-1 pl-4 border-l-2 border-[#2A2A35]",children:(n?.tasks??e.tasks).map(i=>{const a=i.agent??(i.agentId?t[i.agentId]:null),o=i.status;return r.jsxs("div",{className:"flex items-center gap-2 py-1",children:[r.jsx(jW,{status:i.status}),a&&r.jsx("span",{className:"text-[11px]",children:a.emoji}),r.jsx("span",{className:"text-[12px] text-[#C8C8D4] flex-1 truncate",children:i.title}),"startedAt"in i&&i.startedAt&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E] font-mono",children:new Date(i.startedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),"completedAt"in i&&i.completedAt&&r.jsxs("span",{className:"text-[10px] text-[#5A5A6E]",children:["→ ",new Date(i.completedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]}),r.jsx("span",{className:"text-[10px] px-1 py-0.5 rounded",style:{color:Qi[o]??"#8A8A99",backgroundColor:(Qi[o]??"#8A8A99")+"10"},children:i.status})]},i.id)})}),n?.events&&n.events.length>0&&r.jsx("div",{className:"mt-2 pl-4 space-y-0.5",children:n.events.slice(-8).map((i,a)=>r.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-[#5A5A6E]",children:[r.jsx("span",{className:"font-mono",children:new Date(i.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}),r.jsx("span",{className:ye(i.type.includes("completed")?"text-[#10B981]":i.type.includes("failed")?"text-[#EF4444]":i.type.includes("dispatched")?"text-[#6366F1]":"text-[#8A8A99]"),children:i.type.replace(/_/g," ")}),i.agentEmoji&&r.jsx("span",{children:i.agentEmoji}),i.taskTitle&&r.jsx("span",{className:"text-[#8A8A99] truncate",children:i.taskTitle}),i.detail&&r.jsxs("span",{className:"text-[#5A5A6E]",children:["(",i.detail,")"]})]},a))})]})}function s8e({agentId:e,onClose:t}){const{data:n}=L.dashboard.agentPerformance.useQuery({agentId:e}),{data:s=[]}=L.agents.list.useQuery(),i=s.find(o=>o.id===e);if(!n||!i)return null;const a=n.successRate!==null?Math.round(n.successRate*100):null;return r.jsxs(ne.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"absolute right-4 top-16 w-[280px] bg-[#16161A] border border-[#2A2A35] rounded-xl shadow-2xl z-30 overflow-hidden",children:[r.jsxs("div",{className:"px-4 py-3 border-b border-[#2A2A35] flex items-center gap-2",children:[r.jsx("span",{className:"w-7 h-7 rounded-full flex items-center justify-center text-[14px]",style:{backgroundColor:i.color+"20"},children:i.emoji}),r.jsxs("div",{className:"flex-1",children:[r.jsx("span",{className:"text-[13px] font-medium text-[#F0F0F5]",children:i.name}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:i.role})]}),r.jsx("button",{onClick:t,className:"text-[#5A5A6E] hover:text-[#C8C8D4]",children:r.jsx(Te,{className:"w-3.5 h-3.5"})})]}),r.jsxs("div",{className:"px-4 py-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:"Success rate"}),r.jsx("span",{className:ye("text-[13px] font-medium",a!==null&&a>=80?"text-[#10B981]":a!==null&&a>=50?"text-[#F59E0B]":"text-[#EF4444]"),children:a!==null?`${a}%`:"—"})]}),r.jsx("div",{className:"h-1.5 bg-[#1E1E28] rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${a??0}%`,backgroundColor:(a??0)>=80?"#10B981":(a??0)>=50?"#F59E0B":"#EF4444"}})}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg px-2.5 py-2",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:"Completed"}),r.jsx("span",{className:"text-[14px] font-medium text-[#F0F0F5]",children:n.delegationsCompleted})]}),r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg px-2.5 py-2",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:"Failed"}),r.jsx("span",{className:"text-[14px] font-medium text-[#EF4444]",children:n.delegationsFailed})]}),r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg px-2.5 py-2",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:"Avg time"}),r.jsx("span",{className:"text-[14px] font-medium text-[#F0F0F5]",children:n.avgCompletionMs?`${Math.round(n.avgCompletionMs/1e3)}s`:"—"})]}),r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg px-2.5 py-2",children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block",children:"Cost (7d)"}),r.jsxs("span",{className:"text-[14px] font-medium text-[#F0F0F5]",children:["$",n.costWeek.toFixed(2)]})]})]}),r.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Last dream"}),r.jsx("span",{className:"text-[#C8C8D4]",children:n.lastDreamAt?new Date(n.lastDreamAt).toLocaleDateString():"Never"})]}),n.dreamInsights>0&&r.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[r.jsx("span",{className:"text-[#8A8A99]",children:"Dream insights"}),r.jsxs("span",{className:"text-[#8B5CF6]",children:[n.dreamInsights," notes"]})]}),Object.keys(n.bySource).length>0&&r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block mb-1",children:"Sources (7d)"}),r.jsx("div",{className:"flex gap-2",children:Object.entries(n.bySource).map(([o,l])=>r.jsxs("span",{className:"text-[10px] text-[#8A8A99] bg-[#0F0F11] px-1.5 py-0.5 rounded",children:[o,": ",l.calls," calls · $",l.cost.toFixed(2)]},o))})]}),n.currentTasks.length>0&&r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-[#5A5A6E] block mb-1",children:"Active tasks"}),n.currentTasks.map(o=>r.jsx("div",{className:"text-[11px] text-[#C8C8D4] truncate py-0.5",children:o.task.slice(0,60)},o.id))]})]})]})}function i8e({missionId:e}){const{data:t}=L.files.listMissionDeliverables.useQuery({missionId:e}),n=t?.files??[];if(n.length===0)return null;const s={};for(const a of n)s[a.category]=(s[a.category]??0)+1;const i={structured:ym,code:rL,images:hL,documents:li};return r.jsx("div",{className:"mt-3 px-3 py-2 rounded-md bg-[#13131A] border border-[#2A2A35]/50",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(li,{className:"w-3.5 h-3.5 text-[#8A8A99] flex-shrink-0"}),r.jsxs("span",{className:"text-[12px] text-[#C8C8D4]",children:[n.length," deliverable",n.length!==1?"s":""]}),r.jsx("div",{className:"flex-1"}),r.jsx("div",{className:"flex items-center gap-2",children:Object.entries(s).map(([a,o])=>{const l=i[a]??li;return r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-[#5A5A6E]",children:[r.jsx(l,{className:"w-3 h-3"}),o]},a)})})]})})}function CW({task:e,missionId:t,missionTitle:n,agent:s,agentChannel:i,compact:a}){const o=an(),[l,c]=y.useState(!1),[d,f]=y.useState(""),p=e.status,m=L.useUtils(),g=L.missions.updateTask.useMutation({onSuccess:()=>{m.missions.list.invalidate(),f(""),c(!1)}}),b=L.messages.send.useMutation({onSuccess:()=>{f(""),c(!1)}});function _(){d.trim()&&(e.status==="pending"?g.mutate({missionTaskId:e.id,instruction:d.trim()}):i&&(e.status==="working"||e.status==="dispatched"||e.status==="completed")?b.mutate({channelId:i.id,content:`[Mission: ${n}] ${d.trim()}`}):e.status==="failed"&&e.agentId&&g.mutate({missionTaskId:e.id,instruction:d.trim(),status:"pending"}))}const w=e.status==="pending"?"Edit instruction before dispatch...":e.status==="failed"?"Fix instruction and retry...":e.status==="completed"?"Request revision...":"Send context to agent...",A=g.isPending||b.isPending;return r.jsxs("div",{className:"rounded-md bg-[#13131A]",children:[r.jsxs("div",{className:"flex items-center gap-2.5 py-1.5 px-3",children:[r.jsx(jW,{status:e.status}),r.jsx("button",{onClick:S=>{S.stopPropagation(),i&&o(`/channels/${i.id}`)},className:"text-[12px] text-[#C8C8D4] flex-1 truncate text-left hover:text-[#6366F1] transition-colors",title:i?"Open agent chat":e.title,children:e.title}),e.status==="completed"&&r.jsx("button",{onClick:S=>{S.stopPropagation(),o(`/deliverables?mission=${t}`)},className:"text-[#5A5A6E] hover:text-[#10B981] transition-colors",title:"View deliverables",children:r.jsx(lL,{className:"w-3 h-3"})}),r.jsx("button",{onClick:S=>{S.stopPropagation(),c(!l)},className:ye("transition-colors",l?"text-[#6366F1]":"text-[#3A3A45] hover:text-[#8A8A99]"),title:e.status==="pending"?"Edit instruction":e.status==="failed"?"Fix & retry":e.status==="completed"?"Request revision":"Send context to agent",children:r.jsx(Yse,{className:"w-3 h-3"})}),s&&r.jsxs("button",{onClick:S=>{S.stopPropagation(),i&&o(`/channels/${i.id}`)},className:"flex items-center gap-1 text-[11px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",title:`Open ${s.name}'s chat`,children:[r.jsx("span",{children:s.emoji}),!a&&r.jsx("span",{children:s.name})]}),!s&&e.status==="pending"&&!a&&r.jsx("span",{className:"text-[10px] text-[#5A5A6E] italic",children:"unassigned"}),!a&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{color:Qi[p]??"#8A8A99",backgroundColor:(Qi[p]??"#8A8A99")+"10"},children:e.status}),!a&&r.jsx(a8e,{taskId:e.id,status:e.status,missionId:t})]}),r.jsx(Me,{children:l&&r.jsx(ne.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:r.jsxs("div",{className:"flex items-center gap-2 px-3 pb-2 pt-1",children:[r.jsx("input",{autoFocus:!0,value:d,onChange:S=>f(S.target.value),onKeyDown:S=>{S.key==="Enter"&&!S.shiftKey&&(S.preventDefault(),_()),S.key==="Escape"&&c(!1)},placeholder:w,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded px-2.5 py-1.5 text-[11px] text-[#F0F0F5] placeholder-[#3A3A45] outline-none focus:border-[#6366F1]/40"}),r.jsx("button",{onClick:_,disabled:!d.trim()||A,className:"px-2 py-1.5 rounded bg-[#6366F1]/10 text-[#6366F1] hover:bg-[#6366F1]/20 transition-colors disabled:opacity-30",children:A?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Ji,{className:"w-3 h-3"})}),e.status==="failed"&&d.trim()&&r.jsx("button",{onClick:()=>{g.mutate({missionTaskId:e.id,instruction:d.trim(),status:"pending"})},disabled:A,className:"px-2 py-1.5 rounded bg-[#F59E0B]/10 text-[#F59E0B] text-[10px] hover:bg-[#F59E0B]/20 transition-colors disabled:opacity-30",children:"Retry"})]})})}),!a&&r.jsx(r8e,{task:e,agent:s})]})}function r8e({task:e,agent:t}){const[n,s]=y.useState(!1),i=e.agentTasks?.find(d=>d.status==="completed"||d.status==="failed"),a=i?.result;if(e.status!=="completed"||!a)return null;const o=a.split(`
434
434
  `),l=o.length>5,c=l&&!n?o.slice(0,5).join(`
435
- `):a;return r.jsxs("div",{className:"mx-3 mb-2 rounded-md bg-[#0F0F11] border border-[#2A2A35]/50 p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-[#8A8A99]",children:[r.jsx("span",{children:t.emoji}),r.jsx("span",{children:t.name})]}),i?.crossInstance&&i.federationNodeName&&r.jsxs("span",{className:"flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded bg-[#6366F1]/10 text-[#818CF8]",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),i.federationNodeName]}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:"Result"})]}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap break-words leading-relaxed font-mono",children:c}),l&&r.jsx("button",{onClick:()=>s(!n),className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] mt-1.5 transition-colors",children:n?"Collapse":`Show full result (${o.length} lines)`})]})}function a8e({taskId:e,status:t}){const[n,s]=y.useState(!1),i=L.useUtils(),a=L.missions.removeTask.useMutation({onSuccess:()=>{i.missions.list.invalidate(),s(!1)}}),o=L.missions.updateTask.useMutation({onSuccess:()=>{i.missions.list.invalidate(),s(!1)}});return r.jsxs("div",{className:"relative",children:[r.jsx("button",{onClick:l=>{l.stopPropagation(),s(!n)},className:"text-[#3A3A45] hover:text-[#8A8A99] transition-colors p-0.5",children:r.jsx(iL,{className:"w-3 h-3"})}),n&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>s(!1)}),r.jsxs("div",{className:"absolute right-0 top-5 z-30 bg-[#1A1A24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[140px]",children:[t==="pending"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),s(!1)},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#C8C8D4] hover:bg-white/5 transition-colors",children:"Edit instruction"}),(t==="working"||t==="dispatched")&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"cancelled"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#F59E0B] hover:bg-[#F59E0B]/10 transition-colors",children:"Cancel task"}),t==="failed"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"pending"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors",children:"Retry task"}),t==="completed"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"pending"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#8A8A99] hover:bg-white/5 transition-colors",children:"Re-open"}),r.jsx("button",{onClick:l=>{l.stopPropagation(),a.mutate({missionTaskId:e})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors",children:"Remove"})]})]})]})}function jW({status:e}){switch(e){case"completed":return r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"});case"failed":return r.jsx(Te,{className:"w-3.5 h-3.5 text-[#EF4444]"});case"working":case"dispatched":return r.jsx(Pe,{className:"w-3.5 h-3.5 text-[#6366F1] animate-spin"});case"review":return r.jsx(ql,{className:"w-3.5 h-3.5 text-[#F59E0B]"});case"cancelled":return r.jsx(Te,{className:"w-3.5 h-3.5 text-[#5A5A6E]"});default:return r.jsx("div",{className:"w-3.5 h-3.5 rounded-full border border-[#3A3A45]"})}}function o8e({open:e,onClose:t,onCreated:n}){const[s,i]=y.useState(""),[a,o]=y.useState(""),[l,c]=y.useState("normal"),d=L.missions.create.useMutation({onSuccess:()=>n()});return r.jsx(ji,{open:e,onOpenChange:f=>{f||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-50"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[460px] bg-[#16161A] border border-[#2A2A35] rounded-xl p-6 z-50 shadow-2xl",children:[r.jsx(nr,{className:"text-[15px] font-medium text-[#F0F0F5] mb-4",children:"New Mission"}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Title"}),r.jsx("input",{autoFocus:!0,value:s,onChange:f=>i(f.target.value),placeholder:"What needs to be done?",className:"w-full px-3 py-2 bg-[#0F0F11] border border-[#2A2A35] rounded-md text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] focus:outline-none focus:border-[#6366F1]",onKeyDown:f=>{f.key==="Enter"&&s.trim()&&d.mutate({title:s.trim(),description:a.trim()||void 0,priority:l})}})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Description"}),r.jsx("textarea",{value:a,onChange:f=>o(f.target.value),placeholder:"Optional details...",rows:3,className:"w-full px-3 py-2 bg-[#0F0F11] border border-[#2A2A35] rounded-md text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] focus:outline-none focus:border-[#6366F1] resize-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Priority"}),r.jsx("div",{className:"flex gap-2",children:["low","normal","high","critical"].map(f=>r.jsx("button",{onClick:()=>c(f),className:ye("px-3 py-1.5 rounded-md text-[12px] font-medium transition-colors",l===f?"text-white":"text-[#5A5A6E] bg-[#1E1E28] hover:text-[#8A8A99]"),style:l===f?{backgroundColor:My[f]}:void 0,children:SW[f]},f))})]})]}),r.jsxs("div",{className:"flex items-center justify-end gap-2 mt-5",children:[r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-md text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] transition-colors",children:"Cancel"})}),r.jsxs("button",{onClick:()=>{s.trim()&&d.mutate({title:s.trim(),description:a.trim()||void 0,priority:l})},disabled:!s.trim()||d.isPending,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-md bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E6] transition-colors disabled:opacity-50",children:[d.isPending&&r.jsx(Pe,{className:"w-3 h-3 animate-spin"}),"Create Mission"]})]})]})]})})}const l8e=4;function c8e({current:e}){return r.jsx("div",{className:"flex items-center gap-2",children:Array.from({length:l8e}).map((t,n)=>r.jsx("div",{className:ye("rounded-full transition-all duration-300",n<e?"w-2 h-2 bg-[#6366F1]":n===e?"w-6 h-2 bg-[#6366F1]":"w-2 h-2 bg-[#2A2A35]")},n))})}function Vd({children:e}){return r.jsx(ne.div,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:-24},transition:{duration:.22,ease:[.16,1,.3,1]},className:"w-full max-w-lg mx-auto",children:e})}function lO({onDetected:e,alreadyRunning:t}){const[n,s]=y.useState("."),i=L.onboarding.pollOpenClaw.useQuery(void 0,{refetchInterval:3e3,refetchOnWindowFocus:!1,retry:!1});return y.useEffect(()=>{t||i.data?.running&&e()},[i.data?.running]),y.useEffect(()=>{const a=setInterval(()=>s(o=>o.length>=3?".":o+"."),500);return()=>clearInterval(a)},[]),i.data?.running?r.jsxs("div",{className:"flex items-center gap-2 mt-4 text-[12px] text-emerald-400",children:[r.jsx(sa,{className:"w-3.5 h-3.5"}),"OpenClaw detected — advancing…"]}):r.jsxs("div",{className:"flex items-center gap-2 mt-4 text-[12px] text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),"Waiting for OpenClaw",n]})}function IC({code:e}){const[t,n]=y.useState(!1);function s(){navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)}return r.jsxs("div",{className:"flex items-center justify-between bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 font-mono text-[12px] text-[#C8C8D4]",children:[r.jsx("span",{children:e}),r.jsx("button",{onClick:s,className:ye("ml-3 flex-shrink-0 transition-colors",t?"text-emerald-400":"text-[#5A5A6E] hover:text-[#C8C8D4]"),children:t?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Po,{className:"w-3.5 h-3.5"})})]})}function u8e({onNext:e,onSkip:t}){const{data:n,isLoading:s}=L.onboarding.checkOpenClaw.useQuery(void 0,{refetchOnWindowFocus:!1,retry:!1}),i=L.onboarding.skipOpenClaw.useMutation(),[a,o]=y.useState(!1),[l,c]=y.useState("docker"),[d,f]=y.useState(void 0);n?.runMode&&n.runMode!==d&&(f(n.runMode),n.runMode==="docker"?c("npm"):n.runMode==="npm"&&c("docker"));const[p,m]=y.useState(""),[g,b]=y.useState(!1),[_,w]=y.useState(""),[A,S]=y.useState(""),[C,E]=y.useState("idle"),k=L.onboarding.saveWaitlistEmail.useMutation(),T=L.onboarding.testConnection.useMutation();if(s)return r.jsx(Vd,{children:r.jsxs("div",{className:"flex items-center gap-3 py-8",children:[r.jsx(Pe,{className:"w-4 h-4 animate-spin text-[#6366F1]"}),r.jsx("span",{className:"text-[14px] text-[#8A8A99]",children:"Checking OpenClaw…"})]})});async function F(){await i.mutateAsync(),t()}async function M(){if(!_.trim()||!A.trim())return;E("testing");const q=await T.mutateAsync({url:_.trim(),token:A.trim()});E(q.ok?"ok":"fail"),q.ok&&setTimeout(()=>e(),1e3)}async function I(){p.trim()&&(await k.mutateAsync({email:p.trim()}),b(!0))}const R=n?.running===!0,H=n?.runMode??null,K=[{id:"docker",label:"Docker",sub:"Agents run isolated",badge:"Recommended"},{id:"npm",label:"Local (npm)",sub:"Best for dedicated machines",badge:null},{id:"cloud",label:"Cloud (VPS)",sub:"Always-on, team access",badge:null}].filter(q=>q.id!==H);return R&&!a?r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Connect OpenClaw"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"damn.dev runs agents through OpenClaw, the local AI gateway."}),r.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-6",children:[r.jsx(sa,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("p",{className:"text-[13px] font-medium text-emerald-400",children:["OpenClaw detected",H==="docker"?" via Docker":H==="cloud"?" via Cloud":H==="npm"?" locally":""]}),(n.agentCount??0)>0&&r.jsxs("p",{className:"text-[11px] text-emerald-400/70",children:[n.agentCount," agent",n.agentCount!==1?"s":""," detected"]})]})]}),r.jsxs("button",{onClick:e,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] transition-colors mb-4",children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),r.jsx("button",{onClick:()=>o(!0),className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Want to connect to a different instance?"})]}):r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Connect OpenClaw"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"damn.dev runs agents through OpenClaw, the local AI gateway."}),R&&a&&r.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-4",children:[r.jsx(sa,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),r.jsx("div",{className:"flex-1",children:r.jsxs("p",{className:"text-[13px] font-medium text-emerald-400",children:["OpenClaw is running",H==="docker"?" via Docker":H==="cloud"?" via Cloud":H==="npm"?" locally":""]})}),r.jsxs("button",{onClick:e,className:"ml-auto flex items-center gap-1 text-[12px] font-medium text-emerald-400 hover:text-emerald-300 transition-colors flex-shrink-0",children:["Continue ",r.jsx(Jt,{className:"w-3 h-3"})]})]}),r.jsx("div",{className:ye("grid gap-3 mb-4",K.length===2?"grid-cols-2":"grid-cols-3"),children:K.map(q=>r.jsxs("button",{onClick:()=>c(q.id),className:ye("relative text-left rounded-2xl p-4 border transition-all",l===q.id?"border-[#6366F1]/50 bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] bg-[#16161A] hover:border-[#3A3A45]"),children:[q.badge&&r.jsx("span",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[9px] font-semibold bg-[#6366F1] text-white tracking-wide",children:q.badge}),r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mt-1",children:q.label}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:q.sub})]},q.id))}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 mb-4",children:[l==="docker"&&r.jsxs("div",{children:[r.jsxs("a",{href:"https://www.docker.com/products/docker-desktop/",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg border border-[#2A2A35] text-[13px] text-[#C8C8D4] hover:border-[#3A3A45] hover:text-[#F0F0F5] transition-colors mb-3",children:[r.jsx(cs,{className:"w-3.5 h-3.5"}),"Download Docker Desktop"]}),r.jsx("button",{onClick:()=>window.open("http://localhost:3001/setup/docker-compose.yml","_blank"),className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg bg-[#6366F1]/10 border border-[#6366F1]/30 text-[13px] text-[#6366F1] hover:bg-[#6366F1]/20 transition-colors mb-4",children:"Download docker-compose.yml"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] leading-relaxed",children:"Open Docker Desktop → Compose → Open File → Run"}),r.jsx(lO,{onDetected:e,alreadyRunning:R})]}),l==="npm"&&r.jsxs("div",{children:[r.jsxs("div",{className:"space-y-2 mb-4",children:[r.jsx(IC,{code:"npm install -g openclaw"}),r.jsx(IC,{code:"openclaw start"})]}),r.jsx(lO,{onDetected:e,alreadyRunning:R})]}),l==="cloud"&&r.jsxs("div",{className:"space-y-5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4] mb-1",children:"Want OpenClaw fully managed in the cloud?"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mb-3",children:"Join the waitlist for cloud.damn.dev."}),g?r.jsx("p",{className:"text-[12px] text-emerald-400",children:"You're on the list. We'll notify you when cloud.damn.dev launches."}):r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"email",value:p,onChange:q=>m(q.target.value),placeholder:"you@example.com",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:I,disabled:!p.trim()||k.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:k.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):"Join waitlist"})]})]}),r.jsxs("div",{className:"border-t border-[#2A2A35] pt-5",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4] mb-3",children:"Already running on a VPS?"}),r.jsxs("div",{className:"space-y-2 mb-3",children:[r.jsx("input",{type:"url",value:_,onChange:q=>{w(q.target.value),E("idle")},placeholder:"https://openclaw.myserver.com",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("input",{type:"password",value:A,onChange:q=>{S(q.target.value),E("idle")},placeholder:"Bearer token",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"})]}),r.jsxs("button",{onClick:M,disabled:!_.trim()||!A.trim()||C==="testing"||C==="ok",className:"flex items-center gap-2 px-4 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors",children:[C==="testing"&&r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),C==="ok"&&r.jsx(Fe,{className:"w-3.5 h-3.5 text-emerald-400"}),C==="fail"&&r.jsx(Te,{className:"w-3.5 h-3.5 text-red-400"}),C==="ok"?"Connected":"Test connection"]})]})]})]}),r.jsx("button",{onClick:F,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"I'll connect OpenClaw later →"})]})}function d8e({onDetected:e}){const[t,n]=y.useState("."),s=L.onboarding.pollOllama.useQuery(void 0,{refetchInterval:3e3,refetchOnWindowFocus:!1,retry:!1});return y.useEffect(()=>{s.data?.running&&s.data.models.length>0&&e(s.data.models)},[s.data?.running]),y.useEffect(()=>{const i=setInterval(()=>n(a=>a.length>=3?".":a+"."),500);return()=>clearInterval(i)},[]),s.data?.running?r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[12px] text-emerald-400",children:[r.jsx(sa,{className:"w-3.5 h-3.5"}),"Ollama detected"]}):r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[12px] text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),"Waiting for Ollama",t]})}function h8e({onNext:e,onSkip:t}){const[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(""),[f,p]=y.useState(null),[m,g]=y.useState(null),[b,_]=y.useState(!1),[w,A]=y.useState(null),[S,C]=y.useState(null),[E,k]=y.useState(""),[T,F]=y.useState(""),[M,I]=y.useState(""),[R,H]=y.useState(""),[V,K]=y.useState([]),[q,$]=y.useState(!1),B=y.useRef(null),{data:Y,isLoading:U}=L.onboarding.checkModels.useQuery(void 0,{refetchOnWindowFocus:!1,retry:!1}),{data:W}=L.onboarding.getState.useQuery(void 0,{refetchOnWindowFocus:!1});y.useEffect(()=>{Y?.envOpenRouterConfigured&&!w&&(A({valid:!0,modelCount:Y.openRouterModelCount??0,suggestedReasoningModel:W?.defaultReasoningModel??null,suggestedFastModel:W?.defaultFastModel??null}),s("sk-or-v1-••••••••••••••••••••••••••••••••"),W?.defaultReasoningModel&&!E&&k(W.defaultReasoningModel),W?.defaultFastModel&&!T&&F(W.defaultFastModel)),(Y?.ollamaModels?.length??0)>0&&K(Y.ollamaModels)},[Y?.envOpenRouterConfigured,Y?.ollamaModels?.length,W?.defaultReasoningModel]);const O=L.onboarding.validateApiKey.useMutation(),D=L.onboarding.setDefaultModels.useMutation();function Q(me){me.suggestedReasoningModel&&!E&&k(me.suggestedReasoningModel),me.suggestedFastModel&&!T&&F(me.suggestedFastModel)}async function z(){if(!n.trim())return;const me=await O.mutateAsync({provider:"openrouter",key:n.trim()});A(me),me.valid&&Q(me)}async function J(){if(!i.trim())return;const me=await O.mutateAsync({provider:"anthropic",key:i.trim()});C(me),me.valid&&Q(me)}async function ee(){if(!o.trim())return;const me=await O.mutateAsync({provider:"openai",key:o.trim()});p(me),me.valid&&Q(me)}async function re(){if(!c.trim())return;const me=await O.mutateAsync({provider:"gemini",key:c.trim()});g(me),me.valid&&Q(me)}const oe=V.length>0,se=oe||w?.valid===!0||S?.valid===!0||f?.valid===!0||m?.valid===!0||Y?.envOpenRouterConfigured===!0,ae=[];if(oe)for(const me of V)ae.push({id:me,label:me,group:"Ollama"});if(w?.valid){const me=[{id:"anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6"},{id:"anthropic/claude-opus-4.6",label:"Claude Opus 4.6"},{id:"anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5"},{id:"openai/gpt-4o",label:"GPT-4o"},{id:"openai/gpt-4o-mini",label:"GPT-4o mini"},{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"meta-llama/llama-3.3-70b-instruct:free",label:"Llama 3.3 70B (free)"}];for(const $e of me)ae.push({...$e,group:"OpenRouter"})}if(S?.valid){const me=[{id:"anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6"},{id:"anthropic/claude-opus-4.6",label:"Claude Opus 4.6"},{id:"anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"Anthropic"})}if(f?.valid){const me=[{id:"openai/gpt-4o",label:"GPT-4o"},{id:"openai/gpt-4o-mini",label:"GPT-4o mini"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"OpenAI"})}if(m?.valid){const me=[{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"Google"})}const le=se&&ae.length>0,je=(Y?.ramGb??0)>=8,Ee=Y?.recommendedLocalModel??null,de=Y?.recommendedModelSize??null;return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-1",children:"Configure models"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-4 leading-relaxed",children:"Connect at least one model source for your agents to use."}),r.jsxs("div",{className:"space-y-2.5 mb-4",children:[r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Ollama (local)"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mt-0.5",children:"Free, runs on your machine"})]}),U?r.jsx("div",{className:"w-4 h-4 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):oe?r.jsxs("span",{className:"text-[11px] text-emerald-400 font-medium",children:[V.length," model",V.length!==1?"s":""]}):r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"Not detected"})]}),oe?r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[V.slice(0,6).map(me=>r.jsx("span",{className:"px-2 py-0.5 rounded-md text-[11px] font-medium bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:me},me)),V.length>6&&r.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[11px] text-[#8A8A99]",children:["+",V.length-6," more"]})]}):!U&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"rounded-xl border border-[#2A2A35] bg-[#0F0F11] p-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4]",children:"Get started with OpenRouter"}),r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-semibold bg-[#6366F1]/15 text-[#6366F1] border border-[#6366F1]/20",children:"No install needed"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mb-2",children:"Free models available. The fastest way to get running."}),r.jsx("button",{onClick:()=>B.current?.focus(),className:"text-[12px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Go to OpenRouter section ↓"})]}),r.jsx("button",{onClick:()=>$(me=>!me),className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:q?"Hide local install ↑":"Prefer fully local? →"}),q&&r.jsx("div",{className:"rounded-xl border border-[#2A2A35] bg-[#0F0F11] p-3 space-y-3",children:je?r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://ollama.com",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg border border-[#2A2A35] text-[13px] text-[#C8C8D4] hover:border-[#3A3A45] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(cs,{className:"w-3.5 h-3.5"}),"Download Ollama"]}),Ee&&r.jsxs("div",{className:"space-y-1.5",children:[r.jsx(IC,{code:`ollama pull ${Ee}`}),de&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:de})]}),r.jsx(d8e,{onDetected:me=>K(me)})]}):r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Local models require at least 8GB RAM. We recommend OpenRouter instead."})})]})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"OpenRouter"}),Y?.envOpenRouterConfigured&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-emerald-400",children:[r.jsx(Fe,{className:"w-3 h-3"})," Configured via .env"]})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Access 200+ models via one API key"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:n,onChange:me=>{s(me.target.value),A(null)},placeholder:"sk-or-v1-...",ref:B,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:z,disabled:!n.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),w&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",w.valid?"text-emerald-400":"text-red-400"),children:[w.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),w.valid?`Valid — ${w.modelCount} models available`:"Invalid key"]}),w?.valid&&w.suggestedReasoningModel&&r.jsx("div",{className:"mt-3 pt-3 border-t border-[#2A2A35]",children:r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-1",children:"Models available via OpenRouter"})})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Anthropic"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Claude models (Haiku, Sonnet, Opus)"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:i,onChange:me=>{a(me.target.value),C(null)},placeholder:"sk-ant-...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:J,disabled:!i.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),S&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",S.valid?"text-emerald-400":"text-red-400"),children:[S.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),S.valid?"Valid":"Invalid key"]})]}),r.jsxs("button",{onClick:()=>_(me=>!me),className:"flex items-center gap-1.5 text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors w-full py-0.5",children:[r.jsx("span",{children:b?"↑ Hide":"↓ More providers"}),r.jsx("span",{className:"text-[#3A3A45]",children:"(OpenAI, Gemini)"})]}),b&&r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"OpenAI"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"GPT-4o, o1, o3-mini"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:o,onChange:me=>{l(me.target.value),p(null)},placeholder:"sk-...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:ee,disabled:!o.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),f&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",f.valid?"text-emerald-400":"text-red-400"),children:[f.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),f.valid?"Valid":"Invalid key"]})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Google Gemini"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Gemini 2.0, Flash, Pro"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:c,onChange:me=>{d(me.target.value),g(null)},placeholder:"AIza...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:re,disabled:!c.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),m&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",m.valid?"text-emerald-400":"text-red-400"),children:[m.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),m.valid?"Valid":"Invalid key"]})]})]})]}),le&&r.jsxs("div",{className:"bg-[#16161A] border border-[#6366F1]/20 rounded-2xl p-4 mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Default models"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-3",children:"Pre-selected for you. Change anytime in Settings."}),r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Primary (reasoning)"}),r.jsxs(ss,{value:E,onValueChange:me=>{k(me),I("")},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#0F0F11] text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/50 transition-colors",children:[r.jsx("span",{className:"truncate",children:(ae.find(me=>me.id===E)?.label??E)||"Select model..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[280px] max-h-[240px] z-[9999]",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx("input",{value:M,onChange:me=>I(me.target.value),onKeyDown:me=>{me.key==="Enter"&&M.trim()&&k(M.trim())},placeholder:"Type model ID...",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded px-2 py-1.5 text-[11px] text-[#C8C8D4] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] transition-colors"})}),r.jsx(os,{children:Object.entries(ae.reduce((me,$e)=>((me[$e.group]??=[]).push($e),me),{})).map(([me,$e])=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:me}),$e.map(nt=>r.jsxs(vn,{value:nt.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:nt.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},nt.id))]},me))})]})})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Fast (quick tasks)"}),r.jsxs(ss,{value:T,onValueChange:me=>{F(me),H("")},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#0F0F11] text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/50 transition-colors",children:[r.jsx("span",{className:"truncate",children:(ae.find(me=>me.id===T)?.label??T)||"Select model..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[280px] max-h-[240px] z-[9999]",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx("input",{value:R,onChange:me=>H(me.target.value),onKeyDown:me=>{me.key==="Enter"&&R.trim()&&F(R.trim())},placeholder:"Type model ID...",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded px-2 py-1.5 text-[11px] text-[#C8C8D4] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] transition-colors"})}),r.jsx(os,{children:Object.entries(ae.reduce((me,$e)=>((me[$e.group]??=[]).push($e),me),{})).map(([me,$e])=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:me}),$e.map(nt=>r.jsxs(vn,{value:nt.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:nt.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},nt.id))]},me))})]})})]})]})]})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[r.jsx("button",{onClick:async()=>{E&&T&&await D.mutateAsync({reasoningModel:E,fastModel:T}),e()},disabled:!se||D.isPending,className:ye("flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium transition-colors",se?"bg-[#6366F1] text-white hover:bg-[#5254CC]":"bg-white/5 text-[#5A5A6E] border border-[#2A2A35] cursor-not-allowed"),children:D.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}):r.jsxs(r.Fragment,{children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]})}),r.jsx("button",{onClick:t,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip for now"})]})]})}function f8e({onNext:e}){const[t,n]=y.useState(null);return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Share your workspace"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"How will you use damn.dev?"}),r.jsx("div",{className:"grid grid-cols-2 gap-3 mb-6",children:["solo","team"].map(s=>r.jsxs("button",{onClick:()=>n(s),className:ye("text-left rounded-2xl p-4 border transition-all",t===s?"border-[#6366F1]/50 bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] bg-[#16161A] hover:border-[#3A3A45]"),children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mt-1",children:s==="solo"?"Just me":"With my team"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:s==="solo"?"Default":"Share access via Tailscale"})]},s))}),t==="team"&&r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 mb-6",children:r.jsx(V5,{onComplete:()=>e(),onSkip:e})}),t!=="team"&&r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("button",{onClick:e,disabled:t===null,className:ye("flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium transition-colors",t!==null?"bg-[#6366F1] text-white hover:bg-[#5254CC]":"bg-white/5 text-[#5A5A6E] border border-[#2A2A35] cursor-not-allowed"),children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),r.jsx("button",{onClick:e,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip"})]})]})}function p8e({onComplete:e}){const t=an(),n=L.useUtils(),s=L.onboarding.complete.useMutation(),i=L.onboarding.cooOnboardingChat.useMutation(),a=L.onboarding.setWorkspaceContext.useMutation(),[o,l]=y.useState([]),[c,d]=y.useState(""),[f,p]=y.useState(null),[m,g]=y.useState(!1),[b,_]=y.useState(!0),[w,A]=y.useState(null),S=y.useRef(null),C=y.useRef(null);y.useEffect(()=>{let M=!1;return i.mutateAsync({message:"Hello",history:[]}).then(I=>{M||(l([{role:"assistant",content:I.reply}]),_(!1))}).catch(()=>{M||(_(!1),A("Could not reach COO. You can skip this step and set workspace context later."))}),()=>{M=!0}},[]),y.useEffect(()=>{S.current?.scrollTo({top:S.current.scrollHeight,behavior:"smooth"})},[o,f]);async function E(){const M=c.trim();if(!M||i.isPending)return;d(""),A(null);const I=[...o,{role:"user",content:M}];l(I);try{const R=await i.mutateAsync({message:M,history:I});l([...I,{role:"assistant",content:R.reply}]),R.workspaceContext&&p(R.workspaceContext)}catch{A("COO failed to respond. Try again or skip this step.")}C.current?.focus()}async function k(){f&&(await a.mutateAsync({context:f}),g(!0))}async function T(){await s.mutateAsync(),await n.onboarding.getState.refetch(),t("/channels/chan_coo",{replace:!0}),e()}async function F(){await s.mutateAsync(),await n.onboarding.getState.refetch(),t("/channels/chan_coo",{replace:!0}),e()}return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-1",children:"Meet your COO"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-4 leading-relaxed",children:"A few questions to set up your workspace context."}),r.jsxs("div",{ref:S,className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4 mb-3 space-y-3 max-h-[320px] overflow-y-auto",children:[b&&r.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-[#5A5A6E]",children:[r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),"COO is thinking..."]}),w&&r.jsx("div",{className:"text-[13px] text-red-400/80 leading-relaxed",children:w}),o.map((M,I)=>r.jsx("div",{className:ye("flex",M.role==="user"?"justify-end":"justify-start"),children:r.jsx("div",{className:ye("rounded-xl px-3 py-2 text-[13px] leading-relaxed max-w-[85%]",M.role==="user"?"bg-[#6366F1] text-white":"bg-[#1E1E28] text-[#C8C8D4] border border-[#2A2A35]"),children:M.content})},I)),i.isPending&&o.length>0&&r.jsx("div",{className:"flex justify-start",children:r.jsx("div",{className:"rounded-xl px-3 py-2 bg-[#1E1E28] border border-[#2A2A35]",children:r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin text-[#5A5A6E]"})})})]}),f&&!m&&r.jsxs("div",{className:"bg-[#0F0F11] border border-[#6366F1]/30 rounded-xl p-3 mb-3",children:[r.jsx("p",{className:"text-[11px] font-medium text-[#6366F1] mb-2",children:"Proposed workspace context"}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap leading-relaxed max-h-[160px] overflow-y-auto mb-2",children:f}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{onClick:k,disabled:a.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Fe,{className:"w-3 h-3"}),"Approve"]}),r.jsx("button",{onClick:()=>p(null),className:"px-3 py-1.5 rounded-lg text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Revise"})]})]}),m&&r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-3",children:[r.jsx(sa,{className:"w-3.5 h-3.5 text-emerald-400"}),r.jsx("span",{className:"text-[12px] text-emerald-400",children:"Workspace context saved"})]}),!m&&!b&&r.jsxs("div",{className:"flex gap-2 mb-3",children:[r.jsx("input",{ref:C,type:"text",value:c,onChange:M=>d(M.target.value),onKeyDown:M=>M.key==="Enter"&&E(),placeholder:"Type your answer...",disabled:i.isPending,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors disabled:opacity-50"}),r.jsx("button",{onClick:E,disabled:!c.trim()||i.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-50 transition-colors flex-shrink-0",children:"Send"})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[m&&r.jsxs("button",{onClick:T,disabled:s.isPending,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[s.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):null,"Open damn.dev",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),!m&&r.jsx("button",{onClick:F,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip this step"})]})]})}function m8e(){const e=an(),[t,n]=y.useState(0),s=L.onboarding.skip.useMutation();async function i(){await s.mutateAsync(),e("/",{replace:!0})}return r.jsx("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col items-center justify-center",children:r.jsxs("div",{className:"w-full max-w-lg px-6 flex flex-col",style:{maxHeight:"100vh"},children:[r.jsxs("div",{className:"flex items-center justify-between mb-8 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[18px]",children:"⚡"}),r.jsx("span",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"damn.dev"})]}),r.jsx(c8e,{current:t}),r.jsx("button",{onClick:i,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip setup"})]}),r.jsx("div",{className:"overflow-y-auto flex-1 pb-6",children:r.jsxs(Me,{mode:"wait",children:[t===0&&r.jsx(u8e,{onNext:()=>n(1),onSkip:()=>n(1)},"step0"),t===1&&r.jsx(h8e,{onNext:()=>n(2),onSkip:()=>n(2)},"step1"),t===2&&r.jsx(f8e,{onNext:()=>n(3)},"step2"),t===3&&r.jsx(p8e,{onComplete:()=>{}},"step3")]})})]})})}function x8e(){const e=an(),{data:t}=L.workspace.getMyMembership.useQuery(),{data:n=[]}=L.channels.list.useQuery(),s=L.workspace.completeOnboarding.useMutation();async function i(){await s.mutateAsync();const a=n.find(o=>o.name==="general"&&o.visibility==="public"&&o.channelType==="topic");e(a?`/channels/${a.id}`:"/channels/direction",{replace:!0})}return r.jsx("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col items-center justify-center",children:r.jsxs(ne.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,ease:[.16,1,.3,1]},className:"w-full max-w-md px-6 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mx-auto mb-6",children:r.jsx("span",{className:"text-3xl",children:"👋"})}),r.jsxs("h1",{className:"text-[24px] font-semibold text-[#F0F0F5] mb-3",children:["Welcome to ",t?.workspaceName??"the workspace"]}),t?.ownerName&&r.jsxs("p",{className:"text-[14px] text-[#8A8A99] mb-8 leading-relaxed",children:["You've been invited by ",t.ownerName]}),r.jsxs("button",{onClick:i,disabled:s.isPending,className:"inline-flex items-center gap-2 px-6 py-3 rounded-xl text-[14px] font-semibold bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[s.isPending?r.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):null,"Explore your workspace",r.jsx(Jt,{className:"w-4 h-4"})]})]})})}function g8e(){const[e,t]=y.useState("signin"),[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(!1),[c,d]=y.useState(null),[f,p]=y.useState(!1),{data:m}=L.onboarding.hasGoogleAuth.useQuery(),{data:g}=L.onboarding.signupAllowed.useQuery(),b=g?.allowed??!1,_=g?.registrationMode??"closed";y.useEffect(()=>{!b&&e==="signup"&&t("signin")},[b,e]);async function w(A){if(A.preventDefault(),d(null),e==="signup"&&!b){d("This workspace requires an invitation to join.");return}if(i.length<12){d("Password must be at least 12 characters.");return}p(!0);try{if(e==="signup"){const S=await cz.email({email:n,password:i,name:n.split("@")[0]});S.error&&d(S.error.message??"Sign up failed.")}else{const S=await v0.email({email:n,password:i});S.error&&d(S.error.message??"Invalid credentials.")}}catch{d("Something went wrong. Please try again.")}finally{p(!1)}}return r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-6 max-w-sm w-full px-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center",children:r.jsx("span",{className:"text-2xl font-bold text-[#6366F1]",children:"d"})}),r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"damn.dev"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:e==="signin"?"Sign in to your workspace":"Create your workspace"})]}),r.jsxs("form",{onSubmit:w,className:"flex flex-col gap-3 w-full",children:[r.jsx("input",{type:"email",placeholder:"Email",value:n,onChange:A=>s(A.target.value),required:!0,className:"w-full rounded-lg bg-[#1A1A20] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:o?"text":"password",placeholder:"Password (min 12 characters)",value:i,onChange:A=>a(A.target.value),required:!0,minLength:12,className:"w-full rounded-lg bg-[#1A1A20] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 pr-11 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("button",{type:"button",onClick:()=>l(A=>!A),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#5A5A6A] hover:text-[#8A8A99] transition-colors",tabIndex:-1,children:o?r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 4.411m0 0L21 21"})}):r.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]}),c&&r.jsx("p",{className:"text-[13px] text-red-400",children:c}),r.jsx("button",{type:"submit",disabled:f,className:"w-full rounded-lg bg-[#6366F1] text-white px-5 py-3 text-[14px] font-medium hover:bg-[#5254CC] disabled:opacity-50 transition-colors",children:f?"...":e==="signin"?"Sign in":"Create account"})]}),b?r.jsx("button",{type:"button",onClick:()=>{t(e==="signin"?"signup":"signin"),d(null)},className:"text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:e==="signin"?"Don't have an account? Create one":"Already have an account? Sign in"}):_==="invite"?r.jsx("p",{className:"text-[13px] text-[#5A5A6E] text-center",children:"Need an account? Ask the workspace admin for an invite link."}):r.jsx("p",{className:"text-[13px] text-[#5A5A6E] text-center",children:"Registration is closed."}),m?.enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-3 w-full",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6A]",children:"or"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),r.jsxs("button",{onClick:()=>v0.social({provider:"google",callbackURL:window.location.origin+"/"}),className:"flex items-center gap-3 w-full justify-center rounded-lg bg-white text-[#1a1a1a] px-5 py-3 text-[14px] font-medium hover:bg-[#f0f0f0] transition-colors",children:[r.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continue with Google"]})]})]})})}function b8e(e){if(!e||typeof e!="object")return!1;const t=String(e.message??"");return t.includes("Failed to fetch")||t.includes("NetworkError")||t.includes("ERR_CONNECTION_REFUSED")||t.includes("ECONNREFUSED")||t.includes("Load failed")||t.includes("fetch failed")}function v8e(){const[e,t]=y.useState(!1);function n(){t(!0),setTimeout(()=>window.location.reload(),500)}return r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-5 max-w-md text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-amber-500/10 border border-amber-500/20 flex items-center justify-center",children:r.jsx("span",{className:"text-amber-400 text-xl",children:"!"})}),r.jsx("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:"Can't reach this workspace"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] leading-relaxed",children:"This is a private workspace running on someone's machine. You need to be on their private network to access it."}),r.jsxs("div",{className:"w-full bg-[#16161A] border border-[#2A2A35] rounded-xl p-5 text-left space-y-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4]",children:"If they shared a Tailscale link:"}),r.jsxs("div",{className:"space-y-2 text-[12px] text-[#8A8A99]",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"1."}),r.jsxs("div",{children:["Install Tailscale on your device",r.jsxs("a",{href:"https://tailscale.com/download",target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 mt-1 text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(cs,{className:"w-3 h-3"}),"tailscale.com/download"]})]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"2."}),r.jsx("span",{children:"Ask them to add you to their Tailnet at tailscale.com/admin"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"3."}),r.jsx("span",{children:"Once connected, refresh this page"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Already have Tailscale? Make sure it's running and you're on the same Tailnet as the workspace host."})]}),r.jsxs("button",{onClick:n,disabled:e,className:"flex items-center gap-2 px-4 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 transition-colors disabled:opacity-50",children:[r.jsx(Xi,{className:`w-3.5 h-3.5 ${e?"animate-spin":""}`}),"Retry connection"]})]})})}function y8e(){const{token:e}=am(),t=an(),{data:n}=Mi(),[s,i]=y.useState("signup"),[a,o]=y.useState(""),[l,c]=y.useState(""),[d,f]=y.useState(null),[p,m]=y.useState(!1),{data:g,isLoading:b,error:_}=L.workspace.getInvitation.useQuery({token:e},{enabled:!!e,retry:!1}),w=L.workspace.acceptInvitation.useMutation({onSuccess:()=>{setTimeout(()=>t("/"),2e3)}});y.useEffect(()=>{if(w.isSuccess){const S=setTimeout(()=>t("/"),2e3);return()=>clearTimeout(S)}},[w.isSuccess,t]);async function A(S){if(S.preventDefault(),f(null),l.length<12){f("Password must be at least 12 characters.");return}m(!0);try{if(s==="signup"){const C=await cz.email({email:a,password:l,name:a.split("@")[0],fetchOptions:{headers:{"x-invite-token":e}}});C.error&&f(C.error.message??"Sign up failed.")}else{const C=await v0.email({email:a,password:l});C.error&&f(C.error.message??"Invalid credentials.")}}catch{f("Something went wrong. Please try again.")}finally{m(!1)}}return b?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):_&&b8e(_)?r.jsx(v8e,{}):_||!g?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-[#EF4444]/10 border border-[#EF4444]/20 flex items-center justify-center",children:r.jsx("span",{className:"text-[#EF4444] text-xl",children:"✕"})}),r.jsx("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:"Invitation not valid"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:"This invitation is no longer valid or has expired."}),r.jsx(gn,{to:"/",className:"text-[13px] text-[#6366F1] hover:underline",children:"Go to workspace"})]})}):w.isSuccess?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-[#10B981]/10 border border-[#10B981]/20 flex items-center justify-center",children:r.jsx("span",{className:"text-[#10B981] text-xl",children:"✓"})}),r.jsxs("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:["You've joined ",g.workspaceName,"!"]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Redirecting you to your workspace..."}),r.jsx("div",{className:"w-4 h-4 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})]})}):r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"w-[400px] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl p-8 flex flex-col items-center gap-5",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center",children:r.jsx("span",{className:"text-2xl font-bold text-[#6366F1]",children:"d"})}),r.jsxs("div",{className:"text-center",children:[r.jsx("h1",{className:"text-[20px] font-semibold text-[#F0F0F5]",children:g.workspaceName}),r.jsxs("p",{className:"text-[13px] text-[#8A8A99] mt-1",children:[g.inviterName," invited you to join as"," ",r.jsx("span",{className:"text-[#C8C8D4]",children:g.role})]})]}),w.error&&r.jsx("p",{className:"text-[12px] text-[#EF4444] text-center",children:w.error.message}),n?r.jsx("button",{onClick:()=>w.mutate({token:e}),disabled:w.isPending,className:"w-full px-4 py-2.5 rounded-lg bg-[#6366F1] text-white text-[14px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:w.isPending?"Joining...":"Join Workspace"}):r.jsxs("div",{className:"w-full flex flex-col gap-3",children:[r.jsxs("form",{onSubmit:A,className:"flex flex-col gap-3 w-full",children:[r.jsx("input",{type:"email",placeholder:"Email",value:a,onChange:S=>o(S.target.value),required:!0,className:"w-full rounded-lg bg-[#13131A] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("input",{type:"password",placeholder:"Password (min 12 characters)",value:l,onChange:S=>c(S.target.value),required:!0,minLength:12,className:"w-full rounded-lg bg-[#13131A] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),d&&r.jsx("p",{className:"text-[12px] text-red-400",children:d}),r.jsx("button",{type:"submit",disabled:p,className:"w-full rounded-lg bg-[#6366F1] text-white px-5 py-3 text-[14px] font-medium hover:bg-[#5254CC] disabled:opacity-50 transition-colors",children:p?"...":s==="signup"?"Create account & join":"Sign in & join"})]}),r.jsx("button",{type:"button",onClick:()=>{i(s==="signin"?"signup":"signin"),f(null)},className:"text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:s==="signup"?"Already have an account? Sign in":"Don't have an account? Create one"}),r.jsxs("div",{className:"flex items-center gap-3 w-full",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6A]",children:"or"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),r.jsxs("button",{onClick:()=>v0.social({provider:"google",callbackURL:`${window.location.origin}/invite/${e}`}),className:"flex items-center gap-3 w-full justify-center rounded-lg bg-white text-[#1a1a1a] px-5 py-3 text-[14px] font-medium hover:bg-[#f0f0f0] transition-colors",children:[r.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continue with Google"]})]})]})})}function _8e({open:e,onClose:t}){const[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(0),c=y.useRef(null),d=an(),[f,p]=y.useState(e);e&&!f&&(s(""),a(""),l(0)),e!==f&&p(e),y.useEffect(()=>{e&&setTimeout(()=>c.current?.focus(),50)},[e]),y.useEffect(()=>{const A=setTimeout(()=>a(n),200);return()=>clearTimeout(A)},[n]);const{data:m=[]}=L.messages.search.useQuery({query:i},{enabled:i.length>=2}),g=m.reduce((A,S)=>{const C=A[S.channelName]??[];return C.push(S),A[S.channelName]=C,A},{}),b=m;function _(A){d(`/channels/${A.channelId}`),t(),setTimeout(()=>{document.getElementById(`msg-${A.messageId}`)?.scrollIntoView({behavior:"smooth",block:"center"})},300)}function w(A){A.key==="Escape"?t():A.key==="ArrowDown"?(A.preventDefault(),l(S=>Math.min(S+1,b.length-1))):A.key==="ArrowUp"?(A.preventDefault(),l(S=>Math.max(S-1,0))):A.key==="Enter"&&b[o]&&_(b[o])}return r.jsx(Me,{children:e&&r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-[100] flex items-start justify-center pt-[15vh]",style:{backdropFilter:"blur(8px)",backgroundColor:"rgba(0,0,0,0.6)"},onClick:A=>{A.target===A.currentTarget&&t()},children:r.jsxs(ne.div,{initial:{opacity:0,y:-12,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.97},transition:{duration:.2,ease:[.16,1,.3,1]},className:"w-full max-w-[600px] mx-4 bg-[#13131A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-[#2A2A35]",children:[r.jsx(Io,{className:"w-5 h-5 text-[#8A8A99] flex-shrink-0"}),r.jsx("input",{ref:c,value:n,onChange:A=>{s(A.target.value),l(0)},onKeyDown:w,placeholder:"Search messages...",className:"flex-1 bg-transparent text-[20px] text-[#F0F0F5] placeholder:text-[#8A8A99]/50 outline-none"}),r.jsx("kbd",{className:"text-[11px] text-[#8A8A99] bg-white/5 border border-[#2A2A35] px-1.5 py-0.5 rounded-md",children:"esc"})]}),i.length>=2&&r.jsx("div",{className:"max-h-[420px] overflow-y-auto py-2",children:m.length===0?r.jsx("div",{className:"px-5 py-8 text-center",children:r.jsxs("p",{className:"text-[14px] text-[#8A8A99]",children:['No messages found for "',i,'"']})}):Object.entries(g).map(([A,S])=>r.jsxs("div",{children:[r.jsx("div",{className:"px-4 py-1.5 sticky top-0 bg-[#13131A]",children:r.jsxs("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:["#",A]})}),S.map(C=>{const E=b.indexOf(C),k=E===o;return r.jsxs("button",{onClick:()=>_(C),onMouseEnter:()=>l(E),className:"w-full text-left px-4 py-3 transition-colors",style:{backgroundColor:k?"rgba(255,255,255,0.04)":"transparent"},children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-0.5",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#C8C8D4]",children:"Message"}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:Ir(C.createdAt)})]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] leading-relaxed",children:w8e(C.snippet,i)})]},C.messageId)})]},A))}),i.length<2&&r.jsx("div",{className:"px-5 py-6 text-center",children:r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Type at least 2 characters to search"})}),r.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 border-t border-[#2A2A35]",children:[r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[r.jsx("kbd",{className:"bg-white/5 border border-[#2A2A35] px-1 py-0.5 rounded text-[10px] mr-1",children:"↑↓"}),"navigate"]}),r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[r.jsx("kbd",{className:"bg-white/5 border border-[#2A2A35] px-1 py-0.5 rounded text-[10px] mr-1",children:"↵"}),"jump"]})]})]})})})}function w8e(e,t){return e.split(new RegExp(`(${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi")).map((s,i)=>s.toLowerCase()===t.toLowerCase()?r.jsx("mark",{className:"bg-[#6366F1]/30 text-[#A5B4FC] rounded-sm px-0.5",children:s},i):s)}function A8e(){return/iPad|iPhone|iPod/.test(navigator.userAgent)&&!("MSStream"in window)}function S8e(){return window.matchMedia("(display-mode: standalone)").matches||"standalone"in navigator&&navigator.standalone===!0}function C8e(){const[e,t]=y.useState(!1),[n,s]=y.useState(!1),[i,a]=y.useState(null);y.useEffect(()=>{if(S8e())return;if(A8e()){localStorage.getItem("pwa-install-dismissed")||t(!0);return}function d(f){f.preventDefault(),a(f),sessionStorage.getItem("pwa-install-dismissed")||s(!0)}return window.addEventListener("beforeinstallprompt",d),()=>window.removeEventListener("beforeinstallprompt",d)},[]);const o=y.useCallback(()=>{localStorage.setItem("pwa-install-dismissed","1"),t(!1)},[]),l=y.useCallback(()=>{sessionStorage.setItem("pwa-install-dismissed","1"),s(!1)},[]),c=y.useCallback(async()=>{i&&(await i.prompt(),s(!1),a(null))},[i]);return r.jsxs(Me,{children:[e&&r.jsxs(ne.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-4 left-4 right-4 z-50 rounded-xl bg-[#1A1A2E] border border-[#2A2A35] p-4 shadow-2xl max-w-md mx-auto",children:[r.jsxs("p",{className:"text-[13px] text-[#C0C0CC] leading-relaxed",children:["For the best experience, add damn.dev to your Home Screen: tap"," ",r.jsx("span",{className:"inline-flex items-center align-middle mx-0.5",children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#6366F1]",children:[r.jsx("path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"}),r.jsx("polyline",{points:"16 6 12 2 8 6"}),r.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"15"})]})})," ","Share → Add to Home Screen"]}),r.jsx("button",{onClick:o,className:"mt-3 text-[12px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Got it"})]}),n&&r.jsxs(ne.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-4 left-4 right-4 z-50 rounded-xl bg-[#1A1A2E] border border-[#2A2A35] p-4 shadow-2xl max-w-md mx-auto flex items-center justify-between gap-3",children:[r.jsx("p",{className:"text-[13px] text-[#C0C0CC]",children:"Install damn.dev for a native experience"}),r.jsxs("div",{className:"flex gap-2 shrink-0",children:[r.jsx("button",{onClick:l,className:"text-[12px] text-[#8A8A99] hover:text-[#C0C0CC] transition-colors px-2 py-1",children:"Not now"}),r.jsx("button",{onClick:c,className:"text-[12px] font-medium bg-[#6366F1] text-white rounded-lg px-3 py-1.5 hover:bg-[#5558E6] transition-colors",children:"Install"})]})]})]})}function j8e(e){const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),s=atob(n),i=new Uint8Array(s.length);for(let a=0;a<s.length;a++)i[a]=s.charCodeAt(a);return i}const cO="pwa-push-retry-after";function N8e(){const e=y.useRef(!1),{data:t}=L.notifications.getVapidKey.useQuery(void 0,{enabled:!Va}),n=L.notifications.registerToken.useMutation(),s=y.useCallback(async()=>{if(!t?.vapidKey||!("serviceWorker"in navigator)||!("PushManager"in window))return;const a=await navigator.serviceWorker.ready;let o=await a.pushManager.getSubscription();o||(o=await a.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:j8e(t.vapidKey).buffer})),n.mutate({token:JSON.stringify(o.toJSON()),platform:"web"})},[t?.vapidKey,n]),i=y.useCallback(async()=>{if(e.current)return;e.current=!0;const a=localStorage.getItem(cO);if(!(a&&Date.now()<Number(a))){if(Notification.permission==="granted"){await s();return}Notification.permission==="default"&&(await Notification.requestPermission()==="granted"?await s():localStorage.setItem(cO,String(Date.now()+1440*60*1e3)))}},[s]);return y.useEffect(()=>{t?.vapidKey&&Notification.permission==="granted"&&s()},[t?.vapidKey,s]),y.useEffect(()=>{if(!t?.vapidKey||Notification.permission!=="default")return;function a(){i()}return window.addEventListener("pwa-push-prompt",a,{once:!0}),()=>window.removeEventListener("pwa-push-prompt",a)},[t?.vapidKey,i]),{promptForPermission:i}}function k8e(){const[e,t]=y.useState(null),[n,s]=y.useState(!1),[i,a]=y.useState("idle"),[o,l]=y.useState(null),[c,d]=y.useState(!1);y.useEffect(()=>{fetch(`${oi}/api/version`,{credentials:"include"}).then(b=>b.json()).then(b=>{if(b.updateAvailable&&b.latest){const _=`dismissed_update_${b.latest}`;localStorage.getItem(_)||t(b)}}).catch(()=>{})},[]);const f=y.useCallback(()=>{const b=Date.now(),_=setInterval(async()=>{if(Date.now()-b>3e5){clearInterval(_),a("error"),l("Update may have failed. Check server logs.");return}try{(await fetch(`${oi}/health`)).ok&&(clearInterval(_),a("done"),setTimeout(()=>window.location.reload(),1e3))}catch{a("restarting")}},2e3)},[]),p=y.useCallback(async()=>{if(!e)return;if(typeof window<"u"&&"__TAURI__"in window){try{const{check:_}=await X(async()=>{const{check:A}=await import("./index-Cpew6ait.js");return{check:A}},__vite__mapDeps([105,1])),w=await _();if(w){a("updating"),await w.downloadAndInstall();const{relaunch:A}=await X(async()=>{const{relaunch:S}=await import("./index-CO34o7br.js");return{relaunch:S}},__vite__mapDeps([106,1]));await A()}}catch{a("error"),l("Download the latest version from damn.dev")}return}a("updating");try{const _=await fetch(`${oi}/api/update`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}});if(_.status===403){a("error"),l("Only the workspace owner can trigger updates");return}const w=await _.json();if(w.error==="use_native_updater"){a("error"),l("Download the latest version from damn.dev");return}if(!w.ok){a("error"),l(w.error??"Update failed");return}f()}catch{a("error"),l("Failed to start update. Check server logs.")}},[e,f]);if(!e||n)return null;function m(){e?.latest&&localStorage.setItem(`dismissed_update_${e.latest}`,"1"),s(!0)}const g={"docker-vps":"SSH into your server and re-run your install script.",tauri:"Download the latest version from damn.dev."};return r.jsxs("div",{className:"bg-[#1A1A2E] border-b border-[#2A2A35] text-[#9090A0] text-[12px] py-1.5 px-4 flex flex-col flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:["damn.dev ",e.latest," is available"]}),e.canAutoUpdate?r.jsx("button",{onClick:p,className:"px-2 py-0.5 rounded bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 transition-colors text-[11px] font-medium",children:"Update now"}):r.jsx("span",{className:"text-[#707080]",children:g[e.installPath]??"Re-run your install script to update."}),e.releaseNotes&&r.jsx("button",{onClick:()=>d(b=>!b),className:"text-[#707080] hover:text-[#9090A0] transition-colors text-[11px]",children:c?"Hide":"What's new"})]}),i==="updating"&&r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Updating..."]}),i==="restarting"&&r.jsxs("span",{className:"flex items-center gap-2 animate-pulse",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Restarting..."]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E]",children:"Updated!"}),i==="error"&&r.jsx("span",{className:"text-[#F87171]",children:o})]}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:m,className:"ml-4 text-[#9090A0] hover:text-[#F0F0F5] transition-colors",children:"×"})]}),c&&e.releaseNotes&&r.jsx("div",{className:"mt-1.5 pt-1.5 border-t border-[#2A2A35] text-[11px] text-[#707080] whitespace-pre-wrap max-h-40 overflow-y-auto",children:e.releaseNotes})]})}function E8e(){const{data:e,refetch:t}=L.settings.getOpenClawVersion.useQuery(void 0,{refetchInterval:6e4,retry:!1}),[n,s]=y.useState(!1),[i,a]=y.useState("idle"),[o,l]=y.useState(null),c=L.settings.updateOpenClaw.useMutation();if(!e?.updateAvailable||n)return null;async function d(){a("updating");try{const f=await c.mutateAsync();f.ok?(a("done"),setTimeout(()=>{t(),s(!0)},3e3)):(a("error"),l(f.error??"Update failed"))}catch{a("error"),l("Failed to start update. Check server logs.")}}return r.jsxs("div",{className:"bg-[#1A1A2E] border-b border-[#2A2A35] text-[#9090A0] text-[12px] py-1.5 px-4 flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:["OpenClaw ",e.minimum," required (current: ",e.current,")"]}),r.jsx("button",{onClick:d,className:"px-2 py-0.5 rounded bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 transition-colors text-[11px] font-medium",children:"Update now"})]}),i==="updating"&&r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Updating OpenClaw..."]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E]",children:"OpenClaw updated!"}),i==="error"&&r.jsx("span",{className:"text-[#F87171]",children:o})]}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:()=>s(!0),className:"ml-4 text-[#9090A0] hover:text-[#F0F0F5] transition-colors",children:"×"})]})}function F8e(){return r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center px-8",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mb-4",children:r.jsx("span",{className:"text-2xl",children:"⚡"})}),r.jsx("h2",{className:"text-[18px] font-semibold text-[#F0F0F5] mb-2",children:"Select a channel"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] max-w-xs leading-relaxed",children:"Choose a channel from the sidebar to start working with your team."})]})}function T8e({children:e}){const t=an(),{data:n,isLoading:s}=L.workspace.getMyMembership.useQuery(void 0,{staleTime:0,refetchOnWindowFocus:!1,retry:!1}),i=n?.role==="owner",{data:a,isLoading:o}=L.onboarding.getState.useQuery(void 0,{staleTime:0,refetchOnWindowFocus:!1,retry:!1,enabled:i});return y.useEffect(()=>{if(!(s||!n)){if(n.role!=="owner"){n.onboardedAt||t("/welcome",{replace:!0});return}o||!a||!a.completed&&!a.skippedAt&&t("/onboarding",{replace:!0})}},[a,o,n,s,t]),s||i&&o?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):r.jsx(r.Fragment,{children:e})}function M8e({children:e}){const{data:t,isPending:n}=Mi();return n?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):t?r.jsx(r.Fragment,{children:e}):r.jsx(g8e,{})}function R8e({children:e}){const{isPending:t}=Mi();return t?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):r.jsx(r.Fragment,{children:e})}function D8e(){const[e,t]=y.useState(!1),n=Je(a=>a.setUnreadCounts),{data:s}=Mi(),{data:i}=L.readReceipts.getUnread.useQuery(void 0,{staleTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,enabled:!!s});return y.useEffect(()=>{i&&n(i)},[i,n]),y.useEffect(()=>{function a(o){(o.metaKey||o.ctrlKey)&&o.key==="k"&&(o.preventDefault(),t(l=>!l))}return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[]),N8e(),r.jsxs("div",{className:"flex flex-col h-screen",children:[r.jsx(k8e,{}),r.jsx(E8e,{}),r.jsxs(Q_,{children:[r.jsx(ms,{path:"/invite/:token",element:r.jsx(R8e,{children:r.jsx(y8e,{})})}),r.jsx(ms,{path:"*",element:r.jsxs(M8e,{children:[r.jsxs(Q_,{children:[r.jsx(ms,{path:"/onboarding",element:r.jsx(m8e,{})}),r.jsx(ms,{path:"/welcome",element:r.jsx(x8e,{})}),r.jsx(ms,{path:"*",element:r.jsx(T8e,{children:r.jsx(qye,{children:r.jsxs(Q_,{children:[r.jsx(ms,{path:"/",element:r.jsx(lm,{to:"/channels/direction",replace:!0})}),r.jsx(ms,{path:"/channels/:channelId",element:r.jsx(UMe,{})}),r.jsx(ms,{path:"/agents",element:r.jsx(tRe,{})}),r.jsx(ms,{path:"/agents/new",element:r.jsx(pRe,{})}),r.jsx(ms,{path:"/agents/edit-soul/:agentId",element:r.jsx(xRe,{})}),r.jsx(ms,{path:"/skills",element:r.jsx(BRe,{})}),r.jsx(ms,{path:"/deliverables",element:r.jsx(qDe,{})}),r.jsx(ms,{path:"/missions",element:r.jsx(GDe,{})}),r.jsx(ms,{path:"/coo",element:r.jsx(ZRe,{})}),r.jsx(ms,{path:"/settings",element:r.jsx(uDe,{})}),r.jsx(ms,{path:"/federation/:nodeId/:agentId",element:r.jsx(IDe,{})}),r.jsx(ms,{path:"*",element:r.jsx(F8e,{})})]})})})})]}),r.jsx(_8e,{open:e,onClose:()=>t(!1)})]})})]}),r.jsx(C8e,{})]})}GG.createRoot(document.getElementById("root")).render(r.jsx(y.StrictMode,{children:r.jsx(aJ,{children:r.jsxs(pY,{children:[r.jsx(D8e,{}),r.jsx(QY,{position:"bottom-right",toastOptions:{style:{background:"#1C1C24",border:"1px solid #2A2A35",color:"#C8C8D4",fontSize:"12px"}}})]})})}));
435
+ `):a;return r.jsxs("div",{className:"mx-3 mb-2 rounded-md bg-[#0F0F11] border border-[#2A2A35]/50 p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-[#8A8A99]",children:[r.jsx("span",{children:t.emoji}),r.jsx("span",{children:t.name})]}),i?.crossInstance&&i.federationNodeName&&r.jsxs("span",{className:"flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded bg-[#6366F1]/10 text-[#818CF8]",children:[r.jsx(Xt,{className:"w-2.5 h-2.5"}),i.federationNodeName]}),r.jsx("span",{className:"text-[10px] text-[#5A5A6E]",children:"Result"})]}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap break-words leading-relaxed font-mono",children:c}),l&&r.jsx("button",{onClick:()=>s(!n),className:"text-[10px] text-[#6366F1] hover:text-[#818CF8] mt-1.5 transition-colors",children:n?"Collapse":`Show full result (${o.length} lines)`})]})}function a8e({taskId:e,status:t}){const[n,s]=y.useState(!1),i=L.useUtils(),a=L.missions.removeTask.useMutation({onSuccess:()=>{i.missions.list.invalidate(),s(!1)}}),o=L.missions.updateTask.useMutation({onSuccess:()=>{i.missions.list.invalidate(),s(!1)}});return r.jsxs("div",{className:"relative",children:[r.jsx("button",{onClick:l=>{l.stopPropagation(),s(!n)},className:"text-[#3A3A45] hover:text-[#8A8A99] transition-colors p-0.5",children:r.jsx(iL,{className:"w-3 h-3"})}),n&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>s(!1)}),r.jsxs("div",{className:"absolute right-0 top-5 z-30 bg-[#1A1A24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[140px]",children:[t==="pending"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),s(!1)},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#C8C8D4] hover:bg-white/5 transition-colors",children:"Edit instruction"}),(t==="working"||t==="dispatched")&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"cancelled"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#F59E0B] hover:bg-[#F59E0B]/10 transition-colors",children:"Cancel task"}),t==="failed"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"pending"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#6366F1] hover:bg-[#6366F1]/10 transition-colors",children:"Retry task"}),t==="completed"&&r.jsx("button",{onClick:l=>{l.stopPropagation(),o.mutate({missionTaskId:e,status:"pending"})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#8A8A99] hover:bg-white/5 transition-colors",children:"Re-open"}),r.jsx("button",{onClick:l=>{l.stopPropagation(),a.mutate({missionTaskId:e})},className:"w-full text-left px-3 py-1.5 text-[11px] text-[#EF4444] hover:bg-[#EF4444]/10 transition-colors",children:"Remove"})]})]})]})}function jW({status:e}){switch(e){case"completed":return r.jsx(Fe,{className:"w-3.5 h-3.5 text-[#10B981]"});case"failed":return r.jsx(Te,{className:"w-3.5 h-3.5 text-[#EF4444]"});case"working":case"dispatched":return r.jsx(Pe,{className:"w-3.5 h-3.5 text-[#6366F1] animate-spin"});case"review":return r.jsx(ql,{className:"w-3.5 h-3.5 text-[#F59E0B]"});case"cancelled":return r.jsx(Te,{className:"w-3.5 h-3.5 text-[#5A5A6E]"});default:return r.jsx("div",{className:"w-3.5 h-3.5 rounded-full border border-[#3A3A45]"})}}function o8e({open:e,onClose:t,onCreated:n}){const[s,i]=y.useState(""),[a,o]=y.useState(""),[l,c]=y.useState("normal"),d=L.missions.create.useMutation({onSuccess:()=>n()});return r.jsx(ji,{open:e,onOpenChange:f=>{f||t()},children:r.jsxs(Ni,{children:[r.jsx(ir,{className:"fixed inset-0 bg-black/60 z-50"}),r.jsxs(ki,{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[460px] bg-[#16161A] border border-[#2A2A35] rounded-xl p-6 z-50 shadow-2xl",children:[r.jsx(nr,{className:"text-[15px] font-medium text-[#F0F0F5] mb-4",children:"New Mission"}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Title"}),r.jsx("input",{autoFocus:!0,value:s,onChange:f=>i(f.target.value),placeholder:"What needs to be done?",className:"w-full px-3 py-2 bg-[#0F0F11] border border-[#2A2A35] rounded-md text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] focus:outline-none focus:border-[#6366F1]",onKeyDown:f=>{f.key==="Enter"&&s.trim()&&d.mutate({title:s.trim(),description:a.trim()||void 0,priority:l})}})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Description"}),r.jsx("textarea",{value:a,onChange:f=>o(f.target.value),placeholder:"Optional details...",rows:3,className:"w-full px-3 py-2 bg-[#0F0F11] border border-[#2A2A35] rounded-md text-[13px] text-[#F0F0F5] placeholder-[#3A3A45] focus:outline-none focus:border-[#6366F1] resize-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#8A8A99] uppercase tracking-wider mb-1 block",children:"Priority"}),r.jsx("div",{className:"flex gap-2",children:["low","normal","high","critical"].map(f=>r.jsx("button",{onClick:()=>c(f),className:ye("px-3 py-1.5 rounded-md text-[12px] font-medium transition-colors",l===f?"text-white":"text-[#5A5A6E] bg-[#1E1E28] hover:text-[#8A8A99]"),style:l===f?{backgroundColor:My[f]}:void 0,children:SW[f]},f))})]})]}),r.jsxs("div",{className:"flex items-center justify-end gap-2 mt-5",children:[r.jsx(Gs,{asChild:!0,children:r.jsx("button",{className:"px-3 py-1.5 rounded-md text-[12px] text-[#8A8A99] hover:text-[#C8C8D4] transition-colors",children:"Cancel"})}),r.jsxs("button",{onClick:()=>{s.trim()&&d.mutate({title:s.trim(),description:a.trim()||void 0,priority:l})},disabled:!s.trim()||d.isPending,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-md bg-[#6366F1] text-white text-[12px] font-medium hover:bg-[#5558E6] transition-colors disabled:opacity-50",children:[d.isPending&&r.jsx(Pe,{className:"w-3 h-3 animate-spin"}),"Create Mission"]})]})]})]})})}const l8e=4;function c8e({current:e}){return r.jsx("div",{className:"flex items-center gap-2",children:Array.from({length:l8e}).map((t,n)=>r.jsx("div",{className:ye("rounded-full transition-all duration-300",n<e?"w-2 h-2 bg-[#6366F1]":n===e?"w-6 h-2 bg-[#6366F1]":"w-2 h-2 bg-[#2A2A35]")},n))})}function Vd({children:e}){return r.jsx(ne.div,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:-24},transition:{duration:.22,ease:[.16,1,.3,1]},className:"w-full max-w-lg mx-auto",children:e})}function lO({onDetected:e,alreadyRunning:t}){const[n,s]=y.useState("."),i=L.onboarding.pollOpenClaw.useQuery(void 0,{refetchInterval:3e3,refetchOnWindowFocus:!1,retry:!1});return y.useEffect(()=>{t||i.data?.running&&e()},[i.data?.running]),y.useEffect(()=>{const a=setInterval(()=>s(o=>o.length>=3?".":o+"."),500);return()=>clearInterval(a)},[]),i.data?.running?r.jsxs("div",{className:"flex items-center gap-2 mt-4 text-[12px] text-emerald-400",children:[r.jsx(sa,{className:"w-3.5 h-3.5"}),"OpenClaw detected — advancing…"]}):r.jsxs("div",{className:"flex items-center gap-2 mt-4 text-[12px] text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),"Waiting for OpenClaw",n]})}function IC({code:e}){const[t,n]=y.useState(!1);function s(){navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)}return r.jsxs("div",{className:"flex items-center justify-between bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 font-mono text-[12px] text-[#C8C8D4]",children:[r.jsx("span",{children:e}),r.jsx("button",{onClick:s,className:ye("ml-3 flex-shrink-0 transition-colors",t?"text-emerald-400":"text-[#5A5A6E] hover:text-[#C8C8D4]"),children:t?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Po,{className:"w-3.5 h-3.5"})})]})}function u8e({onNext:e,onSkip:t}){const{data:n,isLoading:s}=L.onboarding.checkOpenClaw.useQuery(void 0,{refetchOnWindowFocus:!1,retry:!1}),i=L.onboarding.skipOpenClaw.useMutation(),[a,o]=y.useState(!1),[l,c]=y.useState("docker"),[d,f]=y.useState(void 0);n?.runMode&&n.runMode!==d&&(f(n.runMode),n.runMode==="docker"?c("npm"):n.runMode==="npm"&&c("docker"));const[p,m]=y.useState(""),[g,b]=y.useState(!1),[_,w]=y.useState(""),[A,S]=y.useState(""),[C,E]=y.useState("idle"),k=L.onboarding.saveWaitlistEmail.useMutation(),T=L.onboarding.testConnection.useMutation();if(s)return r.jsx(Vd,{children:r.jsxs("div",{className:"flex items-center gap-3 py-8",children:[r.jsx(Pe,{className:"w-4 h-4 animate-spin text-[#6366F1]"}),r.jsx("span",{className:"text-[14px] text-[#8A8A99]",children:"Checking OpenClaw…"})]})});async function F(){await i.mutateAsync(),t()}async function M(){if(!_.trim()||!A.trim())return;E("testing");const q=await T.mutateAsync({url:_.trim(),token:A.trim()});E(q.ok?"ok":"fail"),q.ok&&setTimeout(()=>e(),1e3)}async function I(){p.trim()&&(await k.mutateAsync({email:p.trim()}),b(!0))}const R=n?.running===!0,H=n?.runMode??null,K=[{id:"docker",label:"Docker",sub:"Agents run isolated",badge:"Recommended"},{id:"npm",label:"Local (npm)",sub:"Best for dedicated machines",badge:null},{id:"cloud",label:"Cloud (VPS)",sub:"Always-on, team access",badge:null}].filter(q=>q.id!==H);return R&&!a?r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Connect OpenClaw"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"damn.dev runs agents through OpenClaw, the local AI gateway."}),r.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-6",children:[r.jsx(sa,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("p",{className:"text-[13px] font-medium text-emerald-400",children:["OpenClaw detected",H==="docker"?" via Docker":H==="cloud"?" via Cloud":H==="npm"?" locally":""]}),(n.agentCount??0)>0&&r.jsxs("p",{className:"text-[11px] text-emerald-400/70",children:[n.agentCount," agent",n.agentCount!==1?"s":""," detected"]})]})]}),r.jsxs("button",{onClick:e,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] transition-colors mb-4",children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),r.jsx("button",{onClick:()=>o(!0),className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Want to connect to a different instance?"})]}):r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Connect OpenClaw"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"damn.dev runs agents through OpenClaw, the local AI gateway."}),R&&a&&r.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-4",children:[r.jsx(sa,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),r.jsx("div",{className:"flex-1",children:r.jsxs("p",{className:"text-[13px] font-medium text-emerald-400",children:["OpenClaw is running",H==="docker"?" via Docker":H==="cloud"?" via Cloud":H==="npm"?" locally":""]})}),r.jsxs("button",{onClick:e,className:"ml-auto flex items-center gap-1 text-[12px] font-medium text-emerald-400 hover:text-emerald-300 transition-colors flex-shrink-0",children:["Continue ",r.jsx(Jt,{className:"w-3 h-3"})]})]}),r.jsx("div",{className:ye("grid gap-3 mb-4",K.length===2?"grid-cols-2":"grid-cols-3"),children:K.map(q=>r.jsxs("button",{onClick:()=>c(q.id),className:ye("relative text-left rounded-2xl p-4 border transition-all",l===q.id?"border-[#6366F1]/50 bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] bg-[#16161A] hover:border-[#3A3A45]"),children:[q.badge&&r.jsx("span",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[9px] font-semibold bg-[#6366F1] text-white tracking-wide",children:q.badge}),r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mt-1",children:q.label}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:q.sub})]},q.id))}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 mb-4",children:[l==="docker"&&r.jsxs("div",{children:[r.jsxs("a",{href:"https://www.docker.com/products/docker-desktop/",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg border border-[#2A2A35] text-[13px] text-[#C8C8D4] hover:border-[#3A3A45] hover:text-[#F0F0F5] transition-colors mb-3",children:[r.jsx(cs,{className:"w-3.5 h-3.5"}),"Download Docker Desktop"]}),r.jsx("button",{onClick:()=>window.open("http://localhost:3001/setup/docker-compose.yml","_blank"),className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg bg-[#6366F1]/10 border border-[#6366F1]/30 text-[13px] text-[#6366F1] hover:bg-[#6366F1]/20 transition-colors mb-4",children:"Download docker-compose.yml"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] leading-relaxed",children:"Open Docker Desktop → Compose → Open File → Run"}),r.jsx(lO,{onDetected:e,alreadyRunning:R})]}),l==="npm"&&r.jsxs("div",{children:[r.jsxs("div",{className:"space-y-2 mb-4",children:[r.jsx(IC,{code:"npm install -g openclaw"}),r.jsx(IC,{code:"openclaw start"})]}),r.jsx(lO,{onDetected:e,alreadyRunning:R})]}),l==="cloud"&&r.jsxs("div",{className:"space-y-5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4] mb-1",children:"Want OpenClaw fully managed in the cloud?"}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mb-3",children:"Join the waitlist for cloud.damn.dev."}),g?r.jsx("p",{className:"text-[12px] text-emerald-400",children:"You're on the list. We'll notify you when cloud.damn.dev launches."}):r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"email",value:p,onChange:q=>m(q.target.value),placeholder:"you@example.com",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:I,disabled:!p.trim()||k.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:k.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):"Join waitlist"})]})]}),r.jsxs("div",{className:"border-t border-[#2A2A35] pt-5",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4] mb-3",children:"Already running on a VPS?"}),r.jsxs("div",{className:"space-y-2 mb-3",children:[r.jsx("input",{type:"url",value:_,onChange:q=>{w(q.target.value),E("idle")},placeholder:"https://openclaw.myserver.com",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("input",{type:"password",value:A,onChange:q=>{S(q.target.value),E("idle")},placeholder:"Bearer token",className:"w-full bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"})]}),r.jsxs("button",{onClick:M,disabled:!_.trim()||!A.trim()||C==="testing"||C==="ok",className:"flex items-center gap-2 px-4 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors",children:[C==="testing"&&r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),C==="ok"&&r.jsx(Fe,{className:"w-3.5 h-3.5 text-emerald-400"}),C==="fail"&&r.jsx(Te,{className:"w-3.5 h-3.5 text-red-400"}),C==="ok"?"Connected":"Test connection"]})]})]})]}),r.jsx("button",{onClick:F,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"I'll connect OpenClaw later →"})]})}function d8e({onDetected:e}){const[t,n]=y.useState("."),s=L.onboarding.pollOllama.useQuery(void 0,{refetchInterval:3e3,refetchOnWindowFocus:!1,retry:!1});return y.useEffect(()=>{s.data?.running&&s.data.models.length>0&&e(s.data.models)},[s.data?.running]),y.useEffect(()=>{const i=setInterval(()=>n(a=>a.length>=3?".":a+"."),500);return()=>clearInterval(i)},[]),s.data?.running?r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[12px] text-emerald-400",children:[r.jsx(sa,{className:"w-3.5 h-3.5"}),"Ollama detected"]}):r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[12px] text-[#5A5A6E]",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#5A5A6E] animate-pulse"}),"Waiting for Ollama",t]})}function h8e({onNext:e,onSkip:t}){const[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(""),[c,d]=y.useState(""),[f,p]=y.useState(null),[m,g]=y.useState(null),[b,_]=y.useState(!1),[w,A]=y.useState(null),[S,C]=y.useState(null),[E,k]=y.useState(""),[T,F]=y.useState(""),[M,I]=y.useState(""),[R,H]=y.useState(""),[V,K]=y.useState([]),[q,$]=y.useState(!1),B=y.useRef(null),{data:Y,isLoading:U}=L.onboarding.checkModels.useQuery(void 0,{refetchOnWindowFocus:!1,retry:!1}),{data:W}=L.onboarding.getState.useQuery(void 0,{refetchOnWindowFocus:!1});y.useEffect(()=>{Y?.envOpenRouterConfigured&&!w&&(A({valid:!0,modelCount:Y.openRouterModelCount??0,suggestedReasoningModel:W?.defaultReasoningModel??null,suggestedFastModel:W?.defaultFastModel??null}),s("sk-or-v1-••••••••••••••••••••••••••••••••"),W?.defaultReasoningModel&&!E&&k(W.defaultReasoningModel),W?.defaultFastModel&&!T&&F(W.defaultFastModel)),(Y?.ollamaModels?.length??0)>0&&K(Y.ollamaModels)},[Y?.envOpenRouterConfigured,Y?.ollamaModels?.length,W?.defaultReasoningModel]);const O=L.onboarding.validateApiKey.useMutation(),D=L.onboarding.setDefaultModels.useMutation();function Q(me){me.suggestedReasoningModel&&!E&&k(me.suggestedReasoningModel),me.suggestedFastModel&&!T&&F(me.suggestedFastModel)}async function z(){if(!n.trim())return;const me=await O.mutateAsync({provider:"openrouter",key:n.trim()});A(me),me.valid&&Q(me)}async function J(){if(!i.trim())return;const me=await O.mutateAsync({provider:"anthropic",key:i.trim()});C(me),me.valid&&Q(me)}async function ee(){if(!o.trim())return;const me=await O.mutateAsync({provider:"openai",key:o.trim()});p(me),me.valid&&Q(me)}async function re(){if(!c.trim())return;const me=await O.mutateAsync({provider:"gemini",key:c.trim()});g(me),me.valid&&Q(me)}const oe=V.length>0,se=oe||w?.valid===!0||S?.valid===!0||f?.valid===!0||m?.valid===!0||Y?.envOpenRouterConfigured===!0,ae=[];if(oe)for(const me of V)ae.push({id:me,label:me,group:"Ollama"});if(w?.valid){const me=[{id:"openrouter/anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6"},{id:"openrouter/anthropic/claude-opus-4.6",label:"Claude Opus 4.6"},{id:"openrouter/anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5"},{id:"openrouter/openai/gpt-4o",label:"GPT-4o"},{id:"openrouter/openai/gpt-4o-mini",label:"GPT-4o mini"},{id:"openrouter/google/gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"openrouter/google/gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"openrouter/meta-llama/llama-3.3-70b-instruct:free",label:"Llama 3.3 70B (free)"}];for(const $e of me)ae.push({...$e,group:"OpenRouter"})}if(S?.valid){const me=[{id:"anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6"},{id:"anthropic/claude-opus-4.6",label:"Claude Opus 4.6"},{id:"anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"Anthropic"})}if(f?.valid){const me=[{id:"openai/gpt-4o",label:"GPT-4o"},{id:"openai/gpt-4o-mini",label:"GPT-4o mini"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"OpenAI"})}if(m?.valid){const me=[{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash"}];for(const $e of me)ae.some(nt=>nt.id===$e.id)||ae.push({...$e,group:"Google"})}const le=se&&ae.length>0,je=(Y?.ramGb??0)>=8,Ee=Y?.recommendedLocalModel??null,de=Y?.recommendedModelSize??null;return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-1",children:"Configure models"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-4 leading-relaxed",children:"Connect at least one model source for your agents to use."}),r.jsxs("div",{className:"space-y-2.5 mb-4",children:[r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"Ollama (local)"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mt-0.5",children:"Free, runs on your machine"})]}),U?r.jsx("div",{className:"w-4 h-4 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):oe?r.jsxs("span",{className:"text-[11px] text-emerald-400 font-medium",children:[V.length," model",V.length!==1?"s":""]}):r.jsx("span",{className:"text-[11px] text-[#5A5A6E]",children:"Not detected"})]}),oe?r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[V.slice(0,6).map(me=>r.jsx("span",{className:"px-2 py-0.5 rounded-md text-[11px] font-medium bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:me},me)),V.length>6&&r.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[11px] text-[#8A8A99]",children:["+",V.length-6," more"]})]}):!U&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"rounded-xl border border-[#2A2A35] bg-[#0F0F11] p-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4]",children:"Get started with OpenRouter"}),r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-semibold bg-[#6366F1]/15 text-[#6366F1] border border-[#6366F1]/20",children:"No install needed"})]}),r.jsx("p",{className:"text-[12px] text-[#8A8A99] mb-2",children:"Free models available. The fastest way to get running."}),r.jsx("button",{onClick:()=>B.current?.focus(),className:"text-[12px] text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Go to OpenRouter section ↓"})]}),r.jsx("button",{onClick:()=>$(me=>!me),className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:q?"Hide local install ↑":"Prefer fully local? →"}),q&&r.jsx("div",{className:"rounded-xl border border-[#2A2A35] bg-[#0F0F11] p-3 space-y-3",children:je?r.jsxs(r.Fragment,{children:[r.jsxs("a",{href:"https://ollama.com",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 w-full justify-center py-2 px-4 rounded-lg border border-[#2A2A35] text-[13px] text-[#C8C8D4] hover:border-[#3A3A45] hover:text-[#F0F0F5] transition-colors",children:[r.jsx(cs,{className:"w-3.5 h-3.5"}),"Download Ollama"]}),Ee&&r.jsxs("div",{className:"space-y-1.5",children:[r.jsx(IC,{code:`ollama pull ${Ee}`}),de&&r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:de})]}),r.jsx(d8e,{onDetected:me=>K(me)})]}):r.jsx("p",{className:"text-[12px] text-[#8A8A99]",children:"Local models require at least 8GB RAM. We recommend OpenRouter instead."})})]})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5]",children:"OpenRouter"}),Y?.envOpenRouterConfigured&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-emerald-400",children:[r.jsx(Fe,{className:"w-3 h-3"})," Configured via .env"]})]}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Access 200+ models via one API key"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:n,onChange:me=>{s(me.target.value),A(null)},placeholder:"sk-or-v1-...",ref:B,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:z,disabled:!n.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),w&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",w.valid?"text-emerald-400":"text-red-400"),children:[w.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),w.valid?`Valid — ${w.modelCount} models available`:"Invalid key"]}),w?.valid&&w.suggestedReasoningModel&&r.jsx("div",{className:"mt-3 pt-3 border-t border-[#2A2A35]",children:r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-1",children:"Models available via OpenRouter"})})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Anthropic"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Claude models (Haiku, Sonnet, Opus)"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:i,onChange:me=>{a(me.target.value),C(null)},placeholder:"sk-ant-...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:J,disabled:!i.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),S&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",S.valid?"text-emerald-400":"text-red-400"),children:[S.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),S.valid?"Valid":"Invalid key"]})]}),r.jsxs("button",{onClick:()=>_(me=>!me),className:"flex items-center gap-1.5 text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors w-full py-0.5",children:[r.jsx("span",{children:b?"↑ Hide":"↓ More providers"}),r.jsx("span",{className:"text-[#3A3A45]",children:"(OpenAI, Gemini)"})]}),b&&r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"OpenAI"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"GPT-4o, o1, o3-mini"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:o,onChange:me=>{l(me.target.value),p(null)},placeholder:"sk-...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:ee,disabled:!o.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),f&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",f.valid?"text-emerald-400":"text-red-400"),children:[f.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),f.valid?"Valid":"Invalid key"]})]}),r.jsxs("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Google Gemini"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-2.5",children:"Gemini 2.0, Flash, Pro"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"password",value:c,onChange:me=>{d(me.target.value),g(null)},placeholder:"AIza...",className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors"}),r.jsx("button",{onClick:re,disabled:!c.trim()||O.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 disabled:opacity-50 transition-colors flex-shrink-0",children:O.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"}):"Validate"})]}),m&&r.jsxs("div",{className:ye("flex items-center gap-1.5 mt-2 text-[12px]",m.valid?"text-emerald-400":"text-red-400"),children:[m.valid?r.jsx(Fe,{className:"w-3.5 h-3.5"}):r.jsx(Te,{className:"w-3.5 h-3.5"}),m.valid?"Valid":"Invalid key"]})]})]})]}),le&&r.jsxs("div",{className:"bg-[#16161A] border border-[#6366F1]/20 rounded-2xl p-4 mb-1",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mb-0.5",children:"Default models"}),r.jsx("p",{className:"text-[11px] text-[#8A8A99] mb-3",children:"Pre-selected for you. Change anytime in Settings."}),r.jsxs("div",{className:"space-y-2.5",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Primary (reasoning)"}),r.jsxs(ss,{value:E,onValueChange:me=>{k(me),I("")},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#0F0F11] text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/50 transition-colors",children:[r.jsx("span",{className:"truncate",children:(ae.find(me=>me.id===E)?.label??E)||"Select model..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[280px] max-h-[240px] z-[9999]",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx("input",{value:M,onChange:me=>I(me.target.value),onKeyDown:me=>{me.key==="Enter"&&M.trim()&&k(M.trim())},placeholder:"Type model ID...",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded px-2 py-1.5 text-[11px] text-[#C8C8D4] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] transition-colors"})}),r.jsx(os,{children:Object.entries(ae.reduce((me,$e)=>((me[$e.group]??=[]).push($e),me),{})).map(([me,$e])=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:me}),$e.map(nt=>r.jsxs(vn,{value:nt.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:nt.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},nt.id))]},me))})]})})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[11px] text-[#5A5A6E] mb-1 block",children:"Fast (quick tasks)"}),r.jsxs(ss,{value:T,onValueChange:me=>{F(me),H("")},children:[r.jsxs(is,{className:"w-full flex items-center justify-between px-3 py-2 rounded-lg border border-[#2A2A35] bg-[#0F0F11] text-[13px] text-[#F0F0F5] outline-none focus:border-[#6366F1]/50 transition-colors",children:[r.jsx("span",{className:"truncate",children:(ae.find(me=>me.id===T)?.label??T)||"Select model..."}),r.jsx(Yl,{children:r.jsx(ft,{className:"w-3.5 h-3.5 text-[#5A5A6E]"})})]}),r.jsx(rs,{children:r.jsxs(as,{position:"popper",sideOffset:4,className:"bg-[#1C1C24] border border-[#2A2A35] rounded-lg shadow-xl py-1 min-w-[280px] max-h-[240px] z-[9999]",children:[r.jsx("div",{className:"px-2 pb-1 mb-1 border-b border-[#2A2A35]",children:r.jsx("input",{value:R,onChange:me=>H(me.target.value),onKeyDown:me=>{me.key==="Enter"&&R.trim()&&F(R.trim())},placeholder:"Type model ID...",className:"w-full bg-[#13131A] border border-[#2A2A35] rounded px-2 py-1.5 text-[11px] text-[#C8C8D4] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1] transition-colors"})}),r.jsx(os,{children:Object.entries(ae.reduce((me,$e)=>((me[$e.group]??=[]).push($e),me),{})).map(([me,$e])=>r.jsxs(Ro,{children:[r.jsx(Do,{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-[#5A5A6E] uppercase tracking-widest",children:me}),$e.map(nt=>r.jsxs(vn,{value:nt.id,className:"flex items-center justify-between px-3 py-1.5 text-[12px] text-[#C8C8D4] cursor-pointer outline-none data-[highlighted]:bg-white/5",children:[r.jsx(yn,{children:nt.label}),r.jsx(ui,{children:r.jsx(Fe,{className:"w-3 h-3 text-[#6366F1]"})})]},nt.id))]},me))})]})})]})]})]})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[r.jsx("button",{onClick:async()=>{E&&T&&await D.mutateAsync({reasoningModel:E,fastModel:T}),e()},disabled:!se||D.isPending,className:ye("flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium transition-colors",se?"bg-[#6366F1] text-white hover:bg-[#5254CC]":"bg-white/5 text-[#5A5A6E] border border-[#2A2A35] cursor-not-allowed"),children:D.isPending?r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}):r.jsxs(r.Fragment,{children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]})}),r.jsx("button",{onClick:t,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip for now"})]})]})}function f8e({onNext:e}){const[t,n]=y.useState(null);return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-2",children:"Share your workspace"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-6 leading-relaxed",children:"How will you use damn.dev?"}),r.jsx("div",{className:"grid grid-cols-2 gap-3 mb-6",children:["solo","team"].map(s=>r.jsxs("button",{onClick:()=>n(s),className:ye("text-left rounded-2xl p-4 border transition-all",t===s?"border-[#6366F1]/50 bg-[#6366F1]/5 ring-1 ring-[#6366F1]/20":"border-[#2A2A35] bg-[#16161A] hover:border-[#3A3A45]"),children:[r.jsx("p",{className:"text-[13px] font-medium text-[#F0F0F5] mt-1",children:s==="solo"?"Just me":"With my team"}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E] mt-0.5",children:s==="solo"?"Default":"Share access via Tailscale"})]},s))}),t==="team"&&r.jsx("div",{className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-5 mb-6",children:r.jsx(V5,{onComplete:()=>e(),onSkip:e})}),t!=="team"&&r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("button",{onClick:e,disabled:t===null,className:ye("flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium transition-colors",t!==null?"bg-[#6366F1] text-white hover:bg-[#5254CC]":"bg-white/5 text-[#5A5A6E] border border-[#2A2A35] cursor-not-allowed"),children:["Continue",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),r.jsx("button",{onClick:e,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip"})]})]})}function p8e({onComplete:e}){const t=an(),n=L.useUtils(),s=L.onboarding.complete.useMutation(),i=L.onboarding.cooOnboardingChat.useMutation(),a=L.onboarding.setWorkspaceContext.useMutation(),[o,l]=y.useState([]),[c,d]=y.useState(""),[f,p]=y.useState(null),[m,g]=y.useState(!1),[b,_]=y.useState(!0),[w,A]=y.useState(null),S=y.useRef(null),C=y.useRef(null);y.useEffect(()=>{let M=!1;return i.mutateAsync({message:"Hello",history:[]}).then(I=>{M||(l([{role:"assistant",content:I.reply}]),_(!1))}).catch(()=>{M||(_(!1),A("Could not reach COO. You can skip this step and set workspace context later."))}),()=>{M=!0}},[]),y.useEffect(()=>{S.current?.scrollTo({top:S.current.scrollHeight,behavior:"smooth"})},[o,f]);async function E(){const M=c.trim();if(!M||i.isPending)return;d(""),A(null);const I=[...o,{role:"user",content:M}];l(I);try{const R=await i.mutateAsync({message:M,history:I});l([...I,{role:"assistant",content:R.reply}]),R.workspaceContext&&p(R.workspaceContext)}catch{A("COO failed to respond. Try again or skip this step.")}C.current?.focus()}async function k(){f&&(await a.mutateAsync({context:f}),g(!0))}async function T(){await s.mutateAsync(),await n.onboarding.getState.refetch(),t("/channels/chan_coo",{replace:!0}),e()}async function F(){await s.mutateAsync(),await n.onboarding.getState.refetch(),t("/channels/chan_coo",{replace:!0}),e()}return r.jsxs(Vd,{children:[r.jsx("h2",{className:"text-[22px] font-semibold text-[#F0F0F5] mb-1",children:"Meet your COO"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] mb-4 leading-relaxed",children:"A few questions to set up your workspace context."}),r.jsxs("div",{ref:S,className:"bg-[#16161A] border border-[#2A2A35] rounded-2xl p-4 mb-3 space-y-3 max-h-[320px] overflow-y-auto",children:[b&&r.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-[#5A5A6E]",children:[r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}),"COO is thinking..."]}),w&&r.jsx("div",{className:"text-[13px] text-red-400/80 leading-relaxed",children:w}),o.map((M,I)=>r.jsx("div",{className:ye("flex",M.role==="user"?"justify-end":"justify-start"),children:r.jsx("div",{className:ye("rounded-xl px-3 py-2 text-[13px] leading-relaxed max-w-[85%]",M.role==="user"?"bg-[#6366F1] text-white":"bg-[#1E1E28] text-[#C8C8D4] border border-[#2A2A35]"),children:M.content})},I)),i.isPending&&o.length>0&&r.jsx("div",{className:"flex justify-start",children:r.jsx("div",{className:"rounded-xl px-3 py-2 bg-[#1E1E28] border border-[#2A2A35]",children:r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin text-[#5A5A6E]"})})})]}),f&&!m&&r.jsxs("div",{className:"bg-[#0F0F11] border border-[#6366F1]/30 rounded-xl p-3 mb-3",children:[r.jsx("p",{className:"text-[11px] font-medium text-[#6366F1] mb-2",children:"Proposed workspace context"}),r.jsx("pre",{className:"text-[11px] text-[#C8C8D4] whitespace-pre-wrap leading-relaxed max-h-[160px] overflow-y-auto mb-2",children:f}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{onClick:k,disabled:a.isPending,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[a.isPending?r.jsx(Pe,{className:"w-3 h-3 animate-spin"}):r.jsx(Fe,{className:"w-3 h-3"}),"Approve"]}),r.jsx("button",{onClick:()=>p(null),className:"px-3 py-1.5 rounded-lg text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Revise"})]})]}),m&&r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-emerald-500/10 border border-emerald-500/20 mb-3",children:[r.jsx(sa,{className:"w-3.5 h-3.5 text-emerald-400"}),r.jsx("span",{className:"text-[12px] text-emerald-400",children:"Workspace context saved"})]}),!m&&!b&&r.jsxs("div",{className:"flex gap-2 mb-3",children:[r.jsx("input",{ref:C,type:"text",value:c,onChange:M=>d(M.target.value),onKeyDown:M=>M.key==="Enter"&&E(),placeholder:"Type your answer...",disabled:i.isPending,className:"flex-1 bg-[#0F0F11] border border-[#2A2A35] rounded-lg px-3 py-2 text-[13px] text-[#F0F0F5] placeholder:text-[#5A5A6E] outline-none focus:border-[#6366F1]/50 transition-colors disabled:opacity-50"}),r.jsx("button",{onClick:E,disabled:!c.trim()||i.isPending,className:"px-3 py-2 rounded-lg text-[12px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-50 transition-colors flex-shrink-0",children:"Send"})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[m&&r.jsxs("button",{onClick:T,disabled:s.isPending,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-medium bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[s.isPending?r.jsx(Pe,{className:"w-3.5 h-3.5 animate-spin"}):null,"Open damn.dev",r.jsx(Jt,{className:"w-3.5 h-3.5"})]}),!m&&r.jsx("button",{onClick:F,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip this step"})]})]})}function m8e(){const e=an(),[t,n]=y.useState(0),s=L.onboarding.skip.useMutation();async function i(){await s.mutateAsync(),e("/",{replace:!0})}return r.jsx("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col items-center justify-center",children:r.jsxs("div",{className:"w-full max-w-lg px-6 flex flex-col",style:{maxHeight:"100vh"},children:[r.jsxs("div",{className:"flex items-center justify-between mb-8 flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[18px]",children:"⚡"}),r.jsx("span",{className:"text-[15px] font-semibold text-[#F0F0F5]",children:"damn.dev"})]}),r.jsx(c8e,{current:t}),r.jsx("button",{onClick:i,className:"text-[12px] text-[#5A5A6E] hover:text-[#8A8A99] transition-colors",children:"Skip setup"})]}),r.jsx("div",{className:"overflow-y-auto flex-1 pb-6",children:r.jsxs(Me,{mode:"wait",children:[t===0&&r.jsx(u8e,{onNext:()=>n(1),onSkip:()=>n(1)},"step0"),t===1&&r.jsx(h8e,{onNext:()=>n(2),onSkip:()=>n(2)},"step1"),t===2&&r.jsx(f8e,{onNext:()=>n(3)},"step2"),t===3&&r.jsx(p8e,{onComplete:()=>{}},"step3")]})})]})})}function x8e(){const e=an(),{data:t}=L.workspace.getMyMembership.useQuery(),{data:n=[]}=L.channels.list.useQuery(),s=L.workspace.completeOnboarding.useMutation();async function i(){await s.mutateAsync();const a=n.find(o=>o.name==="general"&&o.visibility==="public"&&o.channelType==="topic");e(a?`/channels/${a.id}`:"/channels/direction",{replace:!0})}return r.jsx("div",{className:"flex h-screen w-screen overflow-hidden bg-[#0F0F11] flex-col items-center justify-center",children:r.jsxs(ne.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,ease:[.16,1,.3,1]},className:"w-full max-w-md px-6 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mx-auto mb-6",children:r.jsx("span",{className:"text-3xl",children:"👋"})}),r.jsxs("h1",{className:"text-[24px] font-semibold text-[#F0F0F5] mb-3",children:["Welcome to ",t?.workspaceName??"the workspace"]}),t?.ownerName&&r.jsxs("p",{className:"text-[14px] text-[#8A8A99] mb-8 leading-relaxed",children:["You've been invited by ",t.ownerName]}),r.jsxs("button",{onClick:i,disabled:s.isPending,className:"inline-flex items-center gap-2 px-6 py-3 rounded-xl text-[14px] font-semibold bg-[#6366F1] text-white hover:bg-[#5254CC] disabled:opacity-60 transition-colors",children:[s.isPending?r.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):null,"Explore your workspace",r.jsx(Jt,{className:"w-4 h-4"})]})]})})}function g8e(){const[e,t]=y.useState("signin"),[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(!1),[c,d]=y.useState(null),[f,p]=y.useState(!1),{data:m}=L.onboarding.hasGoogleAuth.useQuery(),{data:g}=L.onboarding.signupAllowed.useQuery(),b=g?.allowed??!1,_=g?.registrationMode??"closed";y.useEffect(()=>{!b&&e==="signup"&&t("signin")},[b,e]);async function w(A){if(A.preventDefault(),d(null),e==="signup"&&!b){d("This workspace requires an invitation to join.");return}if(i.length<12){d("Password must be at least 12 characters.");return}p(!0);try{if(e==="signup"){const S=await cz.email({email:n,password:i,name:n.split("@")[0]});S.error&&d(S.error.message??"Sign up failed.")}else{const S=await v0.email({email:n,password:i});S.error&&d(S.error.message??"Invalid credentials.")}}catch{d("Something went wrong. Please try again.")}finally{p(!1)}}return r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-6 max-w-sm w-full px-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center",children:r.jsx("span",{className:"text-2xl font-bold text-[#6366F1]",children:"d"})}),r.jsx("h1",{className:"text-[22px] font-semibold text-[#F0F0F5]",children:"damn.dev"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:e==="signin"?"Sign in to your workspace":"Create your workspace"})]}),r.jsxs("form",{onSubmit:w,className:"flex flex-col gap-3 w-full",children:[r.jsx("input",{type:"email",placeholder:"Email",value:n,onChange:A=>s(A.target.value),required:!0,className:"w-full rounded-lg bg-[#1A1A20] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:o?"text":"password",placeholder:"Password (min 12 characters)",value:i,onChange:A=>a(A.target.value),required:!0,minLength:12,className:"w-full rounded-lg bg-[#1A1A20] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 pr-11 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("button",{type:"button",onClick:()=>l(A=>!A),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#5A5A6A] hover:text-[#8A8A99] transition-colors",tabIndex:-1,children:o?r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 4.411m0 0L21 21"})}):r.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]}),c&&r.jsx("p",{className:"text-[13px] text-red-400",children:c}),r.jsx("button",{type:"submit",disabled:f,className:"w-full rounded-lg bg-[#6366F1] text-white px-5 py-3 text-[14px] font-medium hover:bg-[#5254CC] disabled:opacity-50 transition-colors",children:f?"...":e==="signin"?"Sign in":"Create account"})]}),b?r.jsx("button",{type:"button",onClick:()=>{t(e==="signin"?"signup":"signin"),d(null)},className:"text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:e==="signin"?"Don't have an account? Create one":"Already have an account? Sign in"}):_==="invite"?r.jsx("p",{className:"text-[13px] text-[#5A5A6E] text-center",children:"Need an account? Ask the workspace admin for an invite link."}):r.jsx("p",{className:"text-[13px] text-[#5A5A6E] text-center",children:"Registration is closed."}),m?.enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-3 w-full",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6A]",children:"or"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),r.jsxs("button",{onClick:()=>v0.social({provider:"google",callbackURL:window.location.origin+"/"}),className:"flex items-center gap-3 w-full justify-center rounded-lg bg-white text-[#1a1a1a] px-5 py-3 text-[14px] font-medium hover:bg-[#f0f0f0] transition-colors",children:[r.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continue with Google"]})]})]})})}function b8e(e){if(!e||typeof e!="object")return!1;const t=String(e.message??"");return t.includes("Failed to fetch")||t.includes("NetworkError")||t.includes("ERR_CONNECTION_REFUSED")||t.includes("ECONNREFUSED")||t.includes("Load failed")||t.includes("fetch failed")}function v8e(){const[e,t]=y.useState(!1);function n(){t(!0),setTimeout(()=>window.location.reload(),500)}return r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-5 max-w-md text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-amber-500/10 border border-amber-500/20 flex items-center justify-center",children:r.jsx("span",{className:"text-amber-400 text-xl",children:"!"})}),r.jsx("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:"Can't reach this workspace"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] leading-relaxed",children:"This is a private workspace running on someone's machine. You need to be on their private network to access it."}),r.jsxs("div",{className:"w-full bg-[#16161A] border border-[#2A2A35] rounded-xl p-5 text-left space-y-4",children:[r.jsx("p",{className:"text-[13px] font-medium text-[#C8C8D4]",children:"If they shared a Tailscale link:"}),r.jsxs("div",{className:"space-y-2 text-[12px] text-[#8A8A99]",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"1."}),r.jsxs("div",{children:["Install Tailscale on your device",r.jsxs("a",{href:"https://tailscale.com/download",target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 mt-1 text-[#6366F1] hover:text-[#818CF8] transition-colors",children:[r.jsx(cs,{className:"w-3 h-3"}),"tailscale.com/download"]})]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"2."}),r.jsx("span",{children:"Ask them to add you to their Tailnet at tailscale.com/admin"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-[#6366F1] font-medium flex-shrink-0",children:"3."}),r.jsx("span",{children:"Once connected, refresh this page"})]})]}),r.jsx("p",{className:"text-[11px] text-[#5A5A6E]",children:"Already have Tailscale? Make sure it's running and you're on the same Tailnet as the workspace host."})]}),r.jsxs("button",{onClick:n,disabled:e,className:"flex items-center gap-2 px-4 py-2 rounded-lg text-[13px] font-medium bg-[#6366F1]/10 text-[#6366F1] border border-[#6366F1]/30 hover:bg-[#6366F1]/20 transition-colors disabled:opacity-50",children:[r.jsx(Xi,{className:`w-3.5 h-3.5 ${e?"animate-spin":""}`}),"Retry connection"]})]})})}function y8e(){const{token:e}=am(),t=an(),{data:n}=Mi(),[s,i]=y.useState("signup"),[a,o]=y.useState(""),[l,c]=y.useState(""),[d,f]=y.useState(null),[p,m]=y.useState(!1),{data:g,isLoading:b,error:_}=L.workspace.getInvitation.useQuery({token:e},{enabled:!!e,retry:!1}),w=L.workspace.acceptInvitation.useMutation({onSuccess:()=>{setTimeout(()=>t("/"),2e3)}});y.useEffect(()=>{if(w.isSuccess){const S=setTimeout(()=>t("/"),2e3);return()=>clearTimeout(S)}},[w.isSuccess,t]);async function A(S){if(S.preventDefault(),f(null),l.length<12){f("Password must be at least 12 characters.");return}m(!0);try{if(s==="signup"){const C=await cz.email({email:a,password:l,name:a.split("@")[0],fetchOptions:{headers:{"x-invite-token":e}}});C.error&&f(C.error.message??"Sign up failed.")}else{const C=await v0.email({email:a,password:l});C.error&&f(C.error.message??"Invalid credentials.")}}catch{f("Something went wrong. Please try again.")}finally{m(!1)}}return b?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):_&&b8e(_)?r.jsx(v8e,{}):_||!g?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-[#EF4444]/10 border border-[#EF4444]/20 flex items-center justify-center",children:r.jsx("span",{className:"text-[#EF4444] text-xl",children:"✕"})}),r.jsx("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:"Invitation not valid"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99]",children:"This invitation is no longer valid or has expired."}),r.jsx(gn,{to:"/",className:"text-[13px] text-[#6366F1] hover:underline",children:"Go to workspace"})]})}):w.isSuccess?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm text-center px-8",children:[r.jsx("div",{className:"w-12 h-12 rounded-2xl bg-[#10B981]/10 border border-[#10B981]/20 flex items-center justify-center",children:r.jsx("span",{className:"text-[#10B981] text-xl",children:"✓"})}),r.jsxs("h1",{className:"text-[18px] font-semibold text-[#F0F0F5]",children:["You've joined ",g.workspaceName,"!"]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Redirecting you to your workspace..."}),r.jsx("div",{className:"w-4 h-4 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})]})}):r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsxs("div",{className:"w-[400px] bg-[#1C1C24] border border-[#2A2A35] rounded-xl shadow-2xl p-8 flex flex-col items-center gap-5",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center",children:r.jsx("span",{className:"text-2xl font-bold text-[#6366F1]",children:"d"})}),r.jsxs("div",{className:"text-center",children:[r.jsx("h1",{className:"text-[20px] font-semibold text-[#F0F0F5]",children:g.workspaceName}),r.jsxs("p",{className:"text-[13px] text-[#8A8A99] mt-1",children:[g.inviterName," invited you to join as"," ",r.jsx("span",{className:"text-[#C8C8D4]",children:g.role})]})]}),w.error&&r.jsx("p",{className:"text-[12px] text-[#EF4444] text-center",children:w.error.message}),n?r.jsx("button",{onClick:()=>w.mutate({token:e}),disabled:w.isPending,className:"w-full px-4 py-2.5 rounded-lg bg-[#6366F1] text-white text-[14px] font-medium hover:bg-[#5558E8] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:w.isPending?"Joining...":"Join Workspace"}):r.jsxs("div",{className:"w-full flex flex-col gap-3",children:[r.jsxs("form",{onSubmit:A,className:"flex flex-col gap-3 w-full",children:[r.jsx("input",{type:"email",placeholder:"Email",value:a,onChange:S=>o(S.target.value),required:!0,className:"w-full rounded-lg bg-[#13131A] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),r.jsx("input",{type:"password",placeholder:"Password (min 12 characters)",value:l,onChange:S=>c(S.target.value),required:!0,minLength:12,className:"w-full rounded-lg bg-[#13131A] border border-[#2A2A35] text-[#F0F0F5] placeholder-[#5A5A6A] px-4 py-3 text-[14px] outline-none focus:border-[#6366F1] transition-colors"}),d&&r.jsx("p",{className:"text-[12px] text-red-400",children:d}),r.jsx("button",{type:"submit",disabled:p,className:"w-full rounded-lg bg-[#6366F1] text-white px-5 py-3 text-[14px] font-medium hover:bg-[#5254CC] disabled:opacity-50 transition-colors",children:p?"...":s==="signup"?"Create account & join":"Sign in & join"})]}),r.jsx("button",{type:"button",onClick:()=>{i(s==="signin"?"signup":"signin"),f(null)},className:"text-[13px] text-[#8A8A99] hover:text-[#F0F0F5] transition-colors",children:s==="signup"?"Already have an account? Sign in":"Don't have an account? Create one"}),r.jsxs("div",{className:"flex items-center gap-3 w-full",children:[r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"}),r.jsx("span",{className:"text-[12px] text-[#5A5A6A]",children:"or"}),r.jsx("div",{className:"flex-1 h-px bg-[#2A2A35]"})]}),r.jsxs("button",{onClick:()=>v0.social({provider:"google",callbackURL:`${window.location.origin}/invite/${e}`}),className:"flex items-center gap-3 w-full justify-center rounded-lg bg-white text-[#1a1a1a] px-5 py-3 text-[14px] font-medium hover:bg-[#f0f0f0] transition-colors",children:[r.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Continue with Google"]})]})]})})}function _8e({open:e,onClose:t}){const[n,s]=y.useState(""),[i,a]=y.useState(""),[o,l]=y.useState(0),c=y.useRef(null),d=an(),[f,p]=y.useState(e);e&&!f&&(s(""),a(""),l(0)),e!==f&&p(e),y.useEffect(()=>{e&&setTimeout(()=>c.current?.focus(),50)},[e]),y.useEffect(()=>{const A=setTimeout(()=>a(n),200);return()=>clearTimeout(A)},[n]);const{data:m=[]}=L.messages.search.useQuery({query:i},{enabled:i.length>=2}),g=m.reduce((A,S)=>{const C=A[S.channelName]??[];return C.push(S),A[S.channelName]=C,A},{}),b=m;function _(A){d(`/channels/${A.channelId}`),t(),setTimeout(()=>{document.getElementById(`msg-${A.messageId}`)?.scrollIntoView({behavior:"smooth",block:"center"})},300)}function w(A){A.key==="Escape"?t():A.key==="ArrowDown"?(A.preventDefault(),l(S=>Math.min(S+1,b.length-1))):A.key==="ArrowUp"?(A.preventDefault(),l(S=>Math.max(S-1,0))):A.key==="Enter"&&b[o]&&_(b[o])}return r.jsx(Me,{children:e&&r.jsx(ne.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-[100] flex items-start justify-center pt-[15vh]",style:{backdropFilter:"blur(8px)",backgroundColor:"rgba(0,0,0,0.6)"},onClick:A=>{A.target===A.currentTarget&&t()},children:r.jsxs(ne.div,{initial:{opacity:0,y:-12,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.97},transition:{duration:.2,ease:[.16,1,.3,1]},className:"w-full max-w-[600px] mx-4 bg-[#13131A] border border-[#2A2A35] rounded-2xl shadow-2xl overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-[#2A2A35]",children:[r.jsx(Io,{className:"w-5 h-5 text-[#8A8A99] flex-shrink-0"}),r.jsx("input",{ref:c,value:n,onChange:A=>{s(A.target.value),l(0)},onKeyDown:w,placeholder:"Search messages...",className:"flex-1 bg-transparent text-[20px] text-[#F0F0F5] placeholder:text-[#8A8A99]/50 outline-none"}),r.jsx("kbd",{className:"text-[11px] text-[#8A8A99] bg-white/5 border border-[#2A2A35] px-1.5 py-0.5 rounded-md",children:"esc"})]}),i.length>=2&&r.jsx("div",{className:"max-h-[420px] overflow-y-auto py-2",children:m.length===0?r.jsx("div",{className:"px-5 py-8 text-center",children:r.jsxs("p",{className:"text-[14px] text-[#8A8A99]",children:['No messages found for "',i,'"']})}):Object.entries(g).map(([A,S])=>r.jsxs("div",{children:[r.jsx("div",{className:"px-4 py-1.5 sticky top-0 bg-[#13131A]",children:r.jsxs("span",{className:"text-[11px] font-semibold text-[#8A8A99] uppercase tracking-widest",children:["#",A]})}),S.map(C=>{const E=b.indexOf(C),k=E===o;return r.jsxs("button",{onClick:()=>_(C),onMouseEnter:()=>l(E),className:"w-full text-left px-4 py-3 transition-colors",style:{backgroundColor:k?"rgba(255,255,255,0.04)":"transparent"},children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-0.5",children:[r.jsx("span",{className:"text-[12px] font-medium text-[#C8C8D4]",children:"Message"}),r.jsx("span",{className:"text-[11px] text-[#8A8A99]",children:Ir(C.createdAt)})]}),r.jsx("p",{className:"text-[13px] text-[#8A8A99] leading-relaxed",children:w8e(C.snippet,i)})]},C.messageId)})]},A))}),i.length<2&&r.jsx("div",{className:"px-5 py-6 text-center",children:r.jsx("p",{className:"text-[13px] text-[#8A8A99]",children:"Type at least 2 characters to search"})}),r.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 border-t border-[#2A2A35]",children:[r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[r.jsx("kbd",{className:"bg-white/5 border border-[#2A2A35] px-1 py-0.5 rounded text-[10px] mr-1",children:"↑↓"}),"navigate"]}),r.jsxs("span",{className:"text-[11px] text-[#8A8A99]",children:[r.jsx("kbd",{className:"bg-white/5 border border-[#2A2A35] px-1 py-0.5 rounded text-[10px] mr-1",children:"↵"}),"jump"]})]})]})})})}function w8e(e,t){return e.split(new RegExp(`(${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi")).map((s,i)=>s.toLowerCase()===t.toLowerCase()?r.jsx("mark",{className:"bg-[#6366F1]/30 text-[#A5B4FC] rounded-sm px-0.5",children:s},i):s)}function A8e(){return/iPad|iPhone|iPod/.test(navigator.userAgent)&&!("MSStream"in window)}function S8e(){return window.matchMedia("(display-mode: standalone)").matches||"standalone"in navigator&&navigator.standalone===!0}function C8e(){const[e,t]=y.useState(!1),[n,s]=y.useState(!1),[i,a]=y.useState(null);y.useEffect(()=>{if(S8e())return;if(A8e()){localStorage.getItem("pwa-install-dismissed")||t(!0);return}function d(f){f.preventDefault(),a(f),sessionStorage.getItem("pwa-install-dismissed")||s(!0)}return window.addEventListener("beforeinstallprompt",d),()=>window.removeEventListener("beforeinstallprompt",d)},[]);const o=y.useCallback(()=>{localStorage.setItem("pwa-install-dismissed","1"),t(!1)},[]),l=y.useCallback(()=>{sessionStorage.setItem("pwa-install-dismissed","1"),s(!1)},[]),c=y.useCallback(async()=>{i&&(await i.prompt(),s(!1),a(null))},[i]);return r.jsxs(Me,{children:[e&&r.jsxs(ne.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-4 left-4 right-4 z-50 rounded-xl bg-[#1A1A2E] border border-[#2A2A35] p-4 shadow-2xl max-w-md mx-auto",children:[r.jsxs("p",{className:"text-[13px] text-[#C0C0CC] leading-relaxed",children:["For the best experience, add damn.dev to your Home Screen: tap"," ",r.jsx("span",{className:"inline-flex items-center align-middle mx-0.5",children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#6366F1]",children:[r.jsx("path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"}),r.jsx("polyline",{points:"16 6 12 2 8 6"}),r.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"15"})]})})," ","Share → Add to Home Screen"]}),r.jsx("button",{onClick:o,className:"mt-3 text-[12px] font-medium text-[#6366F1] hover:text-[#818CF8] transition-colors",children:"Got it"})]}),n&&r.jsxs(ne.div,{initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:"fixed bottom-4 left-4 right-4 z-50 rounded-xl bg-[#1A1A2E] border border-[#2A2A35] p-4 shadow-2xl max-w-md mx-auto flex items-center justify-between gap-3",children:[r.jsx("p",{className:"text-[13px] text-[#C0C0CC]",children:"Install damn.dev for a native experience"}),r.jsxs("div",{className:"flex gap-2 shrink-0",children:[r.jsx("button",{onClick:l,className:"text-[12px] text-[#8A8A99] hover:text-[#C0C0CC] transition-colors px-2 py-1",children:"Not now"}),r.jsx("button",{onClick:c,className:"text-[12px] font-medium bg-[#6366F1] text-white rounded-lg px-3 py-1.5 hover:bg-[#5558E6] transition-colors",children:"Install"})]})]})]})}function j8e(e){const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),s=atob(n),i=new Uint8Array(s.length);for(let a=0;a<s.length;a++)i[a]=s.charCodeAt(a);return i}const cO="pwa-push-retry-after";function N8e(){const e=y.useRef(!1),{data:t}=L.notifications.getVapidKey.useQuery(void 0,{enabled:!Va}),n=L.notifications.registerToken.useMutation(),s=y.useCallback(async()=>{if(!t?.vapidKey||!("serviceWorker"in navigator)||!("PushManager"in window))return;const a=await navigator.serviceWorker.ready;let o=await a.pushManager.getSubscription();o||(o=await a.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:j8e(t.vapidKey).buffer})),n.mutate({token:JSON.stringify(o.toJSON()),platform:"web"})},[t?.vapidKey,n]),i=y.useCallback(async()=>{if(e.current)return;e.current=!0;const a=localStorage.getItem(cO);if(!(a&&Date.now()<Number(a))){if(Notification.permission==="granted"){await s();return}Notification.permission==="default"&&(await Notification.requestPermission()==="granted"?await s():localStorage.setItem(cO,String(Date.now()+1440*60*1e3)))}},[s]);return y.useEffect(()=>{t?.vapidKey&&Notification.permission==="granted"&&s()},[t?.vapidKey,s]),y.useEffect(()=>{if(!t?.vapidKey||Notification.permission!=="default")return;function a(){i()}return window.addEventListener("pwa-push-prompt",a,{once:!0}),()=>window.removeEventListener("pwa-push-prompt",a)},[t?.vapidKey,i]),{promptForPermission:i}}function k8e(){const[e,t]=y.useState(null),[n,s]=y.useState(!1),[i,a]=y.useState("idle"),[o,l]=y.useState(null),[c,d]=y.useState(!1);y.useEffect(()=>{fetch(`${oi}/api/version`,{credentials:"include"}).then(b=>b.json()).then(b=>{if(b.updateAvailable&&b.latest){const _=`dismissed_update_${b.latest}`;localStorage.getItem(_)||t(b)}}).catch(()=>{})},[]);const f=y.useCallback(()=>{const b=Date.now(),_=setInterval(async()=>{if(Date.now()-b>3e5){clearInterval(_),a("error"),l("Update may have failed. Check server logs.");return}try{(await fetch(`${oi}/health`)).ok&&(clearInterval(_),a("done"),setTimeout(()=>window.location.reload(),1e3))}catch{a("restarting")}},2e3)},[]),p=y.useCallback(async()=>{if(!e)return;if(typeof window<"u"&&"__TAURI__"in window){try{const{check:_}=await X(async()=>{const{check:A}=await import("./index-Cpew6ait.js");return{check:A}},__vite__mapDeps([105,1])),w=await _();if(w){a("updating"),await w.downloadAndInstall();const{relaunch:A}=await X(async()=>{const{relaunch:S}=await import("./index-CO34o7br.js");return{relaunch:S}},__vite__mapDeps([106,1]));await A()}}catch{a("error"),l("Download the latest version from damn.dev")}return}a("updating");try{const _=await fetch(`${oi}/api/update`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}});if(_.status===403){a("error"),l("Only the workspace owner can trigger updates");return}const w=await _.json();if(w.error==="use_native_updater"){a("error"),l("Download the latest version from damn.dev");return}if(!w.ok){a("error"),l(w.error??"Update failed");return}f()}catch{a("error"),l("Failed to start update. Check server logs.")}},[e,f]);if(!e||n)return null;function m(){e?.latest&&localStorage.setItem(`dismissed_update_${e.latest}`,"1"),s(!0)}const g={"docker-vps":"SSH into your server and re-run your install script.",tauri:"Download the latest version from damn.dev."};return r.jsxs("div",{className:"bg-[#1A1A2E] border-b border-[#2A2A35] text-[#9090A0] text-[12px] py-1.5 px-4 flex flex-col flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:["damn.dev ",e.latest," is available"]}),e.canAutoUpdate?r.jsx("button",{onClick:p,className:"px-2 py-0.5 rounded bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 transition-colors text-[11px] font-medium",children:"Update now"}):r.jsx("span",{className:"text-[#707080]",children:g[e.installPath]??"Re-run your install script to update."}),e.releaseNotes&&r.jsx("button",{onClick:()=>d(b=>!b),className:"text-[#707080] hover:text-[#9090A0] transition-colors text-[11px]",children:c?"Hide":"What's new"})]}),i==="updating"&&r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Updating..."]}),i==="restarting"&&r.jsxs("span",{className:"flex items-center gap-2 animate-pulse",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Restarting..."]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E]",children:"Updated!"}),i==="error"&&r.jsx("span",{className:"text-[#F87171]",children:o})]}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:m,className:"ml-4 text-[#9090A0] hover:text-[#F0F0F5] transition-colors",children:"×"})]}),c&&e.releaseNotes&&r.jsx("div",{className:"mt-1.5 pt-1.5 border-t border-[#2A2A35] text-[11px] text-[#707080] whitespace-pre-wrap max-h-40 overflow-y-auto",children:e.releaseNotes})]})}function E8e(){const{data:e,refetch:t}=L.settings.getOpenClawVersion.useQuery(void 0,{refetchInterval:6e4,retry:!1}),[n,s]=y.useState(!1),[i,a]=y.useState("idle"),[o,l]=y.useState(null),c=L.settings.updateOpenClaw.useMutation();if(!e?.updateAvailable||n)return null;async function d(){a("updating");try{const f=await c.mutateAsync();f.ok?(a("done"),setTimeout(()=>{t(),s(!0)},3e3)):(a("error"),l(f.error??"Update failed"))}catch{a("error"),l("Failed to start update. Check server logs.")}}return r.jsxs("div",{className:"bg-[#1A1A2E] border-b border-[#2A2A35] text-[#9090A0] text-[12px] py-1.5 px-4 flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:["OpenClaw ",e.minimum," required (current: ",e.current,")"]}),r.jsx("button",{onClick:d,className:"px-2 py-0.5 rounded bg-[#6366F1]/20 text-[#818CF8] hover:bg-[#6366F1]/30 transition-colors text-[11px] font-medium",children:"Update now"})]}),i==="updating"&&r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-3 h-3 border border-[#6366F1]/40 border-t-[#6366F1] rounded-full animate-spin"}),"Updating OpenClaw..."]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E]",children:"OpenClaw updated!"}),i==="error"&&r.jsx("span",{className:"text-[#F87171]",children:o})]}),(i==="idle"||i==="error")&&r.jsx("button",{onClick:()=>s(!0),className:"ml-4 text-[#9090A0] hover:text-[#F0F0F5] transition-colors",children:"×"})]})}function F8e(){const{data:e,refetch:t,isFetching:n}=L.settings.getOpenClawHealth.useQuery(void 0,{refetchInterval:15e3,retry:!1,refetchOnWindowFocus:!0}),s=L.settings.restartOpenClaw.useMutation(),[i,a]=y.useState("idle"),[o,l]=y.useState(null),c=e?.checkedAt&&e.checkedAt!==new Date(0).toISOString();if(!e||e.healthy||!c)return null;async function d(){a("restarting"),l(null);try{const p=await s.mutateAsync(void 0);p.kind==="restarted"?(a("done"),setTimeout(()=>{a("idle"),t()},1500)):p.kind==="skipped"?(a("skipped"),l(p.detail??p.reason)):(a("failed"),l(p.error))}catch(p){a("failed"),l(p instanceof Error?p.message:"Restart request failed.")}}const f=e.installPath==="docker-local"?"The backend will restart OpenClaw via `docker compose up -d`.":e.installPath==="tauri"?"The sidecar backend will restart OpenClaw via `docker compose up -d`.":e.installPath==="docker-vps"?e.canRestartFromBackend?"The backend will restart OpenClaw via the docker-socket-proxy sidecar.":"This backend runs inside a container without a docker-socket-proxy sidecar. SSH into the host and run `docker compose restart openclaw` — or redeploy to pick up the proxy service.":"OpenClaw runs as a native process on this install. Restart it from the terminal (e.g. `openclaw start`).";return r.jsxs("div",{className:"bg-[#2A1414] border-b border-[#F87171]/30 text-[#FCA5A5] text-[12px] py-1.5 px-4 flex items-center justify-between flex-shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[r.jsx("span",{className:"font-medium",children:"OpenClaw unreachable"}),r.jsxs("span",{className:"text-[#F87171]/70",children:["· ",f]}),e.lastError&&r.jsxs("span",{className:"text-[#F87171]/50 text-[11px]",children:["(",e.lastError,")"]})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i==="idle"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{t()},disabled:n,className:"px-2 py-0.5 rounded bg-[#F87171]/10 text-[#FCA5A5] hover:bg-[#F87171]/20 transition-colors text-[11px] font-medium disabled:opacity-50",children:n?"Checking…":"Retry"}),e.canRestartFromBackend&&r.jsx("button",{onClick:d,className:"px-2 py-0.5 rounded bg-[#F87171]/20 text-[#FCA5A5] hover:bg-[#F87171]/30 transition-colors text-[11px] font-medium",children:"Restart OpenClaw"})]}),i==="restarting"&&r.jsxs("span",{className:"flex items-center gap-2 text-[11px]",children:[r.jsx("span",{className:"w-3 h-3 border border-[#F87171]/40 border-t-[#F87171] rounded-full animate-spin"}),"Restarting…"]}),i==="done"&&r.jsx("span",{className:"text-[#22C55E] text-[11px]",children:"Restart succeeded"}),i==="skipped"&&r.jsx("span",{className:"text-[#F59E0B] text-[11px]",title:o??void 0,children:"Skipped — hover for details"}),i==="failed"&&r.jsx("span",{className:"text-[#F87171] text-[11px]",title:o??void 0,children:"Failed — hover for details"})]})]})}function T8e(){return r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center px-8",children:[r.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-[#6366F1]/20 to-[#8B5CF6]/20 border border-[#6366F1]/30 flex items-center justify-center mb-4",children:r.jsx("span",{className:"text-2xl",children:"⚡"})}),r.jsx("h2",{className:"text-[18px] font-semibold text-[#F0F0F5] mb-2",children:"Select a channel"}),r.jsx("p",{className:"text-[14px] text-[#8A8A99] max-w-xs leading-relaxed",children:"Choose a channel from the sidebar to start working with your team."})]})}function M8e({children:e}){const t=an(),{data:n,isLoading:s}=L.workspace.getMyMembership.useQuery(void 0,{staleTime:0,refetchOnWindowFocus:!1,retry:!1}),i=n?.role==="owner",{data:a,isLoading:o}=L.onboarding.getState.useQuery(void 0,{staleTime:0,refetchOnWindowFocus:!1,retry:!1,enabled:i});return y.useEffect(()=>{if(!(s||!n)){if(n.role!=="owner"){n.onboardedAt||t("/welcome",{replace:!0});return}o||!a||!a.completed&&!a.skippedAt&&t("/onboarding",{replace:!0})}},[a,o,n,s,t]),s||i&&o?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):r.jsx(r.Fragment,{children:e})}function R8e({children:e}){const{data:t,isPending:n}=Mi();return n?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):t?r.jsx(r.Fragment,{children:e}):r.jsx(g8e,{})}function D8e({children:e}){const{isPending:t}=Mi();return t?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-[#0F0F11]",children:r.jsx("div",{className:"w-5 h-5 border-2 border-[#6366F1]/30 border-t-[#6366F1] rounded-full animate-spin"})}):r.jsx(r.Fragment,{children:e})}function O8e(){const[e,t]=y.useState(!1),n=Je(a=>a.setUnreadCounts),{data:s}=Mi(),{data:i}=L.readReceipts.getUnread.useQuery(void 0,{staleTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,enabled:!!s});return y.useEffect(()=>{i&&n(i)},[i,n]),y.useEffect(()=>{function a(o){(o.metaKey||o.ctrlKey)&&o.key==="k"&&(o.preventDefault(),t(l=>!l))}return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[]),N8e(),r.jsxs("div",{className:"flex flex-col h-screen",children:[r.jsx(k8e,{}),r.jsx(E8e,{}),r.jsx(F8e,{}),r.jsxs(Q_,{children:[r.jsx(ms,{path:"/invite/:token",element:r.jsx(D8e,{children:r.jsx(y8e,{})})}),r.jsx(ms,{path:"*",element:r.jsxs(R8e,{children:[r.jsxs(Q_,{children:[r.jsx(ms,{path:"/onboarding",element:r.jsx(m8e,{})}),r.jsx(ms,{path:"/welcome",element:r.jsx(x8e,{})}),r.jsx(ms,{path:"*",element:r.jsx(M8e,{children:r.jsx(qye,{children:r.jsxs(Q_,{children:[r.jsx(ms,{path:"/",element:r.jsx(lm,{to:"/channels/direction",replace:!0})}),r.jsx(ms,{path:"/channels/:channelId",element:r.jsx(UMe,{})}),r.jsx(ms,{path:"/agents",element:r.jsx(tRe,{})}),r.jsx(ms,{path:"/agents/new",element:r.jsx(pRe,{})}),r.jsx(ms,{path:"/agents/edit-soul/:agentId",element:r.jsx(xRe,{})}),r.jsx(ms,{path:"/skills",element:r.jsx(BRe,{})}),r.jsx(ms,{path:"/deliverables",element:r.jsx(qDe,{})}),r.jsx(ms,{path:"/missions",element:r.jsx(GDe,{})}),r.jsx(ms,{path:"/coo",element:r.jsx(ZRe,{})}),r.jsx(ms,{path:"/settings",element:r.jsx(uDe,{})}),r.jsx(ms,{path:"/federation/:nodeId/:agentId",element:r.jsx(IDe,{})}),r.jsx(ms,{path:"*",element:r.jsx(T8e,{})})]})})})})]}),r.jsx(_8e,{open:e,onClose:()=>t(!1)})]})})]}),r.jsx(C8e,{})]})}GG.createRoot(document.getElementById("root")).render(r.jsx(y.StrictMode,{children:r.jsx(aJ,{children:r.jsxs(pY,{children:[r.jsx(O8e,{}),r.jsx(QY,{position:"bottom-right",toastOptions:{style:{background:"#1C1C24",border:"1px solid #2A2A35",color:"#C8C8D4",fontSize:"12px"}}})]})})}));